@markus-global/cli 0.11.3 → 0.12.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +5 -1
- package/dist/backend.js.map +1 -1
- package/dist/commands/approval-card.d.ts +53 -0
- package/dist/commands/approval-card.d.ts.map +1 -0
- package/dist/commands/approval-card.js +43 -0
- package/dist/commands/approval-card.js.map +1 -0
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +11 -5
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +7 -5
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/model.d.ts.map +1 -1
- package/dist/commands/model.js +6 -4
- package/dist/commands/model.js.map +1 -1
- package/dist/commands/outbound.d.ts +76 -0
- package/dist/commands/outbound.d.ts.map +1 -0
- package/dist/commands/outbound.js +80 -0
- package/dist/commands/outbound.js.map +1 -0
- package/dist/commands/start.d.ts +124 -2
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +718 -82
- package/dist/commands/start.js.map +1 -1
- package/dist/index.js +5 -20
- package/dist/index.js.map +1 -1
- package/dist/markus.mjs +112615 -103125
- package/dist/web-ui/assets/AsyncState-BebkDWbq.js +1 -0
- package/dist/web-ui/assets/{CommentInput-DN3Cichs.js → CommentInput-BRZWIC3U.js} +1 -1
- package/dist/web-ui/assets/{ContentRenderer-CjHOyYgJ.js → ContentRenderer-PGP8H_Zz.js} +2 -2
- package/dist/web-ui/assets/DeliverableShareModal-CcigVYGz.js +1 -0
- package/dist/web-ui/assets/Deliverables-CQwXaCA4.js +3 -0
- package/dist/web-ui/assets/{Notifications-CCsdBfdg.js → Notifications-BvHJCIRG.js} +1 -1
- package/dist/web-ui/assets/Search-BA-aXh7i.js +1 -0
- package/dist/web-ui/assets/SendToChat-CAfyKhpq.js +1 -0
- package/dist/web-ui/assets/Settings-icFp6tNI.js +8 -0
- package/dist/web-ui/assets/{Store-BWi97VP9.js → Store-DKwOcmMu.js} +1 -1
- package/dist/web-ui/assets/Switch-C7lFnHA7.js +1 -0
- package/dist/web-ui/assets/Team-DyqXLZ-X.js +84 -0
- package/dist/web-ui/assets/Work-BXGrda4S.js +12 -0
- package/dist/web-ui/assets/{arc-Cg0-C295.js → arc-Dnk6N-Zc.js} +1 -1
- package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-BctEHNLp.js → architectureDiagram-3BPJPVTR-CV8JIXXD.js} +1 -1
- package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-hxr2ZwOV.js → blockDiagram-GPEHLZMM-D9pKmrXH.js} +1 -1
- package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-CfIRo1GE.js → c4Diagram-AAUBKEIU-Q26HvIpY.js} +1 -1
- package/dist/web-ui/assets/channel-BZs6ereM.js +1 -0
- package/dist/web-ui/assets/{chunk-2J33WTMH-T0bENsqX.js → chunk-2J33WTMH-BSjFVwnx.js} +1 -1
- package/dist/web-ui/assets/{chunk-4BX2VUAB-ChLLkyYx.js → chunk-4BX2VUAB-BZXv4MQp.js} +1 -1
- package/dist/web-ui/assets/{chunk-55IACEB6-BD3ENYp9.js → chunk-55IACEB6-CeKd3oeJ.js} +1 -1
- package/dist/web-ui/assets/{chunk-727SXJPM-BAes4atE.js → chunk-727SXJPM-DP1tSQo5.js} +1 -1
- package/dist/web-ui/assets/{chunk-AQP2D5EJ-FymM7gfT.js → chunk-AQP2D5EJ-DqEncn7j.js} +1 -1
- package/dist/web-ui/assets/{chunk-FMBD7UC4-N5sRT0m9.js → chunk-FMBD7UC4-tuDUJ9Xx.js} +1 -1
- package/dist/web-ui/assets/{chunk-ND2GUHAM-BSjS3JyS.js → chunk-ND2GUHAM-DoC8aLWB.js} +1 -1
- package/dist/web-ui/assets/{chunk-QZHKN3VN-Dkwitdbr.js → chunk-QZHKN3VN-74zpvcgs.js} +1 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-C9JIxJeJ.js +1 -0
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-C9JIxJeJ.js +1 -0
- package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-BLuYATCK.js → cose-bilkent-S5V4N54A-DjYUalC1.js} +1 -1
- package/dist/web-ui/assets/{dagre-BM42HDAG-DGLiqiH2.js → dagre-BM42HDAG-oSewacE8.js} +1 -1
- package/dist/web-ui/assets/{diagram-2AECGRRQ-Cq_GnNKs.js → diagram-2AECGRRQ-C1fiWe46.js} +1 -1
- package/dist/web-ui/assets/{diagram-5GNKFQAL-CHNz-2dA.js → diagram-5GNKFQAL-9G_q6hCa.js} +1 -1
- package/dist/web-ui/assets/{diagram-KO2AKTUF-D8eKa7jh.js → diagram-KO2AKTUF-CSm-lJp-.js} +1 -1
- package/dist/web-ui/assets/{diagram-LMA3HP47-RkDgQcLr.js → diagram-LMA3HP47-BTAORcHx.js} +1 -1
- package/dist/web-ui/assets/{diagram-OG6HWLK6-LqxQrIwa.js → diagram-OG6HWLK6-DbcCkDfo.js} +1 -1
- package/dist/web-ui/assets/{docx-preview-Be-Qo_ag.js → docx-preview-DjqdA44x.js} +1 -1
- package/dist/web-ui/assets/{erDiagram-TEJ5UH35-BX0zZgYQ.js → erDiagram-TEJ5UH35-DFa-B8-u.js} +1 -1
- package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-DKnfIFA4.js → flowDiagram-I6XJVG4X-WCTnaK9M.js} +1 -1
- package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-DjBURmY-.js → ganttDiagram-6RSMTGT7-DbW1CoJJ.js} +1 -1
- package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-BvSi7SvS.js → gitGraphDiagram-PVQCEYII-1faDfO29.js} +1 -1
- package/dist/web-ui/assets/index-B8h1PPzP.js +883 -0
- package/dist/web-ui/assets/index-DD3NMntN.css +1 -0
- package/dist/web-ui/assets/{infoDiagram-5YYISTIA-CwtIgim2.js → infoDiagram-5YYISTIA-DfXKP4tQ.js} +1 -1
- package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-CWhXJfSa.js → ishikawaDiagram-YF4QCWOH-D6FOsFQ5.js} +1 -1
- package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-DN9rorlL.js → journeyDiagram-JHISSGLW-DXpxntIF.js} +1 -1
- package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-Burf5FE8.js → kanban-definition-UN3LZRKU-Dt7FBCF3.js} +1 -1
- package/dist/web-ui/assets/{mermaid.core-Dx4rzlyC.js → mermaid.core-sTcSUoRD.js} +5 -5
- package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-DqZ21Siw.js → mindmap-definition-RKZ34NQL-CvOU23ga.js} +1 -1
- package/dist/web-ui/assets/{pieDiagram-4H26LBE5-C_4ksu-T.js → pieDiagram-4H26LBE5-DUedtXVj.js} +1 -1
- package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-Dl6Rjg1X.js → quadrantDiagram-W4KKPZXB-CqpHHRca.js} +1 -1
- package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-CzmWi02d.js → requirementDiagram-4Y6WPE33-CKZYvVDJ.js} +1 -1
- package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-D8K7e8we.js → sankeyDiagram-5OEKKPKP-gZ0nzDfs.js} +1 -1
- package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-1z9rqtVx.js → sequenceDiagram-3UESZ5HK-DN3XdBkW.js} +1 -1
- package/dist/web-ui/assets/{stateDiagram-AJRCARHV-nneYkkHa.js → stateDiagram-AJRCARHV-BvtafGxO.js} +1 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-B2nWDV5R.js +1 -0
- package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-D6GmLlRi.js → timeline-definition-PNZ67QCA-BrR919lp.js} +1 -1
- package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-TVefhiCa.js → vennDiagram-CIIHVFJN-B7CTm4yM.js} +1 -1
- package/dist/web-ui/assets/{wardley-L42UT6IY-BgUuAeiM.js → wardley-L42UT6IY-CyqFngx_.js} +1 -1
- package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-CyJ_l94o.js → wardleyDiagram-YWT4CUSO-BCqEPBJ5.js} +1 -1
- package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-kajbbx7a.js → xychartDiagram-2RQKCTM6-BmT6Cmz-.js} +1 -1
- package/dist/web-ui/index.html +2 -2
- package/docs/README.md +1 -0
- package/docs/architecture/architecture.md +1 -1
- package/docs/architecture/configuration-model.md +156 -0
- package/docs/architecture/messaging-gateway.md +1043 -0
- package/docs/architecture/notification-delivery.md +273 -0
- package/docs/design/remote-access-contract.md +445 -0
- package/docs/guides/development.md +1 -1
- package/docs/guides/guide.md +4 -2
- package/docs/guides/remote-access.md +147 -214
- package/docs/handoff/approval-tri-state-handoff.md +69 -0
- package/docs/handoff/remote-access-handoff.md +160 -0
- package/docs/records/agent-platform-friction-2026-10.md +102 -2
- package/package.json +1 -1
- package/dist/web-ui/assets/DeliverableShareModal-CBSvxB-X.js +0 -1
- package/dist/web-ui/assets/Deliverables-BaAF4-w0.js +0 -3
- package/dist/web-ui/assets/Search-BiBdevAU.js +0 -1
- package/dist/web-ui/assets/Settings-CawBnWuy.js +0 -8
- package/dist/web-ui/assets/Team-CfUDkdc3.js +0 -84
- package/dist/web-ui/assets/Work-DrIXOW-P.js +0 -12
- package/dist/web-ui/assets/channel-DAQ2Rbxq.js +0 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-BZyCVtJb.js +0 -1
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-BZyCVtJb.js +0 -1
- package/dist/web-ui/assets/index-D8vskks7.js +0 -882
- package/dist/web-ui/assets/index-DEN_qReg.css +0 -1
- package/dist/web-ui/assets/modelCapabilities-DDtCBZ6o.js +0 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-C-hpzcms.js +0 -1
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import{y as Vl,z as Wl,x as Fl,R as Yl,r as p,j as t,u as $e,l as le,B as Gl,a as yr,k as Kl,n as kt,P as He,b as Ul,c as Xl,m as Zl,d as Ls,w as mt,C as Tt,E as Or,p as zr,M as Ql,i as Jl,F as qn,q as ur,G as Qa,A as Fs,H as Ao,J as As,K as Do,L as Ds,Q as Po,U as $o,V as Bo,O as ec,W as Ja,X as ei,Y as tc}from"./index-D8vskks7.js";import{ContentRenderer as nc}from"./ContentRenderer-CjHOyYgJ.js";import{s as ht,e as ti,f as Ys,T as vs,g as ws,t as rc}from"./transform-CpIVI4vC.js";import{i as ks}from"./value-DIujSiJ7.js";import{C as ni}from"./CommentInput-DN3Cichs.js";function sc(e){let n;for(;n=e.sourceEvent;)e=n;return e}function It(e,n){if(e=sc(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 oc={passive:!1},fr={capture:!0,passive:!1};function js(e){e.stopImmediatePropagation()}function Yn(e){e.preventDefault(),e.stopImmediatePropagation()}function ri(e){var n=e.document.documentElement,s=ht(e).on("dragstart.drag",Yn,fr);"onselectstart"in n?s.on("selectstart.drag",Yn,fr):(n.__noselect=n.style.MozUserSelect,n.style.MozUserSelect="none")}function si(e,n){var s=e.document.documentElement,r=ht(e).on("dragstart.drag",null);n&&(r.on("click.drag",Yn,fr),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 Hr=e=>()=>e;function Ps(e,{sourceEvent:n,subject:s,target:r,identifier:i,active:o,x:a,y:c,dx:l,dy:d,dispatch:h}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},subject:{value:s,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:a,enumerable:!0,configurable:!0},y:{value:c,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:d,enumerable:!0,configurable:!0},_:{value:h}})}Ps.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function ac(e){return!e.ctrlKey&&!e.button}function ic(){return this.parentNode}function lc(e,n){return n??{x:e.x,y:e.y}}function cc(){return navigator.maxTouchPoints||"ontouchstart"in this}function oi(){var e=ac,n=ic,s=lc,r=cc,i={},o=ti("start","drag","end"),a=0,c,l,d,h,f=0;function m(b){b.on("mousedown.drag",u).filter(r).on("touchstart.drag",C).on("touchmove.drag",v,oc).on("touchend.drag touchcancel.drag",y).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function u(b,j){if(!(h||!e.call(this,b,j))){var k=g(this,n.call(this,b,j),b,j,"mouse");k&&(ht(b.view).on("mousemove.drag",x,fr).on("mouseup.drag",E,fr),ri(b.view),js(b),d=!1,c=b.clientX,l=b.clientY,k("start",b))}}function x(b){if(Yn(b),!d){var j=b.clientX-c,k=b.clientY-l;d=j*j+k*k>f}i.mouse("drag",b)}function E(b){ht(b.view).on("mousemove.drag mouseup.drag",null),si(b.view,d),Yn(b),i.mouse("end",b)}function C(b,j){if(e.call(this,b,j)){var k=b.changedTouches,M=n.call(this,b,j),R=k.length,D,A;for(D=0;D<R;++D)(A=g(this,M,b,j,k[D].identifier,k[D]))&&(js(b),A("start",b,k[D]))}}function v(b){var j=b.changedTouches,k=j.length,M,R;for(M=0;M<k;++M)(R=i[j[M].identifier])&&(Yn(b),R("drag",b,j[M]))}function y(b){var j=b.changedTouches,k=j.length,M,R;for(h&&clearTimeout(h),h=setTimeout(function(){h=null},500),M=0;M<k;++M)(R=i[j[M].identifier])&&(js(b),R("end",b,j[M]))}function g(b,j,k,M,R,D){var A=o.copy(),T=It(D||k,j),$,z,N;if((N=s.call(b,new Ps("beforestart",{sourceEvent:k,target:m,identifier:R,active:a,x:T[0],y:T[1],dx:0,dy:0,dispatch:A}),M))!=null)return $=N.x-T[0]||0,z=N.y-T[1]||0,function O(L,_,I){var P=T,q;switch(L){case"start":i[R]=O,q=a++;break;case"end":delete i[R],--a;case"drag":T=It(I||_,j),q=a;break}A.call(L,b,new Ps(L,{sourceEvent:_,subject:N,target:m,identifier:R,active:q,x:T[0]+$,y:T[1]+z,dx:T[0]-P[0],dy:T[1]-P[1],dispatch:A}),M)}}return m.filter=function(b){return arguments.length?(e=typeof b=="function"?b:Hr(!!b),m):e},m.container=function(b){return arguments.length?(n=typeof b=="function"?b:Hr(b),m):n},m.subject=function(b){return arguments.length?(s=typeof b=="function"?b:Hr(b),m):s},m.touchable=function(b){return arguments.length?(r=typeof b=="function"?b:Hr(!!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 dc=1e-12;function Oo(e){return((e=Math.exp(e))+1/e)/2}function uc(e){return((e=Math.exp(e))-1/e)/2}function fc(e){return((e=Math.exp(2*e))-1)/(e+1)}const Zr=(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,E=u*u+x*x,C,v;if(E<dc)v=Math.log(m/d)/n,C=function(M){return[c+M*u,l+M*x,d*Math.exp(n*M*v)]};else{var y=Math.sqrt(E),g=(m*m-d*d+r*E)/(2*d*s*y),b=(m*m-d*d-r*E)/(2*m*s*y),j=Math.log(Math.sqrt(g*g+1)-g),k=Math.log(Math.sqrt(b*b+1)-b);v=(k-j)/n,C=function(M){var R=M*v,D=Oo(j),A=d/(s*y)*(D*fc(n*R+j)-uc(j));return[c+A*u,l+A*x,d*D/Oo(n*R+j)]}}return C.duration=v*1e3*n/Math.SQRT2,C}return i.rho=function(o){var a=Math.max(.001,+o),c=a*a,l=c*c;return e(a,c,l)},i})(Math.SQRT2,2,4),qr=e=>()=>e;function hc(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 mc(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function pc(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function zo(){return this.__zoom||Ys}function gc(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function xc(){return navigator.maxTouchPoints||"ontouchstart"in this}function bc(e,n,s){var r=e.invertX(n[0][0])-s[0][0],i=e.invertX(n[1][0])-s[1][0],o=e.invertY(n[0][1])-s[0][1],a=e.invertY(n[1][1])-s[1][1];return e.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),a>o?(o+a)/2:Math.min(0,o)||Math.max(0,a))}function ai(){var e=mc,n=pc,s=bc,r=gc,i=xc,o=[0,1/0],a=[[-1/0,-1/0],[1/0,1/0]],c=250,l=Zr,d=ti("start","zoom","end"),h,f,m,u=500,x=150,E=0,C=10;function v(N){N.property("__zoom",zo).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",D).on("dblclick.zoom",A).filter(i).on("touchstart.zoom",T).on("touchmove.zoom",$).on("touchend.zoom touchcancel.zoom",z).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}v.transform=function(N,O,L,_){var I=N.selection?N.selection():N;I.property("__zoom",zo),N!==I?j(N,O,L,_):I.interrupt().each(function(){k(this,arguments).event(_).start().zoom(null,typeof O=="function"?O.apply(this,arguments):O).end()})},v.scaleBy=function(N,O,L,_){v.scaleTo(N,function(){var I=this.__zoom.k,P=typeof O=="function"?O.apply(this,arguments):O;return I*P},L,_)},v.scaleTo=function(N,O,L,_){v.transform(N,function(){var I=n.apply(this,arguments),P=this.__zoom,q=L==null?b(I):typeof L=="function"?L.apply(this,arguments):L,Y=P.invert(q),F=typeof O=="function"?O.apply(this,arguments):O;return s(g(y(P,F),q,Y),I,a)},L,_)},v.translateBy=function(N,O,L,_){v.transform(N,function(){return s(this.__zoom.translate(typeof O=="function"?O.apply(this,arguments):O,typeof L=="function"?L.apply(this,arguments):L),n.apply(this,arguments),a)},null,_)},v.translateTo=function(N,O,L,_,I){v.transform(N,function(){var P=n.apply(this,arguments),q=this.__zoom,Y=_==null?b(P):typeof _=="function"?_.apply(this,arguments):_;return s(Ys.translate(Y[0],Y[1]).scale(q.k).translate(typeof O=="function"?-O.apply(this,arguments):-O,typeof L=="function"?-L.apply(this,arguments):-L),P,a)},_,I)};function y(N,O){return O=Math.max(o[0],Math.min(o[1],O)),O===N.k?N:new vs(O,N.x,N.y)}function g(N,O,L){var _=O[0]-L[0]*N.k,I=O[1]-L[1]*N.k;return _===N.x&&I===N.y?N:new vs(N.k,_,I)}function b(N){return[(+N[0][0]+ +N[1][0])/2,(+N[0][1]+ +N[1][1])/2]}function j(N,O,L,_){N.on("start.zoom",function(){k(this,arguments).event(_).start()}).on("interrupt.zoom end.zoom",function(){k(this,arguments).event(_).end()}).tween("zoom",function(){var I=this,P=arguments,q=k(I,P).event(_),Y=n.apply(I,P),F=L==null?b(Y):typeof L=="function"?L.apply(I,P):L,Q=Math.max(Y[1][0]-Y[0][0],Y[1][1]-Y[0][1]),B=I.__zoom,S=typeof O=="function"?O.apply(I,P):O,V=l(B.invert(F).concat(Q/B.k),S.invert(F).concat(Q/S.k));return function(W){if(W===1)W=S;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 k(N,O,L){return!L&&N.__zooming||new M(N,O)}function M(N,O){this.that=N,this.args=O,this.active=0,this.sourceEvent=null,this.extent=n.apply(N,O),this.taps=0}M.prototype={event:function(N){return N&&(this.sourceEvent=N),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(N,O){return this.mouse&&N!=="mouse"&&(this.mouse[1]=O.invert(this.mouse[0])),this.touch0&&N!=="touch"&&(this.touch0[1]=O.invert(this.touch0[0])),this.touch1&&N!=="touch"&&(this.touch1[1]=O.invert(this.touch1[0])),this.that.__zoom=O,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(N){var O=ht(this.that).datum();d.call(N,this.that,new hc(N,{sourceEvent:this.sourceEvent,target:v,transform:this.that.__zoom,dispatch:d}),O)}};function R(N,...O){if(!e.apply(this,arguments))return;var L=k(this,O).event(N),_=this.__zoom,I=Math.max(o[0],Math.min(o[1],_.k*Math.pow(2,r.apply(this,arguments)))),P=It(N);if(L.wheel)(L.mouse[0][0]!==P[0]||L.mouse[0][1]!==P[1])&&(L.mouse[1]=_.invert(L.mouse[0]=P)),clearTimeout(L.wheel);else{if(_.k===I)return;L.mouse=[P,_.invert(P)],ws(this),L.start()}lr(N),L.wheel=setTimeout(q,x),L.zoom("mouse",s(g(y(_,I),L.mouse[0],L.mouse[1]),L.extent,a));function q(){L.wheel=null,L.end()}}function D(N,...O){if(m||!e.apply(this,arguments))return;var L=N.currentTarget,_=k(this,O,!0).event(N),I=ht(N.view).on("mousemove.zoom",F,!0).on("mouseup.zoom",Q,!0),P=It(N,L),q=N.clientX,Y=N.clientY;ri(N.view),Ns(N),_.mouse=[P,this.__zoom.invert(P)],ws(this),_.start();function F(B){if(lr(B),!_.moved){var S=B.clientX-q,V=B.clientY-Y;_.moved=S*S+V*V>E}_.event(B).zoom("mouse",s(g(_.that.__zoom,_.mouse[0]=It(B,L),_.mouse[1]),_.extent,a))}function Q(B){I.on("mousemove.zoom mouseup.zoom",null),si(B.view,_.moved),lr(B),_.event(B).end()}}function A(N,...O){if(e.apply(this,arguments)){var L=this.__zoom,_=It(N.changedTouches?N.changedTouches[0]:N,this),I=L.invert(_),P=L.k*(N.shiftKey?.5:2),q=s(g(y(L,P),_,I),n.apply(this,O),a);lr(N),c>0?ht(this).transition().duration(c).call(j,q,_,N):ht(this).call(v.transform,q,_,N)}}function T(N,...O){if(e.apply(this,arguments)){var L=N.touches,_=L.length,I=k(this,O,N.changedTouches.length===_).event(N),P,q,Y,F;for(Ns(N),q=0;q<_;++q)Y=L[q],F=It(Y,this),F=[F,this.__zoom.invert(F),Y.identifier],I.touch0?!I.touch1&&I.touch0[2]!==F[2]&&(I.touch1=F,I.taps=0):(I.touch0=F,P=!0,I.taps=1+!!h);h&&(h=clearTimeout(h)),P&&(I.taps<2&&(f=F[0],h=setTimeout(function(){h=null},u)),ws(this),I.start())}}function $(N,...O){if(this.__zooming){var L=k(this,O).event(N),_=N.changedTouches,I=_.length,P,q,Y,F;for(lr(N),P=0;P<I;++P)q=_[P],Y=It(q,this),L.touch0&&L.touch0[2]===q.identifier?L.touch0[0]=Y:L.touch1&&L.touch1[2]===q.identifier&&(L.touch1[0]=Y);if(q=L.that.__zoom,L.touch1){var Q=L.touch0[0],B=L.touch0[1],S=L.touch1[0],V=L.touch1[1],W=(W=S[0]-Q[0])*W+(W=S[1]-Q[1])*W,H=(H=V[0]-B[0])*H+(H=V[1]-B[1])*H;q=y(q,Math.sqrt(W/H)),Y=[(Q[0]+S[0])/2,(Q[1]+S[1])/2],F=[(B[0]+V[0])/2,(B[1]+V[1])/2]}else if(L.touch0)Y=L.touch0[0],F=L.touch0[1];else return;L.zoom("touch",s(g(q,Y,F),L.extent,a))}}function z(N,...O){if(this.__zooming){var L=k(this,O).event(N),_=N.changedTouches,I=_.length,P,q;for(Ns(N),m&&clearTimeout(m),m=setTimeout(function(){m=null},u),P=0;P<I;++P)q=_[P],L.touch0&&L.touch0[2]===q.identifier?delete L.touch0:L.touch1&&L.touch1[2]===q.identifier&&delete L.touch1;if(L.touch1&&!L.touch0&&(L.touch0=L.touch1,delete L.touch1),L.touch0)L.touch0[1]=this.__zoom.invert(L.touch0[0]);else if(L.end(),L.taps===2&&(q=It(q,this),Math.hypot(f[0]-q[0],f[1]-q[1])<C)){var Y=ht(this).on("dblclick.zoom");Y&&Y.apply(this,arguments)}}}return v.wheelDelta=function(N){return arguments.length?(r=typeof N=="function"?N:qr(+N),v):r},v.filter=function(N){return arguments.length?(e=typeof N=="function"?N:qr(!!N),v):e},v.touchable=function(N){return arguments.length?(i=typeof N=="function"?N:qr(!!N),v):i},v.extent=function(N){return arguments.length?(n=typeof N=="function"?N:qr([[+N[0][0],+N[0][1]],[+N[1][0],+N[1][1]]]),v):n},v.scaleExtent=function(N){return arguments.length?(o[0]=+N[0],o[1]=+N[1],v):[o[0],o[1]]},v.translateExtent=function(N){return arguments.length?(a[0][0]=+N[0][0],a[1][0]=+N[1][0],a[0][1]=+N[0][1],a[1][1]=+N[1][1],v):[[a[0][0],a[0][1]],[a[1][0],a[1][1]]]},v.constrain=function(N){return arguments.length?(s=N,v):s},v.duration=function(N){return arguments.length?(c=+N,v):c},v.interpolate=function(N){return arguments.length?(l=N,v):l},v.on=function(){var N=d.on.apply(d,arguments);return N===d?v:N},v.clickDistance=function(N){return arguments.length?(E=(N=+N)*N,v):Math.sqrt(E)},v.tapDistance=function(N){return arguments.length?(C=+N,v):C},v}function Ye(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=Ye(e[s]))!==""&&(n+=(n&&" ")+r);else for(let s in e)e[s]&&(n+=(n&&" ")+s);return n}const Wt={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."},hr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ii=["Enter"," ","Escape"],li={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:n,y:s})=>`Moved selected node ${e}. New position, x: ${n}, y: ${s}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var Gn;(function(e){e.Strict="strict",e.Loose="loose"})(Gn||(Gn={}));var Mn;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Mn||(Mn={}));var mr;(function(e){e.Partial="partial",e.Full="full"})(mr||(mr={}));const ci={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var fn;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(fn||(fn={}));var Kn;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Kn||(Kn={}));var ve;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(ve||(ve={}));const Ho={[ve.Left]:ve.Right,[ve.Right]:ve.Left,[ve.Top]:ve.Bottom,[ve.Bottom]:ve.Top};function di(e){return e===null?null:e?"valid":"invalid"}const ui=e=>"id"in e&&"source"in e&&"target"in e,yc=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Gs=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),vr=(e,n=[0,0])=>{const{width:s,height:r}=rn(e),i=e.origin??n,o=s*i[0],a=r*i[1];return{x:e.position.x-o,y:e.position.y-a}},vc=(e,n={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const s=e.reduce((r,i)=>{const o=typeof i=="string";let a=!n.nodeLookup&&!o?i:void 0;n.nodeLookup&&(a=o?n.nodeLookup.get(i):Gs(i)?i:n.nodeLookup.get(i.id));const c=a?ts(a,n.nodeOrigin):{x:0,y:0,x2:0,y2:0};return is(r,c)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return ls(s)},wr=(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=is(s,ts(i)),r=!0)}),r?ls(s):{x:0,y:0,width:0,height:0}},Ks=(e,n,[s,r,i]=[0,0,1],o=!1,a=!1)=>{const c={...jr(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,E=pr(c,Xn(d)),C=(u??0)*(x??0),v=o&&E>0;(!d.internals.handleBounds||v||E>=C||d.dragging)&&l.push(d)}return l},wc=(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 kc(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 jc({nodes:e,width:n,height:s,panZoom:r,minZoom:i,maxZoom:o},a){if(e.size===0)return Promise.resolve(!0);const c=kc(e,a),l=wr(c),d=Us(l,n,s,a?.minZoom??i,a?.maxZoom??o,a?.padding??.1);return await r.setViewport(d,{duration:a?.duration,ease:a?.ease,interpolate:a?.interpolate}),Promise.resolve(!0)}function fi({nodeId:e,nextPosition:n,nodeLookup:s,nodeOrigin:r=[0,0],nodeExtent:i,onError:o}){const a=s.get(e),c=a.parentId?s.get(a.parentId):void 0,{x:l,y:d}=c?c.internals.positionAbsolute:{x:0,y:0},h=a.origin??r;let f=a.extent||i;if(a.extent==="parent"&&!a.expandParent)if(!c)o?.("005",Wt.error005());else{const u=c.measured.width,x=c.measured.height;u&&x&&(f=[[l,d],[l+u,d+x]])}else c&&Zn(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=Zn(f)?Tn(n,f,a.measured):n;return(a.measured.width===void 0||a.measured.height===void 0)&&o?.("015",Wt.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 Nc({nodesToRemove:e=[],edgesToRemove:n=[],nodes:s,edges:r,onBeforeDelete:i}){const o=new Set(e.map(m=>m.id)),a=[];for(const m of s){if(m.deletable===!1)continue;const u=o.has(m.id),x=!u&&m.parentId&&a.find(E=>E.id===m.parentId);(u||x)&&a.push(m)}const c=new Set(n.map(m=>m.id)),l=r.filter(m=>m.deletable!==!1),h=wc(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 Un=(e,n=0,s=1)=>Math.min(Math.max(e,n),s),Tn=(e={x:0,y:0},n,s)=>({x:Un(e.x,n[0][0],n[1][0]-(s?.width??0)),y:Un(e.y,n[0][1],n[1][1]-(s?.height??0))});function hi(e,n,s){const{width:r,height:i}=rn(s),{x:o,y:a}=s.internals.positionAbsolute;return Tn(e,[[o,a],[o+r,a+i]],n)}const qo=(e,n,s)=>e<n?Un(Math.abs(e-n),1,n)/n:e>s?-Un(Math.abs(e-s),1,n)/n:0,mi=(e,n,s=15,r=40)=>{const i=qo(e.x,r,n.width-r)*s,o=qo(e.y,r,n.height-r)*s;return[i,o]},is=(e,n)=>({x:Math.min(e.x,n.x),y:Math.min(e.y,n.y),x2:Math.max(e.x2,n.x2),y2:Math.max(e.y2,n.y2)}),$s=({x:e,y:n,width:s,height:r})=>({x:e,y:n,x2:e+s,y2:n+r}),ls=({x:e,y:n,x2:s,y2:r})=>({x:e,y:n,width:s-e,height:r-n}),Xn=(e,n=[0,0])=>{const{x:s,y:r}=Gs(e)?e.internals.positionAbsolute:vr(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}},ts=(e,n=[0,0])=>{const{x:s,y:r}=Gs(e)?e.internals.positionAbsolute:vr(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)}},pi=(e,n)=>ls(is($s(e),$s(n))),pr=(e,n)=>{const s=Math.max(0,Math.min(e.x+e.width,n.x+n.width)-Math.max(e.x,n.x)),r=Math.max(0,Math.min(e.y+e.height,n.y+n.height)-Math.max(e.y,n.y));return Math.ceil(s*r)},Vo=e=>Rt(e.width)&&Rt(e.height)&&Rt(e.x)&&Rt(e.y),Rt=e=>!isNaN(e)&&isFinite(e),Cc=(e,n)=>{},kr=(e,n=[1,1])=>({x:n[0]*Math.round(e.x/n[0]),y:n[1]*Math.round(e.y/n[1])}),jr=({x:e,y:n},[s,r,i],o=!1,a=[1,1])=>{const c={x:(e-s)/i,y:(n-r)/i};return o?kr(c,a):c},ns=({x:e,y:n},[s,r,i])=>({x:e*i+s,y:n*i+r});function Hn(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 Sc(e,n,s){if(typeof e=="string"||typeof e=="number"){const r=Hn(e,s),i=Hn(e,n);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e=="object"){const r=Hn(e.top??e.y??0,s),i=Hn(e.bottom??e.y??0,s),o=Hn(e.left??e.x??0,n),a=Hn(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 Ec(e,n,s,r,i,o){const{x:a,y:c}=ns(e,[n,s,r]),{x:l,y:d}=ns({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 Us=(e,n,s,r,i,o)=>{const a=Sc(o,n,s),c=(n-a.x)/e.width,l=(s-a.y)/e.height,d=Math.min(c,l),h=Un(d,r,i),f=e.x+e.width/2,m=e.y+e.height/2,u=n/2-f*h,x=s/2-m*h,E=Ec(e,u,x,h,n,s),C={left:Math.min(E.left-a.left,0),top:Math.min(E.top-a.top,0),right:Math.min(E.right-a.right,0),bottom:Math.min(E.bottom-a.bottom,0)};return{x:u-C.left+C.right,y:x-C.top+C.bottom,zoom:h}},gr=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Zn(e){return e!=null&&e!=="parent"}function rn(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function gi(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function xi(e,n={width:0,height:0},s,r,i){const o={...e},a=r.get(s);if(a){const c=a.origin||i;o.x+=a.internals.positionAbsolute.x-(n.width??0)*c[0],o.y+=a.internals.positionAbsolute.y-(n.height??0)*c[1]}return o}function Wo(e,n){if(e.size!==n.size)return!1;for(const s of e)if(!n.has(s))return!1;return!0}function Mc(){let e,n;return{promise:new Promise((r,i)=>{e=r,n=i}),resolve:e,reject:n}}function Tc(e){return{...li,...e||{}}}function cr(e,{snapGrid:n=[0,0],snapToGrid:s=!1,transform:r,containerBounds:i}){const{x:o,y:a}=_t(e),c=jr({x:o-(i?.left??0),y:a-(i?.top??0)},r),{x:l,y:d}=s?kr(c,n):c;return{xSnapped:l,ySnapped:d,...c}}const Xs=e=>({width:e.offsetWidth,height:e.offsetHeight}),bi=e=>e?.getRootNode?.()||window?.document,Ic=["INPUT","SELECT","TEXTAREA"];function yi(e){const n=e.composedPath?.()?.[0]||e.target;return n?.nodeType!==1?!1:Ic.includes(n.nodeName)||n.hasAttribute("contenteditable")||!!n.closest(".nokey")}const vi=e=>"clientX"in e,_t=(e,n)=>{const s=vi(e),r=s?e.clientX:e.touches?.[0].clientX,i=s?e.clientY:e.touches?.[0].clientY;return{x:r-(n?.left??0),y:i-(n?.top??0)}},Fo=(e,n,s,r,i)=>{const o=n.querySelectorAll(`.${e}`);return!o||!o.length?null:Array.from(o).map(a=>{const c=a.getBoundingClientRect();return{id:a.getAttribute("data-handleid"),type:e,nodeId:i,position:a.getAttribute("data-handlepos"),x:(c.left-s.left)/r,y:(c.top-s.top)/r,...Xs(a)}})};function wi({sourceX:e,sourceY:n,targetX:s,targetY:r,sourceControlX:i,sourceControlY:o,targetControlX:a,targetControlY:c}){const l=e*.125+i*.375+a*.375+s*.125,d=n*.125+o*.375+c*.375+r*.125,h=Math.abs(l-e),f=Math.abs(d-n);return[l,d,h,f]}function Vr(e,n){return e>=0?.5*e:n*25*Math.sqrt(-e)}function Yo({pos:e,x1:n,y1:s,x2:r,y2:i,c:o}){switch(e){case ve.Left:return[n-Vr(n-r,o),s];case ve.Right:return[n+Vr(r-n,o),s];case ve.Top:return[n,s-Vr(s-i,o)];case ve.Bottom:return[n,s+Vr(i-s,o)]}}function ki({sourceX:e,sourceY:n,sourcePosition:s=ve.Bottom,targetX:r,targetY:i,targetPosition:o=ve.Top,curvature:a=.25}){const[c,l]=Yo({pos:s,x1:e,y1:n,x2:r,y2:i,c:a}),[d,h]=Yo({pos:o,x1:r,y1:i,x2:e,y2:n,c:a}),[f,m,u,x]=wi({sourceX:e,sourceY:n,targetX:r,targetY:i,sourceControlX:c,sourceControlY:l,targetControlX:d,targetControlY:h});return[`M${e},${n} C${c},${l} ${d},${h} ${r},${i}`,f,m,u,x]}function ji({sourceX:e,sourceY:n,targetX:s,targetY:r}){const i=Math.abs(s-e)/2,o=s<e?s+i:s-i,a=Math.abs(r-n)/2,c=r<n?r+a:r-a;return[o,c,i,a]}function Rc({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 _c({sourceNode:e,targetNode:n,width:s,height:r,transform:i}){const o=is(ts(e),ts(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,ls(o))>0}const Lc=({source:e,sourceHandle:n,target:s,targetHandle:r})=>`xy-edge__${e}${n||""}-${s}${r||""}`,Ac=(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)),Dc=(e,n,s={})=>{if(!e.source||!e.target)return n;const r=s.getEdgeId||Lc;let i;return ui(e)?i={...e}:i={...e,id:r(e)},Ac(i,n)?n:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,n.concat(i))};function Ni({sourceX:e,sourceY:n,targetX:s,targetY:r}){const[i,o,a,c]=ji({sourceX:e,sourceY:n,targetX:s,targetY:r});return[`M ${e},${n}L ${s},${r}`,i,o,a,c]}const Go={[ve.Left]:{x:-1,y:0},[ve.Right]:{x:1,y:0},[ve.Top]:{x:0,y:-1},[ve.Bottom]:{x:0,y:1}},Pc=({source:e,sourcePosition:n=ve.Bottom,target:s})=>n===ve.Left||n===ve.Right?e.x<s.x?{x:1,y:0}:{x:-1,y:0}:e.y<s.y?{x:0,y:1}:{x:0,y:-1},Ko=(e,n)=>Math.sqrt(Math.pow(n.x-e.x,2)+Math.pow(n.y-e.y,2));function $c({source:e,sourcePosition:n=ve.Bottom,target:s,targetPosition:r=ve.Top,center:i,offset:o,stepPosition:a}){const c=Go[n],l=Go[r],d={x:e.x+c.x*o,y:e.y+c.y*o},h={x:s.x+l.x*o,y:s.y+l.y*o},f=Pc({source:d,sourcePosition:n,target:h}),m=f.x!==0?"x":"y",u=f[m];let x=[],E,C;const v={x:0,y:0},y={x:0,y:0},[,,g,b]=ji({sourceX:e.x,sourceY:e.y,targetX:s.x,targetY:s.y});if(c[m]*l[m]===-1){m==="x"?(E=i.x??d.x+(h.x-d.x)*a,C=i.y??(d.y+h.y)/2):(E=i.x??(d.x+h.x)/2,C=i.y??d.y+(h.y-d.y)*a);const k=[{x:E,y:d.y},{x:E,y:h.y}],M=[{x:d.x,y:C},{x:h.x,y:C}];c[m]===u?x=m==="x"?k:M:x=m==="x"?M:k}else{const k=[{x:d.x,y:h.y}],M=[{x:h.x,y:d.y}];if(m==="x"?x=c.x===u?M:k:x=c.y===u?k:M,n===r){const $=Math.abs(e[m]-s[m]);if($<=o){const z=Math.min(o-1,o-$);c[m]===u?v[m]=(d[m]>e[m]?-1:1)*z:y[m]=(h[m]>s[m]?-1:1)*z}}if(n!==r){const $=m==="x"?"y":"x",z=c[m]===l[$],N=d[$]>h[$],O=d[$]<h[$];(c[m]===1&&(!z&&N||z&&O)||c[m]!==1&&(!z&&O||z&&N))&&(x=m==="x"?k:M)}const R={x:d.x+v.x,y:d.y+v.y},D={x:h.x+y.x,y:h.y+y.y},A=Math.max(Math.abs(R.x-x[0].x),Math.abs(D.x-x[0].x)),T=Math.max(Math.abs(R.y-x[0].y),Math.abs(D.y-x[0].y));A>=T?(E=(R.x+D.x)/2,C=x[0].y):(E=x[0].x,C=(R.y+D.y)/2)}return[[e,{x:d.x+v.x,y:d.y+v.y},...x,{x:h.x+y.x,y:h.y+y.y},s],E,C,g,b]}function Bc(e,n,s,r){const i=Math.min(Ko(e,n)/2,Ko(n,s)/2,r),{x:o,y:a}=n;if(e.x===o&&o===s.x||e.y===a&&a===s.y)return`L${o} ${a}`;if(e.y===a){const d=e.x<s.x?-1:1,h=e.y<s.y?1:-1;return`L ${o+i*d},${a}Q ${o},${a} ${o},${a+i*h}`}const c=e.x<s.x?1:-1,l=e.y<s.y?-1:1;return`L ${o},${a+i*l}Q ${o},${a} ${o+i*c},${a}`}function Bs({sourceX:e,sourceY:n,sourcePosition:s=ve.Bottom,targetX:r,targetY:i,targetPosition:o=ve.Top,borderRadius:a=5,centerX:c,centerY:l,offset:d=20,stepPosition:h=.5}){const[f,m,u,x,E]=$c({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((v,y,g)=>{let b="";return g>0&&g<f.length-1?b=Bc(f[g-1],y,f[g+1],a):b=`${g===0?"M":"L"}${y.x} ${y.y}`,v+=b,v},""),m,u,x,E]}function Uo(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Oc(e){const{sourceNode:n,targetNode:s}=e;if(!Uo(n)||!Uo(s))return null;const r=n.internals.handleBounds||Xo(n.handles),i=s.internals.handleBounds||Xo(s.handles),o=Zo(r?.source??[],e.sourceHandle),a=Zo(e.connectionMode===Gn.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!o||!a)return e.onError?.("008",Wt.error008(o?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const c=o?.position||ve.Bottom,l=a?.position||ve.Top,d=In(n,o,c),h=In(s,a,l);return{sourceX:d.x,sourceY:d.y,targetX:h.x,targetY:h.y,sourcePosition:c,targetPosition:l}}function Xo(e){if(!e)return null;const n=[],s=[];for(const r of e)r.width=r.width??1,r.height=r.height??1,r.type==="source"?n.push(r):r.type==="target"&&s.push(r);return{source:n,target:s}}function In(e,n,s=ve.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??rn(e);if(r)return{x:i+a/2,y:o+c/2};switch(n?.position??s){case ve.Top:return{x:i+a/2,y:o};case ve.Right:return{x:i+a,y:o+c/2};case ve.Bottom:return{x:i+a/2,y:o+c};case ve.Left:return{x:i,y:o+c/2}}}function Zo(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 zc(e,{id:n,defaultColor:s,defaultMarkerStart:r,defaultMarkerEnd:i}){const o=new Set;return e.reduce((a,c)=>([c.markerStart||r,c.markerEnd||i].forEach(l=>{if(l&&typeof l=="object"){const d=Os(l,n);o.has(d)||(a.push({id:d,color:l.color||s,...l}),o.add(d))}}),a),[]).sort((a,c)=>a.id.localeCompare(c.id))}const Ci=1e3,Hc=10,Zs={nodeOrigin:[0,0],nodeExtent:hr,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},qc={...Zs,checkEquality:!0};function Qs(e,n){const s={...e};for(const r in n)n[r]!==void 0&&(s[r]=n[r]);return s}function Vc(e,n,s){const r=Qs(Zs,s);for(const i of e.values())if(i.parentId)eo(i,e,n,r);else{const o=vr(i,r.nodeOrigin),a=Zn(i.extent)?i.extent:r.nodeExtent,c=Tn(o,a,rn(i));i.internals.positionAbsolute=c}}function Wc(e,n){if(!e.handles)return e.measured?n?.internals.handleBounds:void 0;const s=[],r=[];for(const i of e.handles){const o={id:i.id,width:i.width??1,height:i.height??1,nodeId:e.id,x:i.x,y:i.y,position:i.position,type:i.type};i.type==="source"?s.push(o):i.type==="target"&&r.push(o)}return{source:s,target:r}}function Js(e){return e==="manual"}function zs(e,n,s,r={}){const i=Qs(qc,r),o={i:0},a=new Map(n),c=i?.elevateNodesOnSelect&&!Js(i.zIndexMode)?Ci:0;let l=e.length>0;n.clear(),s.clear();for(const d of e){let h=a.get(d.id);if(i.checkEquality&&d===h?.internals.userNode)n.set(d.id,h);else{const f=vr(d,i.nodeOrigin),m=Zn(d.extent)?d.extent:i.nodeExtent,u=Tn(f,m,rn(d));h={...i.defaults,...d,measured:{width:d.measured?.width,height:d.measured?.height},internals:{positionAbsolute:u,handleBounds:Wc(d,h),z:Si(d,c,i.zIndexMode),userNode:d}},n.set(d.id,h)}(h.measured===void 0||h.measured.width===void 0||h.measured.height===void 0)&&!h.hidden&&(l=!1),d.parentId&&eo(h,n,s,r,o)}return l}function Fc(e,n){if(!e.parentId)return;const s=n.get(e.parentId);s?s.set(e.id,e):n.set(e.parentId,new Map([[e.id,e]]))}function eo(e,n,s,r,i){const{elevateNodesOnSelect:o,nodeOrigin:a,nodeExtent:c,zIndexMode:l}=Qs(Zs,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}Fc(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*Hc),i&&h.internals.rootParentIndex!==void 0&&(i.i=h.internals.rootParentIndex);const f=o&&!Js(l)?Ci:0,{x:m,y:u,z:x}=Yc(e,h,a,c,f,l),{positionAbsolute:E}=e.internals,C=m!==E.x||u!==E.y;(C||x!==e.internals.z)&&n.set(e.id,{...e,internals:{...e.internals,positionAbsolute:C?{x:m,y:u}:E,z:x}})}function Si(e,n,s){const r=Rt(e.zIndex)?e.zIndex:0;return Js(s)?r:r+(e.selected?n:0)}function Yc(e,n,s,r,i,o){const{x:a,y:c}=n.internals.positionAbsolute,l=rn(e),d=vr(e,s),h=Zn(e.extent)?Tn(d,e.extent,l):d;let f=Tn({x:a+h.x,y:c+h.y},r,l);e.extent==="parent"&&(f=hi(f,l,n));const m=Si(e,i,o),u=n.internals.z??0;return{x:f.x,y:f.y,z:u>=m?u+1:m}}function to(e,n,s,r=[0,0]){const i=[],o=new Map;for(const a of e){const c=n.get(a.parentId);if(!c)continue;const l=o.get(a.parentId)?.expandedRect??Xn(c),d=pi(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=rn(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)),E=Math.max(h.height,Math.round(a.height)),C=(x-h.width)*f[0],v=(E-h.height)*f[1];(m>0||u>0||C||v)&&(i.push({id:l,type:"position",position:{x:c.position.x-m+C,y:c.position.y-u+v}}),s.get(l)?.forEach(y=>{e.some(g=>g.id===y.id)||i.push({id:y.id,type:"position",position:{x:y.position.x+m,y:y.position.y+u}})})),(h.width<a.width||h.height<a.height||m||u)&&i.push({id:l,type:"dimensions",setAttributes:!0,dimensions:{width:x+(m?f[0]*m-C:0),height:E+(u?f[1]*u-v:0)}})}),i}function Gc(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 E=Xs(u.nodeElement),C=x.measured.width!==E.width||x.measured.height!==E.height;if(!!(E.width&&E.height&&(C||!x.internals.handleBounds||u.force))){const y=u.nodeElement.getBoundingClientRect(),g=Zn(x.extent)?x.extent:o;let{positionAbsolute:b}=x.internals;x.parentId&&x.extent==="parent"?b=hi(b,E,n.get(x.parentId)):g&&(b=Tn(b,g,E));const j={...x,measured:E,internals:{...x.internals,positionAbsolute:b,handleBounds:{source:Fo("source",u.nodeElement,y,f,x.id),target:Fo("target",u.nodeElement,y,f,x.id)}}};n.set(x.id,j),x.parentId&&eo(j,n,s,{nodeOrigin:i,zIndexMode:a}),l=!0,C&&(d.push({id:x.id,type:"dimensions",dimensions:E}),x.expandParent&&x.parentId&&m.push({id:x.id,parentId:x.parentId,rect:Xn(j,i)}))}}if(m.length>0){const u=to(m,n,s,i);d.push(...u)}return{changes:d,updatedInternals:l}}async function Kc({delta:e,panZoom:n,transform:s,translateExtent:r,width:i,height:o}){if(!n||!e.x&&!e.y)return Promise.resolve(!1);const a=await n.setViewportConstrained({x:s[0]+e.x,y:s[1]+e.y,zoom:s[2]},[[0,0],[i,o]],r),c=!!a&&(a.x!==s[0]||a.y!==s[1]||a.k!==s[2]);return Promise.resolve(c)}function Qo(e,n,s,r,i,o){let a=i;const c=r.get(a)||new Map;r.set(a,c.set(s,n)),a=`${i}-${e}`;const l=r.get(a)||new Map;if(r.set(a,l.set(s,n)),o){a=`${i}-${e}-${o}`;const d=r.get(a)||new Map;r.set(a,d.set(s,n))}}function Ei(e,n,s){e.clear(),n.clear();for(const r of s){const{source:i,target:o,sourceHandle:a=null,targetHandle:c=null}=r,l={edgeId:r.id,source:i,target:o,sourceHandle:a,targetHandle:c},d=`${i}-${a}--${o}-${c}`,h=`${o}-${c}--${i}-${a}`;Qo("source",l,h,e,i,a),Qo("target",l,d,e,o,c),n.set(r.id,r)}}function Mi(e,n){if(!e.parentId)return!1;const s=n.get(e.parentId);return s?s.selected?!0:Mi(s,n):!1}function Jo(e,n,s){let r=e;do{if(r?.matches?.(n))return!0;if(r===s)return!1;r=r?.parentElement}while(r);return!1}function Uc(e,n,s,r){const i=new Map;for(const[o,a]of e)if((a.selected||a.id===r)&&(!a.parentId||!Mi(a,e))&&(a.draggable||n&&typeof a.draggable>"u")){const c=e.get(o);c&&i.set(o,{id:o,position:c.position||{x:0,y:0},distance:{x:s.x-c.internals.positionAbsolute.x,y:s.y-c.internals.positionAbsolute.y},extent:c.extent,parentId:c.parentId,origin:c.origin,expandParent:c.expandParent,internals:{positionAbsolute:c.internals.positionAbsolute||{x:0,y:0}},measured:{width:c.measured.width??0,height:c.measured.height??0}})}return i}function Cs({nodeId:e,dragItems:n,nodeLookup:s,dragging:r=!0}){const i=[];for(const[a,c]of n){const l=s.get(a)?.internals.userNode;l&&i.push({...l,position:c.position,dragging:r})}if(!e)return[i[0],i];const o=s.get(e)?.internals.userNode;return[o?{...o,position:n.get(e)?.position||o.position,dragging:r}:i[0],i]}function Xc({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=kr(o,n);return{x:a.x-o.x,y:a.y-o.y}}function Zc({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,E=null;function C({noDragClassName:y,handleSelector:g,domNode:b,isSelectable:j,nodeId:k,nodeClickDistance:M=0}){m=ht(b);function R({x:$,y:z}){const{nodeLookup:N,nodeExtent:O,snapGrid:L,snapToGrid:_,nodeOrigin:I,onNodeDrag:P,onSelectionDrag:q,onError:Y,updateNodePositions:F}=n();o={x:$,y:z};let Q=!1;const B=c.size>1,S=B&&O?$s(wr(c)):null,V=B&&_?Xc({dragItems:c,snapGrid:L,x:$,y:z}):null;for(const[W,H]of c){if(!N.has(W))continue;let K={x:$-H.distance.x,y:z-H.distance.y};_&&(K=V?{x:Math.round(K.x+V.x),y:Math.round(K.y+V.y)}:kr(K,L));let te=null;if(B&&O&&!H.extent&&S){const{positionAbsolute:J}=H.internals,Z=J.x-S.x+O[0][0],ce=J.x+H.measured.width-S.x2+O[1][0],ae=J.y-S.y+O[0][1],pe=J.y+H.measured.height-S.y2+O[1][1];te=[[Z,ae],[ce,pe]]}const{position:re,positionAbsolute:fe}=fi({nodeId:W,nextPosition:K,nodeLookup:N,nodeExtent:te||O,nodeOrigin:I,onError:Y});Q=Q||H.position.x!==re.x||H.position.y!==re.y,H.position=re,H.internals.positionAbsolute=fe}if(x=x||Q,!!Q&&(F(c,!0),E&&(r||P||!k&&q))){const[W,H]=Cs({nodeId:k,dragItems:c,nodeLookup:N});r?.(E,c,W,H),P?.(E,W,H),k||q?.(E,H)}}async function D(){if(!h)return;const{transform:$,panBy:z,autoPanSpeed:N,autoPanOnNodeDrag:O}=n();if(!O){l=!1,cancelAnimationFrame(a);return}const[L,_]=mi(d,h,N);(L!==0||_!==0)&&(o.x=(o.x??0)-L/$[2],o.y=(o.y??0)-_/$[2],await z({x:L,y:_})&&R(o)),a=requestAnimationFrame(D)}function A($){const{nodeLookup:z,multiSelectionActive:N,nodesDraggable:O,transform:L,snapGrid:_,snapToGrid:I,selectNodesOnDrag:P,onNodeDragStart:q,onSelectionDragStart:Y,unselectNodesAndEdges:F}=n();f=!0,(!P||!j)&&!N&&k&&(z.get(k)?.selected||F()),j&&P&&k&&e?.(k);const Q=cr($.sourceEvent,{transform:L,snapGrid:_,snapToGrid:I,containerBounds:h});if(o=Q,c=Uc(z,O,Q,k),c.size>0&&(s||q||!k&&Y)){const[B,S]=Cs({nodeId:k,dragItems:c,nodeLookup:z});s?.($.sourceEvent,c,B,S),q?.($.sourceEvent,B,S),k||Y?.($.sourceEvent,S)}}const T=oi().clickDistance(M).on("start",$=>{const{domNode:z,nodeDragThreshold:N,transform:O,snapGrid:L,snapToGrid:_}=n();h=z?.getBoundingClientRect()||null,u=!1,x=!1,E=$.sourceEvent,N===0&&A($),o=cr($.sourceEvent,{transform:O,snapGrid:L,snapToGrid:_,containerBounds:h}),d=_t($.sourceEvent,h)}).on("drag",$=>{const{autoPanOnNodeDrag:z,transform:N,snapGrid:O,snapToGrid:L,nodeDragThreshold:_,nodeLookup:I}=n(),P=cr($.sourceEvent,{transform:N,snapGrid:O,snapToGrid:L,containerBounds:h});if(E=$.sourceEvent,($.sourceEvent.type==="touchmove"&&$.sourceEvent.touches.length>1||k&&!I.has(k))&&(u=!0),!u){if(!l&&z&&f&&(l=!0,D()),!f){const q=_t($.sourceEvent,h),Y=q.x-d.x,F=q.y-d.y;Math.sqrt(Y*Y+F*F)>_&&A($)}(o.x!==P.xSnapped||o.y!==P.ySnapped)&&c&&f&&(d=_t($.sourceEvent,h),R(P))}}).on("end",$=>{if(!(!f||u)&&(l=!1,f=!1,cancelAnimationFrame(a),c.size>0)){const{nodeLookup:z,updateNodePositions:N,onNodeDragStop:O,onSelectionDragStop:L}=n();if(x&&(N(c,!1),x=!1),i||O||!k&&L){const[_,I]=Cs({nodeId:k,dragItems:c,nodeLookup:z,dragging:!1});i?.($.sourceEvent,c,_,I),O?.($.sourceEvent,_,I),k||L?.($.sourceEvent,I)}}}).filter($=>{const z=$.target;return!$.button&&(!y||!Jo(z,`.${y}`,b))&&(!g||Jo(z,g,b))});m.call(T)}function v(){m?.on(".drag",null)}return{update:C,destroy:v}}function Qc(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,Xn(o))>0&&r.push(o);return r}const Jc=250;function ed(e,n,s,r){let i=[],o=1/0;const a=Qc(e,s,n+Jc);for(const c of a){const l=[...c.internals.handleBounds?.source??[],...c.internals.handleBounds?.target??[]];for(const d of l){if(r.nodeId===d.nodeId&&r.type===d.type&&r.id===d.id)continue;const{x:h,y:f}=In(c,d,d.position,!0),m=Math.sqrt(Math.pow(h-e.x,2)+Math.pow(f-e.y,2));m>n||(m<o?(i=[{...d,x:h,y:f}],o=m):m===o&&i.push({...d,x:h,y:f}))}}if(!i.length)return null;if(i.length>1){const c=r.type==="source"?"target":"source";return i.find(l=>l.type===c)??i[0]}return i[0]}function Ti(e,n,s,r,i,o=!1){const a=r.get(e);if(!a)return null;const c=i==="strict"?a.internals.handleBounds?.[n]:[...a.internals.handleBounds?.source??[],...a.internals.handleBounds?.target??[]],l=(s?c?.find(d=>d.id===s):c?.[0])??null;return l&&o?{...l,...In(a,l,l.position,!0)}:l}function Ii(e,n){return e||(n?.classList.contains("target")?"target":n?.classList.contains("source")?"source":null)}function td(e,n){let s=null;return n?s=!0:e&&!n&&(s=!1),s}const Ri=()=>!0;function nd(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:E,onConnectEnd:C,isValidConnection:v=Ri,onReconnectEnd:y,updateConnection:g,getTransform:b,getFromHandle:j,autoPanSpeed:k,dragThreshold:M=1,handleDomNode:R}){const D=bi(e.target);let A=0,T;const{x:$,y:z}=_t(e),N=Ii(o,R),O=c?.getBoundingClientRect();let L=!1;if(!O||!N)return;const _=Ti(i,N,r,l,n);if(!_)return;let I=_t(e,O),P=!1,q=null,Y=!1,F=null;function Q(){if(!h||!O)return;const[re,fe]=mi(I,O,k);m({x:re,y:fe}),A=requestAnimationFrame(Q)}const B={..._,nodeId:i,type:N,position:_.position},S=l.get(i);let W={inProgress:!0,isValid:null,from:In(S,B,ve.Left,!0),fromHandle:B,fromPosition:B.position,fromNode:S,to:I,toHandle:null,toPosition:Ho[B.position],toNode:null,pointer:I};function H(){L=!0,g(W),x?.(e,{nodeId:i,handleId:r,handleType:N})}M===0&&H();function K(re){if(!L){const{x:pe,y:ge}=_t(re),U=pe-$,oe=ge-z;if(!(U*U+oe*oe>M*M))return;H()}if(!j()||!B){te(re);return}const fe=b();I=_t(re,O),T=ed(jr(I,fe,!1,[1,1]),s,l,B),P||(Q(),P=!0);const J=_i(re,{handle:T,connectionMode:n,fromNodeId:i,fromHandleId:r,fromType:a?"target":"source",isValidConnection:v,doc:D,lib:d,flowId:f,nodeLookup:l});F=J.handleDomNode,q=J.connection,Y=td(!!T,J.isValid);const Z=l.get(i),ce=Z?In(Z,B,ve.Left,!0):W.from,ae={...W,from:ce,isValid:Y,to:J.toHandle&&Y?ns({x:J.toHandle.x,y:J.toHandle.y},fe):I,toHandle:J.toHandle,toPosition:Y&&J.toHandle?J.toHandle.position:Ho[B.position],toNode:J.toHandle?l.get(J.toHandle.nodeId):null,pointer:I};g(ae),W=ae}function te(re){if(!("touches"in re&&re.touches.length>0)){if(L){(T||F)&&q&&Y&&E?.(q);const{inProgress:fe,...J}=W,Z={...J,toPosition:W.toHandle?W.toPosition:null};C?.(re,Z),o&&y?.(re,Z)}u(),cancelAnimationFrame(A),P=!1,Y=!1,q=null,F=null,D.removeEventListener("mousemove",K),D.removeEventListener("mouseup",te),D.removeEventListener("touchmove",K),D.removeEventListener("touchend",te)}}D.addEventListener("mousemove",K),D.addEventListener("mouseup",te),D.addEventListener("touchmove",K),D.addEventListener("touchend",te)}function _i(e,{handle:n,connectionMode:s,fromNodeId:r,fromHandleId:i,fromType:o,doc:a,lib:c,flowId:l,isValidConnection:d=Ri,nodeLookup:h}){const f=o==="target",m=n?a.querySelector(`.${c}-flow__handle[data-id="${l}-${n?.nodeId}-${n?.id}-${n?.type}"]`):null,{x:u,y:x}=_t(e),E=a.elementFromPoint(u,x),C=E?.classList.contains(`${c}-flow__handle`)?E:m,v={handleDomNode:C,isValid:!1,connection:null,toHandle:null};if(C){const y=Ii(void 0,C),g=C.getAttribute("data-nodeid"),b=C.getAttribute("data-handleid"),j=C.classList.contains("connectable"),k=C.classList.contains("connectableend");if(!g||!y)return v;const M={source:f?g:r,sourceHandle:f?b:i,target:f?r:g,targetHandle:f?i:b};v.connection=M;const D=j&&k&&(s===Gn.Strict?f&&y==="source"||!f&&y==="target":g!==r||b!==i);v.isValid=D&&d(M),v.toHandle=Ti(g,y,b,h,s,!0)}return v}const Hs={onPointerDown:nd,isValid:_i};function rd({domNode:e,panZoom:n,getTransform:s,getViewScale:r}){const i=ht(e);function o({translateExtent:c,width:l,height:d,zoomStep:h=1,pannable:f=!0,zoomable:m=!0,inversePan:u=!1}){const x=g=>{if(g.sourceEvent.type!=="wheel"||!n)return;const b=s(),j=g.sourceEvent.ctrlKey&&gr()?10:1,k=-g.sourceEvent.deltaY*(g.sourceEvent.deltaMode===1?.05:g.sourceEvent.deltaMode?1:.002)*h,M=b[2]*Math.pow(2,k*j);n.scaleTo(M)};let E=[0,0];const C=g=>{(g.sourceEvent.type==="mousedown"||g.sourceEvent.type==="touchstart")&&(E=[g.sourceEvent.clientX??g.sourceEvent.touches[0].clientX,g.sourceEvent.clientY??g.sourceEvent.touches[0].clientY])},v=g=>{const b=s();if(g.sourceEvent.type!=="mousemove"&&g.sourceEvent.type!=="touchmove"||!n)return;const j=[g.sourceEvent.clientX??g.sourceEvent.touches[0].clientX,g.sourceEvent.clientY??g.sourceEvent.touches[0].clientY],k=[j[0]-E[0],j[1]-E[1]];E=j;const M=r()*Math.max(b[2],Math.log(b[2]))*(u?-1:1),R={x:b[0]-k[0]*M,y:b[1]-k[1]*M},D=[[0,0],[l,d]];n.setViewportConstrained({x:R.x,y:R.y,zoom:b[2]},D,c)},y=ai().on("start",C).on("zoom",f?v:null).on("zoom.wheel",m?x:null);i.call(y,{})}function a(){i.on("zoom",null)}return{update:o,destroy:a,pointer:It}}const cs=e=>({x:e.x,y:e.y,zoom:e.k}),Ss=({x:e,y:n,zoom:s})=>Ys.translate(e,n).scale(s),Vn=(e,n)=>e.target.closest(`.${n}`),Li=(e,n)=>n===2&&Array.isArray(e)&&e.includes(2),sd=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Es=(e,n=0,s=sd,r=()=>{})=>{const i=typeof n=="number"&&n>0;return i||r(),i?e.transition().duration(n).ease(s).on("end",r):e},Ai=e=>{const n=e.ctrlKey&&gr()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*n};function od({zoomPanValues:e,noWheelClassName:n,d3Selection:s,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:o,zoomOnPinch:a,onPanZoomStart:c,onPanZoom:l,onPanZoomEnd:d}){return h=>{if(Vn(h,n))return h.ctrlKey&&h.preventDefault(),!1;h.preventDefault(),h.stopImmediatePropagation();const f=s.property("__zoom").k||1;if(h.ctrlKey&&a){const C=It(h),v=Ai(h),y=f*Math.pow(2,v);r.scaleTo(s,y,C,h);return}const m=h.deltaMode===1?20:1;let u=i===Mn.Vertical?0:h.deltaX*m,x=i===Mn.Horizontal?0:h.deltaY*m;!gr()&&h.shiftKey&&i!==Mn.Vertical&&(u=h.deltaY*m,x=0),r.translateBy(s,-(u/f)*o,-(x/f)*o,{internal:!0});const E=cs(s.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(l?.(h,E),e.panScrollTimeout=setTimeout(()=>{d?.(h,E),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,c?.(h,E))}}function ad({noWheelClassName:e,preventScrolling:n,d3ZoomHandler:s}){return function(r,i){const o=r.type==="wheel",a=!n&&o&&!r.ctrlKey,c=Vn(r,e);if(r.ctrlKey&&o&&c&&r.preventDefault(),a||c)return null;r.preventDefault(),s.call(this,r,i)}}function id({zoomPanValues:e,onDraggingChange:n,onPanZoomStart:s}){return r=>{if(r.sourceEvent?.internal)return;const i=cs(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 ld({zoomPanValues:e,panOnDrag:n,onPaneContextMenu:s,onTransformChange:r,onPanZoom:i}){return o=>{e.usedRightMouseButton=!!(s&&Li(n,e.mouseButton??0)),o.sourceEvent?.sync||r([o.transform.x,o.transform.y,o.transform.k]),i&&!o.sourceEvent?.internal&&i?.(o.sourceEvent,cs(o.transform))}}function cd({zoomPanValues:e,panOnDrag:n,panOnScroll:s,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:o}){return a=>{if(!a.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,o&&Li(n,e.mouseButton??0)&&!e.usedRightMouseButton&&a.sourceEvent&&o(a.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){const c=cs(a.transform);e.prevViewport=c,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(a.sourceEvent,c)},s?150:0)}}}function dd({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"&&(Vn(f,`${d}-flow__node`)||Vn(f,`${d}-flow__edge`)))return!0;if(!r&&!m&&!i&&!o&&!s||a||h&&!x||Vn(f,c)&&x||Vn(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 E=Array.isArray(r)&&r.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||x)&&E}}function ud({domNode:e,minZoom:n,maxZoom:s,translateExtent:r,viewport:i,onPanZoom:o,onPanZoomStart:a,onPanZoomEnd:c,onDraggingChange:l}){const d={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},h=e.getBoundingClientRect(),f=ai().scaleExtent([n,s]).translateExtent(r),m=ht(e).call(f);y({x:i.x,y:i.y,zoom:Un(i.zoom,n,s)},[[0,0],[h.width,h.height]],r);const u=m.on("wheel.zoom"),x=m.on("dblclick.zoom");f.wheelDelta(Ai);function E(T,$){return m?new Promise(z=>{f?.interpolate($?.interpolate==="linear"?ks:Zr).transform(Es(m,$?.duration,$?.ease,()=>z(!0)),T)}):Promise.resolve(!1)}function C({noWheelClassName:T,noPanClassName:$,onPaneContextMenu:z,userSelectionActive:N,panOnScroll:O,panOnDrag:L,panOnScrollMode:_,panOnScrollSpeed:I,preventScrolling:P,zoomOnPinch:q,zoomOnScroll:Y,zoomOnDoubleClick:F,zoomActivationKeyPressed:Q,lib:B,onTransformChange:S,connectionInProgress:V,paneClickDistance:W,selectionOnDrag:H}){N&&!d.isZoomingOrPanning&&v();const K=O&&!Q&&!N;f.clickDistance(H?1/0:!Rt(W)||W<0?0:W);const te=K?od({zoomPanValues:d,noWheelClassName:T,d3Selection:m,d3Zoom:f,panOnScrollMode:_,panOnScrollSpeed:I,zoomOnPinch:q,onPanZoomStart:a,onPanZoom:o,onPanZoomEnd:c}):ad({noWheelClassName:T,preventScrolling:P,d3ZoomHandler:u});if(m.on("wheel.zoom",te,{passive:!1}),!N){const fe=id({zoomPanValues:d,onDraggingChange:l,onPanZoomStart:a});f.on("start",fe);const J=ld({zoomPanValues:d,panOnDrag:L,onPaneContextMenu:!!z,onPanZoom:o,onTransformChange:S});f.on("zoom",J);const Z=cd({zoomPanValues:d,panOnDrag:L,panOnScroll:O,onPaneContextMenu:z,onPanZoomEnd:c,onDraggingChange:l});f.on("end",Z)}const re=dd({zoomActivationKeyPressed:Q,panOnDrag:L,zoomOnScroll:Y,panOnScroll:O,zoomOnDoubleClick:F,zoomOnPinch:q,userSelectionActive:N,noPanClassName:$,noWheelClassName:T,lib:B,connectionInProgress:V});f.filter(re),F?m.on("dblclick.zoom",x):m.on("dblclick.zoom",null)}function v(){f.on("zoom",null)}async function y(T,$,z){const N=Ss(T),O=f?.constrain()(N,$,z);return O&&await E(O),new Promise(L=>L(O))}async function g(T,$){const z=Ss(T);return await E(z,$),new Promise(N=>N(z))}function b(T){if(m){const $=Ss(T),z=m.property("__zoom");(z.k!==T.zoom||z.x!==T.x||z.y!==T.y)&&f?.transform(m,$,null,{sync:!0})}}function j(){const T=m?rc(m.node()):{x:0,y:0,k:1};return{x:T.x,y:T.y,zoom:T.k}}function k(T,$){return m?new Promise(z=>{f?.interpolate($?.interpolate==="linear"?ks:Zr).scaleTo(Es(m,$?.duration,$?.ease,()=>z(!0)),T)}):Promise.resolve(!1)}function M(T,$){return m?new Promise(z=>{f?.interpolate($?.interpolate==="linear"?ks:Zr).scaleBy(Es(m,$?.duration,$?.ease,()=>z(!0)),T)}):Promise.resolve(!1)}function R(T){f?.scaleExtent(T)}function D(T){f?.translateExtent(T)}function A(T){const $=!Rt(T)||T<0?0:T;f?.clickDistance($)}return{update:C,destroy:v,setViewport:g,setViewportConstrained:y,getViewport:j,scaleTo:k,scaleBy:M,setScaleExtent:R,setTranslateExtent:D,syncViewport:b,setClickDistance:A}}var Qn;(function(e){e.Line="line",e.Handle="handle"})(Qn||(Qn={}));function fd({width:e,prevWidth:n,height:s,prevHeight:r,affectsX:i,affectsY:o}){const a=e-n,c=s-r,l=[a>0?1:a<0?-1:0,c>0?1:c<0?-1:0];return a&&i&&(l[0]=l[0]*-1),c&&o&&(l[1]=l[1]*-1),l}function ea(e){const n=e.includes("right")||e.includes("left"),s=e.includes("bottom")||e.includes("top"),r=e.includes("left"),i=e.includes("top");return{isHorizontal:n,isVertical:s,affectsX:r,affectsY:i}}function dn(e,n){return Math.max(0,n-e)}function un(e,n){return Math.max(0,e-n)}function Wr(e,n,s){return Math.max(0,n-e,e-s)}function ta(e,n){return e?!n:n}function hd(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:E,maxWidth:C,minHeight:v,maxHeight:y}=r,{x:g,y:b,width:j,height:k,aspectRatio:M}=e;let R=Math.floor(h?u-e.pointerX:0),D=Math.floor(f?x-e.pointerY:0);const A=j+(l?-R:R),T=k+(d?-D:D),$=-o[0]*j,z=-o[1]*k;let N=Wr(A,E,C),O=Wr(T,v,y);if(a){let I=0,P=0;l&&R<0?I=dn(g+R+$,a[0][0]):!l&&R>0&&(I=un(g+A+$,a[1][0])),d&&D<0?P=dn(b+D+z,a[0][1]):!d&&D>0&&(P=un(b+T+z,a[1][1])),N=Math.max(N,I),O=Math.max(O,P)}if(c){let I=0,P=0;l&&R>0?I=un(g+R,c[0][0]):!l&&R<0&&(I=dn(g+A,c[1][0])),d&&D>0?P=un(b+D,c[0][1]):!d&&D<0&&(P=dn(b+T,c[1][1])),N=Math.max(N,I),O=Math.max(O,P)}if(i){if(h){const I=Wr(A/M,v,y)*M;if(N=Math.max(N,I),a){let P=0;!l&&!d||l&&!d&&m?P=un(b+z+A/M,a[1][1])*M:P=dn(b+z+(l?R:-R)/M,a[0][1])*M,N=Math.max(N,P)}if(c){let P=0;!l&&!d||l&&!d&&m?P=dn(b+A/M,c[1][1])*M:P=un(b+(l?R:-R)/M,c[0][1])*M,N=Math.max(N,P)}}if(f){const I=Wr(T*M,E,C)/M;if(O=Math.max(O,I),a){let P=0;!l&&!d||d&&!l&&m?P=un(g+T*M+$,a[1][0])/M:P=dn(g+(d?D:-D)*M+$,a[0][0])/M,O=Math.max(O,P)}if(c){let P=0;!l&&!d||d&&!l&&m?P=dn(g+T*M,c[1][0])/M:P=un(g+(d?D:-D)*M,c[0][0])/M,O=Math.max(O,P)}}}D=D+(D<0?O:-O),R=R+(R<0?N:-N),i&&(m?A>T*M?D=(ta(l,d)?-R:R)/M:R=(ta(l,d)?-D:D)*M:h?(D=R/M,d=l):(R=D*M,l=d));const L=l?g+R:g,_=d?b+D:b;return{width:j+(l?-R:R),height:k+(d?-D:D),x:o[0]*R*(l?-1:1)+L,y:o[1]*D*(d?-1:1)+_}}const Di={width:0,height:0,x:0,y:0},md={...Di,pointerX:0,pointerY:0,aspectRatio:1};function pd(e){return[[0,0],[e.measured.width,e.measured.height]]}function gd(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 xd({domNode:e,nodeId:n,getStoreItems:s,onChange:r,onEnd:i}){const o=ht(e);let a={controlDirection:ea("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function c({controlPosition:d,boundaries:h,keepAspectRatio:f,resizeDirection:m,onResizeStart:u,onResize:x,onResizeEnd:E,shouldResize:C}){let v={...Di},y={...md};a={boundaries:h,resizeDirection:m,keepAspectRatio:f,controlDirection:ea(d)};let g,b=null,j=[],k,M,R,D=!1;const A=oi().on("start",T=>{const{nodeLookup:$,transform:z,snapGrid:N,snapToGrid:O,nodeOrigin:L,paneDomNode:_}=s();if(g=$.get(n),!g)return;b=_?.getBoundingClientRect()??null;const{xSnapped:I,ySnapped:P}=cr(T.sourceEvent,{transform:z,snapGrid:N,snapToGrid:O,containerBounds:b});v={width:g.measured.width??0,height:g.measured.height??0,x:g.position.x??0,y:g.position.y??0},y={...v,pointerX:I,pointerY:P,aspectRatio:v.width/v.height},k=void 0,g.parentId&&(g.extent==="parent"||g.expandParent)&&(k=$.get(g.parentId),M=k&&g.extent==="parent"?pd(k):void 0),j=[],R=void 0;for(const[q,Y]of $)if(Y.parentId===n&&(j.push({id:q,position:{...Y.position},extent:Y.extent}),Y.extent==="parent"||Y.expandParent)){const F=gd(Y,g,Y.origin??L);R?R=[[Math.min(F[0][0],R[0][0]),Math.min(F[0][1],R[0][1])],[Math.max(F[1][0],R[1][0]),Math.max(F[1][1],R[1][1])]]:R=F}u?.(T,{...v})}).on("drag",T=>{const{transform:$,snapGrid:z,snapToGrid:N,nodeOrigin:O}=s(),L=cr(T.sourceEvent,{transform:$,snapGrid:z,snapToGrid:N,containerBounds:b}),_=[];if(!g)return;const{x:I,y:P,width:q,height:Y}=v,F={},Q=g.origin??O,{width:B,height:S,x:V,y:W}=hd(y,a.controlDirection,L,a.boundaries,a.keepAspectRatio,Q,M,R),H=B!==q,K=S!==Y,te=V!==I&&H,re=W!==P&&K;if(!te&&!re&&!H&&!K)return;if((te||re||Q[0]===1||Q[1]===1)&&(F.x=te?V:v.x,F.y=re?W:v.y,v.x=F.x,v.y=F.y,j.length>0)){const ce=V-I,ae=W-P;for(const pe of j)pe.position={x:pe.position.x-ce+Q[0]*(B-q),y:pe.position.y-ae+Q[1]*(S-Y)},_.push(pe)}if((H||K)&&(F.width=H&&(!a.resizeDirection||a.resizeDirection==="horizontal")?B:v.width,F.height=K&&(!a.resizeDirection||a.resizeDirection==="vertical")?S:v.height,v.width=F.width,v.height=F.height),k&&g.expandParent){const ce=Q[0]*(F.width??0);F.x&&F.x<ce&&(v.x=ce,y.x=y.x-(F.x-ce));const ae=Q[1]*(F.height??0);F.y&&F.y<ae&&(v.y=ae,y.y=y.y-(F.y-ae))}const fe=fd({width:v.width,prevWidth:q,height:v.height,prevHeight:Y,affectsX:a.controlDirection.affectsX,affectsY:a.controlDirection.affectsY}),J={...v,direction:fe};C?.(T,J)!==!1&&(D=!0,x?.(T,J),r(F,_))}).on("end",T=>{D&&(E?.(T,{...v}),i?.({...v}),D=!1)});o.call(A)}function l(){o.on(".drag",null)}return{update:c,destroy:l}}var Ms={exports:{}},Ts={};var na;function bd(){if(na)return Ts;na=1;var e=Vl(),n=Wl();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 Ts.useSyncExternalStoreWithSelector=function(d,h,f,m,u){var x=o(null);if(x.current===null){var E={hasValue:!1,value:null};x.current=E}else E=x.current;x=c(function(){function v(k){if(!y){if(y=!0,g=k,k=m(k),u!==void 0&&E.hasValue){var M=E.value;if(u(M,k))return b=M}return b=k}if(M=b,r(g,k))return M;var R=m(k);return u!==void 0&&u(M,R)?(g=k,M):(g=k,b=R)}var y=!1,g,b,j=f===void 0?null:f;return[function(){return v(h())},j===null?void 0:function(){return v(j())}]},[h,f,m,u]);var C=i(d,x[0],x[1]);return a(function(){E.hasValue=!0,E.value=C},[C]),l(C),C},Ts}var ra;function yd(){return ra||(ra=1,Ms.exports=bd()),Ms.exports}var vd=yd();const wd=Fl(vd),kd={},sa=e=>{let n;const s=new Set,r=(h,f)=>{const m=typeof h=="function"?h(n):h;if(!Object.is(m,n)){const u=n;n=f??(typeof m!="object"||m===null)?m:Object.assign({},n,m),s.forEach(x=>x(n,u))}},i=()=>n,l={setState:r,getState:i,getInitialState:()=>d,subscribe:h=>(s.add(h),()=>s.delete(h)),destroy:()=>{(kd?"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},jd=e=>e?sa(e):sa,{useDebugValue:Nd}=Yl,{useSyncExternalStoreWithSelector:Cd}=wd,Sd=e=>e;function Pi(e,n=Sd,s){const r=Cd(e.subscribe,e.getState,e.getServerState||e.getInitialState,n,s);return Nd(r),r}const oa=(e,n)=>{const s=jd(e),r=(i,o=n)=>Pi(s,i,o);return Object.assign(r,s),r},Ed=(e,n)=>e?oa(e,n):oa;function qe(e,n){if(Object.is(e,n))return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;if(e instanceof Map&&n instanceof Map){if(e.size!==n.size)return!1;for(const[r,i]of e)if(!Object.is(i,n.get(r)))return!1;return!0}if(e instanceof Set&&n instanceof Set){if(e.size!==n.size)return!1;for(const r of e)if(!n.has(r))return!1;return!0}const s=Object.keys(e);if(s.length!==Object.keys(n).length)return!1;for(const r of s)if(!Object.prototype.hasOwnProperty.call(n,r)||!Object.is(e[r],n[r]))return!1;return!0}const ds=p.createContext(null),Md=ds.Provider,$i=Wt.error001();function _e(e,n){const s=p.useContext(ds);if(s===null)throw new Error($i);return Pi(s,e,n)}function Oe(){const e=p.useContext(ds);if(e===null)throw new Error($i);return p.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const aa={display:"none"},Td={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Bi="react-flow__node-desc",Oi="react-flow__edge-desc",Id="react-flow__aria-live",Rd=e=>e.ariaLiveMessage,_d=e=>e.ariaLabelConfig;function Ld({rfId:e}){const n=_e(Rd);return t.jsx("div",{id:`${Id}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Td,children:n})}function Ad({rfId:e,disableKeyboardA11y:n}){const s=_e(_d);return t.jsxs(t.Fragment,{children:[t.jsx("div",{id:`${Bi}-${e}`,style:aa,children:n?s["node.a11yDescription.default"]:s["node.a11yDescription.keyboardDisabled"]}),t.jsx("div",{id:`${Oi}-${e}`,style:aa,children:s["edge.a11yDescription.default"]}),!n&&t.jsx(Ld,{rfId:e})]})}const us=p.forwardRef(({position:e="top-left",children:n,className:s,style:r,...i},o)=>{const a=`${e}`.split("-");return t.jsx("div",{className:Ye(["react-flow__panel",s,...a]),style:r,ref:o,...i,children:n})});us.displayName="Panel";function Dd({proOptions:e,position:n="bottom-right"}){return e?.hideAttribution?null:t.jsx(us,{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 Pd=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}},Fr=e=>e.id;function $d(e,n){return qe(e.selectedNodes.map(Fr),n.selectedNodes.map(Fr))&&qe(e.selectedEdges.map(Fr),n.selectedEdges.map(Fr))}function Bd({onSelectionChange:e}){const n=Oe(),{selectedNodes:s,selectedEdges:r}=_e(Pd,$d);return p.useEffect(()=>{const i={nodes:s,edges:r};e?.(i),n.getState().onSelectionChangeHandlers.forEach(o=>o(i))},[s,r,e]),null}const Od=e=>!!e.onSelectionChangeHandlers;function zd({onSelectionChange:e}){const n=_e(Od);return e||n?t.jsx(Bd,{onSelectionChange:e}):null}const zi=[0,0],Hd={x:0,y:0,zoom:1},qd=["nodes","edges","defaultNodes","defaultEdges","onConnect","onConnectStart","onConnectEnd","onClickConnectStart","onClickConnectEnd","nodesDraggable","autoPanOnNodeFocus","nodesConnectable","nodesFocusable","edgesFocusable","edgesReconnectable","elevateNodesOnSelect","elevateEdgesOnSelect","minZoom","maxZoom","nodeExtent","onNodesChange","onEdgesChange","elementsSelectable","connectionMode","snapGrid","snapToGrid","translateExtent","connectOnClick","defaultEdgeOptions","fitView","fitViewOptions","onNodesDelete","onEdgesDelete","onDelete","onNodeDrag","onNodeDragStart","onNodeDragStop","onSelectionDrag","onSelectionDragStart","onSelectionDragStop","onMoveStart","onMove","onMoveEnd","noPanClassName","nodeOrigin","autoPanOnConnect","autoPanOnNodeDrag","onError","connectionRadius","isValidConnection","selectNodesOnDrag","nodeDragThreshold","connectionDragThreshold","onBeforeDelete","debug","autoPanSpeed","ariaLabelConfig","zIndexMode"],ia=[...qd,"rfId"],Vd=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),la={translateExtent:hr,nodeOrigin:zi,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function Wd(e){const{setNodes:n,setEdges:s,setMinZoom:r,setMaxZoom:i,setTranslateExtent:o,setNodeExtent:a,reset:c,setDefaultNodesAndEdges:l}=_e(Vd,qe),d=Oe();p.useEffect(()=>(l(e.defaultNodes,e.defaultEdges),()=>{h.current=la,c()}),[]);const h=p.useRef(la);return p.useEffect(()=>{for(const f of ia){const m=e[f],u=h.current[f];m!==u&&(typeof e[f]>"u"||(f==="nodes"?n(m):f==="edges"?s(m):f==="minZoom"?r(m):f==="maxZoom"?i(m):f==="translateExtent"?o(m):f==="nodeExtent"?a(m):f==="ariaLabelConfig"?d.setState({ariaLabelConfig:Tc(m)}):f==="fitView"?d.setState({fitViewQueued:m}):f==="fitViewOptions"?d.setState({fitViewOptions:m}):d.setState({[f]:m})))}h.current=e},ia.map(f=>e[f])),null}function ca(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function Fd(e){const[n,s]=p.useState(e==="system"?null:e);return p.useEffect(()=>{if(e!=="system"){s(e);return}const r=ca(),i=()=>s(r?.matches?"dark":"light");return i(),r?.addEventListener("change",i),()=>{r?.removeEventListener("change",i)}},[e]),n!==null?n:ca()?.matches?"dark":"light"}const da=typeof document<"u"?document:null;function xr(e=null,n={target:da,actInsideInputWithModifier:!0}){const[s,r]=p.useState(!1),i=p.useRef(!1),o=p.useRef(new Set([])),[a,c]=p.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 p.useEffect(()=>{const l=n?.target??da,d=n?.actInsideInputWithModifier??!0;if(e!==null){const h=u=>{if(i.current=u.ctrlKey||u.metaKey||u.shiftKey||u.altKey,(!i.current||i.current&&!d)&&yi(u))return!1;const E=fa(u.code,c);if(o.current.add(u[E]),ua(a,o.current,!1)){const C=u.composedPath?.()?.[0]||u.target,v=C?.nodeName==="BUTTON"||C?.nodeName==="A";n.preventDefault!==!1&&(i.current||!v)&&u.preventDefault(),r(!0)}},f=u=>{const x=fa(u.code,c);ua(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 ua(e,n,s){return e.filter(r=>s||r.length===n.size).some(r=>r.every(i=>n.has(i)))}function fa(e,n){return n.includes(e)?"code":"key"}const Yd=()=>{const e=Oe();return p.useMemo(()=>({zoomIn:n=>{const{panZoom:s}=e.getState();return s?s.scaleBy(1.2,{duration:n?.duration}):Promise.resolve(!1)},zoomOut:n=>{const{panZoom:s}=e.getState();return s?s.scaleBy(1/1.2,{duration:n?.duration}):Promise.resolve(!1)},zoomTo:(n,s)=>{const{panZoom:r}=e.getState();return r?r.scaleTo(n,{duration:s?.duration}):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(n,s)=>{const{transform:[r,i,o],panZoom:a}=e.getState();return a?(await a.setViewport({x:n.x??r,y:n.y??i,zoom:n.zoom??o},s),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[n,s,r]=e.getState().transform;return{x:n,y:s,zoom:r}},setCenter:async(n,s,r)=>e.getState().setCenter(n,s,r),fitBounds:async(n,s)=>{const{width:r,height:i,minZoom:o,maxZoom:a,panZoom:c}=e.getState(),l=Us(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 jr(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=ns(n,s);return{x:a.x+i,y:a.y+o}}}),[])};function Hi(e,n){const s=[],r=new Map,i=[];for(const o of e)if(o.type==="add"){i.push(o);continue}else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const a=r.get(o.id);a?a.push(o):r.set(o.id,[o])}for(const o of n){const a=r.get(o.id);if(!a){s.push(o);continue}if(a[0].type==="remove")continue;if(a[0].type==="replace"){s.push({...a[0].item});continue}const c={...o};for(const l of a)Gd(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 Gd(e,n){switch(e.type){case"select":{n.selected=e.selected;break}case"position":{typeof e.position<"u"&&(n.position=e.position),typeof e.dragging<"u"&&(n.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(n.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(n.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(n.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(n.resizing=e.resizing);break}}}function qi(e,n){return Hi(e,n)}function Vi(e,n){return Hi(e,n)}function En(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(En(o.id,a)))}return r}function ha({items:e=[],lookup:n}){const s=[],r=new Map(e.map(i=>[i.id,i]));for(const[i,o]of e.entries()){const a=n.get(o.id),c=a?.internals?.userNode??a;c!==void 0&&c!==o&&s.push({id:o.id,item:o,type:"replace"}),c===void 0&&s.push({item:o,type:"add",index:i})}for(const[i]of n)r.get(i)===void 0&&s.push({id:i,type:"remove"});return s}function ma(e){return{id:e.id,type:"remove"}}const pa=e=>yc(e),Kd=e=>ui(e);function Wi(e){return p.forwardRef(e)}const Ud=typeof window<"u"?p.useLayoutEffect:p.useEffect;function ga(e){const[n,s]=p.useState(BigInt(0)),[r]=p.useState(()=>Xd(()=>s(i=>i+BigInt(1))));return Ud(()=>{const i=r.get();i.length&&(e(i),r.reset())},[n]),r}function Xd(e){let n=[];return{get:()=>n,reset:()=>{n=[]},push:s=>{n.push(s),e()}}}const Fi=p.createContext(null);function Zd({children:e}){const n=Oe(),s=p.useCallback(c=>{const{nodes:l=[],setNodes:d,hasDefaultNodes:h,onNodesChange:f,nodeLookup:m,fitViewQueued:u,onNodesChangeMiddlewareMap:x}=n.getState();let E=l;for(const v of c)E=typeof v=="function"?v(E):v;let C=ha({items:E,lookup:m});for(const v of x.values())C=v(C);h&&d(E),C.length>0?f?.(C):u&&window.requestAnimationFrame(()=>{const{fitViewQueued:v,nodes:y,setNodes:g}=n.getState();v&&g(y)})},[]),r=ga(s),i=p.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(ha({items:u,lookup:m}))},[]),o=ga(i),a=p.useMemo(()=>({nodeQueue:r,edgeQueue:o}),[]);return t.jsx(Fi.Provider,{value:a,children:e})}function Qd(){const e=p.useContext(Fi);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const Jd=e=>!!e.panZoom;function no(){const e=Yd(),n=Oe(),s=Qd(),r=_e(Jd),i=p.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=pa(f)?f:m.get(f.id),E=x.parentId?xi(x.position,x.measured,x.parentId,m,u):x.position,C={...x,position:E,width:x.measured?.width??x.width,height:x.measured?.height??x.height};return Xn(C)},d=(f,m,u={replace:!1})=>{a(x=>x.map(E=>{if(E.id===f){const C=typeof m=="function"?m(E):m;return u.replace&&pa(C)?C:{...E,...C}}return E}))},h=(f,m,u={replace:!1})=>{c(x=>x.map(E=>{if(E.id===f){const C=typeof m=="function"?m(E):m;return u.replace&&Kd(C)?C:{...E,...C}}return E}))};return{getNodes:()=>n.getState().nodes.map(f=>({...f})),getNode:f=>o(f)?.internals.userNode,getInternalNode:o,getEdges:()=>{const{edges:f=[]}=n.getState();return f.map(m=>({...m}))},getEdge:f=>n.getState().edgeLookup.get(f),setNodes:a,setEdges:c,addNodes:f=>{const m=Array.isArray(f)?f:[f];s.nodeQueue.push(u=>[...u,...m])},addEdges:f=>{const m=Array.isArray(f)?f:[f];s.edgeQueue.push(u=>[...u,...m])},toObject:()=>{const{nodes:f=[],edges:m=[],transform:u}=n.getState(),[x,E,C]=u;return{nodes:f.map(v=>({...v})),edges:m.map(v=>({...v})),viewport:{x,y:E,zoom:C}}},deleteElements:async({nodes:f=[],edges:m=[]})=>{const{nodes:u,edges:x,onNodesDelete:E,onEdgesDelete:C,triggerNodeChanges:v,triggerEdgeChanges:y,onDelete:g,onBeforeDelete:b}=n.getState(),{nodes:j,edges:k}=await Nc({nodesToRemove:f,edgesToRemove:m,nodes:u,edges:x,onBeforeDelete:b}),M=k.length>0,R=j.length>0;if(M){const D=k.map(ma);C?.(k),y(D)}if(R){const D=j.map(ma);E?.(j),v(D)}return(R||M)&&g?.({nodes:j,edges:k}),{deletedNodes:j,deletedEdges:k}},getIntersectingNodes:(f,m=!0,u)=>{const x=Vo(f),E=x?f:l(f),C=u!==void 0;return E?(u||n.getState().nodes).filter(v=>{const y=n.getState().nodeLookup.get(v.id);if(y&&!x&&(v.id===f.id||!y.internals.positionAbsolute))return!1;const g=Xn(C?v:y),b=pr(g,E);return m&&b>0||b>=g.width*g.height||b>=E.width*E.height}):[]},isNodeIntersecting:(f,m,u=!0)=>{const E=Vo(f)?f:l(f);if(!E)return!1;const C=pr(E,m);return u&&C>0||C>=m.width*m.height||C>=E.width*E.height},updateNode:d,updateNodeData:(f,m,u={replace:!1})=>{d(f,x=>{const E=typeof m=="function"?m(x):m;return u.replace?{...x,data:E}:{...x,data:{...x.data,...E}}},u)},updateEdge:h,updateEdgeData:(f,m,u={replace:!1})=>{h(f,x=>{const E=typeof m=="function"?m(x):m;return u.replace?{...x,data:E}:{...x,data:{...x.data,...E}}},u)},getNodesBounds:f=>{const{nodeLookup:m,nodeOrigin:u}=n.getState();return vc(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??Mc();return n.setState({fitViewQueued:!0,fitViewOptions:f,fitViewResolver:m}),s.nodeQueue.push(u=>[...u]),m.promise}}},[]);return p.useMemo(()=>({...i,...e,viewportInitialized:r}),[r])}const xa=e=>e.selected,eu=typeof window<"u"?window:void 0;function tu({deleteKeyCode:e,multiSelectionKeyCode:n}){const s=Oe(),{deleteElements:r}=no(),i=xr(e,{actInsideInputWithModifier:!1}),o=xr(n,{target:eu});p.useEffect(()=>{if(i){const{edges:a,nodes:c}=s.getState();r({nodes:c.filter(xa),edges:a.filter(xa)}),s.setState({nodesSelectionActive:!1})}},[i]),p.useEffect(()=>{s.setState({multiSelectionActive:o})},[o])}function nu(e){const n=Oe();p.useEffect(()=>{const s=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const r=Xs(e.current);(r.height===0||r.width===0)&&n.getState().onError?.("004",Wt.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 fs={position:"absolute",width:"100%",height:"100%",top:0,left:0},ru=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function su({onPaneContextMenu:e,zoomOnScroll:n=!0,zoomOnPinch:s=!0,panOnScroll:r=!1,panOnScrollSpeed:i=.5,panOnScrollMode:o=Mn.Free,zoomOnDoubleClick:a=!0,panOnDrag:c=!0,defaultViewport:l,translateExtent:d,minZoom:h,maxZoom:f,zoomActivationKeyCode:m,preventScrolling:u=!0,children:x,noWheelClassName:E,noPanClassName:C,onViewportChange:v,isControlledViewport:y,paneClickDistance:g,selectionOnDrag:b}){const j=Oe(),k=p.useRef(null),{userSelectionActive:M,lib:R,connectionInProgress:D}=_e(ru,qe),A=xr(m),T=p.useRef();nu(k);const $=p.useCallback(z=>{v?.({x:z[0],y:z[1],zoom:z[2]}),y||j.setState({transform:z})},[v,y]);return p.useEffect(()=>{if(k.current){T.current=ud({domNode:k.current,minZoom:h,maxZoom:f,translateExtent:d,viewport:l,onDraggingChange:L=>j.setState(_=>_.paneDragging===L?_:{paneDragging:L}),onPanZoomStart:(L,_)=>{const{onViewportChangeStart:I,onMoveStart:P}=j.getState();P?.(L,_),I?.(_)},onPanZoom:(L,_)=>{const{onViewportChange:I,onMove:P}=j.getState();P?.(L,_),I?.(_)},onPanZoomEnd:(L,_)=>{const{onViewportChangeEnd:I,onMoveEnd:P}=j.getState();P?.(L,_),I?.(_)}});const{x:z,y:N,zoom:O}=T.current.getViewport();return j.setState({panZoom:T.current,transform:[z,N,O],domNode:k.current.closest(".react-flow")}),()=>{T.current?.destroy()}}},[]),p.useEffect(()=>{T.current?.update({onPaneContextMenu:e,zoomOnScroll:n,zoomOnPinch:s,panOnScroll:r,panOnScrollSpeed:i,panOnScrollMode:o,zoomOnDoubleClick:a,panOnDrag:c,zoomActivationKeyPressed:A,preventScrolling:u,noPanClassName:C,userSelectionActive:M,noWheelClassName:E,lib:R,onTransformChange:$,connectionInProgress:D,selectionOnDrag:b,paneClickDistance:g})},[e,n,s,r,i,o,a,c,A,u,C,M,E,R,$,D,b,g]),t.jsx("div",{className:"react-flow__renderer",ref:k,style:fs,children:x})}const ou=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function au(){const{userSelectionActive:e,userSelectionRect:n}=_e(ou,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 Is=(e,n)=>s=>{s.target===n.current&&e?.(s)},iu=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function lu({isSelecting:e,selectionKeyPressed:n,selectionMode:s=mr.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 E=Oe(),{userSelectionActive:C,elementsSelectable:v,dragging:y,connectionInProgress:g}=_e(iu,qe),b=v&&(e||C),j=p.useRef(null),k=p.useRef(),M=p.useRef(new Set),R=p.useRef(new Set),D=p.useRef(!1),A=I=>{if(D.current||g){D.current=!1;return}l?.(I),E.getState().resetSelectedElements(),E.setState({nodesSelectionActive:!1})},T=I=>{if(Array.isArray(r)&&r?.includes(2)){I.preventDefault();return}d?.(I)},$=h?I=>h(I):void 0,z=I=>{D.current&&(I.stopPropagation(),D.current=!1)},N=I=>{const{domNode:P}=E.getState();if(k.current=P?.getBoundingClientRect(),!k.current)return;const q=I.target===j.current;if(!q&&!!I.target.closest(".nokey")||!e||!(o&&q||n)||I.button!==0||!I.isPrimary)return;I.target?.setPointerCapture?.(I.pointerId),D.current=!1;const{x:Q,y:B}=_t(I.nativeEvent,k.current);E.setState({userSelectionRect:{width:0,height:0,startX:Q,startY:B,x:Q,y:B}}),q||(I.stopPropagation(),I.preventDefault())},O=I=>{const{userSelectionRect:P,transform:q,nodeLookup:Y,edgeLookup:F,connectionLookup:Q,triggerNodeChanges:B,triggerEdgeChanges:S,defaultEdgeOptions:V,resetSelectedElements:W}=E.getState();if(!k.current||!P)return;const{x:H,y:K}=_t(I.nativeEvent,k.current),{startX:te,startY:re}=P;if(!D.current){const ae=n?0:i;if(Math.hypot(H-te,K-re)<=ae)return;W(),a?.(I)}D.current=!0;const fe={startX:te,startY:re,x:H<te?H:te,y:K<re?K:re,width:Math.abs(H-te),height:Math.abs(K-re)},J=M.current,Z=R.current;M.current=new Set(Ks(Y,fe,q,s===mr.Partial,!0).map(ae=>ae.id)),R.current=new Set;const ce=V?.selectable??!0;for(const ae of M.current){const pe=Q.get(ae);if(pe)for(const{edgeId:ge}of pe.values()){const U=F.get(ge);U&&(U.selectable??ce)&&R.current.add(ge)}}if(!Wo(J,M.current)){const ae=Wn(Y,M.current,!0);B(ae)}if(!Wo(Z,R.current)){const ae=Wn(F,R.current);S(ae)}E.setState({userSelectionRect:fe,userSelectionActive:!0,nodesSelectionActive:!1})},L=I=>{I.button===0&&(I.target?.releasePointerCapture?.(I.pointerId),!C&&I.target===j.current&&E.getState().userSelectionRect&&A?.(I),E.setState({userSelectionActive:!1,userSelectionRect:null}),D.current&&(c?.(I),E.setState({nodesSelectionActive:M.current.size>0})))},_=r===!0||Array.isArray(r)&&r.includes(0);return t.jsxs("div",{className:Ye(["react-flow__pane",{draggable:_,dragging:y,selection:e}]),onClick:b?void 0:Is(A,j),onContextMenu:Is(T,j),onWheel:Is($,j),onPointerEnter:b?void 0:f,onPointerMove:b?O:m,onPointerUp:b?L:void 0,onPointerDownCapture:b?N:void 0,onClickCapture:b?z:void 0,onPointerLeave:u,ref:j,style:fs,children:[x,t.jsx(au,{})]})}function qs({id:e,store:n,unselect:s=!1,nodeRef:r}){const{addSelectedNodes:i,unselectNodesAndEdges:o,multiSelectionActive:a,nodeLookup:c,onError:l}=n.getState(),d=c.get(e);if(!d){l?.("012",Wt.error012(e));return}n.setState({nodesSelectionActive:!1}),d.selected?(s||d.selected&&a)&&(o({nodes:[d],edges:[]}),requestAnimationFrame(()=>r?.current?.blur())):i([e])}function Yi({nodeRef:e,disabled:n=!1,noDragClassName:s,handleSelector:r,nodeId:i,isSelectable:o,nodeClickDistance:a}){const c=Oe(),[l,d]=p.useState(!1),h=p.useRef();return p.useEffect(()=>{h.current=Zc({getStoreItems:()=>c.getState(),onNodeMouseDown:f=>{qs({id:f,store:c,nodeRef:e})},onDragStart:()=>{d(!0)},onDragStop:()=>{d(!1)}})},[]),p.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 cu=e=>n=>n.selected&&(n.draggable||e&&typeof n.draggable>"u");function Gi(){const e=Oe();return p.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=cu(a),u=i?o[0]:5,x=i?o[1]:5,E=s.direction.x*u*s.factor,C=s.direction.y*x*s.factor;for(const[,v]of d){if(!m(v))continue;let y={x:v.internals.positionAbsolute.x+E,y:v.internals.positionAbsolute.y+C};i&&(y=kr(y,o));const{position:g,positionAbsolute:b}=fi({nodeId:v.id,nextPosition:y,nodeLookup:d,nodeExtent:r,nodeOrigin:h,onError:c});v.position=g,v.internals.positionAbsolute=b,f.set(v.id,v)}l(f)},[])}const ro=p.createContext(null),du=ro.Provider;ro.Consumer;const Ki=()=>p.useContext(ro),uu=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),fu=(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===Gn.Strict?c?.type!==s:e!==c?.nodeId||n!==c?.id,connectionInProcess:!!c,clickConnectionInProcess:!!i,valid:h&&d}};function hu({type:e="source",position:n=ve.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,E=e==="target",C=Oe(),v=Ki(),{connectOnClick:y,noPanClassName:g,rfId:b}=_e(uu,qe),{connectingFrom:j,connectingTo:k,clickConnecting:M,isPossibleEndHandle:R,connectionInProcess:D,clickConnectionInProcess:A,valid:T}=_e(fu(v,x,e),qe);v||C.getState().onError?.("010",Wt.error010());const $=O=>{const{defaultEdgeOptions:L,onConnect:_,hasDefaultEdges:I}=C.getState(),P={...L,...O};if(I){const{edges:q,setEdges:Y}=C.getState();Y(Dc(P,q))}_?.(P),c?.(P)},z=O=>{if(!v)return;const L=vi(O.nativeEvent);if(i&&(L&&O.button===0||!L)){const _=C.getState();Hs.onPointerDown(O.nativeEvent,{handleDomNode:O.currentTarget,autoPanOnConnect:_.autoPanOnConnect,connectionMode:_.connectionMode,connectionRadius:_.connectionRadius,domNode:_.domNode,nodeLookup:_.nodeLookup,lib:_.lib,isTarget:E,handleId:x,nodeId:v,flowId:_.rfId,panBy:_.panBy,cancelConnection:_.cancelConnection,onConnectStart:_.onConnectStart,onConnectEnd:(...I)=>C.getState().onConnectEnd?.(...I),updateConnection:_.updateConnection,onConnect:$,isValidConnection:s||((...I)=>C.getState().isValidConnection?.(...I)??!0),getTransform:()=>C.getState().transform,getFromHandle:()=>C.getState().connection.fromHandle,autoPanSpeed:_.autoPanSpeed,dragThreshold:_.connectionDragThreshold})}L?h?.(O):f?.(O)},N=O=>{const{onClickConnectStart:L,onClickConnectEnd:_,connectionClickStartHandle:I,connectionMode:P,isValidConnection:q,lib:Y,rfId:F,nodeLookup:Q,connection:B}=C.getState();if(!v||!I&&!i)return;if(!I){L?.(O.nativeEvent,{nodeId:v,handleId:x,handleType:e}),C.setState({connectionClickStartHandle:{nodeId:v,type:e,id:x}});return}const S=bi(O.target),V=s||q,{connection:W,isValid:H}=Hs.isValid(O.nativeEvent,{handle:{nodeId:v,id:x,type:e},connectionMode:P,fromNodeId:I.nodeId,fromHandleId:I.id||null,fromType:I.type,isValidConnection:V,flowId:F,doc:S,lib:Y,nodeLookup:Q});H&&W&&$(W);const K=structuredClone(B);delete K.inProgress,K.toPosition=K.toHandle?K.toHandle.position:null,_?.(O,K),C.setState({connectionClickStartHandle:null})};return t.jsx("div",{"data-handleid":x,"data-nodeid":v,"data-handlepos":n,"data-id":`${b}-${v}-${x}-${e}`,className:Ye(["react-flow__handle",`react-flow__handle-${n}`,"nodrag",g,d,{source:!E,target:E,connectable:r,connectablestart:i,connectableend:o,clickconnecting:M,connectingfrom:j,connectingto:k,valid:T,connectionindicator:r&&(!D||R)&&(D||A?o:i)}]),onMouseDown:z,onTouchStart:z,onClick:y?N:void 0,ref:u,...m,children:l})}const mn=p.memo(Wi(hu));function mu({data:e,isConnectable:n,sourcePosition:s=ve.Bottom}){return t.jsxs(t.Fragment,{children:[e?.label,t.jsx(mn,{type:"source",position:s,isConnectable:n})]})}function pu({data:e,isConnectable:n,targetPosition:s=ve.Top,sourcePosition:r=ve.Bottom}){return t.jsxs(t.Fragment,{children:[t.jsx(mn,{type:"target",position:s,isConnectable:n}),e?.label,t.jsx(mn,{type:"source",position:r,isConnectable:n})]})}function gu(){return null}function xu({data:e,isConnectable:n,targetPosition:s=ve.Top}){return t.jsxs(t.Fragment,{children:[t.jsx(mn,{type:"target",position:s,isConnectable:n}),e?.label]})}const rs={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},ba={input:mu,default:pu,output:xu,group:gu};function bu(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 yu=e=>{const{width:n,height:s,x:r,y:i}=wr(e.nodeLookup,{filter:o=>!!o.selected});return{width:Rt(n)?n:null,height:Rt(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 vu({onSelectionContextMenu:e,noPanClassName:n,disableKeyboardA11y:s}){const r=Oe(),{width:i,height:o,transformString:a,userSelectionActive:c}=_e(yu,qe),l=Gi(),d=p.useRef(null);p.useEffect(()=>{s||d.current?.focus({preventScroll:!0})},[s]);const h=!c&&i!==null&&o!==null;if(Yi({nodeRef:d,disabled:!h}),!h)return null;const f=e?u=>{const x=r.getState().nodes.filter(E=>E.selected);e(u,x)}:void 0,m=u=>{Object.prototype.hasOwnProperty.call(rs,u.key)&&(u.preventDefault(),l({direction:rs[u.key],factor:u.shiftKey?4:1}))};return t.jsx("div",{className:Ye(["react-flow__nodesselection","react-flow__container",n]),style:{transform:a},children:t.jsx("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:f,tabIndex:s?void 0:-1,onKeyDown:s?void 0:m,style:{width:i,height:o}})})}const ya=typeof window<"u"?window:void 0,wu=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Ui({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:E,zoomActivationKeyCode:C,elementsSelectable:v,zoomOnScroll:y,zoomOnPinch:g,panOnScroll:b,panOnScrollSpeed:j,panOnScrollMode:k,zoomOnDoubleClick:M,panOnDrag:R,defaultViewport:D,translateExtent:A,minZoom:T,maxZoom:$,preventScrolling:z,onSelectionContextMenu:N,noWheelClassName:O,noPanClassName:L,disableKeyboardA11y:_,onViewportChange:I,isControlledViewport:P}){const{nodesSelectionActive:q,userSelectionActive:Y}=_e(wu,qe),F=xr(d,{target:ya}),Q=xr(E,{target:ya}),B=Q||R,S=Q||b,V=h&&B!==!0,W=F||Y||V;return tu({deleteKeyCode:l,multiSelectionKeyCode:x}),t.jsx(su,{onPaneContextMenu:o,elementsSelectable:v,zoomOnScroll:y,zoomOnPinch:g,panOnScroll:S,panOnScrollSpeed:j,panOnScrollMode:k,zoomOnDoubleClick:M,panOnDrag:!F&&B,defaultViewport:D,translateExtent:A,minZoom:T,maxZoom:$,zoomActivationKeyCode:C,preventScrolling:z,noWheelClassName:O,noPanClassName:L,onViewportChange:I,isControlledViewport:P,paneClickDistance:c,selectionOnDrag:V,children:t.jsxs(lu,{onSelectionStart:m,onSelectionEnd:u,onPaneClick:n,onPaneMouseEnter:s,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:o,onPaneScroll:a,panOnDrag:B,isSelecting:!!W,selectionMode:f,selectionKeyPressed:F,paneClickDistance:c,selectionOnDrag:V,children:[e,q&&t.jsx(vu,{onSelectionContextMenu:N,noPanClassName:L,disableKeyboardA11y:_})]})})}Ui.displayName="FlowRenderer";const ku=p.memo(Ui),ju=e=>n=>e?Ks(n.nodeLookup,{x:0,y:0,width:n.width,height:n.height},n.transform,!0).map(s=>s.id):Array.from(n.nodeLookup.keys());function Nu(e){return _e(p.useCallback(ju(e),[e]),qe)}const Cu=e=>e.updateNodeInternals;function Su(){const e=_e(Cu),[n]=p.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(s=>{const r=new Map;s.forEach(i=>{const o=i.target.getAttribute("data-id");r.set(o,{id:o,nodeElement:i.target,force:!0})}),e(r)}));return p.useEffect(()=>()=>{n?.disconnect()},[n]),n}function Eu({node:e,nodeType:n,hasDimensions:s,resizeObserver:r}){const i=Oe(),o=p.useRef(null),a=p.useRef(null),c=p.useRef(e.sourcePosition),l=p.useRef(e.targetPosition),d=p.useRef(n),h=s&&!!e.internals.handleBounds;return p.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]),p.useEffect(()=>()=>{a.current&&(r?.unobserve(a.current),a.current=null)},[]),p.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 Mu({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:E,nodeTypes:C,nodeClickDistance:v,onError:y}){const{node:g,internals:b,isParent:j}=_e(H=>{const K=H.nodeLookup.get(e),te=H.parentLookup.has(e);return{node:K,internals:K.internals,isParent:te}},qe);let k=g.type||"default",M=C?.[k]||ba[k];M===void 0&&(y?.("003",Wt.error003(k)),k="default",M=C?.default||ba.default);const R=!!(g.draggable||c&&typeof g.draggable>"u"),D=!!(g.selectable||l&&typeof g.selectable>"u"),A=!!(g.connectable||d&&typeof g.connectable>"u"),T=!!(g.focusable||h&&typeof g.focusable>"u"),$=Oe(),z=gi(g),N=Eu({node:g,nodeType:k,hasDimensions:z,resizeObserver:f}),O=Yi({nodeRef:N,disabled:g.hidden||!R,noDragClassName:m,handleSelector:g.dragHandle,nodeId:e,isSelectable:D,nodeClickDistance:v}),L=Gi();if(g.hidden)return null;const _=rn(g),I=bu(g),P=D||R||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,B=a?H=>a(H,{...b.userNode}):void 0,S=H=>{const{selectNodesOnDrag:K,nodeDragThreshold:te}=$.getState();D&&(!K||!R||te>0)&&qs({id:e,store:$,nodeRef:N}),n&&n(H,{...b.userNode})},V=H=>{if(!(yi(H.nativeEvent)||x)){if(ii.includes(H.key)&&D){const K=H.key==="Escape";qs({id:e,store:$,unselect:K,nodeRef:N})}else if(R&&g.selected&&Object.prototype.hasOwnProperty.call(rs,H.key)){H.preventDefault();const{ariaLabelConfig:K}=$.getState();$.setState({ariaLiveMessage:K["node.a11yDescription.ariaLiveMessage"]({direction:H.key.replace("Arrow","").toLowerCase(),x:~~b.positionAbsolute.x,y:~~b.positionAbsolute.y})}),L({direction:rs[H.key],factor:H.shiftKey?4:1})}}},W=()=>{if(x||!N.current?.matches(":focus-visible"))return;const{transform:H,width:K,height:te,autoPanOnNodeFocus:re,setCenter:fe}=$.getState();if(!re)return;Ks(new Map([[e,g]]),{x:0,y:0,width:K,height:te},H,!0).length>0||fe(g.position.x+_.width/2,g.position.y+_.height/2,{zoom:H[2]})};return t.jsx("div",{className:Ye(["react-flow__node",`react-flow__node-${k}`,{[u]:R},g.className,{selected:g.selected,selectable:D,parent:j,draggable:R,dragging:O}]),ref:N,style:{zIndex:b.z,transform:`translate(${b.positionAbsolute.x}px,${b.positionAbsolute.y}px)`,pointerEvents:P?"all":"none",visibility:z?"visible":"hidden",...g.style,...I},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:q,onMouseMove:Y,onMouseLeave:F,onContextMenu:Q,onClick:S,onDoubleClick:B,onKeyDown:T?V:void 0,tabIndex:T?0:void 0,onFocus:T?W:void 0,role:g.ariaRole??(T?"group":void 0),"aria-roledescription":"node","aria-describedby":x?void 0:`${Bi}-${E}`,"aria-label":g.ariaLabel,...g.domAttributes,children:t.jsx(du,{value:e,children:t.jsx(M,{id:e,data:g.data,type:k,positionAbsoluteX:b.positionAbsolute.x,positionAbsoluteY:b.positionAbsolute.y,selected:g.selected??!1,selectable:D,draggable:R,deletable:g.deletable??!0,isConnectable:A,sourcePosition:g.sourcePosition,targetPosition:g.targetPosition,dragging:O,dragHandle:g.dragHandle,zIndex:b.z,parentId:g.parentId,..._})})})}var Tu=p.memo(Mu);const Iu=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function Xi(e){const{nodesDraggable:n,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,onError:o}=_e(Iu,qe),a=Nu(e.onlyRenderVisibleElements),c=Su();return t.jsx("div",{className:"react-flow__nodes",style:fs,children:a.map(l=>t.jsx(Tu,{id:l,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:c,nodesDraggable:n,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,nodeClickDistance:e.nodeClickDistance,onError:o},l))})}Xi.displayName="NodeRenderer";const Ru=p.memo(Xi);function _u(e){return _e(p.useCallback(s=>{if(!e)return s.edges.map(i=>i.id);const r=[];if(s.width&&s.height)for(const i of s.edges){const o=s.nodeLookup.get(i.source),a=s.nodeLookup.get(i.target);o&&a&&_c({sourceNode:o,targetNode:a,width:s.width,height:s.height,transform:s.transform})&&r.push(i.id)}return r},[e]),qe)}const Lu=({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"})},Au=({color:e="none",strokeWidth:n=1})=>{const s={strokeWidth:n,...e&&{stroke:e,fill:e}};return t.jsx("polyline",{className:"arrowclosed",style:s,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},va={[Kn.Arrow]:Lu,[Kn.ArrowClosed]:Au};function Du(e){const n=Oe();return p.useMemo(()=>Object.prototype.hasOwnProperty.call(va,e)?va[e]:(n.getState().onError?.("009",Wt.error009(e)),null),[e])}const Pu=({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=Du(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},Zi=({defaultColor:e,rfId:n})=>{const s=_e(o=>o.edges),r=_e(o=>o.defaultEdgeOptions),i=p.useMemo(()=>zc(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(Pu,{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};Zi.displayName="MarkerDefinitions";var $u=p.memo(Zi);function Qi({x:e,y:n,label:s,labelStyle:r,labelShowBg:i=!0,labelBgStyle:o,labelBgPadding:a=[2,4],labelBgBorderRadius:c=2,children:l,className:d,...h}){const[f,m]=p.useState({x:1,y:0,width:0,height:0}),u=Ye(["react-flow__edge-textwrapper",d]),x=p.useRef(null);return p.useEffect(()=>{if(x.current){const E=x.current.getBBox();m({x:E.x,y:E.y,width:E.width,height:E.height})}},[s]),s?t.jsxs("g",{transform:`translate(${e-f.width/2} ${n-f.height/2})`,className:u,visibility:f.width?"visible":"hidden",...h,children:[i&&t.jsx("rect",{width:f.width+2*a[0],x:-a[0],y:-a[1],height:f.height+2*a[1],className:"react-flow__edge-textbg",style:o,rx: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}Qi.displayName="EdgeText";const Bu=p.memo(Qi);function hs({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:Ye(["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&&Rt(n)&&Rt(s)?t.jsx(Bu,{x:n,y:s,label:r,labelStyle:i,labelShowBg:o,labelBgStyle:a,labelBgPadding:c,labelBgBorderRadius:l}):null]})}function wa({pos:e,x1:n,y1:s,x2:r,y2:i}){return e===ve.Left||e===ve.Right?[.5*(n+r),s]:[n,.5*(s+i)]}function Ji({sourceX:e,sourceY:n,sourcePosition:s=ve.Bottom,targetX:r,targetY:i,targetPosition:o=ve.Top}){const[a,c]=wa({pos:s,x1:e,y1:n,x2:r,y2:i}),[l,d]=wa({pos:o,x1:r,y1:i,x2:e,y2:n}),[h,f,m,u]=wi({sourceX:e,sourceY:n,targetX:r,targetY:i,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:d});return[`M${e},${n} C${a},${c} ${l},${d} ${r},${i}`,h,f,m,u]}function el(e){return p.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:E,markerStart:C,interactionWidth:v})=>{const[y,g,b]=Ji({sourceX:s,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:c}),j=e.isInternal?void 0:n;return t.jsx(hs,{id:j,path:y,labelX:g,labelY:b,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:x,markerEnd:E,markerStart:C,interactionWidth:v})})}const Ou=el({isInternal:!1}),tl=el({isInternal:!0});Ou.displayName="SimpleBezierEdge";tl.displayName="SimpleBezierEdgeInternal";function nl(e){return p.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=ve.Bottom,targetPosition:x=ve.Top,markerEnd:E,markerStart:C,pathOptions:v,interactionWidth:y})=>{const[g,b,j]=Bs({sourceX:s,sourceY:r,sourcePosition:u,targetX:i,targetY:o,targetPosition:x,borderRadius:v?.borderRadius,offset:v?.offset,stepPosition:v?.stepPosition}),k=e.isInternal?void 0:n;return t.jsx(hs,{id:k,path:g,labelX:b,labelY:j,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:E,markerStart:C,interactionWidth:y})})}const rl=nl({isInternal:!1}),sl=nl({isInternal:!0});rl.displayName="SmoothStepEdge";sl.displayName="SmoothStepEdgeInternal";function ol(e){return p.memo(({id:n,...s})=>{const r=e.isInternal?void 0:n;return t.jsx(rl,{...s,id:r,pathOptions:p.useMemo(()=>({borderRadius:0,offset:s.pathOptions?.offset}),[s.pathOptions?.offset])})})}const zu=ol({isInternal:!1}),al=ol({isInternal:!0});zu.displayName="StepEdge";al.displayName="StepEdgeInternal";function il(e){return p.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:E})=>{const[C,v,y]=Ni({sourceX:s,sourceY:r,targetX:i,targetY:o}),g=e.isInternal?void 0:n;return t.jsx(hs,{id:g,path:C,labelX:v,labelY:y,label:a,labelStyle:c,labelShowBg:l,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:f,style:m,markerEnd:u,markerStart:x,interactionWidth:E})})}const Hu=il({isInternal:!1}),ll=il({isInternal:!0});Hu.displayName="StraightEdge";ll.displayName="StraightEdgeInternal";function cl(e){return p.memo(({id:n,sourceX:s,sourceY:r,targetX:i,targetY:o,sourcePosition:a=ve.Bottom,targetPosition:c=ve.Top,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:x,markerEnd:E,markerStart:C,pathOptions:v,interactionWidth:y})=>{const[g,b,j]=ki({sourceX:s,sourceY:r,sourcePosition:a,targetX:i,targetY:o,targetPosition:c,curvature:v?.curvature}),k=e.isInternal?void 0:n;return t.jsx(hs,{id:k,path:g,labelX:b,labelY:j,label:l,labelStyle:d,labelShowBg:h,labelBgStyle:f,labelBgPadding:m,labelBgBorderRadius:u,style:x,markerEnd:E,markerStart:C,interactionWidth:y})})}const qu=cl({isInternal:!1}),dl=cl({isInternal:!0});qu.displayName="BezierEdge";dl.displayName="BezierEdgeInternal";const ka={default:dl,straight:ll,step:al,smoothstep:sl,simplebezier:tl},ja={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},Vu=(e,n,s)=>s===ve.Left?e-n:s===ve.Right?e+n:e,Wu=(e,n,s)=>s===ve.Top?e-n:s===ve.Bottom?e+n:e,Na="react-flow__edgeupdater";function Ca({position:e,centerX:n,centerY:s,radius:r=10,onMouseDown:i,onMouseEnter:o,onMouseOut:a,type:c}){return t.jsx("circle",{onMouseDown:i,onMouseEnter:o,onMouseOut:a,className:Ye([Na,`${Na}-${c}`]),cx:Vu(n,r,e),cy:Wu(s,r,e),r,stroke:"transparent",fill:"transparent"})}function Fu({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=Oe(),E=(b,j)=>{if(b.button!==0)return;const{autoPanOnConnect:k,domNode:M,connectionMode:R,connectionRadius:D,lib:A,onConnectStart:T,cancelConnection:$,nodeLookup:z,rfId:N,panBy:O,updateConnection:L}=x.getState(),_=j.type==="target",I=(Y,F)=>{m(!1),f?.(Y,s,j.type,F)},P=Y=>d?.(s,Y),q=(Y,F)=>{m(!0),h?.(b,s,j.type),T?.(Y,F)};Hs.onPointerDown(b.nativeEvent,{autoPanOnConnect:k,connectionMode:R,connectionRadius:D,domNode:M,handleId:j.id,nodeId:j.nodeId,nodeLookup:z,isTarget:_,edgeUpdaterType:j.type,lib:A,flowId:N,cancelConnection:$,panBy:O,isValidConnection:(...Y)=>x.getState().isValidConnection?.(...Y)??!0,onConnect:P,onConnectStart:q,onConnectEnd:(...Y)=>x.getState().onConnectEnd?.(...Y),onReconnectEnd:I,updateConnection:L,getTransform:()=>x.getState().transform,getFromHandle:()=>x.getState().connection.fromHandle,dragThreshold:x.getState().connectionDragThreshold,handleDomNode:b.currentTarget})},C=b=>E(b,{nodeId:s.target,id:s.targetHandle??null,type:"target"}),v=b=>E(b,{nodeId:s.source,id:s.sourceHandle??null,type:"source"}),y=()=>u(!0),g=()=>u(!1);return t.jsxs(t.Fragment,{children:[(e===!0||e==="source")&&t.jsx(Ca,{position:c,centerX:r,centerY:i,radius:n,onMouseDown:C,onMouseEnter:y,onMouseOut:g,type:"source"}),(e===!0||e==="target")&&t.jsx(Ca,{position:l,centerX:o,centerY:a,radius:n,onMouseDown:v,onMouseEnter:y,onMouseOut:g,type:"target"})]})}function Yu({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:E,noPanClassName:C,onError:v,disableKeyboardA11y:y}){let g=_e(fe=>fe.edgeLookup.get(e));const b=_e(fe=>fe.defaultEdgeOptions);g=b?{...b,...g}:g;let j=g.type||"default",k=E?.[j]||ka[j];k===void 0&&(v?.("011",Wt.error011(j)),j="default",k=E?.default||ka.default);const M=!!(g.focusable||n&&typeof g.focusable>"u"),R=typeof f<"u"&&(g.reconnectable||s&&typeof g.reconnectable>"u"),D=!!(g.selectable||r&&typeof g.selectable>"u"),A=p.useRef(null),[T,$]=p.useState(!1),[z,N]=p.useState(!1),O=Oe(),{zIndex:L,sourceX:_,sourceY:I,targetX:P,targetY:q,sourcePosition:Y,targetPosition:F}=_e(p.useCallback(fe=>{const J=fe.nodeLookup.get(g.source),Z=fe.nodeLookup.get(g.target);if(!J||!Z)return{zIndex:g.zIndex,...ja};const ce=Oc({id:e,sourceNode:J,targetNode:Z,sourceHandle:g.sourceHandle||null,targetHandle:g.targetHandle||null,connectionMode:fe.connectionMode,onError:v});return{zIndex:Rc({selected:g.selected,zIndex:g.zIndex,sourceNode:J,targetNode:Z,elevateOnSelect:fe.elevateEdgesOnSelect,zIndexMode:fe.zIndexMode}),...ce||ja}},[g.source,g.target,g.sourceHandle,g.targetHandle,g.selected,g.zIndex]),qe),Q=p.useMemo(()=>g.markerStart?`url('#${Os(g.markerStart,x)}')`:void 0,[g.markerStart,x]),B=p.useMemo(()=>g.markerEnd?`url('#${Os(g.markerEnd,x)}')`:void 0,[g.markerEnd,x]);if(g.hidden||_===null||I===null||P===null||q===null)return null;const S=fe=>{const{addSelectedEdges:J,unselectNodesAndEdges:Z,multiSelectionActive:ce}=O.getState();D&&(O.setState({nodesSelectionActive:!1}),g.selected&&ce?(Z({nodes:[],edges:[g]}),A.current?.blur()):J([e])),i&&i(fe,g)},V=o?fe=>{o(fe,{...g})}:void 0,W=a?fe=>{a(fe,{...g})}:void 0,H=c?fe=>{c(fe,{...g})}:void 0,K=l?fe=>{l(fe,{...g})}:void 0,te=d?fe=>{d(fe,{...g})}:void 0,re=fe=>{if(!y&&ii.includes(fe.key)&&D){const{unselectNodesAndEdges:J,addSelectedEdges:Z}=O.getState();fe.key==="Escape"?(A.current?.blur(),J({edges:[g]})):Z([e])}};return t.jsx("svg",{style:{zIndex:L},children:t.jsxs("g",{className:Ye(["react-flow__edge",`react-flow__edge-${j}`,g.className,C,{selected:g.selected,animated:g.animated,inactive:!D&&!i,updating:T,selectable:D}]),onClick:S,onDoubleClick:V,onContextMenu:W,onMouseEnter:H,onMouseMove:K,onMouseLeave:te,onKeyDown:M?re:void 0,tabIndex:M?0:void 0,role:g.ariaRole??(M?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":g.ariaLabel===null?void 0:g.ariaLabel||`Edge from ${g.source} to ${g.target}`,"aria-describedby":M?`${Oi}-${x}`:void 0,ref:A,...g.domAttributes,children:[!z&&t.jsx(k,{id:e,source:g.source,target:g.target,type:g.type,selected:g.selected,animated:g.animated,selectable:D,deletable:g.deletable??!0,label:g.label,labelStyle:g.labelStyle,labelShowBg:g.labelShowBg,labelBgStyle:g.labelBgStyle,labelBgPadding:g.labelBgPadding,labelBgBorderRadius:g.labelBgBorderRadius,sourceX:_,sourceY:I,targetX:P,targetY:q,sourcePosition:Y,targetPosition:F,data:g.data,style:g.style,sourceHandleId:g.sourceHandle,targetHandleId:g.targetHandle,markerStart:Q,markerEnd:B,pathOptions:"pathOptions"in g?g.pathOptions:void 0,interactionWidth:g.interactionWidth}),R&&t.jsx(Fu,{edge:g,isReconnectable:R,reconnectRadius:h,onReconnect:f,onReconnectStart:m,onReconnectEnd:u,sourceX:_,sourceY:I,targetX:P,targetY:q,sourcePosition:Y,targetPosition:F,setUpdateHover:$,setReconnecting:N})]})})}var Gu=p.memo(Yu);const Ku=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function ul({defaultMarkerColor:e,onlyRenderVisibleElements:n,rfId:s,edgeTypes:r,noPanClassName:i,onReconnect:o,onEdgeContextMenu:a,onEdgeMouseEnter:c,onEdgeMouseMove:l,onEdgeMouseLeave:d,onEdgeClick:h,reconnectRadius:f,onEdgeDoubleClick:m,onReconnectStart:u,onReconnectEnd:x,disableKeyboardA11y:E}){const{edgesFocusable:C,edgesReconnectable:v,elementsSelectable:y,onError:g}=_e(Ku,qe),b=_u(n);return t.jsxs("div",{className:"react-flow__edges",children:[t.jsx($u,{defaultColor:e,rfId:s}),b.map(j=>t.jsx(Gu,{id:j,edgesFocusable:C,edgesReconnectable:v,elementsSelectable:y,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:g,edgeTypes:r,disableKeyboardA11y:E},j))]})}ul.displayName="EdgeRenderer";const Uu=p.memo(ul),Xu=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Zu({children:e}){const n=_e(Xu);return t.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:n},children:e})}function Qu(e){const n=no(),s=p.useRef(!1);p.useEffect(()=>{!s.current&&n.viewportInitialized&&e&&(setTimeout(()=>e(n),1),s.current=!0)},[e,n.viewportInitialized])}const Ju=e=>e.panZoom?.syncViewport;function ef(e){const n=_e(Ju),s=Oe();return p.useEffect(()=>{e&&(n?.(e),s.setState({transform:[e.x,e.y,e.zoom]}))},[e,n]),null}function tf(e){return e.connection.inProgress?{...e.connection,to:jr(e.connection.to,e.transform)}:{...e.connection}}function nf(e){return tf}function rf(e){const n=nf();return _e(n,qe)}const sf=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function of({containerStyle:e,style:n,type:s,component:r}){const{nodesConnectable:i,width:o,height:a,isValid:c,inProgress:l}=_e(sf,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:Ye(["react-flow__connection",di(c)]),children:t.jsx(fl,{style:n,type:s,CustomComponent:r,isValid:c})})})}const fl=({style:e,type:n=fn.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}=rf();if(!i)return;if(s)return t.jsx(s,{connectionLineType:n,connectionLineStyle:e,fromNode:a,fromHandle:c,fromX:o.x,fromY:o.y,toX:d.x,toY:d.y,fromPosition:l,toPosition:m,connectionStatus:di(r),toNode:h,toHandle:f,pointer:u});let x="";const E={sourceX:o.x,sourceY:o.y,sourcePosition:l,targetX:d.x,targetY:d.y,targetPosition:m};switch(n){case fn.Bezier:[x]=ki(E);break;case fn.SimpleBezier:[x]=Ji(E);break;case fn.Step:[x]=Bs({...E,borderRadius:0});break;case fn.SmoothStep:[x]=Bs(E);break;default:[x]=Ni(E)}return t.jsx("path",{d:x,fill:"none",className:"react-flow__connection-path",style:e})};fl.displayName="ConnectionLine";const af={};function Sa(e=af){p.useRef(e),Oe(),p.useEffect(()=>{},[e])}function lf(){Oe(),p.useRef(!1),p.useEffect(()=>{},[])}function hl({nodeTypes:e,edgeTypes:n,onInit:s,onNodeClick:r,onEdgeClick:i,onNodeDoubleClick:o,onEdgeDoubleClick:a,onNodeMouseEnter:c,onNodeMouseMove:l,onNodeMouseLeave:d,onNodeContextMenu:h,onSelectionContextMenu:f,onSelectionStart:m,onSelectionEnd:u,connectionLineType:x,connectionLineStyle:E,connectionLineComponent:C,connectionLineContainerStyle:v,selectionKeyCode:y,selectionOnDrag:g,selectionMode:b,multiSelectionKeyCode:j,panActivationKeyCode:k,zoomActivationKeyCode:M,deleteKeyCode:R,onlyRenderVisibleElements:D,elementsSelectable:A,defaultViewport:T,translateExtent:$,minZoom:z,maxZoom:N,preventScrolling:O,defaultMarkerColor:L,zoomOnScroll:_,zoomOnPinch:I,panOnScroll:P,panOnScrollSpeed:q,panOnScrollMode:Y,zoomOnDoubleClick:F,panOnDrag:Q,onPaneClick:B,onPaneMouseEnter:S,onPaneMouseMove:V,onPaneMouseLeave:W,onPaneScroll:H,onPaneContextMenu:K,paneClickDistance:te,nodeClickDistance:re,onEdgeContextMenu:fe,onEdgeMouseEnter:J,onEdgeMouseMove:Z,onEdgeMouseLeave:ce,reconnectRadius:ae,onReconnect:pe,onReconnectStart:ge,onReconnectEnd:U,noDragClassName:oe,noWheelClassName:ue,noPanClassName:we,disableKeyboardA11y:de,nodeExtent:se,rfId:xe,viewport:Me,onViewportChange:ye}){return Sa(e),Sa(n),lf(),Qu(s),ef(Me),t.jsx(ku,{onPaneClick:B,onPaneMouseEnter:S,onPaneMouseMove:V,onPaneMouseLeave:W,onPaneContextMenu:K,onPaneScroll:H,paneClickDistance:te,deleteKeyCode:R,selectionKeyCode:y,selectionOnDrag:g,selectionMode:b,onSelectionStart:m,onSelectionEnd:u,multiSelectionKeyCode:j,panActivationKeyCode:k,zoomActivationKeyCode:M,elementsSelectable:A,zoomOnScroll:_,zoomOnPinch:I,zoomOnDoubleClick:F,panOnScroll:P,panOnScrollSpeed:q,panOnScrollMode:Y,panOnDrag:Q,defaultViewport:T,translateExtent:$,minZoom:z,maxZoom:N,onSelectionContextMenu:f,preventScrolling:O,noDragClassName:oe,noWheelClassName:ue,noPanClassName:we,disableKeyboardA11y:de,onViewportChange:ye,isControlledViewport:!!Me,children:t.jsxs(Zu,{children:[t.jsx(Uu,{edgeTypes:n,onEdgeClick:i,onEdgeDoubleClick:a,onReconnect:pe,onReconnectStart:ge,onReconnectEnd:U,onlyRenderVisibleElements:D,onEdgeContextMenu:fe,onEdgeMouseEnter:J,onEdgeMouseMove:Z,onEdgeMouseLeave:ce,reconnectRadius:ae,defaultMarkerColor:L,noPanClassName:we,disableKeyboardA11y:de,rfId:xe}),t.jsx(of,{style:E,type:x,component:C,containerStyle:v}),t.jsx("div",{className:"react-flow__edgelabel-renderer"}),t.jsx(Ru,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:o,onNodeMouseEnter:c,onNodeMouseMove:l,onNodeMouseLeave:d,onNodeContextMenu:h,nodeClickDistance:re,onlyRenderVisibleElements:D,noPanClassName:we,noDragClassName:oe,disableKeyboardA11y:de,nodeExtent:se,rfId:xe}),t.jsx("div",{className:"react-flow__viewport-portal"})]})})}hl.displayName="GraphView";const cf=p.memo(hl),Ea=({nodes:e,edges:n,defaultNodes:s,defaultEdges:r,width:i,height:o,fitView:a,fitViewOptions:c,minZoom:l=.5,maxZoom:d=2,nodeOrigin:h,nodeExtent:f,zIndexMode:m="basic"}={})=>{const u=new Map,x=new Map,E=new Map,C=new Map,v=r??n??[],y=s??e??[],g=h??[0,0],b=f??hr;Ei(E,C,v);const j=zs(y,u,x,{nodeOrigin:g,nodeExtent:b,zIndexMode:m});let k=[0,0,1];if(a&&i&&o){const M=wr(u,{filter:T=>!!((T.width||T.initialWidth)&&(T.height||T.initialHeight))}),{x:R,y:D,zoom:A}=Us(M,i,o,l,d,c?.padding??.1);k=[R,D,A]}return{rfId:"1",width:i??0,height:o??0,transform:k,nodes:y,nodesInitialized:j,nodeLookup:u,parentLookup:x,edges:v,edgeLookup:C,connectionLookup:E,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:s!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:l,maxZoom:d,translateExtent:hr,nodeExtent:b,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Gn.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:g,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:a??!1,fitViewOptions:c,fitViewResolver:null,connection:{...ci},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:Cc,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:li,zIndexMode:m,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},df=({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})=>Ed((u,x)=>{async function E(){const{nodeLookup:C,panZoom:v,fitViewOptions:y,fitViewResolver:g,width:b,height:j,minZoom:k,maxZoom:M}=x();v&&(await jc({nodes:C,width:b,height:j,panZoom:v,minZoom:k,maxZoom:M},y),g?.resolve(!0),u({fitViewResolver:null}))}return{...Ea({nodes:e,edges:n,width:i,height:o,fitView:a,fitViewOptions:c,minZoom:l,maxZoom:d,nodeOrigin:h,nodeExtent:f,defaultNodes:s,defaultEdges:r,zIndexMode:m}),setNodes:C=>{const{nodeLookup:v,parentLookup:y,nodeOrigin:g,elevateNodesOnSelect:b,fitViewQueued:j,zIndexMode:k}=x(),M=zs(C,v,y,{nodeOrigin:g,nodeExtent:f,elevateNodesOnSelect:b,checkEquality:!0,zIndexMode:k});j&&M?(E(),u({nodes:C,nodesInitialized:M,fitViewQueued:!1,fitViewOptions:void 0})):u({nodes:C,nodesInitialized:M})},setEdges:C=>{const{connectionLookup:v,edgeLookup:y}=x();Ei(v,y,C),u({edges:C})},setDefaultNodesAndEdges:(C,v)=>{if(C){const{setNodes:y}=x();y(C),u({hasDefaultNodes:!0})}if(v){const{setEdges:y}=x();y(v),u({hasDefaultEdges:!0})}},updateNodeInternals:C=>{const{triggerNodeChanges:v,nodeLookup:y,parentLookup:g,domNode:b,nodeOrigin:j,nodeExtent:k,debug:M,fitViewQueued:R,zIndexMode:D}=x(),{changes:A,updatedInternals:T}=Gc(C,y,g,b,j,k,D);T&&(Vc(y,g,{nodeOrigin:j,nodeExtent:k,zIndexMode:D}),R?(E(),u({fitViewQueued:!1,fitViewOptions:void 0})):u({}),A?.length>0&&(M&&console.log("React Flow: trigger node changes",A),v?.(A)))},updateNodePositions:(C,v=!1)=>{const y=[];let g=[];const{nodeLookup:b,triggerNodeChanges:j,connection:k,updateConnection:M,onNodesChangeMiddlewareMap:R}=x();for(const[D,A]of C){const T=b.get(D),$=!!(T?.expandParent&&T?.parentId&&A?.position),z={id:D,type:"position",position:$?{x:Math.max(0,A.position.x),y:Math.max(0,A.position.y)}:A.position,dragging:v};if(T&&k.inProgress&&k.fromNode.id===T.id){const N=In(T,k.fromHandle,ve.Left,!0);M({...k,from:N})}$&&T.parentId&&y.push({id:D,parentId:T.parentId,rect:{...A.internals.positionAbsolute,width:A.measured.width??0,height:A.measured.height??0}}),g.push(z)}if(y.length>0){const{parentLookup:D,nodeOrigin:A}=x(),T=to(y,b,D,A);g.push(...T)}for(const D of R.values())g=D(g);j(g)},triggerNodeChanges:C=>{const{onNodesChange:v,setNodes:y,nodes:g,hasDefaultNodes:b,debug:j}=x();if(C?.length){if(b){const k=qi(C,g);y(k)}j&&console.log("React Flow: trigger node changes",C),v?.(C)}},triggerEdgeChanges:C=>{const{onEdgesChange:v,setEdges:y,edges:g,hasDefaultEdges:b,debug:j}=x();if(C?.length){if(b){const k=Vi(C,g);y(k)}j&&console.log("React Flow: trigger edge changes",C),v?.(C)}},addSelectedNodes:C=>{const{multiSelectionActive:v,edgeLookup:y,nodeLookup:g,triggerNodeChanges:b,triggerEdgeChanges:j}=x();if(v){const k=C.map(M=>En(M,!0));b(k);return}b(Wn(g,new Set([...C]),!0)),j(Wn(y))},addSelectedEdges:C=>{const{multiSelectionActive:v,edgeLookup:y,nodeLookup:g,triggerNodeChanges:b,triggerEdgeChanges:j}=x();if(v){const k=C.map(M=>En(M,!0));j(k);return}j(Wn(y,new Set([...C]))),b(Wn(g,new Set,!0))},unselectNodesAndEdges:({nodes:C,edges:v}={})=>{const{edges:y,nodes:g,nodeLookup:b,triggerNodeChanges:j,triggerEdgeChanges:k}=x(),M=C||g,R=v||y,D=[];for(const T of M){if(!T.selected)continue;const $=b.get(T.id);$&&($.selected=!1),D.push(En(T.id,!1))}const A=[];for(const T of R)T.selected&&A.push(En(T.id,!1));j(D),k(A)},setMinZoom:C=>{const{panZoom:v,maxZoom:y}=x();v?.setScaleExtent([C,y]),u({minZoom:C})},setMaxZoom:C=>{const{panZoom:v,minZoom:y}=x();v?.setScaleExtent([y,C]),u({maxZoom:C})},setTranslateExtent:C=>{x().panZoom?.setTranslateExtent(C),u({translateExtent:C})},resetSelectedElements:()=>{const{edges:C,nodes:v,triggerNodeChanges:y,triggerEdgeChanges:g,elementsSelectable:b}=x();if(!b)return;const j=v.reduce((M,R)=>R.selected?[...M,En(R.id,!1)]:M,[]),k=C.reduce((M,R)=>R.selected?[...M,En(R.id,!1)]:M,[]);y(j),g(k)},setNodeExtent:C=>{const{nodes:v,nodeLookup:y,parentLookup:g,nodeOrigin:b,elevateNodesOnSelect:j,nodeExtent:k,zIndexMode:M}=x();C[0][0]===k[0][0]&&C[0][1]===k[0][1]&&C[1][0]===k[1][0]&&C[1][1]===k[1][1]||(zs(v,y,g,{nodeOrigin:b,nodeExtent:C,elevateNodesOnSelect:j,checkEquality:!1,zIndexMode:M}),u({nodeExtent:C}))},panBy:C=>{const{transform:v,width:y,height:g,panZoom:b,translateExtent:j}=x();return Kc({delta:C,panZoom:b,transform:v,translateExtent:j,width:y,height:g})},setCenter:async(C,v,y)=>{const{width:g,height:b,maxZoom:j,panZoom:k}=x();if(!k)return Promise.resolve(!1);const M=typeof y?.zoom<"u"?y.zoom:j;return await k.setViewport({x:g/2-C*M,y:b/2-v*M,zoom:M},{duration:y?.duration,ease:y?.ease,interpolate:y?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{u({connection:{...ci}})},updateConnection:C=>{u({connection:C})},reset:()=>u({...Ea()})}},Object.is);function uf({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]=p.useState(()=>df({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(Md,{value:x,children:t.jsx(Zd,{children:u})})}function ff({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 p.useContext(ds)?t.jsx(t.Fragment,{children:e}):t.jsx(uf,{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 hf={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function mf({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:E,onClickConnectStart:C,onClickConnectEnd:v,onNodeMouseEnter:y,onNodeMouseMove:g,onNodeMouseLeave:b,onNodeContextMenu:j,onNodeDoubleClick:k,onNodeDragStart:M,onNodeDrag:R,onNodeDragStop:D,onNodesDelete:A,onEdgesDelete:T,onDelete:$,onSelectionChange:z,onSelectionDragStart:N,onSelectionDrag:O,onSelectionDragStop:L,onSelectionContextMenu:_,onSelectionStart:I,onSelectionEnd:P,onBeforeDelete:q,connectionMode:Y,connectionLineType:F=fn.Bezier,connectionLineStyle:Q,connectionLineComponent:B,connectionLineContainerStyle:S,deleteKeyCode:V="Backspace",selectionKeyCode:W="Shift",selectionOnDrag:H=!1,selectionMode:K=mr.Full,panActivationKeyCode:te="Space",multiSelectionKeyCode:re=gr()?"Meta":"Control",zoomActivationKeyCode:fe=gr()?"Meta":"Control",snapToGrid:J,snapGrid:Z,onlyRenderVisibleElements:ce=!1,selectNodesOnDrag:ae,nodesDraggable:pe,autoPanOnNodeFocus:ge,nodesConnectable:U,nodesFocusable:oe,nodeOrigin:ue=zi,edgesFocusable:we,edgesReconnectable:de,elementsSelectable:se=!0,defaultViewport:xe=Hd,minZoom:Me=.5,maxZoom:ye=2,translateExtent:Re=hr,preventScrolling:pt=!0,nodeExtent:gt,defaultMarkerColor:jt="#b1b1b7",zoomOnScroll:Ft=!0,zoomOnPinch:Qe=!0,panOnScroll:Yt=!1,panOnScrollSpeed:dt=.5,panOnScrollMode:At=Mn.Free,zoomOnDoubleClick:ut=!0,panOnDrag:Ue=!0,onPaneClick:Dt,onPaneMouseEnter:xt,onPaneMouseMove:st,onPaneMouseLeave:Nt,onPaneScroll:Xe,onPaneContextMenu:be,paneClickDistance:Je=1,nodeClickDistance:it=0,children:Pt,onReconnect:et,onReconnectStart:bt,onReconnectEnd:Gt,onEdgeContextMenu:Ne,onEdgeDoubleClick:Ce,onEdgeMouseEnter:Ae,onEdgeMouseMove:De,onEdgeMouseLeave:ze,reconnectRadius:$t=10,onNodesChange:Ze,onEdgesChange:Bt,noDragClassName:ot="nodrag",noWheelClassName:Kt="nowheel",noPanClassName:Ct="nopan",fitView:Ut,fitViewOptions:Ot,connectOnClick:Ge,attributionPosition:lt,proOptions:pn,defaultEdgeOptions:sn,elevateNodesOnSelect:on=!0,elevateEdgesOnSelect:zt=!1,disableKeyboardA11y:tt=!1,autoPanOnConnect:Xt,autoPanOnNodeDrag:Ht,autoPanSpeed:We,connectionRadius:G,isValidConnection:me,onError:Te,style:Ie,id:Ee,nodeDragThreshold:nt,connectionDragThreshold:qt,viewport:gn,onViewportChange:Zt,width:xn,height:bn,colorMode:Rn="light",debug:yn,onScroll:er,ariaLabelConfig:ms,zIndexMode:vn="basic",...Nr},an){const St=Ee||"1",Cr=Fd(Rn),Sr=p.useCallback(tr=>{tr.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),er?.(tr)},[er]);return t.jsx("div",{"data-testid":"rf__wrapper",...Nr,onScroll:Sr,style:{...Ie,...hf},ref:an,className:Ye(["react-flow",i,Cr]),id:Ee,role:"application",children:t.jsxs(ff,{nodes:e,edges:n,width:xn,height:bn,fitView:Ut,fitViewOptions:Ot,minZoom:Me,maxZoom:ye,nodeOrigin:ue,nodeExtent:gt,zIndexMode:vn,children:[t.jsx(cf,{onInit:d,onNodeClick:c,onEdgeClick:l,onNodeMouseEnter:y,onNodeMouseMove:g,onNodeMouseLeave:b,onNodeContextMenu:j,onNodeDoubleClick:k,nodeTypes:o,edgeTypes:a,connectionLineType:F,connectionLineStyle:Q,connectionLineComponent:B,connectionLineContainerStyle:S,selectionKeyCode:W,selectionOnDrag:H,selectionMode:K,deleteKeyCode:V,multiSelectionKeyCode:re,panActivationKeyCode:te,zoomActivationKeyCode:fe,onlyRenderVisibleElements:ce,defaultViewport:xe,translateExtent:Re,minZoom:Me,maxZoom:ye,preventScrolling:pt,zoomOnScroll:Ft,zoomOnPinch:Qe,zoomOnDoubleClick:ut,panOnScroll:Yt,panOnScrollSpeed:dt,panOnScrollMode:At,panOnDrag:Ue,onPaneClick:Dt,onPaneMouseEnter:xt,onPaneMouseMove:st,onPaneMouseLeave:Nt,onPaneScroll:Xe,onPaneContextMenu:be,paneClickDistance:Je,nodeClickDistance:it,onSelectionContextMenu:_,onSelectionStart:I,onSelectionEnd:P,onReconnect:et,onReconnectStart:bt,onReconnectEnd:Gt,onEdgeContextMenu:Ne,onEdgeDoubleClick:Ce,onEdgeMouseEnter:Ae,onEdgeMouseMove:De,onEdgeMouseLeave:ze,reconnectRadius:$t,defaultMarkerColor:jt,noDragClassName:ot,noWheelClassName:Kt,noPanClassName:Ct,rfId:St,disableKeyboardA11y:tt,nodeExtent:gt,viewport:gn,onViewportChange:Zt}),t.jsx(Wd,{nodes:e,edges:n,defaultNodes:s,defaultEdges:r,onConnect:u,onConnectStart:x,onConnectEnd:E,onClickConnectStart:C,onClickConnectEnd:v,nodesDraggable:pe,autoPanOnNodeFocus:ge,nodesConnectable:U,nodesFocusable:oe,edgesFocusable:we,edgesReconnectable:de,elementsSelectable:se,elevateNodesOnSelect:on,elevateEdgesOnSelect:zt,minZoom:Me,maxZoom:ye,nodeExtent:gt,onNodesChange:Ze,onEdgesChange:Bt,snapToGrid:J,snapGrid:Z,connectionMode:Y,translateExtent:Re,connectOnClick:Ge,defaultEdgeOptions:sn,fitView:Ut,fitViewOptions:Ot,onNodesDelete:A,onEdgesDelete:T,onDelete:$,onNodeDragStart:M,onNodeDrag:R,onNodeDragStop:D,onSelectionDrag:O,onSelectionDragStart:N,onSelectionDragStop:L,onMove:h,onMoveStart:f,onMoveEnd:m,noPanClassName:Ct,nodeOrigin:ue,rfId:St,autoPanOnConnect:Xt,autoPanOnNodeDrag:Ht,autoPanSpeed:We,onError:Te,connectionRadius:G,isValidConnection:me,selectNodesOnDrag:ae,nodeDragThreshold:nt,connectionDragThreshold:qt,onBeforeDelete:q,debug:yn,ariaLabelConfig:ms,zIndexMode:vn}),t.jsx(zd,{onSelectionChange:z}),Pt,t.jsx(Dd,{proOptions:pn,position:lt}),t.jsx(Ad,{rfId:St,disableKeyboardA11y:tt})]})})}var pf=Wi(mf);function gf(){const e=Oe();return p.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 xf(e){const[n,s]=p.useState(e),r=p.useCallback(i=>s(o=>qi(i,o)),[]);return[n,s,r]}function bf(e){const[n,s]=p.useState(e),r=p.useCallback(i=>s(o=>Vi(i,o)),[]);return[n,s,r]}function yf({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:Ye(["react-flow__background-pattern",s,r])})}function vf({radius:e,className:n}){return t.jsx("circle",{cx:e,cy:e,r:e,className:Ye(["react-flow__background-pattern","dots",n])})}var hn;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(hn||(hn={}));const wf={[hn.Dots]:1,[hn.Lines]:1,[hn.Cross]:6},kf=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function ml({id:e,variant:n=hn.Dots,gap:s=20,size:r,lineWidth:i=1,offset:o=0,color:a,bgColor:c,style:l,className:d,patternClassName:h}){const f=p.useRef(null),{transform:m,patternId:u}=_e(kf,qe),x=r||wf[n],E=n===hn.Dots,C=n===hn.Cross,v=Array.isArray(s)?s:[s,s],y=[v[0]*m[2]||1,v[1]*m[2]||1],g=x*m[2],b=Array.isArray(o)?o:[o,o],j=C?[g,g]:y,k=[b[0]*m[2]||1+j[0]/2,b[1]*m[2]||1+j[1]/2],M=`${u}${e||""}`;return t.jsxs("svg",{className:Ye(["react-flow__background",d]),style:{...l,...fs,"--xy-background-color-props":c,"--xy-background-pattern-color-props":a},ref:f,"data-testid":"rf__background",children:[t.jsx("pattern",{id:M,x:m[0]%y[0],y:m[1]%y[1],width:y[0],height:y[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${k[0]},-${k[1]})`,children:E?t.jsx(vf,{radius:g/2,className:h}):t.jsx(yf,{dimensions:j,lineWidth:i,variant:n,className:h})}),t.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${M})`})]})}ml.displayName="Background";const jf=p.memo(ml);function Nf(){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 Cf(){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 Sf(){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 Ef(){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 Mf(){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 Yr({children:e,className:n,...s}){return t.jsx("button",{type:"button",className:Ye(["react-flow__controls-button",n]),...s,children:e})}const Tf=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function pl({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=Oe(),{isInteractive:E,minZoomReached:C,maxZoomReached:v,ariaLabelConfig:y}=_e(Tf,qe),{zoomIn:g,zoomOut:b,fitView:j}=no(),k=()=>{g(),o?.()},M=()=>{b(),a?.()},R=()=>{j(i),c?.()},D=()=>{x.setState({nodesDraggable:!E,nodesConnectable:!E,elementsSelectable:!E}),l?.(!E)},A=m==="horizontal"?"horizontal":"vertical";return t.jsxs(us,{className:Ye(["react-flow__controls",A,d]),position:f,style:e,"data-testid":"rf__controls","aria-label":u??y["controls.ariaLabel"],children:[n&&t.jsxs(t.Fragment,{children:[t.jsx(Yr,{onClick:k,className:"react-flow__controls-zoomin",title:y["controls.zoomIn.ariaLabel"],"aria-label":y["controls.zoomIn.ariaLabel"],disabled:v,children:t.jsx(Nf,{})}),t.jsx(Yr,{onClick:M,className:"react-flow__controls-zoomout",title:y["controls.zoomOut.ariaLabel"],"aria-label":y["controls.zoomOut.ariaLabel"],disabled:C,children:t.jsx(Cf,{})})]}),s&&t.jsx(Yr,{className:"react-flow__controls-fitview",onClick:R,title:y["controls.fitView.ariaLabel"],"aria-label":y["controls.fitView.ariaLabel"],children:t.jsx(Sf,{})}),r&&t.jsx(Yr,{className:"react-flow__controls-interactive",onClick:D,title:y["controls.interactive.ariaLabel"],"aria-label":y["controls.interactive.ariaLabel"],children:E?t.jsx(Mf,{}):t.jsx(Ef,{})}),h]})}pl.displayName="Controls";const If=p.memo(pl);function Rf({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:E}=o||{},C=a||x||E;return t.jsx("rect",{className:Ye(["react-flow__minimap-node",{selected:m},d]),x:n,y:s,rx:h,ry:h,width:r,height:i,style:{fill:C,stroke:c,strokeWidth:l},shapeRendering:f,onClick:u?v=>u(v,e):void 0})}const _f=p.memo(Rf),Lf=e=>e.nodes.map(n=>n.id),Rs=e=>e instanceof Function?e:()=>e;function Af({nodeStrokeColor:e,nodeColor:n,nodeClassName:s="",nodeBorderRadius:r=5,nodeStrokeWidth:i,nodeComponent:o=_f,onClick:a}){const c=_e(Lf,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(Pf,{id:m,nodeColorFunc:l,nodeStrokeColorFunc:d,nodeClassNameFunc:h,nodeBorderRadius:r,nodeStrokeWidth:i,NodeComponent:o,onClick:a,shapeRendering:f},m))})}function Df({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}=_e(x=>{const E=x.nodeLookup.get(e);if(!E)return{node:void 0,x:0,y:0,width:0,height:0};const C=E.internals.userNode,{x:v,y}=E.internals.positionAbsolute,{width:g,height:b}=rn(C);return{node:C,x:v,y,width:g,height:b}},qe);return!d||d.hidden||!gi(d)?null:t.jsx(c,{x:h,y:f,width:m,height:u,style:d.style,selected:!!d.selected,className:r(d),color:n(d),borderRadius:i,strokeColor:s(d),strokeWidth:o,shapeRendering:a,onClick:l,id:d.id})}const Pf=p.memo(Df);var $f=p.memo(Af);const Bf=200,Of=150,zf=e=>!e.hidden,Hf=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?pi(wr(e.nodeLookup,{filter:zf}),n):n,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},qf="react-flow__minimap-desc";function gl({style:e,className:n,nodeStrokeColor:s,nodeColor:r,nodeClassName:i="",nodeBorderRadius:o=5,nodeStrokeWidth:a,nodeComponent:c,bgColor:l,maskColor:d,maskStrokeColor:h,maskStrokeWidth:f,position:m="bottom-right",onClick:u,onNodeClick:x,pannable:E=!1,zoomable:C=!1,ariaLabel:v,inversePan:y,zoomStep:g=1,offsetScale:b=5}){const j=Oe(),k=p.useRef(null),{boundingRect:M,viewBB:R,rfId:D,panZoom:A,translateExtent:T,flowWidth:$,flowHeight:z,ariaLabelConfig:N}=_e(Hf,qe),O=e?.width??Bf,L=e?.height??Of,_=M.width/O,I=M.height/L,P=Math.max(_,I),q=P*O,Y=P*L,F=b*P,Q=M.x-(q-M.width)/2-F,B=M.y-(Y-M.height)/2-F,S=q+F*2,V=Y+F*2,W=`${qf}-${D}`,H=p.useRef(0),K=p.useRef();H.current=P,p.useEffect(()=>{if(k.current&&A)return K.current=rd({domNode:k.current,panZoom:A,getTransform:()=>j.getState().transform,getViewScale:()=>H.current}),()=>{K.current?.destroy()}},[A]),p.useEffect(()=>{K.current?.update({translateExtent:T,width:$,height:z,inversePan:y,pannable:E,zoomStep:g,zoomable:C})},[E,C,y,g,T,$,z]);const te=u?J=>{const[Z,ce]=K.current?.pointer(J)||[0,0];u(J,{x:Z,y:ce})}:void 0,re=x?p.useCallback((J,Z)=>{const ce=j.getState().nodeLookup.get(Z).internals.userNode;x(J,ce)},[]):void 0,fe=v??N["minimap.ariaLabel"];return t.jsx(us,{position:m,style:{...e,"--xy-minimap-background-color-props":typeof l=="string"?l:void 0,"--xy-minimap-mask-background-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-stroke-color-props":typeof h=="string"?h:void 0,"--xy-minimap-mask-stroke-width-props":typeof f=="number"?f*P:void 0,"--xy-minimap-node-background-color-props":typeof r=="string"?r:void 0,"--xy-minimap-node-stroke-color-props":typeof s=="string"?s:void 0,"--xy-minimap-node-stroke-width-props":typeof a=="number"?a:void 0},className:Ye(["react-flow__minimap",n]),"data-testid":"rf__minimap",children:t.jsxs("svg",{width:O,height:L,viewBox:`${Q} ${B} ${S} ${V}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":W,ref:k,onClick:te,children:[fe&&t.jsx("title",{id:W,children:fe}),t.jsx($f,{onClick:re,nodeColor:r,nodeStrokeColor:s,nodeBorderRadius:o,nodeClassName:i,nodeStrokeWidth:a,nodeComponent:c}),t.jsx("path",{className:"react-flow__minimap-mask",d:`M${Q-F},${B-F}h${S+F*2}v${V+F*2}h${-S-F*2}z
|
|
7
|
-
M${R.x},${R.y}h${R.width}v${R.height}h${-R.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}gl.displayName="MiniMap";const Vf=p.memo(gl),Wf=e=>n=>e?`${Math.max(1/n.transform[2],1)}`:void 0,Ff={[Qn.Line]:"right",[Qn.Handle]:"bottom-right"};function Yf({nodeId:e,position:n,variant:s=Qn.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:E,onResize:C,onResizeEnd:v}){const y=Ki(),g=typeof e=="string"?e:y,b=Oe(),j=p.useRef(null),k=s===Qn.Handle,M=_e(p.useCallback(Wf(k&&u),[k,u]),qe),R=p.useRef(null),D=n??Ff[s];p.useEffect(()=>{if(!(!j.current||!g))return R.current||(R.current=xd({domNode:j.current,nodeId:g,getStoreItems:()=>{const{nodeLookup:T,transform:$,snapGrid:z,snapToGrid:N,nodeOrigin:O,domNode:L}=b.getState();return{nodeLookup:T,transform:$,snapGrid:z,snapToGrid:N,nodeOrigin:O,paneDomNode:L}},onChange:(T,$)=>{const{triggerNodeChanges:z,nodeLookup:N,parentLookup:O,nodeOrigin:L}=b.getState(),_=[],I={x:T.x,y:T.y},P=N.get(g);if(P&&P.expandParent&&P.parentId){const q=P.origin??L,Y=T.width??P.measured.width??0,F=T.height??P.measured.height??0,Q={id:P.id,parentId:P.parentId,rect:{width:Y,height:F,...xi({x:T.x??P.position.x,y:T.y??P.position.y},{width:Y,height:F},P.parentId,N,q)}},B=to([Q],N,O,L);_.push(...B),I.x=T.x?Math.max(q[0]*Y,T.x):void 0,I.y=T.y?Math.max(q[1]*F,T.y):void 0}if(I.x!==void 0&&I.y!==void 0){const q={id:g,type:"position",position:{...I}};_.push(q)}if(T.width!==void 0&&T.height!==void 0){const Y={id:g,type:"dimensions",resizing:!0,setAttributes:m?m==="horizontal"?"width":"height":!0,dimensions:{width:T.width,height:T.height}};_.push(Y)}for(const q of $){const Y={...q,type:"position"};_.push(Y)}z(_)},onEnd:({width:T,height:$})=>{const z={id:g,type:"dimensions",resizing:!1,dimensions:{width:T,height:$}};b.getState().triggerNodeChanges([z])}})),R.current.update({controlPosition:D,boundaries:{minWidth:c,minHeight:l,maxWidth:d,maxHeight:h},keepAspectRatio:f,resizeDirection:m,onResizeStart:E,onResize:C,onResizeEnd:v,shouldResize:x}),()=>{R.current?.destroy()}},[D,c,l,d,h,f,E,C,v,x]);const A=D.split("-");return t.jsx("div",{className:Ye(["react-flow__resize-control","nodrag",...A,s,r]),ref:j,style:{...i,scale:M,...a&&{[k?"backgroundColor":"borderColor"]:a}},children:o})}p.memo(Yf);var Pe=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),Lt=Pe((e,n)=>{var s=Object.defineProperty,r=(z,N,O)=>N in z?s(z,N,{enumerable:!0,configurable:!0,writable:!0,value:O}):z[N]=O,i=(z,N)=>()=>(N||z((N={exports:{}}).exports,N),N.exports),o=(z,N,O)=>r(z,typeof N!="symbol"?N+"":N,O),a=i((z,N)=>{var O="\0",L="\0",_="",I=class{constructor(B){o(this,"_isDirected",!0),o(this,"_isMultigraph",!1),o(this,"_isCompound",!1),o(this,"_label"),o(this,"_defaultNodeLabelFn",()=>{}),o(this,"_defaultEdgeLabelFn",()=>{}),o(this,"_nodes",{}),o(this,"_in",{}),o(this,"_preds",{}),o(this,"_out",{}),o(this,"_sucs",{}),o(this,"_edgeObjs",{}),o(this,"_edgeLabels",{}),o(this,"_nodeCount",0),o(this,"_edgeCount",0),o(this,"_parent"),o(this,"_children"),B&&(this._isDirected=Object.hasOwn(B,"directed")?B.directed:!0,this._isMultigraph=Object.hasOwn(B,"multigraph")?B.multigraph:!1,this._isCompound=Object.hasOwn(B,"compound")?B.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[L]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(B){return this._label=B,this}graph(){return this._label}setDefaultNodeLabel(B){return this._defaultNodeLabelFn=B,typeof B!="function"&&(this._defaultNodeLabelFn=()=>B),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var B=this;return this.nodes().filter(S=>Object.keys(B._in[S]).length===0)}sinks(){var B=this;return this.nodes().filter(S=>Object.keys(B._out[S]).length===0)}setNodes(B,S){var V=arguments,W=this;return B.forEach(function(H){V.length>1?W.setNode(H,S):W.setNode(H)}),this}setNode(B,S){return Object.hasOwn(this._nodes,B)?(arguments.length>1&&(this._nodes[B]=S),this):(this._nodes[B]=arguments.length>1?S:this._defaultNodeLabelFn(B),this._isCompound&&(this._parent[B]=L,this._children[B]={},this._children[L][B]=!0),this._in[B]={},this._preds[B]={},this._out[B]={},this._sucs[B]={},++this._nodeCount,this)}node(B){return this._nodes[B]}hasNode(B){return Object.hasOwn(this._nodes,B)}removeNode(B){var S=this;if(Object.hasOwn(this._nodes,B)){var V=W=>S.removeEdge(S._edgeObjs[W]);delete this._nodes[B],this._isCompound&&(this._removeFromParentsChildList(B),delete this._parent[B],this.children(B).forEach(function(W){S.setParent(W)}),delete this._children[B]),Object.keys(this._in[B]).forEach(V),delete this._in[B],delete this._preds[B],Object.keys(this._out[B]).forEach(V),delete this._out[B],delete this._sucs[B],--this._nodeCount}return this}setParent(B,S){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(S===void 0)S=L;else{S+="";for(var V=S;V!==void 0;V=this.parent(V))if(V===B)throw new Error("Setting "+S+" as parent of "+B+" would create a cycle");this.setNode(S)}return this.setNode(B),this._removeFromParentsChildList(B),this._parent[B]=S,this._children[S][B]=!0,this}_removeFromParentsChildList(B){delete this._children[this._parent[B]][B]}parent(B){if(this._isCompound){var S=this._parent[B];if(S!==L)return S}}children(B=L){if(this._isCompound){var S=this._children[B];if(S)return Object.keys(S)}else{if(B===L)return this.nodes();if(this.hasNode(B))return[]}}predecessors(B){var S=this._preds[B];if(S)return Object.keys(S)}successors(B){var S=this._sucs[B];if(S)return Object.keys(S)}neighbors(B){var S=this.predecessors(B);if(S){let W=new Set(S);for(var V of this.successors(B))W.add(V);return Array.from(W.values())}}isLeaf(B){var S;return this.isDirected()?S=this.successors(B):S=this.neighbors(B),S.length===0}filterNodes(B){var S=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});S.setGraph(this.graph());var V=this;Object.entries(this._nodes).forEach(function([K,te]){B(K)&&S.setNode(K,te)}),Object.values(this._edgeObjs).forEach(function(K){S.hasNode(K.v)&&S.hasNode(K.w)&&S.setEdge(K,V.edge(K))});var W={};function H(K){var te=V.parent(K);return te===void 0||S.hasNode(te)?(W[K]=te,te):te in W?W[te]:H(te)}return this._isCompound&&S.nodes().forEach(K=>S.setParent(K,H(K))),S}setDefaultEdgeLabel(B){return this._defaultEdgeLabelFn=B,typeof B!="function"&&(this._defaultEdgeLabelFn=()=>B),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(B,S){var V=this,W=arguments;return B.reduce(function(H,K){return W.length>1?V.setEdge(H,K,S):V.setEdge(H,K),K}),this}setEdge(){var B,S,V,W,H=!1,K=arguments[0];typeof K=="object"&&K!==null&&"v"in K?(B=K.v,S=K.w,V=K.name,arguments.length===2&&(W=arguments[1],H=!0)):(B=K,S=arguments[1],V=arguments[3],arguments.length>2&&(W=arguments[2],H=!0)),B=""+B,S=""+S,V!==void 0&&(V=""+V);var te=Y(this._isDirected,B,S,V);if(Object.hasOwn(this._edgeLabels,te))return H&&(this._edgeLabels[te]=W),this;if(V!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(B),this.setNode(S),this._edgeLabels[te]=H?W:this._defaultEdgeLabelFn(B,S,V);var re=F(this._isDirected,B,S,V);return B=re.v,S=re.w,Object.freeze(re),this._edgeObjs[te]=re,P(this._preds[S],B),P(this._sucs[B],S),this._in[S][te]=re,this._out[B][te]=re,this._edgeCount++,this}edge(B,S,V){var W=arguments.length===1?Q(this._isDirected,arguments[0]):Y(this._isDirected,B,S,V);return this._edgeLabels[W]}edgeAsObj(){let B=this.edge(...arguments);return typeof B!="object"?{label:B}:B}hasEdge(B,S,V){var W=arguments.length===1?Q(this._isDirected,arguments[0]):Y(this._isDirected,B,S,V);return Object.hasOwn(this._edgeLabels,W)}removeEdge(B,S,V){var W=arguments.length===1?Q(this._isDirected,arguments[0]):Y(this._isDirected,B,S,V),H=this._edgeObjs[W];return H&&(B=H.v,S=H.w,delete this._edgeLabels[W],delete this._edgeObjs[W],q(this._preds[S],B),q(this._sucs[B],S),delete this._in[S][W],delete this._out[B][W],this._edgeCount--),this}inEdges(B,S){return this.isDirected()?this.filterEdges(this._in[B],B,S):this.nodeEdges(B,S)}outEdges(B,S){return this.isDirected()?this.filterEdges(this._out[B],B,S):this.nodeEdges(B,S)}nodeEdges(B,S){if(B in this._nodes)return this.filterEdges({...this._in[B],...this._out[B]},B,S)}filterEdges(B,S,V){if(B){var W=Object.values(B);return V?W.filter(function(H){return H.v===S&&H.w===V||H.v===V&&H.w===S}):W}}};function P(B,S){B[S]?B[S]++:B[S]=1}function q(B,S){--B[S]||delete B[S]}function Y(B,S,V,W){var H=""+S,K=""+V;if(!B&&H>K){var te=H;H=K,K=te}return H+_+K+_+(W===void 0?O:W)}function F(B,S,V,W){var H=""+S,K=""+V;if(!B&&H>K){var te=H;H=K,K=te}var re={v:H,w:K};return W&&(re.name=W),re}function Q(B,S){return Y(B,S.v,S.w,S.name)}N.exports=I}),c=i((z,N)=>{N.exports="3.0.2"}),l=i((z,N)=>{N.exports={Graph:a(),version:c()}}),d=i((z,N)=>{var O=a();N.exports={write:L,read:P};function L(q){var Y={options:{directed:q.isDirected(),multigraph:q.isMultigraph(),compound:q.isCompound()},nodes:_(q),edges:I(q)};return q.graph()!==void 0&&(Y.value=structuredClone(q.graph())),Y}function _(q){return q.nodes().map(function(Y){var F=q.node(Y),Q=q.parent(Y),B={v:Y};return F!==void 0&&(B.value=F),Q!==void 0&&(B.parent=Q),B})}function I(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 P(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,N)=>{N.exports=L;var O=()=>1;function L(I,P,q,Y){return _(I,String(P),q||O,Y||function(F){return I.outEdges(F)})}function _(I,P,q,Y){var F={},Q=!0,B=0,S=I.nodes(),V=function(te){var re=q(te);F[te.v].distance+re<F[te.w].distance&&(F[te.w]={distance:F[te.v].distance+re,predecessor:te.v},Q=!0)},W=function(){S.forEach(function(te){Y(te).forEach(function(re){var fe=re.v===te?re.v:re.w,J=fe===re.v?re.w:re.v;V({v:fe,w:J})})})};S.forEach(function(te){var re=te===P?0:Number.POSITIVE_INFINITY;F[te]={distance:re}});for(var H=S.length,K=1;K<H&&(Q=!1,B++,W(),!!Q);K++);if(B===H-1&&(Q=!1,W(),Q))throw new Error("The graph contains a negative weight cycle");return F}}),f=i((z,N)=>{N.exports=O;function O(L){var _={},I=[],P;function q(Y){Object.hasOwn(_,Y)||(_[Y]=!0,P.push(Y),L.successors(Y).forEach(q),L.predecessors(Y).forEach(q))}return L.nodes().forEach(function(Y){P=[],q(Y),P.length&&I.push(P)}),I}}),m=i((z,N)=>{var O=class{constructor(){o(this,"_arr",[]),o(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(L){return L.key})}has(L){return Object.hasOwn(this._keyIndices,L)}priority(L){var _=this._keyIndices[L];if(_!==void 0)return this._arr[_].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(L,_){var I=this._keyIndices;if(L=String(L),!Object.hasOwn(I,L)){var P=this._arr,q=P.length;return I[L]=q,P.push({key:L,priority:_}),this._decrease(q),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var L=this._arr.pop();return delete this._keyIndices[L.key],this._heapify(0),L.key}decrease(L,_){var I=this._keyIndices[L];if(_>this._arr[I].priority)throw new Error("New priority is greater than current priority. Key: "+L+" Old: "+this._arr[I].priority+" New: "+_);this._arr[I].priority=_,this._decrease(I)}_heapify(L){var _=this._arr,I=2*L,P=I+1,q=L;I<_.length&&(q=_[I].priority<_[q].priority?I:q,P<_.length&&(q=_[P].priority<_[q].priority?P:q),q!==L&&(this._swap(L,q),this._heapify(q)))}_decrease(L){for(var _=this._arr,I=_[L].priority,P;L!==0&&(P=L>>1,!(_[P].priority<I));)this._swap(L,P),L=P}_swap(L,_){var I=this._arr,P=this._keyIndices,q=I[L],Y=I[_];I[L]=Y,I[_]=q,P[Y.key]=L,P[q.key]=_}};N.exports=O}),u=i((z,N)=>{var O=m();N.exports=_;var L=()=>1;function _(P,q,Y,F){var Q=function(B){return P.outEdges(B)};return I(P,String(q),Y||L,F||Q)}function I(P,q,Y,F){var Q={},B=new O,S,V,W=function(H){var K=H.v!==S?H.v:H.w,te=Q[K],re=Y(H),fe=V.distance+re;if(re<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+H+" Weight: "+re);fe<te.distance&&(te.distance=fe,te.predecessor=S,B.decrease(K,fe))};for(P.nodes().forEach(function(H){var K=H===q?0:Number.POSITIVE_INFINITY;Q[H]={distance:K},B.add(H,K)});B.size()>0&&(S=B.removeMin(),V=Q[S],V.distance!==Number.POSITIVE_INFINITY);)F(S).forEach(W);return Q}}),x=i((z,N)=>{var O=u();N.exports=L;function L(_,I,P){return _.nodes().reduce(function(q,Y){return q[Y]=O(_,Y,I,P),q},{})}}),E=i((z,N)=>{N.exports=O;function O(_,I,P){if(_[I].predecessor!==void 0)throw new Error("Invalid source vertex");if(_[P].predecessor===void 0&&P!==I)throw new Error("Invalid destination vertex");return{weight:_[P].distance,path:L(_,I,P)}}function L(_,I,P){for(var q=[],Y=P;Y!==I;)q.push(Y),Y=_[Y].predecessor;return q.push(I),q.reverse()}}),C=i((z,N)=>{N.exports=O;function O(L){var _=0,I=[],P={},q=[];function Y(F){var Q=P[F]={onStack:!0,lowlink:_,index:_++};if(I.push(F),L.successors(F).forEach(function(V){Object.hasOwn(P,V)?P[V].onStack&&(Q.lowlink=Math.min(Q.lowlink,P[V].index)):(Y(V),Q.lowlink=Math.min(Q.lowlink,P[V].lowlink))}),Q.lowlink===Q.index){var B=[],S;do S=I.pop(),P[S].onStack=!1,B.push(S);while(F!==S);q.push(B)}}return L.nodes().forEach(function(F){Object.hasOwn(P,F)||Y(F)}),q}}),v=i((z,N)=>{var O=C();N.exports=L;function L(_){return O(_).filter(function(I){return I.length>1||I.length===1&&_.hasEdge(I[0],I[0])})}}),y=i((z,N)=>{N.exports=L;var O=()=>1;function L(I,P,q){return _(I,P||O,q||function(Y){return I.outEdges(Y)})}function _(I,P,q){var Y={},F=I.nodes();return F.forEach(function(Q){Y[Q]={},Y[Q][Q]={distance:0},F.forEach(function(B){Q!==B&&(Y[Q][B]={distance:Number.POSITIVE_INFINITY})}),q(Q).forEach(function(B){var S=B.v===Q?B.w:B.v,V=P(B);Y[Q][S]={distance:V,predecessor:Q}})}),F.forEach(function(Q){var B=Y[Q];F.forEach(function(S){var V=Y[S];F.forEach(function(W){var H=V[Q],K=B[W],te=V[W],re=H.distance+K.distance;re<te.distance&&(te.distance=re,te.predecessor=K.predecessor)})})}),Y}}),g=i((z,N)=>{function O(_){var I={},P={},q=[];function Y(F){if(Object.hasOwn(P,F))throw new L;Object.hasOwn(I,F)||(P[F]=!0,I[F]=!0,_.predecessors(F).forEach(Y),delete P[F],q.push(F))}if(_.sinks().forEach(Y),Object.keys(I).length!==_.nodeCount())throw new L;return q}var L=class extends Error{constructor(){super(...arguments)}};N.exports=O,O.CycleException=L}),b=i((z,N)=>{var O=g();N.exports=L;function L(_){try{O(_)}catch(I){if(I instanceof O.CycleException)return!1;throw I}return!0}}),j=i((z,N)=>{N.exports=O;function O(_,I,P,q,Y){Array.isArray(I)||(I=[I]);var F=(_.isDirected()?_.successors:_.neighbors).bind(_),Q={};return I.forEach(function(B){if(!_.hasNode(B))throw new Error("Graph does not have node: "+B);Y=L(_,B,P==="post",Q,F,q,Y)}),Y}function L(_,I,P,q,Y,F,Q){return Object.hasOwn(q,I)||(q[I]=!0,P||(Q=F(Q,I)),Y(I).forEach(function(B){Q=L(_,B,P,q,Y,F,Q)}),P&&(Q=F(Q,I))),Q}}),k=i((z,N)=>{var O=j();N.exports=L;function L(_,I,P){return O(_,I,P,function(q,Y){return q.push(Y),q},[])}}),M=i((z,N)=>{var O=k();N.exports=L;function L(_,I){return O(_,I,"post")}}),R=i((z,N)=>{var O=k();N.exports=L;function L(_,I){return O(_,I,"pre")}}),D=i((z,N)=>{var O=a(),L=m();N.exports=_;function _(I,P){var q=new O,Y={},F=new L,Q;function B(V){var W=V.v===Q?V.w:V.v,H=F.priority(W);if(H!==void 0){var K=P(V);K<H&&(Y[W]=Q,F.decrease(W,K))}}if(I.nodeCount()===0)return q;I.nodes().forEach(function(V){F.add(V,Number.POSITIVE_INFINITY),q.setNode(V)}),F.decrease(I.nodes()[0],0);for(var S=!1;F.size()>0;){if(Q=F.removeMin(),Object.hasOwn(Y,Q))q.setEdge(Q,Y[Q]);else{if(S)throw new Error("Input graph is not connected: "+I);S=!0}I.nodeEdges(Q).forEach(B)}return q}}),A=i((z,N)=>{var O=u(),L=h();N.exports=_;function _(P,q,Y,F){return I(P,q,Y,F||function(Q){return P.outEdges(Q)})}function I(P,q,Y,F){if(Y===void 0)return O(P,q,Y,F);for(var Q=!1,B=P.nodes(),S=0;S<B.length;S++){for(var V=F(B[S]),W=0;W<V.length;W++){var H=V[W],K=H.v===B[S]?H.v:H.w,te=K===H.v?H.w:H.v;Y({v:K,w:te})<0&&(Q=!0)}if(Q)return L(P,q,Y,F)}return O(P,q,Y,F)}}),T=i((z,N)=>{N.exports={bellmanFord:h(),components:f(),dijkstra:u(),dijkstraAll:x(),extractPath:E(),findCycles:v(),floydWarshall:y(),isAcyclic:b(),postorder:M(),preorder:R(),prim:D(),shortestPaths:A(),reduce:j(),tarjan:C(),topsort:g()}}),$=l();n.exports={Graph:$.Graph,json:d(),alg:T(),version:$.version}}),Gf=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}),Kf=Pe((e,n)=>{var s=Lt().Graph,r=Gf();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=[],E=m[m.length-1],C=m[0],v;for(;f.nodeCount();){for(;v=C.dequeue();)c(f,m,u,v);for(;v=E.dequeue();)c(f,m,u,v);if(f.nodeCount()){for(let y=m.length-2;y>0;--y)if(v=m[y].dequeue(),v){x=x.concat(c(f,m,u,v,!0));break}}}return x}function c(f,m,u,x,E){let C=E?[]:void 0;return f.inEdges(x.v).forEach(v=>{let y=f.edge(v),g=f.node(v.v);E&&C.push({v:v.v,w:v.w}),g.out-=y,d(m,u,g)}),f.outEdges(x.v).forEach(v=>{let y=f.edge(v),g=v.w,b=f.node(g);b.in-=y,d(m,u,b)}),f.removeNode(x.v),C}function l(f,m){let u=new s,x=0,E=0;f.nodes().forEach(y=>{u.setNode(y,{v:y,in:0,out:0})}),f.edges().forEach(y=>{let g=u.edge(y.v,y.w)||0,b=m(y),j=g+b;u.setEdge(y.v,y.w,j),E=Math.max(E,u.node(y.v).out+=b),x=Math.max(x,u.node(y.w).in+=b)});let C=h(E+x+3).map(()=>new r),v=x+1;return u.nodes().forEach(y=>{d(C,v,u.node(y))}),{graph:u,buckets:C,zeroIdx:v}}function d(f,m,u){u.out?u.in?f[u.out-u.in+m].enqueue(u):f[f.length-1].enqueue(u):f[0].enqueue(u)}function h(f){let m=[];for(let u=0;u<f;u++)m.push(u);return m}}),Fe=Pe((e,n)=>{var s=Lt().Graph;n.exports={addBorderNode:m,addDummyNode:r,applyWithChunking:E,asNonCompoundGraph:o,buildLayerMatrix:d,intersectRect:l,mapValues:R,maxRank:C,normalizeRanks:h,notime:g,partition:v,pick:M,predecessorWeights:c,range:k,removeEmptyRanks:f,simplify:i,successorWeights:a,time:y,uniqueId:j,zipObject:D};function r(A,T,$,z){for(var N=z;A.hasNode(N);)N=j(z);return $.dummy=T,A.setNode(N,$),N}function i(A){let T=new s().setGraph(A.graph());return A.nodes().forEach($=>T.setNode($,A.node($))),A.edges().forEach($=>{let z=T.edge($.v,$.w)||{weight:0,minlen:1},N=A.edge($);T.setEdge($.v,$.w,{weight:z.weight+N.weight,minlen:Math.max(z.minlen,N.minlen)})}),T}function o(A){let T=new s({multigraph:A.isMultigraph()}).setGraph(A.graph());return A.nodes().forEach($=>{A.children($).length||T.setNode($,A.node($))}),A.edges().forEach($=>{T.setEdge($,A.edge($))}),T}function a(A){let T=A.nodes().map($=>{let z={};return A.outEdges($).forEach(N=>{z[N.w]=(z[N.w]||0)+A.edge(N).weight}),z});return D(A.nodes(),T)}function c(A){let T=A.nodes().map($=>{let z={};return A.inEdges($).forEach(N=>{z[N.v]=(z[N.v]||0)+A.edge(N).weight}),z});return D(A.nodes(),T)}function l(A,T){let $=A.x,z=A.y,N=T.x-$,O=T.y-z,L=A.width/2,_=A.height/2;if(!N&&!O)throw new Error("Not possible to find intersection inside of the rectangle");let I,P;return Math.abs(O)*L>Math.abs(N)*_?(O<0&&(_=-_),I=_*N/O,P=_):(N<0&&(L=-L),I=L,P=L*O/N),{x:$+I,y:z+P}}function d(A){let T=k(C(A)+1).map(()=>[]);return A.nodes().forEach($=>{let z=A.node($),N=z.rank;N!==void 0&&(T[N][z.order]=$)}),T}function h(A){let T=A.nodes().map(z=>{let N=A.node(z).rank;return N===void 0?Number.MAX_VALUE:N}),$=E(Math.min,T);A.nodes().forEach(z=>{let N=A.node(z);Object.hasOwn(N,"rank")&&(N.rank-=$)})}function f(A){let T=A.nodes().map(L=>A.node(L).rank).filter(L=>L!==void 0),$=E(Math.min,T),z=[];A.nodes().forEach(L=>{let _=A.node(L).rank-$;z[_]||(z[_]=[]),z[_].push(L)});let N=0,O=A.graph().nodeRankFactor;Array.from(z).forEach((L,_)=>{L===void 0&&_%O!==0?--N:L!==void 0&&N&&L.forEach(I=>A.node(I).rank+=N)})}function m(A,T,$,z){let N={width:0,height:0};return arguments.length>=4&&(N.rank=$,N.order=z),r(A,"border",N,T)}function u(A,T=x){let $=[];for(let z=0;z<A.length;z+=T){let N=A.slice(z,z+T);$.push(N)}return $}var x=65535;function E(A,T){if(T.length>x){let $=u(T);return A.apply(null,$.map(z=>A.apply(null,z)))}else return A.apply(null,T)}function C(A){let T=A.nodes().map($=>{let z=A.node($).rank;return z===void 0?Number.MIN_VALUE:z});return E(Math.max,T)}function v(A,T){let $={lhs:[],rhs:[]};return A.forEach(z=>{T(z)?$.lhs.push(z):$.rhs.push(z)}),$}function y(A,T){let $=Date.now();try{return T()}finally{console.log(A+" time: "+(Date.now()-$)+"ms")}}function g(A,T){return T()}var b=0;function j(A){var T=++b;return A+(""+T)}function k(A,T,$=1){T==null&&(T=A,A=0);let z=O=>O<T;$<0&&(z=O=>T<O);let N=[];for(let O=A;z(O);O+=$)N.push(O);return N}function M(A,T){let $={};for(let z of T)A[z]!==void 0&&($[z]=A[z]);return $}function R(A,T){let $=T;return typeof T=="string"&&($=z=>z[T]),Object.entries(A).reduce((z,[N,O])=>(z[N]=$(O,N),z),{})}function D(A,T){return A.reduce(($,z,N)=>($[z]=T[N],$),{})}}),Uf=Pe((e,n)=>{var s=Kf(),r=Fe().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)}})}}),Xf=Pe((e,n)=>{var s=Fe();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 E,C,v;for(v=0,++d;d<f;++v,++d)u.points=[],C={width:0,height:0,edgeLabel:u,edgeObj:c,rank:d},E=s.addDummyNode(a,"edge",C,"_d"),d===x&&(C.width=u.width,C.height=u.height,C.dummy="edge-label",C.labelpos=u.labelpos),a.setEdge(l,E,{weight:u.weight},m),v===0&&a.graph().dummyChains.push(E),l=E;a.setEdge(l,h,{weight:u.weight},m)}function o(a){a.graph().dummyChains.forEach(c=>{let l=a.node(c),d=l.edgeLabel,h;for(a.setEdge(l.edgeObj,d);l.dummy;)h=a.successors(c)[0],a.removeNode(c),d.points.push({x:l.x,y:l.y}),l.dummy==="edge-label"&&(d.x=l.x,d.y=l.y,d.width=l.width,d.height=l.height),c=h,l=a.node(c)})}}),ss=Pe((e,n)=>{var{applyWithChunking:s}=Fe();n.exports={longestPath:r,slack:i};function r(o){var a={};function c(l){var d=o.node(l);if(Object.hasOwn(a,l))return d.rank;a[l]=!0;let h=o.outEdges(l).map(m=>m==null?Number.POSITIVE_INFINITY:c(m.w)-o.edge(m).minlen);var f=s(Math.min,h);return f===Number.POSITIVE_INFINITY&&(f=0),d.rank=f}o.sources().forEach(c)}function i(o,a){return o.node(a.w).rank-o.node(a.v).rank-o.edge(a).minlen}}),xl=Pe((e,n)=>{var s=Lt().Graph,r=ss().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)}}),Zf=Pe((e,n)=>{var s=xl(),r=ss().slack,i=ss().longestPath,o=Lt().alg.preorder,a=Lt().alg.postorder,c=Fe().simplify;n.exports=l,l.initLowLimValues=m,l.initCutValues=d,l.calcCutValue=f,l.leaveEdge=x,l.enterEdge=E,l.exchangeEdges=C;function l(b){b=c(b),i(b);var j=s(b);m(j),d(j,b);for(var k,M;k=x(j);)M=E(j,b,k),C(j,b,k,M)}function d(b,j){var k=a(b,b.nodes());k=k.slice(0,k.length-1),k.forEach(M=>h(b,j,M))}function h(b,j,k){var M=b.node(k),R=M.parent;b.edge(k,R).cutvalue=f(b,j,k)}function f(b,j,k){var M=b.node(k),R=M.parent,D=!0,A=j.edge(k,R),T=0;return A||(D=!1,A=j.edge(R,k)),T=A.weight,j.nodeEdges(k).forEach($=>{var z=$.v===k,N=z?$.w:$.v;if(N!==R){var O=z===D,L=j.edge($).weight;if(T+=O?L:-L,y(b,k,N)){var _=b.edge(k,N).cutvalue;T+=O?-_:_}}}),T}function m(b,j){arguments.length<2&&(j=b.nodes()[0]),u(b,{},1,j)}function u(b,j,k,M,R){var D=k,A=b.node(M);return j[M]=!0,b.neighbors(M).forEach(T=>{Object.hasOwn(j,T)||(k=u(b,j,k,T,M))}),A.low=D,A.lim=k++,R?A.parent=R:delete A.parent,k}function x(b){return b.edges().find(j=>b.edge(j).cutvalue<0)}function E(b,j,k){var M=k.v,R=k.w;j.hasEdge(M,R)||(M=k.w,R=k.v);var D=b.node(M),A=b.node(R),T=D,$=!1;D.lim>A.lim&&(T=A,$=!0);var z=j.edges().filter(N=>$===g(b,b.node(N.v),T)&&$!==g(b,b.node(N.w),T));return z.reduce((N,O)=>r(j,O)<r(j,N)?O:N)}function C(b,j,k,M){var R=k.v,D=k.w;b.removeEdge(R,D),b.setEdge(M.v,M.w,{}),m(b),d(b,j),v(b,j)}function v(b,j){var k=b.nodes().find(R=>!j.node(R).parent),M=o(b,k);M=M.slice(1),M.forEach(R=>{var D=b.node(R).parent,A=j.edge(R,D),T=!1;A||(A=j.edge(D,R),T=!0),j.node(R).rank=j.node(D).rank+(T?A.minlen:-A.minlen)})}function y(b,j,k){return b.hasEdge(j,k)}function g(b,j,k){return k.low<=j.lim&&j.lim<=k.lim}}),Qf=Pe((e,n)=>{var s=ss(),r=s.longestPath,i=xl(),o=Zf();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)}}),Jf=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],E=!0;for(;c!==d.w;){if(l=o.node(c),E){for(;(x=f[u])!==m&&o.node(x).maxRank<l.rank;)u++;x===m&&(E=!1)}if(!E){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}}),eh=Pe((e,n)=>{var s=Fe();n.exports={run:r,cleanup:c};function r(l){let d=s.addDummyNode(l,"root",{},"_root"),h=o(l),f=Object.values(h),m=s.applyWithChunking(Math.max,f)-1,u=2*m+1;l.graph().nestingRoot=d,l.edges().forEach(E=>l.edge(E).minlen*=u);let x=a(l)+1;l.children().forEach(E=>i(l,d,u,x,m,h,E)),l.graph().nodeRankFactor=u}function i(l,d,h,f,m,u,x){let E=l.children(x);if(!E.length){x!==d&&l.setEdge(d,x,{weight:0,minlen:h});return}let C=s.addBorderNode(l,"_bt"),v=s.addBorderNode(l,"_bb"),y=l.node(x);l.setParent(C,x),y.borderTop=C,l.setParent(v,x),y.borderBottom=v,E.forEach(g=>{i(l,d,h,f,m,u,g);let b=l.node(g),j=b.borderTop?b.borderTop:g,k=b.borderBottom?b.borderBottom:g,M=b.borderTop?f:2*f,R=j!==k?1:m-u[x]+1;l.setEdge(C,j,{weight:M,minlen:R,nestingEdge:!0}),l.setEdge(k,v,{weight:M,minlen:R,nestingEdge:!0})}),l.parent(x)||l.setEdge(d,C,{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)})}}),th=Pe((e,n)=>{var s=Fe();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})}}),nh=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}}),rh=Pe((e,n)=>{var s=Fe();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}}),sh=Pe((e,n)=>{var s=Fe().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,E)=>E)),d=a.flatMap(x=>o.outEdges(x).map(E=>({pos:l[E.w],weight:o.edge(E).weight})).sort((E,C)=>E.pos-C.pos)),h=1;for(;h<c.length;)h<<=1;let f=2*h-1;h-=1;let m=new Array(f).fill(0),u=0;return d.forEach(x=>{let E=x.pos+h;m[E]+=x.weight;let C=0;for(;E>0;)E%2&&(C+=m[E+1]),E=E-1>>1,m[E]+=x.weight;u+=x.weight*C}),u}}),oh=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}})}}),ah=Pe((e,n)=>{var s=Fe();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}}),ih=Pe((e,n)=>{var s=Fe();n.exports=r;function r(a,c){let l=s.partition(a,C=>Object.hasOwn(C,"barycenter")),d=l.lhs,h=l.rhs.sort((C,v)=>v.i-C.i),f=[],m=0,u=0,x=0;d.sort(o(!!c)),x=i(f,h,x),d.forEach(C=>{x+=C.vs.length,f.push(C.vs),m+=C.barycenter*C.weight,u+=C.weight,x=i(f,h,x)});let E={vs:f.flat(!0)};return u&&(E.barycenter=m/u,E.weight=u),E}function i(a,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}}),lh=Pe((e,n)=>{var s=oh(),r=ah(),i=ih();n.exports=o;function o(l,d,h,f){let m=l.children(d),u=l.node(d),x=u?u.borderLeft:void 0,E=u?u.borderRight:void 0,C={};x&&(m=m.filter(b=>b!==x&&b!==E));let v=s(l,m);v.forEach(b=>{if(l.children(b.v).length){let j=o(l,b.v,h,f);C[b.v]=j,Object.hasOwn(j,"barycenter")&&c(b,j)}});let y=r(v,h);a(y,C);let g=i(y,f);if(x&&(g.vs=[x,g.vs,E].flat(!0),l.predecessors(x).length)){let b=l.node(l.predecessors(x)[0]),j=l.node(l.predecessors(E)[0]);Object.hasOwn(g,"barycenter")||(g.barycenter=0,g.weight=0),g.barycenter=(g.barycenter*g.weight+b.order+j.order)/(g.weight+2),g.weight+=2}return g}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)}}),ch=Pe((e,n)=>{var s=Lt().Graph,r=Fe();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(E=>{let C=E.v===m?E.w:E.v,v=f.edge(C,m),y=v!==void 0?v.weight:0;f.setEdge(C,m,{weight:a.edge(E).weight+y})}),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}}),dh=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}})}}),uh=Pe((e,n)=>{var s=rh(),r=sh(),i=lh(),o=ch(),a=dh(),c=Lt().Graph,l=Fe();n.exports=d;function d(u,x={}){if(typeof x.customOrder=="function"){x.customOrder(u,d);return}let E=l.maxRank(u),C=h(u,l.range(1,E+1),"inEdges"),v=h(u,l.range(E-1,-1,-1),"outEdges"),y=s(u);if(m(u,y),x.disableOptimalOrderHeuristic)return;let g=Number.POSITIVE_INFINITY,b,j=x.constraints||[];for(let k=0,M=0;M<4;++k,++M){f(k%2?C:v,k%4>=2,j),y=l.buildLayerMatrix(u);let R=r(u,y);R<g?(M=0,b=Object.assign({},y),g=R):R===g&&(b=structuredClone(y))}m(u,b)}function h(u,x,E){let C=new Map,v=(y,g)=>{C.has(y)||C.set(y,[]),C.get(y).push(g)};for(let y of u.nodes()){let g=u.node(y);if(typeof g.rank=="number"&&v(g.rank,y),typeof g.minRank=="number"&&typeof g.maxRank=="number")for(let b=g.minRank;b<=g.maxRank;b++)b!==g.rank&&v(b,y)}return x.map(function(y){return o(u,y,E,C.get(y)||[])})}function f(u,x,E){let C=new c;u.forEach(function(v){E.forEach(b=>C.setEdge(b.left,b.right));let y=v.graph().root,g=i(v,y,C,x);g.vs.forEach((b,j)=>v.node(b).order=j),a(v,C,g.vs)})}function m(u,x){Object.values(x).forEach(E=>E.forEach((C,v)=>u.node(C).order=v))}}),fh=Pe((e,n)=>{var s=Lt().Graph,r=Fe();n.exports={positionX:E,findType1Conflicts:i,findType2Conflicts:o,addConflict:c,hasConflict:l,verticalAlignment:d,horizontalCompaction:h,alignCoordinates:u,findSmallestWidthAlignment:m,balance:x};function i(y,g){let b={};function j(k,M){let R=0,D=0,A=k.length,T=M[M.length-1];return M.forEach(($,z)=>{let N=a(y,$),O=N?y.node(N).order:A;(N||$===T)&&(M.slice(D,z+1).forEach(L=>{y.predecessors(L).forEach(_=>{let I=y.node(_),P=I.order;(P<R||O<P)&&!(I.dummy&&y.node(L).dummy)&&c(b,_,L)})}),D=z+1,R=O)}),M}return g.length&&g.reduce(j),b}function o(y,g){let b={};function j(M,R,D,A,T){let $;r.range(R,D).forEach(z=>{$=M[z],y.node($).dummy&&y.predecessors($).forEach(N=>{let O=y.node(N);O.dummy&&(O.order<A||O.order>T)&&c(b,N,$)})})}function k(M,R){let D=-1,A,T=0;return R.forEach(($,z)=>{if(y.node($).dummy==="border"){let N=y.predecessors($);N.length&&(A=y.node(N[0]).order,j(R,T,z,D,A),T=z,D=A)}j(R,T,R.length,A,M.length)}),R}return g.length&&g.reduce(k),b}function a(y,g){if(y.node(g).dummy)return y.predecessors(g).find(b=>y.node(b).dummy)}function c(y,g,b){if(g>b){let k=g;g=b,b=k}let j=y[g];j||(y[g]=j={}),j[b]=!0}function l(y,g,b){if(g>b){let j=g;g=b,b=j}return!!y[g]&&Object.hasOwn(y[g],b)}function d(y,g,b,j){let k={},M={},R={};return g.forEach(D=>{D.forEach((A,T)=>{k[A]=A,M[A]=A,R[A]=T})}),g.forEach(D=>{let A=-1;D.forEach(T=>{let $=j(T);if($.length){$=$.sort((N,O)=>R[N]-R[O]);let z=($.length-1)/2;for(let N=Math.floor(z),O=Math.ceil(z);N<=O;++N){let L=$[N];M[T]===T&&A<R[L]&&!l(b,T,L)&&(M[L]=T,M[T]=k[T]=k[L],A=R[L])}}})}),{root:k,align:M}}function h(y,g,b,j,k){let M={},R=f(y,g,b,k),D=k?"borderLeft":"borderRight";function A(z,N){let O=R.nodes().slice(),L={},_=O.pop();for(;_;){if(L[_])z(_);else{L[_]=!0,O.push(_);for(let I of N(_))O.push(I)}_=O.pop()}}function T(z){M[z]=R.inEdges(z).reduce((N,O)=>Math.max(N,M[O.v]+R.edge(O)),0)}function $(z){let N=R.outEdges(z).reduce((L,_)=>Math.min(L,M[_.w]-R.edge(_)),Number.POSITIVE_INFINITY),O=y.node(z);N!==Number.POSITIVE_INFINITY&&O.borderType!==D&&(M[z]=Math.max(M[z],N))}return A(T,R.predecessors.bind(R)),A($,R.successors.bind(R)),Object.keys(j).forEach(z=>M[z]=M[b[z]]),M}function f(y,g,b,j){let k=new s,M=y.graph(),R=C(M.nodesep,M.edgesep,j);return g.forEach(D=>{let A;D.forEach(T=>{let $=b[T];if(k.setNode($),A){var z=b[A],N=k.edge(z,$);k.setEdge(z,$,Math.max(R(y,T,A),N||0))}A=T})}),k}function m(y,g){return Object.values(g).reduce((b,j)=>{let k=Number.NEGATIVE_INFINITY,M=Number.POSITIVE_INFINITY;Object.entries(j).forEach(([D,A])=>{let T=v(y,D)/2;k=Math.max(A+T,k),M=Math.min(A-T,M)});let R=k-M;return R<b[0]&&(b=[R,j]),b},[Number.POSITIVE_INFINITY,null])[1]}function u(y,g){let b=Object.values(g),j=r.applyWithChunking(Math.min,b),k=r.applyWithChunking(Math.max,b);["u","d"].forEach(M=>{["l","r"].forEach(R=>{let D=M+R,A=y[D];if(A===g)return;let T=Object.values(A),$=j-r.applyWithChunking(Math.min,T);R!=="l"&&($=k-r.applyWithChunking(Math.max,T)),$&&(y[D]=r.mapValues(A,z=>z+$))})})}function x(y,g){return r.mapValues(y.ul,(b,j)=>{if(g)return y[g.toLowerCase()][j];{let k=Object.values(y).map(M=>M[j]).sort((M,R)=>M-R);return(k[1]+k[2])/2}})}function E(y){let g=r.buildLayerMatrix(y),b=Object.assign(i(y,g),o(y,g)),j={},k;["u","d"].forEach(R=>{k=R==="u"?g:Object.values(g).reverse(),["l","r"].forEach(D=>{D==="r"&&(k=k.map(z=>Object.values(z).reverse()));let A=(R==="u"?y.predecessors:y.successors).bind(y),T=d(y,k,b,A),$=h(y,k,T.root,T.align,D==="r");D==="r"&&($=r.mapValues($,z=>-z)),j[R+D]=$})});let M=m(y,j);return u(j,M),x(j,y.graph().align)}function C(y,g,b){return(j,k,M)=>{let R=j.node(k),D=j.node(M),A=0,T;if(A+=R.width/2,Object.hasOwn(R,"labelpos"))switch(R.labelpos.toLowerCase()){case"l":T=-R.width/2;break;case"r":T=R.width/2;break}if(T&&(A+=b?T:-T),T=0,A+=(R.dummy?g:y)/2,A+=(D.dummy?g:y)/2,A+=D.width/2,Object.hasOwn(D,"labelpos"))switch(D.labelpos.toLowerCase()){case"l":T=D.width/2;break;case"r":T=-D.width/2;break}return T&&(A+=b?T:-T),T=0,A}}function v(y,g){return y.node(g).width}}),hh=Pe((e,n)=>{var s=Fe(),r=fh().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 E=a.node(x).height;return u>E?u:E},0);f.forEach(u=>{let x=a.node(u);d==="top"?x.y=h+x.height/2:d==="bottom"?x.y=h+m-x.height/2:x.y=h+m/2}),h+=m+l})}}),mh=Pe((e,n)=>{var s=Uf(),r=Xf(),i=Qf(),o=Fe().normalizeRanks,a=Jf(),c=Fe().removeEmptyRanks,l=eh(),d=th(),h=nh(),f=uh(),m=hh(),u=Fe(),x=Lt().Graph;n.exports=E;function E(S,V={}){let W=V.debugTiming?u.time:u.notime;return W("layout",()=>{let H=W(" buildLayoutGraph",()=>A(S));return W(" runLayout",()=>C(H,W,V)),W(" updateInputGraph",()=>v(S,H)),H})}function C(S,V,W){V(" makeSpaceForEdgeLabels",()=>T(S)),V(" removeSelfEdges",()=>q(S)),V(" acyclic",()=>s.run(S)),V(" nestingGraph.run",()=>l.run(S)),V(" rank",()=>i(u.asNonCompoundGraph(S))),V(" injectEdgeLabelProxies",()=>$(S)),V(" removeEmptyRanks",()=>c(S)),V(" nestingGraph.cleanup",()=>l.cleanup(S)),V(" normalizeRanks",()=>o(S)),V(" assignRankMinMax",()=>z(S)),V(" removeEdgeLabelProxies",()=>N(S)),V(" normalize.run",()=>r.run(S)),V(" parentDummyChains",()=>a(S)),V(" addBorderSegments",()=>d(S)),V(" order",()=>f(S,W)),V(" insertSelfEdges",()=>Y(S)),V(" adjustCoordinateSystem",()=>h.adjust(S)),V(" position",()=>m(S)),V(" positionSelfEdges",()=>F(S)),V(" removeBorderNodes",()=>P(S)),V(" normalize.undo",()=>r.undo(S)),V(" fixupEdgeLabelCoords",()=>_(S)),V(" undoCoordinateSystem",()=>h.undo(S)),V(" translateGraph",()=>O(S)),V(" assignNodeIntersects",()=>L(S)),V(" reversePoints",()=>I(S)),V(" acyclic.undo",()=>s.undo(S))}function v(S,V){S.nodes().forEach(W=>{let H=S.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))}),S.edges().forEach(W=>{let H=S.edge(W),K=V.edge(W);H.points=K.points,Object.hasOwn(K,"x")&&(H.x=K.x,H.y=K.y)}),S.graph().width=V.graph().width,S.graph().height=V.graph().height}var y=["nodesep","edgesep","ranksep","marginx","marginy"],g={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},b=["acyclicer","ranker","rankdir","align","rankalign"],j=["width","height","rank"],k={width:0,height:0},M=["minlen","weight","width","height","labeloffset"],R={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},D=["labelpos"];function A(S){let V=new x({multigraph:!0,compound:!0}),W=B(S.graph());return V.setGraph(Object.assign({},g,Q(W,y),u.pick(W,b))),S.nodes().forEach(H=>{let K=B(S.node(H)),te=Q(K,j);Object.keys(k).forEach(re=>{te[re]===void 0&&(te[re]=k[re])}),V.setNode(H,te),V.setParent(H,S.parent(H))}),S.edges().forEach(H=>{let K=B(S.edge(H));V.setEdge(H,Object.assign({},R,Q(K,M),u.pick(K,D)))}),V}function T(S){let V=S.graph();V.ranksep/=2,S.edges().forEach(W=>{let H=S.edge(W);H.minlen*=2,H.labelpos.toLowerCase()!=="c"&&(V.rankdir==="TB"||V.rankdir==="BT"?H.width+=H.labeloffset:H.height+=H.labeloffset)})}function $(S){S.edges().forEach(V=>{let W=S.edge(V);if(W.width&&W.height){let H=S.node(V.v),K={rank:(S.node(V.w).rank-H.rank)/2+H.rank,e:V};u.addDummyNode(S,"edge-proxy",K,"_ep")}})}function z(S){let V=0;S.nodes().forEach(W=>{let H=S.node(W);H.borderTop&&(H.minRank=S.node(H.borderTop).rank,H.maxRank=S.node(H.borderBottom).rank,V=Math.max(V,H.maxRank))}),S.graph().maxRank=V}function N(S){S.nodes().forEach(V=>{let W=S.node(V);W.dummy==="edge-proxy"&&(S.edge(W.e).labelRank=W.rank,S.removeNode(V))})}function O(S){let V=Number.POSITIVE_INFINITY,W=0,H=Number.POSITIVE_INFINITY,K=0,te=S.graph(),re=te.marginx||0,fe=te.marginy||0;function J(Z){let ce=Z.x,ae=Z.y,pe=Z.width,ge=Z.height;V=Math.min(V,ce-pe/2),W=Math.max(W,ce+pe/2),H=Math.min(H,ae-ge/2),K=Math.max(K,ae+ge/2)}S.nodes().forEach(Z=>J(S.node(Z))),S.edges().forEach(Z=>{let ce=S.edge(Z);Object.hasOwn(ce,"x")&&J(ce)}),V-=re,H-=fe,S.nodes().forEach(Z=>{let ce=S.node(Z);ce.x-=V,ce.y-=H}),S.edges().forEach(Z=>{let ce=S.edge(Z);ce.points.forEach(ae=>{ae.x-=V,ae.y-=H}),Object.hasOwn(ce,"x")&&(ce.x-=V),Object.hasOwn(ce,"y")&&(ce.y-=H)}),te.width=W-V+re,te.height=K-H+fe}function L(S){S.edges().forEach(V=>{let W=S.edge(V),H=S.node(V.v),K=S.node(V.w),te,re;W.points?(te=W.points[0],re=W.points[W.points.length-1]):(W.points=[],te=K,re=H),W.points.unshift(u.intersectRect(H,te)),W.points.push(u.intersectRect(K,re))})}function _(S){S.edges().forEach(V=>{let W=S.edge(V);if(Object.hasOwn(W,"x"))switch((W.labelpos==="l"||W.labelpos==="r")&&(W.width-=W.labeloffset),W.labelpos){case"l":W.x-=W.width/2+W.labeloffset;break;case"r":W.x+=W.width/2+W.labeloffset;break}})}function I(S){S.edges().forEach(V=>{let W=S.edge(V);W.reversed&&W.points.reverse()})}function P(S){S.nodes().forEach(V=>{if(S.children(V).length){let W=S.node(V),H=S.node(W.borderTop),K=S.node(W.borderBottom),te=S.node(W.borderLeft[W.borderLeft.length-1]),re=S.node(W.borderRight[W.borderRight.length-1]);W.width=Math.abs(re.x-te.x),W.height=Math.abs(K.y-H.y),W.x=te.x+W.width/2,W.y=H.y+W.height/2}}),S.nodes().forEach(V=>{S.node(V).dummy==="border"&&S.removeNode(V)})}function q(S){S.edges().forEach(V=>{if(V.v===V.w){var W=S.node(V.v);W.selfEdges||(W.selfEdges=[]),W.selfEdges.push({e:V,label:S.edge(V)}),S.removeEdge(V)}})}function Y(S){var V=u.buildLayerMatrix(S);V.forEach(W=>{var H=0;W.forEach((K,te)=>{var re=S.node(K);re.order=te+H,(re.selfEdges||[]).forEach(fe=>{u.addDummyNode(S,"selfedge",{width:fe.label.width,height:fe.label.height,rank:re.rank,order:te+ ++H,e:fe.e,label:fe.label},"_se")}),delete re.selfEdges})})}function F(S){S.nodes().forEach(V=>{var W=S.node(V);if(W.dummy==="selfedge"){var H=S.node(W.e.v),K=H.x+H.width/2,te=H.y,re=W.x-K,fe=H.height/2;S.setEdge(W.e,W.label),S.removeNode(V),W.label.points=[{x:K+2*re/3,y:te-fe},{x:K+5*re/6,y:te-fe},{x:K+re,y:te},{x:K+5*re/6,y:te+fe},{x:K+2*re/3,y:te+fe}],W.label.x=W.x,W.label.y=W.y}})}function Q(S,V){return u.mapValues(u.pick(S,V),Number)}function B(S){var V={};return S&&Object.entries(S).forEach(([W,H])=>{typeof W=="string"&&(W=W.toLowerCase()),V[W]=H}),V}}),ph=Pe((e,n)=>{var s=Fe(),r=Lt().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}}),gh=Pe((e,n)=>{n.exports="2.0.4"}),xh=Pe((e,n)=>{n.exports={graphlib:Lt(),layout:mh(),debug:ph(),util:{time:Fe().time,notime:Fe().notime},version:gh()}});const Ma=xh();const Ta={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"}},bh={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function yh({data:e}){const{t:n}=$e(["work","common"]),{task:s,agentName:r,selected:i,direction:o="TB",isExpandedRoot:a,onCollapse:c}=e,l=Ta[s.status]??Ta.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"?ve.Left:ve.Top,m=o==="LR"?ve.Right:ve.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(mn,{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 ${bh[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(mn,{type:"source",position:m,className:"!bg-border-default !w-2 !h-2"}),a&&c&&t.jsx("button",{onClick:u=>{u.stopPropagation(),c()},className:"absolute top-1/2 -translate-y-1/2 -right-7 w-5 h-5 rounded-full bg-surface-secondary border border-border-default flex items-center justify-center text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay transition-colors shadow-sm",title:n("work:dag.backToOverview"),children:t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})})]})}const Ia={pending:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"},in_progress:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"},completed:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"},rejected:{bg:"bg-red-500/10",border:"border-red-500/30",text:"text-red-500"},cancelled:{bg:"bg-gray-500/8",border:"border-gray-500/20",text:"text-fg-tertiary"}},Ra={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done",archived:"done"};function vh({data:e}){const{t:n}=$e(["work","common"]),{req:s,selected:r,direction:i="TB",isExpandedRoot:o,onCollapse:a}=e,c=Ia[s.status]??Ia.pending,l=i==="LR"?ve.Left:ve.Top,d=i==="LR"?ve.Right:ve.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(mn,{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(mn,{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 wh={task:yh,requirement:vh};function kh({nodeIds:e,rfRef:n}){const s=gf();return p.useEffect(()=>{if(e.length===0)return;const r=setTimeout(()=>{s(e),requestAnimationFrame(()=>{n.current?.fitView({padding:.2})})},300);return()=>clearTimeout(r)},[e.length]),null}const jh=()=>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,Nh=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 Ch(){return p.useSyncExternalStore(Nh,jh,()=>!1)}const Qr=200,Jr=80;function _a(e,n,s="TB"){const r=o=>{const a=new Ma.graphlib.Graph;a.setDefaultEdgeLabel(()=>({})),a.setGraph({rankdir:o,nodesep:40,ranksep:60});for(const c of e)a.setNode(c.id,{width:Qr,height:Jr});for(const c of n)a.setEdge(c.source,c.target);return Ma.layout(a),e.map(c=>{const l=a.node(c.id);return{...c,position:{x:(l?.x??0)-Qr/2,y:(l?.y??0)-Jr/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+Qr),c=Math.min(c,m.position.y),l=Math.max(l,m.position.y+Jr);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 Sh(e,n){const s=new Map,r=new Map;for(const a of e)r.set(a.id,a),s.set(a.id,new Set);for(const a of n)s.get(a.source)?.add(a.target),s.get(a.target)?.add(a.source);const i=new Set,o=[];for(const a of e){if(i.has(a.id))continue;const c=new Set,l=[a.id];for(;l.length>0;){const d=l.pop();if(!i.has(d)){i.add(d),c.add(d);for(const h of s.get(d)??[])i.has(h)||l.push(h)}}o.push({nodes:e.filter(d=>c.has(d.id)),edges:n.filter(d=>c.has(d.source)&&c.has(d.target))})}return o}function La(e,n){if(e.length===0)return{nodes:[],direction:"TB"};const s=Sh(e,n);if(s.length===1)return _a(e,n);let r="TB";const i=s.map(m=>{const{nodes:u,direction:x}=_a(m.nodes,m.edges);r=x;let E=1/0,C=-1/0,v=1/0,y=-1/0;for(const g of u)E=Math.min(E,g.position.x),C=Math.max(C,g.position.x+Qr),v=Math.min(v,g.position.y),y=Math.max(y,g.position.y+Jr);for(const g of u)g.position.x-=E,g.position.y-=v;return{nodes:u,w:C-E,h:y-v}});i.sort((m,u)=>u.h-m.h);const o=60,a=i.reduce((m,u)=>m+(u.w+o)*(u.h+o),0),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 Eh(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 Fn=[{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(Fn.map(e=>e.id));const Gr=new Set(Fn.filter(e=>e.id!=="done").map(e=>e.id)),_s=e=>e.status==="archived";function Mh(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 Th({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}=$e(["work","common"]),E=Ch(),[C,v]=p.useState(null),[y,g]=p.useState(null),[b,j]=p.useState(()=>new Set(Gr)),[k,M]=p.useState(m??null),[R,D]=p.useState(r??!1),A=r??R,T=p.useCallback(de=>{const se=typeof de=="function"?de(A):de;D(se),i?.(se)},[A,i]);p.useEffect(()=>{r!==void 0&&D(r)},[r]),p.useEffect(()=>{m&&M(m)},[m]);const $=p.useMemo(()=>e.filter(de=>_s(de)).length,[e]),z=p.useMemo(()=>{const de=new Set;for(const se of Fn)if(b.has(se.id))for(const xe of se.statuses)de.add(xe);return de},[b]),N=p.useMemo(()=>{const de=new Set;for(const se of e)for(const xe of Fn)if(xe.statuses.has(se.status)){de.add(xe.id);break}for(const se of n){const xe=Ra[se.status];xe&&de.add(xe)}return Fn.filter(se=>de.has(se.id))},[e,n]),O=p.useCallback(de=>{j(se=>{const xe=new Set(se);return xe.has(de)?xe.delete(de):xe.add(de),xe})},[]),L=p.useCallback((de,se="success")=>{v({msg:de,type:se}),setTimeout(()=>v(null),2500)},[]),_=p.useMemo(()=>{const de=new Map;for(const se of s)de.set(se.id,se.name);return de},[s]),I=p.useMemo(()=>{const de=new Map;for(const se of e)de.set(se.id,se);return de},[e]),P=p.useMemo(()=>{const de=new Map;for(const se of n)de.set(se.id,se);return de},[n]),q=p.useRef(!1),Y=p.useCallback(()=>{q.current=!1,M(null),c?.()},[c]),F=E?"#94a3b8":"#6b7280",Q=p.useCallback((de,se,xe)=>({id:`${de}->${se}`,source:de,target:se,animated:xe==="blocked",markerEnd:{type:Kn.ArrowClosed,width:14,height:14,color:xe==="blocked"?"#ef4444":F},style:{stroke:xe==="blocked"?"#ef4444":F,strokeWidth:1.5,cursor:"pointer"}}),[F]),{initialNodes:B,initialEdges:S,topLevelIds:V}=p.useMemo(()=>{const de=(be,Je)=>{const it=new Set,Pt=be.map(Ne=>(it.add(Ne.id),{id:Ne.id,type:"task",data:{task:Ne,agentName:Ne.assignedAgentId?_.get(Ne.assignedAgentId):void 0,selected:Ne.id===d},position:{x:0,y:0}}));for(const Ne of Je){const Ce=`req-${Ne.id}`;it.add(Ce),Pt.push({id:Ce,type:"requirement",data:{req:Ne,selected:Ne.id===h},position:{x:0,y:0}})}const et=[];for(const Ne of be)if(Ne.blockedBy)for(const Ce of Ne.blockedBy)it.has(Ce)&&et.push(Q(Ce,Ne.id,Ne.status));const bt=new Set,Gt=(Ne,Ce)=>{const Ae=`${Ne}->${Ce}`;bt.has(Ae)||(bt.add(Ae),et.push({id:Ae,source:Ne,target:Ce,markerEnd:{type:Kn.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Ne of Je){const Ce=`req-${Ne.id}`;for(const Ae of Ne.taskIds)it.has(Ae)&&Gt(Ce,Ae)}for(const Ne of be)if(Ne.requirementId){const Ce=`req-${Ne.requirementId}`;it.has(Ce)&&Gt(Ce,Ne.id)}return{nodes:Pt,edges:et}},se=e.filter(be=>z.has(be.status)&&(A||!_s(be))),xe=new Set;for(const be of Fn)b.has(be.id)&&xe.add(be.id);const Me=n.filter(be=>{const Je=Ra[be.status];return Je&&xe.has(Je)}),ye=new Set(["completed","rejected","cancelled","archived"]),Re=new Set(Me.filter(be=>!ye.has(be.status)).map(be=>be.id)),pt=new Set;for(const be of n)if(Re.has(be.id))for(const Je of be.taskIds)pt.add(Je);const gt=e.filter(be=>pt.has(be.id)&&(A||!_s(be))),jt=[...new Map([...se,...gt].map(be=>[be.id,be])).values()],{nodes:Ft,edges:Qe}=de(jt,Me),Yt=new Set;for(const be of Qe)Yt.add(be.target);const dt=new Set(Ft.filter(be=>!Yt.has(be.id)).map(be=>be.id));if(!k||!dt.has(k)){const be=Ft,{nodes:Je,direction:it}=La(be,Qe);return{initialNodes:Je.map(et=>({...et,data:{...et.data,direction:it}})),initialEdges:Qe,topLevelIds:dt}}const{nodes:At,edges:ut}=de(e,n),Ue=Mh(k,I,P,e),Dt=At.filter(be=>Ue.has(be.id)).map(be=>be.id===k?{...be,data:{...be.data,isExpandedRoot:!0,onCollapse:Y}}:be),xt=ut.filter(be=>Ue.has(be.source)&&Ue.has(be.target)),{nodes:st,direction:Nt}=La(Dt,xt);return{initialNodes:st.map(be=>({...be,data:{...be.data,direction:Nt}})),initialEdges:xt,topLevelIds:dt}},[e,n,_,I,P,Q,z,b,A,d,h,k,Y]),[W,H,K]=xf(B),[te,re,fe]=bf(S),J=p.useRef(null),Z=p.useRef({groupFilter:b,showArchived:A});p.useEffect(()=>{const de=Z.current;(de.groupFilter!==b||de.showArchived!==A)&&(q.current=!1,M(null),Z.current={groupFilter:b,showArchived:A})},[b,A]),p.useEffect(()=>{H(B),re(S),q.current||requestAnimationFrame(()=>{J.current?.fitView({padding:.2,duration:300})})},[B,S,H,re]),p.useEffect(()=>{const de=setTimeout(()=>{J.current?.fitView({padding:.2,duration:300})},50);return()=>clearTimeout(de)},[f]);const ce=p.useCallback(de=>{de&&(q.current=!0)},[]),ae=p.useCallback((de,se)=>{if(!k&&V.has(se.id)&&(q.current=!1,M(se.id)),se.id.startsWith("req-")){const xe=P.get(se.id.slice(4));xe&&a&&a(xe)}else{const xe=I.get(se.id);xe&&o&&o(xe)}},[I,P,o,a,V,k]),pe=p.useCallback(async de=>{const{source:se,target:xe}=de;if(!se||!xe||se===xe)return;const Me=I.get(xe);if(!Me)return;if(Me.blockedBy?.includes(se)){L(x("work:dag.toast.dependencyExists"),"error");return}if(Eh(I,se,xe)){L(x("work:dag.toast.cycleError"),"error");return}const ye=[...Me.blockedBy??[],se];try{await le.tasks.update(xe,{blockedBy:ye}),L(x("work:dag.toast.dependencyAdded")),l?.()}catch(Re){L(x("work:dag.toast.failed",{message:Re instanceof Error?Re.message:String(Re)}),"error")}},[I,L,l,x]),ge=p.useCallback((de,se)=>{g(se)},[]),U=p.useCallback(async()=>{if(!y)return;const de=I.get(y.target);if(!de){g(null);return}const se=(de.blockedBy??[]).filter(xe=>xe!==y.source);try{await le.tasks.update(y.target,{blockedBy:se}),L(x("work:dag.toast.dependencyRemoved")),l?.()}catch(xe){L(x("work:dag.toast.failed",{message:xe instanceof Error?xe.message:String(xe)}),"error")}g(null)},[y,I,L,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 oe=b.size===Gr.size&&[...Gr].every(de=>b.has(de))&&!A,ue=y?I.get(y.source):null,we=y?I.get(y.target):null;return t.jsxs("div",{className:"flex-1 min-h-0 relative",style:{height:"100%"},children:[t.jsxs(pf,{nodes:W,edges:te,onNodesChange:K,onEdgesChange:fe,onNodeClick:ae,onConnect:pe,onEdgeClick:ge,onMoveEnd:ce,onInit:de=>{J.current=de},nodeTypes:wh,fitView:!0,minZoom:.3,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[u&&t.jsx(kh,{nodeIds:W.map(de=>de.id),rfRef:J}),t.jsx(jf,{color:E?"#cbd5e1":"#374151",gap:20,size:1}),t.jsx(If,{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(Vf,{nodeColor:de=>{const se=de.data?.task,xe=se?.status;return se?.taskType==="scheduled"?"#8b8fa3":xe==="completed"||xe==="accepted"?"#10b981":xe==="in_progress"?"#f59e0b":xe==="blocked"||xe==="failed"?"#ef4444":E?"#94a3b8":"#6b7280"},maskColor:E?"rgba(255,255,255,0.7)":"rgba(0,0,0,0.7)",className:"!bg-surface-secondary !border-border-default"})]}),t.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 px-3 py-1.5 bg-surface-secondary/90 border border-border-default rounded-lg backdrop-blur-sm z-10 flex flex-col items-center gap-1",children:[t.jsxs("div",{className:"flex items-center gap-1 flex-wrap justify-center",children:[N.map(de=>{const se=b.has(de.id);return t.jsx("button",{onClick:()=>O(de.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${se?`${de.color.bg} ${de.color.border} ${de.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:x(`work:dag.filter.${de.id}`)},de.id)}),$>0&&t.jsx("button",{onClick:()=>T(de=>!de),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:$})}),!oe&&t.jsx("button",{onClick:()=>{j(new Set(Gr)),T(!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:[k?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")})]})]}),C&&t.jsx("div",{className:`absolute bottom-4 left-1/2 -translate-x-1/2 px-4 py-2 rounded-lg text-xs font-medium shadow-xl border backdrop-blur-sm transition-opacity ${C.type==="success"?"bg-green-500/15 border-green-500/30 text-green-600":"bg-red-500/15 border-red-500/30 text-red-600"}`,children:C.msg}),y&&t.jsx("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-50 backdrop-blur-[2px]",onClick:()=>g(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:de=>de.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:we?.title??y.target.slice(-8),source:ue?.title??y.source.slice(-8)})}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>g(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:U,className:"px-3 py-1.5 text-xs text-red-500 bg-red-600/20 hover:bg-red-600/30 rounded-lg border border-red-500/40 hover:border-red-500/60 transition-colors",children:x("common:remove")})]})]})})]})}function Ih({orgId:e,onCreated:n,onClose:s}){const{t:r}=$e(["work","common"]);Gl(!0);const[i,o]=p.useState(""),[a,c]=p.useState(""),[l,d]=p.useState(""),[h,f]=p.useState("main"),[m,u]=p.useState([]),[x,E]=p.useState([]),[C,v]=p.useState(!1),[y,g]=p.useState(""),[b,j]=p.useState(!1),k=yr();p.useEffect(()=>{le.teams.list().then(D=>E(D.teams)).catch(()=>{})},[]),p.useEffect(()=>{const D=A=>{A.key==="Escape"&&s()};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[s]);const M=p.useCallback(async D=>{if(D?.preventDefault(),j(!0),!(!i.trim()||C)){v(!0),g("");try{const A=l.trim()?[{url:l.trim(),defaultBranch:h.trim()||"main"}]:[],T=await le.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(T.project)}catch(A){g(A instanceof Error?A.message:r("project.failedToCreate"))}v(!1)}},[i,a,l,h,m,e,C,n,r]),R=b&&!i.trim();return Kl.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 ${k?"w-full":"w-[520px]"}`,onClick:D=>D.stopPropagation(),onSubmit:M,children:[t.jsx("h3",{className:"text-base font-semibold mb-5",children:r("project.newProject")}),t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:r("project.projectName")}),t.jsx("input",{value:i,onChange:D=>{o(D.target.value),g("")},onBlur:()=>j(!0),placeholder:r("project.projectNamePlaceholder"),className:`input ${R?"!border-red-500 focus:!ring-red-500/25":""}`,autoFocus:!k}),R&&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(T=>A?T.filter($=>$!==D.id):[...T,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"})]})]}),y&&t.jsx("div",{className:"text-xs text-red-400 bg-red-500/10 rounded-lg px-3 py-2",children:y}),t.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[t.jsx("button",{type:"button",onClick:s,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:r("common:cancel")}),t.jsx("button",{type:"submit",disabled:!i.trim()||C,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-white",children:r(C?"common:creating":"project.createProject")})]})]})]})}),document.body)}function Rh({projects:e,selectedProjectId:n,allSelected:s,taskCounts:r,totalTaskCount:i,onSelectAll:o,onSelectProject:a,onEditProject:c,onCreateProject:l,onCollapse:d,width:h,onResizeStart:f,hidden:m,focused:u,onActivate:x}){const{t:E}=$e(["work","common"]),C=s??n==null;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{"data-keyboard-pane":"l1",onPointerDown:()=>x?.(),className:"bg-surface-primary flex flex-col shrink-0 border-r border-border-default/60",style:m?{display:"none"}:h!=null?{width:h}:void 0,children:[t.jsxs("div",{"data-electron-drag":!0,className:"px-3 h-14 flex items-center shrink-0 gap-2",children:[d&&t.jsx("button",{type:"button","data-no-drag":!0,onClick:d,className:"w-8 h-8 flex items-center justify-center rounded-lg transition-colors shrink-0 bg-brand-500/15 text-brand-500 hover:bg-brand-500/25",title:E("common:shortcuts.toggleLeft"),children:t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),t.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),t.jsx("h2",{className:"text-sm font-semibold text-fg-primary truncate",children:E("work:task.projects",{defaultValue:"Projects"})}),t.jsx("button",{type:"button","data-no-drag":!0,onClick:l,className:"ml-auto w-7 h-7 flex items-center justify-center rounded-md text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated transition-colors",title:E("work:project.newProject"),children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),t.jsx("div",{className:"flex-1 overflow-y-auto px-2 pb-3 space-y-0.5",children:e.length===0?t.jsxs("div",{className:"px-2 py-8 text-center space-y-3",children:[t.jsx("div",{className:"w-10 h-10 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:t.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),t.jsx("p",{className:"text-[11px] text-fg-tertiary leading-relaxed px-1",children:E("work:task.emptyNoProjectsHint")}),t.jsx("button",{type:"button",onClick:l,className:"inline-flex items-center gap-1 px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:E("work:project.newProject")})]}):t.jsxs(t.Fragment,{children:[o&&t.jsxs("button",{type:"button","data-project-id":"__all__",onClick:o,className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-left transition-colors ${C?u?"bg-brand-500/20 ring-1 ring-brand-500/40 text-brand-500":"bg-brand-500/15 text-brand-600":"text-fg-secondary hover:bg-surface-elevated hover:text-fg-primary"}`,children:[t.jsx("span",{className:`w-7 h-7 rounded-md flex items-center justify-center shrink-0 ${C?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),t.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),t.jsx("rect",{x:"14",y:"14",width:"7",height:"7"}),t.jsx("rect",{x:"3",y:"14",width:"7",height:"7"})]})}),t.jsx("span",{className:"min-w-0 flex-1",children:t.jsx("span",{className:"block text-[12px] font-medium truncate",children:E("work:task.all")})}),(i??0)>0&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:i})]}),[...e].sort((v,y)=>{const g=v.status==="archived"?1:0,b=y.status==="archived"?1:0;return g-b}).map(v=>{const y=!C&&v.id===n,g=r[v.id]??0,b=v.status==="paused",j=v.status==="archived";return t.jsxs("div",{role:"button",tabIndex:0,"data-project-id":v.id,onClick:()=>a(v.id),onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),a(v.id))},className:`group w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-left cursor-pointer transition-colors ${y?u?"bg-brand-500/20 ring-1 ring-brand-500/40 text-brand-500":"bg-brand-500/15 text-brand-600":"text-fg-secondary hover:bg-surface-elevated hover:text-fg-primary"}`,children:[t.jsx("span",{className:`w-7 h-7 rounded-md flex items-center justify-center text-[11px] font-bold shrink-0 ${y?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:v.name[0]?.toUpperCase()??"?"}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block text-[12px] font-medium truncate",children:v.name}),j&&t.jsx("span",{className:"block text-[10px] text-fg-tertiary italic",children:E("work:project.statusArchived")}),b&&t.jsx("span",{className:"block text-[10px] text-amber-500/80",children:E("work:project.statusPaused")})]}),c&&t.jsx("button",{type:"button","data-no-drag":!0,title:E("work:project.editProject"),"aria-label":E("work:project.editProject"),onClick:k=>{k.stopPropagation(),c(v.id)},className:"w-6 h-6 flex items-center justify-center rounded-md text-fg-tertiary hover:text-brand-500 hover:bg-surface-elevated transition-opacity opacity-0 group-hover:opacity-100 focus:opacity-100 shrink-0",children:t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),g>0&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:g})]},v.id)})]})})]}),!m&&f&&t.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:f,children:t.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})})]})}function _h({project:e,onUpdateProject:n}){const{t:s}=$e(["work","common"]),r=e.knowledgeBasePaths??[],[i,o]=p.useState(""),[a,c]=p.useState(!1),[l,d]=p.useState(!1),[h,f]=p.useState([]),[m,u]=p.useState(null),[x,E]=p.useState(null),C=p.useCallback(async()=>{if(e.id){d(!0);try{const{results:R}=await le.deliverables.search({projectId:e.id,source:"knowledge",limit:200});f(R)}catch(R){u({type:"error",text:`${s("work:project.kbLoadFailed")}: ${String(R)}`})}finally{d(!1)}}},[e.id,s]);p.useEffect(()=>{C()},[C]);const v=async()=>{const R=i.trim();if(!(!R||a))try{const D=[...new Set([...r,R])];await n({knowledgeBasePaths:D}),o(""),await j()}catch(D){u({type:"error",text:`${s("work:project.kbPathsSaveFailed")}: ${String(D)}`})}},y=async()=>{const R=x;if(!R||a)return;E(null);const D=r.filter(A=>A!==R);await n({knowledgeBasePaths:D}),await j(D)},g=typeof window<"u"&&!!window.markusDesktop?.selectDirectory,b=async()=>{try{const R=await window.markusDesktop?.selectDirectory?.(s("work:project.kbBrowseTitle"));R&&o(R)}catch(R){u({type:"error",text:`${s("work:project.kbBrowseFailed")}: ${String(R)}`})}},j=async R=>{if(!a){c(!0),u(null);try{const D=await le.projects.syncKnowledge(e.id,R);u({type:D.errors.length>0?"error":"success",text:s("work:project.kbSyncResult",{scanned:D.scanned,registered:D.registered,updated:D.updated,outdated:D.outdated,errors:D.errors.length})}),await C()}catch(D){u({type:"error",text:`${s("work:project.kbSyncFailed")}: ${String(D)}`})}finally{c(!1)}}},k=async()=>{await j(r.length?r:void 0)},M=R=>{kt.navigate(He.DELIVERABLES,{projectId:e.id,source:"knowledge",...R?{openDeliverable:R}:{}})};return t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 mb-3",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary",children:s("work:project.kbHeading")}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("button",{type:"button",onClick:()=>M(),className:"text-[10px] px-2 py-1 rounded-md text-fg-tertiary hover:text-brand-500 hover:bg-surface-overlay transition-colors",children:s("work:project.kbOpenInDeliverables")}),t.jsx("button",{type:"button",onClick:k,disabled:a||r.length===0,className:"text-[10px] px-2 py-1 rounded-md bg-brand-600 text-white hover:bg-brand-500 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:s(a?"work:project.kbSyncing":"work:project.kbSync")})]})]}),x&&t.jsxs("div",{className:"mb-3 px-3 py-2 bg-surface-overlay border border-border-default rounded-lg",children:[t.jsx("p",{className:"text-xs text-fg-secondary mb-2",children:s("work:project.kbRemoveConfirm",{path:x})}),t.jsxs("div",{className:"flex gap-2 justify-end",children:[t.jsx("button",{type:"button",onClick:()=>E(null),className:"px-2.5 py-1 text-xs rounded-md bg-surface-secondary text-fg-secondary hover:text-fg-primary border border-border-default transition-colors",children:s("common:cancel")}),t.jsx("button",{type:"button",onClick:()=>{y()},disabled:a,className:"px-2.5 py-1 text-xs rounded-md bg-red-600 text-white hover:bg-red-500 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:s(a?"work:project.kbSyncing":"common:confirm")})]})]}),t.jsxs("div",{className:"space-y-1.5 mb-3",children:[r.length===0&&t.jsx("p",{className:"text-[11px] text-fg-tertiary",children:s("work:project.kbNoPaths")}),r.map((R,D)=>t.jsxs("div",{className:"flex items-center gap-2 group",children:[t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary shrink-0",children:t.jsx("path",{d:"M3 7v10a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-6l-2-2H5a2 2 0 0 0-2 2z"})}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 min-w-0 truncate font-mono",title:R,children:R}),t.jsx("button",{type:"button",onClick:()=>E(R),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:s("work:project.removeRepo"),children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},`${R}-${D}`)),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:i,onChange:R=>o(R.target.value),onKeyDown:R=>{R.key==="Enter"&&v()},placeholder:s("work:project.kbPathPlaceholder"),className:"flex-1 min-w-0 px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary font-mono"}),g&&t.jsx("button",{type:"button",onClick:()=>{b()},disabled:a,title:s("work:project.kbBrowse"),className:"shrink-0 px-2.5 py-1.5 text-xs bg-surface-overlay text-fg-secondary hover:text-fg-primary rounded-md disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:s("work:project.kbBrowse")}),t.jsx("button",{type:"button",onClick:v,disabled:!i.trim()||a,className:"px-2.5 py-1.5 text-xs bg-surface-overlay text-fg-secondary hover:text-fg-primary rounded-md disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:s(a?"work:project.kbSyncing":"work:project.kbAdd")})]})]}),m&&t.jsx("div",{className:`mb-2 px-2.5 py-1.5 text-[11px] rounded-md ${m.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:m.text}),t.jsxs("div",{className:"border-t border-border-default/60 pt-3",children:[t.jsxs("h5",{className:"text-[11px] font-medium text-fg-tertiary mb-2",children:[s("work:project.kbDocsHeading"),h.length>0&&t.jsxs("span",{className:"ml-1 text-fg-quaternary",children:["(",h.length,")"]})]}),l?t.jsx("p",{className:"text-[11px] text-fg-tertiary",children:s("work:project.kbLoadingDocs")}):h.length===0?t.jsx("p",{className:"text-[11px] text-fg-tertiary",children:s("work:project.kbNoDocs")}):t.jsx("div",{className:"max-h-64 overflow-y-auto space-y-0.5",children:h.map(R=>t.jsxs("button",{type:"button",onClick:()=>M(R.id),className:"w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left hover:bg-surface-overlay transition-colors group",title:R.reference??R.title,children:[t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-overlay text-fg-tertiary shrink-0 uppercase",children:R.format??"file"}),t.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1 min-w-0 group-hover:text-brand-500",children:R.title}),t.jsx("span",{className:"text-[10px] text-fg-quaternary shrink-0",children:"→"})]},R.id))})]})]})}const Aa="markus_work_l1_collapsed",Lh=["backlog","kanban","dag","workflows"];function so(e){const n=e.agentId,s=e.activityId;return!n||!s?null:Ja({seq:e.seq,type:e.type,content:e.content??"",metadata:e.metadata,createdAt:e.createdAt??new Date().toISOString()},s,n)}function oo(e,n,s){const r=e.get(n)??[];if(r.some(o=>o.id===s.id))return e;const i=new Map(e);return i.set(n,[...r,s]),i}function ao({entries:e}){const[n,s]=p.useState("compact");return e.length===0?null:t.jsx("div",{onClick:r=>r.stopPropagation(),children:n==="compact"?t.jsx(tc,{entries:e,isActive:!0,onExpand:()=>s("full"),embedded:!0}):t.jsx(ei,{entries:e,isActive:!0,onCollapse:()=>s("compact"),embedded:!0})})}function io(e,n){const[s,r]=p.useState(null);return p.useEffect(()=>{if(!n||!e.current){r(null);return}const i=()=>{const o=e.current?.getBoundingClientRect();if(!o)return;const a=240,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 wt({options:e,value:n,onChange:s,placeholder:r,noMatchesText:i,className:o,disabled:a,size:c}){const[l,d]=p.useState(!1),[h,f]=p.useState(""),m=p.useRef(null),u=p.useRef(null),x=p.useRef(null),E=p.useRef(null),C=io(u,l);p.useEffect(()=>{const b=j=>{m.current&&!m.current.contains(j.target)&&E.current&&!E.current.contains(j.target)&&d(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[]);const v=c==="sm"?"px-2 py-1.5 text-xs":"px-3 py-2 text-sm",y=e.find(b=>b.value===n)?.label??"",g=h?e.filter(b=>b.label.toLowerCase().includes(h.toLowerCase())):e;return t.jsxs("div",{ref:m,className:o??"",children:[t.jsxs("div",{ref:u,onClick:()=>{a||(d(!l),f(""),setTimeout(()=>x.current?.focus(),0))},className:`w-full ${v} bg-surface-elevated border border-border-default rounded-lg focus-within:border-brand-500 outline-none flex items-center ${a?"opacity-50 cursor-not-allowed pointer-events-none":"cursor-pointer"}`,children:[l?t.jsx("input",{ref:x,value:h,onChange:b=>f(b.target.value),onClick:b=>b.stopPropagation(),className:`w-full bg-transparent outline-none text-fg-primary ${v.split(" ").slice(2).join(" ")}`,placeholder:y||r,autoFocus:!0}):t.jsx("span",{className:y?"text-fg-primary":"text-fg-tertiary",children:y||r}),t.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),l&&C&&t.jsx("div",{ref:E,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:C.flipUp?{bottom:window.innerHeight-C.top,left:C.left,width:C.width}:{top:C.top,left:C.left,width:C.width},children:g.length===0?t.jsx("div",{className:`${v} text-fg-tertiary`,children:i??"No matches"}):g.map(b=>t.jsx("div",{onClick:()=>{s(b.value),d(!1),f("")},className:`${v} cursor-pointer hover:bg-brand-500/10 ${b.value===n?"bg-brand-500/10 text-brand-500 font-medium":"text-fg-primary"}`,children:b.label},b.value))})]})}function Ah(e,n,s){if(e){if(n.some(r=>r.id===e))return`agent:${e}`;if(s.some(r=>r.id===e))return`human:${e}`}return n[0]?`agent:${n[0].id}`:s[0]?`human:${s[0].id}`:""}function bl({onClick:e,label:n}){return t.jsxs("button",{type:"button",onClick:e,title:n,"aria-label":n,className:"shrink-0 inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg border border-border-default text-xs text-fg-secondary hover:text-brand-500 hover:border-brand-500/40 hover:bg-brand-500/10 transition-colors",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("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"}),t.jsx("line",{x1:"12",y1:"7",x2:"12",y2:"11"}),t.jsx("line",{x1:"10",y1:"9",x2:"14",y2:"9"})]}),t.jsx("span",{className:"hidden sm:inline",children:n})]})}function yl({kind:e,entity:n,agents:s,users:r,projects:i,onClose:o}){const{t:a}=$e(["work","common"]),[c,l]=p.useState(()=>Ah(n.createdBy,s,r)),[d,h]=p.useState(""),f=p.useMemo(()=>{const j=d.trim().toLowerCase(),k=M=>!j||M.toLowerCase().includes(j);return[...s.filter(M=>k(M.name)).map(M=>({value:`agent:${M.id}`,name:M.name,meta:M.status,isAgent:!0})),...r.filter(M=>k(M.name)).map(M=>({value:`human:${M.id}`,name:M.name,meta:"",isAgent:!1}))]},[s,r,d]),m=n.title?.trim()||n.id,u=m.length>40?`${m.slice(0,24)}…${m.slice(-12)}`:m,x=n.projectId?i.find(j=>j.id===n.projectId)?.name??n.projectId:"",E=`${e==="requirement"?"📋":"✅"} ${u}`,C=[`@[${m}](${e}:${n.id})`,`[${e}]`,`ID: ${n.id}`,`Title: ${m}`,n.status?`Status: ${n.status}`:"",n.priority?`Priority: ${n.priority}`:"",x?`Project: ${x}`:""].filter(Boolean).join(`
|
|
8
|
-
`),[v,y]=c.split(":"),g=v==="agent"?s.find(j=>j.id===y)?.name??"":r.find(j=>j.id===y)?.name??"",b=()=>{if(!c)return;const[j,k]=c.split(":"),M={chatChips:JSON.stringify([{label:E,content:C}])};j==="agent"?M.agentId=k:M.dm=k,kt.navigate(He.TEAM,M),o()};return t.jsx("div",{className:"fixed inset-0 z-[10050] flex items-center justify-center bg-black/60 p-4",onClick:o,children:t.jsxs("div",{className:"w-full max-w-md max-h-[85vh] flex flex-col bg-surface-primary border border-border-default rounded-2xl shadow-2xl overflow-hidden",onClick:j=>j.stopPropagation(),children:[t.jsxs("div",{className:"px-5 pt-4 pb-3 border-b border-border-default shrink-0",children:[t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:a("work:task.sendToChatTitle",{defaultValue:"发送到对话"})}),t.jsx("button",{onClick:o,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none -mt-1","aria-label":a("common:close"),children:"×"})]}),t.jsx("p",{className:"mt-1 text-xs text-fg-tertiary leading-relaxed",children:a("work:task.sendToChatHint",{defaultValue:"选择要发送到的对话,它会作为上下文标签加入输入框,你可以接着补充说明。"})})]}),t.jsxs("div",{className:"px-5 pt-3 pb-2 shrink-0",children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:a("work:task.sendToChatTarget",{defaultValue:"发送给"})}),t.jsxs("div",{className:"relative",children:[t.jsxs("svg",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-fg-tertiary pointer-events-none",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"11",cy:"11",r:"8"}),t.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),t.jsx("input",{value:d,onChange:j=>h(j.target.value),placeholder:a("work:task.sendToChatSearch",{defaultValue:"搜索智能体或成员…"}),className:"w-full pl-8 pr-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary outline-none focus:border-brand-500 placeholder:text-fg-tertiary"})]}),t.jsx("div",{className:"mt-1.5 text-[11px] text-fg-tertiary truncate",children:g?`${a("work:task.sendToChatTarget",{defaultValue:"发送给"})}:${g}`:a("work:task.sendToChatNoTarget",{defaultValue:"当前没有可发送的对象"})})]}),t.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-2 pb-2",children:f.length===0?t.jsx("div",{className:"px-3 py-6 text-center text-xs text-fg-tertiary",children:a("work:task.sendToChatEmpty",{defaultValue:"没有匹配的对象"})}):f.map((j,k)=>{const M=k===0||f[k-1].isAgent!==j.isAgent,R=j.value===c;return t.jsxs("div",{children:[M&&t.jsx("div",{className:"px-3 pt-2 pb-1 text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:j.isAgent?a("work:task.sendToChatAgents",{defaultValue:"智能体"}):a("work:task.sendToChatHumans",{defaultValue:"成员"})}),t.jsxs("button",{type:"button",onClick:()=>l(j.value),className:`w-full text-left px-3 py-2 rounded-lg flex items-center gap-2 transition-colors ${R?"bg-brand-500/15 text-brand-500 font-medium":"text-fg-secondary hover:bg-surface-elevated"}`,children:[t.jsx("span",{className:"w-5 h-5 flex items-center justify-center text-sm shrink-0",children:j.isAgent?"🤖":"👤"}),t.jsx("span",{className:"flex-1 min-w-0 truncate text-sm",children:j.name}),j.meta&&t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:j.meta}),R&&t.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t.jsx("polyline",{points:"20 6 9 17 4 12"})})]})]},j.value)})}),t.jsxs("div",{className:"px-5 py-3 border-t border-border-default bg-surface-secondary/40 shrink-0",children:[t.jsx("span",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:a("work:task.sendToChatContext",{defaultValue:"将加入的上下文标签"})}),t.jsx("span",{className:"inline-flex items-center gap-1 max-w-full pl-2 pr-2 py-1 rounded-lg bg-brand-500/10 text-brand-500 text-xs border border-brand-500/20",title:C,children:t.jsx("span",{className:"truncate",children:E})}),t.jsxs("div",{className:"mt-3 flex items-center justify-end gap-2",children:[t.jsx("button",{type:"button",onClick:o,className:"px-3 py-1.5 text-xs rounded-lg border border-border-default text-fg-secondary hover:bg-surface-elevated transition-colors",children:a("common:cancel")}),t.jsx("button",{type:"button",onClick:b,disabled:!c,className:"px-3 py-1.5 text-xs rounded-lg bg-brand-600 hover:bg-brand-500 text-white font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:a("work:task.sendToChatConfirm",{defaultValue:"发送到对话"})})]})]})]})})}function Dh({options:e,selected:n,onAdd:s,placeholder:r,noMatchesText:i,className:o}){const[a,c]=p.useState(!1),[l,d]=p.useState(""),h=p.useRef(null),f=p.useRef(null),m=p.useRef(null),u=p.useRef(null),x=io(f,a);p.useEffect(()=>{const v=y=>{h.current&&!h.current.contains(y.target)&&u.current&&!u.current.contains(y.target)&&c(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]);const E=e.filter(v=>!n.includes(v.value)),C=l?E.filter(v=>v.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:v=>d(v.target.value),onClick:v=>v.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder:r,autoFocus:!0}):t.jsx("span",{className:"text-fg-tertiary",children:r}),t.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),a&&x&&t.jsx("div",{ref:u,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:x.flipUp?{bottom:window.innerHeight-x.top,left:x.left,width:x.width}:{top:x.top,left:x.left,width:x.width},children:C.length===0?t.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:i??"No matches"}):C.map(v=>t.jsx("div",{onClick:()=>{s(v.value),d("")},className:"px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 text-fg-primary",children:v.label},v.value))})]})}function Ph({options:e,onSelect:n,placeholder:s,noMatchesText:r,className:i,itemSuffix:o}){const[a,c]=p.useState(!1),[l,d]=p.useState(""),h=p.useRef(null),f=p.useRef(null),m=p.useRef(null),u=p.useRef(null),x=io(f,a);p.useEffect(()=>{const C=v=>{h.current&&!h.current.contains(v.target)&&u.current&&!u.current.contains(v.target)&&c(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]);const E=l?e.filter(C=>C.label.toLowerCase().includes(l.toLowerCase())):e;return t.jsxs("div",{ref:h,className:i??"",children:[t.jsxs("div",{ref:f,onClick:()=>{c(!a),d(""),setTimeout(()=>m.current?.focus(),0)},className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-[11px] text-fg-secondary focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[a?t.jsx("input",{ref:m,value:l,onChange:C=>d(C.target.value),onClick:C=>C.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-[11px]",placeholder:s,autoFocus:!0}):t.jsx("span",{className:"text-fg-tertiary",children:s}),t.jsx("svg",{className:"w-3.5 h-3.5 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),a&&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:E.length===0?t.jsx("div",{className:"px-3 py-2 text-xs text-fg-tertiary",children:r??"No matches"}):E.map(C=>t.jsxs("div",{onClick:()=>{n(C.value),c(!1),d("")},className:"px-3 py-2 text-xs cursor-pointer hover:bg-brand-500/10 text-fg-primary flex items-center justify-between gap-2",children:[t.jsx("span",{className:"truncate",children:C.label}),o?.(C)]},C.value))})]})}function Jn(e,n,s,r="Admin"){if(!e)return null;const i=n.find(a=>a.id===e);if(i)return i.name;const o=s.find(a=>a.id===e);return o?o.name:e==="anonymous"?r:null}function $h({value:e,onSave:n,className:s,placeholder:r}){const{t:i}=$e(["work","common"]),[o,a]=p.useState(!1),[c,l]=p.useState(e),d=p.useRef(null);p.useEffect(()=>{l(e)},[e]),p.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 Bh({value:e,onSave:n,className:s,placeholder:r}){const{t:i}=$e(["work","common"]),[o,a]=p.useState(!1),[c,l]=p.useState(e),d=p.useRef(null);p.useEffect(()=>{l(e)},[e]),p.useEffect(()=>{o&&d.current&&(d.current.focus(),d.current.style.height="auto",d.current.style.height=d.current.scrollHeight+"px")},[o]);const 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 Oh=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function vl(e){const n=e.match(Oh);return n?{timestamp:n[1].trim(),author:n[2]?.trim()??"System",content:n[3].trim()}:{timestamp:"",author:"",content:e}}function zh(e,n){if(!e)return"";const s=e.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);if(!s)return e;const r=new Date,i=+s[1],o=+s[2]-1,a=+s[3],c=+s[4],l=+s[5],d=new Date(i,o,a,c,l),h=r.getTime()-d.getTime();return h<6e4?n("work:relative.justNow"):h<36e5?n("work:relative.minutesAgo",{count:Math.floor(h/6e4)}):h<864e5?n("work:relative.hoursAgo",{count:Math.floor(h/36e5)}):h<6048e5?n("work:relative.daysAgo",{count:Math.floor(h/864e5)}):`${i}-${String(o+1).padStart(2,"0")}-${String(a).padStart(2,"0")}`}const Da=[{bg:"bg-brand-600/30",text:"text-brand-500",border:"border-brand-500/30"},{bg:"bg-blue-600/30",text:"text-blue-400",border:"border-blue-500/30"},{bg:"bg-green-600/30",text:"text-green-400",border:"border-green-500/30"},{bg:"bg-amber-600/30",text:"text-amber-400",border:"border-amber-500/30"},{bg:"bg-purple-600/30",text:"text-purple-400",border:"border-purple-500/30"},{bg:"bg-pink-600/30",text:"text-pink-400",border:"border-pink-500/30"}];function Hh(e){let n=0;for(let s=0;s<e.length;s++)n=(n<<5)-n+e.charCodeAt(s)|0;return Da[Math.abs(n)%Da.length]}function qh({note:e,compact:n}){const{t:s}=$e(["work","common"]),r=vl(e),i=s("work:task.systemAuthor"),o=Hh(r.author||i),a=r.author?r.author.split(/[\s_-]+/).map(d=>d[0]).join("").slice(0,2).toUpperCase():"SY",c=zh(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(ur,{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(ur,{content:r.content,className:"text-xs text-fg-secondary"})})]})})]})}const Vh=new Set(["rejected","cancelled","archived"]),os=[{id:"failed",statuses:["failed"],accent:"border-t-red-500",dropStatus:"failed"},{id:"todo",statuses:["pending"],accent:"border-t-amber-500",dropStatus:"pending"},{id:"in_progress",statuses:["in_progress","blocked"],accent:"border-t-brand-500",dropStatus:"in_progress"},{id:"review",statuses:["review"],accent:"border-t-purple-500",dropStatus:"review"},{id:"done",statuses:["completed"],accent:"border-t-green-500",dropStatus:"completed"},{id:"closed",statuses:["rejected","cancelled","archived"],accent:"border-t-gray-500",dropStatus:"cancelled"}],Pa={pending:"bg-amber-500/15 text-amber-600",blocked:"bg-amber-500/15 text-amber-600",failed:"bg-red-500/15 text-red-500",rejected:"bg-red-500/15 text-red-500"},$a={pending:"bg-amber-500/15 text-amber-600",in_progress:"bg-blue-500/15 text-blue-500",blocked:"bg-orange-500/15 text-orange-500",review:"bg-purple-500/15 text-purple-500",revision:"bg-amber-500/15 text-amber-600",completed:"bg-green-500/15 text-green-600",failed:"bg-red-500/15 text-red-500",rejected:"bg-red-500/15 text-red-500",cancelled:"bg-gray-500/15 text-fg-tertiary",archived:"bg-gray-500/15 text-fg-tertiary"},Ba={low:"bg-gray-500/15 text-fg-tertiary",medium:"bg-blue-500/15 text-blue-500",high:"bg-amber-500/15 text-amber-600",urgent:"bg-red-500/15 text-red-500"},Oa={pending:"bg-amber-500/15 text-amber-600",in_progress:"bg-brand-500/15 text-brand-500",completed:"bg-green-500/15 text-green-600",rejected:"bg-red-500/15 text-red-500",cancelled:"bg-gray-600/15 text-fg-tertiary",archived:"bg-gray-600/10 text-fg-tertiary/60"};function wl(e){return Object.keys($a).reduce((n,s)=>(n[s]={label:e(`work:status.task.${s}`),cls:$a[s]},n),{})}function kl(e){return Object.keys(Pa).reduce((n,s)=>(n[s]={label:e(`work:status.sub.${s}`),cls:Pa[s]},n),{})}function Wh(e){return Object.keys(Ba).reduce((n,s)=>(n[s]={label:e(`work:priority.${s}`),cls:Ba[s]},n),{})}function lo(e){return Object.keys(Oa).reduce((n,s)=>(n[s]={label:e(`work:status.requirement.${s}`),cls:Oa[s]},n),{})}const za=["low","medium","high","urgent"],Ha=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],qa=["pending","in_progress","completed","rejected","cancelled"],Va={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([])},Vs={pending:new Set(["in_progress","rejected","cancelled"]),in_progress:new Set(["completed","cancelled"]),completed:new Set([]),rejected:new Set([]),cancelled:new Set([])},br={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 Fh({agent:e,anchorRect:n,onClose:s}){const{t:r}=$e(["work","common"]),i=p.useRef(null);p.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(),kt.navigate(He.TEAM,{selectAgent:e.id})},className:"w-full text-center text-[10px] text-brand-500 hover:text-brand-500 border border-border-default hover:border-gray-600 rounded-lg py-1 transition-colors",children:r("work:task.viewProfile")})]})}function dr({comment:e,agents:n,onReply:s}){const{t:r}=$e(["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]=p.useState(null),[h,f]=p.useState(!1),[m,u]=p.useState([]),[x,E]=p.useState(!1),C=p.useCallback((j,k)=>{const M=n.find(R=>R.name.toLowerCase()===j.toLowerCase());if(M){const R=k.target.getBoundingClientRect();d({agent:M,top:R.bottom,left:R.left})}},[n]),v=p.useMemo(()=>n.map(j=>j.name),[n]),y=p.useCallback(j=>{const k=n.find(M=>M.name.toLowerCase()===e.authorName.toLowerCase());if(k){const M=j.currentTarget.getBoundingClientRect();d({agent:k,top:M.bottom,left:M.left})}},[n,e.authorName]),g=p.useCallback(async()=>{if(h){f(!1);return}const j=e.activityId;if(j&&(f(!0),!(m.length>0))){E(!0);try{const{logs:k}=await le.agents.getActivityLogs(e.authorId,j),M=k.map(R=>Ja(R,j,e.authorId)).filter(R=>R!==null).map(R=>({...R,ts:new Date(R.createdAt).getTime()}));u(M)}catch{}E(!1)}},[h,m.length,e]),b=p.useMemo(()=>Ds(m.map(As).filter(j=>j!==null)),[m]);return t.jsxs("div",{className:"flex gap-2.5 group py-1",id:`comment-${e.id}`,children:[t.jsx("div",{onClick:y,className:`flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center text-[10px] mt-0.5 cursor-pointer transition-all hover:ring-1 hover:ring-brand-500/40 ${i?"bg-indigo-500/20 text-indigo-400":"bg-blue-500/20 text-blue-400"}`,children:e.authorName.slice(0,2).toUpperCase()}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[t.jsx("span",{className:`text-[11px] font-medium cursor-pointer hover:underline ${i?"text-indigo-400":"text-blue-400"}`,onClick:y,children:e.authorName}),t.jsxs("span",{className:"text-fg-tertiary text-[10px]",children:[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:g,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 j=document.getElementById(`comment-${e.replyTo}`);j&&(j.scrollIntoView({behavior:"smooth",block:"center"}),j.classList.add("bg-brand-500/10"),setTimeout(()=>j.classList.remove("bg-brand-500/10"),1500))},className:"flex items-center gap-1.5 mb-1 pl-2 py-0.5 border-l-2 border-brand-500/40 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors cursor-pointer",children:[t.jsx("span",{className:"font-medium text-brand-500/70",children:e.replyToAuthor}),t.jsx("span",{className:"truncate max-w-[200px]",children:e.replyToContent??"..."})]}),t.jsx(ur,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:C,knownNames:v}),e.attachments?.map((j,k)=>j.type==="image"?t.jsx("img",{src:j.url,alt:j.name,className:"mt-1 max-w-[200px] rounded"},k):null),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(ei,{entries:m,isActive:!1,onCollapse:()=>f(!1),embedded:!0})})]}),l&&t.jsx(Fh,{agent:l.agent,anchorRect:{top:l.top,left:l.left},onClose:()=>d(null)})]})}function Yh({task:e,agents:n,users:s,authUser:r}){const{t:i}=$e(["work","common"]),[o,a]=p.useState([]),[c,l]=p.useState([]),d=p.useRef(null),[h,f]=p.useState(new Map);p.useEffect(()=>{l([]),f(new Map),d.current&&(clearTimeout(d.current),d.current=null),le.tasks.getComments(e.id).then(v=>a(v.comments)).catch(()=>{})},[e.id]),p.useEffect(()=>mt.on("task:comment",y=>{if(y.payload?.taskId===e.id&&y.payload.comment){const g=y.payload.comment;a(b=>b.some(j=>j.id===g.id)?b:[...b,g]),(g.authorType==="agent"||g.authorId?.startsWith("agt_"))&&(l(b=>{const j=b.filter(k=>k.id!==g.authorId);return j.length===0&&d.current&&(clearTimeout(d.current),d.current=null),j}),f(b=>{const j=new Map(b);return j.delete(g.authorId),j}))}}),[e.id]),p.useEffect(()=>{if(c.length===0)return;const v=new Set(c.map(g=>g.id));return mt.on("agent:activity_log",g=>{const b=g.payload;if(!b)return;const j=b.agentId;if(!v.has(j))return;const k=so(b);k&&f(M=>oo(M,j,k))})},[c]);const m=p.useMemo(()=>{const v=[];for(const y of e.notes??[]){const g=vl(y);let b;if(g.timestamp){const j=g.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);b=j?new Date(+j[1],+j[2]-1,+j[3],+j[4],+j[5],+(j[6]??0)):new Date(0)}else b=new Date(0);v.push({type:"note",note:y,ts:b})}for(const y of o)v.push({type:"comment",comment:y,ts:new Date(y.createdAt)});return v.sort((y,g)=>y.ts.getTime()-g.ts.getTime()),v},[e.notes,o]),[u,x]=p.useState(null),E=async(v,y,g,b)=>{let j;g.length>0&&(j=(await le.uploads.upload(g.map(A=>({dataUrl:A.dataUrl,name:A.name})),"comments")).files.map(A=>({type:"image",url:A.url,name:A.name}))),await le.tasks.addComment(e.id,v,r?.name,j,r?.id,y.length>0?y:void 0,b);const k=[],M=new Set,R=D=>{if(M.has(D)||D===r?.id)return;M.add(D);const A=n.find(T=>T.id===D);A&&k.push({id:A.id,name:A.name,avatarUrl:A.avatarUrl})};for(const D of y){const A=n.find(T=>T.name.toLowerCase()===D.toLowerCase());A&&R(A.id)}e.assignedAgentId&&R(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&R(e.createdBy),k.length>0&&(d.current&&clearTimeout(d.current),l(k),d.current=setTimeout(()=>l([]),12e4))},C=p.useCallback(v=>{x({id:v.id,authorName:v.authorName,content:v.content.slice(0,100)})},[]);return t.jsxs("div",{className:"mt-5",children:[t.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:i("work:task.activityCommentsHeading")}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[m.length===0&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:i("work:task.noActivityYet")}),m.map((v,y)=>v.type==="note"?t.jsx(qh,{note:v.note,compact:!0},`n-${y}`):t.jsx(dr,{comment:v.comment,agents:n,onReply:C},`c-${v.comment.id}`)),c.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:c.map(v=>{const y=h.get(v.id)??[];return t.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>kt.navigate(He.TEAM,{agentId:v.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(Fs,{name:v.name,avatarUrl:v.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),t.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),t.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:v.name}),y.length===0&&t.jsxs("span",{className:"flex items-center gap-0.5",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("work:task.agentProcessing")}),t.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),y.length>0&&t.jsx("div",{className:"ml-8 mt-1",children:t.jsx(ao,{entries:y})})]},v.id)})})]}),t.jsx(ni,{agents:n,humans:s,onSubmit:E,replyTo:u,onCancelReply:()=>x(null),placeholder:i("work:task.commentPlaceholder")})]})}function Gh({task:e,isRunning:n,authUser:s,agents:r}){const i=e.id,{t:o}=$e(["work","common"]),[a,c]=p.useState([]),[l,d]=p.useState(new Map),[h,f]=p.useState(new Set),[m,u]=p.useState([]),[x,E]=p.useState(""),[C,v]=p.useState(n),[y,g]=p.useState(!0),[b,j]=p.useState(new Set),[k,M]=p.useState(""),[R,D]=p.useState(!1),[A,T]=p.useState([]),$=p.useRef(null),[z,N]=p.useState(new Map),[O,L]=p.useState([]),[_,I]=p.useState([]),[P,q]=p.useState(!1),Y=p.useRef(null),F=p.useRef(null);p.useEffect(()=>{v(n)},[n]),p.useEffect(()=>{T([]),N(new Map),$.current&&(clearTimeout($.current),$.current=null)},[i]),p.useEffect(()=>{g(!0),Promise.all([le.tasks.getLogsSummary(i).catch(()=>({rounds:[]})),le.tasks.getComments(i).catch(()=>({comments:[]}))]).then(([J,Z])=>{const ce=J.rounds;if(c(ce),u(Z.comments),ce.length===0){g(!1);return}const ae=ce[ce.length-1].round;j(new Set([ae])),le.tasks.getLogs(i,ae).catch(()=>({logs:[]})).then(pe=>{d(new Map([[ae,pe.logs]])),g(!1)})})},[i]),p.useEffect(()=>{const J=e.assignedAgentId;J&&(q(!0),le.agents.getActivities(J,{taskId:i,limit:20}).then(Z=>I(Z.activities)).catch(()=>I([])).finally(()=>q(!1)))},[i,e.assignedAgentId]);const Q=p.useCallback(J=>{l.has(J)||h.has(J)||(f(Z=>new Set(Z).add(J)),le.tasks.getLogs(i,J).catch(()=>({logs:[]})).then(Z=>{d(ce=>new Map(ce).set(J,Z.logs)),f(ce=>{const ae=new Set(ce);return ae.delete(J),ae})}))},[i,l,h]),B=p.useCallback(J=>{j(Z=>{const ce=new Set(Z);return ce.has(J)?ce.delete(J):(ce.add(J),l.has(J)||Q(J)),ce})},[l,Q]);p.useEffect(()=>{const J=mt.on("task:log",ae=>{const pe=ae.payload;if(pe.taskId!==i)return;const ge={id:pe.id,taskId:pe.taskId,agentId:pe.agentId,seq:pe.seq,type:pe.logType,content:pe.content,metadata:pe.metadata,executionRound:pe.executionRound,createdAt:pe.createdAt},U=ge.executionRound??1;c(oe=>oe.find(we=>we.round===U)?oe:[...oe,{round:U,logCount:0,toolCount:0,firstAt:ge.createdAt,lastAt:ge.createdAt,status:"running"}]),j(oe=>oe.has(U)?oe:new Set(oe).add(U)),d(oe=>{const ue=oe.get(U)??[];return ge.id&&ue.some(we=>we.id===ge.id)?oe:new Map(oe).set(U,[...ue,ge])}),ge.type==="text"&&E(""),ge.type==="status"&&(ge.content==="started"||ge.content==="resumed"?v(!0):["completed","failed","cancelled","execution_finished"].includes(ge.content)&&(v(!1),c(oe=>oe.map(ue=>ue.round===U?{...ue,status:ge.content}:ue)))),ge.type==="error"&&v(!1)}),Z=mt.on("task:log:delta",ae=>{const pe=ae.payload;pe.taskId===i&&E(ge=>ge+pe.text)}),ce=mt.on("task:comment",ae=>{const pe=ae.payload;if(pe.taskId!==i)return;const ge=pe.comment;u(U=>U.some(oe=>oe.id===ge.id)?U:[...U,ge]),(ge.authorType==="agent"||ge.authorId?.startsWith("agt_"))&&(T(U=>{const oe=U.filter(ue=>ue.id!==ge.authorId);return oe.length===0&&$.current&&(clearTimeout($.current),$.current=null),oe}),N(U=>{const oe=new Map(U);return oe.delete(ge.authorId),oe}))});return()=>{J(),Z(),ce()}},[i]),p.useEffect(()=>{if(A.length===0)return;const J=new Set(A.map(ce=>ce.id));return mt.on("agent:activity_log",ce=>{const ae=ce.payload;if(!ae)return;const pe=ae.agentId;if(!J.has(pe))return;const ge=so(ae);ge&&N(U=>oo(U,pe,ge))})},[A]);const S=p.useMemo(()=>{const J=[];for(const[,Z]of l)J.push(...Z);return J.sort((Z,ce)=>Z.seq-ce.seq),J},[l]),V=p.useMemo(()=>S.map(J=>Ao(J)),[S]),W=a.length>1,H=J=>{const Z=J.target.files;if(Z){for(const ce of Array.from(Z)){if(!ce.type.startsWith("image/"))continue;const ae=new FileReader;ae.onload=()=>{L(pe=>[...pe,{type:"image",url:ae.result,name:ce.name}])},ae.readAsDataURL(ce)}J.target.value=""}},K=async()=>{if(!(!k.trim()&&O.length===0)){D(!0);try{let J;O.length>0&&(J=(await le.uploads.upload(O.map(U=>({dataUrl:U.url,name:U.name})),"comments")).files.map(U=>({type:"image",url:U.url,name:U.name})));const Z=await le.tasks.addComment(i,k,s?.name,J,s?.id);Z.comment&&u(ge=>ge.some(U=>U.id===Z.comment.id)?ge:[...ge,Z.comment]),M(""),L([]);const ce=[],ae=new Set,pe=ge=>{if(ae.has(ge)||ge===s?.id)return;ae.add(ge);const U=r.find(oe=>oe.id===ge);U&&ce.push({id:U.id,name:U.name,avatarUrl:U.avatarUrl})};e.assignedAgentId&&pe(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&pe(e.createdBy),ce.length>0&&($.current&&clearTimeout($.current),T(ce),$.current=setTimeout(()=>T([]),12e4))}catch{}D(!1)}},te=t.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-primary z-10",children:[O.length>0&&t.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:O.map((J,Z)=>t.jsxs("div",{className:"relative group",children:[t.jsx("img",{src:J.url,alt:J.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),t.jsx("button",{onClick:()=>L(ce=>ce.filter((ae,pe)=>pe!==Z)),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:"×"})]},Z))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:k,onChange:J=>M(J.target.value),onKeyDown:J=>{J.key==="Enter"&&!J.shiftKey&&(J.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:R||!k.trim()&&O.length===0,className:"px-3 py-1.5 bg-blue-600 hover:bg-blue-500 rounded-lg text-white text-xs disabled:opacity-50",children:o("common:send")})]})]});if(y)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-fg-tertiary",children:o("work:task.loadingLogs")});if(a.length===0&&!x){const J=e.assignedAgentId?r.find(we=>we.id===e.assignedAgentId):void 0,Z=_.length>0,ce=J&&J.currentTaskId&&J.currentTaskId!==e.id,ae=e.status==="pending",pe=e.status==="in_progress",ge=!e.assignedAgentId;let U="📋",oe=o("work:task.emptyLogs.default"),ue=o("work:task.emptyLogs.defaultHint");return ge?(U="👤",oe=o("work:task.emptyLogs.noAgent"),ue=o("work:task.emptyLogs.noAgentHint")):ae?(U="⏳",oe=o("work:task.emptyLogs.pending"),ue=o("work:task.emptyLogs.pendingHint")):pe&&ce?(U="🔄",oe=o("work:task.emptyLogs.agentBusy",{agent:J?.name??e.assignedAgentId}),ue=o("work:task.emptyLogs.agentBusyHint")):pe&&(U="⏳",oe=o("work:task.emptyLogs.starting"),ue=o("work:task.emptyLogs.startingHint")),t.jsxs("div",{className:"flex flex-col min-h-full",children:[t.jsx("div",{className:"flex-1 overflow-y-auto",children:P?t.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-fg-tertiary",children:o("work:task.loadingLogs")}):Z?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:J?.name??o("work:task.agent"),count:_.length})]}),t.jsx("div",{className:"space-y-1.5",children:_.map(we=>{const de=!we.endedAt,se=we.type==="task"?"🔧":we.type==="chat"||we.type==="respond_in_session"?"💬":we.type==="heartbeat"?"💓":"📋";return t.jsxs("button",{className:"w-full flex items-center gap-2 px-3 py-2 rounded-lg bg-surface-elevated hover:bg-surface-elevated/80 border border-border-default/50 text-left transition-colors group",onClick:()=>kt.navigate(He.TEAM,{agentId:e.assignedAgentId}),children:[t.jsx("span",{className:"text-sm shrink-0",children:se}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-xs text-fg-primary truncate",children:we.label}),t.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[new Date(we.startedAt).toLocaleString(),we.endedAt?` — ${we.totalTools} tools, ${we.totalTokens.toLocaleString()} tokens`:""]})]}),de&&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")]}),!de&&t.jsx("span",{className:`shrink-0 text-[10px] ${we.success?"text-fg-tertiary":"text-red-400"}`,children:we.success?"✓":"✗"}),t.jsx("span",{className:"shrink-0 text-fg-tertiary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity",children:"→"})]},we.id)})})]}):t.jsx("div",{className:"flex items-center justify-center py-8",children:t.jsxs("div",{className:"text-center text-fg-tertiary",children:[t.jsx("div",{className:"text-2xl mb-2",children:U}),t.jsxs("div",{className:"text-xs",children:[oe,t.jsx("br",{}),t.jsx("span",{className:"text-fg-muted",children:ue})]})]})})}),te]})}if(!W){const J=V.map(ae=>As(ae)).filter(ae=>ae!==null),Z=Do(S,Ds(J)),ce=[...Z.map(ae=>({kind:"entry",entry:ae,ts:ae.timestamp?new Date(ae.timestamp).getTime():0})),...m.map(ae=>({kind:"comment",comment:ae,ts:new Date(ae.createdAt).getTime()}))];return ce.sort((ae,pe)=>ae.ts-pe.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:[ce.map((ae,pe)=>ae.kind==="comment"?t.jsx(dr,{comment:ae.comment,agents:r},`c-${ae.comment.id}`):t.jsx(Po,{entry:ae.entry,showTime:!0,isLast:pe===ce.length-1},`e-${pe}`)),C&&x&&t.jsx($o,{content:x}),C&&!x&&Z.length>0&&t.jsx(Bo,{})]}),te]})}const re=(J,Z)=>{const ce=J.firstAt?new Date(J.firstAt).getTime():0,ae=Z?.firstAt?new Date(Z.firstAt).getTime():1/0;return m.filter(pe=>{const ge=new Date(pe.createdAt).getTime();return ge>=ce&&ge<ae})},fe=a.length>0?m.filter(J=>new Date(J.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:[fe.length>0&&t.jsx("div",{className:"space-y-0.5",children:fe.map(J=>t.jsx(dr,{comment:J,agents:r},J.id))}),a.map((J,Z)=>{const ce=b.has(J.round),ae=J.round===a[a.length-1].round,pe=l.get(J.round),ge=h.has(J.round),U=re(J,a[Z+1]),oe=J.status==="completed"||J.status==="execution_finished"?"✅":J.status==="failed"?"❌":J.status==="cancelled"?"⏹":"🔄",ue=J.lastAt&&J.firstAt?Math.max(0,new Date(J.lastAt).getTime()-new Date(J.firstAt).getTime()):0,we=ue>=6e4?`${Math.floor(ue/6e4)}m ${Math.floor(ue%6e4/1e3)}s`:ue>=1e3?`${Math.floor(ue/1e3)}s`:"";return t.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[t.jsxs("button",{onClick:()=>B(J.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:oe}),t.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:o("work:task.roundHeader",{n:J.round})}),U.length>0&&t.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",U.length]}),ae&&C&&t.jsxs("svg",{className:"w-3 h-3 animate-spin text-brand-500",viewBox:"0 0 24 24",fill:"none",children:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.toolCount",{count:J.toolCount})}),we&&t.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:we}),t.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${ce?"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"})})]})]}),ce&&t.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[ge&&t.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:o("work:task.loadingRound",{n:J.round})}),pe&&(()=>{const se=pe.map(ye=>Ao(ye)).map(ye=>As(ye)).filter(ye=>ye!==null),Me=[...Do(pe,Ds(se)).map(ye=>({kind:"entry",entry:ye,ts:ye.timestamp?new Date(ye.timestamp).getTime():0})),...U.map(ye=>({kind:"comment",comment:ye,ts:new Date(ye.createdAt).getTime()}))];return Me.sort((ye,Re)=>ye.ts-Re.ts),Me.map((ye,Re)=>ye.kind==="comment"?t.jsx(dr,{comment:ye.comment,agents:r},`c-${ye.comment.id}`):t.jsx(Po,{entry:ye.entry,showTime:!0,isLast:Re===Me.length-1},`e-${Re}`))})(),ae&&C&&x&&t.jsx($o,{content:x}),ae&&C&&!x&&!ge&&t.jsx(Bo,{})]})]},J.round)}),A.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 mt-2",children:A.map(J=>{const Z=z.get(J.id)??[];return t.jsxs("div",{className:"px-3 py-2 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>kt.navigate(He.TEAM,{agentId:J.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(Fs,{name:J.name,avatarUrl:J.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:J.name}),Z.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:"→"})]}),Z.length>0&&t.jsx("div",{className:"ml-9 mt-1",children:t.jsx(ao,{entries:Z})})]},J.id)})})]}),te]})}const Fa=new Set([".md",".markdown",".txt",".json",".yaml",".yml",".toml",".csv",".xml",".html",".htm",".css",".js",".ts",".jsx",".tsx",".py",".sh",".log",".env",".cfg",".ini",".png",".jpg",".jpeg",".gif",".webp",".svg",".mp3",".wav",".ogg",".flac",".aac",".m4a",".opus",".mp4",".webm",".mov",".mkv",".m4v",".pdf",".docx",".doc",".xlsx",".xls",".pptx",".ppt"]);function Kr(e){return e==null?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Kh({filePath:e,onClose:n,onOpenExternal:s}){const{t:r}=$e(["work","common"]),[i,o]=p.useState([e]),a=i[i.length-1],[c,l]=p.useState(null),[d,h]=p.useState(null),[f,m]=p.useState(!0),[u,x]=p.useState(!1);p.useEffect(()=>{m(!0),h(null),l(null),le.files.preview(a).then(R=>l(R)).catch(R=>h(String(R))).finally(()=>m(!1))},[a]);const E=R=>o(D=>[...D,R]),C=()=>o(R=>R.length>1?R.slice(0,-1):R),v=i.length>1,y=R=>{le.files.reveal(R).catch(()=>{})},g=()=>{navigator.clipboard?.writeText(a).then(()=>{x(!0),setTimeout(()=>x(!1),1500)}).catch(()=>{})},b=R=>{R.isDirectory||Fa.has(R.ext)?E(R.path):y(R.path)},j=a.split("/").pop()??a,k=c?.type==="directory",M=(R,D)=>{if(D)return"📁";const A=[".md",".markdown"],T=[".png",".jpg",".jpeg",".gif",".webp",".svg"];return A.includes(R)?"📝":T.includes(R)?"🖼":[".json",".yaml",".yml",".toml",".xml"].includes(R)?"⚙":[".js",".ts",".jsx",".tsx",".py",".sh"].includes(R)?"💻":"📄"};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:R=>R.stopPropagation(),children:[t.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-default shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[v&&t.jsx("button",{onClick:C,className:"text-fg-tertiary hover:text-fg-primary text-sm shrink-0 p-1 -ml-1 rounded hover:bg-surface-elevated/60 transition-colors",title:r("common:back"),children:t.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),k?t.jsx("svg",{className:"w-4 h-4 text-amber-500 shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:t.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.879a1.5 1.5 0 011.06.44l.872.87A.5.5 0 008.665 3.5H13.5A1.5 1.5 0 0115 5v8.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 13.5v-10z"})}):t.jsxs("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[t.jsx("path",{d:"M3 1h7l4 4v10H3V1zm7 1H4v12h10V5.5L10 2z"}),t.jsx("path",{d:"M10 1v4h4",fill:"none",stroke:"currentColor",strokeWidth:"1"})]}),t.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:j}),k&&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:g,className:"text-fg-tertiary hover:text-fg-primary px-2 py-1.5 rounded hover:bg-surface-elevated/60 transition-colors text-xs",title:r("common:copyPath",{defaultValue:"复制路径"}),children:u?`${r("common:copied",{defaultValue:"已复制"})} ✓`:r("common:copyPath",{defaultValue:"复制路径"})}),t.jsx("button",{onClick:()=>s?s():y(a),className:"text-fg-tertiary hover:text-fg-primary p-1.5 rounded hover:bg-surface-elevated/60 transition-colors",title:r(s?"work:task.openInDeliverables":"work:task.openInFinder"),children:t.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"}),t.jsx("polyline",{points:"15 3 21 3 21 9"}),t.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}),t.jsx("button",{onClick:n,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0",children:"×"})]})]}),t.jsx("div",{className:"px-4 py-1 border-b border-border-default/60",children:t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:a})}),t.jsxs("div",{className:"flex-1 overflow-auto min-h-0",children:[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(R=>t.jsxs("button",{onClick:()=>b(R),className:"w-full flex items-center gap-3 px-5 py-2.5 hover:bg-surface-elevated/40 transition-colors text-left group",children:[t.jsx("span",{className:"text-sm shrink-0",children:M(R.ext,R.isDirectory)}),t.jsx("span",{className:"flex-1 min-w-0 truncate text-sm text-fg-primary group-hover:text-brand-400 transition-colors",children:R.name}),!R.isDirectory&&R.size!=null&&t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:Kr(R.size)}),R.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"})}),!R.isDirectory&&!Fa.has(R.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"})]})]},R.path))]}),c&&c.type!=="directory"&&t.jsx("div",{className:"p-5",children:c.type==="office"&&c.streamUrl?t.jsx(ec,{data:{format:(c.extension||"").replace(/^\./,"")||"pdf",streamUrl:c.streamUrl||(c.path?le.files.streamUrl(c.path):le.files.streamUrl(a)),name:c.name,size:c.size},reference:c.path||a,onFallback:()=>y(a)}):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?le.files.streamUrl(c.path):le.files.streamUrl(a)),className:"w-full"}),t.jsxs("span",{className:"text-xs text-fg-tertiary",children:[c.name,c.size!=null?` · ${Kr(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?le.files.streamUrl(c.path):le.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?` · ${Kr(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?` · ${Kr(c.size)}`:""]}),t.jsx("button",{onClick:()=>y(a),className:"px-3 py-2 text-xs rounded-lg bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors",children:r("work:task.openInFinder")})]}):t.jsx(nc,{content:c.content,format:c.type==="text"?"text":c.type,className:"text-sm text-fg-secondary leading-relaxed"})})]})]})})}function Ya({task:e,agents:n,projects:s,requirements:r,allTasks:i,users:o,onClose:a,onRefresh:c,authUser:l,scrollToComments:d,onScrollToCommentsDone:h,onReqClick:f,onProjectClick:m}){const{t:u}=$e(["work","common"]),x=p.useMemo(()=>wl(u),[u]),[E,C]=p.useState([]),[v,y]=p.useState(""),[g,b]=p.useState(!1),[j,k]=p.useState(!1),[M,R]=p.useState(null),[D,A]=p.useState(null),[T,$]=p.useState(!1),[z,N]=p.useState(!1),[O,L]=p.useState(!1),[_,I]=p.useState("every"),[P,q]=p.useState(""),[Y,F]=p.useState(""),[Q,B]=p.useState(""),[S,V]=p.useState(!1),[W,H]=p.useState(!1),[K,te]=p.useState("details"),re=p.useRef(null),[fe,J]=p.useState("none"),[Z,ce]=p.useState(1),[ae,pe]=p.useState([]),ge=p.useCallback(async()=>{try{const{results:G}=await le.deliverables.search({taskId:e.id,limit:200});pe(G.filter(me=>me.status!=="outdated"))}catch{}},[e.id]),U=p.useCallback(G=>{te(G),G==="deliverables"&&ge(),requestAnimationFrame(()=>{re.current?.scrollTo({top:0,behavior:"instant"})})},[ge]),oe=p.useMemo(()=>[{id:"details"},{id:"logs"},{id:"deliverables"},{id:"history"}],[]),ue=Ls(oe,K,U);p.useEffect(()=>{const G=re.current;if(!G)return;const me=()=>{const{scrollTop:Ie,scrollHeight:Ee,clientHeight:nt}=G;if(!(Ee>nt+50)){J("none");return}const gn=Ie<30,Zt=Ie+nt>=Ee-30;J(gn?"top":Zt?"bottom":"middle")};me(),G.addEventListener("scroll",me,{passive:!0});const Te=new ResizeObserver(me);return Te.observe(G),()=>{G.removeEventListener("scroll",me),Te.disconnect()}},[K]),p.useEffect(()=>{if(!d)return;te("details");const G=setTimeout(()=>{const me=re.current;me&&me.scrollTo({top:me.scrollHeight,behavior:"smooth"}),h?.()},300);return()=>clearTimeout(G)},[d,h]);const[we,de]=p.useState(null),[se,xe]=p.useState(!1),[Me,ye]=p.useState(null),[Re,pt]=p.useState(!1),[gt,jt]=p.useState(e.description),Ft=p.useRef(null),Qe=p.useRef(null),Yt=p.useRef(80);p.useEffect(()=>{if(Re&&Qe.current){const G=Qe.current;G.style.height="auto",G.style.height=Math.max(G.scrollHeight,Yt.current)+"px",G.focus()}},[Re]);const[dt,At]=p.useState(!1),[ut,Ue]=p.useState("");p.useEffect(()=>{ge()},[ge,e.updatedAt]),p.useEffect(()=>{const G=["created","updated","removed"].map(me=>mt.on(`deliverable:${me}`,Te=>{const Ie=Te.payload;!Ie||Ie.taskId!==e.id||ge()}));return()=>{G.forEach(me=>me())}},[e.id,ge]);const[Dt,xt]=p.useState(!1),st=yr(),Nt=20,Xe=p.useCallback(async()=>{try{const G=await le.tasks.listSubtasks(e.id);C(G.subtasks)}catch{}},[e.id]);p.useEffect(()=>{Xe()},[Xe,e.updatedAt]);const be=async G=>{if(!S){V(!0);try{await G(),c(),await Xe()}catch(me){de(String(me).replace("Error: ",""))}finally{V(!1)}}},Je=G=>be(()=>le.tasks.update(e.id,{priority:G})),it=G=>be(()=>le.tasks.assign(e.id,G||null)),Pt=G=>be(()=>le.tasks.update(e.id,{projectId:G||null})),et=async()=>{if(!S){V(!0);try{await le.tasks.pause(e.id),c()}finally{V(!1)}}},bt=G=>{if(G instanceof Qa){if(G.code==="TASK_BLOCKED"){const me=G.data?.dependencyTitles??[];return me.length?u("work:task.errorBlockedDeps",{deps:me.join("、")}):u("work:task.errorBlocked")}if(G.code==="TASK_NOT_BLOCKED")return u("work:task.errorNotBlocked");if(G.code==="TASK_NOT_RETRYABLE")return u("work:task.errorNotRetryable")}return String(G).replace("Error: API error: 400","Server error").replace("Error: ","")},Gt=async()=>{if(!S){V(!0),de(null),U("logs");try{await le.tasks.resume(e.id),c()}catch(G){de(bt(G))}finally{V(!1)}}},Ne=async()=>{v.trim()&&(await le.tasks.createSubtask(e.id,v.trim()),y(""),b(!1),Xe(),c())},Ce=async G=>{G.status==="completed"||G.status==="cancelled"?await le.tasks.cancelSubtask(e.id,G.id):await le.tasks.completeSubtask(e.id,G.id),Xe(),c()},Ae=async G=>{await le.tasks.deleteSubtask(e.id,G.id),R(null),Xe(),c()},De=async()=>{if(!S){V(!0);try{await le.tasks.updateStatus(e.id,"in_progress"),c()}finally{V(!1)}}},ze=async()=>{if(!S){V(!0),de(null),U("logs");try{await le.tasks.retry(e.id),c()}catch(G){de(bt(G))}finally{V(!1)}}},$t=async()=>{if(!S){V(!0),de(null),U("logs");try{await le.tasks.runNow(e.id),c()}catch(G){de(bt(G)),c()}finally{V(!1)}}},Ze=p.useRef(c);Ze.current=c,p.useEffect(()=>mt.on("task:update",me=>{me.payload.taskId===e.id&&(Xe(),ge(),Ze.current())}),[e.id,Xe,ge]);const Bt=E.filter(G=>G.status==="completed").length,ot=E.filter(G=>G.status==="cancelled").length,Kt=Bt+ot,Ct=e.status==="in_progress",Ut=e.status==="blocked",Ot=Ut&&(!e.blockedBy||e.blockedBy.length===0||e.blockedBy.every(G=>{const me=i.find(Te=>Te.id===G);return me&&me.status==="completed"})),Ge=e.status==="completed",lt=e.status==="failed",pn=e.status==="rejected",sn=e.status==="cancelled",on=e.status==="archived",zt=Ge||lt||pn||sn||on,tt=e.taskType==="scheduled"&&!!e.scheduleConfig,Xt=tt&&!!e.scheduleConfig?.paused,Ht=(()=>{const G=s.find(me=>me.id===e.projectId);return G&&G.name!=="default"?G:void 0})(),We=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:[st&&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," ")})})(),Ot&&t.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle bg-red-500/15 text-red-500",children:u("work:task.abnormalBlock")})]})]}),t.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t.jsx(bl,{onClick:()=>H(!0),label:u("work:task.sendToChat",{defaultValue:"发送到对话"})}),t.jsx("button",{onClick:a,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]})]}),W&&t.jsx(yl,{kind:"task",entity:e,agents:n,users:o,projects:s,onClose:()=>H(!1)}),t.jsxs("div",{className:"flex gap-1 px-6 pt-2 pb-0 shrink-0",children:[t.jsx("button",{onClick:()=>U("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${K==="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:()=>U("logs"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${K==="logs"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:[u("work:task.executionLogTab"),Ct&&t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),t.jsx("button",{onClick:()=>U("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${K==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:(()=>{const G=ae.filter(me=>typeof me.reference=="string"&&me.reference.length>0).length;return G>0?u("work:task.deliverablesCount",{count:G}):u("work:task.deliverables")})()}),t.jsx("button",{onClick:()=>U("history"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${K==="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:re,className:"h-full overflow-y-auto overflow-x-hidden",onTouchStart:ue.onTouchStart,onTouchEnd:ue.onTouchEnd,children:[t.jsxs("div",{className:K==="logs"?"min-w-0 min-h-full":"hidden",children:[we&&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")})," ",we]}),t.jsx(Gh,{task:e,isRunning:e.status==="in_progress",authUser:l,agents:n})]}),t.jsxs("div",{className:K==="details"?"":"hidden",children:[t.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:Re?t.jsx("textarea",{ref:Qe,value:gt,onChange:G=>{jt(G.target.value);const me=G.target;me.style.height="auto",me.style.height=me.scrollHeight+"px"},onBlur:()=>{gt!==e.description&&be(()=>le.tasks.update(e.id,{description:gt})),pt(!1)},onKeyDown:G=>{G.key==="Escape"&&(G.preventDefault(),jt(e.description),pt(!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:Ft,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]")||(Yt.current=Math.max(Ft.current?.offsetHeight??80,60),jt(e.description),pt(!0))},role:"button",tabIndex:0,onKeyDown:G=>G.key==="Enter"&&(jt(e.description),pt(!0)),children:e.description?t.jsxs("div",{children:[t.jsx("div",{className:st&&!Dt?"line-clamp-3":"",children:t.jsx(ur,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),st&&e.description.length>150&&t.jsx("button",{onClick:G=>{G.stopPropagation(),xt(!Dt)},className:"text-[11px] text-brand-500 mt-1 font-medium",children:u(Dt?"work:task.collapse":"common:showMore")})]}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:u("work:task.noDescription")})})}),(Ht||We)&&t.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[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 ${m?"cursor-pointer hover:bg-brand-500/20 transition-colors":""}`,onClick:m?()=>m(Ht.id):void 0,role:m?"button":void 0,tabIndex:m?0:void 0,onKeyDown:m?G=>G.key==="Enter"&&m(Ht.id):void 0,children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:u("work:task.projectLabel")}),Ht.name]}),We&&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(We):void 0,role:f?"button":void 0,tabIndex:f?0:void 0,onKeyDown:f?G=>G.key==="Enter"&&f(We):void 0,children:[t.jsx("span",{className:"text-[9px] text-brand-500/60",children:u("work:task.requirementLabel")}),We.title.length>40?We.title.slice(0,40)+"…":We.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 me=i.find(Ie=>Ie.id===G),Te=me&&(me.status==="completed"||me.status==="cancelled");return t.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${Te?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[t.jsx("span",{className:"text-[9px]",children:Te?"✓":"⏳"}),t.jsx("span",{className:`font-mono ${Te?"line-through opacity-60":""}`,children:me?me.title.slice(0,30):G.slice(-8)}),!zt&&t.jsx("button",{onClick:async()=>{const Ie=(e.blockedBy??[]).filter(Ee=>Ee!==G);await le.tasks.update(e.id,{blockedBy:Ie}),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")}),Ot&&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")})]}),!zt&&t.jsx(Ph,{options:i.filter(G=>G.id!==e.id&&!(e.blockedBy??[]).includes(G.id)).map(G=>({value:G.id,label:G.title,status:G.status})),placeholder:u("work:task.addDependency"),noMatchesText:u("work:task.noMatches"),itemSuffix:G=>G.status==="completed"||G.status==="archived"?t.jsx("span",{className:"text-[9px] text-green-600 shrink-0",children:"✓"}):G.status==="cancelled"?t.jsx("span",{className:"text-[9px] text-fg-tertiary shrink-0",children:"✕"}):null,onSelect:async G=>{if(!G)return;const me=[...e.blockedBy??[],G];await le.tasks.update(e.id,{blockedBy:me}),c()}})]}),t.jsxs("div",{className:"px-6 py-4 border-b border-border-default/60 space-y-3",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1",children:u("work:task.projectLabel")}),t.jsx(wt,{size:"sm",disabled:S,options:[{value:"",label:u("work:task.noProject")},...s.map(G=>({value:G.id,label:G.name}))],value:e.projectId??"",onChange:G=>{Pt(G)},placeholder:u("work:task.noProject"),noMatchesText:u("work:task.noMatches")})]}),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.jsx(wt,{size:"sm",disabled:S,options:[{value:"",label:u("work:task.noRequirement")},...r.filter(G=>!e.projectId||G.projectId===e.projectId).map(G=>({value:G.id,label:G.title}))],value:e.requirementId??"",onChange:G=>be(()=>le.tasks.update(e.id,{requirementId:G||null})),placeholder:u("work:task.noRequirement"),noMatchesText:u("work:task.noMatches")})]})]}),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.jsx(wt,{size:"sm",disabled:S,options:[{value:"",label:u("work:task.unassigned")},...n.map(G=>({value:G.id,label:`${G.name} (${G.status})`}))],value:e.assignedAgentId??"",onChange:G=>{it(G)},placeholder:u("work:task.unassigned"),noMatchesText:u("work:task.noMatches")})]}),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.jsx(wt,{size:"sm",disabled:S,options:[...o.map(G=>({value:`human:${G.id}`,label:G.name})),...n.map(G=>({value:`agent:${G.id}`,label:`${G.name} (${G.status})`}))],value:`${e.reviewerType??"agent"}:${e.reviewerId??""}`,onChange:G=>{if(!G)return;const me=G.startsWith("human:"),Te=G.replace(/^(human|agent):/,"");(Te!==e.reviewerId||(me?"human":"agent")!==(e.reviewerType??"agent"))&&be(()=>le.tasks.update(e.id,{reviewerId:Te,reviewerType:me?"human":"agent"}))},placeholder:u("work:task.selectReviewer"),noMatchesText:u("work:task.noMatches")})]}),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=>{Je(G.target.value)},disabled:S,className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-xs text-fg-primary focus:border-brand-500 outline-none disabled:opacity-50 cursor-pointer",children:[t.jsx("option",{value:"low",children:u("work:priority.low")}),t.jsx("option",{value:"medium",children:u("work:priority.medium")}),t.jsx("option",{value:"high",children:u("work:priority.high")}),t.jsx("option",{value:"urgent",children:u("work:priority.urgent")})]})]})]})]}),t.jsxs("div",{className:"px-6 py-3 border-b border-border-default/60 flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[11px] text-fg-tertiary",children:[e.createdBy&&t.jsx("span",{children:u("work:task.createdBy",{name:Jn(e.createdBy,n,o)??e.createdBy})}),e.updatedBy&&t.jsx("span",{children:u("work:task.updatedBy",{name:Jn(e.updatedBy,n,o)??e.updatedBy})}),e.createdAt&&t.jsx("span",{children:new Date(e.createdAt).toLocaleDateString()}),e.startedAt&&t.jsx("span",{children:u("work:task.started",{date:new Date(e.startedAt).toLocaleDateString()})}),e.updatedAt&&t.jsx("span",{children:u("work:task.updatedMeta",{date:new Date(e.updatedAt).toLocaleDateString()})}),e.projectId&&t.jsxs("span",{className:"font-mono text-blue-600/70",children:["task/",e.id]}),(e.executionRound??1)>1&&t.jsx("span",{className:"text-amber-600",children:u("work:task.executionRound",{n:e.executionRound})})]}),t.jsxs("div",{className:"px-6 py-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:[u("work:task.subtasks")," ",E.length>0&&t.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal normal-case",children:[u("work:task.subtasksProgress",{done:Bt,total:E.length-ot}),ot>0?` · ${ot} cancelled`:""]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[Kt>0&&t.jsx("button",{onClick:()=>k(G=>!G),className:`text-[10px] px-2 py-0.5 rounded-full border transition-colors ${j?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-tertiary border-border-default hover:text-fg-secondary"}`,children:j?u("work:task.hideCompleted"):u("work:task.showCompleted",{count:Kt})}),t.jsx("button",{onClick:()=>b(!0),className:"text-xs text-brand-500 hover:text-brand-500 transition-colors",children:u("work:task.addSubtask")})]})]}),(()=>{const G=j?E:E.filter(me=>me.status!=="completed"&&me.status!=="cancelled");return G.length>0?t.jsx("div",{className:"space-y-1.5 mb-3",children:G.map(me=>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 ${me.status==="cancelled"?"opacity-50":""}`,children:[t.jsxs("button",{onClick:()=>{Ce(me)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${me.status==="completed"?"bg-green-600 border-green-600 text-white":me.status==="cancelled"?"bg-gray-500 border-gray-500 text-white":"border-gray-600 hover:border-brand-500"}`,children:[me.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"})}),me.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 ${me.status==="completed"?"line-through text-fg-tertiary":me.status==="cancelled"?"line-through text-fg-quaternary":"text-fg-secondary"}`,children:me.title}),t.jsx("button",{onClick:()=>R(me),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},me.id))}):null})(),E.length===0&&!g&&t.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:u("work:task.noSubtasksYet")}),g&&t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsx("input",{autoFocus:!0,value:v,onChange:G=>y(G.target.value),onKeyDown:G=>{G.key==="Enter"&&Ne(),G.key==="Escape"&&(b(!1),y(""))},placeholder:u("work:task.subtaskTitlePlaceholder"),className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"}),t.jsx("button",{onClick:()=>{Ne()},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg",children:u("work:task.add")}),t.jsx("button",{onClick:()=>{b(!1),y("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:u("common:cancel")})]}),(()=>{const G=ae.filter(Ie=>typeof Ie.reference=="string"&&Ie.reference.length>0);if(G.length===0)return null;const me={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"},Te=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:()=>U("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:Te.map(Ie=>{const Ee=/^https?:\/\//i.test(Ie.reference),nt=Ee?Ie.summary||Ie.reference:Ie.reference.split("/").pop()??Ie.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 ${me[Ie.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Ie.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[Ee?t.jsxs("a",{href:Ie.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:Ie.reference,children:[nt," ",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:()=>ye(Ie.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Ie.reference,children:nt}),Ie.summary&&!Ee&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Ie.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Ie.reference})]})]},Ie.id)})})]})})(),t.jsx(Yh,{task:e,agents:n,users:o,authUser:l})]})]}),t.jsx("div",{className:K==="history"?"":"hidden",children:t.jsx(Cl,{entityType:"task",entityId:e.id})}),t.jsx("div",{className:K==="deliverables"?"px-6 py-4":"hidden",children:(()=>{const G=ae.filter(Ee=>typeof Ee.reference=="string"&&Ee.reference.length>0);if(G.length===0)return t.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:u("work:task.noDeliverablesYet")});const me={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"},Te=Math.ceil(G.length/Nt),Ie=G.slice((Z-1)*Nt,Z*Nt);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})}),Te>1&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[t.jsx("button",{disabled:Z<=1,onClick:()=>ce(Ee=>Ee-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),t.jsxs("span",{children:[Z,"/",Te]}),t.jsx("button",{disabled:Z>=Te,onClick:()=>ce(Ee=>Ee+1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"›"})]})]}),t.jsx("div",{className:"space-y-1.5",children:Ie.map(Ee=>{const nt=/^https?:\/\//i.test(Ee.reference),qt=nt?Ee.summary||Ee.reference:Ee.reference.split("/").pop()??Ee.reference;return t.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${me[Ee.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Ee.type}),t.jsxs("div",{className:"flex-1 min-w-0",children:[nt?t.jsxs("a",{href:Ee.reference,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Ee.reference,children:[qt," ",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:()=>ye(Ee.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Ee.reference,children:qt}),Ee.summary&&!nt&&t.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Ee.summary}),t.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Ee.reference})]})]},Ee.id)})})]})})()})]}),fe!=="none"&&fe!=="top"&&t.jsx("button",{onClick:()=>re.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"})})}),fe!=="none"&&fe!=="bottom"&&t.jsx("button",{onClick:()=>{const G=re.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"})})})]}),tt&&e.scheduleConfig&&t.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${Xt?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"} ${!Ct&&!O&&!e.scheduleConfig.runAt?"cursor-pointer hover:border-brand-500/40 transition-colors":""}`,onClick:()=>{Ct||O||e.scheduleConfig?.runAt||(I(e.scheduleConfig?.cron?"cron":"every"),q(e.scheduleConfig?.every??"4h"),F(e.scheduleConfig?.cron??""),B(e.scheduleConfig?.maxRuns&&e.scheduleConfig.maxRuns>0?String(e.scheduleConfig.maxRuns):""),L(!0))},children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:Xt?"text-amber-600":"text-brand-500",children:Xt?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")}),!Xt&&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 me=Math.floor(G/6e4);if(me<60)return u("work:task.scheduleInMinutes",{count:me});const Te=Math.floor(me/60);return Te<24?u("work:task.scheduleInHoursMinutes",{h:Te,m:me%60}):u("work:task.scheduleInDaysHours",{d:Math.floor(Te/24),h:Te%24})})()})})]}),!Ct&&!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:_,onChange:G=>I(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")})]}),_==="every"?t.jsxs("select",{value:P,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=>B(G.target.value.replace(/\D/g,"")),placeholder:u("work:task.scheduleMaxRunsPlaceholder"),className:"w-20 px-2 py-1 text-xs bg-surface-elevated border border-border-default rounded-lg outline-none focus:border-brand-500"})]}),t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[t.jsx("button",{onClick:async()=>{const G={};_==="every"?G.every=P:G.cron=Y.trim(),Q&&(G.maxRuns=parseInt(Q,10)),await be(()=>le.tasks.updateSchedule(e.id,G)),L(!1)},disabled:S,className:"px-3 py-1 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:u("common:save")}),t.jsx("button",{onClick:()=>L(!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(),me=Math.floor(G/6e4);if(me<1)return u("work:task.noteTimeJustNow");if(me<60)return u("work:task.noteTimeMinutes",{count:me});const Te=Math.floor(me/60);return Te<24?u("work:task.noteTimeHours",{count:Te}):u("work:task.noteTimeDays",{count:Math.floor(Te/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(tt){xe(!0);return}be(()=>le.tasks.approve(e.id))},disabled:S,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:e.createdBy&&!e.createdBy.startsWith("agt_")?u("work:task.startExecution"):u("work:task.approve")}),e.createdBy&&!e.createdBy.startsWith("agt_")?t.jsx("button",{onClick:async()=>{const{count:G}=await le.tasks.getDependentCount(e.id);A({dependentCount:G})},disabled:S,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:u("work:task.cancelTask")}):t.jsx("button",{onClick:()=>$(!0),disabled:S,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:u("work:task.reject")})]}),e.status==="review"&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>{be(()=>le.tasks.accept(e.id,l?.id))},disabled:S,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.approveCheck")}),dt?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("input",{type:"text",value:ut,onChange:G=>Ue(G.target.value),onKeyDown:G=>{G.key==="Enter"&&ut.trim()&&(be(()=>le.tasks.revision(e.id,ut.trim(),l?.id)),At(!1),Ue(""))},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:()=>{be(()=>le.tasks.revision(e.id,ut.trim()||u("work:task.revisionsNeededDefault"),l?.id)),At(!1),Ue("")},disabled:S,className:"px-2.5 py-1 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:u("common:send")}),t.jsx("button",{onClick:()=>{At(!1),Ue("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):t.jsx("button",{onClick:()=>At(!0),disabled:S,className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.requestRevision")})]}),Ct&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{et()},disabled:S,className:"px-3 py-1.5 text-xs border border-amber-500/30 text-amber-600 rounded-lg hover:bg-amber-500/10 disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:[t.jsx("rect",{x:"2",y:"1.5",width:"3",height:"9",rx:"0.5"}),t.jsx("rect",{x:"7",y:"1.5",width:"3",height:"9",rx:"0.5"})]}),u("work:task.pause")]}),t.jsxs("button",{onClick:()=>{ze()},disabled:S,className:"px-3 py-1.5 text-xs border border-blue-500/30 text-blue-600 rounded-lg hover:bg-blue-500/10 disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[t.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),t.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),u("work:task.retry")]})]}),Ut&&t.jsx("button",{onClick:()=>{Gt()},disabled:S,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:S?t.jsx(t.Fragment,{children:u("work:task.resuming")}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),u("work:task.resume")]})}),lt&&!tt&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>{ze()},disabled:S,className:"px-3 py-1.5 text-xs bg-blue-600 hover:bg-blue-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:[t.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[t.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),t.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),u("work:task.retry")]}),t.jsxs("button",{onClick:()=>{De()},disabled:S,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1",children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),u("work:task.continueTask")]})]}),tt&&(Ge||lt||sn)&&!on&&t.jsx("button",{onClick:()=>{$t()},disabled:S,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1.5",children:S?t.jsx(t.Fragment,{children:u("work:task.running")}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:t.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),u("work:task.runNow")]})}),tt&&!Ct&&!on&&!pn&&(Xt?t.jsx("button",{onClick:()=>{be(()=>le.tasks.resumeSchedule(e.id))},disabled:S,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.resumeSchedule")}):t.jsx("button",{onClick:()=>{be(()=>le.tasks.pauseSchedule(e.id))},disabled:S,className:"px-3 py-1.5 text-xs border border-amber-500/30 text-amber-600 rounded-lg hover:bg-amber-500/10 disabled:opacity-50",children:u("work:task.pauseSchedule")})),(Ge||lt||pn||sn)&&t.jsx("button",{onClick:()=>N(!0),disabled:S,className:"px-3 py-1.5 text-xs bg-gray-600 hover:bg-gray-500 rounded-lg text-white disabled:opacity-50",children:u("work:task.archive")}),Ge&&!tt&&t.jsx("button",{onClick:()=>{De()},disabled:S,className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary disabled:opacity-50",children:u("work:task.reopen")}),!zt&&e.status!=="pending"&&t.jsx("button",{onClick:async()=>{const{count:G}=await le.tasks.getDependentCount(e.id);A({dependentCount:G})},disabled:S,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:u("work:task.cancelTask")})]})}),M&&t.jsx(qn,{title:u("work:task.deleteSubtaskTitle",{title:M.title}),message:u("work:task.deleteSubtaskMessage"),confirmLabel:u("common:delete"),onConfirm:()=>{Ae(M)},onCancel:()=>R(null)}),T&&t.jsx(qn,{title:u("work:task.rejectConfirmTitle"),message:u("work:task.rejectConfirmMessage"),confirmLabel:u("work:task.reject"),onConfirm:()=>{$(!1),be(()=>le.tasks.reject(e.id))},onCancel:()=>$(!1)}),z&&t.jsx(qn,{title:u("work:task.archiveConfirmTitle"),message:u(tt?"work:task.archiveScheduledConfirmMessage":"work:task.archiveConfirmMessage"),confirmLabel:u("work:task.archive"),onConfirm:()=>{N(!1),be(()=>le.tasks.archive(e.id))},onCancel:()=>N(!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:[tt&&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),be(()=>le.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),be(()=>le.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(qn,{title:u("work:task.cancelTaskModalTitle"),message:u(tt?"work:task.cancelScheduledConfirmMessage":"work:task.cancelConfirmMessage"),confirmLabel:u("work:task.cancelTask"),onConfirm:()=>{A(null),be(()=>le.tasks.cancel(e.id))},onCancel:()=>A(null)}),Me&&t.jsx(Kh,{filePath:Me,onClose:()=>ye(null),onOpenExternal:()=>{ye(null),le.deliverables.search({taskId:e.id,limit:100}).then(({results:G})=>{const me=G.find(Te=>Te.reference===Me);me?kt.navigate(He.DELIVERABLES,{openDeliverable:me.id}):kt.navigate(He.DELIVERABLES)}).catch(()=>kt.navigate(He.DELIVERABLES))}}),se&&e.scheduleConfig&&t.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>xe(!1),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[380px] shadow-2xl",onClick:G=>G.stopPropagation(),children:[t.jsx("h3",{className:"font-semibold text-base mb-2",children:u("work:task.scheduleApproveTitle")}),t.jsx("p",{className:"text-sm text-fg-secondary mb-5 leading-relaxed",children:u("work:task.scheduleApproveDesc",{schedule:e.scheduleConfig.cron?`Cron: ${e.scheduleConfig.cron}`:e.scheduleConfig.every?u("work:task.scheduleEvery",{interval:e.scheduleConfig.every}):"",nextRun:e.scheduleConfig.nextRunAt?new Date(e.scheduleConfig.nextRunAt).toLocaleString():u("work:task.scheduleNA")})}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("button",{disabled:S,onClick:()=>{xe(!1),be(()=>le.tasks.approve(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-green-600 hover:bg-green-500 text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:u("work:task.scheduleApproveRunNow")}),t.jsx("button",{disabled:S,onClick:()=>{xe(!1),be(()=>le.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:()=>xe(!1),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:u("common:cancel")})]})]})})]})}function Uh({project:e,tasks:n,requirements:s,agents:r,onDeleteProject:i,onUpdateProject:o,onRefresh:a}){const c=p.useMemo(()=>n.filter(T=>T.projectId===e.id),[n,e.id]),l=p.useMemo(()=>s.filter(T=>T.projectId===e.id),[s,e.id]),d=p.useMemo(()=>{const T={total:c.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:l.length,reqsDone:0};for(const $ of c)$.status==="completed"||$.status==="accepted"?T.completed++:$.status==="in_progress"?T.inProgress++:$.status==="review"||$.status==="revision"?T.inReview++:$.status==="blocked"?T.blocked++:$.status==="failed"?T.failed++:T.pending++;for(const $ of l)$.status==="completed"&&T.reqsDone++;return T},[c,l]),h=p.useMemo(()=>new Set(c.map(T=>T.assignedAgentId).filter(Boolean)),[c]),f=p.useMemo(()=>r.filter(T=>h.has(T.id)),[r,h]),[m,u]=p.useState(!1),[x,E]=p.useState(""),[C,v]=p.useState("main"),[y,g]=p.useState(!1),[b,j]=p.useState(!1),{t:k}=$e(["work","common"]),M=[{value:"active",label:k("work:project.statusActive"),desc:k("work:project.statusActiveDesc")},{value:"paused",label:k("work:project.statusPaused"),desc:k("work:project.statusPausedDesc")},{value:"archived",label:k("work:project.statusArchived"),desc:k("work:project.statusArchivedDesc")}],R=async T=>{if(T!==e.status){g(!0);try{await o({status:T}),a()}finally{g(!1)}}},D=async()=>{const T=x.trim();if(!T)return;const $=[...e.repositories??[],{url:"",localPath:T,defaultBranch:C||"main"}];await o({repositories:$}),E(""),v("main"),u(!1),a()},A=async T=>{const $=(e.repositories??[]).filter((z,N)=>N!==T);await o({repositories:$}),a()};return t.jsxs("div",{className:"p-5 space-y-5 max-w-3xl",children:[t.jsxs("div",{className:"space-y-3",children:[t.jsx(Bh,{value:e.description??"",onSave:async T=>{await o({description:T}),a()},className:"text-sm text-fg-secondary",placeholder:k("work:project.descriptionPlaceholderLong")}),t.jsxs("div",{className:"flex items-center gap-3 text-xs text-fg-tertiary",children:[e.createdAt&&t.jsxs("span",{children:[k("work:project.createdLabel")," ",new Date(e.createdAt).toLocaleDateString()]}),e.updatedAt&&t.jsxs("span",{children:[k("work:project.updatedLabel")," ",new Date(e.updatedAt).toLocaleDateString()]})]})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:k("work:project.projectStatusHeading")}),t.jsx("div",{className:"flex gap-2",children:M.map(T=>t.jsxs("button",{disabled:y,onClick:()=>R(T.value),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all ${e.status===T.value?T.value==="active"?"bg-green-500/15 text-green-600 ring-1 ring-green-500/30":T.value==="paused"?"bg-amber-500/15 text-amber-600 ring-1 ring-amber-500/30":"bg-gray-500/15 text-fg-tertiary ring-1 ring-gray-500/30":"bg-surface-elevated text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay"} ${y?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[t.jsx("div",{children:T.label}),t.jsx("div",{className:"text-[10px] opacity-70 mt-0.5",children:T.desc})]},T.value))})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:k("work:project.taskOverview")}),t.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-3",children:[t.jsx(nn,{label:k("work:project.statTotal"),value:d.total,color:"text-fg-primary"}),t.jsx(nn,{label:k("work:project.statCompleted"),value:d.completed,color:"text-green-600"}),t.jsx(nn,{label:k("work:project.statInProgress"),value:d.inProgress,color:"text-brand-500"}),t.jsx(nn,{label:k("work:project.statInReview"),value:d.inReview,color:"text-brand-500"}),t.jsx(nn,{label:k("work:project.statBlocked"),value:d.blocked,color:"text-amber-600"}),t.jsx(nn,{label:k("work:project.statFailed"),value:d.failed,color:"text-red-500"})]}),d.total>0&&t.jsxs("div",{className:"mt-3 flex h-2 rounded-full overflow-hidden bg-surface-elevated",children:[d.completed>0&&t.jsx("div",{className:"bg-green-500",style:{width:`${d.completed/d.total*100}%`}}),d.inProgress>0&&t.jsx("div",{className:"bg-brand-500",style:{width:`${d.inProgress/d.total*100}%`}}),d.inReview>0&&t.jsx("div",{className:"bg-brand-500",style:{width:`${d.inReview/d.total*100}%`}}),d.blocked>0&&t.jsx("div",{className:"bg-amber-500",style:{width:`${d.blocked/d.total*100}%`}}),d.pending>0&&t.jsx("div",{className:"bg-blue-500/40",style:{width:`${d.pending/d.total*100}%`}}),d.failed>0&&t.jsx("div",{className:"bg-red-500",style:{width:`${d.failed/d.total*100}%`}})]})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:k("work:project.requirementsHeading")}),t.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.jsx(nn,{label:k("work:project.statTotal"),value:d.reqs,color:"text-fg-primary"}),t.jsx(nn,{label:k("work:project.statCompleted"),value:d.reqsDone,color:"text-green-600"}),t.jsx(nn,{label:k("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:k("work:project.agentsHeading",{count:f.length})}),t.jsx("div",{className:"flex flex-wrap gap-2",children:f.map(T=>{const $=c.filter(N=>N.assignedAgentId===T.id),z=$.filter(N=>!["completed","failed","cancelled","archived"].includes(N.status));return t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-surface-elevated/60 rounded-lg",children:[t.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${T.status==="working"?"bg-blue-500":T.status==="idle"?"bg-green-500":"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary",children:T.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:k("work:project.agentTaskCounts",{active:z.length,total:$.length})})]},T.id)})})]}),t.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsx("h4",{className:"text-xs font-semibold text-fg-secondary",children:k("work:project.repositories")}),t.jsx("button",{onClick:()=>u(!m),className:"text-[10px] text-brand-500 hover:text-brand-500",children:k(m?"common:cancel":"work:project.addRepo")})]}),(e.repositories??[]).length===0&&!m&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:k("work:project.noReposLinked")}),(e.repositories??[]).map((T,$)=>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:T.url||T.localPath}),t.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:T.defaultBranch}),t.jsx("button",{onClick:()=>A($),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:k("work:project.removeRepo"),children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},$)),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:T=>E(T.target.value),placeholder:k("work:project.repoPathPlaceholder"),className:"w-full px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:C,onChange:T=>v(T.target.value),placeholder:k("work:project.repoBranchPlaceholder"),className:"flex-1 px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary"}),t.jsx("button",{onClick: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:k("work:task.add")})]})]})]}),t.jsx(_h,{project:e,onUpdateProject:o}),t.jsxs("div",{className:"border border-red-500/20 rounded-xl p-4",children:[t.jsx("h4",{className:"text-xs font-semibold text-red-500/80 mb-2",children:k("work:project.dangerZone")}),t.jsx("p",{className:"text-[11px] text-fg-tertiary mb-3",children:k("work:project.dangerZoneDeleteHint")}),t.jsx("button",{onClick:()=>j(!0),className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 hover:bg-red-500/10 rounded-lg transition-colors",children:k("work:project.deleteProject")})]}),b&&t.jsx(qn,{title:k("work:project.deleteProjectConfirmTitle"),message:k("work:project.deleteProjectConfirmBody",{name:e.name,tasks:d.total,reqs:d.reqs}),confirmLabel:k("work:project.deleteProject"),onConfirm:()=>{j(!1),i()},onCancel:()=>j(!1)})]})}function nn({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 es={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed",archived:"closed"},jl={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},Xh={urgent:0,high:1,medium:2,low:3},as={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},Ga={failed:"border-l-red-500 bg-red-500/5",todo:"border-l-blue-500 bg-blue-500/5",in_progress:"border-l-brand-500 bg-brand-500/5",review:"border-l-purple-500 bg-brand-500/5",done:"border-l-green-500 bg-green-500/5",closed:"border-l-gray-500 bg-gray-500/5"},Zh={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"},Qh=["pending","in_progress","completed","rejected","cancelled","archived"];function Nl(e){for(const n of os)if(n.statuses.includes(e))return n.id;return"closed"}function Ka(e,n){const s=Date.now()-new Date(e).getTime(),r=Math.floor(s/6e4);if(r<1)return n("work:relative.justNow");if(r<60)return n("work:relative.minutesAgo",{count:r});const i=Math.floor(r/60);if(i<24)return n("work:relative.hoursAgo",{count:i});const o=Math.floor(i/24);return n("work:relative.daysAgo",{count:o})}function Ur({value:e,options:n,onSelect:s,allowedValues:r}){const[i,o]=p.useState(!1),a=p.useRef(null),c=p.useRef(null),l=n.find(d=>d.value===e);return p.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 Ua({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}=$e(["work","common"]),E=p.useMemo(()=>wl(x),[x]),C=p.useMemo(()=>lo(x),[x]),v=p.useMemo(()=>Wh(x),[x]),y=e.data.status,g=e.data.priority,b=e.kind==="task"?r.get(e.data.assignedAgentId??""):void 0,j=(()=>{const M=i.get((e.kind==="task",e.data.projectId??""));return M&&M.name!=="default"?M:void 0})(),k=e.kind==="req"?t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children: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 ${Ga[e.group]??"border-l-gray-700"} ${f?"bg-brand-500/25 border-l-brand-500 ring-1 ring-inset ring-brand-500/35":"active:bg-surface-elevated/50"}`,children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[k,u&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500",children:"⚠"}),t.jsx("span",{className:"text-sm text-fg-primary truncate flex-1",children:e.data.title})]}),t.jsxs("div",{className:"flex items-center gap-2 mt-1.5 flex-wrap",children:[t.jsx("div",{onClick:M=>M.stopPropagation(),children:t.jsx(Ur,{value:y,options:e.kind==="task"?Ha.map(M=>({value:M,label:E[M]?.label??M,cls:E[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})):qa.map(M=>({value:M,label:C[M]?.label??M,cls:C[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?Va[y]:Vs[y],onSelect:M=>{d(e,M)}})}),t.jsx("div",{onClick:M=>M.stopPropagation(),children:t.jsx(Ur,{value:g,options:za.map(M=>({value:M,label:v[M]?.label??M,cls:v[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:M=>{h(e,M)}})}),b&&t.jsxs("span",{className:"flex items-center gap-1 text-[10px]",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${br[b.status]??"bg-gray-500"}`}),t.jsx("span",{className:`${Wa[b.status]??"text-fg-secondary"}`,children:b.name})]}),j?.name&&t.jsx("span",{className:"text-[10px] text-brand-400/70 truncate max-w-[80px]",children:j.name}),t.jsx("span",{className:"text-[9px] text-fg-muted ml-auto",children:Ka(e.data.updatedAt??"",x)})]})]}):t.jsxs("div",{"data-work-item-id":e.data.id,draggable:!0,onDragStart:M=>c(M,n),onDragEnd:l,onClick:()=>e.kind==="task"?o(e.data):a(e.data),className:`flex items-center gap-2 px-6 py-2 border-b border-border-default/40 cursor-pointer transition-colors border-l-2 ${Ga[e.group]??"border-l-gray-700"} ${s===n?"opacity-40":""} ${f?"bg-brand-500/25 border-l-brand-500 ring-1 ring-inset ring-brand-500/35 hover:bg-brand-500/30":"hover:bg-surface-elevated/50"}`,children:[t.jsx("div",{className:"w-12 shrink-0",children:k}),t.jsxs("div",{className:"flex-1 min-w-[200px] text-sm text-fg-primary truncate flex items-center gap-1.5",children:[t.jsx("span",{className:"truncate",children:e.data.title}),u&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500 shrink-0",children:"⚠"})]}),t.jsx("div",{className:"w-[130px] shrink-0",onClick:M=>M.stopPropagation(),children:t.jsx(Ur,{value:y,options:e.kind==="task"?Ha.map(M=>({value:M,label:E[M]?.label??M,cls:E[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})):qa.map(M=>({value:M,label:C[M]?.label??M,cls:C[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?Va[y]:Vs[y],onSelect:M=>{d(e,M)}})}),t.jsx("div",{className:"w-[100px] shrink-0",onClick:M=>M.stopPropagation(),children:t.jsx(Ur,{value:g,options:za.map(M=>({value:M,label:v[M]?.label??M,cls:v[M]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:M=>{h(e,M)}})}),t.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:b?t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${br[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:j?.name?t.jsx("span",{className:"text-brand-400/70",children:j.name}):t.jsx("span",{className:"text-fg-muted",children:"—"})}),t.jsx("div",{className:"w-[90px] shrink-0 text-[10px] text-fg-muted text-right",children:Ka(e.data.updatedAt??"",x)})]})}function Jh({tasks:e,requirements:n,agents:s,projects:r,onTaskClick:i,onReqClick:o,onRefresh:a,selectedTaskId:c,selectedReqId:l}){const{t:d}=$e(["work","common"]),h=yr(),[f,m]=p.useState("status"),[u,x]=p.useState(null),[E,C]=p.useState(null),v=p.useMemo(()=>{const _=new Map;for(const I of e)_.set(I.id,I);return _},[e]),y=p.useCallback(_=>_.status!=="blocked"?!1:!_.blockedBy||_.blockedBy.length===0?!0:_.blockedBy.every(I=>{const P=v.get(I);return P&&P.status==="completed"}),[v]),g=p.useMemo(()=>{const _=[];for(const I of e){const P=Nl(I.status);_.push({kind:"task",data:I,group:P,groupOrder:as[P]??5})}for(const I of n){const P=es[I.status]??"todo";_.push({kind:"req",data:I,group:P,groupOrder:as[P]??5})}if(f==="status")_.sort((I,P)=>{if(I.groupOrder!==P.groupOrder)return I.groupOrder-P.groupOrder;const q=new Date(I.data.updatedAt??0).getTime();return new Date(P.data.updatedAt??0).getTime()-q});else{const I=P=>Xh[P.data.priority]??2;_.sort((P,q)=>{const Y=I(P),F=I(q);return Y!==F?Y-F:new Date(q.data.updatedAt??0).getTime()-new Date(P.data.updatedAt??0).getTime()})}return _},[e,n,f]),b=async(_,I)=>{try{_.kind==="task"?await le.tasks.updateStatus(_.data.id,I):await le.requirements.updateStatus(_.data.id,I),a()}catch{}},j=async(_,I)=>{try{_.kind==="task"?await le.tasks.update(_.data.id,{priority:I}):await le.requirements.update(_.data.id,{priority:I}),a()}catch{}},k=(_,I)=>{x(I),_.dataTransfer.effectAllowed="move",_.dataTransfer.setData("text/plain",String(I)),_.currentTarget.style.opacity="0.4"},M=_=>{_.currentTarget.style.opacity="1",x(null),C(null)},R=(_,I)=>{_.preventDefault(),_.dataTransfer.dropEffect="move",E!==I&&C(I)},D=async(_,I)=>{if(_.preventDefault(),C(null),u==null)return;const P=g[u];if(!P||P.group===I)return;const q=os.find(Y=>Y.id===I);if(q){try{if(P.kind==="task"){if(P.data.status==="pending")return;await le.tasks.updateStatus(P.data.id,q.dropStatus)}else{const Y=jl[I];Y&&await le.requirements.updateStatus(P.data.id,Y)}a()}catch{}x(null)}},A=p.useMemo(()=>new Map(s.map(_=>[_.id,_])),[s]),T=p.useMemo(()=>new Map(r.map(_=>[_.id,_])),[r]),$=["todo","in_progress","review","done"],z=p.useMemo(()=>{const _={};for(const I of g)_[I.group]=(_[I.group]??0)+1;return _},[g]),{rowsByGroup:N,rowIndexMap:O}=p.useMemo(()=>{const _=new Map,I=new Map;for(let P=0;P<g.length;P++){const q=g[P];I.set(q,P);const Y=_.get(q.group)??[];Y.push(q),_.set(q.group,Y)}return{rowsByGroup:_,rowIndexMap:I}},[g]),L=p.useMemo(()=>{if(f!=="status")return null;const _=new Set(g.map(q=>q.group)),I=[],P=new Set;_.has("failed")&&(I.push("failed"),P.add("failed"));for(const q of $)I.push(q),P.add(q);for(const q of g)P.has(q.group)||(I.push(q.group),P.add(q.group));return I},[g,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:g.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"&&L?L.map(_=>{const I=N.get(_)??[];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 ${Zh[_]??""} ${E===_?"ring-1 ring-brand-500/40":""}`,onDragOver:P=>R(P,_),onDragLeave:()=>C(null),onDrop:P=>{D(P,_)},children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:d(`work:boardColumn.${_}`)}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:z[_]??0})]}),I.map(P=>t.jsx(Ua,{row:P,idx:O.get(P)??0,dragIdx:u,agentMap:A,projMap:T,onTaskClick:i,onReqClick:o,onRowDragStart:k,onRowDragEnd:M,handleStatusChange:b,handlePriorityChange:j,selected:P.kind==="task"?P.data.id===c:P.data.id===l,isMobile:h,isAbnormalBlocked:P.kind==="task"?y(P.data):!1},`${P.kind}-${P.data.id}`))]},_)}):g.map((_,I)=>t.jsx(Ua,{row:_,idx:I,dragIdx:u,agentMap:A,projMap:T,onTaskClick:i,onReqClick:o,onRowDragStart:k,onRowDragEnd:M,handleStatusChange:b,handlePriorityChange:j,selected:_.kind==="task"?_.data.id===c:_.data.id===l,isMobile:h,isAbnormalBlocked:_.kind==="task"?y(_.data):!1},`${_.kind}-${_.data.id}`)),g.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 em(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 Xr(e){return/[:#\[\]{}&*!|>'"%@`\n]/.test(e)||e.startsWith(" ")||e.endsWith(" ")?JSON.stringify(e):e}function tm(e,n,s){const r=[];r.push(`name: ${Xr(e)}`),r.push(`description: ${Xr(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: ${Xr(i.name)}`),r.push(" type: agent_task"),r.push(` role: ${Xr(i.role)}`),i.depends_on.length>0&&r.push(` depends_on: [${i.depends_on.join(", ")}]`),i.depends_on.length>0){r.push(" inputs:");for(const o of i.depends_on)r.push(` - from: ${o}`),r.push(` as: ${o}_output`)}r.push(" prompt: |");for(const o of i.prompt.split(`
|
|
9
|
-
`))r.push(` ${o}`);r.push("")}return r.join(`
|
|
10
|
-
`)}function nm({req:e,tasks:n,agents:s,teamId:r,onClose:i,onSaved:o}){const{t:a}=$e(["work"]),c=p.useMemo(()=>{const D={};for(const A of s)D[A.id]=A.name;return D},[s]),l=p.useMemo(()=>em(n,c),[n,c]),[d,h]=p.useState(()=>Ws(e.title)),[f,m]=p.useState(e.description||e.title),[u,x]=p.useState(l),[E,C]=p.useState(!1),[v,y]=p.useState(null),g=(D,A,T)=>{x($=>$.map((z,N)=>N===D?{...z,[A]:T}:z))},b=D=>{const A=u[D]?.id;x(T=>T.filter(($,z)=>z!==D).map($=>({...$,depends_on:$.depends_on.filter(z=>z!==A)})))},[j,k]=p.useState(!1),M=async()=>{if(d.trim()){C(!0),y(null);try{const D=tm(d.trim(),f,u);await le.workflows.create(r,d.trim(),D),k(!0),setTimeout(()=>o(),800)}catch(D){y(String(D))}C(!1)}},R=p.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:R.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:T=>g(A,"name",T.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:T=>g(A,"role",T.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(T=>{const $=u.find(z=>z.id===T);return t.jsx("span",{className:"px-1.5 py-0.5 bg-surface-elevated rounded text-fg-secondary",children:$?.name??T},T)})]}),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))})]}),v&&t.jsx("p",{className:"text-xs text-red-500",children:v}),j&&t.jsx("p",{className:"text-xs text-green-500 font-medium",children:a("work:task.workflowSavedSuccess","Workflow saved successfully")})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2 px-6 py-4 border-t border-border-default",children:[t.jsx("button",{onClick:i,className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary hover:bg-surface-elevated rounded-lg transition-colors",children:a("work:task.cancel","Cancel")}),t.jsx("button",{onClick:M,disabled:E||j||!d.trim()||u.length===0,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm rounded-lg font-medium transition-colors",children:E?a("work:task.saving","Saving..."):j?a("work:task.workflowSavedSuccess","Saved!"):a("work:task.saveWorkflow","Save Workflow")})]})]})})}function Xa({teamId:e,agents:n,compact:s}){const{t:r}=$e(["work"]),i=p.useMemo(()=>e?n.find(a=>a.teamId===e&&a.agentRole==="manager"):n.find(a=>a.agentRole==="manager"),[n,e]),o=()=>{i&&kt.navigate(He.TEAM,{agentId:i.id,prefillMessage:r("work:task.workflowCreatePrompt","Please create a workflow template for our team. Review the team composition, then design a multi-step process that matches our regular work. Use the workflow_create tool to save it. If the user specifies a project, bind the workflow to that project by including a project_id parameter. Otherwise, leave project as an optional runtime parameter so users can choose when starting a run.")})};return t.jsxs("div",{className:s?"max-w-4xl space-y-3":"max-w-lg w-full text-center space-y-5",children:[!s&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-brand-500/10",children:t.jsx("svg",{className:"w-8 h-8 text-brand-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3.75 6A2.25 2.25 0 016 3.75h2.25A2.25 2.25 0 0110.5 6v2.25a2.25 2.25 0 01-2.25 2.25H6a2.25 2.25 0 01-2.25-2.25V6zM3.75 15.75A2.25 2.25 0 016 13.5h2.25a2.25 2.25 0 012.25 2.25V18a2.25 2.25 0 01-2.25 2.25H6A2.25 2.25 0 013.75 18v-2.25zM13.5 6a2.25 2.25 0 012.25-2.25H18A2.25 2.25 0 0120.25 6v2.25A2.25 2.25 0 0118 10.5h-2.25a2.25 2.25 0 01-2.25-2.25V6zM13.5 15.75a2.25 2.25 0 012.25-2.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-2.25A2.25 2.25 0 0113.5 18v-2.25z"})})}),t.jsxs("div",{children:[t.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-1.5",children:r("work:task.workflowEmptyTitle","No workflow templates yet")}),t.jsx("p",{className:"text-sm text-fg-secondary leading-relaxed",children:r("work:task.workflowEmptyDesc","Workflows automate repeatable multi-step processes. Define a sequence of tasks as a DAG — the system handles dependencies, role assignment, and scheduling automatically.")})]})]}),t.jsxs("details",{className:s?"group":"",open:!s,children:[t.jsxs("summary",{className:`text-xs font-medium text-fg-secondary uppercase tracking-wider cursor-pointer select-none list-none flex items-center gap-1.5 ${s?"py-1":"sr-only"}`,children:[t.jsx("svg",{className:"w-3 h-3 transition-transform group-open:rotate-90",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),r("work:task.workflowHowItWorks","How it works")]}),t.jsxs("div",{className:`bg-surface-secondary border border-border-default/40 rounded-xl p-4 text-left space-y-3 ${s?"mt-2":""}`,children:[!s&&t.jsx("p",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:r("work:task.workflowHowItWorks","How it works")}),t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:"shrink-0 w-6 h-6 rounded-full bg-brand-500/15 flex items-center justify-center text-[11px] font-bold text-brand-500",children:"1"}),t.jsxs("div",{className:"text-xs text-fg-secondary leading-relaxed",children:[t.jsx("span",{className:"font-medium text-fg-primary",children:r("work:task.workflowStep1Title","Requirement")})," — ",r("work:task.workflowStep1Desc","A workflow run creates a Requirement to group all its tasks under one trackable goal.")]})]}),t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:"shrink-0 w-6 h-6 rounded-full bg-brand-500/15 flex items-center justify-center text-[11px] font-bold text-brand-500",children:"2"}),t.jsxs("div",{className:"text-xs text-fg-secondary leading-relaxed",children:[t.jsx("span",{className:"font-medium text-fg-primary",children:r("work:task.workflowStep2Title","Task DAG")})," — ",r("work:task.workflowStep2Desc","Each step becomes a Task assigned to the right team member. Dependencies are tracked — downstream tasks wait for upstream ones to finish.")]})]}),t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:"shrink-0 w-6 h-6 rounded-full bg-brand-500/15 flex items-center justify-center text-[11px] font-bold text-brand-500",children:"3"}),t.jsxs("div",{className:"text-xs text-fg-secondary leading-relaxed",children:[t.jsx("span",{className:"font-medium text-fg-primary",children:r("work:task.workflowStep3Title","Auto-execution")})," — ",r("work:task.workflowStep3Desc","Agents pick up tasks, pass deliverables downstream, and the workflow completes automatically. Optionally, schedule it to run on a recurring basis.")]})]})]})]}),i&&t.jsx("div",{className:s?"":"text-center",children:t.jsxs("button",{onClick:o,className:"inline-flex items-center gap-2 px-4 py-2 bg-brand-600 hover:bg-brand-500 text-white text-sm rounded-lg font-medium transition-colors",children:[t.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),r("work:task.workflowAskManager","Ask {{name}} to create a workflow",{name:i.name})]})})]})}function rm({teamId:e,projectId:n,agents:s,projects:r,onViewRunTasks:i}){const{t:o}=$e(["work"]),[a,c]=p.useState([]),[l,d]=p.useState({}),[h,f]=p.useState(!1),[m,u]=p.useState(null),[x,E]=p.useState({}),[C,v]=p.useState(!1),[y,g]=p.useState(null),[b,j]=p.useState([]),[k,M]=p.useState(null),[R,D]=p.useState(null),[A,T]=p.useState({}),[$,z]=p.useState(null),[N,O]=p.useState(null),[L,_]=p.useState(null),[I,P]=p.useState([]),[q,Y]=p.useState({}),[F,Q]=p.useState(null),[B,S]=p.useState({}),[V,W]=p.useState(new Set),H=e??k;p.useEffect(()=>{e||le.teams.list().then(({teams:U})=>{j(U.map(oe=>({id:oe.id,name:oe.name})))}).catch(()=>{})},[e]),p.useMemo(()=>{const U={};for(const oe of s)U[oe.id]=oe.name;return U},[s]);const K=p.useCallback(async()=>{const U=H?[H]:b.map(oe=>oe.id);if(U.length!==0){f(!0);try{const oe=[],ue={},we={};await Promise.all(U.map(async de=>{try{const{workflows:se}=await le.workflows.list(de);for(const xe of se)we[xe.name]=de;oe.push(...se),await Promise.all(se.map(async xe=>{try{const{runs:Me}=await le.workflows.listRuns(de,xe.name,5);ue[xe.name]=Me}catch{}}))}catch{}})),c(oe),d(ue),S(we)}catch{}f(!1)}},[H,b]);p.useEffect(()=>{K()},[K]);const te=U=>H??B[U],re=async U=>{if(R===U.name){D(null);return}D(U.name);const oe=te(U.name);if(!A[U.name]&&oe)try{const{template:ue}=await le.workflows.get(oe,U.name);T(we=>({...we,[U.name]:ue}))}catch{}},fe=U=>{const oe={};for(const se of U.params??[])se.default&&(oe[se.name]=se.default);E(oe),g(null),P([]),Y({});const ue=localStorage.getItem(`markus_wf_project_${U.name}`)??localStorage.getItem("markus_wf_project_last"),we=ue&&r.some(se=>se.id===ue)?ue:null;Q(n??we??r[0]?.id??null),u(U);const de=te(U.name);de&&le.workflows.roles(de,U.name).then(({roles:se})=>P(se)).catch(()=>{})},J=async()=>{const U=F??r[0]?.id,oe=m?te(m.name):void 0;if(!m||!oe||!U){g(U?o("work:task.workflowNoTeam","Cannot determine team for this workflow"):o("work:task.workflowNoProject","Please select a project"));return}v(!0),g(null);try{let ue;if(I.length>0){ue={};for(const we of I)ue[we.role]=q[we.role]??we.recommended??""}await le.workflows.startRun(oe,m.name,U,x,ue),localStorage.setItem(`markus_wf_project_${m.name}`,U),localStorage.setItem("markus_wf_project_last",U),u(null),K()}catch(ue){g(String(ue))}v(!1)};if(!H&&b.length===0&&!e)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:o("work:task.selectProjectForWorkflows","Select a project with a team to view workflows")});if(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 Z=async U=>{z(U),O(null);try{await le.workflows.cancelRun(U),K()}catch{}z(null)},ce=async U=>{_(U.id);try{U.status==="running"?await le.workflows.pauseRun(U.id):U.status==="paused"&&await le.workflows.resumeRun(U.id),K()}catch{}_(null)},ae=U=>{U.requirementId&&i&&i(U.requirementId)},pe=U=>{const oe={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 ${oe[U]??"bg-gray-500/20 text-gray-400"}`,children:U})},ge=m&&(m.params??[]).some(U=>U.required&&!x[U.name]?.trim());return t.jsxs("div",{className:"flex-1 min-h-0 overflow-auto px-4 py-5",children:[!e&&b.length>0&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-4",children:[t.jsx("button",{onClick:()=>{k!==null&&(M(null),c([]),d({}))},className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${k===null?"bg-brand-600 text-white":"bg-surface-secondary border border-border-default/50 text-fg-secondary hover:text-fg-primary hover:border-border-default"}`,children:o("work:task.all","All")}),b.map(U=>t.jsx("button",{onClick:()=>{k!==U.id&&(M(U.id),c([]),d({}))},className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${k===U.id?"bg-brand-600 text-white":"bg-surface-secondary border border-border-default/50 text-fg-secondary hover:text-fg-primary hover:border-border-default"}`,children:U.name},U.id))]}),a.length===0&&!h?t.jsx("div",{className:"flex-1 flex items-center justify-center px-4",children:t.jsx(Xa,{teamId:H,agents:s})}):t.jsxs("div",{className:"grid gap-4 max-w-4xl",children:[a.map(U=>{const oe=R===U.name,ue=A[U.name],de=(l[U.name]??[]).some(se=>se.status==="running"||se.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:()=>re(U),children:[t.jsx("div",{className:"flex-1 min-w-0",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("svg",{className:`w-3.5 h-3.5 text-fg-tertiary shrink-0 transition-transform ${oe?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),t.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:U.displayName||U.name}),t.jsx("span",{className:"text-[11px] text-fg-tertiary",children:o("work:task.workflowStepsCount","{{count}} steps",{count:U.stepCount})})]})}),t.jsxs("div",{className:"flex 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:se=>{se.stopPropagation();const xe=te(U.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&&kt.navigate(He.TEAM,{agentId:ye,prefillMessage:`@[${U.displayName||U.name}](workflow:${U.name}) `})},children:[t.jsx("svg",{className:"w-3.5 h-3.5 inline mr-0.5 -mt-px",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),U.name]}),U.hasSchedule&&t.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-500/20 text-purple-400",children:o("work:task.workflowScheduled","Scheduled")}),t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["v",U.version]}),de?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:se=>{se.stopPropagation(),fe(U)},className:"px-3 py-1 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg font-medium transition-colors",children:o("work:task.workflowRun","Run")})]})]}),oe&&ue&&t.jsxs("div",{className:"border-t border-border-default/30 pt-3 mt-1 ml-5 space-y-3",children:[U.description&&t.jsx("p",{className:"text-xs text-fg-tertiary",children:U.description}),t.jsxs("div",{children:[t.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium mb-2 uppercase tracking-wider",children:o("work:task.workflowSteps","Steps")}),t.jsx("div",{className:"space-y-1.5",children:ue.steps.map((se,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:se.name}),t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary",children:se.role}),se.depends_on&&se.depends_on.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["← ",se.depends_on.join(", ")]})]}),t.jsx("p",{className:"text-[10px] text-fg-tertiary line-clamp-1 mt-0.5",children:se.prompt})]})]},se.id))})]}),ue.steps.some(se=>se.depends_on&&se.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:ue.steps.map((se,xe)=>{const Me=se.depends_on&&se.depends_on.length>0;return t.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[Me&&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:se.name})]},se.id)})})]}),ue.params&&ue.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:ue.params.length})}),t.jsx("div",{className:"flex flex-wrap gap-2",children:ue.params.map(se=>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:se.label||se.name}),t.jsxs("span",{className:"text-fg-quaternary",children:["(",se.type||"string",")"]}),se.required&&t.jsx("span",{className:"text-red-400",children:"*"})]},se.name))})]}),ue.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:[ue.schedule.cron&&`cron: ${ue.schedule.cron}`,ue.schedule.interval&&`every: ${ue.schedule.interval}`]})]})]}),(()=>{const se=l[U.name]??[];if(se.length===0)return null;const xe=V.has(U.name),Me=xe?se:se.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(U.name)?Re.delete(U.name):Re.add(U.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")}),se.length>1&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["(",se.length,")"]})]}),t.jsx("div",{className:"space-y-1",children:Me.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]}),pe(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(),ce(ye)},disabled:L===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:L===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:()=>ae(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))})]})})()]},U.name)}),t.jsx(Xa,{teamId:H,agents:s,compact:!0})]}),m&&t.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50",onClick:()=>u(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-full max-w-md shadow-2xl",onClick:U=>U.stopPropagation(),children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary mb-1",children:o("work:task.workflowRunTitle","Run: {{name}}",{name:m.displayName||m.name})}),t.jsx("p",{className:"text-xs text-fg-tertiary mb-4",children:m.description}),(m.params??[]).length>0&&t.jsx("div",{className:"space-y-3 mb-4",children:(m.params??[]).map(U=>t.jsxs("div",{children:[t.jsxs("label",{className:"block text-xs text-fg-secondary mb-1",children:[U.label||U.name,U.required&&t.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),U.type==="enum"&&U.options?t.jsx(wt,{options:[{value:"",label:"—"},...U.options.map(oe=>({value:oe,label:oe}))],value:x[U.name]??"",onChange:oe=>E(ue=>({...ue,[U.name]:oe})),placeholder:"—",className:"w-full"}):t.jsx("textarea",{value:x[U.name]??"",onChange:oe=>{E(de=>({...de,[U.name]:oe.target.value}));const ue=oe.target;ue.style.height="auto";const we=parseFloat(getComputedStyle(ue).lineHeight)||18;ue.style.height=Math.min(ue.scrollHeight,we*7)+"px"},placeholder:U.default??"",rows:1,className:"input-field text-xs w-full resize-none overflow-y-auto",style:{maxHeight:`${7*1.5}em`}})]},U.name))}),I.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:I.map(U=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-xs text-fg-secondary w-24 shrink-0 font-medium",children:U.role}),t.jsx(wt,{options:U.candidates.map(oe=>({value:oe.agentId,label:oe.agentName+(oe.agentId===U.recommended?" ★":"")})),value:q[U.role]??U.recommended??"",onChange:oe=>Y(ue=>({...ue,[U.role]:oe})),className:"flex-1"})]},U.role))})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("label",{className:"block text-xs text-fg-secondary mb-1",children:o("work:task.workflowProject","Project")}),t.jsx(wt,{options:[{value:"",label:o("work:task.workflowSelectProject","— Select a project —")},...r.map(U=>({value:U.id,label:U.name}))],value:F??"",onChange:U=>{const oe=U||null;Q(oe),g(null),oe&&localStorage.setItem("markus_wf_project_last",oe)},placeholder:o("work:task.workflowSelectProject","— Select a project —"),className:"w-full"})]}),y&&t.jsx("p",{className:"text-xs text-red-400 mb-3",children:y}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>u(null),className:"btn-secondary text-xs px-4 py-1.5",children:o("work:task.workflowCancel","Cancel")}),t.jsx("button",{onClick:J,disabled:C||!!ge,className:"btn-primary text-xs px-4 py-1.5",children:C?o("work:task.workflowStarting","Starting..."):o("work:task.workflowStartRun","Start Run")})]})]})}),N&&t.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50",onClick:()=>O(null),children:t.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-full max-w-sm shadow-2xl",onClick:U=>U.stopPropagation(),children:[t.jsx("h3",{className:"text-sm font-semibold text-fg-primary mb-2",children:o("work:task.workflowConfirmCancelTitle","Cancel Workflow Run")}),t.jsx("p",{className:"text-xs text-fg-secondary mb-5",children:o("work:task.workflowConfirmCancelDesc","This will cancel all running and pending tasks in this workflow run. This action cannot be undone.")}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:()=>O(null),className:"btn-secondary text-xs px-4 py-1.5",children:o("work:task.workflowNo","No")}),t.jsx("button",{onClick:()=>Z(N),disabled:$===N,className:"px-4 py-1.5 bg-red-600 hover:bg-red-500 text-white text-xs rounded-lg font-medium transition-colors",children:$===N?o("work:task.workflowCancelling","Cancelling..."):o("work:task.workflowConfirmCancelBtn","Confirm Cancel")})]})]})})]})}function dm({authUser:e,previewMode:n,previewData:s}={}){const{t:r}=$e(["work","common"]),i=Ul(He.WORK),o=p.useMemo(()=>os.map(w=>({...w,label:r(`work:boardColumn.${w.id}`)})),[r]),a=p.useMemo(()=>kl(r),[r]),c=p.useMemo(()=>lo(r),[r]),l=yr(),d=Xl(),h=d?.leftCollapsed??!1,f=p.useRef(null),[m,u]=p.useState(0);p.useEffect(()=>{const w=f.current;if(!w)return;const X=new ResizeObserver(([ee])=>u(ee.contentRect.width));return X.observe(w),u(w.clientWidth),()=>X.disconnect()},[]);const[x,E]=p.useState(()=>{if(n)return!1;try{return localStorage.getItem(Aa)==="1"}catch{return!1}}),C=p.useCallback(w=>{E(w);try{localStorage.setItem(Aa,w?"1":"0")}catch{}},[]),v=p.useRef(h);p.useEffect(()=>{n||l||v.current!==h&&(v.current=h,E(h))},[h,n,l]);const y=Zl({side:"left",defaultWidth:240,minWidth:180,maxWidth:360,storageKey:"markus_work_l1"}),g=6,b=!l&&!x?y.width+g:0,j=Math.max(0,(m||window.innerWidth)-b-g-8),k=Math.max(320,Math.round(j/2)),[M,R]=p.useState("auto"),D=Math.max(320,j-280),A=M==="auto"?Math.min(k,D):M,T=Math.max(320,Math.min(A,D)),$=p.useRef(T);$.current=T;const z=p.useRef(D);z.current=D;const N=p.useCallback(w=>{w.preventDefault();const X=w.clientX,ee=$.current,ne=Se=>{const ke=Math.max(320,Math.min(z.current,ee+(X-Se.clientX)));R(ke)},he=()=>{document.removeEventListener("mousemove",ne),document.removeEventListener("mouseup",he),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",ne),document.addEventListener("mouseup",he),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]),[O,L]=p.useState(!1),_=p.useRef(O);_.current=O;const[I,P]=p.useState(s?.projects??[]),[q,Y]=p.useState("all"),[F,Q]=p.useState(null),[B,S]=p.useState("closed"),[V,W]=p.useState("projects"),[H,K]=p.useState(s?.board??{}),[te,re]=p.useState(s?.agents??[]),[fe,J]=p.useState([]),[Z,ce]=p.useState(s?.users??[]),[ae,pe]=p.useState(s?.allRequirements??[]),[ge,U]=p.useState(!s),[oe,ue]=p.useState(""),we=p.useCallback(()=>{Nr(F??""),Zt(!0)},[F]),[de,se]=p.useState(!1),[xe,Me]=p.useState(!1),[ye,Re]=p.useState(""),[pt,gt]=p.useState(""),[jt,Ft]=p.useState("medium"),[Qe,Yt]=p.useState(""),[dt,At]=p.useState(""),[ut,Ue]=p.useState(""),[Dt,xt]=p.useState(""),[st,Nt]=p.useState([]),[Xe,be]=p.useState("standard"),[Je,it]=p.useState("4h"),[Pt,et]=p.useState(""),[bt,Gt]=p.useState(!1),[Ne,Ce]=p.useState(null),[Ae,De]=p.useState(()=>s?.initialSelectedReqId&&s.allRequirements?s.allRequirements.find(w=>w.id===s.initialSelectedReqId)??null:null);p.useEffect(()=>{s?.initialSelectedReqId&&Ae&&S("item")},[]);const[ze,$t]=p.useState(new Set),[Ze,Bt]=p.useState(!1),[ot,Kt]=p.useState(new Set),Ct=p.useRef(new Set),[Ut,Ot]=p.useState(null),[Ge,lt]=p.useState(s?.initialBoardType??"backlog"),[pn,sn]=p.useState(null),on=p.useMemo(()=>[{id:"backlog"},{id:"kanban"},{id:"dag"},{id:"workflows"}],[]),zt=Ls(on,Ge,lt),tt=p.useRef(null),Xt=p.useMemo(()=>({scrollContainerRef:tt}),[]),Ht=Ls(on,Ge,lt,Xt),[We,G]=p.useState(!1),[me,Te]=p.useState(null),[Ie,Ee]=p.useState(!1),nt=p.useRef(null),qt=p.useRef(null),[gn,Zt]=p.useState(!1),[xn,bn]=p.useState(""),[Rn,yn]=p.useState(""),[er,ms]=p.useState("medium"),[vn,Nr]=p.useState(""),[an,St]=p.useState(null),[Cr,Sr]=p.useState(""),[tr,ln]=p.useState(""),[ps,co]=p.useState(!1),[uo,_n]=p.useState(""),ct=w=>{ue(w),setTimeout(()=>ue(""),3e3)};p.useEffect(()=>{const w=X=>{X.key==="Escape"&&(an?(St(null),_n("")):xe?(Me(!1),et("")):gn?(Zt(!1),bn(""),yn(""),ln("")):Ie?Ee(!1):B!=="closed"&&(S("closed"),Ce(null),De(null),l&&_.current&&L(!1)))};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[an,xe,gn,Ie,B,l]);const yt=I.find(w=>w.id===F)??null,Sl=yt?.teamIds?.[0]??null,El=p.useMemo(()=>I.filter(w=>w.status!=="archived"),[I]),fo=p.useCallback(()=>{F&&(Ce(null),De(null),S("project"),R("auto"),l&&L(!0))},[F,l]),Er=p.useCallback(()=>{if(B==="project"){S("closed"),l&&L(!1);return}fo()},[B,fo,l]);p.useEffect(()=>{Ct.current=ot},[ot]);const wn=p.useCallback(async()=>{try{const{projects:w}=await le.projects.list();P(w)}catch{}},[]),rt=p.useCallback(async()=>{const w={};q==="project"&&F&&(w.projectId=F);try{const{board:X}=await le.tasks.board(w);K(X)}catch{}},[q,F]),nr=p.useCallback(async()=>{try{const{agents:w}=await le.agents.list();re(w)}catch{}},[]),ho=p.useCallback(async()=>{try{const{teams:w}=await le.teams.list();J(w.map(X=>({id:X.id,name:X.name})))}catch{}},[]),mo=p.useCallback(async()=>{try{const{users:w}=await le.users.list(e?.orgId);ce(w)}catch{}},[e?.orgId]),Et=p.useCallback(async()=>{try{const{requirements:w}=await le.requirements.list({});pe(w)}catch{}},[]),po=p.useCallback(async()=>{await Promise.all([wn(),rt(),nr(),mo(),Et(),ho()]),U(!1)},[wn,rt,nr,mo,Et,ho]);p.useEffect(()=>{n||po()},[n,po]),p.useEffect(()=>{!n||!s||(P(s.projects??[]),K(s.board??{}),re(s.agents??[]),ce(s.users??[]),pe(s.allRequirements??[]))},[n,s]);const Mr=p.useCallback(w=>{W("items"),Ce(X=>X?.id===w.id&&B==="item"?(S("closed"),l&&_.current&&L(!1),null):(S("item"),R("auto"),l&&(L(!0),history.pushState({mobileDetail:He.WORK},"",window.location.hash)),w)),De(null)},[l,B]),Tr=p.useCallback(w=>{W("items"),De(X=>X?.id===w.id&&B==="item"?(S("closed"),l&&_.current&&L(!1),null):(S("item"),R("auto"),l&&(L(!0),history.pushState({mobileDetail:He.WORK},"",window.location.hash)),w)),Ce(null)},[l,B]),kn=p.useCallback(()=>{Ce(null),De(null),S("closed"),l&&_.current&&L(!1)},[l]),Qt=p.useRef(Ne);Qt.current=Ne;const Jt=p.useRef(Ae);Jt.current=Ae;const jn=p.useRef(B);jn.current=B;const Ln=p.useRef(V);Ln.current=V;const An=p.useRef(x);An.current=x;const gs=p.useRef(Ge);gs.current=Ge;const Ml=p.useCallback(()=>{Ce(null),Jt.current||(S("closed"),l&&_.current&&L(!1))},[l]);p.useEffect(()=>{if(!l)return;const w=()=>{_.current&&(L(!1),Ce(null),De(null),S("closed"))};return window.addEventListener("popstate",w),()=>window.removeEventListener("popstate",w)},[l]),p.useEffect(()=>{if(n||!i)return;rt(),nr(),Et();const w=Qt.current?12e4:45e3,X=setInterval(()=>{rt(),nr(),Et()},w);let ee=null;const ne=()=>{ee||(ee=setTimeout(()=>{ee=null,rt()},800))};let he=null;const Se=()=>{he||(he=setTimeout(()=>{he=null,Et()},800))},ke=mt.on("task:update",Be=>{Tt("/taskboard"),ne();const je=Be?.payload;je?.taskId&&(Ce(Ve=>{if(!Ve||Ve.id!==je.taskId)return Ve;const Le={};return typeof je.status=="string"&&(Le.status=je.status),Array.isArray(je.deliverables)&&(Le.deliverables=je.deliverables),Array.isArray(je.notes)&&(Le.notes=je.notes),je.result!==void 0&&(Le.result=je.result),{...Ve,...Le}}),Qt.current?.id===je.taskId&&(Tt("/tasks/"+je.taskId),le.tasks.get(je.taskId).then(Ve=>{Ve.task&&Ce(Le=>Le?.id===Ve.task.id?Ve.task:Le)}).catch(()=>{})))}),ie=mt.on("task:create",()=>{ne()}),vt=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(Be=>mt.on(Be,je=>{Tt("/requirements"),Se();const Ve=je?.payload,Le=Ve?.id??Ve?.requirementId;Le&&Jt.current?.id===Le&&(Tt("/requirements/"+Le),le.requirements.get(Le).then(tn=>{tn.requirement&&De(Sn=>Sn?.id===tn.requirement.id?tn.requirement:Sn)}).catch(()=>{}))})),ft=()=>{Tt("/taskboard"),Tt("/tasks"),Tt("/requirements"),rt(),Et(),Qt.current&&le.tasks.get(Qt.current.id).then(Be=>{Be.task&&Ce(je=>je?.id===Be.task.id?Be.task:je)}).catch(()=>{}),Jt.current&&le.requirements.get(Jt.current.id).then(Be=>{Be.requirement&&De(je=>je?.id===Be.requirement.id?Be.requirement:je)}).catch(()=>{})};return window.addEventListener("markus:data-changed",ft),()=>{clearInterval(X),ke(),ie(),vt.forEach(Be=>Be()),window.removeEventListener("markus:data-changed",ft),ee&&clearTimeout(ee),he&&clearTimeout(he)}},[n,i,rt,nr,Et]);const go=p.useRef(H);go.current=H;const xo=p.useRef(ae);xo.current=ae,p.useEffect(()=>{const w=Qt.current;if(!w)return;const ee=Object.values(H).flat().find(ne=>ne.id===w.id);ee&&ee.updatedAt!==w.updatedAt&&Ce(ee)},[H]),p.useEffect(()=>{const w=Jt.current;if(!w)return;const X=ae.find(ee=>ee.id===w.id);X&&X.updatedAt!==w.updatedAt&&De(X)},[ae]);const cn=p.useCallback(w=>{if(!w){Kt(new Set),Q(null),Y("all"),history.replaceState(null,"",Or(He.WORK)),le.tasks.board({}).then(X=>K(X.board)).catch(()=>{});return}Q(w),Y("project"),Kt(new Set),history.replaceState(null,"",Or(He.WORK,w)),le.tasks.board({projectId:w}).then(X=>K(X.board)).catch(()=>{})},[]),[xs,rr]=p.useState(!1),sr=p.useCallback((w,X)=>{Ce(w),De(null),S("item"),W("items"),R("auto"),X?.scrollToComments&&rr(!0),l&&L(!0)},[l]),Dn=p.useCallback((w,X)=>{De(w),Ce(null),S("item"),W("items"),R("auto"),X?.scrollToComments&&rr(!0),l&&L(!0)},[l]),Pn=p.useRef(null);p.useEffect(()=>{const w=Pn.current||localStorage.getItem("markus_nav_openTask");if(!w)return;const ee=Object.values(H).flat().find(ne=>ne.id===w);ee?(Pn.current=null,cn(ee.projectId),sr(ee),localStorage.removeItem("markus_nav_openTask")):Pn.current||(Pn.current=w,localStorage.removeItem("markus_nav_openTask"),le.tasks.get(w).then(ne=>{ne.task&&(Pn.current=null,cn(ne.task.projectId),sr(ne.task))}).catch(()=>{Pn.current=null}))},[H,sr,cn]);const $n=p.useRef(null);p.useEffect(()=>{const w=$n.current||localStorage.getItem("markus_nav_openRequirement");if(!w)return;const X=ae.find(ee=>ee.id===w);X?($n.current=null,cn(X.projectId),Dn(X),localStorage.removeItem("markus_nav_openRequirement")):$n.current||($n.current=w,localStorage.removeItem("markus_nav_openRequirement"),le.requirements.get(w).then(ee=>{ee.requirement&&($n.current=null,cn(ee.requirement.projectId),Dn(ee.requirement))}).catch(()=>{$n.current=null}))},[ae,Dn,cn]);const Mt=p.useCallback((w,X)=>{Kt(new Set),Q(w),Y("project"),W(x?"items":"projects"),X?.keepItemDetail||(Ce(null),De(null),S(ee=>ee==="closed"?ee:"project")),history.replaceState(null,"",Or(He.WORK,w))},[x]),Vt=p.useCallback(w=>{Kt(new Set),Q(null),Y("all"),W(x?"items":"projects"),w?.keepItemDetail||(Ce(null),De(null),S(X=>X==="closed"?X:X==="project"?"closed":"empty")),history.replaceState(null,"",Or(He.WORK))},[x]),Nn=p.useRef(!1);p.useEffect(()=>{if(Nn.current)return;const w=window.location.hash.slice(1).split("/");if(zr(w[0])===He.WORK&&w[1]){Nn.current=!0,Mt(w[1],{keepItemDetail:!0});return}const X=localStorage.getItem("markus_nav_projectId");if(X){Nn.current=!0,localStorage.removeItem("markus_nav_projectId"),Mt(X,{keepItemDetail:!0});return}Nn.current=!0,Vt({keepItemDetail:!0})},[]),p.useEffect(()=>{if(!ge){if(!F){Nn.current=!0,q!=="all"&&Y("all");return}if(I.some(w=>w.id===F)){Nn.current=!0;return}Nn.current=!0,Vt({keepItemDetail:!0})}},[ge,I,F,Vt,q]);const Tl=p.useRef(zr(window.location.hash.slice(1).split("/")[0]));p.useEffect(()=>{if(n)return;const w=()=>{const ee=window.location.hash.slice(1).split("/"),ne=zr(ee[0]);Tl.current=ne,ne===He.WORK&&(ee[1]?Mt(ee[1],{keepItemDetail:!0}):Vt({keepItemDetail:!0}))},X=async ee=>{const ne=ee.detail;if(zr(ne.page)===He.WORK){if(ne.params?.openTask){const he=ne.params.openTask,Se=ne.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let ke=Object.values(go.current).flat().find(ie=>ie.id===he);if(!ke)try{ke=(await le.tasks.get(he)).task}catch{}ke&&(cn(ke.projectId),sr(ke,{scrollToComments:Se}))}if(ne.params?.openRequirement){const he=ne.params.openRequirement,Se=ne.params.scrollToComments==="true";let ke=xo.current.find(ie=>ie.id===he);if(!ke)try{ke=(await le.requirements.get(he)).requirement}catch{}ke&&(cn(ke.projectId),Dn(ke,{scrollToComments:Se}))}if(ne.params?.projectId&&Mt(ne.params.projectId),ne.params?.statusFilter){const he=ne.params.statusFilter;localStorage.removeItem("markus_nav_statusFilter"),Vh.has(he)&&G(!0),Te(he)}}};return window.addEventListener("markus:navigate",X),window.addEventListener("hashchange",w),()=>{window.removeEventListener("markus:navigate",X),window.removeEventListener("hashchange",w)}},[n]);const Il=w=>{se(!1),ct(r("work:task.projectCreated")),P(X=>X.some(ee=>ee.id===w.id)?X:[...X,w]),Mt(w.id),wn()},Rl=async w=>{try{await le.projects.delete(w),F===w&&Vt(),ct(r("work:task.projectDeleted")),wn(),rt()}catch(X){ct(r("work:task.errorGeneric",{message:String(X)}))}},bo=async()=>{if(!ye||!Qe||!dt||bt)return;et("");const w=dt.startsWith("human:"),X=dt.replace(/^(human|agent):/,"");if(Qe===X&&!w){ct(r("work:task.assignedReviewerDifferent"));return}const ee=ut||void 0,ne=Dt||void 0;Gt(!0);try{const{task:he}=await le.tasks.create(ye,pt,Qe,X,jt,ee,st.length>0?st:void 0,ne,Xe!=="standard"?Xe:void 0,Xe==="scheduled"?{every:Je}:void 0,w?"human":"agent");Re(""),gt(""),Nt([]),xt(""),be("standard"),it("4h"),Me(!1),rt(),he&&sr(he)}catch(he){const ke=`work:task.errorCode_${(he instanceof Qa?he.code:void 0)||"unknown"}`,ie=r(ke,{defaultValue:""});et(ie||r("work:task.errorCreatingTask",{message:he instanceof Error?he.message:String(he)}))}finally{Gt(!1)}},Bn=w=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:w}))},yo=()=>{Tt("/taskboard"),rt(),Ne&&(Bn({taskId:Ne.id}),Tt("/tasks/"+Ne.id),le.tasks.get(Ne.id).then(w=>{w.task&&Ce(X=>X?.id===w.task.id?w.task:X)}).catch(()=>{}))},Cn=()=>{Tt("/requirements"),Et(),Ae&&(Tt("/requirements/"+Ae.id),le.requirements.get(Ae.id).then(w=>{w.requirement&&De(X=>X?.id===w.requirement.id?w.requirement:X)}).catch(()=>{}))},vo=async()=>{if(!ps){if(!xn.trim()){ln(r("work:task.pleaseReqTitle"));return}if(!Rn.trim()){ln(r("work:task.pleaseReqDesc"));return}if(!vn){ln(r("work:task.pleaseReqProject"));return}ln(""),co(!0);try{const{requirement:w}=await le.requirements.create({title:xn.trim(),description:Rn.trim(),priority:er,projectId:vn});ct(r("work:task.requirementCreated")),bn(""),yn(""),Zt(!1),Et(),w&&Dn(w)}catch(w){ln(w instanceof Error?w.message:String(w))}finally{co(!1)}}},bs=async w=>{try{await le.requirements.approve(w),ct(r("work:task.requirementApproved")),Bn({requirementId:w}),Cn(),rt()}catch(X){ct(r("work:task.errorGeneric",{message:String(X)}))}},_l=async()=>{if(an){_n("");try{await le.requirements.reject(an,Cr),ct(r("work:task.requirementRejected")),Bn({requirementId:an}),St(null),Sr(""),_n(""),Cn()}catch(w){_n(w instanceof Error?w.message:String(w))}}},wo=async w=>{try{await le.requirements.cancel(w),ct(r("work:task.requirementCancelled")),Bn({requirementId:w}),Cn()}catch(X){ct(r("work:task.errorGeneric",{message:String(X)}))}},Ll=(w,X)=>{nt.current=X,qt.current=null,w.dataTransfer.effectAllowed="move",w.dataTransfer.setData("text/plain",`task:${X.id}`),w.currentTarget.style.opacity="0.4"},Al=(w,X)=>{qt.current=X,nt.current=null,w.dataTransfer.effectAllowed="move",w.dataTransfer.setData("text/plain",`req:${X.id}`),w.currentTarget.style.opacity="0.4"},ko=w=>{w.currentTarget.style.opacity="1",nt.current=null,qt.current=null,Ot(null)},Dl=(w,X)=>{w.preventDefault(),w.dataTransfer.dropEffect="move",Ut!==X&&Ot(X)},Pl=(w,X)=>{const ee=w.currentTarget.getBoundingClientRect(),{clientX:ne,clientY:he}=w;(ne<ee.left||ne>ee.right||he<ee.top||he>ee.bottom)&&Ut===X&&Ot(null)},$l=async(w,X)=>{w.preventDefault(),Ot(null);const ee=nt.current,ne=qt.current;if(ee){const he=o.find(ke=>ke.id===X);if(!he)return;const Se=he.dropStatus;if(ee.status===Se||ee.status==="pending")return;try{await le.tasks.updateStatus(ee.id,Se),rt()}catch{}}else if(ne){const he=jl[X];if(!he||ne.status===he)return;try{await le.requirements.updateStatus(ne.id,he),Et()}catch{}}},jo=w=>{$t(X=>{const ee=new Set(X);return ee.has(w)?ee.delete(w):ee.add(w),ee})},Ir=w=>{Mt(w)},Bl=new Set(["rejected","cancelled","archived"]),Rr=w=>Bl.has(w.status),or=(w,X=!1)=>{let ee=w.filter(ne=>We||!Rr(ne));return me&&(ee=ee.filter(ne=>ne.status===me)),q==="project"&&F&&(ee=ee.filter(ne=>ne.projectId===F)),ot.size>0&&(ee=ee.filter(ne=>ne.projectId&&ot.has(ne.projectId))),ze.size>0&&(ee=ee.filter(ne=>ne.assignedAgentId&&ze.has(ne.assignedAgentId))),Ze&&e?.id&&(ee=ee.filter(ne=>ne.createdBy===e.id)),ee},Ol=p.useMemo(()=>{const w=new Map;for(const X of Object.values(H))for(const ee of X)w.set(ee.id,ee);return w},[H]),zl=p.useMemo(()=>new Set(te.map(w=>w.id)),[te]),No=w=>w.statuses.flatMap(X=>or(H[X]??[])),en=p.useMemo(()=>{let w=ae;return We||(w=w.filter(X=>!Rr(X))),q==="project"&&F&&(w=w.filter(X=>X.projectId===F)),ot.size>0&&(w=w.filter(X=>X.projectId&&ot.has(X.projectId))),ze.size>0&&(w=w.filter(X=>ze.has(X.createdBy))),Ze&&e?.id&&(w=w.filter(X=>X.createdBy===e.id)),w},[ae,We,q,F,ot,ze,Ze,e?.id,zl]),Co=p.useCallback(w=>en.filter(X=>es[X.status]===w.id),[en]),Hl=o.filter(w=>{if(w.id==="failed"||w.id==="closed"){const X=No(w),ee=Co(w);return X.length+ee.length>0}return!0}),ar=Object.values(H).flat().filter(w=>Rr(w)).length+ae.filter(w=>Rr(w)).length,So=p.useMemo(()=>{const w=new Set(["completed","failed","cancelled","archived"]),X=Object.values(H).flat(),ee=new Set;for(const ne of X)ne.assignedAgentId&&!w.has(ne.status)&&(!F||ne.projectId===F)&&ee.add(ne.assignedAgentId);return[...te].sort((ne,he)=>{const Se=ee.has(ne.id)?0:1,ke=ee.has(he.id)?0:1;return Se-ke})},[te,H,F]),_r=p.useMemo(()=>{const w=new Map,X=[];for(const ne of So)if(ne.teamId){const he=w.get(ne.teamId)??[];he.push(ne.id),w.set(ne.teamId,he)}else X.push(ne);const ee=[];for(const ne of X)ee.push({kind:"agent",agent:ne});for(const ne of fe){const he=w.get(ne.id);he&&he.length>0&&ee.push({kind:"team",id:ne.id,name:ne.name,agentIds:he})}return ee},[So,fe]);p.useMemo(()=>{const w=new Set(["completed","failed","cancelled","archived"]),X=Object.values(H).flat(),ee=new Set;for(const he of X)he.projectId&&!w.has(he.status)&&ee.add(he.projectId);return[...We?I:I.filter(he=>he.status!=="archived")].sort((he,Se)=>{const ke=he.status==="archived"?1:0,ie=Se.status==="archived"?1:0;if(ke!==ie)return ke-ie;const Ke=ee.has(he.id)?0:1,vt=ee.has(Se.id)?0:1;return Ke!==vt?Ke-vt:he.name.localeCompare(Se.name)})},[I,H,We]);const Lr=p.useMemo(()=>[...I].sort((w,X)=>{const ee=w.status==="archived"?1:0,ne=X.status==="archived"?1:0;return ee!==ne?ee-ne:w.name.localeCompare(X.name)}),[I]),Ar=p.useMemo(()=>{const w={};for(const X of Object.values(H))for(const ee of X){const ne=ee.projectId??"__none__";w[ne]=(w[ne]??0)+1}return w},[H]),Dr=Object.values(Ar).reduce((w,X)=>w+X,0),ql=F?Ar[F]??0:Dr,Eo=p.useMemo(()=>{const w=or(Object.values(H).flat()),X=[];if(Ge==="kanban"){for(const ne of os){const he=ne.statuses.flatMap(ie=>w.filter(Ke=>Ke.status===ie)),ke=[...en.filter(ie=>es[ie.status]===ne.id).map(ie=>({kind:"req",data:ie,time:new Date(ie.updatedAt??ie.createdAt).getTime()})),...he.map(ie=>({kind:"task",data:ie,time:new Date(ie.updatedAt??ie.createdAt??0).getTime()}))];ke.sort((ie,Ke)=>Ke.time-ie.time);for(const ie of ke)ie.kind==="req"?X.push({kind:"req",data:ie.data}):X.push({kind:"task",data:ie.data})}return X}const ee=[];for(const ne of w){const he=Nl(ne.status);ee.push({kind:"task",data:ne,groupOrder:as[he]??5,time:new Date(ne.updatedAt??ne.createdAt??0).getTime()})}for(const ne of en){const he=es[ne.status]??"todo";ee.push({kind:"req",data:ne,groupOrder:as[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,en,Ge,We,me,F,ot,ze,Ze,e?.id,q]),Pr=p.useRef(Eo);Pr.current=Eo;const Mo=p.useRef(Lr);Mo.current=Lr;const ys=p.useRef(F);ys.current=F;const On=p.useCallback(w=>{w.kind==="req"?(De(w.data),Ce(null)):(Ce(w.data),De(null)),S("item"),R("auto"),W("items")},[]),To=p.useCallback(()=>{if(jn.current==="item"||jn.current==="empty"){S("closed"),Ce(null),De(null);return}if(Qt.current||Jt.current){S("item"),R("auto"),W("items");return}const w=Pr.current;if(w.length>0){On(w[0]);return}Ce(null),De(null),S("empty"),R("auto")},[On]);p.useEffect(()=>{if(!l)if(x){if(W("items"),jn.current==="project")if(Qt.current||Jt.current)S("item");else{const w=Pr.current;w.length>0?On(w[0]):S("closed")}}else Ln.current==="items"&&jn.current==="closed"||!x&&jn.current==="closed"&&W("projects")},[x,l,On]);const ir=d?.keyboardPane??"content",Io=p.useRef(ir);if(p.useEffect(()=>{if(n||l||!i)return;const w=Io.current;Io.current=ir,ir==="l1"&&(W("projects"),w!=="l1"&&An.current&&(C(!1),d?.setLeftCollapsed(!1)))},[ir,n,l,i,C,d]),p.useEffect(()=>{if(n||l||!i)return;const w=navigator.platform.toUpperCase().includes("MAC"),X=ee=>{if(d?.keyboardPane==="l0")return;const ne=w?ee.metaKey&&!ee.ctrlKey:ee.ctrlKey&&!ee.metaKey;if(ee.ctrlKey&&!ee.metaKey&&ee.key==="Tab"){ee.preventDefault();const je=Lh,Ve=je.indexOf(gs.current),Le=ee.shiftKey?je[(Ve-1+je.length)%je.length]:je[(Ve+1)%je.length];lt(Le);return}if(ne&&!ee.altKey&&!ee.shiftKey){const je=ee.key.toLowerCase();if(je==="j"){ee.preventDefault(),Er();return}if(je==="l"){ee.preventDefault(),To();return}}if(ne||ee.altKey||ee.ctrlKey||ee.metaKey||Jl(ee.target))return;const he=ee.key.length===1?ee.key.toLowerCase():ee.key;if(he==="h"||he==="ArrowLeft"){if(An.current){ee.preventDefault(),C(!1),d?.setLeftCollapsed(!1),W("projects"),d?.setKeyboardPane("l1");return}if(Ln.current==="items"){ee.preventDefault(),W("projects"),d?.setKeyboardPane("l1");return}ee.preventDefault(),d?.setL0FocusPageId(He.WORK),d?.setLeftCollapsed(!1),d?.setKeyboardPane("l0");return}if((he==="l"||he==="ArrowRight"||he==="Tab"&&!ee.shiftKey)&&!An.current&&Ln.current==="projects"){ee.preventDefault(),W("items"),d?.setKeyboardPane("content");return}if((he==="l"||he==="ArrowRight")&&(An.current||Ln.current==="items")){ee.preventDefault();return}const Se=he==="j"||he==="ArrowDown"?1:he==="k"||he==="ArrowUp"?-1:0;if(!Se)return;if((An.current?"items":Ln.current)==="projects"){ee.preventDefault(),d?.setKeyboardPane("l1");const je=Mo.current,Ve=je.length+1;if(je.length===0)return;const Le=ys.current==null?0:je.findIndex(zn=>zn.id===ys.current)+1,tn=Le<0?0:Le,Sn=Math.max(0,Math.min(Ve-1,tn+Se));if(Sn===0)Vt(),requestAnimationFrame(()=>{document.querySelector('[data-project-id="__all__"]')?.scrollIntoView({block:"nearest"})});else{const zn=je[Sn-1];Mt(zn.id),jn.current!=="closed"&&(S("project"),Ce(null),De(null)),requestAnimationFrame(()=>{document.querySelector(`[data-project-id="${zn.id}"]`)?.scrollIntoView({block:"nearest"})})}return}const ie=gs.current;if(ie!=="backlog"&&ie!=="kanban")return;ee.preventDefault(),d?.setKeyboardPane("content");const Ke=Pr.current;if(Ke.length===0){S(je=>je==="closed"?"empty":je);return}const vt=Qt.current?.id??Jt.current?.id??null;let ft=vt?Ke.findIndex(je=>je.data.id===vt):-1;ft<0&&(ft=Se>0?-1:0);const Be=Math.max(0,Math.min(Ke.length-1,ft+Se));On(Ke[Be]),requestAnimationFrame(()=>{document.querySelector(`[data-work-item-id="${Ke[Be].data.id}"]`)?.scrollIntoView({block:"nearest"})})};return document.addEventListener("keydown",X,!0),()=>document.removeEventListener("keydown",X,!0)},[n,l,i,Er,To,Mt,Vt,On,C,d]),ge)return t.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary",children:r("work:task.loadingPage")});const Ro=B!=="closed"||!!(Ne||Ae),$r=!l&&!!(Ne&&Ae)&&B==="item",_o=l?O:Ro;return t.jsxs("div",{ref:f,className:"flex-1 overflow-hidden flex bg-surface-primary",children:[!l&&t.jsx(Rh,{projects:Lr,selectedProjectId:F,allSelected:q==="all"&&!F,taskCounts:Ar,totalTaskCount:Dr,onSelectAll:()=>{Vt(),W("projects")},onSelectProject:w=>{Mt(w),W("projects")},onEditProject:w=>{Mt(w),Ce(null),De(null),S("project"),W("projects")},onCreateProject:()=>se(!0),onCollapse:()=>{const w=!x;C(w),d?.setLeftCollapsed(w)},width:y.width,onResizeStart:y.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:[oe&&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:oe}),l?t.jsxs("div",{className:"shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[t.jsx(Ql,{}),yt?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:yt.name}),t.jsx("button",{onClick:Er,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${B==="project"?"bg-surface-overlay text-fg-primary":"text-fg-tertiary"}`,children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):t.jsx("h2",{className:"text-sm font-semibold text-fg-primary min-w-0 flex-1 truncate",children:r("work:task.projectsCount",{count:I.length})}),t.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[t.jsx("button",{onClick:()=>se(!0),className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:r("work:task.shortProject")}),t.jsx("button",{onClick:we,className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:r("work:task.shortReq")}),t.jsx("button",{onClick:()=>{Ue(F??""),Me(!0)},className:"px-2 py-1 text-[11px] border border-amber-500/60 text-amber-600 rounded-md",children:r("work:task.shortTask")})]})]}),t.jsxs("div",{className:"flex 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:()=>lt(w),className:`px-2 py-0.5 text-[10px] font-medium transition-colors ${Ge===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:()=>G(w=>!w),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${We?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:We?r("work:task.hideArchived"):r("work:task.archivedCount",{count:ar})}),t.jsx("div",{className:"flex-1"}),me&&t.jsxs("button",{onClick:()=>Te(null),className:"px-2 py-0.5 text-[11px] rounded-md font-medium bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/30 flex items-center gap-1",children:[r(`common:status.${me==="in_progress"?"inProgress":me}`),t.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})]}),(El.length>1||te.length>0||e?.id)&&t.jsxs("button",{onClick:()=>Ee(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${ze.size>0||Ze?"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"})}),ze.size+(Ze?1:0)>0?r("work:task.filterWithCount",{count:ze.size+(Ze?1:0)}):r("work:task.filter")]})]})]}):t.jsxs("div",{"data-electron-drag":!0,className:"flex items-center gap-3 px-6 h-14 shrink-0",children:[t.jsx("button",{"data-no-drag":!0,type:"button",onClick:()=>{const w=!x;C(w),d?.setLeftCollapsed(w),W("projects")},className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors shrink-0 ${x?"bg-brand-500/15 text-brand-500 hover:bg-brand-500/25":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,title:r(x?"work:task.expand":"work:task.collapse"),children:t.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),t.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),yt?t.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1 shrink-0 min-w-0",children:[t.jsx($h,{value:yt.name,onSave:async w=>{await le.projects.update(yt.id,{name:w}),wn()},className:"text-sm font-semibold text-fg-primary"}),t.jsx("button",{onClick:Er,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${B==="project"?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:`${r("work:project.settingsTitle")} (⌘J)`,children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):t.jsx("h2",{className:"text-sm font-semibold text-fg-primary shrink-0",children:r("work:task.projectsCount",{count:I.length})}),ar>0&&t.jsx("button",{onClick:()=>G(w=>!w),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${We?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:We?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:()=>lt(w),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${Ge===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:we,className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg font-medium transition-colors",children:r("work:task.newRequirement")}),t.jsx("button",{onClick:()=>{Ue(F??""),Me(!0)},className:"px-3 py-1.5 border border-amber-500/60 text-amber-600 hover:bg-amber-500/10 text-xs rounded-lg font-medium transition-colors",children:r("work:task.newTaskBtn")})]}),t.jsx("div",{className:"flex-1"})]}),!l&&Ge!=="workflows"&&(_r.length>0||e?.id)&&(ql>0||en.length>0||ze.size>0||Ze)&&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:()=>{$t(new Set),Bt(!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 ${ze.size>0||Ze?"visible opacity-100":"invisible opacity-0"}`,children:r("work:task.clear")}),e?.id&&t.jsx("button",{type:"button",onClick:()=>Bt(w=>!w),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Ze?"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")}),_r.map(w=>{if(w.kind==="team"){const ne=w.agentIds.every(Se=>ze.has(Se)),he=!ne&&w.agentIds.some(Se=>ze.has(Se));return t.jsxs("button",{onClick:()=>{$t(Se=>{const ke=new Set(Se);if(ne)for(const ie of w.agentIds)ke.delete(ie);else for(const ie of w.agentIds)ke.add(ie);return ke})},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${ne?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":he?"bg-brand-600/10 text-brand-400 ring-1 ring-brand-500/20":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[t.jsx("svg",{className:"w-3.5 h-3.5 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"})}),w.name,t.jsx("span",{className:"text-[9px] text-fg-quaternary",children:w.agentIds.length})]},`team-${w.id}`)}const X=w.agent,ee=ze.has(X.id);return t.jsxs("button",{onClick:()=>jo(X.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:X.name[0]?.toUpperCase()}),X.name]},X.id)})]}),I.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:()=>se(!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&&en.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"})]})}),ze.size>0||Ze?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:()=>{$t(new Set),Bt(!1)},className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg font-medium transition-colors",children:r("work:task.clear")})]}):t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyNoReqsTitle")}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed whitespace-pre-line",children:r("work:task.emptyNoReqsHint")}),t.jsxs("div",{className:"flex items-center justify-center gap-2 pt-1",children:[t.jsx("button",{onClick:we,className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:r("work:task.createRequirementCta")}),t.jsx("button",{onClick:()=>{Ue(F??""),Me(!0)},className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs border border-amber-500/60 text-amber-600 hover:bg-amber-500/10 rounded-lg font-medium transition-colors",children:r("work:task.newTaskBtn")})]}),q==="project"&&t.jsxs("p",{className:"pt-3 text-[11px] text-fg-tertiary leading-relaxed",children:[r("work:task.emptyNoReqsUnassignedHint")," ",t.jsx("button",{type:"button",onClick:()=>Vt(),className:"inline text-brand-500 hover:text-brand-500 hover:underline",children:r("work:allProjects")})]})]})]})}):Ge==="backlog"?t.jsx("div",{className:"flex-1 min-h-0 flex flex-col",onTouchStart:l?zt.onTouchStart:void 0,onTouchEnd:l?zt.onTouchEnd:void 0,children:t.jsx(Jh,{tasks:or(Object.values(H).flat()),requirements:en,agents:te,projects:I,onTaskClick:w=>Mr(w),onReqClick:w=>Tr(w),onRefresh:()=>{rt(),Et()},selectedTaskId:Ne?.id,selectedReqId:Ae?.id})}):Ge==="workflows"?t.jsx(rm,{teamId:Sl,projectId:F,agents:te,projects:I,onViewRunTasks:w=>{const X=ne=>{Dn(ne),sn(`req-${ne.id}`),lt("dag")},ee=ae.find(ne=>ne.id===w);ee?X(ee):le.requirements.get(w).then(ne=>{ne.requirement&&(pe(he=>[...he,ne.requirement]),X(ne.requirement))}).catch(()=>{})}}):Ge==="dag"?t.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",onTouchStart:l?zt.onTouchStart:void 0,onTouchEnd:l?zt.onTouchEnd:void 0,children:[t.jsx(Th,{tasks:(()=>{const w=or(Object.values(H).flat(),!0);if(n&&Ae){const X=new Set(Ae.taskIds??[]);return w.filter(ee=>X.has(ee.id))}return w})(),requirements:n&&Ae?[Ae]:en,agents:te,showArchived:We,onShowArchivedChange:G,onTaskClick:w=>Mr(w),onReqClick:w=>Tr(w),onCollapseDAG:()=>{Ce(null),De(null),sn(null)},onDependencyChange:rt,selectedTaskId:Ne?.id,selectedReqId:Ae?.id,hasDetailPanel:Ro,defaultExpandedNodeId:pn??(n&&Ae?`req-${Ae.id}`:void 0),previewMode:n}),l&&t.jsx("button",{onClick:()=>lt("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:tt,className:"flex-1 min-h-0 overflow-auto px-4 py-5",onTouchStart:l?Ht.onTouchStart:void 0,onTouchEnd:l?Ht.onTouchEnd:void 0,children:t.jsx("div",{className:"flex gap-3 items-stretch",children:Hl.map(w=>{const X=No(w),ee=Co(w),ne=X.length+ee.length,he=Ut===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:Se=>Dl(Se,w.id),onDragLeave:Se=>Pl(Se,w.id),onDrop:Se=>{$l(Se,w.id)},children:[t.jsxs("div",{className:`flex justify-between items-center px-3 py-2.5 shrink-0 border-b border-border-default/30 sticky top-0 z-10 rounded-t-xl ${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 Se=[...ee.map(ke=>({kind:"req",data:ke,time:new Date(ke.updatedAt??ke.createdAt).getTime()})),...X.map(ke=>({kind:"task",data:ke,time:new Date(ke.updatedAt??ke.createdAt??0).getTime()}))];return Se.sort((ke,ie)=>ie.time-ke.time),Se.map(ke=>{if(ke.kind==="req"){const ie=ke.data,Ke=c[ie.status]??{label:ie.status,cls:"bg-gray-500/15 text-fg-secondary"},ft=ie.source==="agent"&&ie.status==="pending",Be=q==="all"&&ie.projectId?I.find(Le=>Le.id===ie.projectId):null,je=Jn(ie.createdBy,te,Z)??ie.createdBy.slice(0,10),Ve=Ae?.id===ie.id;return t.jsxs("div",{"data-work-item-id":ie.id,role:"button",tabIndex:0,draggable:!0,onDragStart:Le=>Al(Le,ie),onDragEnd:ko,onClick:()=>Tr(ie),onKeyDown:Le=>Le.key==="Enter"&&Tr(ie),className:`group rounded-lg p-2.5 border border-transparent transition-all cursor-grab active:cursor-grabbing
|
|
11
|
-
${ft?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15":"bg-surface-elevated/80 hover:bg-surface-elevated border-border-default/50 hover:border-brand-400/40"}
|
|
12
|
-
${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 ${Ke.cls}`,children:Ke.label})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:ie.title}),ie.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:ie.description}),t.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[Be&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded truncate max-w-[90px]",title:Be.name,children:Be.name}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:ie.priority}),t.jsxs("span",{className:"text-[10px] text-fg-quaternary",children:["by ",je]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[ie.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:ie.goalConfig.completionCriteria,children:["🎯 ",ie.goalConfig.currentIteration,"/",ie.goalConfig.maxIterations]}),ie.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:["📋 ",ie.taskIds.length]})]})]}),ft&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[t.jsx("button",{onClick:Le=>{Le.stopPropagation(),bs(ie.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:Le=>{Le.stopPropagation(),St(ie.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-${ie.id}`)}else{const ie=ke.data,Ke=ie.subtasks?.length??0,vt=a[ie.status],ft=ie.status==="pending",Be=ie.taskType==="scheduled"&&!!ie.scheduleConfig,je=Be?ie.scheduleConfig.every?r("work:task.everyInterval",{interval:ie.scheduleConfig.every}):ie.scheduleConfig.cron?r("work:task.cronLabel"):r("work:task.scheduledShort"):null,Ve=q==="all"&&ie.projectId?(()=>{const at=I.find(Br=>Br.id===ie.projectId)?.name;return at&&at!=="default"?at:null})():null,Le=ie.requirementId?ae.find(at=>at.id===ie.requirementId)?.title:null,tn=ie.createdBy?Jn(ie.createdBy,te,Z)??ie.createdBy:null,Sn=Ne?.id===ie.id,zn={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"},Lo=ie.status==="blocked"&&(!ie.blockedBy||ie.blockedBy.length===0||ie.blockedBy.every(at=>{const Br=Ol.get(at);return Br&&Br.status==="completed"}));return t.jsxs("div",{"data-work-item-id":ie.id,role:"button",tabIndex:0,"aria-label":ie.title,draggable:!ft,onDragStart:at=>!ft&&Ll(at,ie),onDragEnd:ko,onClick:()=>Mr(ie),onKeyDown:at=>at.key==="Enter"&&Mr(ie),className:`group rounded-lg p-2.5 border border-transparent transition-all ${Lo?"bg-red-500/[0.06] border-red-500/30 ring-1 ring-red-500/15 cursor-pointer":ft?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":Be?"bg-blue-500/[0.04] border-blue-500/20 hover:border-blue-400/40 cursor-pointer":"bg-surface-elevated/80 hover:bg-surface-elevated border-border-default/50 hover:border-brand-400/40 cursor-grab active:cursor-grabbing"} ${Sn?"!bg-brand-500/25 !border-brand-500/50 ring-1 ring-brand-500/40":""}`,children:[t.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[t.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${zn[ie.priority]??"bg-gray-400"}`,title:ie.priority}),Be&&t.jsx("span",{className:"text-blue-500 shrink-0",title:je??"Scheduled",children:t.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.3"})})}),Be&&je&&t.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:je}),vt&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${vt.cls}`,children:vt.label}),Lo&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-md shrink-0 bg-red-500/15 text-red-500 font-medium",children:"⚠"})]}),t.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:ie.title}),ie.description&&t.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:ie.description}),(Ve||Le||ie.blockedBy&&ie.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}),Le&&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:Le,children:["# ",Le]}),ie.blockedBy&&ie.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:["⏳ ",ie.blockedBy.length," dep",ie.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:tn&&t.jsxs("span",{className:"text-[10px] text-fg-quaternary",title:`by ${tn}`,children:["by ",tn]})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[Ke>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",Ke]}),ie.notes&&ie.notes.length>0&&t.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",ie.notes.length]}),ie.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 ${br[te.find(at=>at.id===ie.assignedAgentId)?.status??""]??"bg-gray-500"}`}),te.find(at=>at.id===ie.assignedAgentId)?.name??ie.assignedAgentId.slice(0,8)]})]})]})]},ie.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&&_o&&t.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:N,children:t.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})}),_o&&t.jsx("div",{className:`${l||$r?"flex-1":"shrink-0"} overflow-hidden min-w-0 flex border-l border-border-default/60`,style:l||$r?void 0:{width:T},children:B==="project"&&yt?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:kn,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(Uh,{project:yt,tasks:Object.values(H).flat().filter(w=>w.projectId===yt.id),requirements:ae.filter(w=>w.projectId===yt.id),agents:te,onDeleteProject:()=>Rl(yt.id),onUpdateProject:async w=>{await le.projects.update(yt.id,w),wn()},onRefresh:()=>{wn()}})]}):B==="empty"?t.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:t.jsxs("div",{className:"max-w-xs w-full text-center space-y-3",children:[t.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-surface-elevated flex items-center justify-center",children:t.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary",children:[t.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),t.jsx("path",{d:"M9 12h6"})]})}),t.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:r("work:task.emptyDetailTitle",{defaultValue:"No item selected"})}),t.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("work:task.emptyDetailHint",{defaultValue:"Select a requirement or task from the list, or create one to get started."})}),t.jsxs("div",{className:"flex items-center justify-center gap-2",children:[t.jsx("button",{onClick:we,className:"px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium",children:r("work:task.newRequirement")}),t.jsx("button",{onClick:()=>{Ue(F??""),Me(!0)},className:"px-3 py-1.5 text-[11px] border border-amber-500/60 text-amber-600 rounded-lg font-medium",children:r("work:task.newTaskBtn")})]}),t.jsx("button",{type:"button",onClick:kn,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(Za,{req:Ae,agents:te,projects:I,allTasks:Object.values(H).flat(),users:Z,onClose:()=>{De(null),Ne||kn()},onApprove:w=>{bs(w)},onReject:w=>{St(w)},onCancel:w=>{wo(w),De(null)},onStatusChange:async(w,X)=>{try{await le.requirements.updateStatus(w,X),ct(`Requirement status → ${X}`),Bn({requirementId:w}),Cn(),rt()}catch(ee){ct(`Error: ${ee}`)}},onRefresh:Cn,authUser:e,onTaskClick:w=>{Ce(w),S("item")},onCreateTask:(w,X)=>{xt(w),X&&Ue(X),Me(!0)},onProjectClick:Ir,previewMode:n})}),t.jsx("div",{className:"w-px shrink-0 bg-border-default"}),t.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:t.jsx(Ya,{task:Ne,agents:te,projects:I,requirements:ae,allTasks:Object.values(H).flat(),users:Z,onClose:Ml,onRefresh:yo,authUser:e,scrollToComments:xs,onScrollToCommentsDone:()=>rr(!1),onReqClick:w=>{De(X=>X?.id===w.id?null:w),S("item")},onProjectClick:Ir})})]}):Ne?t.jsx(Ya,{task:Ne,agents:te,projects:I,requirements:ae,allTasks:Object.values(H).flat(),users:Z,onClose:kn,onRefresh:yo,authUser:e,scrollToComments:xs,onScrollToCommentsDone:()=>rr(!1),onReqClick:w=>{De(w),Ce(null),S("item")},onProjectClick:Ir}):Ae?t.jsx(Za,{req:Ae,agents:te,projects:I,allTasks:Object.values(H).flat(),users:Z,onClose:kn,onApprove:w=>{bs(w)},onReject:w=>{St(w)},onCancel:w=>{wo(w),kn()},onStatusChange:async(w,X)=>{try{await le.requirements.updateStatus(w,X),ct(`Requirement status → ${X}`),Bn({requirementId:w}),Cn(),rt()}catch(ee){ct(`Error: ${ee}`)}},scrollToComments:xs,onScrollToCommentsDone:()=>rr(!1),onRefresh:Cn,authUser:e,onTaskClick:w=>{Ce(w),De(null),S("item"),l&&(L(!0),history.pushState({mobileDetail:He.WORK},"",window.location.hash))},onCreateTask:(w,X)=>{xt(w),X&&Ue(X),Me(!0)},onProjectClick:Ir,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:kn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("common:close")})]})})}),de&&t.jsx(Ih,{orgId:e?.orgId,onCreated:Il,onClose:()=>se(!1)}),xe&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Me(!1),et("")},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"&&bo()},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.descriptionField")}),t.jsx("textarea",{value:pt,onChange:w=>gt(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(wt,{options:[{value:"",label:r("work:task.noProject")},...I.map(w=>({value:w.id,label:w.name}))],value:ut,onChange:w=>{Ue(w),xt("")},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(wt,{options:[{value:"",label:r("work:task.selectRequirement")},...ae.filter(w=>w.status==="in_progress"&&(!ut||w.projectId===ut)).map(w=>({value:w.id,label:w.title}))],value:Dt,onChange:xt,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(wt,{options:te.map(w=>({value:w.id,label:`${w.name} (${w.status})`})),value:Qe,onChange:Yt,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(wt,{options:[...Z.map(w=>({value:`human:${w.id}`,label:w.name})),...te.filter(w=>w.id!==Qe).map(w=>({value:`agent:${w.id}`,label:`${w.name} (${w.status})`}))],value:dt,onChange:At,placeholder:r("work:task.selectReviewer"),noMatchesText:r("work:task.noMatches")})]})]}),t.jsxs("div",{className:`grid gap-4 ${Xe==="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:jt,onChange:w=>Ft(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:Xe,onChange:w=>be(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")})]})]}),Xe==="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:Je,onChange:w=>it(w.target.value),className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",children:[t.jsx("option",{value:"30m",children:r("work:task.freq30m")}),t.jsx("option",{value:"1h",children:r("work:task.freq1h")}),t.jsx("option",{value:"2h",children:r("work:task.freq2h")}),t.jsx("option",{value:"4h",children:r("work:task.freq4h")}),t.jsx("option",{value:"8h",children:r("work:task.freq8h")}),t.jsx("option",{value:"12h",children:r("work:task.freq12h")}),t.jsx("option",{value:"1d",children:r("work:task.freq1d")}),t.jsx("option",{value:"1w",children:r("work:task.freq1w")})]})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:r("work:task.blockedBy")}),t.jsx(Dh,{options:Object.values(H).flat().filter(w=>w.status!=="completed"&&w.status!=="cancelled").map(w=>({value:w.id,label:w.title})),selected:st,onAdd:w=>Nt([...st,w]),placeholder:r("work:task.selectDependency"),noMatchesText:r("work:task.noMatches")}),st.length>0&&t.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:st.map(w=>{const X=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:[X?X.title.slice(0,30):w.slice(-8),t.jsx("button",{onClick:()=>Nt(st.filter(ee=>ee!==w)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},w)})})]}),Pt&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Pt}),t.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[t.jsx("button",{onClick:()=>{Me(!1),et("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:r("common:cancel")}),t.jsx("button",{onClick:()=>{bo()},disabled:!ye.trim()||!Qe||!dt||bt,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:r(bt?"common:creating":"common:create")})]})]})}),gn&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Zt(!1),bn(""),yn(""),ln("")},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(wt,{options:I.map(w=>({value:w.id,label:w.name})),value:vn,onChange:Nr,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:xn,onChange:w=>bn(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"&&xn.trim()&&vo()}})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-fg-secondary mb-1.5",children:[r("work:task.descriptionField")," ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx("textarea",{value:Rn,onChange:w=>yn(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=>ms(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:()=>{Zt(!1),bn(""),yn(""),ln("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:r("common:cancel")}),t.jsx("button",{onClick:()=>{vo()},disabled:!xn.trim()||!Rn.trim()||!vn||ps,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(ps?"common:creating":"common:create")})]})]})}),an&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{St(null),_n("")},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:Cr,onChange:w=>Sr(w.target.value),placeholder:r("work:task.rejectReasonPlaceholder"),rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-red-500 outline-none resize-none",autoFocus:!l})]}),uo&&t.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:uo}),t.jsxs("div",{className:"flex justify-end gap-3",children:[t.jsx("button",{onClick:()=>{St(null),_n("")},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:()=>{_l()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:r("work:task.reject")})]})]})}),Ie&&t.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>Ee(!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:[(ze.size>0||Ze)&&t.jsx("button",{onClick:()=>{$t(new Set),Bt(!1)},className:"text-[11px] text-brand-500 font-medium",children:r("work:task.clearAll")}),t.jsx("button",{onClick:()=>Ee(!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"})]})})]})]}),I.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:()=>{Vt(),Ee(!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})]}),Lr.map(w=>{const X=F===w.id,ee=Ar[w.id]??0;return t.jsxs("button",{type:"button",onClick:()=>{Mt(w.id),Ee(!1)},className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-lg transition-all ${X?"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 ${X?"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:()=>Bt(w=>!w),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Ze?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:r("work:task.myTasks")})}),_r.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:_r.map(w=>{if(w.kind==="team"){const ne=w.agentIds.every(Se=>ze.has(Se)),he=!ne&&w.agentIds.some(Se=>ze.has(Se));return t.jsxs("button",{onClick:()=>{$t(Se=>{const ke=new Set(Se);if(ne)for(const ie of w.agentIds)ke.delete(ie);else for(const ie of w.agentIds)ke.add(ie);return ke})},className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ne?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":he?"bg-brand-600/10 text-brand-400 ring-1 ring-brand-500/20":"bg-surface-elevated text-fg-secondary"}`,children:[t.jsx("svg",{className:"w-3.5 h-3.5 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"})}),w.name,t.jsx("span",{className:"text-[9px] text-fg-quaternary",children:w.agentIds.length})]},`team-${w.id}`)}const X=w.agent,ee=ze.has(X.id);return t.jsxs("button",{onClick:()=>jo(X.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:X.name[0]?.toUpperCase()}),X.name]},X.id)})})]}),t.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function sm({requirementId:e,createdBy:n,agents:s,users:r,authUser:i}){const{t:o}=$e(["work","common"]),[a,c]=p.useState([]),[l,d]=p.useState([]),h=p.useRef(null),[f,m]=p.useState(new Map);p.useEffect(()=>{d([]),m(new Map),h.current&&(clearTimeout(h.current),h.current=null),le.requirements.getComments(e).then(v=>c(v.comments)).catch(()=>{})},[e]),p.useEffect(()=>mt.on("requirement:comment",y=>{if(y.payload?.requirementId===e&&y.payload.comment){const g=y.payload.comment;c(b=>b.some(j=>j.id===g.id)?b:[...b,g]),(g.authorType==="agent"||g.authorId?.startsWith("agt_"))&&(d(b=>{const j=b.filter(k=>k.id!==g.authorId);return j.length===0&&h.current&&(clearTimeout(h.current),h.current=null),j}),m(b=>{const j=new Map(b);return j.delete(g.authorId),j}))}}),[e]),p.useEffect(()=>{if(l.length===0)return;const v=new Set(l.map(g=>g.id));return mt.on("agent:activity_log",g=>{const b=g.payload;if(!b)return;const j=b.agentId;if(!v.has(j))return;const k=so(b);k&&m(M=>oo(M,j,k))})},[l]);const[u,x]=p.useState(null),E=async(v,y,g,b)=>{let j;g.length>0&&(j=(await le.uploads.upload(g.map(A=>({dataUrl:A.dataUrl,name:A.name})),"comments")).files.map(A=>({type:"image",url:A.url,name:A.name}))),await le.requirements.addComment(e,v,i?.name,j,i?.id,y.length>0?y:void 0,b);const k=[],M=new Set,R=D=>{if(M.has(D)||D===i?.id)return;M.add(D);const A=s.find(T=>T.id===D);A&&k.push({id:A.id,name:A.name,avatarUrl:A.avatarUrl})};for(const D of y){const A=s.find(T=>T.name.toLowerCase()===D.toLowerCase());A&&R(A.id)}n?.startsWith("agt_")&&R(n),k.length>0&&(h.current&&clearTimeout(h.current),d(k),h.current=setTimeout(()=>d([]),12e4))},C=p.useCallback(v=>{x({id:v.id,authorName:v.authorName,content:v.content.slice(0,100)})},[]);return t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:a.length>0?o("work:task.commentsWithCount",{count:a.length}):o("work:task.comments")}),t.jsxs("div",{className:"space-y-0.5 mb-3",children:[a.length===0&&t.jsx("p",{className:"text-xs text-fg-tertiary text-center py-4",children:o("work:task.noCommentsYet")}),a.map(v=>t.jsx(dr,{comment:v,agents:s,onReply:C},v.id)),l.length>0&&t.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:l.map(v=>{const y=f.get(v.id)??[];return t.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>kt.navigate(He.TEAM,{agentId:v.id,profileTab:"mind"}),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative shrink-0",children:[t.jsx(Fs,{name:v.name,avatarUrl:v.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),t.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),t.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:v.name}),y.length===0&&t.jsxs("span",{className:"flex items-center gap-0.5",children:[t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),t.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),t.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.agentProcessing")}),t.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),y.length>0&&t.jsx("div",{className:"ml-8 mt-1",children:t.jsx(ao,{entries:y})})]},v.id)})})]}),t.jsx(ni,{agents:s,humans:r,onSubmit:E,replyTo:u,onCancelReply:()=>x(null)})]})}function Za({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:E,onProjectClick:C,previewMode:v}){const{t:y}=$e(["work","common"]),g=p.useMemo(()=>lo(y),[y]),b=p.useMemo(()=>kl(y),[y]),j=yr(),[k,M]=p.useState(!1),[R,D]=p.useState(e.description),[A,T]=p.useState(!1),[$,z]=p.useState(!1),[N,O]=p.useState(!1),[L,_]=p.useState(!1),I=p.useRef(null),[P,q]=p.useState("none"),Y=p.useRef(null),F=p.useRef(null),Q=p.useRef(80);p.useEffect(()=>{const Z=I.current;if(!Z)return;const ce=()=>{const{scrollTop:pe,scrollHeight:ge,clientHeight:U}=Z;if(!(ge>U+50)){q("none");return}const ue=pe<30,we=pe+U>=ge-30;q(ue?"top":we?"bottom":"middle")};ce(),Z.addEventListener("scroll",ce,{passive:!0});const ae=new ResizeObserver(ce);return ae.observe(Z),()=>{Z.removeEventListener("scroll",ce),ae.disconnect()}},[]),p.useEffect(()=>{if(k&&F.current){const Z=F.current;Z.style.height="auto",Z.style.height=Math.max(Z.scrollHeight,Q.current)+"px",Z.focus()}},[k]),p.useEffect(()=>{if(!m)return;const Z=setTimeout(()=>{const ce=I.current;ce&&ce.scrollTo({top:ce.scrollHeight,behavior:"smooth"}),u?.()},300);return()=>clearTimeout(Z)},[m,u]);const B=g[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},S=e.source==="agent",V=S&&e.status==="pending",W=e.status==="pending"||e.status==="in_progress",H=e.status==="completed"||e.status==="rejected"||e.status==="cancelled"||e.status==="archived",K=e.projectId?s.find(Z=>Z.id===e.projectId):null,te=Jn(e.createdBy,n,i)??e.createdBy.slice(0,12),re=r.filter(Z=>e.taskIds.includes(Z.id)),fe=K?.teamIds?.[0]??null;p.useMemo(()=>new Map(re.map(Z=>[Z.id,Z])),[re]);const J=re.length>=2;return p.useEffect(()=>{D(e.description),M(!1)},[e.id,e.description]),t.jsxs("div",{className:"flex flex-col w-full h-full overflow-hidden bg-surface-primary shadow-xl shadow-black/8 ring-1 ring-border-default/20",children:[t.jsxs("div",{className:"flex items-start justify-between gap-4 p-5 pb-0 border-b border-border-default",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[j&&t.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})})}),t.jsxs("h2",{className:"flex-1 min-w-0 pb-4 text-lg font-semibold text-fg-primary leading-snug",children:[e.title," ",t.jsx("span",{className:"text-[10px] font-bold text-brand-500 bg-brand-500/15 px-2 py-0.5 rounded align-middle",children:y("work:task.requirementShort")})," ",t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium align-middle ${B.cls}`,children:B.label})," ",e.priority==="high"||e.priority==="urgent"?t.jsx("span",{className:`text-[10px] font-medium align-middle ${e.priority==="urgent"?"text-red-500":"text-amber-600"}`,children:y("common:priority."+e.priority,{defaultValue:e.priority})}):t.jsx("span",{className:"text-[10px] text-fg-tertiary align-middle",children:y("common:priority."+e.priority,{defaultValue:e.priority})})]})]}),t.jsxs("div",{className:"flex items-center gap-2 shrink-0 mb-4",children:[t.jsx(bl,{onClick:()=>_(!0),label:y("work:task.sendToChat",{defaultValue:"发送到对话"})}),t.jsx("button",{onClick:o,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0",children:"×"})]})]}),L&&t.jsx(yl,{kind:"requirement",entity:e,agents:n,users:i,projects:s,onClose:()=>_(!1)}),t.jsxs("div",{className:"flex-1 min-h-0 relative",children:[t.jsxs("div",{ref:I,className:"h-full overflow-y-auto p-5 space-y-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:y("work:task.requirementDetailDescription")}),k?t.jsx("textarea",{ref:F,value:R,onChange:Z=>{D(Z.target.value);const ce=Z.target;ce.style.height="auto",ce.style.height=ce.scrollHeight+"px"},onBlur:async()=>{if(R!==e.description){T(!0);try{await le.requirements.update(e.id,{description:R}),h?.()}catch{}finally{T(!1)}}M(!1)},onKeyDown:Z=>{Z.key==="Escape"&&(Z.preventDefault(),D(e.description),M(!1))},className:"w-full bg-transparent border border-brand-500/30 rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none -mx-2 px-2 -my-1 py-1",placeholder:y("work:task.requirementDetailDescription")}):t.jsx("div",{ref:Y,className:`group relative rounded-lg -mx-2 px-2 -my-1 py-1 transition-colors ${H?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:H?void 0:Z=>{Z.target.closest("a, button, [data-entity-link]")||(Q.current=Math.max(Y.current?.offsetHeight??80,60),D(e.description),M(!0))},role:H?void 0:"button",tabIndex:H?void 0:0,onKeyDown:H?void 0:Z=>Z.key==="Enter"&&(D(e.description),M(!0)),children:e.description?t.jsx(ur,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):t.jsx("p",{className:"text-sm text-fg-tertiary italic",children:y("work:task.requirementNoDescription")})})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",children:[t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:y("work:task.createdByLabel")}),t.jsx("span",{className:"text-fg-secondary",children:te}),S&&t.jsx("span",{className:"text-[10px] text-brand-500 ml-1.5",children:y("work:task.agentTag")})]}),t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:y("work:task.createdLabel")}),t.jsx("span",{className:"text-fg-secondary",children:new Date(e.createdAt).toLocaleString()})]}),K&&t.jsxs("div",{className:`bg-surface-elevated/60 rounded-lg p-2.5 ${C?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,onClick:C?()=>C(K.id):void 0,role:C?"button":void 0,tabIndex:C?0:void 0,onKeyDown:C?Z=>Z.key==="Enter"&&C(K.id):void 0,children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:y("work:task.projectLabel")}),t.jsx("span",{className:"text-fg-secondary",children:K.name})]}),e.approvedBy&&t.jsxs("div",{className:"bg-surface-elevated/60 rounded-lg p-2.5",children:[t.jsx("span",{className:"text-[10px] text-fg-tertiary block mb-1",children:y("work:task.approvedBy")}),t.jsx("span",{className:"text-fg-secondary",children:Jn(e.approvedBy,n,i)??e.approvedBy.slice(0,12)}),e.approvedAt&&t.jsx("span",{className:"text-[10px] text-fg-tertiary ml-1",children:new Date(e.approvedAt).toLocaleDateString()})]})]}),e.rejectedReason&&t.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[t.jsx("span",{className:"text-[10px] font-semibold text-red-500 uppercase tracking-wider block mb-1",children:y("work:task.rejectionReason")}),t.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),e.goalConfig?.loopEnabled&&t.jsxs("div",{className:"bg-brand-500/8 border border-brand-500/20 rounded-lg p-3",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx("span",{className:"text-[10px] font-semibold text-brand-500 uppercase tracking-wider",children:y("work:requirement.goal")}),t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium ${e.goalConfig.currentIteration>=e.goalConfig.maxIterations?"bg-amber-500/15 text-amber-600":"bg-green-500/15 text-green-600"}`,children:e.goalConfig.currentIteration>=e.goalConfig.maxIterations?y("work:requirement.goalMaxReached"):y("work:requirement.goalActive")})]}),t.jsx("p",{className:"text-xs text-fg-secondary mb-2",children:e.goalConfig.completionCriteria}),t.jsxs("div",{className:"flex items-center gap-4 text-[10px] text-fg-tertiary",children:[t.jsx("span",{children:y("work:requirement.goalIteration",{current:e.goalConfig.currentIteration,max:e.goalConfig.maxIterations})}),e.goalConfig.lastCheckedAt&&t.jsx("span",{children:y("work:requirement.goalLastChecked",{time:new Date(e.goalConfig.lastCheckedAt).toLocaleString()})}),e.goalConfig.autoResume&&t.jsx("span",{className:"text-brand-500",children:y("work:requirement.goalAutoResume")})]})]}),Array.isArray(e.tags)&&e.tags.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(Z=>t.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",Z]},Z))}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:y("work:task.linkedTasks",{count:re.length})}),t.jsxs("div",{className:"flex items-center gap-2",children:[J&&fe&&t.jsxs("button",{onClick:()=>O(!0),className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium flex items-center gap-1",children:[t.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),y("work:task.saveAsWorkflow")]}),!H&&E&&t.jsxs("button",{onClick:()=>E(e.id,e.projectId),className:"text-[11px] text-amber-500 hover:text-amber-400 font-medium flex items-center gap-1",children:[t.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),y("work:requirement.createTask")]})]})]}),re.length>0?(()=>{const Z=new Map(re.map(oe=>[oe.id,oe]));if(!re.some(oe=>oe.blockedBy?.some(ue=>Z.has(ue))))return t.jsx("div",{className:"space-y-1.5",children:re.map(oe=>{const ue=b[oe.status];return t.jsxs("div",{onClick:()=>x?.(oe),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 ${br[oe.status]??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:oe.title}),ue&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${ue.cls}`,children:ue.label})]},oe.id)})});const ae=new Map,pe=new Set;for(const oe of re)for(const ue of oe.blockedBy??[])if(Z.has(ue)){pe.add(oe.id);const we=ae.get(ue)??[];we.push(oe.id),ae.set(ue,we)}const ge=re.filter(oe=>!pe.has(oe.id)),U=(oe,ue)=>{const we=b[oe.status],de=(ae.get(oe.id)??[]).map(se=>Z.get(se)).filter(Boolean);return t.jsxs("div",{children:[t.jsxs("div",{onClick:()=>x?.(oe),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:ue>0?{marginLeft:ue*20}:void 0,children:[ue>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 ${br[oe.status]??"bg-gray-500"}`}),t.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:oe.title}),we&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${we.cls}`,children:we.label})]}),de.map(se=>U(se,ue+1))]},oe.id)};return t.jsx("div",{className:"space-y-1.5",children:ge.map(oe=>U(oe,0))})})():t.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:y("work:requirement.noLinkedTasks")})]}),!v&&t.jsx(sm,{requirementId:e.id,createdBy:e.createdBy,agents:n,users:i,authUser:f}),!v&&t.jsx(Cl,{entityType:"requirement",entityId:e.id})]}),P!=="none"&&P!=="top"&&t.jsx("button",{onClick:()=>I.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-20 right-4 md:bottom-14 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:y("work:task.scrollToTop"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),P!=="none"&&P!=="bottom"&&t.jsx("button",{onClick:()=>{const Z=I.current;Z&&Z.scrollTo({top:Z.scrollHeight,behavior:"smooth"})},className:"absolute bottom-6 right-4 md:bottom-4 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:y("work:task.scrollToBottom"),children:t.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),t.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[V&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>a(e.id),className:"px-4 py-2 bg-green-600 hover:bg-green-500 text-white text-sm rounded-lg font-medium transition-colors",children:y("work:requirement.approveRequirement")}),t.jsx("button",{onClick:()=>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:y("work:requirement.rejectRequirement")})]}),!V&&d&&!H&&t.jsx("select",{value:e.status,onChange:Z=>{Z.target.value!==e.status&&d(e.id,Z.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:Qh.map(Z=>{const ce=g[Z],ae=Z===e.status||(Vs[e.status]?.has(Z)??!1);return t.jsx("option",{value:Z,disabled:!ae,children:ce?.label??Z},Z)})}),H&&d&&t.jsx("button",{onClick:()=>d(e.id,"in_progress"),className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",children:y("work:task.reopen")}),t.jsx("div",{className:"flex-1"}),W&&!V&&t.jsx("button",{onClick:()=>z(!0),className:"px-3 py-1.5 text-xs text-red-500/70 hover:text-red-500 hover:bg-red-500/10 border border-transparent hover:border-red-500/20 rounded-lg transition-colors",children:y("work:task.cancelRequirement")})]}),$&&t.jsx(qn,{title:y("work:requirement.cancelConfirmTitle","Cancel Requirement"),message:y("work:requirement.cancelConfirmMessage","Are you sure you want to cancel this requirement? This action cannot be undone."),confirmLabel:y("work:requirement.cancelConfirmLabel","Cancel Requirement"),onConfirm:()=>{z(!1),l(e.id)},onCancel:()=>z(!1)}),N&&fe&&t.jsx(nm,{req:e,tasks:re,agents:n,teamId:fe,onClose:()=>O(!1),onSaved:()=>O(!1)})]})}function Cl({entityType:e,entityId:n}){const{t:s}=$e(["work"]),[r,i]=p.useState([]),[o,a]=p.useState(!0),[c,l]=p.useState(!1);if(p.useEffect(()=>{a(!0),(e==="task"?le.tasks.getHistory:le.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{dm as WorkPage};
|