@markus-global/cli 0.12.3-rc.2 → 0.12.3
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/markus.mjs +85 -5
- package/dist/web-ui/assets/{AsyncState-DlUYNJNs.js → AsyncState-_UC7xcxJ.js} +1 -1
- package/dist/web-ui/assets/{ChatComponents-Buxli2VA.js → ChatComponents-Ca9tWI9W.js} +1 -1
- package/dist/web-ui/assets/{ContentRenderer-Dry2nbFd.js → ContentRenderer-C-V5k_3K.js} +2 -2
- package/dist/web-ui/assets/{DeliverableShareModal-C5hu0BwE.js → DeliverableShareModal-BvpyowYJ.js} +1 -1
- package/dist/web-ui/assets/Deliverables-CQnWqbTb.js +6 -0
- package/dist/web-ui/assets/{MarkdownMessage-BU1Z2MSr.js → MarkdownMessage-DedA8Zob.js} +1 -1
- package/dist/web-ui/assets/{Search-Dk7IVqDd.js → Search-CVYQIy_D.js} +1 -1
- package/dist/web-ui/assets/{SendToChat-CLVw1mNM.js → SendToChat-IOAvuta-.js} +1 -1
- package/dist/web-ui/assets/{Settings-BDFR0Z_o.js → Settings-BQDqf4q5.js} +1 -1
- package/dist/web-ui/assets/{Store-DSubNdbJ.js → Store-BEsLd_RN.js} +1 -1
- package/dist/web-ui/assets/{Switch-CE_QndUQ.js → Switch-C6InTNUi.js} +1 -1
- package/dist/web-ui/assets/{Team-lUUZwXVm.js → Team-nfNyWj-s.js} +36 -36
- package/dist/web-ui/assets/Work-BQvgkynj.js +142 -0
- package/dist/web-ui/assets/{arc-CzLCxbPi.js → arc-DP1Vf7Sx.js} +1 -1
- package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-Bjt1eu5I.js → architectureDiagram-3BPJPVTR-Buq8JYN8.js} +1 -1
- package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-5t_XsWP-.js → blockDiagram-GPEHLZMM-BCa2p2_X.js} +1 -1
- package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-DC4yhIA-.js → c4Diagram-AAUBKEIU-BxsgggQY.js} +1 -1
- package/dist/web-ui/assets/channel-BTSrOo6c.js +1 -0
- package/dist/web-ui/assets/{chunk-2J33WTMH-DpBVR8wv.js → chunk-2J33WTMH-BJZZ60c9.js} +1 -1
- package/dist/web-ui/assets/{chunk-4BX2VUAB-CRHzHTTM.js → chunk-4BX2VUAB-C5hc4E6J.js} +1 -1
- package/dist/web-ui/assets/{chunk-55IACEB6-BiE1vYDP.js → chunk-55IACEB6-CbyvZ6Mk.js} +1 -1
- package/dist/web-ui/assets/{chunk-727SXJPM-C62sZl96.js → chunk-727SXJPM-JmNt9TVA.js} +1 -1
- package/dist/web-ui/assets/{chunk-AQP2D5EJ-BWltDJW9.js → chunk-AQP2D5EJ-BTk0v5ba.js} +1 -1
- package/dist/web-ui/assets/{chunk-FMBD7UC4-Djfb2_hP.js → chunk-FMBD7UC4-BO-dhB1U.js} +1 -1
- package/dist/web-ui/assets/{chunk-ND2GUHAM-B5S005b9.js → chunk-ND2GUHAM-BdjCcLdb.js} +1 -1
- package/dist/web-ui/assets/{chunk-QZHKN3VN-CHbAcqJY.js → chunk-QZHKN3VN-BAzRC82n.js} +1 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-BSYlcnF9.js +1 -0
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-BSYlcnF9.js +1 -0
- package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-BkLxosxB.js → cose-bilkent-S5V4N54A-CVffmErT.js} +1 -1
- package/dist/web-ui/assets/{dagre-BM42HDAG-D3u0UzhI.js → dagre-BM42HDAG-Dd9pB2fX.js} +1 -1
- package/dist/web-ui/assets/{diagram-2AECGRRQ-CI9nnxn2.js → diagram-2AECGRRQ-BG_AUqzM.js} +1 -1
- package/dist/web-ui/assets/{diagram-5GNKFQAL-CcHQ4hSh.js → diagram-5GNKFQAL-D5qFMRFf.js} +1 -1
- package/dist/web-ui/assets/{diagram-KO2AKTUF-DdULvZjD.js → diagram-KO2AKTUF-B3qTxSWl.js} +1 -1
- package/dist/web-ui/assets/{diagram-LMA3HP47-CInbHt1K.js → diagram-LMA3HP47-BrxC1636.js} +1 -1
- package/dist/web-ui/assets/{diagram-OG6HWLK6-B29d5ucM.js → diagram-OG6HWLK6-BvXyEQ9-.js} +1 -1
- package/dist/web-ui/assets/{docx-preview-ChWyJtz_.js → docx-preview-DBAZFeEb.js} +1 -1
- package/dist/web-ui/assets/{erDiagram-TEJ5UH35-CJnS1EyG.js → erDiagram-TEJ5UH35-CMap9oy_.js} +1 -1
- package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-B2WoYwwl.js → flowDiagram-I6XJVG4X-BZerJtvk.js} +1 -1
- package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-DPV693xk.js → ganttDiagram-6RSMTGT7-CagPMHMO.js} +1 -1
- package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-3D2euYF9.js → gitGraphDiagram-PVQCEYII-DZ5dDKRu.js} +1 -1
- package/dist/web-ui/assets/{index-BdiEUYQB.js → index-CKPQYzzR.js} +56 -56
- package/dist/web-ui/assets/index-CzHSs0Vd.css +1 -0
- package/dist/web-ui/assets/{infoDiagram-5YYISTIA-BWUbt7Jc.js → infoDiagram-5YYISTIA-CHLdsDUZ.js} +1 -1
- package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-BE3afH_7.js → ishikawaDiagram-YF4QCWOH-SdeinQaS.js} +1 -1
- package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-CDm95QAx.js → journeyDiagram-JHISSGLW-BtlL2fi0.js} +1 -1
- package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-c0jOBZCa.js → kanban-definition-UN3LZRKU-BKPQYXkB.js} +1 -1
- package/dist/web-ui/assets/{mermaid.core-c5cZjaP1.js → mermaid.core-MkJR6w4B.js} +5 -5
- package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-BbsAVFCx.js → mindmap-definition-RKZ34NQL-CbOmHX_u.js} +1 -1
- package/dist/web-ui/assets/{pieDiagram-4H26LBE5-DyXBINfp.js → pieDiagram-4H26LBE5-CypGjJP1.js} +1 -1
- package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-gMRWTBzV.js → quadrantDiagram-W4KKPZXB-CGtemfUz.js} +1 -1
- package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-OWjUHVO4.js → requirementDiagram-4Y6WPE33-N7YfpCvE.js} +1 -1
- package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-CsIAucjq.js → sankeyDiagram-5OEKKPKP-CYnSrei-.js} +1 -1
- package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-BbxZog_d.js → sequenceDiagram-3UESZ5HK-CsB7dCPF.js} +1 -1
- package/dist/web-ui/assets/{stateDiagram-AJRCARHV-CfNPAfJc.js → stateDiagram-AJRCARHV-DTDFUXFP.js} +1 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-AVnDjlzF.js +1 -0
- package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-BSO--1Kk.js → timeline-definition-PNZ67QCA-C_bWAN9B.js} +1 -1
- package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-FBig_P4B.js → vennDiagram-CIIHVFJN-CX_qAuUT.js} +1 -1
- package/dist/web-ui/assets/{wardley-L42UT6IY-BSFxmcZr.js → wardley-L42UT6IY-q53jQ293.js} +1 -1
- package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-KgYOT0P6.js → wardleyDiagram-YWT4CUSO-D34dKCJU.js} +1 -1
- package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-TiGfFomq.js → xychartDiagram-2RQKCTM6-BFAngp66.js} +1 -1
- package/dist/web-ui/index.html +2 -2
- package/package.json +1 -1
- package/dist/web-ui/assets/Deliverables-KM6_2Vwj.js +0 -3
- package/dist/web-ui/assets/Work-skYgAZu2.js +0 -142
- package/dist/web-ui/assets/channel-Dr_j_eV7.js +0 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-DnBTgapK.js +0 -1
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-DnBTgapK.js +0 -1
- package/dist/web-ui/assets/index-CjwBVJDR.css +0 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-BhOU2GYL.js +0 -1
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import{u as Ve,j as r,b5 as Nf,b6 as Sf,a1 as Cf,b7 as Ef,r as p,k as se,aq as If,a as gr,a3 as Tf,n as tn,P as nt,b as Mf,c as Af,Q as Lf,R as Vi,b8 as _f,b9 as Rf,U as Dt,a_ as qt,ba as Br,W as qr,X as Df,bb as Aa,l as Gn,i as Of,a4 as ys,d as $f,bc as Pf,bd as Bf,aP as qf,be as Mc,bf as zf,A as La,aT as _a,aU as Wi,Z as Ff,t as Hf}from"./index-BdiEUYQB.js";import{S as Ac,a as Lc,r as _c,s as Vf}from"./SendToChat-CLVw1mNM.js";import{L as Wf,P as Kf}from"./AsyncState-DlUYNJNs.js";import{t as Rc,Z as Dc,_ as Ki,$ as Ui,a0 as Uf,a1 as Yf,a2 as Oc,a3 as Gf,P as Xf}from"./ChatComponents-Buxli2VA.js";import{MarkdownMessage as ar}from"./MarkdownMessage-BU1Z2MSr.js";import{ContentRenderer as Zf}from"./ContentRenderer-Dry2nbFd.js";import{s as zt,g as $c,j as Ra,T as Ko,k as Uo,t as Qf}from"./transform-BqqRT-Iy.js";import{i as Yo}from"./value-wA6veExk.js";import"./chatChips-DVIRVTpT.js";function Jf(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Qt(e,t){if(e=Jf(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var s=n.createSVGPoint();return s.x=e.clientX,s.y=e.clientY,s=s.matrixTransform(t.getScreenCTM().inverse()),[s.x,s.y]}if(t.getBoundingClientRect){var o=t.getBoundingClientRect();return[e.clientX-o.left-t.clientLeft,e.clientY-o.top-t.clientTop]}}return[e.pageX,e.pageY]}const eh={passive:!1},ir={capture:!0,passive:!1};function Go(e){e.stopImmediatePropagation()}function Cs(e){e.preventDefault(),e.stopImmediatePropagation()}function Pc(e){var t=e.document.documentElement,n=zt(e).on("dragstart.drag",Cs,ir);"onselectstart"in t?n.on("selectstart.drag",Cs,ir):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function Bc(e,t){var n=e.document.documentElement,s=zt(e).on("dragstart.drag",null);t&&(s.on("click.drag",Cs,ir),setTimeout(function(){s.on("click.drag",null)},0)),"onselectstart"in n?s.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const zr=e=>()=>e;function ma(e,{sourceEvent:t,subject:n,target:s,identifier:o,active:a,x:i,y:l,dx:c,dy:d,dispatch:h}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:s,enumerable:!0,configurable:!0},identifier:{value:o,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:i,enumerable:!0,configurable:!0},y:{value:l,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:d,enumerable:!0,configurable:!0},_:{value:h}})}ma.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function th(e){return!e.ctrlKey&&!e.button}function nh(){return this.parentNode}function sh(e,t){return t??{x:e.x,y:e.y}}function rh(){return navigator.maxTouchPoints||"ontouchstart"in this}function qc(){var e=th,t=nh,n=sh,s=rh,o={},a=$c("start","drag","end"),i=0,l,c,d,h,u=0;function f(w){w.on("mousedown.drag",m).filter(s).on("touchstart.drag",v).on("touchmove.drag",k,eh).on("touchend.drag touchcancel.drag",y).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function m(w,S){if(!(h||!e.call(this,w,S))){var j=x(this,t.call(this,w,S),w,S,"mouse");j&&(zt(w.view).on("mousemove.drag",g,ir).on("mouseup.drag",b,ir),Pc(w.view),Go(w),d=!1,l=w.clientX,c=w.clientY,j("start",w))}}function g(w){if(Cs(w),!d){var S=w.clientX-l,j=w.clientY-c;d=S*S+j*j>u}o.mouse("drag",w)}function b(w){zt(w.view).on("mousemove.drag mouseup.drag",null),Bc(w.view,d),Cs(w),o.mouse("end",w)}function v(w,S){if(e.call(this,w,S)){var j=w.changedTouches,E=t.call(this,w,S),C=j.length,R,P;for(R=0;R<C;++R)(P=x(this,E,w,S,j[R].identifier,j[R]))&&(Go(w),P("start",w,j[R]))}}function k(w){var S=w.changedTouches,j=S.length,E,C;for(E=0;E<j;++E)(C=o[S[E].identifier])&&(Cs(w),C("drag",w,S[E]))}function y(w){var S=w.changedTouches,j=S.length,E,C;for(h&&clearTimeout(h),h=setTimeout(function(){h=null},500),E=0;E<j;++E)(C=o[S[E].identifier])&&(Go(w),C("end",w,S[E]))}function x(w,S,j,E,C,R){var P=a.copy(),T=Qt(R||j,S),D,z,I;if((I=n.call(w,new ma("beforestart",{sourceEvent:j,target:f,identifier:C,active:i,x:T[0],y:T[1],dx:0,dy:0,dispatch:P}),E))!=null)return D=I.x-T[0]||0,z=I.y-T[1]||0,function B(L,q,_){var A=T,$;switch(L){case"start":o[C]=B,$=i++;break;case"end":delete o[C],--i;case"drag":T=Qt(_||q,S),$=i;break}P.call(L,w,new ma(L,{sourceEvent:q,subject:I,target:f,identifier:C,active:$,x:T[0]+D,y:T[1]+z,dx:T[0]-A[0],dy:T[1]-A[1],dispatch:P}),E)}}return f.filter=function(w){return arguments.length?(e=typeof w=="function"?w:zr(!!w),f):e},f.container=function(w){return arguments.length?(t=typeof w=="function"?w:zr(w),f):t},f.subject=function(w){return arguments.length?(n=typeof w=="function"?w:zr(w),f):n},f.touchable=function(w){return arguments.length?(s=typeof w=="function"?w:zr(!!w),f):s},f.on=function(){var w=a.on.apply(a,arguments);return w===a?f:w},f.clickDistance=function(w){return arguments.length?(u=(w=+w)*w,f):Math.sqrt(u)},f}var oh=1e-12;function Yi(e){return((e=Math.exp(e))+1/e)/2}function ah(e){return((e=Math.exp(e))-1/e)/2}function ih(e){return((e=Math.exp(2*e))-1)/(e+1)}const ro=(function e(t,n,s){function o(a,i){var l=a[0],c=a[1],d=a[2],h=i[0],u=i[1],f=i[2],m=h-l,g=u-c,b=m*m+g*g,v,k;if(b<oh)k=Math.log(f/d)/t,v=function(E){return[l+E*m,c+E*g,d*Math.exp(t*E*k)]};else{var y=Math.sqrt(b),x=(f*f-d*d+s*b)/(2*d*n*y),w=(f*f-d*d-s*b)/(2*f*n*y),S=Math.log(Math.sqrt(x*x+1)-x),j=Math.log(Math.sqrt(w*w+1)-w);k=(j-S)/t,v=function(E){var C=E*k,R=Yi(S),P=d/(n*y)*(R*ih(t*C+S)-ah(S));return[l+P*m,c+P*g,d*R/Yi(t*C+S)]}}return v.duration=k*1e3*t/Math.SQRT2,v}return o.rho=function(a){var i=Math.max(.001,+a),l=i*i,c=l*l;return e(i,l,c)},o})(Math.SQRT2,2,4),Fr=e=>()=>e;function lh(e,{sourceEvent:t,target:n,transform:s,dispatch:o}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:s,enumerable:!0,configurable:!0},_:{value:o}})}function Xo(e){e.stopImmediatePropagation()}function Js(e){e.preventDefault(),e.stopImmediatePropagation()}function ch(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function dh(){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 Gi(){return this.__zoom||Ra}function uh(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function fh(){return navigator.maxTouchPoints||"ontouchstart"in this}function hh(e,t,n){var s=e.invertX(t[0][0])-n[0][0],o=e.invertX(t[1][0])-n[1][0],a=e.invertY(t[0][1])-n[0][1],i=e.invertY(t[1][1])-n[1][1];return e.translate(o>s?(s+o)/2:Math.min(0,s)||Math.max(0,o),i>a?(a+i)/2:Math.min(0,a)||Math.max(0,i))}function zc(){var e=ch,t=dh,n=hh,s=uh,o=fh,a=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],l=250,c=ro,d=$c("start","zoom","end"),h,u,f,m=500,g=150,b=0,v=10;function k(I){I.property("__zoom",Gi).on("wheel.zoom",C,{passive:!1}).on("mousedown.zoom",R).on("dblclick.zoom",P).filter(o).on("touchstart.zoom",T).on("touchmove.zoom",D).on("touchend.zoom touchcancel.zoom",z).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}k.transform=function(I,B,L,q){var _=I.selection?I.selection():I;_.property("__zoom",Gi),I!==_?S(I,B,L,q):_.interrupt().each(function(){j(this,arguments).event(q).start().zoom(null,typeof B=="function"?B.apply(this,arguments):B).end()})},k.scaleBy=function(I,B,L,q){k.scaleTo(I,function(){var _=this.__zoom.k,A=typeof B=="function"?B.apply(this,arguments):B;return _*A},L,q)},k.scaleTo=function(I,B,L,q){k.transform(I,function(){var _=t.apply(this,arguments),A=this.__zoom,$=L==null?w(_):typeof L=="function"?L.apply(this,arguments):L,F=A.invert($),V=typeof B=="function"?B.apply(this,arguments):B;return n(x(y(A,V),$,F),_,i)},L,q)},k.translateBy=function(I,B,L,q){k.transform(I,function(){return n(this.__zoom.translate(typeof B=="function"?B.apply(this,arguments):B,typeof L=="function"?L.apply(this,arguments):L),t.apply(this,arguments),i)},null,q)},k.translateTo=function(I,B,L,q,_){k.transform(I,function(){var A=t.apply(this,arguments),$=this.__zoom,F=q==null?w(A):typeof q=="function"?q.apply(this,arguments):q;return n(Ra.translate(F[0],F[1]).scale($.k).translate(typeof B=="function"?-B.apply(this,arguments):-B,typeof L=="function"?-L.apply(this,arguments):-L),A,i)},q,_)};function y(I,B){return B=Math.max(a[0],Math.min(a[1],B)),B===I.k?I:new Ko(B,I.x,I.y)}function x(I,B,L){var q=B[0]-L[0]*I.k,_=B[1]-L[1]*I.k;return q===I.x&&_===I.y?I:new Ko(I.k,q,_)}function w(I){return[(+I[0][0]+ +I[1][0])/2,(+I[0][1]+ +I[1][1])/2]}function S(I,B,L,q){I.on("start.zoom",function(){j(this,arguments).event(q).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event(q).end()}).tween("zoom",function(){var _=this,A=arguments,$=j(_,A).event(q),F=t.apply(_,A),V=L==null?w(F):typeof L=="function"?L.apply(_,A):L,X=Math.max(F[1][0]-F[0][0],F[1][1]-F[0][1]),O=_.__zoom,M=typeof B=="function"?B.apply(_,A):B,K=c(O.invert(V).concat(X/O.k),M.invert(V).concat(X/M.k));return function(W){if(W===1)W=M;else{var H=K(W),Z=X/H[2];W=new Ko(Z,V[0]-H[0]*Z,V[1]-H[1]*Z)}$.zoom(null,W)}})}function j(I,B,L){return!L&&I.__zooming||new E(I,B)}function E(I,B){this.that=I,this.args=B,this.active=0,this.sourceEvent=null,this.extent=t.apply(I,B),this.taps=0}E.prototype={event:function(I){return I&&(this.sourceEvent=I),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(I,B){return this.mouse&&I!=="mouse"&&(this.mouse[1]=B.invert(this.mouse[0])),this.touch0&&I!=="touch"&&(this.touch0[1]=B.invert(this.touch0[0])),this.touch1&&I!=="touch"&&(this.touch1[1]=B.invert(this.touch1[0])),this.that.__zoom=B,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(I){var B=zt(this.that).datum();d.call(I,this.that,new lh(I,{sourceEvent:this.sourceEvent,target:k,transform:this.that.__zoom,dispatch:d}),B)}};function C(I,...B){if(!e.apply(this,arguments))return;var L=j(this,B).event(I),q=this.__zoom,_=Math.max(a[0],Math.min(a[1],q.k*Math.pow(2,s.apply(this,arguments)))),A=Qt(I);if(L.wheel)(L.mouse[0][0]!==A[0]||L.mouse[0][1]!==A[1])&&(L.mouse[1]=q.invert(L.mouse[0]=A)),clearTimeout(L.wheel);else{if(q.k===_)return;L.mouse=[A,q.invert(A)],Uo(this),L.start()}Js(I),L.wheel=setTimeout($,g),L.zoom("mouse",n(x(y(q,_),L.mouse[0],L.mouse[1]),L.extent,i));function $(){L.wheel=null,L.end()}}function R(I,...B){if(f||!e.apply(this,arguments))return;var L=I.currentTarget,q=j(this,B,!0).event(I),_=zt(I.view).on("mousemove.zoom",V,!0).on("mouseup.zoom",X,!0),A=Qt(I,L),$=I.clientX,F=I.clientY;Pc(I.view),Xo(I),q.mouse=[A,this.__zoom.invert(A)],Uo(this),q.start();function V(O){if(Js(O),!q.moved){var M=O.clientX-$,K=O.clientY-F;q.moved=M*M+K*K>b}q.event(O).zoom("mouse",n(x(q.that.__zoom,q.mouse[0]=Qt(O,L),q.mouse[1]),q.extent,i))}function X(O){_.on("mousemove.zoom mouseup.zoom",null),Bc(O.view,q.moved),Js(O),q.event(O).end()}}function P(I,...B){if(e.apply(this,arguments)){var L=this.__zoom,q=Qt(I.changedTouches?I.changedTouches[0]:I,this),_=L.invert(q),A=L.k*(I.shiftKey?.5:2),$=n(x(y(L,A),q,_),t.apply(this,B),i);Js(I),l>0?zt(this).transition().duration(l).call(S,$,q,I):zt(this).call(k.transform,$,q,I)}}function T(I,...B){if(e.apply(this,arguments)){var L=I.touches,q=L.length,_=j(this,B,I.changedTouches.length===q).event(I),A,$,F,V;for(Xo(I),$=0;$<q;++$)F=L[$],V=Qt(F,this),V=[V,this.__zoom.invert(V),F.identifier],_.touch0?!_.touch1&&_.touch0[2]!==V[2]&&(_.touch1=V,_.taps=0):(_.touch0=V,A=!0,_.taps=1+!!h);h&&(h=clearTimeout(h)),A&&(_.taps<2&&(u=V[0],h=setTimeout(function(){h=null},m)),Uo(this),_.start())}}function D(I,...B){if(this.__zooming){var L=j(this,B).event(I),q=I.changedTouches,_=q.length,A,$,F,V;for(Js(I),A=0;A<_;++A)$=q[A],F=Qt($,this),L.touch0&&L.touch0[2]===$.identifier?L.touch0[0]=F:L.touch1&&L.touch1[2]===$.identifier&&(L.touch1[0]=F);if($=L.that.__zoom,L.touch1){var X=L.touch0[0],O=L.touch0[1],M=L.touch1[0],K=L.touch1[1],W=(W=M[0]-X[0])*W+(W=M[1]-X[1])*W,H=(H=K[0]-O[0])*H+(H=K[1]-O[1])*H;$=y($,Math.sqrt(W/H)),F=[(X[0]+M[0])/2,(X[1]+M[1])/2],V=[(O[0]+K[0])/2,(O[1]+K[1])/2]}else if(L.touch0)F=L.touch0[0],V=L.touch0[1];else return;L.zoom("touch",n(x($,F,V),L.extent,i))}}function z(I,...B){if(this.__zooming){var L=j(this,B).event(I),q=I.changedTouches,_=q.length,A,$;for(Xo(I),f&&clearTimeout(f),f=setTimeout(function(){f=null},m),A=0;A<_;++A)$=q[A],L.touch0&&L.touch0[2]===$.identifier?delete L.touch0:L.touch1&&L.touch1[2]===$.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&&($=Qt($,this),Math.hypot(u[0]-$[0],u[1]-$[1])<v)){var F=zt(this).on("dblclick.zoom");F&&F.apply(this,arguments)}}}return k.wheelDelta=function(I){return arguments.length?(s=typeof I=="function"?I:Fr(+I),k):s},k.filter=function(I){return arguments.length?(e=typeof I=="function"?I:Fr(!!I),k):e},k.touchable=function(I){return arguments.length?(o=typeof I=="function"?I:Fr(!!I),k):o},k.extent=function(I){return arguments.length?(t=typeof I=="function"?I:Fr([[+I[0][0],+I[0][1]],[+I[1][0],+I[1][1]]]),k):t},k.scaleExtent=function(I){return arguments.length?(a[0]=+I[0],a[1]=+I[1],k):[a[0],a[1]]},k.translateExtent=function(I){return arguments.length?(i[0][0]=+I[0][0],i[1][0]=+I[1][0],i[0][1]=+I[0][1],i[1][1]=+I[1][1],k):[[i[0][0],i[0][1]],[i[1][0],i[1][1]]]},k.constrain=function(I){return arguments.length?(n=I,k):n},k.duration=function(I){return arguments.length?(l=+I,k):l},k.interpolate=function(I){return arguments.length?(c=I,k):c},k.on=function(){var I=d.on.apply(d,arguments);return I===d?k:I},k.clickDistance=function(I){return arguments.length?(b=(I=+I)*I,k):Math.sqrt(b)},k.tapDistance=function(I){return arguments.length?(v=+I,k):v},k}const Fc=new Set(["completed","failed","rejected","cancelled","archived"]);function lr(e){return!!e&&Fc.has(e)}const Hc=new Set(["completed","rejected","cancelled","archived"]);function mh(e,t={}){const n=[];for(let s=0;s<e.length;s++){const o=e[s];if(o.toStatus!=="review")continue;const a=e[s+1],i=!a,l=`review:${o.id}`,c=t.reviewerId??o.changedById??"",d=t.reviewerName??void 0??o.changedByName??void 0??(o.changedById?t.reviewerNameOf?.(o.changedById):void 0)??c??"reviewer";n.push({id:l,reviewerId:c,reviewerName:d,status:i?"reviewing":"completed",queuedAt:o.createdAt,completedAt:a?a.createdAt:null,round:n.length+1,outcome:a?ph(a.toStatus):null,decidedByName:a?a.changedByName??null:null,note:a?a.reason??null:null})}return n}function ph(e){return e==="completed"?"approved":e==="in_progress"?"revision_requested":"closed"}function Xi(e){return e.find(t=>t.status==="reviewing")??null}function gh(e){return e.some(t=>t.status==="reviewing")}function Hr(e){return e?new Date(e).getTime():Number.NaN}function xh(e,t,n="all"){const s=[];if(n!=="review")for(const o of e){const a=o.firstAt??"";Number.isNaN(Hr(a))||s.push({kind:"execution",key:`exec:${o.round}`,round:o.round,startedAt:a,endedAt:o.lastAt??null,toolCount:o.toolCount??0,logCount:o.logCount??0,status:o.status??""})}if(n!=="execution")for(const o of t)Number.isNaN(Hr(o.queuedAt))||s.push({kind:"review",key:o.id,round:o.round,startedAt:o.queuedAt,endedAt:o.completedAt,session:o});return s.sort((o,a)=>{const i=Hr(o.startedAt)-Hr(a.startedAt);return i!==0?i:o.kind!==a.kind?o.kind==="execution"?-1:1:o.round-a.round})}const Zi=6e4,bh=/^(Reviewing task from\b|Task Review$)/;function yh(e){const t=(e.label??"").trim();return t?bh.test(t):!1}function Vc(e,t){const n=new Date(e).getTime();if(Number.isNaN(n))return!1;const s=new Date(t.queuedAt).getTime();if(Number.isNaN(s))return!1;const o=t.completedAt?new Date(t.completedAt).getTime():Number.POSITIVE_INFINITY;return Number.isNaN(o)?!1:n>=s-Zi&&n<=o+Zi}function wh(e,t){const n=new Date(t.queuedAt).getTime(),s=t.completedAt?new Date(t.completedAt).getTime():Number.POSITIVE_INFINITY;return Number.isNaN(n)||Number.isNaN(s)?[]:e.filter(o=>!yh(o)||o.taskId&&o.taskId!==t.taskId?!1:Vc(o.startedAt,t)).sort((o,a)=>new Date(o.startedAt).getTime()-new Date(a.startedAt).getTime())}const kh=["30m","1h","2h","4h","8h","12h","1d","1w"],vh={"30m":"freq30m","1h":"freq1h","2h":"freq2h","4h":"freq4h","8h":"freq8h","12h":"freq12h","1d":"freq1d","1w":"freq1w"};function Qi(e){return vh[e]??"freq4h"}function jh(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function pa(){return{mode:"calendar",every:"4h",calendar:"daily",weekdays:[1,2,3,4,5],time:"09:00",cron:"",maxRuns:"",timezone:jh()}}function Wc(e){const t=/^(\d{1,2}):(\d{2})$/.exec((e??"").trim());if(!t)return[9,0];const n=Math.min(23,Math.max(0,parseInt(t[1],10))),s=Math.min(59,Math.max(0,parseInt(t[2],10)));return[n,s]}function Nh(e){const[t,n]=Wc(e);return`${String(t).padStart(2,"0")}:${String(n).padStart(2,"0")}`}function Sh(e,t,n){if(e==="cron")return"";const[s,o]=Wc(n),a=e==="daily"?"*":e==="weekdays"?"1-5":t.length>0?[...t].sort((i,l)=>i-l).join(","):"*";return`${o} ${s} * * ${a}`}function Ch(e){const t=/^(\d{1,2})\s+(\d{1,2})\s+\*\s+\*\s+(\S+)$/.exec((e??"").trim());if(!t)return null;const n=parseInt(t[1],10),s=parseInt(t[2],10);if(n>59||s>23)return null;const o=t[3],a=`${String(s).padStart(2,"0")}:${String(n).padStart(2,"0")}`;if(o==="*")return{calendar:"daily",weekdays:[1,2,3,4,5],time:a};if(o==="1-5")return{calendar:"weekdays",weekdays:[1,2,3,4,5],time:a};if(/^\d(,\d)*$/.test(o)){const i=o.split(",").map(l=>parseInt(l,10)).filter(l=>l>=0&&l<=6);if(i.length>0)return{calendar:"weekly",weekdays:i,time:a}}return null}function Eh(e){const t=pa();if(!e)return t;if(e.timezone&&(t.timezone=e.timezone),t.maxRuns=e.maxRuns&&e.maxRuns>0?String(e.maxRuns):"",e.cron){const n=Ch(e.cron);t.mode="calendar",n?(t.calendar=n.calendar,t.weekdays=n.weekdays,t.time=n.time):(t.calendar="cron",t.cron=e.cron)}else e.every&&(t.mode="interval",t.every=e.every);return t}function Kc(e){const t={};e.mode==="interval"?t.every=e.every||"4h":(t.cron=e.calendar==="cron"?e.cron.trim():Sh(e.calendar,e.weekdays,e.time),e.timezone&&(t.timezone=e.timezone));const n=parseInt(e.maxRuns,10);return e.maxRuns.trim()!==""&&Number.isFinite(n)&&n>0&&(t.maxRuns=n),t}const Ih=[1,2,3,4,5,6,0];function Th({options:e,value:t,onChange:n,size:s="md"}){const o=s==="sm"?"px-2.5 py-1 text-xs":"px-3 py-1.5 text-sm";return r.jsx("div",{className:"inline-flex rounded-lg border border-border-default overflow-hidden",children:e.map(a=>r.jsx("button",{type:"button",onClick:()=>n(a.value),className:`${o} transition-colors ${t===a.value?"bg-brand-600 text-on-brand":"bg-surface-elevated text-fg-secondary hover:text-fg-primary"}`,children:a.label},a.value))})}function Uc({value:e,onChange:t,compact:n=!1}){const{t:s}=Ve(),o=h=>t({...e,...h}),a=`px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg outline-none focus:border-brand-500 ${n?"text-xs":"text-sm"}`,i=h=>{const f=e.weekdays.includes(h)?e.weekdays.filter(m=>m!==h):[...e.weekdays,h];o({weekdays:f})};let l;if(e.mode==="interval")l=s(`work:task.${Qi(e.every)}`);else if(e.calendar==="cron")l=s("work:task.scheduleCron",{expr:e.cron.trim()||"—"});else{const h=Nh(e.time);if(e.calendar==="daily")l=s("work:task.scheduleDailyAt",{time:h});else if(e.calendar==="weekdays")l=s("work:task.scheduleWeekdaysAt",{time:h});else{const u=[...e.weekdays].sort((f,m)=>f-m).map(f=>s(`work:task.weekdayShort.${f}`)).join(" ");l=e.weekdays.length?s("work:task.scheduleWeeklyAt",{days:u,time:h}):s("work:task.scheduleNoDays")}}const c=e.calendar==="daily"||e.calendar==="weekdays"||e.calendar==="weekly",d="text-fg-tertiary shrink-0 text-xs w-20";return r.jsxs("div",{className:"rounded-lg border border-border-default/70 bg-surface-elevated/40 p-3 space-y-2.5",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[r.jsx("span",{className:d,children:s("work:task.scheduleRepeatMode")}),r.jsx(Th,{size:n?"sm":"md",value:e.mode,onChange:h=>o({mode:h}),options:[{value:"interval",label:s("work:task.scheduleByInterval")},{value:"calendar",label:s("work:task.scheduleByCalendar")}]})]}),e.mode==="interval"?r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx("span",{className:d,children:s("work:task.scheduleEveryLabel")}),r.jsx("select",{value:e.every,onChange:h=>o({every:h.target.value}),className:a,children:kh.map(h=>r.jsx("option",{value:h,children:s(`work:task.${Qi(h)}`)},h))})]}):r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx("span",{className:d,children:s("work:task.scheduleRepeatLabel")}),r.jsxs("select",{value:e.calendar,onChange:h=>o({calendar:h.target.value}),className:a,children:[r.jsx("option",{value:"daily",children:s("work:task.scheduleCalendarDaily")}),r.jsx("option",{value:"weekdays",children:s("work:task.scheduleCalendarWeekdays")}),r.jsx("option",{value:"weekly",children:s("work:task.scheduleCalendarWeekly")}),r.jsx("option",{value:"cron",children:s("work:task.scheduleCalendarCron")})]}),c&&r.jsx("input",{type:"time",value:e.time,onChange:h=>o({time:h.target.value}),className:a})]}),e.calendar==="weekly"&&r.jsx("div",{className:"flex flex-wrap gap-1 pl-[5.5rem]",children:Ih.map(h=>{const u=e.weekdays.includes(h);return r.jsx("button",{type:"button",onClick:()=>i(h),className:`w-7 h-7 rounded-full text-xs transition-colors ${u?"bg-brand-600 text-on-brand":"bg-surface-elevated text-fg-secondary border border-border-default hover:text-fg-primary"}`,children:s(`work:task.weekdayShort.${h}`)},h)})}),e.calendar==="cron"&&r.jsx("input",{value:e.cron,onChange:h=>o({cron:h.target.value}),placeholder:"0 9 * * 1-5",className:`${a} w-full font-mono`})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:d,children:s("work:task.scheduleMaxRuns")}),r.jsx("input",{value:e.maxRuns,onChange:h=>o({maxRuns:h.target.value.replace(/\D/g,"")}),placeholder:s("work:task.scheduleMaxRunsPlaceholder"),className:`${a} w-20`})]}),r.jsxs("div",{className:"text-[11px] text-fg-secondary pt-1 border-t border-border-default/50",children:[s("work:task.schedulePreview",{desc:l}),r.jsxs("span",{className:"text-fg-tertiary",children:[" · ",s("work:task.scheduleTimezoneNote",{tz:e.timezone})]})]})]})}function kt(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,s;n<e.length;n++)(s=kt(e[n]))!==""&&(t+=(t&&" ")+s);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}const ln={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:t,sourceHandle:n,targetHandle:s})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:s}", edge id: ${t}.`,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."},cr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],Yc=["Enter"," ","Escape"],Gc={"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:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"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 Ts;(function(e){e.Strict="strict",e.Loose="loose"})(Ts||(Ts={}));var Jn;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Jn||(Jn={}));var dr;(function(e){e.Partial="partial",e.Full="full"})(dr||(dr={}));const Xc={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var In;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(In||(In={}));var Ms;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Ms||(Ms={}));var ve;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(ve||(ve={}));const Ji={[ve.Left]:ve.Right,[ve.Right]:ve.Left,[ve.Top]:ve.Bottom,[ve.Bottom]:ve.Top};function Zc(e){return e===null?null:e?"valid":"invalid"}const Qc=e=>"id"in e&&"source"in e&&"target"in e,Mh=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Da=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),xr=(e,t=[0,0])=>{const{width:n,height:s}=wn(e),o=e.origin??t,a=n*o[0],i=s*o[1];return{x:e.position.x-a,y:e.position.y-i}},Ah=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((s,o)=>{const a=typeof o=="string";let i=!t.nodeLookup&&!a?o:void 0;t.nodeLookup&&(i=a?t.nodeLookup.get(o):Da(o)?o:t.nodeLookup.get(o.id));const l=i?fo(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return jo(s,l)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return No(n)},br=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},s=!1;return e.forEach(o=>{(t.filter===void 0||t.filter(o))&&(n=jo(n,fo(o)),s=!0)}),s?No(n):{x:0,y:0,width:0,height:0}},Oa=(e,t,[n,s,o]=[0,0,1],a=!1,i=!1)=>{const l={...wr(t,[n,s,o]),width:t.width/o,height:t.height/o},c=[];for(const d of e.values()){const{measured:h,selectable:u=!0,hidden:f=!1}=d;if(i&&!u||f)continue;const m=h.width??d.width??d.initialWidth??null,g=h.height??d.height??d.initialHeight??null,b=ur(l,Ls(d)),v=(m??0)*(g??0),k=a&&b>0;(!d.internals.handleBounds||k||b>=v||d.dragging)&&c.push(d)}return c},Lh=(e,t)=>{const n=new Set;return e.forEach(s=>{n.add(s.id)}),t.filter(s=>n.has(s.source)||n.has(s.target))};function _h(e,t){const n=new Map,s=t?.nodes?new Set(t.nodes.map(o=>o.id)):null;return e.forEach(o=>{o.measured.width&&o.measured.height&&(t?.includeHiddenNodes||!o.hidden)&&(!s||s.has(o.id))&&n.set(o.id,o)}),n}async function Rh({nodes:e,width:t,height:n,panZoom:s,minZoom:o,maxZoom:a},i){if(e.size===0)return Promise.resolve(!0);const l=_h(e,i),c=br(l),d=$a(c,t,n,i?.minZoom??o,i?.maxZoom??a,i?.padding??.1);return await s.setViewport(d,{duration:i?.duration,ease:i?.ease,interpolate:i?.interpolate}),Promise.resolve(!0)}function Jc({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:s=[0,0],nodeExtent:o,onError:a}){const i=n.get(e),l=i.parentId?n.get(i.parentId):void 0,{x:c,y:d}=l?l.internals.positionAbsolute:{x:0,y:0},h=i.origin??s;let u=i.extent||o;if(i.extent==="parent"&&!i.expandParent)if(!l)a?.("005",ln.error005());else{const m=l.measured.width,g=l.measured.height;m&&g&&(u=[[c,d],[c+m,d+g]])}else l&&_s(i.extent)&&(u=[[i.extent[0][0]+c,i.extent[0][1]+d],[i.extent[1][0]+c,i.extent[1][1]+d]]);const f=_s(u)?es(t,u,i.measured):t;return(i.measured.width===void 0||i.measured.height===void 0)&&a?.("015",ln.error015()),{position:{x:f.x-c+(i.measured.width??0)*h[0],y:f.y-d+(i.measured.height??0)*h[1]},positionAbsolute:f}}async function Dh({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:s,onBeforeDelete:o}){const a=new Set(e.map(f=>f.id)),i=[];for(const f of n){if(f.deletable===!1)continue;const m=a.has(f.id),g=!m&&f.parentId&&i.find(b=>b.id===f.parentId);(m||g)&&i.push(f)}const l=new Set(t.map(f=>f.id)),c=s.filter(f=>f.deletable!==!1),h=Lh(i,c);for(const f of c)l.has(f.id)&&!h.find(g=>g.id===f.id)&&h.push(f);if(!o)return{edges:h,nodes:i};const u=await o({nodes:i,edges:h});return typeof u=="boolean"?u?{edges:h,nodes:i}:{edges:[],nodes:[]}:u}const As=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),es=(e={x:0,y:0},t,n)=>({x:As(e.x,t[0][0],t[1][0]-(n?.width??0)),y:As(e.y,t[0][1],t[1][1]-(n?.height??0))});function ed(e,t,n){const{width:s,height:o}=wn(n),{x:a,y:i}=n.internals.positionAbsolute;return es(e,[[a,i],[a+s,i+o]],t)}const el=(e,t,n)=>e<t?As(Math.abs(e-t),1,t)/t:e>n?-As(Math.abs(e-n),1,t)/t:0,td=(e,t,n=15,s=40)=>{const o=el(e.x,s,t.width-s)*n,a=el(e.y,s,t.height-s)*n;return[o,a]},jo=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),ga=({x:e,y:t,width:n,height:s})=>({x:e,y:t,x2:e+n,y2:t+s}),No=({x:e,y:t,x2:n,y2:s})=>({x:e,y:t,width:n-e,height:s-t}),Ls=(e,t=[0,0])=>{const{x:n,y:s}=Da(e)?e.internals.positionAbsolute:xr(e,t);return{x:n,y:s,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},fo=(e,t=[0,0])=>{const{x:n,y:s}=Da(e)?e.internals.positionAbsolute:xr(e,t);return{x:n,y:s,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:s+(e.measured?.height??e.height??e.initialHeight??0)}},nd=(e,t)=>No(jo(ga(e),ga(t))),ur=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),s=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*s)},tl=e=>Jt(e.width)&&Jt(e.height)&&Jt(e.x)&&Jt(e.y),Jt=e=>!isNaN(e)&&isFinite(e),Oh=(e,t)=>{},yr=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),wr=({x:e,y:t},[n,s,o],a=!1,i=[1,1])=>{const l={x:(e-n)/o,y:(t-s)/o};return a?yr(l,i):l},ho=({x:e,y:t},[n,s,o])=>({x:e*o+n,y:t*o+s});function gs(e,t){if(typeof e=="number")return Math.floor((t-t/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(n)}if(typeof e=="string"&&e.endsWith("%")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.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 $h(e,t,n){if(typeof e=="string"||typeof e=="number"){const s=gs(e,n),o=gs(e,t);return{top:s,right:o,bottom:s,left:o,x:o*2,y:s*2}}if(typeof e=="object"){const s=gs(e.top??e.y??0,n),o=gs(e.bottom??e.y??0,n),a=gs(e.left??e.x??0,t),i=gs(e.right??e.x??0,t);return{top:s,right:i,bottom:o,left:a,x:a+i,y:s+o}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function Ph(e,t,n,s,o,a){const{x:i,y:l}=ho(e,[t,n,s]),{x:c,y:d}=ho({x:e.x+e.width,y:e.y+e.height},[t,n,s]),h=o-c,u=a-d;return{left:Math.floor(i),top:Math.floor(l),right:Math.floor(h),bottom:Math.floor(u)}}const $a=(e,t,n,s,o,a)=>{const i=$h(a,t,n),l=(t-i.x)/e.width,c=(n-i.y)/e.height,d=Math.min(l,c),h=As(d,s,o),u=e.x+e.width/2,f=e.y+e.height/2,m=t/2-u*h,g=n/2-f*h,b=Ph(e,m,g,h,t,n),v={left:Math.min(b.left-i.left,0),top:Math.min(b.top-i.top,0),right:Math.min(b.right-i.right,0),bottom:Math.min(b.bottom-i.bottom,0)};return{x:m-v.left+v.right,y:g-v.top+v.bottom,zoom:h}},fr=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function _s(e){return e!=null&&e!=="parent"}function wn(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function sd(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function rd(e,t={width:0,height:0},n,s,o){const a={...e},i=s.get(n);if(i){const l=i.origin||o;a.x+=i.internals.positionAbsolute.x-(t.width??0)*l[0],a.y+=i.internals.positionAbsolute.y-(t.height??0)*l[1]}return a}function nl(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function Bh(){let e,t;return{promise:new Promise((s,o)=>{e=s,t=o}),resolve:e,reject:t}}function qh(e){return{...Gc,...e||{}}}function sr(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:s,containerBounds:o}){const{x:a,y:i}=en(e),l=wr({x:a-(o?.left??0),y:i-(o?.top??0)},s),{x:c,y:d}=n?yr(l,t):l;return{xSnapped:c,ySnapped:d,...l}}const Pa=e=>({width:e.offsetWidth,height:e.offsetHeight}),od=e=>e?.getRootNode?.()||window?.document,zh=["INPUT","SELECT","TEXTAREA"];function ad(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:zh.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const id=e=>"clientX"in e,en=(e,t)=>{const n=id(e),s=n?e.clientX:e.touches?.[0].clientX,o=n?e.clientY:e.touches?.[0].clientY;return{x:s-(t?.left??0),y:o-(t?.top??0)}},sl=(e,t,n,s,o)=>{const a=t.querySelectorAll(`.${e}`);return!a||!a.length?null:Array.from(a).map(i=>{const l=i.getBoundingClientRect();return{id:i.getAttribute("data-handleid"),type:e,nodeId:o,position:i.getAttribute("data-handlepos"),x:(l.left-n.left)/s,y:(l.top-n.top)/s,...Pa(i)}})};function ld({sourceX:e,sourceY:t,targetX:n,targetY:s,sourceControlX:o,sourceControlY:a,targetControlX:i,targetControlY:l}){const c=e*.125+o*.375+i*.375+n*.125,d=t*.125+a*.375+l*.375+s*.125,h=Math.abs(c-e),u=Math.abs(d-t);return[c,d,h,u]}function Vr(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function rl({pos:e,x1:t,y1:n,x2:s,y2:o,c:a}){switch(e){case ve.Left:return[t-Vr(t-s,a),n];case ve.Right:return[t+Vr(s-t,a),n];case ve.Top:return[t,n-Vr(n-o,a)];case ve.Bottom:return[t,n+Vr(o-n,a)]}}function cd({sourceX:e,sourceY:t,sourcePosition:n=ve.Bottom,targetX:s,targetY:o,targetPosition:a=ve.Top,curvature:i=.25}){const[l,c]=rl({pos:n,x1:e,y1:t,x2:s,y2:o,c:i}),[d,h]=rl({pos:a,x1:s,y1:o,x2:e,y2:t,c:i}),[u,f,m,g]=ld({sourceX:e,sourceY:t,targetX:s,targetY:o,sourceControlX:l,sourceControlY:c,targetControlX:d,targetControlY:h});return[`M${e},${t} C${l},${c} ${d},${h} ${s},${o}`,u,f,m,g]}function dd({sourceX:e,sourceY:t,targetX:n,targetY:s}){const o=Math.abs(n-e)/2,a=n<e?n+o:n-o,i=Math.abs(s-t)/2,l=s<t?s+i:s-i;return[a,l,o,i]}function Fh({sourceNode:e,targetNode:t,selected:n=!1,zIndex:s=0,elevateOnSelect:o=!1,zIndexMode:a="basic"}){if(a==="manual")return s;const i=o&&n?s+1e3:s,l=Math.max(e.parentId||o&&e.selected?e.internals.z:0,t.parentId||o&&t.selected?t.internals.z:0);return i+l}function Hh({sourceNode:e,targetNode:t,width:n,height:s,transform:o}){const a=jo(fo(e),fo(t));a.x===a.x2&&(a.x2+=1),a.y===a.y2&&(a.y2+=1);const i={x:-o[0]/o[2],y:-o[1]/o[2],width:n/o[2],height:s/o[2]};return ur(i,No(a))>0}const Vh=({source:e,sourceHandle:t,target:n,targetHandle:s})=>`xy-edge__${e}${t||""}-${n}${s||""}`,Wh=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),Kh=(e,t,n={})=>{if(!e.source||!e.target)return t;const s=n.getEdgeId||Vh;let o;return Qc(e)?o={...e}:o={...e,id:s(e)},Wh(o,t)?t:(o.sourceHandle===null&&delete o.sourceHandle,o.targetHandle===null&&delete o.targetHandle,t.concat(o))};function ud({sourceX:e,sourceY:t,targetX:n,targetY:s}){const[o,a,i,l]=dd({sourceX:e,sourceY:t,targetX:n,targetY:s});return[`M ${e},${t}L ${n},${s}`,o,a,i,l]}const ol={[ve.Left]:{x:-1,y:0},[ve.Right]:{x:1,y:0},[ve.Top]:{x:0,y:-1},[ve.Bottom]:{x:0,y:1}},Uh=({source:e,sourcePosition:t=ve.Bottom,target:n})=>t===ve.Left||t===ve.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},al=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function Yh({source:e,sourcePosition:t=ve.Bottom,target:n,targetPosition:s=ve.Top,center:o,offset:a,stepPosition:i}){const l=ol[t],c=ol[s],d={x:e.x+l.x*a,y:e.y+l.y*a},h={x:n.x+c.x*a,y:n.y+c.y*a},u=Uh({source:d,sourcePosition:t,target:h}),f=u.x!==0?"x":"y",m=u[f];let g=[],b,v;const k={x:0,y:0},y={x:0,y:0},[,,x,w]=dd({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(l[f]*c[f]===-1){f==="x"?(b=o.x??d.x+(h.x-d.x)*i,v=o.y??(d.y+h.y)/2):(b=o.x??(d.x+h.x)/2,v=o.y??d.y+(h.y-d.y)*i);const j=[{x:b,y:d.y},{x:b,y:h.y}],E=[{x:d.x,y:v},{x:h.x,y:v}];l[f]===m?g=f==="x"?j:E:g=f==="x"?E:j}else{const j=[{x:d.x,y:h.y}],E=[{x:h.x,y:d.y}];if(f==="x"?g=l.x===m?E:j:g=l.y===m?j:E,t===s){const D=Math.abs(e[f]-n[f]);if(D<=a){const z=Math.min(a-1,a-D);l[f]===m?k[f]=(d[f]>e[f]?-1:1)*z:y[f]=(h[f]>n[f]?-1:1)*z}}if(t!==s){const D=f==="x"?"y":"x",z=l[f]===c[D],I=d[D]>h[D],B=d[D]<h[D];(l[f]===1&&(!z&&I||z&&B)||l[f]!==1&&(!z&&B||z&&I))&&(g=f==="x"?j:E)}const C={x:d.x+k.x,y:d.y+k.y},R={x:h.x+y.x,y:h.y+y.y},P=Math.max(Math.abs(C.x-g[0].x),Math.abs(R.x-g[0].x)),T=Math.max(Math.abs(C.y-g[0].y),Math.abs(R.y-g[0].y));P>=T?(b=(C.x+R.x)/2,v=g[0].y):(b=g[0].x,v=(C.y+R.y)/2)}return[[e,{x:d.x+k.x,y:d.y+k.y},...g,{x:h.x+y.x,y:h.y+y.y},n],b,v,x,w]}function Gh(e,t,n,s){const o=Math.min(al(e,t)/2,al(t,n)/2,s),{x:a,y:i}=t;if(e.x===a&&a===n.x||e.y===i&&i===n.y)return`L${a} ${i}`;if(e.y===i){const d=e.x<n.x?-1:1,h=e.y<n.y?1:-1;return`L ${a+o*d},${i}Q ${a},${i} ${a},${i+o*h}`}const l=e.x<n.x?1:-1,c=e.y<n.y?-1:1;return`L ${a},${i+o*c}Q ${a},${i} ${a+o*l},${i}`}function xa({sourceX:e,sourceY:t,sourcePosition:n=ve.Bottom,targetX:s,targetY:o,targetPosition:a=ve.Top,borderRadius:i=5,centerX:l,centerY:c,offset:d=20,stepPosition:h=.5}){const[u,f,m,g,b]=Yh({source:{x:e,y:t},sourcePosition:n,target:{x:s,y:o},targetPosition:a,center:{x:l,y:c},offset:d,stepPosition:h});return[u.reduce((k,y,x)=>{let w="";return x>0&&x<u.length-1?w=Gh(u[x-1],y,u[x+1],i):w=`${x===0?"M":"L"}${y.x} ${y.y}`,k+=w,k},""),f,m,g,b]}function il(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Xh(e){const{sourceNode:t,targetNode:n}=e;if(!il(t)||!il(n))return null;const s=t.internals.handleBounds||ll(t.handles),o=n.internals.handleBounds||ll(n.handles),a=cl(s?.source??[],e.sourceHandle),i=cl(e.connectionMode===Ts.Strict?o?.target??[]:(o?.target??[]).concat(o?.source??[]),e.targetHandle);if(!a||!i)return e.onError?.("008",ln.error008(a?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const l=a?.position||ve.Bottom,c=i?.position||ve.Top,d=ts(t,a,l),h=ts(n,i,c);return{sourceX:d.x,sourceY:d.y,targetX:h.x,targetY:h.y,sourcePosition:l,targetPosition:c}}function ll(e){if(!e)return null;const t=[],n=[];for(const s of e)s.width=s.width??1,s.height=s.height??1,s.type==="source"?t.push(s):s.type==="target"&&n.push(s);return{source:t,target:n}}function ts(e,t,n=ve.Left,s=!1){const o=(t?.x??0)+e.internals.positionAbsolute.x,a=(t?.y??0)+e.internals.positionAbsolute.y,{width:i,height:l}=t??wn(e);if(s)return{x:o+i/2,y:a+l/2};switch(t?.position??n){case ve.Top:return{x:o+i/2,y:a};case ve.Right:return{x:o+i,y:a+l/2};case ve.Bottom:return{x:o+i/2,y:a+l};case ve.Left:return{x:o,y:a+l/2}}}function cl(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function ba(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(s=>`${s}=${e[s]}`).join("&")}`:""}function Zh(e,{id:t,defaultColor:n,defaultMarkerStart:s,defaultMarkerEnd:o}){const a=new Set;return e.reduce((i,l)=>([l.markerStart||s,l.markerEnd||o].forEach(c=>{if(c&&typeof c=="object"){const d=ba(c,t);a.has(d)||(i.push({id:d,color:c.color||n,...c}),a.add(d))}}),i),[]).sort((i,l)=>i.id.localeCompare(l.id))}const fd=1e3,Qh=10,Ba={nodeOrigin:[0,0],nodeExtent:cr,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},Jh={...Ba,checkEquality:!0};function qa(e,t){const n={...e};for(const s in t)t[s]!==void 0&&(n[s]=t[s]);return n}function em(e,t,n){const s=qa(Ba,n);for(const o of e.values())if(o.parentId)Fa(o,e,t,s);else{const a=xr(o,s.nodeOrigin),i=_s(o.extent)?o.extent:s.nodeExtent,l=es(a,i,wn(o));o.internals.positionAbsolute=l}}function tm(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;const n=[],s=[];for(const o of e.handles){const a={id:o.id,width:o.width??1,height:o.height??1,nodeId:e.id,x:o.x,y:o.y,position:o.position,type:o.type};o.type==="source"?n.push(a):o.type==="target"&&s.push(a)}return{source:n,target:s}}function za(e){return e==="manual"}function ya(e,t,n,s={}){const o=qa(Jh,s),a={i:0},i=new Map(t),l=o?.elevateNodesOnSelect&&!za(o.zIndexMode)?fd:0;let c=e.length>0;t.clear(),n.clear();for(const d of e){let h=i.get(d.id);if(o.checkEquality&&d===h?.internals.userNode)t.set(d.id,h);else{const u=xr(d,o.nodeOrigin),f=_s(d.extent)?d.extent:o.nodeExtent,m=es(u,f,wn(d));h={...o.defaults,...d,measured:{width:d.measured?.width,height:d.measured?.height},internals:{positionAbsolute:m,handleBounds:tm(d,h),z:hd(d,l,o.zIndexMode),userNode:d}},t.set(d.id,h)}(h.measured===void 0||h.measured.width===void 0||h.measured.height===void 0)&&!h.hidden&&(c=!1),d.parentId&&Fa(h,t,n,s,a)}return c}function nm(e,t){if(!e.parentId)return;const n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function Fa(e,t,n,s,o){const{elevateNodesOnSelect:a,nodeOrigin:i,nodeExtent:l,zIndexMode:c}=qa(Ba,s),d=e.parentId,h=t.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}nm(e,n),o&&!h.parentId&&h.internals.rootParentIndex===void 0&&c==="auto"&&(h.internals.rootParentIndex=++o.i,h.internals.z=h.internals.z+o.i*Qh),o&&h.internals.rootParentIndex!==void 0&&(o.i=h.internals.rootParentIndex);const u=a&&!za(c)?fd:0,{x:f,y:m,z:g}=sm(e,h,i,l,u,c),{positionAbsolute:b}=e.internals,v=f!==b.x||m!==b.y;(v||g!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:v?{x:f,y:m}:b,z:g}})}function hd(e,t,n){const s=Jt(e.zIndex)?e.zIndex:0;return za(n)?s:s+(e.selected?t:0)}function sm(e,t,n,s,o,a){const{x:i,y:l}=t.internals.positionAbsolute,c=wn(e),d=xr(e,n),h=_s(e.extent)?es(d,e.extent,c):d;let u=es({x:i+h.x,y:l+h.y},s,c);e.extent==="parent"&&(u=ed(u,c,t));const f=hd(e,o,a),m=t.internals.z??0;return{x:u.x,y:u.y,z:m>=f?m+1:f}}function Ha(e,t,n,s=[0,0]){const o=[],a=new Map;for(const i of e){const l=t.get(i.parentId);if(!l)continue;const c=a.get(i.parentId)?.expandedRect??Ls(l),d=nd(c,i.rect);a.set(i.parentId,{expandedRect:d,parent:l})}return a.size>0&&a.forEach(({expandedRect:i,parent:l},c)=>{const d=l.internals.positionAbsolute,h=wn(l),u=l.origin??s,f=i.x<d.x?Math.round(Math.abs(d.x-i.x)):0,m=i.y<d.y?Math.round(Math.abs(d.y-i.y)):0,g=Math.max(h.width,Math.round(i.width)),b=Math.max(h.height,Math.round(i.height)),v=(g-h.width)*u[0],k=(b-h.height)*u[1];(f>0||m>0||v||k)&&(o.push({id:c,type:"position",position:{x:l.position.x-f+v,y:l.position.y-m+k}}),n.get(c)?.forEach(y=>{e.some(x=>x.id===y.id)||o.push({id:y.id,type:"position",position:{x:y.position.x+f,y:y.position.y+m}})})),(h.width<i.width||h.height<i.height||f||m)&&o.push({id:c,type:"dimensions",setAttributes:!0,dimensions:{width:g+(f?u[0]*f-v:0),height:b+(m?u[1]*m-k:0)}})}),o}function rm(e,t,n,s,o,a,i){const l=s?.querySelector(".xyflow__viewport");let c=!1;if(!l)return{changes:[],updatedInternals:c};const d=[],h=window.getComputedStyle(l),{m22:u}=new window.DOMMatrixReadOnly(h.transform),f=[];for(const m of e.values()){const g=t.get(m.id);if(!g)continue;if(g.hidden){t.set(g.id,{...g,internals:{...g.internals,handleBounds:void 0}}),c=!0;continue}const b=Pa(m.nodeElement),v=g.measured.width!==b.width||g.measured.height!==b.height;if(!!(b.width&&b.height&&(v||!g.internals.handleBounds||m.force))){const y=m.nodeElement.getBoundingClientRect(),x=_s(g.extent)?g.extent:a;let{positionAbsolute:w}=g.internals;g.parentId&&g.extent==="parent"?w=ed(w,b,t.get(g.parentId)):x&&(w=es(w,x,b));const S={...g,measured:b,internals:{...g.internals,positionAbsolute:w,handleBounds:{source:sl("source",m.nodeElement,y,u,g.id),target:sl("target",m.nodeElement,y,u,g.id)}}};t.set(g.id,S),g.parentId&&Fa(S,t,n,{nodeOrigin:o,zIndexMode:i}),c=!0,v&&(d.push({id:g.id,type:"dimensions",dimensions:b}),g.expandParent&&g.parentId&&f.push({id:g.id,parentId:g.parentId,rect:Ls(S,o)}))}}if(f.length>0){const m=Ha(f,t,n,o);d.push(...m)}return{changes:d,updatedInternals:c}}async function om({delta:e,panZoom:t,transform:n,translateExtent:s,width:o,height:a}){if(!t||!e.x&&!e.y)return Promise.resolve(!1);const i=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[o,a]],s),l=!!i&&(i.x!==n[0]||i.y!==n[1]||i.k!==n[2]);return Promise.resolve(l)}function dl(e,t,n,s,o,a){let i=o;const l=s.get(i)||new Map;s.set(i,l.set(n,t)),i=`${o}-${e}`;const c=s.get(i)||new Map;if(s.set(i,c.set(n,t)),a){i=`${o}-${e}-${a}`;const d=s.get(i)||new Map;s.set(i,d.set(n,t))}}function md(e,t,n){e.clear(),t.clear();for(const s of n){const{source:o,target:a,sourceHandle:i=null,targetHandle:l=null}=s,c={edgeId:s.id,source:o,target:a,sourceHandle:i,targetHandle:l},d=`${o}-${i}--${a}-${l}`,h=`${a}-${l}--${o}-${i}`;dl("source",c,h,e,o,i),dl("target",c,d,e,a,l),t.set(s.id,s)}}function pd(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:pd(n,t):!1}function ul(e,t,n){let s=e;do{if(s?.matches?.(t))return!0;if(s===n)return!1;s=s?.parentElement}while(s);return!1}function am(e,t,n,s){const o=new Map;for(const[a,i]of e)if((i.selected||i.id===s)&&(!i.parentId||!pd(i,e))&&(i.draggable||t&&typeof i.draggable>"u")){const l=e.get(a);l&&o.set(a,{id:a,position:l.position||{x:0,y:0},distance:{x:n.x-l.internals.positionAbsolute.x,y:n.y-l.internals.positionAbsolute.y},extent:l.extent,parentId:l.parentId,origin:l.origin,expandParent:l.expandParent,internals:{positionAbsolute:l.internals.positionAbsolute||{x:0,y:0}},measured:{width:l.measured.width??0,height:l.measured.height??0}})}return o}function Zo({nodeId:e,dragItems:t,nodeLookup:n,dragging:s=!0}){const o=[];for(const[i,l]of t){const c=n.get(i)?.internals.userNode;c&&o.push({...c,position:l.position,dragging:s})}if(!e)return[o[0],o];const a=n.get(e)?.internals.userNode;return[a?{...a,position:t.get(e)?.position||a.position,dragging:s}:o[0],o]}function im({dragItems:e,snapGrid:t,x:n,y:s}){const o=e.values().next().value;if(!o)return null;const a={x:n-o.distance.x,y:s-o.distance.y},i=yr(a,t);return{x:i.x-a.x,y:i.y-a.y}}function lm({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:s,onDragStop:o}){let a={x:null,y:null},i=0,l=new Map,c=!1,d={x:0,y:0},h=null,u=!1,f=null,m=!1,g=!1,b=null;function v({noDragClassName:y,handleSelector:x,domNode:w,isSelectable:S,nodeId:j,nodeClickDistance:E=0}){f=zt(w);function C({x:D,y:z}){const{nodeLookup:I,nodeExtent:B,snapGrid:L,snapToGrid:q,nodeOrigin:_,onNodeDrag:A,onSelectionDrag:$,onError:F,updateNodePositions:V}=t();a={x:D,y:z};let X=!1;const O=l.size>1,M=O&&B?ga(br(l)):null,K=O&&q?im({dragItems:l,snapGrid:L,x:D,y:z}):null;for(const[W,H]of l){if(!I.has(W))continue;let Z={x:D-H.distance.x,y:z-H.distance.y};q&&(Z=K?{x:Math.round(Z.x+K.x),y:Math.round(Z.y+K.y)}:yr(Z,L));let J=null;if(O&&B&&!H.extent&&M){const{positionAbsolute:pe}=H.internals,we=pe.x-M.x+B[0][0],Ne=pe.x+H.measured.width-M.x2+B[1][0],ke=pe.y-M.y+B[0][1],Be=pe.y+H.measured.height-M.y2+B[1][1];J=[[we,ke],[Ne,Be]]}const{position:le,positionAbsolute:ue}=Jc({nodeId:W,nextPosition:Z,nodeLookup:I,nodeExtent:J||B,nodeOrigin:_,onError:F});X=X||H.position.x!==le.x||H.position.y!==le.y,H.position=le,H.internals.positionAbsolute=ue}if(g=g||X,!!X&&(V(l,!0),b&&(s||A||!j&&$))){const[W,H]=Zo({nodeId:j,dragItems:l,nodeLookup:I});s?.(b,l,W,H),A?.(b,W,H),j||$?.(b,H)}}async function R(){if(!h)return;const{transform:D,panBy:z,autoPanSpeed:I,autoPanOnNodeDrag:B}=t();if(!B){c=!1,cancelAnimationFrame(i);return}const[L,q]=td(d,h,I);(L!==0||q!==0)&&(a.x=(a.x??0)-L/D[2],a.y=(a.y??0)-q/D[2],await z({x:L,y:q})&&C(a)),i=requestAnimationFrame(R)}function P(D){const{nodeLookup:z,multiSelectionActive:I,nodesDraggable:B,transform:L,snapGrid:q,snapToGrid:_,selectNodesOnDrag:A,onNodeDragStart:$,onSelectionDragStart:F,unselectNodesAndEdges:V}=t();u=!0,(!A||!S)&&!I&&j&&(z.get(j)?.selected||V()),S&&A&&j&&e?.(j);const X=sr(D.sourceEvent,{transform:L,snapGrid:q,snapToGrid:_,containerBounds:h});if(a=X,l=am(z,B,X,j),l.size>0&&(n||$||!j&&F)){const[O,M]=Zo({nodeId:j,dragItems:l,nodeLookup:z});n?.(D.sourceEvent,l,O,M),$?.(D.sourceEvent,O,M),j||F?.(D.sourceEvent,M)}}const T=qc().clickDistance(E).on("start",D=>{const{domNode:z,nodeDragThreshold:I,transform:B,snapGrid:L,snapToGrid:q}=t();h=z?.getBoundingClientRect()||null,m=!1,g=!1,b=D.sourceEvent,I===0&&P(D),a=sr(D.sourceEvent,{transform:B,snapGrid:L,snapToGrid:q,containerBounds:h}),d=en(D.sourceEvent,h)}).on("drag",D=>{const{autoPanOnNodeDrag:z,transform:I,snapGrid:B,snapToGrid:L,nodeDragThreshold:q,nodeLookup:_}=t(),A=sr(D.sourceEvent,{transform:I,snapGrid:B,snapToGrid:L,containerBounds:h});if(b=D.sourceEvent,(D.sourceEvent.type==="touchmove"&&D.sourceEvent.touches.length>1||j&&!_.has(j))&&(m=!0),!m){if(!c&&z&&u&&(c=!0,R()),!u){const $=en(D.sourceEvent,h),F=$.x-d.x,V=$.y-d.y;Math.sqrt(F*F+V*V)>q&&P(D)}(a.x!==A.xSnapped||a.y!==A.ySnapped)&&l&&u&&(d=en(D.sourceEvent,h),C(A))}}).on("end",D=>{if(!(!u||m)&&(c=!1,u=!1,cancelAnimationFrame(i),l.size>0)){const{nodeLookup:z,updateNodePositions:I,onNodeDragStop:B,onSelectionDragStop:L}=t();if(g&&(I(l,!1),g=!1),o||B||!j&&L){const[q,_]=Zo({nodeId:j,dragItems:l,nodeLookup:z,dragging:!1});o?.(D.sourceEvent,l,q,_),B?.(D.sourceEvent,q,_),j||L?.(D.sourceEvent,_)}}}).filter(D=>{const z=D.target;return!D.button&&(!y||!ul(z,`.${y}`,w))&&(!x||ul(z,x,w))});f.call(T)}function k(){f?.on(".drag",null)}return{update:v,destroy:k}}function cm(e,t,n){const s=[],o={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const a of t.values())ur(o,Ls(a))>0&&s.push(a);return s}const dm=250;function um(e,t,n,s){let o=[],a=1/0;const i=cm(e,n,t+dm);for(const l of i){const c=[...l.internals.handleBounds?.source??[],...l.internals.handleBounds?.target??[]];for(const d of c){if(s.nodeId===d.nodeId&&s.type===d.type&&s.id===d.id)continue;const{x:h,y:u}=ts(l,d,d.position,!0),f=Math.sqrt(Math.pow(h-e.x,2)+Math.pow(u-e.y,2));f>t||(f<a?(o=[{...d,x:h,y:u}],a=f):f===a&&o.push({...d,x:h,y:u}))}}if(!o.length)return null;if(o.length>1){const l=s.type==="source"?"target":"source";return o.find(c=>c.type===l)??o[0]}return o[0]}function gd(e,t,n,s,o,a=!1){const i=s.get(e);if(!i)return null;const l=o==="strict"?i.internals.handleBounds?.[t]:[...i.internals.handleBounds?.source??[],...i.internals.handleBounds?.target??[]],c=(n?l?.find(d=>d.id===n):l?.[0])??null;return c&&a?{...c,...ts(i,c,c.position,!0)}:c}function xd(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function fm(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const bd=()=>!0;function hm(e,{connectionMode:t,connectionRadius:n,handleId:s,nodeId:o,edgeUpdaterType:a,isTarget:i,domNode:l,nodeLookup:c,lib:d,autoPanOnConnect:h,flowId:u,panBy:f,cancelConnection:m,onConnectStart:g,onConnect:b,onConnectEnd:v,isValidConnection:k=bd,onReconnectEnd:y,updateConnection:x,getTransform:w,getFromHandle:S,autoPanSpeed:j,dragThreshold:E=1,handleDomNode:C}){const R=od(e.target);let P=0,T;const{x:D,y:z}=en(e),I=xd(a,C),B=l?.getBoundingClientRect();let L=!1;if(!B||!I)return;const q=gd(o,I,s,c,t);if(!q)return;let _=en(e,B),A=!1,$=null,F=!1,V=null;function X(){if(!h||!B)return;const[le,ue]=td(_,B,j);f({x:le,y:ue}),P=requestAnimationFrame(X)}const O={...q,nodeId:o,type:I,position:q.position},M=c.get(o);let W={inProgress:!0,isValid:null,from:ts(M,O,ve.Left,!0),fromHandle:O,fromPosition:O.position,fromNode:M,to:_,toHandle:null,toPosition:Ji[O.position],toNode:null,pointer:_};function H(){L=!0,x(W),g?.(e,{nodeId:o,handleId:s,handleType:I})}E===0&&H();function Z(le){if(!L){const{x:Be,y:et}=en(le),Ee=Be-D,Ke=et-z;if(!(Ee*Ee+Ke*Ke>E*E))return;H()}if(!S()||!O){J(le);return}const ue=w();_=en(le,B),T=um(wr(_,ue,!1,[1,1]),n,c,O),A||(X(),A=!0);const pe=yd(le,{handle:T,connectionMode:t,fromNodeId:o,fromHandleId:s,fromType:i?"target":"source",isValidConnection:k,doc:R,lib:d,flowId:u,nodeLookup:c});V=pe.handleDomNode,$=pe.connection,F=fm(!!T,pe.isValid);const we=c.get(o),Ne=we?ts(we,O,ve.Left,!0):W.from,ke={...W,from:Ne,isValid:F,to:pe.toHandle&&F?ho({x:pe.toHandle.x,y:pe.toHandle.y},ue):_,toHandle:pe.toHandle,toPosition:F&&pe.toHandle?pe.toHandle.position:Ji[O.position],toNode:pe.toHandle?c.get(pe.toHandle.nodeId):null,pointer:_};x(ke),W=ke}function J(le){if(!("touches"in le&&le.touches.length>0)){if(L){(T||V)&&$&&F&&b?.($);const{inProgress:ue,...pe}=W,we={...pe,toPosition:W.toHandle?W.toPosition:null};v?.(le,we),a&&y?.(le,we)}m(),cancelAnimationFrame(P),A=!1,F=!1,$=null,V=null,R.removeEventListener("mousemove",Z),R.removeEventListener("mouseup",J),R.removeEventListener("touchmove",Z),R.removeEventListener("touchend",J)}}R.addEventListener("mousemove",Z),R.addEventListener("mouseup",J),R.addEventListener("touchmove",Z),R.addEventListener("touchend",J)}function yd(e,{handle:t,connectionMode:n,fromNodeId:s,fromHandleId:o,fromType:a,doc:i,lib:l,flowId:c,isValidConnection:d=bd,nodeLookup:h}){const u=a==="target",f=t?i.querySelector(`.${l}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:m,y:g}=en(e),b=i.elementFromPoint(m,g),v=b?.classList.contains(`${l}-flow__handle`)?b:f,k={handleDomNode:v,isValid:!1,connection:null,toHandle:null};if(v){const y=xd(void 0,v),x=v.getAttribute("data-nodeid"),w=v.getAttribute("data-handleid"),S=v.classList.contains("connectable"),j=v.classList.contains("connectableend");if(!x||!y)return k;const E={source:u?x:s,sourceHandle:u?w:o,target:u?s:x,targetHandle:u?o:w};k.connection=E;const R=S&&j&&(n===Ts.Strict?u&&y==="source"||!u&&y==="target":x!==s||w!==o);k.isValid=R&&d(E),k.toHandle=gd(x,y,w,h,n,!0)}return k}const wa={onPointerDown:hm,isValid:yd};function mm({domNode:e,panZoom:t,getTransform:n,getViewScale:s}){const o=zt(e);function a({translateExtent:l,width:c,height:d,zoomStep:h=1,pannable:u=!0,zoomable:f=!0,inversePan:m=!1}){const g=x=>{if(x.sourceEvent.type!=="wheel"||!t)return;const w=n(),S=x.sourceEvent.ctrlKey&&fr()?10:1,j=-x.sourceEvent.deltaY*(x.sourceEvent.deltaMode===1?.05:x.sourceEvent.deltaMode?1:.002)*h,E=w[2]*Math.pow(2,j*S);t.scaleTo(E)};let b=[0,0];const v=x=>{(x.sourceEvent.type==="mousedown"||x.sourceEvent.type==="touchstart")&&(b=[x.sourceEvent.clientX??x.sourceEvent.touches[0].clientX,x.sourceEvent.clientY??x.sourceEvent.touches[0].clientY])},k=x=>{const w=n();if(x.sourceEvent.type!=="mousemove"&&x.sourceEvent.type!=="touchmove"||!t)return;const S=[x.sourceEvent.clientX??x.sourceEvent.touches[0].clientX,x.sourceEvent.clientY??x.sourceEvent.touches[0].clientY],j=[S[0]-b[0],S[1]-b[1]];b=S;const E=s()*Math.max(w[2],Math.log(w[2]))*(m?-1:1),C={x:w[0]-j[0]*E,y:w[1]-j[1]*E},R=[[0,0],[c,d]];t.setViewportConstrained({x:C.x,y:C.y,zoom:w[2]},R,l)},y=zc().on("start",v).on("zoom",u?k:null).on("zoom.wheel",f?g:null);o.call(y,{})}function i(){o.on("zoom",null)}return{update:a,destroy:i,pointer:Qt}}const So=e=>({x:e.x,y:e.y,zoom:e.k}),Qo=({x:e,y:t,zoom:n})=>Ra.translate(e,t).scale(n),ws=(e,t)=>e.target.closest(`.${t}`),wd=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),pm=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Jo=(e,t=0,n=pm,s=()=>{})=>{const o=typeof t=="number"&&t>0;return o||s(),o?e.transition().duration(t).ease(n).on("end",s):e},kd=e=>{const t=e.ctrlKey&&fr()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function gm({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:s,panOnScrollMode:o,panOnScrollSpeed:a,zoomOnPinch:i,onPanZoomStart:l,onPanZoom:c,onPanZoomEnd:d}){return h=>{if(ws(h,t))return h.ctrlKey&&h.preventDefault(),!1;h.preventDefault(),h.stopImmediatePropagation();const u=n.property("__zoom").k||1;if(h.ctrlKey&&i){const v=Qt(h),k=kd(h),y=u*Math.pow(2,k);s.scaleTo(n,y,v,h);return}const f=h.deltaMode===1?20:1;let m=o===Jn.Vertical?0:h.deltaX*f,g=o===Jn.Horizontal?0:h.deltaY*f;!fr()&&h.shiftKey&&o!==Jn.Vertical&&(m=h.deltaY*f,g=0),s.translateBy(n,-(m/u)*a,-(g/u)*a,{internal:!0});const b=So(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(h,b),e.panScrollTimeout=setTimeout(()=>{d?.(h,b),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,l?.(h,b))}}function xm({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(s,o){const a=s.type==="wheel",i=!t&&a&&!s.ctrlKey,l=ws(s,e);if(s.ctrlKey&&a&&l&&s.preventDefault(),i||l)return null;s.preventDefault(),n.call(this,s,o)}}function bm({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return s=>{if(s.sourceEvent?.internal)return;const o=So(s.transform);e.mouseButton=s.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=o,s.sourceEvent?.type==="mousedown"&&t(!0),n&&n?.(s.sourceEvent,o)}}function ym({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:s,onPanZoom:o}){return a=>{e.usedRightMouseButton=!!(n&&wd(t,e.mouseButton??0)),a.sourceEvent?.sync||s([a.transform.x,a.transform.y,a.transform.k]),o&&!a.sourceEvent?.internal&&o?.(a.sourceEvent,So(a.transform))}}function wm({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:s,onPanZoomEnd:o,onPaneContextMenu:a}){return i=>{if(!i.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&wd(t,e.mouseButton??0)&&!e.usedRightMouseButton&&i.sourceEvent&&a(i.sourceEvent),e.usedRightMouseButton=!1,s(!1),o)){const l=So(i.transform);e.prevViewport=l,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{o?.(i.sourceEvent,l)},n?150:0)}}}function km({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:s,panOnScroll:o,zoomOnDoubleClick:a,userSelectionActive:i,noWheelClassName:l,noPanClassName:c,lib:d,connectionInProgress:h}){return u=>{const f=e||t,m=n&&u.ctrlKey,g=u.type==="wheel";if(u.button===1&&u.type==="mousedown"&&(ws(u,`${d}-flow__node`)||ws(u,`${d}-flow__edge`)))return!0;if(!s&&!f&&!o&&!a&&!n||i||h&&!g||ws(u,l)&&g||ws(u,c)&&(!g||o&&g&&!e)||!n&&u.ctrlKey&&g)return!1;if(!n&&u.type==="touchstart"&&u.touches?.length>1)return u.preventDefault(),!1;if(!f&&!o&&!m&&g||!s&&(u.type==="mousedown"||u.type==="touchstart")||Array.isArray(s)&&!s.includes(u.button)&&u.type==="mousedown")return!1;const b=Array.isArray(s)&&s.includes(u.button)||!u.button||u.button<=1;return(!u.ctrlKey||g)&&b}}function vm({domNode:e,minZoom:t,maxZoom:n,translateExtent:s,viewport:o,onPanZoom:a,onPanZoomStart:i,onPanZoomEnd:l,onDraggingChange:c}){const d={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},h=e.getBoundingClientRect(),u=zc().scaleExtent([t,n]).translateExtent(s),f=zt(e).call(u);y({x:o.x,y:o.y,zoom:As(o.zoom,t,n)},[[0,0],[h.width,h.height]],s);const m=f.on("wheel.zoom"),g=f.on("dblclick.zoom");u.wheelDelta(kd);function b(T,D){return f?new Promise(z=>{u?.interpolate(D?.interpolate==="linear"?Yo:ro).transform(Jo(f,D?.duration,D?.ease,()=>z(!0)),T)}):Promise.resolve(!1)}function v({noWheelClassName:T,noPanClassName:D,onPaneContextMenu:z,userSelectionActive:I,panOnScroll:B,panOnDrag:L,panOnScrollMode:q,panOnScrollSpeed:_,preventScrolling:A,zoomOnPinch:$,zoomOnScroll:F,zoomOnDoubleClick:V,zoomActivationKeyPressed:X,lib:O,onTransformChange:M,connectionInProgress:K,paneClickDistance:W,selectionOnDrag:H}){I&&!d.isZoomingOrPanning&&k();const Z=B&&!X&&!I;u.clickDistance(H?1/0:!Jt(W)||W<0?0:W);const J=Z?gm({zoomPanValues:d,noWheelClassName:T,d3Selection:f,d3Zoom:u,panOnScrollMode:q,panOnScrollSpeed:_,zoomOnPinch:$,onPanZoomStart:i,onPanZoom:a,onPanZoomEnd:l}):xm({noWheelClassName:T,preventScrolling:A,d3ZoomHandler:m});if(f.on("wheel.zoom",J,{passive:!1}),!I){const ue=bm({zoomPanValues:d,onDraggingChange:c,onPanZoomStart:i});u.on("start",ue);const pe=ym({zoomPanValues:d,panOnDrag:L,onPaneContextMenu:!!z,onPanZoom:a,onTransformChange:M});u.on("zoom",pe);const we=wm({zoomPanValues:d,panOnDrag:L,panOnScroll:B,onPaneContextMenu:z,onPanZoomEnd:l,onDraggingChange:c});u.on("end",we)}const le=km({zoomActivationKeyPressed:X,panOnDrag:L,zoomOnScroll:F,panOnScroll:B,zoomOnDoubleClick:V,zoomOnPinch:$,userSelectionActive:I,noPanClassName:D,noWheelClassName:T,lib:O,connectionInProgress:K});u.filter(le),V?f.on("dblclick.zoom",g):f.on("dblclick.zoom",null)}function k(){u.on("zoom",null)}async function y(T,D,z){const I=Qo(T),B=u?.constrain()(I,D,z);return B&&await b(B),new Promise(L=>L(B))}async function x(T,D){const z=Qo(T);return await b(z,D),new Promise(I=>I(z))}function w(T){if(f){const D=Qo(T),z=f.property("__zoom");(z.k!==T.zoom||z.x!==T.x||z.y!==T.y)&&u?.transform(f,D,null,{sync:!0})}}function S(){const T=f?Qf(f.node()):{x:0,y:0,k:1};return{x:T.x,y:T.y,zoom:T.k}}function j(T,D){return f?new Promise(z=>{u?.interpolate(D?.interpolate==="linear"?Yo:ro).scaleTo(Jo(f,D?.duration,D?.ease,()=>z(!0)),T)}):Promise.resolve(!1)}function E(T,D){return f?new Promise(z=>{u?.interpolate(D?.interpolate==="linear"?Yo:ro).scaleBy(Jo(f,D?.duration,D?.ease,()=>z(!0)),T)}):Promise.resolve(!1)}function C(T){u?.scaleExtent(T)}function R(T){u?.translateExtent(T)}function P(T){const D=!Jt(T)||T<0?0:T;u?.clickDistance(D)}return{update:v,destroy:k,setViewport:x,setViewportConstrained:y,getViewport:S,scaleTo:j,scaleBy:E,setScaleExtent:C,setTranslateExtent:R,syncViewport:w,setClickDistance:P}}var Rs;(function(e){e.Line="line",e.Handle="handle"})(Rs||(Rs={}));function jm({width:e,prevWidth:t,height:n,prevHeight:s,affectsX:o,affectsY:a}){const i=e-t,l=n-s,c=[i>0?1:i<0?-1:0,l>0?1:l<0?-1:0];return i&&o&&(c[0]=c[0]*-1),l&&a&&(c[1]=c[1]*-1),c}function fl(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),s=e.includes("left"),o=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:s,affectsY:o}}function Sn(e,t){return Math.max(0,t-e)}function Cn(e,t){return Math.max(0,e-t)}function Wr(e,t,n){return Math.max(0,t-e,e-n)}function hl(e,t){return e?!t:t}function Nm(e,t,n,s,o,a,i,l){let{affectsX:c,affectsY:d}=t;const{isHorizontal:h,isVertical:u}=t,f=h&&u,{xSnapped:m,ySnapped:g}=n,{minWidth:b,maxWidth:v,minHeight:k,maxHeight:y}=s,{x,y:w,width:S,height:j,aspectRatio:E}=e;let C=Math.floor(h?m-e.pointerX:0),R=Math.floor(u?g-e.pointerY:0);const P=S+(c?-C:C),T=j+(d?-R:R),D=-a[0]*S,z=-a[1]*j;let I=Wr(P,b,v),B=Wr(T,k,y);if(i){let _=0,A=0;c&&C<0?_=Sn(x+C+D,i[0][0]):!c&&C>0&&(_=Cn(x+P+D,i[1][0])),d&&R<0?A=Sn(w+R+z,i[0][1]):!d&&R>0&&(A=Cn(w+T+z,i[1][1])),I=Math.max(I,_),B=Math.max(B,A)}if(l){let _=0,A=0;c&&C>0?_=Cn(x+C,l[0][0]):!c&&C<0&&(_=Sn(x+P,l[1][0])),d&&R>0?A=Cn(w+R,l[0][1]):!d&&R<0&&(A=Sn(w+T,l[1][1])),I=Math.max(I,_),B=Math.max(B,A)}if(o){if(h){const _=Wr(P/E,k,y)*E;if(I=Math.max(I,_),i){let A=0;!c&&!d||c&&!d&&f?A=Cn(w+z+P/E,i[1][1])*E:A=Sn(w+z+(c?C:-C)/E,i[0][1])*E,I=Math.max(I,A)}if(l){let A=0;!c&&!d||c&&!d&&f?A=Sn(w+P/E,l[1][1])*E:A=Cn(w+(c?C:-C)/E,l[0][1])*E,I=Math.max(I,A)}}if(u){const _=Wr(T*E,b,v)/E;if(B=Math.max(B,_),i){let A=0;!c&&!d||d&&!c&&f?A=Cn(x+T*E+D,i[1][0])/E:A=Sn(x+(d?R:-R)*E+D,i[0][0])/E,B=Math.max(B,A)}if(l){let A=0;!c&&!d||d&&!c&&f?A=Sn(x+T*E,l[1][0])/E:A=Cn(x+(d?R:-R)*E,l[0][0])/E,B=Math.max(B,A)}}}R=R+(R<0?B:-B),C=C+(C<0?I:-I),o&&(f?P>T*E?R=(hl(c,d)?-C:C)/E:C=(hl(c,d)?-R:R)*E:h?(R=C/E,d=c):(C=R*E,c=d));const L=c?x+C:x,q=d?w+R:w;return{width:S+(c?-C:C),height:j+(d?-R:R),x:a[0]*C*(c?-1:1)+L,y:a[1]*R*(d?-1:1)+q}}const vd={width:0,height:0,x:0,y:0},Sm={...vd,pointerX:0,pointerY:0,aspectRatio:1};function Cm(e){return[[0,0],[e.measured.width,e.measured.height]]}function Em(e,t,n){const s=t.position.x+e.position.x,o=t.position.y+e.position.y,a=e.measured.width??0,i=e.measured.height??0,l=n[0]*a,c=n[1]*i;return[[s-l,o-c],[s+a-l,o+i-c]]}function Im({domNode:e,nodeId:t,getStoreItems:n,onChange:s,onEnd:o}){const a=zt(e);let i={controlDirection:fl("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function l({controlPosition:d,boundaries:h,keepAspectRatio:u,resizeDirection:f,onResizeStart:m,onResize:g,onResizeEnd:b,shouldResize:v}){let k={...vd},y={...Sm};i={boundaries:h,resizeDirection:f,keepAspectRatio:u,controlDirection:fl(d)};let x,w=null,S=[],j,E,C,R=!1;const P=qc().on("start",T=>{const{nodeLookup:D,transform:z,snapGrid:I,snapToGrid:B,nodeOrigin:L,paneDomNode:q}=n();if(x=D.get(t),!x)return;w=q?.getBoundingClientRect()??null;const{xSnapped:_,ySnapped:A}=sr(T.sourceEvent,{transform:z,snapGrid:I,snapToGrid:B,containerBounds:w});k={width:x.measured.width??0,height:x.measured.height??0,x:x.position.x??0,y:x.position.y??0},y={...k,pointerX:_,pointerY:A,aspectRatio:k.width/k.height},j=void 0,x.parentId&&(x.extent==="parent"||x.expandParent)&&(j=D.get(x.parentId),E=j&&x.extent==="parent"?Cm(j):void 0),S=[],C=void 0;for(const[$,F]of D)if(F.parentId===t&&(S.push({id:$,position:{...F.position},extent:F.extent}),F.extent==="parent"||F.expandParent)){const V=Em(F,x,F.origin??L);C?C=[[Math.min(V[0][0],C[0][0]),Math.min(V[0][1],C[0][1])],[Math.max(V[1][0],C[1][0]),Math.max(V[1][1],C[1][1])]]:C=V}m?.(T,{...k})}).on("drag",T=>{const{transform:D,snapGrid:z,snapToGrid:I,nodeOrigin:B}=n(),L=sr(T.sourceEvent,{transform:D,snapGrid:z,snapToGrid:I,containerBounds:w}),q=[];if(!x)return;const{x:_,y:A,width:$,height:F}=k,V={},X=x.origin??B,{width:O,height:M,x:K,y:W}=Nm(y,i.controlDirection,L,i.boundaries,i.keepAspectRatio,X,E,C),H=O!==$,Z=M!==F,J=K!==_&&H,le=W!==A&&Z;if(!J&&!le&&!H&&!Z)return;if((J||le||X[0]===1||X[1]===1)&&(V.x=J?K:k.x,V.y=le?W:k.y,k.x=V.x,k.y=V.y,S.length>0)){const Ne=K-_,ke=W-A;for(const Be of S)Be.position={x:Be.position.x-Ne+X[0]*(O-$),y:Be.position.y-ke+X[1]*(M-F)},q.push(Be)}if((H||Z)&&(V.width=H&&(!i.resizeDirection||i.resizeDirection==="horizontal")?O:k.width,V.height=Z&&(!i.resizeDirection||i.resizeDirection==="vertical")?M:k.height,k.width=V.width,k.height=V.height),j&&x.expandParent){const Ne=X[0]*(V.width??0);V.x&&V.x<Ne&&(k.x=Ne,y.x=y.x-(V.x-Ne));const ke=X[1]*(V.height??0);V.y&&V.y<ke&&(k.y=ke,y.y=y.y-(V.y-ke))}const ue=jm({width:k.width,prevWidth:$,height:k.height,prevHeight:F,affectsX:i.controlDirection.affectsX,affectsY:i.controlDirection.affectsY}),pe={...k,direction:ue};v?.(T,pe)!==!1&&(R=!0,g?.(T,pe),s(V,q))}).on("end",T=>{R&&(b?.(T,{...k}),o?.({...k}),R=!1)});a.call(P)}function c(){a.on(".drag",null)}return{update:l,destroy:c}}var ea={exports:{}},ta={};var ml;function Tm(){if(ml)return ta;ml=1;var e=Nf(),t=Sf();function n(d,h){return d===h&&(d!==0||1/d===1/h)||d!==d&&h!==h}var s=typeof Object.is=="function"?Object.is:n,o=t.useSyncExternalStore,a=e.useRef,i=e.useEffect,l=e.useMemo,c=e.useDebugValue;return ta.useSyncExternalStoreWithSelector=function(d,h,u,f,m){var g=a(null);if(g.current===null){var b={hasValue:!1,value:null};g.current=b}else b=g.current;g=l(function(){function k(j){if(!y){if(y=!0,x=j,j=f(j),m!==void 0&&b.hasValue){var E=b.value;if(m(E,j))return w=E}return w=j}if(E=w,s(x,j))return E;var C=f(j);return m!==void 0&&m(E,C)?(x=j,E):(x=j,w=C)}var y=!1,x,w,S=u===void 0?null:u;return[function(){return k(h())},S===null?void 0:function(){return k(S())}]},[h,u,f,m]);var v=o(d,g[0],g[1]);return i(function(){b.hasValue=!0,b.value=v},[v]),c(v),v},ta}var pl;function Mm(){return pl||(pl=1,ea.exports=Tm()),ea.exports}var Am=Mm();const Lm=Cf(Am),_m={},gl=e=>{let t;const n=new Set,s=(h,u)=>{const f=typeof h=="function"?h(t):h;if(!Object.is(f,t)){const m=t;t=u??(typeof f!="object"||f===null)?f:Object.assign({},t,f),n.forEach(g=>g(t,m))}},o=()=>t,c={setState:s,getState:o,getInitialState:()=>d,subscribe:h=>(n.add(h),()=>n.delete(h)),destroy:()=>{(_m?"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."),n.clear()}},d=t=e(s,o,c);return c},Rm=e=>e?gl(e):gl,{useDebugValue:Dm}=Ef,{useSyncExternalStoreWithSelector:Om}=Lm,$m=e=>e;function jd(e,t=$m,n){const s=Om(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return Dm(s),s}const xl=(e,t)=>{const n=Rm(e),s=(o,a=t)=>jd(n,o,a);return Object.assign(s,n),s},Pm=(e,t)=>e?xl(e,t):xl;function ft(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[s,o]of e)if(!Object.is(o,t.get(s)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const s of e)if(!t.has(s))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const s of n)if(!Object.prototype.hasOwnProperty.call(t,s)||!Object.is(e[s],t[s]))return!1;return!0}const Co=p.createContext(null),Bm=Co.Provider,Nd=ln.error001();function We(e,t){const n=p.useContext(Co);if(n===null)throw new Error(Nd);return jd(n,e,t)}function ct(){const e=p.useContext(Co);if(e===null)throw new Error(Nd);return p.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const bl={display:"none"},qm={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Sd="react-flow__node-desc",Cd="react-flow__edge-desc",zm="react-flow__aria-live",Fm=e=>e.ariaLiveMessage,Hm=e=>e.ariaLabelConfig;function Vm({rfId:e}){const t=We(Fm);return r.jsx("div",{id:`${zm}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:qm,children:t})}function Wm({rfId:e,disableKeyboardA11y:t}){const n=We(Hm);return r.jsxs(r.Fragment,{children:[r.jsx("div",{id:`${Sd}-${e}`,style:bl,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),r.jsx("div",{id:`${Cd}-${e}`,style:bl,children:n["edge.a11yDescription.default"]}),!t&&r.jsx(Vm,{rfId:e})]})}const Eo=p.forwardRef(({position:e="top-left",children:t,className:n,style:s,...o},a)=>{const i=`${e}`.split("-");return r.jsx("div",{className:kt(["react-flow__panel",n,...i]),style:s,ref:a,...o,children:t})});Eo.displayName="Panel";function Km({proOptions:e,position:t="bottom-right"}){return e?.hideAttribution?null:r.jsx(Eo,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev",children:r.jsx("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const Um=e=>{const t=[],n=[];for(const[,s]of e.nodeLookup)s.selected&&t.push(s.internals.userNode);for(const[,s]of e.edgeLookup)s.selected&&n.push(s);return{selectedNodes:t,selectedEdges:n}},Kr=e=>e.id;function Ym(e,t){return ft(e.selectedNodes.map(Kr),t.selectedNodes.map(Kr))&&ft(e.selectedEdges.map(Kr),t.selectedEdges.map(Kr))}function Gm({onSelectionChange:e}){const t=ct(),{selectedNodes:n,selectedEdges:s}=We(Um,Ym);return p.useEffect(()=>{const o={nodes:n,edges:s};e?.(o),t.getState().onSelectionChangeHandlers.forEach(a=>a(o))},[n,s,e]),null}const Xm=e=>!!e.onSelectionChangeHandlers;function Zm({onSelectionChange:e}){const t=We(Xm);return e||t?r.jsx(Gm,{onSelectionChange:e}):null}const Ed=[0,0],Qm={x:0,y:0,zoom:1},Jm=["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"],yl=[...Jm,"rfId"],ep=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}),wl={translateExtent:cr,nodeOrigin:Ed,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function tp(e){const{setNodes:t,setEdges:n,setMinZoom:s,setMaxZoom:o,setTranslateExtent:a,setNodeExtent:i,reset:l,setDefaultNodesAndEdges:c}=We(ep,ft),d=ct();p.useEffect(()=>(c(e.defaultNodes,e.defaultEdges),()=>{h.current=wl,l()}),[]);const h=p.useRef(wl);return p.useEffect(()=>{for(const u of yl){const f=e[u],m=h.current[u];f!==m&&(typeof e[u]>"u"||(u==="nodes"?t(f):u==="edges"?n(f):u==="minZoom"?s(f):u==="maxZoom"?o(f):u==="translateExtent"?a(f):u==="nodeExtent"?i(f):u==="ariaLabelConfig"?d.setState({ariaLabelConfig:qh(f)}):u==="fitView"?d.setState({fitViewQueued:f}):u==="fitViewOptions"?d.setState({fitViewOptions:f}):d.setState({[u]:f})))}h.current=e},yl.map(u=>e[u])),null}function kl(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function np(e){const[t,n]=p.useState(e==="system"?null:e);return p.useEffect(()=>{if(e!=="system"){n(e);return}const s=kl(),o=()=>n(s?.matches?"dark":"light");return o(),s?.addEventListener("change",o),()=>{s?.removeEventListener("change",o)}},[e]),t!==null?t:kl()?.matches?"dark":"light"}const vl=typeof document<"u"?document:null;function hr(e=null,t={target:vl,actInsideInputWithModifier:!0}){const[n,s]=p.useState(!1),o=p.useRef(!1),a=p.useRef(new Set([])),[i,l]=p.useMemo(()=>{if(e!==null){const d=(Array.isArray(e)?e:[e]).filter(u=>typeof u=="string").map(u=>u.replace("+",`
|
|
2
|
-
`).replace(`
|
|
3
|
-
|
|
4
|
-
`,`
|
|
5
|
-
+`).split(`
|
|
6
|
-
`)),h=d.reduce((u,f)=>u.concat(...f),[]);return[d,h]}return[[],[]]},[e]);return p.useEffect(()=>{const c=t?.target??vl,d=t?.actInsideInputWithModifier??!0;if(e!==null){const h=m=>{if(o.current=m.ctrlKey||m.metaKey||m.shiftKey||m.altKey,(!o.current||o.current&&!d)&&ad(m))return!1;const b=Nl(m.code,l);if(a.current.add(m[b]),jl(i,a.current,!1)){const v=m.composedPath?.()?.[0]||m.target,k=v?.nodeName==="BUTTON"||v?.nodeName==="A";t.preventDefault!==!1&&(o.current||!k)&&m.preventDefault(),s(!0)}},u=m=>{const g=Nl(m.code,l);jl(i,a.current,!0)?(s(!1),a.current.clear()):a.current.delete(m[g]),m.key==="Meta"&&a.current.clear(),o.current=!1},f=()=>{a.current.clear(),s(!1)};return c?.addEventListener("keydown",h),c?.addEventListener("keyup",u),window.addEventListener("blur",f),window.addEventListener("contextmenu",f),()=>{c?.removeEventListener("keydown",h),c?.removeEventListener("keyup",u),window.removeEventListener("blur",f),window.removeEventListener("contextmenu",f)}}},[e,s]),n}function jl(e,t,n){return e.filter(s=>n||s.length===t.size).some(s=>s.every(o=>t.has(o)))}function Nl(e,t){return t.includes(e)?"code":"key"}const sp=()=>{const e=ct();return p.useMemo(()=>({zoomIn:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1.2,{duration:t?.duration}):Promise.resolve(!1)},zoomOut:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,{duration:t?.duration}):Promise.resolve(!1)},zoomTo:(t,n)=>{const{panZoom:s}=e.getState();return s?s.scaleTo(t,{duration:n?.duration}):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{const{transform:[s,o,a],panZoom:i}=e.getState();return i?(await i.setViewport({x:t.x??s,y:t.y??o,zoom:t.zoom??a},n),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[t,n,s]=e.getState().transform;return{x:t,y:n,zoom:s}},setCenter:async(t,n,s)=>e.getState().setCenter(t,n,s),fitBounds:async(t,n)=>{const{width:s,height:o,minZoom:a,maxZoom:i,panZoom:l}=e.getState(),c=$a(t,s,o,a,i,n?.padding??.1);return l?(await l.setViewport(c,{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(t,n={})=>{const{transform:s,snapGrid:o,snapToGrid:a,domNode:i}=e.getState();if(!i)return t;const{x:l,y:c}=i.getBoundingClientRect(),d={x:t.x-l,y:t.y-c},h=n.snapGrid??o,u=n.snapToGrid??a;return wr(d,s,u,h)},flowToScreenPosition:t=>{const{transform:n,domNode:s}=e.getState();if(!s)return t;const{x:o,y:a}=s.getBoundingClientRect(),i=ho(t,n);return{x:i.x+o,y:i.y+a}}}),[])};function Id(e,t){const n=[],s=new Map,o=[];for(const a of e)if(a.type==="add"){o.push(a);continue}else if(a.type==="remove"||a.type==="replace")s.set(a.id,[a]);else{const i=s.get(a.id);i?i.push(a):s.set(a.id,[a])}for(const a of t){const i=s.get(a.id);if(!i){n.push(a);continue}if(i[0].type==="remove")continue;if(i[0].type==="replace"){n.push({...i[0].item});continue}const l={...a};for(const c of i)rp(c,l);n.push(l)}return o.length&&o.forEach(a=>{a.index!==void 0?n.splice(a.index,0,{...a.item}):n.push({...a.item})}),n}function rp(e,t){switch(e.type){case"select":{t.selected=e.selected;break}case"position":{typeof e.position<"u"&&(t.position=e.position),typeof e.dragging<"u"&&(t.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(t.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(t.resizing=e.resizing);break}}}function Td(e,t){return Id(e,t)}function Md(e,t){return Id(e,t)}function Un(e,t){return{id:e,type:"select",selected:t}}function ks(e,t=new Set,n=!1){const s=[];for(const[o,a]of e){const i=t.has(o);!(a.selected===void 0&&!i)&&a.selected!==i&&(n&&(a.selected=i),s.push(Un(a.id,i)))}return s}function Sl({items:e=[],lookup:t}){const n=[],s=new Map(e.map(o=>[o.id,o]));for(const[o,a]of e.entries()){const i=t.get(a.id),l=i?.internals?.userNode??i;l!==void 0&&l!==a&&n.push({id:a.id,item:a,type:"replace"}),l===void 0&&n.push({item:a,type:"add",index:o})}for(const[o]of t)s.get(o)===void 0&&n.push({id:o,type:"remove"});return n}function Cl(e){return{id:e.id,type:"remove"}}const El=e=>Mh(e),op=e=>Qc(e);function Ad(e){return p.forwardRef(e)}const ap=typeof window<"u"?p.useLayoutEffect:p.useEffect;function Il(e){const[t,n]=p.useState(BigInt(0)),[s]=p.useState(()=>ip(()=>n(o=>o+BigInt(1))));return ap(()=>{const o=s.get();o.length&&(e(o),s.reset())},[t]),s}function ip(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const Ld=p.createContext(null);function lp({children:e}){const t=ct(),n=p.useCallback(l=>{const{nodes:c=[],setNodes:d,hasDefaultNodes:h,onNodesChange:u,nodeLookup:f,fitViewQueued:m,onNodesChangeMiddlewareMap:g}=t.getState();let b=c;for(const k of l)b=typeof k=="function"?k(b):k;let v=Sl({items:b,lookup:f});for(const k of g.values())v=k(v);h&&d(b),v.length>0?u?.(v):m&&window.requestAnimationFrame(()=>{const{fitViewQueued:k,nodes:y,setNodes:x}=t.getState();k&&x(y)})},[]),s=Il(n),o=p.useCallback(l=>{const{edges:c=[],setEdges:d,hasDefaultEdges:h,onEdgesChange:u,edgeLookup:f}=t.getState();let m=c;for(const g of l)m=typeof g=="function"?g(m):g;h?d(m):u&&u(Sl({items:m,lookup:f}))},[]),a=Il(o),i=p.useMemo(()=>({nodeQueue:s,edgeQueue:a}),[]);return r.jsx(Ld.Provider,{value:i,children:e})}function cp(){const e=p.useContext(Ld);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const dp=e=>!!e.panZoom;function Va(){const e=sp(),t=ct(),n=cp(),s=We(dp),o=p.useMemo(()=>{const a=u=>t.getState().nodeLookup.get(u),i=u=>{n.nodeQueue.push(u)},l=u=>{n.edgeQueue.push(u)},c=u=>{const{nodeLookup:f,nodeOrigin:m}=t.getState(),g=El(u)?u:f.get(u.id),b=g.parentId?rd(g.position,g.measured,g.parentId,f,m):g.position,v={...g,position:b,width:g.measured?.width??g.width,height:g.measured?.height??g.height};return Ls(v)},d=(u,f,m={replace:!1})=>{i(g=>g.map(b=>{if(b.id===u){const v=typeof f=="function"?f(b):f;return m.replace&&El(v)?v:{...b,...v}}return b}))},h=(u,f,m={replace:!1})=>{l(g=>g.map(b=>{if(b.id===u){const v=typeof f=="function"?f(b):f;return m.replace&&op(v)?v:{...b,...v}}return b}))};return{getNodes:()=>t.getState().nodes.map(u=>({...u})),getNode:u=>a(u)?.internals.userNode,getInternalNode:a,getEdges:()=>{const{edges:u=[]}=t.getState();return u.map(f=>({...f}))},getEdge:u=>t.getState().edgeLookup.get(u),setNodes:i,setEdges:l,addNodes:u=>{const f=Array.isArray(u)?u:[u];n.nodeQueue.push(m=>[...m,...f])},addEdges:u=>{const f=Array.isArray(u)?u:[u];n.edgeQueue.push(m=>[...m,...f])},toObject:()=>{const{nodes:u=[],edges:f=[],transform:m}=t.getState(),[g,b,v]=m;return{nodes:u.map(k=>({...k})),edges:f.map(k=>({...k})),viewport:{x:g,y:b,zoom:v}}},deleteElements:async({nodes:u=[],edges:f=[]})=>{const{nodes:m,edges:g,onNodesDelete:b,onEdgesDelete:v,triggerNodeChanges:k,triggerEdgeChanges:y,onDelete:x,onBeforeDelete:w}=t.getState(),{nodes:S,edges:j}=await Dh({nodesToRemove:u,edgesToRemove:f,nodes:m,edges:g,onBeforeDelete:w}),E=j.length>0,C=S.length>0;if(E){const R=j.map(Cl);v?.(j),y(R)}if(C){const R=S.map(Cl);b?.(S),k(R)}return(C||E)&&x?.({nodes:S,edges:j}),{deletedNodes:S,deletedEdges:j}},getIntersectingNodes:(u,f=!0,m)=>{const g=tl(u),b=g?u:c(u),v=m!==void 0;return b?(m||t.getState().nodes).filter(k=>{const y=t.getState().nodeLookup.get(k.id);if(y&&!g&&(k.id===u.id||!y.internals.positionAbsolute))return!1;const x=Ls(v?k:y),w=ur(x,b);return f&&w>0||w>=x.width*x.height||w>=b.width*b.height}):[]},isNodeIntersecting:(u,f,m=!0)=>{const b=tl(u)?u:c(u);if(!b)return!1;const v=ur(b,f);return m&&v>0||v>=f.width*f.height||v>=b.width*b.height},updateNode:d,updateNodeData:(u,f,m={replace:!1})=>{d(u,g=>{const b=typeof f=="function"?f(g):f;return m.replace?{...g,data:b}:{...g,data:{...g.data,...b}}},m)},updateEdge:h,updateEdgeData:(u,f,m={replace:!1})=>{h(u,g=>{const b=typeof f=="function"?f(g):f;return m.replace?{...g,data:b}:{...g,data:{...g.data,...b}}},m)},getNodesBounds:u=>{const{nodeLookup:f,nodeOrigin:m}=t.getState();return Ah(u,{nodeLookup:f,nodeOrigin:m})},getHandleConnections:({type:u,id:f,nodeId:m})=>Array.from(t.getState().connectionLookup.get(`${m}-${u}${f?`-${f}`:""}`)?.values()??[]),getNodeConnections:({type:u,handleId:f,nodeId:m})=>Array.from(t.getState().connectionLookup.get(`${m}${u?f?`-${u}-${f}`:`-${u}`:""}`)?.values()??[]),fitView:async u=>{const f=t.getState().fitViewResolver??Bh();return t.setState({fitViewQueued:!0,fitViewOptions:u,fitViewResolver:f}),n.nodeQueue.push(m=>[...m]),f.promise}}},[]);return p.useMemo(()=>({...o,...e,viewportInitialized:s}),[s])}const Tl=e=>e.selected,up=typeof window<"u"?window:void 0;function fp({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=ct(),{deleteElements:s}=Va(),o=hr(e,{actInsideInputWithModifier:!1}),a=hr(t,{target:up});p.useEffect(()=>{if(o){const{edges:i,nodes:l}=n.getState();s({nodes:l.filter(Tl),edges:i.filter(Tl)}),n.setState({nodesSelectionActive:!1})}},[o]),p.useEffect(()=>{n.setState({multiSelectionActive:a})},[a])}function hp(e){const t=ct();p.useEffect(()=>{const n=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const s=Pa(e.current);(s.height===0||s.width===0)&&t.getState().onError?.("004",ln.error004()),t.setState({width:s.width||500,height:s.height||500})};if(e.current){n(),window.addEventListener("resize",n);const s=new ResizeObserver(()=>n());return s.observe(e.current),()=>{window.removeEventListener("resize",n),s&&e.current&&s.unobserve(e.current)}}},[])}const Io={position:"absolute",width:"100%",height:"100%",top:0,left:0},mp=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function pp({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:s=!1,panOnScrollSpeed:o=.5,panOnScrollMode:a=Jn.Free,zoomOnDoubleClick:i=!0,panOnDrag:l=!0,defaultViewport:c,translateExtent:d,minZoom:h,maxZoom:u,zoomActivationKeyCode:f,preventScrolling:m=!0,children:g,noWheelClassName:b,noPanClassName:v,onViewportChange:k,isControlledViewport:y,paneClickDistance:x,selectionOnDrag:w}){const S=ct(),j=p.useRef(null),{userSelectionActive:E,lib:C,connectionInProgress:R}=We(mp,ft),P=hr(f),T=p.useRef();hp(j);const D=p.useCallback(z=>{k?.({x:z[0],y:z[1],zoom:z[2]}),y||S.setState({transform:z})},[k,y]);return p.useEffect(()=>{if(j.current){T.current=vm({domNode:j.current,minZoom:h,maxZoom:u,translateExtent:d,viewport:c,onDraggingChange:L=>S.setState(q=>q.paneDragging===L?q:{paneDragging:L}),onPanZoomStart:(L,q)=>{const{onViewportChangeStart:_,onMoveStart:A}=S.getState();A?.(L,q),_?.(q)},onPanZoom:(L,q)=>{const{onViewportChange:_,onMove:A}=S.getState();A?.(L,q),_?.(q)},onPanZoomEnd:(L,q)=>{const{onViewportChangeEnd:_,onMoveEnd:A}=S.getState();A?.(L,q),_?.(q)}});const{x:z,y:I,zoom:B}=T.current.getViewport();return S.setState({panZoom:T.current,transform:[z,I,B],domNode:j.current.closest(".react-flow")}),()=>{T.current?.destroy()}}},[]),p.useEffect(()=>{T.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:s,panOnScrollSpeed:o,panOnScrollMode:a,zoomOnDoubleClick:i,panOnDrag:l,zoomActivationKeyPressed:P,preventScrolling:m,noPanClassName:v,userSelectionActive:E,noWheelClassName:b,lib:C,onTransformChange:D,connectionInProgress:R,selectionOnDrag:w,paneClickDistance:x})},[e,t,n,s,o,a,i,l,P,m,v,E,b,C,D,R,w,x]),r.jsx("div",{className:"react-flow__renderer",ref:j,style:Io,children:g})}const gp=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function xp(){const{userSelectionActive:e,userSelectionRect:t}=We(gp,ft);return e&&t?r.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}const na=(e,t)=>n=>{n.target===t.current&&e?.(n)},bp=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function yp({isSelecting:e,selectionKeyPressed:t,selectionMode:n=dr.Full,panOnDrag:s,paneClickDistance:o,selectionOnDrag:a,onSelectionStart:i,onSelectionEnd:l,onPaneClick:c,onPaneContextMenu:d,onPaneScroll:h,onPaneMouseEnter:u,onPaneMouseMove:f,onPaneMouseLeave:m,children:g}){const b=ct(),{userSelectionActive:v,elementsSelectable:k,dragging:y,connectionInProgress:x}=We(bp,ft),w=k&&(e||v),S=p.useRef(null),j=p.useRef(),E=p.useRef(new Set),C=p.useRef(new Set),R=p.useRef(!1),P=_=>{if(R.current||x){R.current=!1;return}c?.(_),b.getState().resetSelectedElements(),b.setState({nodesSelectionActive:!1})},T=_=>{if(Array.isArray(s)&&s?.includes(2)){_.preventDefault();return}d?.(_)},D=h?_=>h(_):void 0,z=_=>{R.current&&(_.stopPropagation(),R.current=!1)},I=_=>{const{domNode:A}=b.getState();if(j.current=A?.getBoundingClientRect(),!j.current)return;const $=_.target===S.current;if(!$&&!!_.target.closest(".nokey")||!e||!(a&&$||t)||_.button!==0||!_.isPrimary)return;_.target?.setPointerCapture?.(_.pointerId),R.current=!1;const{x:X,y:O}=en(_.nativeEvent,j.current);b.setState({userSelectionRect:{width:0,height:0,startX:X,startY:O,x:X,y:O}}),$||(_.stopPropagation(),_.preventDefault())},B=_=>{const{userSelectionRect:A,transform:$,nodeLookup:F,edgeLookup:V,connectionLookup:X,triggerNodeChanges:O,triggerEdgeChanges:M,defaultEdgeOptions:K,resetSelectedElements:W}=b.getState();if(!j.current||!A)return;const{x:H,y:Z}=en(_.nativeEvent,j.current),{startX:J,startY:le}=A;if(!R.current){const ke=t?0:o;if(Math.hypot(H-J,Z-le)<=ke)return;W(),i?.(_)}R.current=!0;const ue={startX:J,startY:le,x:H<J?H:J,y:Z<le?Z:le,width:Math.abs(H-J),height:Math.abs(Z-le)},pe=E.current,we=C.current;E.current=new Set(Oa(F,ue,$,n===dr.Partial,!0).map(ke=>ke.id)),C.current=new Set;const Ne=K?.selectable??!0;for(const ke of E.current){const Be=X.get(ke);if(Be)for(const{edgeId:et}of Be.values()){const Ee=V.get(et);Ee&&(Ee.selectable??Ne)&&C.current.add(et)}}if(!nl(pe,E.current)){const ke=ks(F,E.current,!0);O(ke)}if(!nl(we,C.current)){const ke=ks(V,C.current);M(ke)}b.setState({userSelectionRect:ue,userSelectionActive:!0,nodesSelectionActive:!1})},L=_=>{_.button===0&&(_.target?.releasePointerCapture?.(_.pointerId),!v&&_.target===S.current&&b.getState().userSelectionRect&&P?.(_),b.setState({userSelectionActive:!1,userSelectionRect:null}),R.current&&(l?.(_),b.setState({nodesSelectionActive:E.current.size>0})))},q=s===!0||Array.isArray(s)&&s.includes(0);return r.jsxs("div",{className:kt(["react-flow__pane",{draggable:q,dragging:y,selection:e}]),onClick:w?void 0:na(P,S),onContextMenu:na(T,S),onWheel:na(D,S),onPointerEnter:w?void 0:u,onPointerMove:w?B:f,onPointerUp:w?L:void 0,onPointerDownCapture:w?I:void 0,onClickCapture:w?z:void 0,onPointerLeave:m,ref:S,style:Io,children:[g,r.jsx(xp,{})]})}function ka({id:e,store:t,unselect:n=!1,nodeRef:s}){const{addSelectedNodes:o,unselectNodesAndEdges:a,multiSelectionActive:i,nodeLookup:l,onError:c}=t.getState(),d=l.get(e);if(!d){c?.("012",ln.error012(e));return}t.setState({nodesSelectionActive:!1}),d.selected?(n||d.selected&&i)&&(a({nodes:[d],edges:[]}),requestAnimationFrame(()=>s?.current?.blur())):o([e])}function _d({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:s,nodeId:o,isSelectable:a,nodeClickDistance:i}){const l=ct(),[c,d]=p.useState(!1),h=p.useRef();return p.useEffect(()=>{h.current=lm({getStoreItems:()=>l.getState(),onNodeMouseDown:u=>{ka({id:u,store:l,nodeRef:e})},onDragStart:()=>{d(!0)},onDragStop:()=>{d(!1)}})},[]),p.useEffect(()=>{if(!(t||!e.current||!h.current))return h.current.update({noDragClassName:n,handleSelector:s,domNode:e.current,isSelectable:a,nodeId:o,nodeClickDistance:i}),()=>{h.current?.destroy()}},[n,s,t,a,e,o,i]),c}const wp=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function Rd(){const e=ct();return p.useCallback(n=>{const{nodeExtent:s,snapToGrid:o,snapGrid:a,nodesDraggable:i,onError:l,updateNodePositions:c,nodeLookup:d,nodeOrigin:h}=e.getState(),u=new Map,f=wp(i),m=o?a[0]:5,g=o?a[1]:5,b=n.direction.x*m*n.factor,v=n.direction.y*g*n.factor;for(const[,k]of d){if(!f(k))continue;let y={x:k.internals.positionAbsolute.x+b,y:k.internals.positionAbsolute.y+v};o&&(y=yr(y,a));const{position:x,positionAbsolute:w}=Jc({nodeId:k.id,nextPosition:y,nodeLookup:d,nodeExtent:s,nodeOrigin:h,onError:l});k.position=x,k.internals.positionAbsolute=w,u.set(k.id,k)}c(u)},[])}const Wa=p.createContext(null),kp=Wa.Provider;Wa.Consumer;const Dd=()=>p.useContext(Wa),vp=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),jp=(e,t,n)=>s=>{const{connectionClickStartHandle:o,connectionMode:a,connection:i}=s,{fromHandle:l,toHandle:c,isValid:d}=i,h=c?.nodeId===e&&c?.id===t&&c?.type===n;return{connectingFrom:l?.nodeId===e&&l?.id===t&&l?.type===n,connectingTo:h,clickConnecting:o?.nodeId===e&&o?.id===t&&o?.type===n,isPossibleEndHandle:a===Ts.Strict?l?.type!==n:e!==l?.nodeId||t!==l?.id,connectionInProcess:!!l,clickConnectionInProcess:!!o,valid:h&&d}};function Np({type:e="source",position:t=ve.Top,isValidConnection:n,isConnectable:s=!0,isConnectableStart:o=!0,isConnectableEnd:a=!0,id:i,onConnect:l,children:c,className:d,onMouseDown:h,onTouchStart:u,...f},m){const g=i||null,b=e==="target",v=ct(),k=Dd(),{connectOnClick:y,noPanClassName:x,rfId:w}=We(vp,ft),{connectingFrom:S,connectingTo:j,clickConnecting:E,isPossibleEndHandle:C,connectionInProcess:R,clickConnectionInProcess:P,valid:T}=We(jp(k,g,e),ft);k||v.getState().onError?.("010",ln.error010());const D=B=>{const{defaultEdgeOptions:L,onConnect:q,hasDefaultEdges:_}=v.getState(),A={...L,...B};if(_){const{edges:$,setEdges:F}=v.getState();F(Kh(A,$))}q?.(A),l?.(A)},z=B=>{if(!k)return;const L=id(B.nativeEvent);if(o&&(L&&B.button===0||!L)){const q=v.getState();wa.onPointerDown(B.nativeEvent,{handleDomNode:B.currentTarget,autoPanOnConnect:q.autoPanOnConnect,connectionMode:q.connectionMode,connectionRadius:q.connectionRadius,domNode:q.domNode,nodeLookup:q.nodeLookup,lib:q.lib,isTarget:b,handleId:g,nodeId:k,flowId:q.rfId,panBy:q.panBy,cancelConnection:q.cancelConnection,onConnectStart:q.onConnectStart,onConnectEnd:(..._)=>v.getState().onConnectEnd?.(..._),updateConnection:q.updateConnection,onConnect:D,isValidConnection:n||((..._)=>v.getState().isValidConnection?.(..._)??!0),getTransform:()=>v.getState().transform,getFromHandle:()=>v.getState().connection.fromHandle,autoPanSpeed:q.autoPanSpeed,dragThreshold:q.connectionDragThreshold})}L?h?.(B):u?.(B)},I=B=>{const{onClickConnectStart:L,onClickConnectEnd:q,connectionClickStartHandle:_,connectionMode:A,isValidConnection:$,lib:F,rfId:V,nodeLookup:X,connection:O}=v.getState();if(!k||!_&&!o)return;if(!_){L?.(B.nativeEvent,{nodeId:k,handleId:g,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:k,type:e,id:g}});return}const M=od(B.target),K=n||$,{connection:W,isValid:H}=wa.isValid(B.nativeEvent,{handle:{nodeId:k,id:g,type:e},connectionMode:A,fromNodeId:_.nodeId,fromHandleId:_.id||null,fromType:_.type,isValidConnection:K,flowId:V,doc:M,lib:F,nodeLookup:X});H&&W&&D(W);const Z=structuredClone(O);delete Z.inProgress,Z.toPosition=Z.toHandle?Z.toHandle.position:null,q?.(B,Z),v.setState({connectionClickStartHandle:null})};return r.jsx("div",{"data-handleid":g,"data-nodeid":k,"data-handlepos":t,"data-id":`${w}-${k}-${g}-${e}`,className:kt(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",x,d,{source:!b,target:b,connectable:s,connectablestart:o,connectableend:a,clickconnecting:E,connectingfrom:S,connectingto:j,valid:T,connectionindicator:s&&(!R||C)&&(R||P?a:o)}]),onMouseDown:z,onTouchStart:z,onClick:y?I:void 0,ref:m,...f,children:c})}const Ln=p.memo(Ad(Np));function Sp({data:e,isConnectable:t,sourcePosition:n=ve.Bottom}){return r.jsxs(r.Fragment,{children:[e?.label,r.jsx(Ln,{type:"source",position:n,isConnectable:t})]})}function Cp({data:e,isConnectable:t,targetPosition:n=ve.Top,sourcePosition:s=ve.Bottom}){return r.jsxs(r.Fragment,{children:[r.jsx(Ln,{type:"target",position:n,isConnectable:t}),e?.label,r.jsx(Ln,{type:"source",position:s,isConnectable:t})]})}function Ep(){return null}function Ip({data:e,isConnectable:t,targetPosition:n=ve.Top}){return r.jsxs(r.Fragment,{children:[r.jsx(Ln,{type:"target",position:n,isConnectable:t}),e?.label]})}const mo={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},Ml={input:Sp,default:Cp,output:Ip,group:Ep};function Tp(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 Mp=e=>{const{width:t,height:n,x:s,y:o}=br(e.nodeLookup,{filter:a=>!!a.selected});return{width:Jt(t)?t:null,height:Jt(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${s}px,${o}px)`}};function Ap({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const s=ct(),{width:o,height:a,transformString:i,userSelectionActive:l}=We(Mp,ft),c=Rd(),d=p.useRef(null);p.useEffect(()=>{n||d.current?.focus({preventScroll:!0})},[n]);const h=!l&&o!==null&&a!==null;if(_d({nodeRef:d,disabled:!h}),!h)return null;const u=e?m=>{const g=s.getState().nodes.filter(b=>b.selected);e(m,g)}:void 0,f=m=>{Object.prototype.hasOwnProperty.call(mo,m.key)&&(m.preventDefault(),c({direction:mo[m.key],factor:m.shiftKey?4:1}))};return r.jsx("div",{className:kt(["react-flow__nodesselection","react-flow__container",t]),style:{transform:i},children:r.jsx("div",{ref:d,className:"react-flow__nodesselection-rect",onContextMenu:u,tabIndex:n?void 0:-1,onKeyDown:n?void 0:f,style:{width:o,height:a}})})}const Al=typeof window<"u"?window:void 0,Lp=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Od({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:s,onPaneMouseLeave:o,onPaneContextMenu:a,onPaneScroll:i,paneClickDistance:l,deleteKeyCode:c,selectionKeyCode:d,selectionOnDrag:h,selectionMode:u,onSelectionStart:f,onSelectionEnd:m,multiSelectionKeyCode:g,panActivationKeyCode:b,zoomActivationKeyCode:v,elementsSelectable:k,zoomOnScroll:y,zoomOnPinch:x,panOnScroll:w,panOnScrollSpeed:S,panOnScrollMode:j,zoomOnDoubleClick:E,panOnDrag:C,defaultViewport:R,translateExtent:P,minZoom:T,maxZoom:D,preventScrolling:z,onSelectionContextMenu:I,noWheelClassName:B,noPanClassName:L,disableKeyboardA11y:q,onViewportChange:_,isControlledViewport:A}){const{nodesSelectionActive:$,userSelectionActive:F}=We(Lp,ft),V=hr(d,{target:Al}),X=hr(b,{target:Al}),O=X||C,M=X||w,K=h&&O!==!0,W=V||F||K;return fp({deleteKeyCode:c,multiSelectionKeyCode:g}),r.jsx(pp,{onPaneContextMenu:a,elementsSelectable:k,zoomOnScroll:y,zoomOnPinch:x,panOnScroll:M,panOnScrollSpeed:S,panOnScrollMode:j,zoomOnDoubleClick:E,panOnDrag:!V&&O,defaultViewport:R,translateExtent:P,minZoom:T,maxZoom:D,zoomActivationKeyCode:v,preventScrolling:z,noWheelClassName:B,noPanClassName:L,onViewportChange:_,isControlledViewport:A,paneClickDistance:l,selectionOnDrag:K,children:r.jsxs(yp,{onSelectionStart:f,onSelectionEnd:m,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:s,onPaneMouseLeave:o,onPaneContextMenu:a,onPaneScroll:i,panOnDrag:O,isSelecting:!!W,selectionMode:u,selectionKeyPressed:V,paneClickDistance:l,selectionOnDrag:K,children:[e,$&&r.jsx(Ap,{onSelectionContextMenu:I,noPanClassName:L,disableKeyboardA11y:q})]})})}Od.displayName="FlowRenderer";const _p=p.memo(Od),Rp=e=>t=>e?Oa(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(n=>n.id):Array.from(t.nodeLookup.keys());function Dp(e){return We(p.useCallback(Rp(e),[e]),ft)}const Op=e=>e.updateNodeInternals;function $p(){const e=We(Op),[t]=p.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const s=new Map;n.forEach(o=>{const a=o.target.getAttribute("data-id");s.set(a,{id:a,nodeElement:o.target,force:!0})}),e(s)}));return p.useEffect(()=>()=>{t?.disconnect()},[t]),t}function Pp({node:e,nodeType:t,hasDimensions:n,resizeObserver:s}){const o=ct(),a=p.useRef(null),i=p.useRef(null),l=p.useRef(e.sourcePosition),c=p.useRef(e.targetPosition),d=p.useRef(t),h=n&&!!e.internals.handleBounds;return p.useEffect(()=>{a.current&&!e.hidden&&(!h||i.current!==a.current)&&(i.current&&s?.unobserve(i.current),s?.observe(a.current),i.current=a.current)},[h,e.hidden]),p.useEffect(()=>()=>{i.current&&(s?.unobserve(i.current),i.current=null)},[]),p.useEffect(()=>{if(a.current){const u=d.current!==t,f=l.current!==e.sourcePosition,m=c.current!==e.targetPosition;(u||f||m)&&(d.current=t,l.current=e.sourcePosition,c.current=e.targetPosition,o.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:a.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),a}function Bp({id:e,onClick:t,onMouseEnter:n,onMouseMove:s,onMouseLeave:o,onContextMenu:a,onDoubleClick:i,nodesDraggable:l,elementsSelectable:c,nodesConnectable:d,nodesFocusable:h,resizeObserver:u,noDragClassName:f,noPanClassName:m,disableKeyboardA11y:g,rfId:b,nodeTypes:v,nodeClickDistance:k,onError:y}){const{node:x,internals:w,isParent:S}=We(H=>{const Z=H.nodeLookup.get(e),J=H.parentLookup.has(e);return{node:Z,internals:Z.internals,isParent:J}},ft);let j=x.type||"default",E=v?.[j]||Ml[j];E===void 0&&(y?.("003",ln.error003(j)),j="default",E=v?.default||Ml.default);const C=!!(x.draggable||l&&typeof x.draggable>"u"),R=!!(x.selectable||c&&typeof x.selectable>"u"),P=!!(x.connectable||d&&typeof x.connectable>"u"),T=!!(x.focusable||h&&typeof x.focusable>"u"),D=ct(),z=sd(x),I=Pp({node:x,nodeType:j,hasDimensions:z,resizeObserver:u}),B=_d({nodeRef:I,disabled:x.hidden||!C,noDragClassName:f,handleSelector:x.dragHandle,nodeId:e,isSelectable:R,nodeClickDistance:k}),L=Rd();if(x.hidden)return null;const q=wn(x),_=Tp(x),A=R||C||t||n||s||o,$=n?H=>n(H,{...w.userNode}):void 0,F=s?H=>s(H,{...w.userNode}):void 0,V=o?H=>o(H,{...w.userNode}):void 0,X=a?H=>a(H,{...w.userNode}):void 0,O=i?H=>i(H,{...w.userNode}):void 0,M=H=>{const{selectNodesOnDrag:Z,nodeDragThreshold:J}=D.getState();R&&(!Z||!C||J>0)&&ka({id:e,store:D,nodeRef:I}),t&&t(H,{...w.userNode})},K=H=>{if(!(ad(H.nativeEvent)||g)){if(Yc.includes(H.key)&&R){const Z=H.key==="Escape";ka({id:e,store:D,unselect:Z,nodeRef:I})}else if(C&&x.selected&&Object.prototype.hasOwnProperty.call(mo,H.key)){H.preventDefault();const{ariaLabelConfig:Z}=D.getState();D.setState({ariaLiveMessage:Z["node.a11yDescription.ariaLiveMessage"]({direction:H.key.replace("Arrow","").toLowerCase(),x:~~w.positionAbsolute.x,y:~~w.positionAbsolute.y})}),L({direction:mo[H.key],factor:H.shiftKey?4:1})}}},W=()=>{if(g||!I.current?.matches(":focus-visible"))return;const{transform:H,width:Z,height:J,autoPanOnNodeFocus:le,setCenter:ue}=D.getState();if(!le)return;Oa(new Map([[e,x]]),{x:0,y:0,width:Z,height:J},H,!0).length>0||ue(x.position.x+q.width/2,x.position.y+q.height/2,{zoom:H[2]})};return r.jsx("div",{className:kt(["react-flow__node",`react-flow__node-${j}`,{[m]:C},x.className,{selected:x.selected,selectable:R,parent:S,draggable:C,dragging:B}]),ref:I,style:{zIndex:w.z,transform:`translate(${w.positionAbsolute.x}px,${w.positionAbsolute.y}px)`,pointerEvents:A?"all":"none",visibility:z?"visible":"hidden",...x.style,..._},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:$,onMouseMove:F,onMouseLeave:V,onContextMenu:X,onClick:M,onDoubleClick:O,onKeyDown:T?K:void 0,tabIndex:T?0:void 0,onFocus:T?W:void 0,role:x.ariaRole??(T?"group":void 0),"aria-roledescription":"node","aria-describedby":g?void 0:`${Sd}-${b}`,"aria-label":x.ariaLabel,...x.domAttributes,children:r.jsx(kp,{value:e,children:r.jsx(E,{id:e,data:x.data,type:j,positionAbsoluteX:w.positionAbsolute.x,positionAbsoluteY:w.positionAbsolute.y,selected:x.selected??!1,selectable:R,draggable:C,deletable:x.deletable??!0,isConnectable:P,sourcePosition:x.sourcePosition,targetPosition:x.targetPosition,dragging:B,dragHandle:x.dragHandle,zIndex:w.z,parentId:x.parentId,...q})})})}var qp=p.memo(Bp);const zp=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function $d(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:s,elementsSelectable:o,onError:a}=We(zp,ft),i=Dp(e.onlyRenderVisibleElements),l=$p();return r.jsx("div",{className:"react-flow__nodes",style:Io,children:i.map(c=>r.jsx(qp,{id:c,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:l,nodesDraggable:t,nodesConnectable:n,nodesFocusable:s,elementsSelectable:o,nodeClickDistance:e.nodeClickDistance,onError:a},c))})}$d.displayName="NodeRenderer";const Fp=p.memo($d);function Hp(e){return We(p.useCallback(n=>{if(!e)return n.edges.map(o=>o.id);const s=[];if(n.width&&n.height)for(const o of n.edges){const a=n.nodeLookup.get(o.source),i=n.nodeLookup.get(o.target);a&&i&&Hh({sourceNode:a,targetNode:i,width:n.width,height:n.height,transform:n.transform})&&s.push(o.id)}return s},[e]),ft)}const Vp=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return r.jsx("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},Wp=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return r.jsx("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},Ll={[Ms.Arrow]:Vp,[Ms.ArrowClosed]:Wp};function Kp(e){const t=ct();return p.useMemo(()=>Object.prototype.hasOwnProperty.call(Ll,e)?Ll[e]:(t.getState().onError?.("009",ln.error009(e)),null),[e])}const Up=({id:e,type:t,color:n,width:s=12.5,height:o=12.5,markerUnits:a="strokeWidth",strokeWidth:i,orient:l="auto-start-reverse"})=>{const c=Kp(t);return c?r.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${s}`,markerHeight:`${o}`,viewBox:"-10 -10 20 20",markerUnits:a,orient:l,refX:"0",refY:"0",children:r.jsx(c,{color:n,strokeWidth:i})}):null},Pd=({defaultColor:e,rfId:t})=>{const n=We(a=>a.edges),s=We(a=>a.defaultEdgeOptions),o=p.useMemo(()=>Zh(n,{id:t,defaultColor:e,defaultMarkerStart:s?.markerStart,defaultMarkerEnd:s?.markerEnd}),[n,s,t,e]);return o.length?r.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:r.jsx("defs",{children:o.map(a=>r.jsx(Up,{id:a.id,type:a.type,color:a.color,width:a.width,height:a.height,markerUnits:a.markerUnits,strokeWidth:a.strokeWidth,orient:a.orient},a.id))})}):null};Pd.displayName="MarkerDefinitions";var Yp=p.memo(Pd);function Bd({x:e,y:t,label:n,labelStyle:s,labelShowBg:o=!0,labelBgStyle:a,labelBgPadding:i=[2,4],labelBgBorderRadius:l=2,children:c,className:d,...h}){const[u,f]=p.useState({x:1,y:0,width:0,height:0}),m=kt(["react-flow__edge-textwrapper",d]),g=p.useRef(null);return p.useEffect(()=>{if(g.current){const b=g.current.getBBox();f({x:b.x,y:b.y,width:b.width,height:b.height})}},[n]),n?r.jsxs("g",{transform:`translate(${e-u.width/2} ${t-u.height/2})`,className:m,visibility:u.width?"visible":"hidden",...h,children:[o&&r.jsx("rect",{width:u.width+2*i[0],x:-i[0],y:-i[1],height:u.height+2*i[1],className:"react-flow__edge-textbg",style:a,rx:l,ry:l}),r.jsx("text",{className:"react-flow__edge-text",y:u.height/2,dy:"0.3em",ref:g,style:s,children:n}),c]}):null}Bd.displayName="EdgeText";const Gp=p.memo(Bd);function To({path:e,labelX:t,labelY:n,label:s,labelStyle:o,labelShowBg:a,labelBgStyle:i,labelBgPadding:l,labelBgBorderRadius:c,interactionWidth:d=20,...h}){return r.jsxs(r.Fragment,{children:[r.jsx("path",{...h,d:e,fill:"none",className:kt(["react-flow__edge-path",h.className])}),d?r.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:d,className:"react-flow__edge-interaction"}):null,s&&Jt(t)&&Jt(n)?r.jsx(Gp,{x:t,y:n,label:s,labelStyle:o,labelShowBg:a,labelBgStyle:i,labelBgPadding:l,labelBgBorderRadius:c}):null]})}function _l({pos:e,x1:t,y1:n,x2:s,y2:o}){return e===ve.Left||e===ve.Right?[.5*(t+s),n]:[t,.5*(n+o)]}function qd({sourceX:e,sourceY:t,sourcePosition:n=ve.Bottom,targetX:s,targetY:o,targetPosition:a=ve.Top}){const[i,l]=_l({pos:n,x1:e,y1:t,x2:s,y2:o}),[c,d]=_l({pos:a,x1:s,y1:o,x2:e,y2:t}),[h,u,f,m]=ld({sourceX:e,sourceY:t,targetX:s,targetY:o,sourceControlX:i,sourceControlY:l,targetControlX:c,targetControlY:d});return[`M${e},${t} C${i},${l} ${c},${d} ${s},${o}`,h,u,f,m]}function zd(e){return p.memo(({id:t,sourceX:n,sourceY:s,targetX:o,targetY:a,sourcePosition:i,targetPosition:l,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:v,interactionWidth:k})=>{const[y,x,w]=qd({sourceX:n,sourceY:s,sourcePosition:i,targetX:o,targetY:a,targetPosition:l}),S=e.isInternal?void 0:t;return r.jsx(To,{id:S,path:y,labelX:x,labelY:w,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:v,interactionWidth:k})})}const Xp=zd({isInternal:!1}),Fd=zd({isInternal:!0});Xp.displayName="SimpleBezierEdge";Fd.displayName="SimpleBezierEdgeInternal";function Hd(e){return p.memo(({id:t,sourceX:n,sourceY:s,targetX:o,targetY:a,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:u,style:f,sourcePosition:m=ve.Bottom,targetPosition:g=ve.Top,markerEnd:b,markerStart:v,pathOptions:k,interactionWidth:y})=>{const[x,w,S]=xa({sourceX:n,sourceY:s,sourcePosition:m,targetX:o,targetY:a,targetPosition:g,borderRadius:k?.borderRadius,offset:k?.offset,stepPosition:k?.stepPosition}),j=e.isInternal?void 0:t;return r.jsx(To,{id:j,path:x,labelX:w,labelY:S,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:u,style:f,markerEnd:b,markerStart:v,interactionWidth:y})})}const Vd=Hd({isInternal:!1}),Wd=Hd({isInternal:!0});Vd.displayName="SmoothStepEdge";Wd.displayName="SmoothStepEdgeInternal";function Kd(e){return p.memo(({id:t,...n})=>{const s=e.isInternal?void 0:t;return r.jsx(Vd,{...n,id:s,pathOptions:p.useMemo(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}const Zp=Kd({isInternal:!1}),Ud=Kd({isInternal:!0});Zp.displayName="StepEdge";Ud.displayName="StepEdgeInternal";function Yd(e){return p.memo(({id:t,sourceX:n,sourceY:s,targetX:o,targetY:a,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:u,style:f,markerEnd:m,markerStart:g,interactionWidth:b})=>{const[v,k,y]=ud({sourceX:n,sourceY:s,targetX:o,targetY:a}),x=e.isInternal?void 0:t;return r.jsx(To,{id:x,path:v,labelX:k,labelY:y,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:u,style:f,markerEnd:m,markerStart:g,interactionWidth:b})})}const Qp=Yd({isInternal:!1}),Gd=Yd({isInternal:!0});Qp.displayName="StraightEdge";Gd.displayName="StraightEdgeInternal";function Xd(e){return p.memo(({id:t,sourceX:n,sourceY:s,targetX:o,targetY:a,sourcePosition:i=ve.Bottom,targetPosition:l=ve.Top,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:v,pathOptions:k,interactionWidth:y})=>{const[x,w,S]=cd({sourceX:n,sourceY:s,sourcePosition:i,targetX:o,targetY:a,targetPosition:l,curvature:k?.curvature}),j=e.isInternal?void 0:t;return r.jsx(To,{id:j,path:x,labelX:w,labelY:S,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:v,interactionWidth:y})})}const Jp=Xd({isInternal:!1}),Zd=Xd({isInternal:!0});Jp.displayName="BezierEdge";Zd.displayName="BezierEdgeInternal";const Rl={default:Zd,straight:Gd,step:Ud,smoothstep:Wd,simplebezier:Fd},Dl={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},eg=(e,t,n)=>n===ve.Left?e-t:n===ve.Right?e+t:e,tg=(e,t,n)=>n===ve.Top?e-t:n===ve.Bottom?e+t:e,Ol="react-flow__edgeupdater";function $l({position:e,centerX:t,centerY:n,radius:s=10,onMouseDown:o,onMouseEnter:a,onMouseOut:i,type:l}){return r.jsx("circle",{onMouseDown:o,onMouseEnter:a,onMouseOut:i,className:kt([Ol,`${Ol}-${l}`]),cx:eg(t,s,e),cy:tg(n,s,e),r:s,stroke:"transparent",fill:"transparent"})}function ng({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:s,sourceY:o,targetX:a,targetY:i,sourcePosition:l,targetPosition:c,onReconnect:d,onReconnectStart:h,onReconnectEnd:u,setReconnecting:f,setUpdateHover:m}){const g=ct(),b=(w,S)=>{if(w.button!==0)return;const{autoPanOnConnect:j,domNode:E,connectionMode:C,connectionRadius:R,lib:P,onConnectStart:T,cancelConnection:D,nodeLookup:z,rfId:I,panBy:B,updateConnection:L}=g.getState(),q=S.type==="target",_=(F,V)=>{f(!1),u?.(F,n,S.type,V)},A=F=>d?.(n,F),$=(F,V)=>{f(!0),h?.(w,n,S.type),T?.(F,V)};wa.onPointerDown(w.nativeEvent,{autoPanOnConnect:j,connectionMode:C,connectionRadius:R,domNode:E,handleId:S.id,nodeId:S.nodeId,nodeLookup:z,isTarget:q,edgeUpdaterType:S.type,lib:P,flowId:I,cancelConnection:D,panBy:B,isValidConnection:(...F)=>g.getState().isValidConnection?.(...F)??!0,onConnect:A,onConnectStart:$,onConnectEnd:(...F)=>g.getState().onConnectEnd?.(...F),onReconnectEnd:_,updateConnection:L,getTransform:()=>g.getState().transform,getFromHandle:()=>g.getState().connection.fromHandle,dragThreshold:g.getState().connectionDragThreshold,handleDomNode:w.currentTarget})},v=w=>b(w,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),k=w=>b(w,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),y=()=>m(!0),x=()=>m(!1);return r.jsxs(r.Fragment,{children:[(e===!0||e==="source")&&r.jsx($l,{position:l,centerX:s,centerY:o,radius:t,onMouseDown:v,onMouseEnter:y,onMouseOut:x,type:"source"}),(e===!0||e==="target")&&r.jsx($l,{position:c,centerX:a,centerY:i,radius:t,onMouseDown:k,onMouseEnter:y,onMouseOut:x,type:"target"})]})}function sg({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:s,onClick:o,onDoubleClick:a,onContextMenu:i,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,reconnectRadius:h,onReconnect:u,onReconnectStart:f,onReconnectEnd:m,rfId:g,edgeTypes:b,noPanClassName:v,onError:k,disableKeyboardA11y:y}){let x=We(ue=>ue.edgeLookup.get(e));const w=We(ue=>ue.defaultEdgeOptions);x=w?{...w,...x}:x;let S=x.type||"default",j=b?.[S]||Rl[S];j===void 0&&(k?.("011",ln.error011(S)),S="default",j=b?.default||Rl.default);const E=!!(x.focusable||t&&typeof x.focusable>"u"),C=typeof u<"u"&&(x.reconnectable||n&&typeof x.reconnectable>"u"),R=!!(x.selectable||s&&typeof x.selectable>"u"),P=p.useRef(null),[T,D]=p.useState(!1),[z,I]=p.useState(!1),B=ct(),{zIndex:L,sourceX:q,sourceY:_,targetX:A,targetY:$,sourcePosition:F,targetPosition:V}=We(p.useCallback(ue=>{const pe=ue.nodeLookup.get(x.source),we=ue.nodeLookup.get(x.target);if(!pe||!we)return{zIndex:x.zIndex,...Dl};const Ne=Xh({id:e,sourceNode:pe,targetNode:we,sourceHandle:x.sourceHandle||null,targetHandle:x.targetHandle||null,connectionMode:ue.connectionMode,onError:k});return{zIndex:Fh({selected:x.selected,zIndex:x.zIndex,sourceNode:pe,targetNode:we,elevateOnSelect:ue.elevateEdgesOnSelect,zIndexMode:ue.zIndexMode}),...Ne||Dl}},[x.source,x.target,x.sourceHandle,x.targetHandle,x.selected,x.zIndex]),ft),X=p.useMemo(()=>x.markerStart?`url('#${ba(x.markerStart,g)}')`:void 0,[x.markerStart,g]),O=p.useMemo(()=>x.markerEnd?`url('#${ba(x.markerEnd,g)}')`:void 0,[x.markerEnd,g]);if(x.hidden||q===null||_===null||A===null||$===null)return null;const M=ue=>{const{addSelectedEdges:pe,unselectNodesAndEdges:we,multiSelectionActive:Ne}=B.getState();R&&(B.setState({nodesSelectionActive:!1}),x.selected&&Ne?(we({nodes:[],edges:[x]}),P.current?.blur()):pe([e])),o&&o(ue,x)},K=a?ue=>{a(ue,{...x})}:void 0,W=i?ue=>{i(ue,{...x})}:void 0,H=l?ue=>{l(ue,{...x})}:void 0,Z=c?ue=>{c(ue,{...x})}:void 0,J=d?ue=>{d(ue,{...x})}:void 0,le=ue=>{if(!y&&Yc.includes(ue.key)&&R){const{unselectNodesAndEdges:pe,addSelectedEdges:we}=B.getState();ue.key==="Escape"?(P.current?.blur(),pe({edges:[x]})):we([e])}};return r.jsx("svg",{style:{zIndex:L},children:r.jsxs("g",{className:kt(["react-flow__edge",`react-flow__edge-${S}`,x.className,v,{selected:x.selected,animated:x.animated,inactive:!R&&!o,updating:T,selectable:R}]),onClick:M,onDoubleClick:K,onContextMenu:W,onMouseEnter:H,onMouseMove:Z,onMouseLeave:J,onKeyDown:E?le:void 0,tabIndex:E?0:void 0,role:x.ariaRole??(E?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":x.ariaLabel===null?void 0:x.ariaLabel||`Edge from ${x.source} to ${x.target}`,"aria-describedby":E?`${Cd}-${g}`:void 0,ref:P,...x.domAttributes,children:[!z&&r.jsx(j,{id:e,source:x.source,target:x.target,type:x.type,selected:x.selected,animated:x.animated,selectable:R,deletable:x.deletable??!0,label:x.label,labelStyle:x.labelStyle,labelShowBg:x.labelShowBg,labelBgStyle:x.labelBgStyle,labelBgPadding:x.labelBgPadding,labelBgBorderRadius:x.labelBgBorderRadius,sourceX:q,sourceY:_,targetX:A,targetY:$,sourcePosition:F,targetPosition:V,data:x.data,style:x.style,sourceHandleId:x.sourceHandle,targetHandleId:x.targetHandle,markerStart:X,markerEnd:O,pathOptions:"pathOptions"in x?x.pathOptions:void 0,interactionWidth:x.interactionWidth}),C&&r.jsx(ng,{edge:x,isReconnectable:C,reconnectRadius:h,onReconnect:u,onReconnectStart:f,onReconnectEnd:m,sourceX:q,sourceY:_,targetX:A,targetY:$,sourcePosition:F,targetPosition:V,setUpdateHover:D,setReconnecting:I})]})})}var rg=p.memo(sg);const og=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function Qd({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:s,noPanClassName:o,onReconnect:a,onEdgeContextMenu:i,onEdgeMouseEnter:l,onEdgeMouseMove:c,onEdgeMouseLeave:d,onEdgeClick:h,reconnectRadius:u,onEdgeDoubleClick:f,onReconnectStart:m,onReconnectEnd:g,disableKeyboardA11y:b}){const{edgesFocusable:v,edgesReconnectable:k,elementsSelectable:y,onError:x}=We(og,ft),w=Hp(t);return r.jsxs("div",{className:"react-flow__edges",children:[r.jsx(Yp,{defaultColor:e,rfId:n}),w.map(S=>r.jsx(rg,{id:S,edgesFocusable:v,edgesReconnectable:k,elementsSelectable:y,noPanClassName:o,onReconnect:a,onContextMenu:i,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,onClick:h,reconnectRadius:u,onDoubleClick:f,onReconnectStart:m,onReconnectEnd:g,rfId:n,onError:x,edgeTypes:s,disableKeyboardA11y:b},S))]})}Qd.displayName="EdgeRenderer";const ag=p.memo(Qd),ig=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function lg({children:e}){const t=We(ig);return r.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function cg(e){const t=Va(),n=p.useRef(!1);p.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const dg=e=>e.panZoom?.syncViewport;function ug(e){const t=We(dg),n=ct();return p.useEffect(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function fg(e){return e.connection.inProgress?{...e.connection,to:wr(e.connection.to,e.transform)}:{...e.connection}}function hg(e){return fg}function mg(e){const t=hg();return We(t,ft)}const pg=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function gg({containerStyle:e,style:t,type:n,component:s}){const{nodesConnectable:o,width:a,height:i,isValid:l,inProgress:c}=We(pg,ft);return!(a&&o&&c)?null:r.jsx("svg",{style:e,width:a,height:i,className:"react-flow__connectionline react-flow__container",children:r.jsx("g",{className:kt(["react-flow__connection",Zc(l)]),children:r.jsx(Jd,{style:t,type:n,CustomComponent:s,isValid:l})})})}const Jd=({style:e,type:t=In.Bezier,CustomComponent:n,isValid:s})=>{const{inProgress:o,from:a,fromNode:i,fromHandle:l,fromPosition:c,to:d,toNode:h,toHandle:u,toPosition:f,pointer:m}=mg();if(!o)return;if(n)return r.jsx(n,{connectionLineType:t,connectionLineStyle:e,fromNode:i,fromHandle:l,fromX:a.x,fromY:a.y,toX:d.x,toY:d.y,fromPosition:c,toPosition:f,connectionStatus:Zc(s),toNode:h,toHandle:u,pointer:m});let g="";const b={sourceX:a.x,sourceY:a.y,sourcePosition:c,targetX:d.x,targetY:d.y,targetPosition:f};switch(t){case In.Bezier:[g]=cd(b);break;case In.SimpleBezier:[g]=qd(b);break;case In.Step:[g]=xa({...b,borderRadius:0});break;case In.SmoothStep:[g]=xa(b);break;default:[g]=ud(b)}return r.jsx("path",{d:g,fill:"none",className:"react-flow__connection-path",style:e})};Jd.displayName="ConnectionLine";const xg={};function Pl(e=xg){p.useRef(e),ct(),p.useEffect(()=>{},[e])}function bg(){ct(),p.useRef(!1),p.useEffect(()=>{},[])}function eu({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:s,onEdgeClick:o,onNodeDoubleClick:a,onEdgeDoubleClick:i,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:h,onSelectionContextMenu:u,onSelectionStart:f,onSelectionEnd:m,connectionLineType:g,connectionLineStyle:b,connectionLineComponent:v,connectionLineContainerStyle:k,selectionKeyCode:y,selectionOnDrag:x,selectionMode:w,multiSelectionKeyCode:S,panActivationKeyCode:j,zoomActivationKeyCode:E,deleteKeyCode:C,onlyRenderVisibleElements:R,elementsSelectable:P,defaultViewport:T,translateExtent:D,minZoom:z,maxZoom:I,preventScrolling:B,defaultMarkerColor:L,zoomOnScroll:q,zoomOnPinch:_,panOnScroll:A,panOnScrollSpeed:$,panOnScrollMode:F,zoomOnDoubleClick:V,panOnDrag:X,onPaneClick:O,onPaneMouseEnter:M,onPaneMouseMove:K,onPaneMouseLeave:W,onPaneScroll:H,onPaneContextMenu:Z,paneClickDistance:J,nodeClickDistance:le,onEdgeContextMenu:ue,onEdgeMouseEnter:pe,onEdgeMouseMove:we,onEdgeMouseLeave:Ne,reconnectRadius:ke,onReconnect:Be,onReconnectStart:et,onReconnectEnd:Ee,noDragClassName:Ke,noWheelClassName:ot,noPanClassName:_e,disableKeyboardA11y:re,nodeExtent:he,rfId:ge,viewport:ee,onViewportChange:ne}){return Pl(e),Pl(t),bg(),cg(n),ug(ee),r.jsx(_p,{onPaneClick:O,onPaneMouseEnter:M,onPaneMouseMove:K,onPaneMouseLeave:W,onPaneContextMenu:Z,onPaneScroll:H,paneClickDistance:J,deleteKeyCode:C,selectionKeyCode:y,selectionOnDrag:x,selectionMode:w,onSelectionStart:f,onSelectionEnd:m,multiSelectionKeyCode:S,panActivationKeyCode:j,zoomActivationKeyCode:E,elementsSelectable:P,zoomOnScroll:q,zoomOnPinch:_,zoomOnDoubleClick:V,panOnScroll:A,panOnScrollSpeed:$,panOnScrollMode:F,panOnDrag:X,defaultViewport:T,translateExtent:D,minZoom:z,maxZoom:I,onSelectionContextMenu:u,preventScrolling:B,noDragClassName:Ke,noWheelClassName:ot,noPanClassName:_e,disableKeyboardA11y:re,onViewportChange:ne,isControlledViewport:!!ee,children:r.jsxs(lg,{children:[r.jsx(ag,{edgeTypes:t,onEdgeClick:o,onEdgeDoubleClick:i,onReconnect:Be,onReconnectStart:et,onReconnectEnd:Ee,onlyRenderVisibleElements:R,onEdgeContextMenu:ue,onEdgeMouseEnter:pe,onEdgeMouseMove:we,onEdgeMouseLeave:Ne,reconnectRadius:ke,defaultMarkerColor:L,noPanClassName:_e,disableKeyboardA11y:re,rfId:ge}),r.jsx(gg,{style:b,type:g,component:v,containerStyle:k}),r.jsx("div",{className:"react-flow__edgelabel-renderer"}),r.jsx(Fp,{nodeTypes:e,onNodeClick:s,onNodeDoubleClick:a,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:h,nodeClickDistance:le,onlyRenderVisibleElements:R,noPanClassName:_e,noDragClassName:Ke,disableKeyboardA11y:re,nodeExtent:he,rfId:ge}),r.jsx("div",{className:"react-flow__viewport-portal"})]})})}eu.displayName="GraphView";const yg=p.memo(eu),Bl=({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,width:o,height:a,fitView:i,fitViewOptions:l,minZoom:c=.5,maxZoom:d=2,nodeOrigin:h,nodeExtent:u,zIndexMode:f="basic"}={})=>{const m=new Map,g=new Map,b=new Map,v=new Map,k=s??t??[],y=n??e??[],x=h??[0,0],w=u??cr;md(b,v,k);const S=ya(y,m,g,{nodeOrigin:x,nodeExtent:w,zIndexMode:f});let j=[0,0,1];if(i&&o&&a){const E=br(m,{filter:T=>!!((T.width||T.initialWidth)&&(T.height||T.initialHeight))}),{x:C,y:R,zoom:P}=$a(E,o,a,c,d,l?.padding??.1);j=[C,R,P]}return{rfId:"1",width:o??0,height:a??0,transform:j,nodes:y,nodesInitialized:S,nodeLookup:m,parentLookup:g,edges:k,edgeLookup:v,connectionLookup:b,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:s!==void 0,panZoom:null,minZoom:c,maxZoom:d,translateExtent:cr,nodeExtent:w,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Ts.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:x,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:i??!1,fitViewOptions:l,fitViewResolver:null,connection:{...Xc},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:Oh,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:Gc,zIndexMode:f,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},wg=({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,width:o,height:a,fitView:i,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:h,nodeExtent:u,zIndexMode:f})=>Pm((m,g)=>{async function b(){const{nodeLookup:v,panZoom:k,fitViewOptions:y,fitViewResolver:x,width:w,height:S,minZoom:j,maxZoom:E}=g();k&&(await Rh({nodes:v,width:w,height:S,panZoom:k,minZoom:j,maxZoom:E},y),x?.resolve(!0),m({fitViewResolver:null}))}return{...Bl({nodes:e,edges:t,width:o,height:a,fitView:i,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:h,nodeExtent:u,defaultNodes:n,defaultEdges:s,zIndexMode:f}),setNodes:v=>{const{nodeLookup:k,parentLookup:y,nodeOrigin:x,elevateNodesOnSelect:w,fitViewQueued:S,zIndexMode:j}=g(),E=ya(v,k,y,{nodeOrigin:x,nodeExtent:u,elevateNodesOnSelect:w,checkEquality:!0,zIndexMode:j});S&&E?(b(),m({nodes:v,nodesInitialized:E,fitViewQueued:!1,fitViewOptions:void 0})):m({nodes:v,nodesInitialized:E})},setEdges:v=>{const{connectionLookup:k,edgeLookup:y}=g();md(k,y,v),m({edges:v})},setDefaultNodesAndEdges:(v,k)=>{if(v){const{setNodes:y}=g();y(v),m({hasDefaultNodes:!0})}if(k){const{setEdges:y}=g();y(k),m({hasDefaultEdges:!0})}},updateNodeInternals:v=>{const{triggerNodeChanges:k,nodeLookup:y,parentLookup:x,domNode:w,nodeOrigin:S,nodeExtent:j,debug:E,fitViewQueued:C,zIndexMode:R}=g(),{changes:P,updatedInternals:T}=rm(v,y,x,w,S,j,R);T&&(em(y,x,{nodeOrigin:S,nodeExtent:j,zIndexMode:R}),C?(b(),m({fitViewQueued:!1,fitViewOptions:void 0})):m({}),P?.length>0&&(E&&console.log("React Flow: trigger node changes",P),k?.(P)))},updateNodePositions:(v,k=!1)=>{const y=[];let x=[];const{nodeLookup:w,triggerNodeChanges:S,connection:j,updateConnection:E,onNodesChangeMiddlewareMap:C}=g();for(const[R,P]of v){const T=w.get(R),D=!!(T?.expandParent&&T?.parentId&&P?.position),z={id:R,type:"position",position:D?{x:Math.max(0,P.position.x),y:Math.max(0,P.position.y)}:P.position,dragging:k};if(T&&j.inProgress&&j.fromNode.id===T.id){const I=ts(T,j.fromHandle,ve.Left,!0);E({...j,from:I})}D&&T.parentId&&y.push({id:R,parentId:T.parentId,rect:{...P.internals.positionAbsolute,width:P.measured.width??0,height:P.measured.height??0}}),x.push(z)}if(y.length>0){const{parentLookup:R,nodeOrigin:P}=g(),T=Ha(y,w,R,P);x.push(...T)}for(const R of C.values())x=R(x);S(x)},triggerNodeChanges:v=>{const{onNodesChange:k,setNodes:y,nodes:x,hasDefaultNodes:w,debug:S}=g();if(v?.length){if(w){const j=Td(v,x);y(j)}S&&console.log("React Flow: trigger node changes",v),k?.(v)}},triggerEdgeChanges:v=>{const{onEdgesChange:k,setEdges:y,edges:x,hasDefaultEdges:w,debug:S}=g();if(v?.length){if(w){const j=Md(v,x);y(j)}S&&console.log("React Flow: trigger edge changes",v),k?.(v)}},addSelectedNodes:v=>{const{multiSelectionActive:k,edgeLookup:y,nodeLookup:x,triggerNodeChanges:w,triggerEdgeChanges:S}=g();if(k){const j=v.map(E=>Un(E,!0));w(j);return}w(ks(x,new Set([...v]),!0)),S(ks(y))},addSelectedEdges:v=>{const{multiSelectionActive:k,edgeLookup:y,nodeLookup:x,triggerNodeChanges:w,triggerEdgeChanges:S}=g();if(k){const j=v.map(E=>Un(E,!0));S(j);return}S(ks(y,new Set([...v]))),w(ks(x,new Set,!0))},unselectNodesAndEdges:({nodes:v,edges:k}={})=>{const{edges:y,nodes:x,nodeLookup:w,triggerNodeChanges:S,triggerEdgeChanges:j}=g(),E=v||x,C=k||y,R=[];for(const T of E){if(!T.selected)continue;const D=w.get(T.id);D&&(D.selected=!1),R.push(Un(T.id,!1))}const P=[];for(const T of C)T.selected&&P.push(Un(T.id,!1));S(R),j(P)},setMinZoom:v=>{const{panZoom:k,maxZoom:y}=g();k?.setScaleExtent([v,y]),m({minZoom:v})},setMaxZoom:v=>{const{panZoom:k,minZoom:y}=g();k?.setScaleExtent([y,v]),m({maxZoom:v})},setTranslateExtent:v=>{g().panZoom?.setTranslateExtent(v),m({translateExtent:v})},resetSelectedElements:()=>{const{edges:v,nodes:k,triggerNodeChanges:y,triggerEdgeChanges:x,elementsSelectable:w}=g();if(!w)return;const S=k.reduce((E,C)=>C.selected?[...E,Un(C.id,!1)]:E,[]),j=v.reduce((E,C)=>C.selected?[...E,Un(C.id,!1)]:E,[]);y(S),x(j)},setNodeExtent:v=>{const{nodes:k,nodeLookup:y,parentLookup:x,nodeOrigin:w,elevateNodesOnSelect:S,nodeExtent:j,zIndexMode:E}=g();v[0][0]===j[0][0]&&v[0][1]===j[0][1]&&v[1][0]===j[1][0]&&v[1][1]===j[1][1]||(ya(k,y,x,{nodeOrigin:w,nodeExtent:v,elevateNodesOnSelect:S,checkEquality:!1,zIndexMode:E}),m({nodeExtent:v}))},panBy:v=>{const{transform:k,width:y,height:x,panZoom:w,translateExtent:S}=g();return om({delta:v,panZoom:w,transform:k,translateExtent:S,width:y,height:x})},setCenter:async(v,k,y)=>{const{width:x,height:w,maxZoom:S,panZoom:j}=g();if(!j)return Promise.resolve(!1);const E=typeof y?.zoom<"u"?y.zoom:S;return await j.setViewport({x:x/2-v*E,y:w/2-k*E,zoom:E},{duration:y?.duration,ease:y?.ease,interpolate:y?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{m({connection:{...Xc}})},updateConnection:v=>{m({connection:v})},reset:()=>m({...Bl()})}},Object.is);function kg({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:s,initialWidth:o,initialHeight:a,initialMinZoom:i,initialMaxZoom:l,initialFitViewOptions:c,fitView:d,nodeOrigin:h,nodeExtent:u,zIndexMode:f,children:m}){const[g]=p.useState(()=>wg({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,width:o,height:a,fitView:d,minZoom:i,maxZoom:l,fitViewOptions:c,nodeOrigin:h,nodeExtent:u,zIndexMode:f}));return r.jsx(Bm,{value:g,children:r.jsx(lp,{children:m})})}function vg({children:e,nodes:t,edges:n,defaultNodes:s,defaultEdges:o,width:a,height:i,fitView:l,fitViewOptions:c,minZoom:d,maxZoom:h,nodeOrigin:u,nodeExtent:f,zIndexMode:m}){return p.useContext(Co)?r.jsx(r.Fragment,{children:e}):r.jsx(kg,{initialNodes:t,initialEdges:n,defaultNodes:s,defaultEdges:o,initialWidth:a,initialHeight:i,fitView:l,initialFitViewOptions:c,initialMinZoom:d,initialMaxZoom:h,nodeOrigin:u,nodeExtent:f,zIndexMode:m,children:e})}const jg={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function Ng({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,className:o,nodeTypes:a,edgeTypes:i,onNodeClick:l,onEdgeClick:c,onInit:d,onMove:h,onMoveStart:u,onMoveEnd:f,onConnect:m,onConnectStart:g,onConnectEnd:b,onClickConnectStart:v,onClickConnectEnd:k,onNodeMouseEnter:y,onNodeMouseMove:x,onNodeMouseLeave:w,onNodeContextMenu:S,onNodeDoubleClick:j,onNodeDragStart:E,onNodeDrag:C,onNodeDragStop:R,onNodesDelete:P,onEdgesDelete:T,onDelete:D,onSelectionChange:z,onSelectionDragStart:I,onSelectionDrag:B,onSelectionDragStop:L,onSelectionContextMenu:q,onSelectionStart:_,onSelectionEnd:A,onBeforeDelete:$,connectionMode:F,connectionLineType:V=In.Bezier,connectionLineStyle:X,connectionLineComponent:O,connectionLineContainerStyle:M,deleteKeyCode:K="Backspace",selectionKeyCode:W="Shift",selectionOnDrag:H=!1,selectionMode:Z=dr.Full,panActivationKeyCode:J="Space",multiSelectionKeyCode:le=fr()?"Meta":"Control",zoomActivationKeyCode:ue=fr()?"Meta":"Control",snapToGrid:pe,snapGrid:we,onlyRenderVisibleElements:Ne=!1,selectNodesOnDrag:ke,nodesDraggable:Be,autoPanOnNodeFocus:et,nodesConnectable:Ee,nodesFocusable:Ke,nodeOrigin:ot=Ed,edgesFocusable:_e,edgesReconnectable:re,elementsSelectable:he=!0,defaultViewport:ge=Qm,minZoom:ee=.5,maxZoom:ne=2,translateExtent:oe=cr,preventScrolling:je=!0,nodeExtent:ye,defaultMarkerColor:Se="#b1b1b7",zoomOnScroll:Te=!0,zoomOnPinch:st=!0,panOnScroll:qe=!1,panOnScrollSpeed:te=.5,panOnScrollMode:Re=Jn.Free,zoomOnDoubleClick:Ue=!0,panOnDrag:mt=!0,onPaneClick:Qe,onPaneMouseEnter:Ae,onPaneMouseMove:Pe,onPaneMouseLeave:Ge,onPaneScroll:at,onPaneContextMenu:G,paneClickDistance:ie=1,nodeClickDistance:be=0,children:de,onReconnect:xe,onReconnectStart:Ce,onReconnectEnd:ze,onEdgeContextMenu:vt,onEdgeDoubleClick:Yt,onEdgeMouseEnter:jt,onEdgeMouseMove:Fe,onEdgeMouseLeave:dt,reconnectRadius:It=10,onNodesChange:_t,onEdgesChange:kn,noDragClassName:yt="nodrag",noWheelClassName:Xe="nowheel",noPanClassName:tt="nopan",fitView:Ze,fitViewOptions:ut,connectOnClick:Ht,attributionPosition:Nt,proOptions:St,defaultEdgeOptions:Tt,elevateNodesOnSelect:Ot=!0,elevateEdgesOnSelect:Gt=!1,disableKeyboardA11y:U=!1,autoPanOnConnect:fe,autoPanOnNodeDrag:Le,autoPanSpeed:$e,connectionRadius:He,isValidConnection:Rt,onError:dn,style:ss,id:_n,nodeDragThreshold:Hs,connectionDragThreshold:Bo,viewport:$t,onViewportChange:Rn,width:Dn,height:Vs,colorMode:Ws="light",debug:vn,onScroll:On,ariaLabelConfig:rs,zIndexMode:os="basic",...$n},Pn){const rn=_n||"1",as=np(Ws),Bn=p.useCallback(Ks=>{Ks.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),On?.(Ks)},[On]);return r.jsx("div",{"data-testid":"rf__wrapper",...$n,onScroll:Bn,style:{...ss,...jg},ref:Pn,className:kt(["react-flow",o,as]),id:_n,role:"application",children:r.jsxs(vg,{nodes:e,edges:t,width:Dn,height:Vs,fitView:Ze,fitViewOptions:ut,minZoom:ee,maxZoom:ne,nodeOrigin:ot,nodeExtent:ye,zIndexMode:os,children:[r.jsx(yg,{onInit:d,onNodeClick:l,onEdgeClick:c,onNodeMouseEnter:y,onNodeMouseMove:x,onNodeMouseLeave:w,onNodeContextMenu:S,onNodeDoubleClick:j,nodeTypes:a,edgeTypes:i,connectionLineType:V,connectionLineStyle:X,connectionLineComponent:O,connectionLineContainerStyle:M,selectionKeyCode:W,selectionOnDrag:H,selectionMode:Z,deleteKeyCode:K,multiSelectionKeyCode:le,panActivationKeyCode:J,zoomActivationKeyCode:ue,onlyRenderVisibleElements:Ne,defaultViewport:ge,translateExtent:oe,minZoom:ee,maxZoom:ne,preventScrolling:je,zoomOnScroll:Te,zoomOnPinch:st,zoomOnDoubleClick:Ue,panOnScroll:qe,panOnScrollSpeed:te,panOnScrollMode:Re,panOnDrag:mt,onPaneClick:Qe,onPaneMouseEnter:Ae,onPaneMouseMove:Pe,onPaneMouseLeave:Ge,onPaneScroll:at,onPaneContextMenu:G,paneClickDistance:ie,nodeClickDistance:be,onSelectionContextMenu:q,onSelectionStart:_,onSelectionEnd:A,onReconnect:xe,onReconnectStart:Ce,onReconnectEnd:ze,onEdgeContextMenu:vt,onEdgeDoubleClick:Yt,onEdgeMouseEnter:jt,onEdgeMouseMove:Fe,onEdgeMouseLeave:dt,reconnectRadius:It,defaultMarkerColor:Se,noDragClassName:yt,noWheelClassName:Xe,noPanClassName:tt,rfId:rn,disableKeyboardA11y:U,nodeExtent:ye,viewport:$t,onViewportChange:Rn}),r.jsx(tp,{nodes:e,edges:t,defaultNodes:n,defaultEdges:s,onConnect:m,onConnectStart:g,onConnectEnd:b,onClickConnectStart:v,onClickConnectEnd:k,nodesDraggable:Be,autoPanOnNodeFocus:et,nodesConnectable:Ee,nodesFocusable:Ke,edgesFocusable:_e,edgesReconnectable:re,elementsSelectable:he,elevateNodesOnSelect:Ot,elevateEdgesOnSelect:Gt,minZoom:ee,maxZoom:ne,nodeExtent:ye,onNodesChange:_t,onEdgesChange:kn,snapToGrid:pe,snapGrid:we,connectionMode:F,translateExtent:oe,connectOnClick:Ht,defaultEdgeOptions:Tt,fitView:Ze,fitViewOptions:ut,onNodesDelete:P,onEdgesDelete:T,onDelete:D,onNodeDragStart:E,onNodeDrag:C,onNodeDragStop:R,onSelectionDrag:B,onSelectionDragStart:I,onSelectionDragStop:L,onMove:h,onMoveStart:u,onMoveEnd:f,noPanClassName:tt,nodeOrigin:ot,rfId:rn,autoPanOnConnect:fe,autoPanOnNodeDrag:Le,autoPanSpeed:$e,onError:dn,connectionRadius:He,isValidConnection:Rt,selectNodesOnDrag:ke,nodeDragThreshold:Hs,connectionDragThreshold:Bo,onBeforeDelete:$,debug:vn,ariaLabelConfig:rs,zIndexMode:os}),r.jsx(Zm,{onSelectionChange:z}),de,r.jsx(Km,{proOptions:St,position:Nt}),r.jsx(Wm,{rfId:rn,disableKeyboardA11y:U})]})})}var Sg=Ad(Ng);function Cg(){const e=ct();return p.useCallback(t=>{const{domNode:n,updateNodeInternals:s}=e.getState(),o=Array.isArray(t)?t:[t],a=new Map;o.forEach(i=>{const l=n?.querySelector(`.react-flow__node[data-id="${i}"]`);l&&a.set(i,{id:i,nodeElement:l,force:!0})}),requestAnimationFrame(()=>s(a,{triggerFitView:!1}))},[])}function Eg(e){const[t,n]=p.useState(e),s=p.useCallback(o=>n(a=>Td(o,a)),[]);return[t,n,s]}function Ig(e){const[t,n]=p.useState(e),s=p.useCallback(o=>n(a=>Md(o,a)),[]);return[t,n,s]}function Tg({dimensions:e,lineWidth:t,variant:n,className:s}){return r.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:kt(["react-flow__background-pattern",n,s])})}function Mg({radius:e,className:t}){return r.jsx("circle",{cx:e,cy:e,r:e,className:kt(["react-flow__background-pattern","dots",t])})}var Mn;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Mn||(Mn={}));const Ag={[Mn.Dots]:1,[Mn.Lines]:1,[Mn.Cross]:6},Lg=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function tu({id:e,variant:t=Mn.Dots,gap:n=20,size:s,lineWidth:o=1,offset:a=0,color:i,bgColor:l,style:c,className:d,patternClassName:h}){const u=p.useRef(null),{transform:f,patternId:m}=We(Lg,ft),g=s||Ag[t],b=t===Mn.Dots,v=t===Mn.Cross,k=Array.isArray(n)?n:[n,n],y=[k[0]*f[2]||1,k[1]*f[2]||1],x=g*f[2],w=Array.isArray(a)?a:[a,a],S=v?[x,x]:y,j=[w[0]*f[2]||1+S[0]/2,w[1]*f[2]||1+S[1]/2],E=`${m}${e||""}`;return r.jsxs("svg",{className:kt(["react-flow__background",d]),style:{...c,...Io,"--xy-background-color-props":l,"--xy-background-pattern-color-props":i},ref:u,"data-testid":"rf__background",children:[r.jsx("pattern",{id:E,x:f[0]%y[0],y:f[1]%y[1],width:y[0],height:y[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${j[0]},-${j[1]})`,children:b?r.jsx(Mg,{radius:x/2,className:h}):r.jsx(Tg,{dimensions:S,lineWidth:o,variant:t,className:h})}),r.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${E})`})]})}tu.displayName="Background";const _g=p.memo(tu);function Rg(){return r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:r.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function Dg(){return r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:r.jsx("path",{d:"M0 0h32v4.2H0z"})})}function Og(){return r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:r.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 $g(){return r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:r.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 Pg(){return r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:r.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 Ur({children:e,className:t,...n}){return r.jsx("button",{type:"button",className:kt(["react-flow__controls-button",t]),...n,children:e})}const Bg=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function nu({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:s=!0,fitViewOptions:o,onZoomIn:a,onZoomOut:i,onFitView:l,onInteractiveChange:c,className:d,children:h,position:u="bottom-left",orientation:f="vertical","aria-label":m}){const g=ct(),{isInteractive:b,minZoomReached:v,maxZoomReached:k,ariaLabelConfig:y}=We(Bg,ft),{zoomIn:x,zoomOut:w,fitView:S}=Va(),j=()=>{x(),a?.()},E=()=>{w(),i?.()},C=()=>{S(o),l?.()},R=()=>{g.setState({nodesDraggable:!b,nodesConnectable:!b,elementsSelectable:!b}),c?.(!b)},P=f==="horizontal"?"horizontal":"vertical";return r.jsxs(Eo,{className:kt(["react-flow__controls",P,d]),position:u,style:e,"data-testid":"rf__controls","aria-label":m??y["controls.ariaLabel"],children:[t&&r.jsxs(r.Fragment,{children:[r.jsx(Ur,{onClick:j,className:"react-flow__controls-zoomin",title:y["controls.zoomIn.ariaLabel"],"aria-label":y["controls.zoomIn.ariaLabel"],disabled:k,children:r.jsx(Rg,{})}),r.jsx(Ur,{onClick:E,className:"react-flow__controls-zoomout",title:y["controls.zoomOut.ariaLabel"],"aria-label":y["controls.zoomOut.ariaLabel"],disabled:v,children:r.jsx(Dg,{})})]}),n&&r.jsx(Ur,{className:"react-flow__controls-fitview",onClick:C,title:y["controls.fitView.ariaLabel"],"aria-label":y["controls.fitView.ariaLabel"],children:r.jsx(Og,{})}),s&&r.jsx(Ur,{className:"react-flow__controls-interactive",onClick:R,title:y["controls.interactive.ariaLabel"],"aria-label":y["controls.interactive.ariaLabel"],children:b?r.jsx(Pg,{}):r.jsx($g,{})}),h]})}nu.displayName="Controls";const qg=p.memo(nu);function zg({id:e,x:t,y:n,width:s,height:o,style:a,color:i,strokeColor:l,strokeWidth:c,className:d,borderRadius:h,shapeRendering:u,selected:f,onClick:m}){const{background:g,backgroundColor:b}=a||{},v=i||g||b;return r.jsx("rect",{className:kt(["react-flow__minimap-node",{selected:f},d]),x:t,y:n,rx:h,ry:h,width:s,height:o,style:{fill:v,stroke:l,strokeWidth:c},shapeRendering:u,onClick:m?k=>m(k,e):void 0})}const Fg=p.memo(zg),Hg=e=>e.nodes.map(t=>t.id),sa=e=>e instanceof Function?e:()=>e;function Vg({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:s=5,nodeStrokeWidth:o,nodeComponent:a=Fg,onClick:i}){const l=We(Hg,ft),c=sa(t),d=sa(e),h=sa(n),u=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return r.jsx(r.Fragment,{children:l.map(f=>r.jsx(Kg,{id:f,nodeColorFunc:c,nodeStrokeColorFunc:d,nodeClassNameFunc:h,nodeBorderRadius:s,nodeStrokeWidth:o,NodeComponent:a,onClick:i,shapeRendering:u},f))})}function Wg({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:s,nodeBorderRadius:o,nodeStrokeWidth:a,shapeRendering:i,NodeComponent:l,onClick:c}){const{node:d,x:h,y:u,width:f,height:m}=We(g=>{const b=g.nodeLookup.get(e);if(!b)return{node:void 0,x:0,y:0,width:0,height:0};const v=b.internals.userNode,{x:k,y}=b.internals.positionAbsolute,{width:x,height:w}=wn(v);return{node:v,x:k,y,width:x,height:w}},ft);return!d||d.hidden||!sd(d)?null:r.jsx(l,{x:h,y:u,width:f,height:m,style:d.style,selected:!!d.selected,className:s(d),color:t(d),borderRadius:o,strokeColor:n(d),strokeWidth:a,shapeRendering:i,onClick:c,id:d.id})}const Kg=p.memo(Wg);var Ug=p.memo(Vg);const Yg=200,Gg=150,Xg=e=>!e.hidden,Zg=e=>{const t={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:t,boundingRect:e.nodeLookup.size>0?nd(br(e.nodeLookup,{filter:Xg}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},Qg="react-flow__minimap-desc";function su({style:e,className:t,nodeStrokeColor:n,nodeColor:s,nodeClassName:o="",nodeBorderRadius:a=5,nodeStrokeWidth:i,nodeComponent:l,bgColor:c,maskColor:d,maskStrokeColor:h,maskStrokeWidth:u,position:f="bottom-right",onClick:m,onNodeClick:g,pannable:b=!1,zoomable:v=!1,ariaLabel:k,inversePan:y,zoomStep:x=1,offsetScale:w=5}){const S=ct(),j=p.useRef(null),{boundingRect:E,viewBB:C,rfId:R,panZoom:P,translateExtent:T,flowWidth:D,flowHeight:z,ariaLabelConfig:I}=We(Zg,ft),B=e?.width??Yg,L=e?.height??Gg,q=E.width/B,_=E.height/L,A=Math.max(q,_),$=A*B,F=A*L,V=w*A,X=E.x-($-E.width)/2-V,O=E.y-(F-E.height)/2-V,M=$+V*2,K=F+V*2,W=`${Qg}-${R}`,H=p.useRef(0),Z=p.useRef();H.current=A,p.useEffect(()=>{if(j.current&&P)return Z.current=mm({domNode:j.current,panZoom:P,getTransform:()=>S.getState().transform,getViewScale:()=>H.current}),()=>{Z.current?.destroy()}},[P]),p.useEffect(()=>{Z.current?.update({translateExtent:T,width:D,height:z,inversePan:y,pannable:b,zoomStep:x,zoomable:v})},[b,v,y,x,T,D,z]);const J=m?pe=>{const[we,Ne]=Z.current?.pointer(pe)||[0,0];m(pe,{x:we,y:Ne})}:void 0,le=g?p.useCallback((pe,we)=>{const Ne=S.getState().nodeLookup.get(we).internals.userNode;g(pe,Ne)},[]):void 0,ue=k??I["minimap.ariaLabel"];return r.jsx(Eo,{position:f,style:{...e,"--xy-minimap-background-color-props":typeof c=="string"?c:void 0,"--xy-minimap-mask-background-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-stroke-color-props":typeof h=="string"?h:void 0,"--xy-minimap-mask-stroke-width-props":typeof u=="number"?u*A:void 0,"--xy-minimap-node-background-color-props":typeof s=="string"?s:void 0,"--xy-minimap-node-stroke-color-props":typeof n=="string"?n:void 0,"--xy-minimap-node-stroke-width-props":typeof i=="number"?i:void 0},className:kt(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:r.jsxs("svg",{width:B,height:L,viewBox:`${X} ${O} ${M} ${K}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":W,ref:j,onClick:J,children:[ue&&r.jsx("title",{id:W,children:ue}),r.jsx(Ug,{onClick:le,nodeColor:s,nodeStrokeColor:n,nodeBorderRadius:a,nodeClassName:o,nodeStrokeWidth:i,nodeComponent:l}),r.jsx("path",{className:"react-flow__minimap-mask",d:`M${X-V},${O-V}h${M+V*2}v${K+V*2}h${-M-V*2}z
|
|
7
|
-
M${C.x},${C.y}h${C.width}v${C.height}h${-C.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}su.displayName="MiniMap";const Jg=p.memo(su),ex=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,tx={[Rs.Line]:"right",[Rs.Handle]:"bottom-right"};function nx({nodeId:e,position:t,variant:n=Rs.Handle,className:s,style:o=void 0,children:a,color:i,minWidth:l=10,minHeight:c=10,maxWidth:d=Number.MAX_VALUE,maxHeight:h=Number.MAX_VALUE,keepAspectRatio:u=!1,resizeDirection:f,autoScale:m=!0,shouldResize:g,onResizeStart:b,onResize:v,onResizeEnd:k}){const y=Dd(),x=typeof e=="string"?e:y,w=ct(),S=p.useRef(null),j=n===Rs.Handle,E=We(p.useCallback(ex(j&&m),[j,m]),ft),C=p.useRef(null),R=t??tx[n];p.useEffect(()=>{if(!(!S.current||!x))return C.current||(C.current=Im({domNode:S.current,nodeId:x,getStoreItems:()=>{const{nodeLookup:T,transform:D,snapGrid:z,snapToGrid:I,nodeOrigin:B,domNode:L}=w.getState();return{nodeLookup:T,transform:D,snapGrid:z,snapToGrid:I,nodeOrigin:B,paneDomNode:L}},onChange:(T,D)=>{const{triggerNodeChanges:z,nodeLookup:I,parentLookup:B,nodeOrigin:L}=w.getState(),q=[],_={x:T.x,y:T.y},A=I.get(x);if(A&&A.expandParent&&A.parentId){const $=A.origin??L,F=T.width??A.measured.width??0,V=T.height??A.measured.height??0,X={id:A.id,parentId:A.parentId,rect:{width:F,height:V,...rd({x:T.x??A.position.x,y:T.y??A.position.y},{width:F,height:V},A.parentId,I,$)}},O=Ha([X],I,B,L);q.push(...O),_.x=T.x?Math.max($[0]*F,T.x):void 0,_.y=T.y?Math.max($[1]*V,T.y):void 0}if(_.x!==void 0&&_.y!==void 0){const $={id:x,type:"position",position:{..._}};q.push($)}if(T.width!==void 0&&T.height!==void 0){const F={id:x,type:"dimensions",resizing:!0,setAttributes:f?f==="horizontal"?"width":"height":!0,dimensions:{width:T.width,height:T.height}};q.push(F)}for(const $ of D){const F={...$,type:"position"};q.push(F)}z(q)},onEnd:({width:T,height:D})=>{const z={id:x,type:"dimensions",resizing:!1,dimensions:{width:T,height:D}};w.getState().triggerNodeChanges([z])}})),C.current.update({controlPosition:R,boundaries:{minWidth:l,minHeight:c,maxWidth:d,maxHeight:h},keepAspectRatio:u,resizeDirection:f,onResizeStart:b,onResize:v,onResizeEnd:k,shouldResize:g}),()=>{C.current?.destroy()}},[R,l,c,d,h,u,b,v,k,g]);const P=R.split("-");return r.jsx("div",{className:kt(["react-flow__resize-control","nodrag",...P,n,s]),ref:S,style:{...o,scale:E,...i&&{[j?"backgroundColor":"borderColor"]:i}},children:a})}p.memo(nx);var Je=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),nn=Je((e,t)=>{var n=Object.defineProperty,s=(z,I,B)=>I in z?n(z,I,{enumerable:!0,configurable:!0,writable:!0,value:B}):z[I]=B,o=(z,I)=>()=>(I||z((I={exports:{}}).exports,I),I.exports),a=(z,I,B)=>s(z,typeof I!="symbol"?I+"":I,B),i=o((z,I)=>{var B="\0",L="\0",q="",_=class{constructor(O){a(this,"_isDirected",!0),a(this,"_isMultigraph",!1),a(this,"_isCompound",!1),a(this,"_label"),a(this,"_defaultNodeLabelFn",()=>{}),a(this,"_defaultEdgeLabelFn",()=>{}),a(this,"_nodes",{}),a(this,"_in",{}),a(this,"_preds",{}),a(this,"_out",{}),a(this,"_sucs",{}),a(this,"_edgeObjs",{}),a(this,"_edgeLabels",{}),a(this,"_nodeCount",0),a(this,"_edgeCount",0),a(this,"_parent"),a(this,"_children"),O&&(this._isDirected=Object.hasOwn(O,"directed")?O.directed:!0,this._isMultigraph=Object.hasOwn(O,"multigraph")?O.multigraph:!1,this._isCompound=Object.hasOwn(O,"compound")?O.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[L]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(O){return this._label=O,this}graph(){return this._label}setDefaultNodeLabel(O){return this._defaultNodeLabelFn=O,typeof O!="function"&&(this._defaultNodeLabelFn=()=>O),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var O=this;return this.nodes().filter(M=>Object.keys(O._in[M]).length===0)}sinks(){var O=this;return this.nodes().filter(M=>Object.keys(O._out[M]).length===0)}setNodes(O,M){var K=arguments,W=this;return O.forEach(function(H){K.length>1?W.setNode(H,M):W.setNode(H)}),this}setNode(O,M){return Object.hasOwn(this._nodes,O)?(arguments.length>1&&(this._nodes[O]=M),this):(this._nodes[O]=arguments.length>1?M:this._defaultNodeLabelFn(O),this._isCompound&&(this._parent[O]=L,this._children[O]={},this._children[L][O]=!0),this._in[O]={},this._preds[O]={},this._out[O]={},this._sucs[O]={},++this._nodeCount,this)}node(O){return this._nodes[O]}hasNode(O){return Object.hasOwn(this._nodes,O)}removeNode(O){var M=this;if(Object.hasOwn(this._nodes,O)){var K=W=>M.removeEdge(M._edgeObjs[W]);delete this._nodes[O],this._isCompound&&(this._removeFromParentsChildList(O),delete this._parent[O],this.children(O).forEach(function(W){M.setParent(W)}),delete this._children[O]),Object.keys(this._in[O]).forEach(K),delete this._in[O],delete this._preds[O],Object.keys(this._out[O]).forEach(K),delete this._out[O],delete this._sucs[O],--this._nodeCount}return this}setParent(O,M){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(M===void 0)M=L;else{M+="";for(var K=M;K!==void 0;K=this.parent(K))if(K===O)throw new Error("Setting "+M+" as parent of "+O+" would create a cycle");this.setNode(M)}return this.setNode(O),this._removeFromParentsChildList(O),this._parent[O]=M,this._children[M][O]=!0,this}_removeFromParentsChildList(O){delete this._children[this._parent[O]][O]}parent(O){if(this._isCompound){var M=this._parent[O];if(M!==L)return M}}children(O=L){if(this._isCompound){var M=this._children[O];if(M)return Object.keys(M)}else{if(O===L)return this.nodes();if(this.hasNode(O))return[]}}predecessors(O){var M=this._preds[O];if(M)return Object.keys(M)}successors(O){var M=this._sucs[O];if(M)return Object.keys(M)}neighbors(O){var M=this.predecessors(O);if(M){let W=new Set(M);for(var K of this.successors(O))W.add(K);return Array.from(W.values())}}isLeaf(O){var M;return this.isDirected()?M=this.successors(O):M=this.neighbors(O),M.length===0}filterNodes(O){var M=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});M.setGraph(this.graph());var K=this;Object.entries(this._nodes).forEach(function([Z,J]){O(Z)&&M.setNode(Z,J)}),Object.values(this._edgeObjs).forEach(function(Z){M.hasNode(Z.v)&&M.hasNode(Z.w)&&M.setEdge(Z,K.edge(Z))});var W={};function H(Z){var J=K.parent(Z);return J===void 0||M.hasNode(J)?(W[Z]=J,J):J in W?W[J]:H(J)}return this._isCompound&&M.nodes().forEach(Z=>M.setParent(Z,H(Z))),M}setDefaultEdgeLabel(O){return this._defaultEdgeLabelFn=O,typeof O!="function"&&(this._defaultEdgeLabelFn=()=>O),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(O,M){var K=this,W=arguments;return O.reduce(function(H,Z){return W.length>1?K.setEdge(H,Z,M):K.setEdge(H,Z),Z}),this}setEdge(){var O,M,K,W,H=!1,Z=arguments[0];typeof Z=="object"&&Z!==null&&"v"in Z?(O=Z.v,M=Z.w,K=Z.name,arguments.length===2&&(W=arguments[1],H=!0)):(O=Z,M=arguments[1],K=arguments[3],arguments.length>2&&(W=arguments[2],H=!0)),O=""+O,M=""+M,K!==void 0&&(K=""+K);var J=F(this._isDirected,O,M,K);if(Object.hasOwn(this._edgeLabels,J))return H&&(this._edgeLabels[J]=W),this;if(K!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(O),this.setNode(M),this._edgeLabels[J]=H?W:this._defaultEdgeLabelFn(O,M,K);var le=V(this._isDirected,O,M,K);return O=le.v,M=le.w,Object.freeze(le),this._edgeObjs[J]=le,A(this._preds[M],O),A(this._sucs[O],M),this._in[M][J]=le,this._out[O][J]=le,this._edgeCount++,this}edge(O,M,K){var W=arguments.length===1?X(this._isDirected,arguments[0]):F(this._isDirected,O,M,K);return this._edgeLabels[W]}edgeAsObj(){let O=this.edge(...arguments);return typeof O!="object"?{label:O}:O}hasEdge(O,M,K){var W=arguments.length===1?X(this._isDirected,arguments[0]):F(this._isDirected,O,M,K);return Object.hasOwn(this._edgeLabels,W)}removeEdge(O,M,K){var W=arguments.length===1?X(this._isDirected,arguments[0]):F(this._isDirected,O,M,K),H=this._edgeObjs[W];return H&&(O=H.v,M=H.w,delete this._edgeLabels[W],delete this._edgeObjs[W],$(this._preds[M],O),$(this._sucs[O],M),delete this._in[M][W],delete this._out[O][W],this._edgeCount--),this}inEdges(O,M){return this.isDirected()?this.filterEdges(this._in[O],O,M):this.nodeEdges(O,M)}outEdges(O,M){return this.isDirected()?this.filterEdges(this._out[O],O,M):this.nodeEdges(O,M)}nodeEdges(O,M){if(O in this._nodes)return this.filterEdges({...this._in[O],...this._out[O]},O,M)}filterEdges(O,M,K){if(O){var W=Object.values(O);return K?W.filter(function(H){return H.v===M&&H.w===K||H.v===K&&H.w===M}):W}}};function A(O,M){O[M]?O[M]++:O[M]=1}function $(O,M){--O[M]||delete O[M]}function F(O,M,K,W){var H=""+M,Z=""+K;if(!O&&H>Z){var J=H;H=Z,Z=J}return H+q+Z+q+(W===void 0?B:W)}function V(O,M,K,W){var H=""+M,Z=""+K;if(!O&&H>Z){var J=H;H=Z,Z=J}var le={v:H,w:Z};return W&&(le.name=W),le}function X(O,M){return F(O,M.v,M.w,M.name)}I.exports=_}),l=o((z,I)=>{I.exports="3.0.2"}),c=o((z,I)=>{I.exports={Graph:i(),version:l()}}),d=o((z,I)=>{var B=i();I.exports={write:L,read:A};function L($){var F={options:{directed:$.isDirected(),multigraph:$.isMultigraph(),compound:$.isCompound()},nodes:q($),edges:_($)};return $.graph()!==void 0&&(F.value=structuredClone($.graph())),F}function q($){return $.nodes().map(function(F){var V=$.node(F),X=$.parent(F),O={v:F};return V!==void 0&&(O.value=V),X!==void 0&&(O.parent=X),O})}function _($){return $.edges().map(function(F){var V=$.edge(F),X={v:F.v,w:F.w};return F.name!==void 0&&(X.name=F.name),V!==void 0&&(X.value=V),X})}function A($){var F=new B($.options).setGraph($.value);return $.nodes.forEach(function(V){F.setNode(V.v,V.value),V.parent&&F.setParent(V.v,V.parent)}),$.edges.forEach(function(V){F.setEdge({v:V.v,w:V.w,name:V.name},V.value)}),F}}),h=o((z,I)=>{I.exports=L;var B=()=>1;function L(_,A,$,F){return q(_,String(A),$||B,F||function(V){return _.outEdges(V)})}function q(_,A,$,F){var V={},X=!0,O=0,M=_.nodes(),K=function(J){var le=$(J);V[J.v].distance+le<V[J.w].distance&&(V[J.w]={distance:V[J.v].distance+le,predecessor:J.v},X=!0)},W=function(){M.forEach(function(J){F(J).forEach(function(le){var ue=le.v===J?le.v:le.w,pe=ue===le.v?le.w:le.v;K({v:ue,w:pe})})})};M.forEach(function(J){var le=J===A?0:Number.POSITIVE_INFINITY;V[J]={distance:le}});for(var H=M.length,Z=1;Z<H&&(X=!1,O++,W(),!!X);Z++);if(O===H-1&&(X=!1,W(),X))throw new Error("The graph contains a negative weight cycle");return V}}),u=o((z,I)=>{I.exports=B;function B(L){var q={},_=[],A;function $(F){Object.hasOwn(q,F)||(q[F]=!0,A.push(F),L.successors(F).forEach($),L.predecessors(F).forEach($))}return L.nodes().forEach(function(F){A=[],$(F),A.length&&_.push(A)}),_}}),f=o((z,I)=>{var B=class{constructor(){a(this,"_arr",[]),a(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 q=this._keyIndices[L];if(q!==void 0)return this._arr[q].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(L,q){var _=this._keyIndices;if(L=String(L),!Object.hasOwn(_,L)){var A=this._arr,$=A.length;return _[L]=$,A.push({key:L,priority:q}),this._decrease($),!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,q){var _=this._keyIndices[L];if(q>this._arr[_].priority)throw new Error("New priority is greater than current priority. Key: "+L+" Old: "+this._arr[_].priority+" New: "+q);this._arr[_].priority=q,this._decrease(_)}_heapify(L){var q=this._arr,_=2*L,A=_+1,$=L;_<q.length&&($=q[_].priority<q[$].priority?_:$,A<q.length&&($=q[A].priority<q[$].priority?A:$),$!==L&&(this._swap(L,$),this._heapify($)))}_decrease(L){for(var q=this._arr,_=q[L].priority,A;L!==0&&(A=L>>1,!(q[A].priority<_));)this._swap(L,A),L=A}_swap(L,q){var _=this._arr,A=this._keyIndices,$=_[L],F=_[q];_[L]=F,_[q]=$,A[F.key]=L,A[$.key]=q}};I.exports=B}),m=o((z,I)=>{var B=f();I.exports=q;var L=()=>1;function q(A,$,F,V){var X=function(O){return A.outEdges(O)};return _(A,String($),F||L,V||X)}function _(A,$,F,V){var X={},O=new B,M,K,W=function(H){var Z=H.v!==M?H.v:H.w,J=X[Z],le=F(H),ue=K.distance+le;if(le<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+H+" Weight: "+le);ue<J.distance&&(J.distance=ue,J.predecessor=M,O.decrease(Z,ue))};for(A.nodes().forEach(function(H){var Z=H===$?0:Number.POSITIVE_INFINITY;X[H]={distance:Z},O.add(H,Z)});O.size()>0&&(M=O.removeMin(),K=X[M],K.distance!==Number.POSITIVE_INFINITY);)V(M).forEach(W);return X}}),g=o((z,I)=>{var B=m();I.exports=L;function L(q,_,A){return q.nodes().reduce(function($,F){return $[F]=B(q,F,_,A),$},{})}}),b=o((z,I)=>{I.exports=B;function B(q,_,A){if(q[_].predecessor!==void 0)throw new Error("Invalid source vertex");if(q[A].predecessor===void 0&&A!==_)throw new Error("Invalid destination vertex");return{weight:q[A].distance,path:L(q,_,A)}}function L(q,_,A){for(var $=[],F=A;F!==_;)$.push(F),F=q[F].predecessor;return $.push(_),$.reverse()}}),v=o((z,I)=>{I.exports=B;function B(L){var q=0,_=[],A={},$=[];function F(V){var X=A[V]={onStack:!0,lowlink:q,index:q++};if(_.push(V),L.successors(V).forEach(function(K){Object.hasOwn(A,K)?A[K].onStack&&(X.lowlink=Math.min(X.lowlink,A[K].index)):(F(K),X.lowlink=Math.min(X.lowlink,A[K].lowlink))}),X.lowlink===X.index){var O=[],M;do M=_.pop(),A[M].onStack=!1,O.push(M);while(V!==M);$.push(O)}}return L.nodes().forEach(function(V){Object.hasOwn(A,V)||F(V)}),$}}),k=o((z,I)=>{var B=v();I.exports=L;function L(q){return B(q).filter(function(_){return _.length>1||_.length===1&&q.hasEdge(_[0],_[0])})}}),y=o((z,I)=>{I.exports=L;var B=()=>1;function L(_,A,$){return q(_,A||B,$||function(F){return _.outEdges(F)})}function q(_,A,$){var F={},V=_.nodes();return V.forEach(function(X){F[X]={},F[X][X]={distance:0},V.forEach(function(O){X!==O&&(F[X][O]={distance:Number.POSITIVE_INFINITY})}),$(X).forEach(function(O){var M=O.v===X?O.w:O.v,K=A(O);F[X][M]={distance:K,predecessor:X}})}),V.forEach(function(X){var O=F[X];V.forEach(function(M){var K=F[M];V.forEach(function(W){var H=K[X],Z=O[W],J=K[W],le=H.distance+Z.distance;le<J.distance&&(J.distance=le,J.predecessor=Z.predecessor)})})}),F}}),x=o((z,I)=>{function B(q){var _={},A={},$=[];function F(V){if(Object.hasOwn(A,V))throw new L;Object.hasOwn(_,V)||(A[V]=!0,_[V]=!0,q.predecessors(V).forEach(F),delete A[V],$.push(V))}if(q.sinks().forEach(F),Object.keys(_).length!==q.nodeCount())throw new L;return $}var L=class extends Error{constructor(){super(...arguments)}};I.exports=B,B.CycleException=L}),w=o((z,I)=>{var B=x();I.exports=L;function L(q){try{B(q)}catch(_){if(_ instanceof B.CycleException)return!1;throw _}return!0}}),S=o((z,I)=>{I.exports=B;function B(q,_,A,$,F){Array.isArray(_)||(_=[_]);var V=(q.isDirected()?q.successors:q.neighbors).bind(q),X={};return _.forEach(function(O){if(!q.hasNode(O))throw new Error("Graph does not have node: "+O);F=L(q,O,A==="post",X,V,$,F)}),F}function L(q,_,A,$,F,V,X){return Object.hasOwn($,_)||($[_]=!0,A||(X=V(X,_)),F(_).forEach(function(O){X=L(q,O,A,$,F,V,X)}),A&&(X=V(X,_))),X}}),j=o((z,I)=>{var B=S();I.exports=L;function L(q,_,A){return B(q,_,A,function($,F){return $.push(F),$},[])}}),E=o((z,I)=>{var B=j();I.exports=L;function L(q,_){return B(q,_,"post")}}),C=o((z,I)=>{var B=j();I.exports=L;function L(q,_){return B(q,_,"pre")}}),R=o((z,I)=>{var B=i(),L=f();I.exports=q;function q(_,A){var $=new B,F={},V=new L,X;function O(K){var W=K.v===X?K.w:K.v,H=V.priority(W);if(H!==void 0){var Z=A(K);Z<H&&(F[W]=X,V.decrease(W,Z))}}if(_.nodeCount()===0)return $;_.nodes().forEach(function(K){V.add(K,Number.POSITIVE_INFINITY),$.setNode(K)}),V.decrease(_.nodes()[0],0);for(var M=!1;V.size()>0;){if(X=V.removeMin(),Object.hasOwn(F,X))$.setEdge(X,F[X]);else{if(M)throw new Error("Input graph is not connected: "+_);M=!0}_.nodeEdges(X).forEach(O)}return $}}),P=o((z,I)=>{var B=m(),L=h();I.exports=q;function q(A,$,F,V){return _(A,$,F,V||function(X){return A.outEdges(X)})}function _(A,$,F,V){if(F===void 0)return B(A,$,F,V);for(var X=!1,O=A.nodes(),M=0;M<O.length;M++){for(var K=V(O[M]),W=0;W<K.length;W++){var H=K[W],Z=H.v===O[M]?H.v:H.w,J=Z===H.v?H.w:H.v;F({v:Z,w:J})<0&&(X=!0)}if(X)return L(A,$,F,V)}return B(A,$,F,V)}}),T=o((z,I)=>{I.exports={bellmanFord:h(),components:u(),dijkstra:m(),dijkstraAll:g(),extractPath:b(),findCycles:k(),floydWarshall:y(),isAcyclic:w(),postorder:E(),preorder:C(),prim:R(),shortestPaths:P(),reduce:S(),tarjan:v(),topsort:x()}}),D=c();t.exports={Graph:D.Graph,json:d(),alg:T(),version:D.version}}),sx=Je((e,t)=>{var n=class{constructor(){let a={};a._next=a._prev=a,this._sentinel=a}dequeue(){let a=this._sentinel,i=a._prev;if(i!==a)return s(i),i}enqueue(a){let i=this._sentinel;a._prev&&a._next&&s(a),a._next=i._next,i._next._prev=a,i._next=a,a._prev=i}toString(){let a=[],i=this._sentinel,l=i._prev;for(;l!==i;)a.push(JSON.stringify(l,o)),l=l._prev;return"["+a.join(", ")+"]"}};function s(a){a._prev._next=a._next,a._next._prev=a._prev,delete a._next,delete a._prev}function o(a,i){if(a!=="_next"&&a!=="_prev")return i}t.exports=n}),rx=Je((e,t)=>{var n=nn().Graph,s=sx();t.exports=a;var o=()=>1;function a(u,f){if(u.nodeCount()<=1)return[];let m=c(u,f||o);return i(m.graph,m.buckets,m.zeroIdx).flatMap(g=>u.outEdges(g.v,g.w))}function i(u,f,m){let g=[],b=f[f.length-1],v=f[0],k;for(;u.nodeCount();){for(;k=v.dequeue();)l(u,f,m,k);for(;k=b.dequeue();)l(u,f,m,k);if(u.nodeCount()){for(let y=f.length-2;y>0;--y)if(k=f[y].dequeue(),k){g=g.concat(l(u,f,m,k,!0));break}}}return g}function l(u,f,m,g,b){let v=b?[]:void 0;return u.inEdges(g.v).forEach(k=>{let y=u.edge(k),x=u.node(k.v);b&&v.push({v:k.v,w:k.w}),x.out-=y,d(f,m,x)}),u.outEdges(g.v).forEach(k=>{let y=u.edge(k),x=k.w,w=u.node(x);w.in-=y,d(f,m,w)}),u.removeNode(g.v),v}function c(u,f){let m=new n,g=0,b=0;u.nodes().forEach(y=>{m.setNode(y,{v:y,in:0,out:0})}),u.edges().forEach(y=>{let x=m.edge(y.v,y.w)||0,w=f(y),S=x+w;m.setEdge(y.v,y.w,S),b=Math.max(b,m.node(y.v).out+=w),g=Math.max(g,m.node(y.w).in+=w)});let v=h(b+g+3).map(()=>new s),k=g+1;return m.nodes().forEach(y=>{d(v,k,m.node(y))}),{graph:m,buckets:v,zeroIdx:k}}function d(u,f,m){m.out?m.in?u[m.out-m.in+f].enqueue(m):u[u.length-1].enqueue(m):u[0].enqueue(m)}function h(u){let f=[];for(let m=0;m<u;m++)f.push(m);return f}}),wt=Je((e,t)=>{var n=nn().Graph;t.exports={addBorderNode:f,addDummyNode:s,applyWithChunking:b,asNonCompoundGraph:a,buildLayerMatrix:d,intersectRect:c,mapValues:C,maxRank:v,normalizeRanks:h,notime:x,partition:k,pick:E,predecessorWeights:l,range:j,removeEmptyRanks:u,simplify:o,successorWeights:i,time:y,uniqueId:S,zipObject:R};function s(P,T,D,z){for(var I=z;P.hasNode(I);)I=S(z);return D.dummy=T,P.setNode(I,D),I}function o(P){let T=new n().setGraph(P.graph());return P.nodes().forEach(D=>T.setNode(D,P.node(D))),P.edges().forEach(D=>{let z=T.edge(D.v,D.w)||{weight:0,minlen:1},I=P.edge(D);T.setEdge(D.v,D.w,{weight:z.weight+I.weight,minlen:Math.max(z.minlen,I.minlen)})}),T}function a(P){let T=new n({multigraph:P.isMultigraph()}).setGraph(P.graph());return P.nodes().forEach(D=>{P.children(D).length||T.setNode(D,P.node(D))}),P.edges().forEach(D=>{T.setEdge(D,P.edge(D))}),T}function i(P){let T=P.nodes().map(D=>{let z={};return P.outEdges(D).forEach(I=>{z[I.w]=(z[I.w]||0)+P.edge(I).weight}),z});return R(P.nodes(),T)}function l(P){let T=P.nodes().map(D=>{let z={};return P.inEdges(D).forEach(I=>{z[I.v]=(z[I.v]||0)+P.edge(I).weight}),z});return R(P.nodes(),T)}function c(P,T){let D=P.x,z=P.y,I=T.x-D,B=T.y-z,L=P.width/2,q=P.height/2;if(!I&&!B)throw new Error("Not possible to find intersection inside of the rectangle");let _,A;return Math.abs(B)*L>Math.abs(I)*q?(B<0&&(q=-q),_=q*I/B,A=q):(I<0&&(L=-L),_=L,A=L*B/I),{x:D+_,y:z+A}}function d(P){let T=j(v(P)+1).map(()=>[]);return P.nodes().forEach(D=>{let z=P.node(D),I=z.rank;I!==void 0&&(T[I][z.order]=D)}),T}function h(P){let T=P.nodes().map(z=>{let I=P.node(z).rank;return I===void 0?Number.MAX_VALUE:I}),D=b(Math.min,T);P.nodes().forEach(z=>{let I=P.node(z);Object.hasOwn(I,"rank")&&(I.rank-=D)})}function u(P){let T=P.nodes().map(L=>P.node(L).rank).filter(L=>L!==void 0),D=b(Math.min,T),z=[];P.nodes().forEach(L=>{let q=P.node(L).rank-D;z[q]||(z[q]=[]),z[q].push(L)});let I=0,B=P.graph().nodeRankFactor;Array.from(z).forEach((L,q)=>{L===void 0&&q%B!==0?--I:L!==void 0&&I&&L.forEach(_=>P.node(_).rank+=I)})}function f(P,T,D,z){let I={width:0,height:0};return arguments.length>=4&&(I.rank=D,I.order=z),s(P,"border",I,T)}function m(P,T=g){let D=[];for(let z=0;z<P.length;z+=T){let I=P.slice(z,z+T);D.push(I)}return D}var g=65535;function b(P,T){if(T.length>g){let D=m(T);return P.apply(null,D.map(z=>P.apply(null,z)))}else return P.apply(null,T)}function v(P){let T=P.nodes().map(D=>{let z=P.node(D).rank;return z===void 0?Number.MIN_VALUE:z});return b(Math.max,T)}function k(P,T){let D={lhs:[],rhs:[]};return P.forEach(z=>{T(z)?D.lhs.push(z):D.rhs.push(z)}),D}function y(P,T){let D=Date.now();try{return T()}finally{console.log(P+" time: "+(Date.now()-D)+"ms")}}function x(P,T){return T()}var w=0;function S(P){var T=++w;return P+(""+T)}function j(P,T,D=1){T==null&&(T=P,P=0);let z=B=>B<T;D<0&&(z=B=>T<B);let I=[];for(let B=P;z(B);B+=D)I.push(B);return I}function E(P,T){let D={};for(let z of T)P[z]!==void 0&&(D[z]=P[z]);return D}function C(P,T){let D=T;return typeof T=="string"&&(D=z=>z[T]),Object.entries(P).reduce((z,[I,B])=>(z[I]=D(B,I),z),{})}function R(P,T){return P.reduce((D,z,I)=>(D[z]=T[I],D),{})}}),ox=Je((e,t)=>{var n=rx(),s=wt().uniqueId;t.exports={run:o,undo:i};function o(l){(l.graph().acyclicer==="greedy"?n(l,c(l)):a(l)).forEach(d=>{let h=l.edge(d);l.removeEdge(d),h.forwardName=d.name,h.reversed=!0,l.setEdge(d.w,d.v,h,s("rev"))});function c(d){return h=>d.edge(h).weight}}function a(l){let c=[],d={},h={};function u(f){Object.hasOwn(h,f)||(h[f]=!0,d[f]=!0,l.outEdges(f).forEach(m=>{Object.hasOwn(d,m.w)?c.push(m):u(m.w)}),delete d[f])}return l.nodes().forEach(u),c}function i(l){l.edges().forEach(c=>{let d=l.edge(c);if(d.reversed){l.removeEdge(c);let h=d.forwardName;delete d.reversed,delete d.forwardName,l.setEdge(c.w,c.v,d,h)}})}}),ax=Je((e,t)=>{var n=wt();t.exports={run:s,undo:a};function s(i){i.graph().dummyChains=[],i.edges().forEach(l=>o(i,l))}function o(i,l){let c=l.v,d=i.node(c).rank,h=l.w,u=i.node(h).rank,f=l.name,m=i.edge(l),g=m.labelRank;if(u===d+1)return;i.removeEdge(l);let b,v,k;for(k=0,++d;d<u;++k,++d)m.points=[],v={width:0,height:0,edgeLabel:m,edgeObj:l,rank:d},b=n.addDummyNode(i,"edge",v,"_d"),d===g&&(v.width=m.width,v.height=m.height,v.dummy="edge-label",v.labelpos=m.labelpos),i.setEdge(c,b,{weight:m.weight},f),k===0&&i.graph().dummyChains.push(b),c=b;i.setEdge(c,h,{weight:m.weight},f)}function a(i){i.graph().dummyChains.forEach(l=>{let c=i.node(l),d=c.edgeLabel,h;for(i.setEdge(c.edgeObj,d);c.dummy;)h=i.successors(l)[0],i.removeNode(l),d.points.push({x:c.x,y:c.y}),c.dummy==="edge-label"&&(d.x=c.x,d.y=c.y,d.width=c.width,d.height=c.height),l=h,c=i.node(l)})}}),po=Je((e,t)=>{var{applyWithChunking:n}=wt();t.exports={longestPath:s,slack:o};function s(a){var i={};function l(c){var d=a.node(c);if(Object.hasOwn(i,c))return d.rank;i[c]=!0;let h=a.outEdges(c).map(f=>f==null?Number.POSITIVE_INFINITY:l(f.w)-a.edge(f).minlen);var u=n(Math.min,h);return u===Number.POSITIVE_INFINITY&&(u=0),d.rank=u}a.sources().forEach(l)}function o(a,i){return a.node(i.w).rank-a.node(i.v).rank-a.edge(i).minlen}}),ru=Je((e,t)=>{var n=nn().Graph,s=po().slack;t.exports=o;function o(c){var d=new n({directed:!1}),h=c.nodes()[0],u=c.nodeCount();d.setNode(h,{});for(var f,m;a(d,c)<u;)f=i(d,c),m=d.hasNode(f.v)?s(c,f):-s(c,f),l(d,c,m);return d}function a(c,d){function h(u){d.nodeEdges(u).forEach(f=>{var m=f.v,g=u===m?f.w:m;!c.hasNode(g)&&!s(d,f)&&(c.setNode(g,{}),c.setEdge(u,g,{}),h(g))})}return c.nodes().forEach(h),c.nodeCount()}function i(c,d){return d.edges().reduce((h,u)=>{let f=Number.POSITIVE_INFINITY;return c.hasNode(u.v)!==c.hasNode(u.w)&&(f=s(d,u)),f<h[0]?[f,u]:h},[Number.POSITIVE_INFINITY,null])[1]}function l(c,d,h){c.nodes().forEach(u=>d.node(u).rank+=h)}}),ix=Je((e,t)=>{var n=ru(),s=po().slack,o=po().longestPath,a=nn().alg.preorder,i=nn().alg.postorder,l=wt().simplify;t.exports=c,c.initLowLimValues=f,c.initCutValues=d,c.calcCutValue=u,c.leaveEdge=g,c.enterEdge=b,c.exchangeEdges=v;function c(w){w=l(w),o(w);var S=n(w);f(S),d(S,w);for(var j,E;j=g(S);)E=b(S,w,j),v(S,w,j,E)}function d(w,S){var j=i(w,w.nodes());j=j.slice(0,j.length-1),j.forEach(E=>h(w,S,E))}function h(w,S,j){var E=w.node(j),C=E.parent;w.edge(j,C).cutvalue=u(w,S,j)}function u(w,S,j){var E=w.node(j),C=E.parent,R=!0,P=S.edge(j,C),T=0;return P||(R=!1,P=S.edge(C,j)),T=P.weight,S.nodeEdges(j).forEach(D=>{var z=D.v===j,I=z?D.w:D.v;if(I!==C){var B=z===R,L=S.edge(D).weight;if(T+=B?L:-L,y(w,j,I)){var q=w.edge(j,I).cutvalue;T+=B?-q:q}}}),T}function f(w,S){arguments.length<2&&(S=w.nodes()[0]),m(w,{},1,S)}function m(w,S,j,E,C){var R=j,P=w.node(E);return S[E]=!0,w.neighbors(E).forEach(T=>{Object.hasOwn(S,T)||(j=m(w,S,j,T,E))}),P.low=R,P.lim=j++,C?P.parent=C:delete P.parent,j}function g(w){return w.edges().find(S=>w.edge(S).cutvalue<0)}function b(w,S,j){var E=j.v,C=j.w;S.hasEdge(E,C)||(E=j.w,C=j.v);var R=w.node(E),P=w.node(C),T=R,D=!1;R.lim>P.lim&&(T=P,D=!0);var z=S.edges().filter(I=>D===x(w,w.node(I.v),T)&&D!==x(w,w.node(I.w),T));return z.reduce((I,B)=>s(S,B)<s(S,I)?B:I)}function v(w,S,j,E){var C=j.v,R=j.w;w.removeEdge(C,R),w.setEdge(E.v,E.w,{}),f(w),d(w,S),k(w,S)}function k(w,S){var j=w.nodes().find(C=>!S.node(C).parent),E=a(w,j);E=E.slice(1),E.forEach(C=>{var R=w.node(C).parent,P=S.edge(C,R),T=!1;P||(P=S.edge(R,C),T=!0),S.node(C).rank=S.node(R).rank+(T?P.minlen:-P.minlen)})}function y(w,S,j){return w.hasEdge(S,j)}function x(w,S,j){return j.low<=S.lim&&S.lim<=j.lim}}),lx=Je((e,t)=>{var n=po(),s=n.longestPath,o=ru(),a=ix();t.exports=i;function i(h){var u=h.graph().ranker;if(u instanceof Function)return u(h);switch(h.graph().ranker){case"network-simplex":d(h);break;case"tight-tree":c(h);break;case"longest-path":l(h);break;case"none":break;default:d(h)}}var l=s;function c(h){s(h),o(h)}function d(h){a(h)}}),cx=Je((e,t)=>{t.exports=n;function n(a){let i=o(a);a.graph().dummyChains.forEach(l=>{let c=a.node(l),d=c.edgeObj,h=s(a,i,d.v,d.w),u=h.path,f=h.lca,m=0,g=u[m],b=!0;for(;l!==d.w;){if(c=a.node(l),b){for(;(g=u[m])!==f&&a.node(g).maxRank<c.rank;)m++;g===f&&(b=!1)}if(!b){for(;m<u.length-1&&a.node(g=u[m+1]).minRank<=c.rank;)m++;g=u[m]}a.setParent(l,g),l=a.successors(l)[0]}})}function s(a,i,l,c){let d=[],h=[],u=Math.min(i[l].low,i[c].low),f=Math.max(i[l].lim,i[c].lim),m,g;m=l;do m=a.parent(m),d.push(m);while(m&&(i[m].low>u||f>i[m].lim));for(g=m,m=c;(m=a.parent(m))!==g;)h.push(m);return{path:d.concat(h.reverse()),lca:g}}function o(a){let i={},l=0;function c(d){let h=l;a.children(d).forEach(c),i[d]={low:h,lim:l++}}return a.children().forEach(c),i}}),dx=Je((e,t)=>{var n=wt();t.exports={run:s,cleanup:l};function s(c){let d=n.addDummyNode(c,"root",{},"_root"),h=a(c),u=Object.values(h),f=n.applyWithChunking(Math.max,u)-1,m=2*f+1;c.graph().nestingRoot=d,c.edges().forEach(b=>c.edge(b).minlen*=m);let g=i(c)+1;c.children().forEach(b=>o(c,d,m,g,f,h,b)),c.graph().nodeRankFactor=m}function o(c,d,h,u,f,m,g){let b=c.children(g);if(!b.length){g!==d&&c.setEdge(d,g,{weight:0,minlen:h});return}let v=n.addBorderNode(c,"_bt"),k=n.addBorderNode(c,"_bb"),y=c.node(g);c.setParent(v,g),y.borderTop=v,c.setParent(k,g),y.borderBottom=k,b.forEach(x=>{o(c,d,h,u,f,m,x);let w=c.node(x),S=w.borderTop?w.borderTop:x,j=w.borderBottom?w.borderBottom:x,E=w.borderTop?u:2*u,C=S!==j?1:f-m[g]+1;c.setEdge(v,S,{weight:E,minlen:C,nestingEdge:!0}),c.setEdge(j,k,{weight:E,minlen:C,nestingEdge:!0})}),c.parent(g)||c.setEdge(d,v,{weight:0,minlen:f+m[g]})}function a(c){var d={};function h(u,f){var m=c.children(u);m&&m.length&&m.forEach(g=>h(g,f+1)),d[u]=f}return c.children().forEach(u=>h(u,1)),d}function i(c){return c.edges().reduce((d,h)=>d+c.edge(h).weight,0)}function l(c){var d=c.graph();c.removeNode(d.nestingRoot),delete d.nestingRoot,c.edges().forEach(h=>{var u=c.edge(h);u.nestingEdge&&c.removeEdge(h)})}}),ux=Je((e,t)=>{var n=wt();t.exports=s;function s(a){function i(l){let c=a.children(l),d=a.node(l);if(c.length&&c.forEach(i),Object.hasOwn(d,"minRank")){d.borderLeft=[],d.borderRight=[];for(let h=d.minRank,u=d.maxRank+1;h<u;++h)o(a,"borderLeft","_bl",l,d,h),o(a,"borderRight","_br",l,d,h)}}a.children().forEach(i)}function o(a,i,l,c,d,h){let u={width:0,height:0,rank:h,borderType:i},f=d[i][h-1],m=n.addDummyNode(a,"border",u,l);d[i][h]=m,a.setParent(m,c),f&&a.setEdge(f,m,{weight:1})}}),fx=Je((e,t)=>{t.exports={adjust:n,undo:s};function n(h){let u=h.graph().rankdir.toLowerCase();(u==="lr"||u==="rl")&&o(h)}function s(h){let u=h.graph().rankdir.toLowerCase();(u==="bt"||u==="rl")&&i(h),(u==="lr"||u==="rl")&&(c(h),o(h))}function o(h){h.nodes().forEach(u=>a(h.node(u))),h.edges().forEach(u=>a(h.edge(u)))}function a(h){let u=h.width;h.width=h.height,h.height=u}function i(h){h.nodes().forEach(u=>l(h.node(u))),h.edges().forEach(u=>{let f=h.edge(u);f.points.forEach(l),Object.hasOwn(f,"y")&&l(f)})}function l(h){h.y=-h.y}function c(h){h.nodes().forEach(u=>d(h.node(u))),h.edges().forEach(u=>{let f=h.edge(u);f.points.forEach(d),Object.hasOwn(f,"x")&&d(f)})}function d(h){let u=h.x;h.x=h.y,h.y=u}}),hx=Je((e,t)=>{var n=wt();t.exports=s;function s(o){let a={},i=o.nodes().filter(u=>!o.children(u).length),l=i.map(u=>o.node(u).rank),c=n.applyWithChunking(Math.max,l),d=n.range(c+1).map(()=>[]);function h(u){if(a[u])return;a[u]=!0;let f=o.node(u);d[f.rank].push(u),o.successors(u).forEach(h)}return i.sort((u,f)=>o.node(u).rank-o.node(f).rank).forEach(h),d}}),mx=Je((e,t)=>{var n=wt().zipObject;t.exports=s;function s(a,i){let l=0;for(let c=1;c<i.length;++c)l+=o(a,i[c-1],i[c]);return l}function o(a,i,l){let c=n(l,l.map((g,b)=>b)),d=i.flatMap(g=>a.outEdges(g).map(b=>({pos:c[b.w],weight:a.edge(b).weight})).sort((b,v)=>b.pos-v.pos)),h=1;for(;h<l.length;)h<<=1;let u=2*h-1;h-=1;let f=new Array(u).fill(0),m=0;return d.forEach(g=>{let b=g.pos+h;f[b]+=g.weight;let v=0;for(;b>0;)b%2&&(v+=f[b+1]),b=b-1>>1,f[b]+=g.weight;m+=g.weight*v}),m}}),px=Je((e,t)=>{t.exports=n;function n(s,o=[]){return o.map(a=>{let i=s.inEdges(a);if(i.length){let l=i.reduce((c,d)=>{let h=s.edge(d),u=s.node(d.v);return{sum:c.sum+h.weight*u.order,weight:c.weight+h.weight}},{sum:0,weight:0});return{v:a,barycenter:l.sum/l.weight,weight:l.weight}}else return{v:a}})}}),gx=Je((e,t)=>{var n=wt();t.exports=s;function s(i,l){let c={};i.forEach((h,u)=>{let f=c[h.v]={indegree:0,in:[],out:[],vs:[h.v],i:u};h.barycenter!==void 0&&(f.barycenter=h.barycenter,f.weight=h.weight)}),l.edges().forEach(h=>{let u=c[h.v],f=c[h.w];u!==void 0&&f!==void 0&&(f.indegree++,u.out.push(c[h.w]))});let d=Object.values(c).filter(h=>!h.indegree);return o(d)}function o(i){let l=[];function c(h){return u=>{u.merged||(u.barycenter===void 0||h.barycenter===void 0||u.barycenter>=h.barycenter)&&a(h,u)}}function d(h){return u=>{u.in.push(h),--u.indegree===0&&i.push(u)}}for(;i.length;){let h=i.pop();l.push(h),h.in.reverse().forEach(c(h)),h.out.forEach(d(h))}return l.filter(h=>!h.merged).map(h=>n.pick(h,["vs","i","barycenter","weight"]))}function a(i,l){let c=0,d=0;i.weight&&(c+=i.barycenter*i.weight,d+=i.weight),l.weight&&(c+=l.barycenter*l.weight,d+=l.weight),i.vs=l.vs.concat(i.vs),i.barycenter=c/d,i.weight=d,i.i=Math.min(l.i,i.i),l.merged=!0}}),xx=Je((e,t)=>{var n=wt();t.exports=s;function s(i,l){let c=n.partition(i,v=>Object.hasOwn(v,"barycenter")),d=c.lhs,h=c.rhs.sort((v,k)=>k.i-v.i),u=[],f=0,m=0,g=0;d.sort(a(!!l)),g=o(u,h,g),d.forEach(v=>{g+=v.vs.length,u.push(v.vs),f+=v.barycenter*v.weight,m+=v.weight,g=o(u,h,g)});let b={vs:u.flat(!0)};return m&&(b.barycenter=f/m,b.weight=m),b}function o(i,l,c){let d;for(;l.length&&(d=l[l.length-1]).i<=c;)l.pop(),i.push(d.vs),c++;return c}function a(i){return(l,c)=>l.barycenter<c.barycenter?-1:l.barycenter>c.barycenter?1:i?c.i-l.i:l.i-c.i}}),bx=Je((e,t)=>{var n=px(),s=gx(),o=xx();t.exports=a;function a(c,d,h,u){let f=c.children(d),m=c.node(d),g=m?m.borderLeft:void 0,b=m?m.borderRight:void 0,v={};g&&(f=f.filter(w=>w!==g&&w!==b));let k=n(c,f);k.forEach(w=>{if(c.children(w.v).length){let S=a(c,w.v,h,u);v[w.v]=S,Object.hasOwn(S,"barycenter")&&l(w,S)}});let y=s(k,h);i(y,v);let x=o(y,u);if(g&&(x.vs=[g,x.vs,b].flat(!0),c.predecessors(g).length)){let w=c.node(c.predecessors(g)[0]),S=c.node(c.predecessors(b)[0]);Object.hasOwn(x,"barycenter")||(x.barycenter=0,x.weight=0),x.barycenter=(x.barycenter*x.weight+w.order+S.order)/(x.weight+2),x.weight+=2}return x}function i(c,d){c.forEach(h=>{h.vs=h.vs.flatMap(u=>d[u]?d[u].vs:u)})}function l(c,d){c.barycenter!==void 0?(c.barycenter=(c.barycenter*c.weight+d.barycenter*d.weight)/(c.weight+d.weight),c.weight+=d.weight):(c.barycenter=d.barycenter,c.weight=d.weight)}}),yx=Je((e,t)=>{var n=nn().Graph,s=wt();t.exports=o;function o(i,l,c,d){d||(d=i.nodes());let h=a(i),u=new n({compound:!0}).setGraph({root:h}).setDefaultNodeLabel(f=>i.node(f));return d.forEach(f=>{let m=i.node(f),g=i.parent(f);(m.rank===l||m.minRank<=l&&l<=m.maxRank)&&(u.setNode(f),u.setParent(f,g||h),i[c](f).forEach(b=>{let v=b.v===f?b.w:b.v,k=u.edge(v,f),y=k!==void 0?k.weight:0;u.setEdge(v,f,{weight:i.edge(b).weight+y})}),Object.hasOwn(m,"minRank")&&u.setNode(f,{borderLeft:m.borderLeft[l],borderRight:m.borderRight[l]}))}),u}function a(i){for(var l;i.hasNode(l=s.uniqueId("_root")););return l}}),wx=Je((e,t)=>{t.exports=n;function n(s,o,a){let i={},l;a.forEach(c=>{let d=s.parent(c),h,u;for(;d;){if(h=s.parent(d),h?(u=i[h],i[h]=d):(u=l,l=d),u&&u!==d){o.setEdge(u,d);return}d=h}})}}),kx=Je((e,t)=>{var n=hx(),s=mx(),o=bx(),a=yx(),i=wx(),l=nn().Graph,c=wt();t.exports=d;function d(m,g={}){if(typeof g.customOrder=="function"){g.customOrder(m,d);return}let b=c.maxRank(m),v=h(m,c.range(1,b+1),"inEdges"),k=h(m,c.range(b-1,-1,-1),"outEdges"),y=n(m);if(f(m,y),g.disableOptimalOrderHeuristic)return;let x=Number.POSITIVE_INFINITY,w,S=g.constraints||[];for(let j=0,E=0;E<4;++j,++E){u(j%2?v:k,j%4>=2,S),y=c.buildLayerMatrix(m);let C=s(m,y);C<x?(E=0,w=Object.assign({},y),x=C):C===x&&(w=structuredClone(y))}f(m,w)}function h(m,g,b){let v=new Map,k=(y,x)=>{v.has(y)||v.set(y,[]),v.get(y).push(x)};for(let y of m.nodes()){let x=m.node(y);if(typeof x.rank=="number"&&k(x.rank,y),typeof x.minRank=="number"&&typeof x.maxRank=="number")for(let w=x.minRank;w<=x.maxRank;w++)w!==x.rank&&k(w,y)}return g.map(function(y){return a(m,y,b,v.get(y)||[])})}function u(m,g,b){let v=new l;m.forEach(function(k){b.forEach(w=>v.setEdge(w.left,w.right));let y=k.graph().root,x=o(k,y,v,g);x.vs.forEach((w,S)=>k.node(w).order=S),i(k,v,x.vs)})}function f(m,g){Object.values(g).forEach(b=>b.forEach((v,k)=>m.node(v).order=k))}}),vx=Je((e,t)=>{var n=nn().Graph,s=wt();t.exports={positionX:b,findType1Conflicts:o,findType2Conflicts:a,addConflict:l,hasConflict:c,verticalAlignment:d,horizontalCompaction:h,alignCoordinates:m,findSmallestWidthAlignment:f,balance:g};function o(y,x){let w={};function S(j,E){let C=0,R=0,P=j.length,T=E[E.length-1];return E.forEach((D,z)=>{let I=i(y,D),B=I?y.node(I).order:P;(I||D===T)&&(E.slice(R,z+1).forEach(L=>{y.predecessors(L).forEach(q=>{let _=y.node(q),A=_.order;(A<C||B<A)&&!(_.dummy&&y.node(L).dummy)&&l(w,q,L)})}),R=z+1,C=B)}),E}return x.length&&x.reduce(S),w}function a(y,x){let w={};function S(E,C,R,P,T){let D;s.range(C,R).forEach(z=>{D=E[z],y.node(D).dummy&&y.predecessors(D).forEach(I=>{let B=y.node(I);B.dummy&&(B.order<P||B.order>T)&&l(w,I,D)})})}function j(E,C){let R=-1,P,T=0;return C.forEach((D,z)=>{if(y.node(D).dummy==="border"){let I=y.predecessors(D);I.length&&(P=y.node(I[0]).order,S(C,T,z,R,P),T=z,R=P)}S(C,T,C.length,P,E.length)}),C}return x.length&&x.reduce(j),w}function i(y,x){if(y.node(x).dummy)return y.predecessors(x).find(w=>y.node(w).dummy)}function l(y,x,w){if(x>w){let j=x;x=w,w=j}let S=y[x];S||(y[x]=S={}),S[w]=!0}function c(y,x,w){if(x>w){let S=x;x=w,w=S}return!!y[x]&&Object.hasOwn(y[x],w)}function d(y,x,w,S){let j={},E={},C={};return x.forEach(R=>{R.forEach((P,T)=>{j[P]=P,E[P]=P,C[P]=T})}),x.forEach(R=>{let P=-1;R.forEach(T=>{let D=S(T);if(D.length){D=D.sort((I,B)=>C[I]-C[B]);let z=(D.length-1)/2;for(let I=Math.floor(z),B=Math.ceil(z);I<=B;++I){let L=D[I];E[T]===T&&P<C[L]&&!c(w,T,L)&&(E[L]=T,E[T]=j[T]=j[L],P=C[L])}}})}),{root:j,align:E}}function h(y,x,w,S,j){let E={},C=u(y,x,w,j),R=j?"borderLeft":"borderRight";function P(z,I){let B=C.nodes().slice(),L={},q=B.pop();for(;q;){if(L[q])z(q);else{L[q]=!0,B.push(q);for(let _ of I(q))B.push(_)}q=B.pop()}}function T(z){E[z]=C.inEdges(z).reduce((I,B)=>Math.max(I,E[B.v]+C.edge(B)),0)}function D(z){let I=C.outEdges(z).reduce((L,q)=>Math.min(L,E[q.w]-C.edge(q)),Number.POSITIVE_INFINITY),B=y.node(z);I!==Number.POSITIVE_INFINITY&&B.borderType!==R&&(E[z]=Math.max(E[z],I))}return P(T,C.predecessors.bind(C)),P(D,C.successors.bind(C)),Object.keys(S).forEach(z=>E[z]=E[w[z]]),E}function u(y,x,w,S){let j=new n,E=y.graph(),C=v(E.nodesep,E.edgesep,S);return x.forEach(R=>{let P;R.forEach(T=>{let D=w[T];if(j.setNode(D),P){var z=w[P],I=j.edge(z,D);j.setEdge(z,D,Math.max(C(y,T,P),I||0))}P=T})}),j}function f(y,x){return Object.values(x).reduce((w,S)=>{let j=Number.NEGATIVE_INFINITY,E=Number.POSITIVE_INFINITY;Object.entries(S).forEach(([R,P])=>{let T=k(y,R)/2;j=Math.max(P+T,j),E=Math.min(P-T,E)});let C=j-E;return C<w[0]&&(w=[C,S]),w},[Number.POSITIVE_INFINITY,null])[1]}function m(y,x){let w=Object.values(x),S=s.applyWithChunking(Math.min,w),j=s.applyWithChunking(Math.max,w);["u","d"].forEach(E=>{["l","r"].forEach(C=>{let R=E+C,P=y[R];if(P===x)return;let T=Object.values(P),D=S-s.applyWithChunking(Math.min,T);C!=="l"&&(D=j-s.applyWithChunking(Math.max,T)),D&&(y[R]=s.mapValues(P,z=>z+D))})})}function g(y,x){return s.mapValues(y.ul,(w,S)=>{if(x)return y[x.toLowerCase()][S];{let j=Object.values(y).map(E=>E[S]).sort((E,C)=>E-C);return(j[1]+j[2])/2}})}function b(y){let x=s.buildLayerMatrix(y),w=Object.assign(o(y,x),a(y,x)),S={},j;["u","d"].forEach(C=>{j=C==="u"?x:Object.values(x).reverse(),["l","r"].forEach(R=>{R==="r"&&(j=j.map(z=>Object.values(z).reverse()));let P=(C==="u"?y.predecessors:y.successors).bind(y),T=d(y,j,w,P),D=h(y,j,T.root,T.align,R==="r");R==="r"&&(D=s.mapValues(D,z=>-z)),S[C+R]=D})});let E=f(y,S);return m(S,E),g(S,y.graph().align)}function v(y,x,w){return(S,j,E)=>{let C=S.node(j),R=S.node(E),P=0,T;if(P+=C.width/2,Object.hasOwn(C,"labelpos"))switch(C.labelpos.toLowerCase()){case"l":T=-C.width/2;break;case"r":T=C.width/2;break}if(T&&(P+=w?T:-T),T=0,P+=(C.dummy?x:y)/2,P+=(R.dummy?x:y)/2,P+=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}return T&&(P+=w?T:-T),T=0,P}}function k(y,x){return y.node(x).width}}),jx=Je((e,t)=>{var n=wt(),s=vx().positionX;t.exports=o;function o(i){i=n.asNonCompoundGraph(i),a(i),Object.entries(s(i)).forEach(([l,c])=>i.node(l).x=c)}function a(i){let l=n.buildLayerMatrix(i),c=i.graph().ranksep,d=i.graph().rankalign,h=0;l.forEach(u=>{let f=u.reduce((m,g)=>{let b=i.node(g).height;return m>b?m:b},0);u.forEach(m=>{let g=i.node(m);d==="top"?g.y=h+g.height/2:d==="bottom"?g.y=h+f-g.height/2:g.y=h+f/2}),h+=f+c})}}),Nx=Je((e,t)=>{var n=ox(),s=ax(),o=lx(),a=wt().normalizeRanks,i=cx(),l=wt().removeEmptyRanks,c=dx(),d=ux(),h=fx(),u=kx(),f=jx(),m=wt(),g=nn().Graph;t.exports=b;function b(M,K={}){let W=K.debugTiming?m.time:m.notime;return W("layout",()=>{let H=W(" buildLayoutGraph",()=>P(M));return W(" runLayout",()=>v(H,W,K)),W(" updateInputGraph",()=>k(M,H)),H})}function v(M,K,W){K(" makeSpaceForEdgeLabels",()=>T(M)),K(" removeSelfEdges",()=>$(M)),K(" acyclic",()=>n.run(M)),K(" nestingGraph.run",()=>c.run(M)),K(" rank",()=>o(m.asNonCompoundGraph(M))),K(" injectEdgeLabelProxies",()=>D(M)),K(" removeEmptyRanks",()=>l(M)),K(" nestingGraph.cleanup",()=>c.cleanup(M)),K(" normalizeRanks",()=>a(M)),K(" assignRankMinMax",()=>z(M)),K(" removeEdgeLabelProxies",()=>I(M)),K(" normalize.run",()=>s.run(M)),K(" parentDummyChains",()=>i(M)),K(" addBorderSegments",()=>d(M)),K(" order",()=>u(M,W)),K(" insertSelfEdges",()=>F(M)),K(" adjustCoordinateSystem",()=>h.adjust(M)),K(" position",()=>f(M)),K(" positionSelfEdges",()=>V(M)),K(" removeBorderNodes",()=>A(M)),K(" normalize.undo",()=>s.undo(M)),K(" fixupEdgeLabelCoords",()=>q(M)),K(" undoCoordinateSystem",()=>h.undo(M)),K(" translateGraph",()=>B(M)),K(" assignNodeIntersects",()=>L(M)),K(" reversePoints",()=>_(M)),K(" acyclic.undo",()=>n.undo(M))}function k(M,K){M.nodes().forEach(W=>{let H=M.node(W),Z=K.node(W);H&&(H.x=Z.x,H.y=Z.y,H.order=Z.order,H.rank=Z.rank,K.children(W).length&&(H.width=Z.width,H.height=Z.height))}),M.edges().forEach(W=>{let H=M.edge(W),Z=K.edge(W);H.points=Z.points,Object.hasOwn(Z,"x")&&(H.x=Z.x,H.y=Z.y)}),M.graph().width=K.graph().width,M.graph().height=K.graph().height}var y=["nodesep","edgesep","ranksep","marginx","marginy"],x={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},w=["acyclicer","ranker","rankdir","align","rankalign"],S=["width","height","rank"],j={width:0,height:0},E=["minlen","weight","width","height","labeloffset"],C={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},R=["labelpos"];function P(M){let K=new g({multigraph:!0,compound:!0}),W=O(M.graph());return K.setGraph(Object.assign({},x,X(W,y),m.pick(W,w))),M.nodes().forEach(H=>{let Z=O(M.node(H)),J=X(Z,S);Object.keys(j).forEach(le=>{J[le]===void 0&&(J[le]=j[le])}),K.setNode(H,J),K.setParent(H,M.parent(H))}),M.edges().forEach(H=>{let Z=O(M.edge(H));K.setEdge(H,Object.assign({},C,X(Z,E),m.pick(Z,R)))}),K}function T(M){let K=M.graph();K.ranksep/=2,M.edges().forEach(W=>{let H=M.edge(W);H.minlen*=2,H.labelpos.toLowerCase()!=="c"&&(K.rankdir==="TB"||K.rankdir==="BT"?H.width+=H.labeloffset:H.height+=H.labeloffset)})}function D(M){M.edges().forEach(K=>{let W=M.edge(K);if(W.width&&W.height){let H=M.node(K.v),Z={rank:(M.node(K.w).rank-H.rank)/2+H.rank,e:K};m.addDummyNode(M,"edge-proxy",Z,"_ep")}})}function z(M){let K=0;M.nodes().forEach(W=>{let H=M.node(W);H.borderTop&&(H.minRank=M.node(H.borderTop).rank,H.maxRank=M.node(H.borderBottom).rank,K=Math.max(K,H.maxRank))}),M.graph().maxRank=K}function I(M){M.nodes().forEach(K=>{let W=M.node(K);W.dummy==="edge-proxy"&&(M.edge(W.e).labelRank=W.rank,M.removeNode(K))})}function B(M){let K=Number.POSITIVE_INFINITY,W=0,H=Number.POSITIVE_INFINITY,Z=0,J=M.graph(),le=J.marginx||0,ue=J.marginy||0;function pe(we){let Ne=we.x,ke=we.y,Be=we.width,et=we.height;K=Math.min(K,Ne-Be/2),W=Math.max(W,Ne+Be/2),H=Math.min(H,ke-et/2),Z=Math.max(Z,ke+et/2)}M.nodes().forEach(we=>pe(M.node(we))),M.edges().forEach(we=>{let Ne=M.edge(we);Object.hasOwn(Ne,"x")&&pe(Ne)}),K-=le,H-=ue,M.nodes().forEach(we=>{let Ne=M.node(we);Ne.x-=K,Ne.y-=H}),M.edges().forEach(we=>{let Ne=M.edge(we);Ne.points.forEach(ke=>{ke.x-=K,ke.y-=H}),Object.hasOwn(Ne,"x")&&(Ne.x-=K),Object.hasOwn(Ne,"y")&&(Ne.y-=H)}),J.width=W-K+le,J.height=Z-H+ue}function L(M){M.edges().forEach(K=>{let W=M.edge(K),H=M.node(K.v),Z=M.node(K.w),J,le;W.points?(J=W.points[0],le=W.points[W.points.length-1]):(W.points=[],J=Z,le=H),W.points.unshift(m.intersectRect(H,J)),W.points.push(m.intersectRect(Z,le))})}function q(M){M.edges().forEach(K=>{let W=M.edge(K);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 _(M){M.edges().forEach(K=>{let W=M.edge(K);W.reversed&&W.points.reverse()})}function A(M){M.nodes().forEach(K=>{if(M.children(K).length){let W=M.node(K),H=M.node(W.borderTop),Z=M.node(W.borderBottom),J=M.node(W.borderLeft[W.borderLeft.length-1]),le=M.node(W.borderRight[W.borderRight.length-1]);W.width=Math.abs(le.x-J.x),W.height=Math.abs(Z.y-H.y),W.x=J.x+W.width/2,W.y=H.y+W.height/2}}),M.nodes().forEach(K=>{M.node(K).dummy==="border"&&M.removeNode(K)})}function $(M){M.edges().forEach(K=>{if(K.v===K.w){var W=M.node(K.v);W.selfEdges||(W.selfEdges=[]),W.selfEdges.push({e:K,label:M.edge(K)}),M.removeEdge(K)}})}function F(M){var K=m.buildLayerMatrix(M);K.forEach(W=>{var H=0;W.forEach((Z,J)=>{var le=M.node(Z);le.order=J+H,(le.selfEdges||[]).forEach(ue=>{m.addDummyNode(M,"selfedge",{width:ue.label.width,height:ue.label.height,rank:le.rank,order:J+ ++H,e:ue.e,label:ue.label},"_se")}),delete le.selfEdges})})}function V(M){M.nodes().forEach(K=>{var W=M.node(K);if(W.dummy==="selfedge"){var H=M.node(W.e.v),Z=H.x+H.width/2,J=H.y,le=W.x-Z,ue=H.height/2;M.setEdge(W.e,W.label),M.removeNode(K),W.label.points=[{x:Z+2*le/3,y:J-ue},{x:Z+5*le/6,y:J-ue},{x:Z+le,y:J},{x:Z+5*le/6,y:J+ue},{x:Z+2*le/3,y:J+ue}],W.label.x=W.x,W.label.y=W.y}})}function X(M,K){return m.mapValues(m.pick(M,K),Number)}function O(M){var K={};return M&&Object.entries(M).forEach(([W,H])=>{typeof W=="string"&&(W=W.toLowerCase()),K[W]=H}),K}}),Sx=Je((e,t)=>{var n=wt(),s=nn().Graph;t.exports={debugOrdering:o};function o(a){let i=n.buildLayerMatrix(a),l=new s({compound:!0,multigraph:!0}).setGraph({});return a.nodes().forEach(c=>{l.setNode(c,{label:c}),l.setParent(c,"layer"+a.node(c).rank)}),a.edges().forEach(c=>l.setEdge(c.v,c.w,{},c.name)),i.forEach((c,d)=>{let h="layer"+d;l.setNode(h,{rank:"same"}),c.reduce((u,f)=>(l.setEdge(u,f,{style:"invis"}),f))}),l}}),Cx=Je((e,t)=>{t.exports="2.0.4"}),Ex=Je((e,t)=>{t.exports={graphlib:nn(),layout:Nx(),debug:Sx(),util:{time:wt().time,notime:wt().notime},version:Cx()}});const ql=Ex();const zl={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"}},Ix={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function Tx({data:e}){const{t}=Ve(["work","common"]),{task:n,agentName:s,selected:o,direction:a="TB",isExpandedRoot:i,onCollapse:l}=e,c=zl[n.status]??zl.pending,d=n.taskType==="scheduled"&&!!n.scheduleConfig,h=d?n.scheduleConfig.every?t("work:task.everyInterval",{interval:n.scheduleConfig.every}):n.scheduleConfig.cron?t("work:task.cronLabel"):"":"",u=a==="LR"?ve.Left:ve.Top,f=a==="LR"?ve.Right:ve.Bottom;return r.jsxs("div",{className:`relative rounded-lg border px-3 py-2 min-w-[180px] max-w-[220px] shadow-md backdrop-blur-sm ${d?`${c.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${c.bg} ${c.border}`} ${o?"ring-2 ring-brand-500 shadow-brand-500/25 shadow-lg":""}`,children:[r.jsx(Ln,{type:"target",position:u,className:"!bg-border-default !w-2 !h-2"}),r.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[r.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${Ix[n.priority]??"bg-gray-500"}`}),r.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${c.text}`,children:t(`work:status.task.${n.status}`,{defaultValue:n.status.replace("_"," ")})}),d&&r.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:[r.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:r.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]})]}),r.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:n.title}),s&&r.jsx("div",{className:"text-[10px] text-fg-tertiary truncate",children:s}),n.blockedBy&&n.blockedBy.length>0&&r.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:t("work:dag.depCount",{count:n.blockedBy.length})}),r.jsx(Ln,{type:"source",position:f,className:"!bg-border-default !w-2 !h-2"}),i&&l&&r.jsx("button",{onClick:m=>{m.stopPropagation(),l()},className:"absolute top-1/2 -translate-y-1/2 -right-7 w-5 h-5 rounded-full bg-surface-secondary border border-border-default flex items-center justify-center text-fg-tertiary hover:text-fg-primary hover:bg-surface-overlay transition-colors shadow-sm",title:t("work:dag.backToOverview"),children:r.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})})]})}const Fl={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"}},Hl={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done",archived:"done"};function Mx({data:e}){const{t}=Ve(["work","common"]),{req:n,selected:s,direction:o="TB",isExpandedRoot:a,onCollapse:i}=e,l=Fl[n.status]??Fl.pending,c=o==="LR"?ve.Left:ve.Top,d=o==="LR"?ve.Right:ve.Bottom;return r.jsxs("div",{className:`relative rounded-lg border-2 border-dashed px-3 py-2 min-w-[180px] max-w-[220px] shadow-lg ${l.bg} ${l.border} ${s?"ring-2 ring-brand-500 shadow-brand-500/25":""}`,children:[r.jsx(Ln,{type:"target",position:c,className:"!bg-border-default !w-2 !h-2"}),r.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[r.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:t("work:dag.reqLabel")}),r.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${l.text}`,children:t(`work:status.requirement.${n.status}`,{defaultValue:n.status.replace("_"," ")})})]}),r.jsx("div",{className:"text-xs font-medium text-fg-primary leading-snug line-clamp-2 mb-1",children:n.title}),n.taskIds.length>0&&r.jsx("div",{className:"text-[10px] text-fg-tertiary",children:t("work:dag.taskCount",{count:n.taskIds.length})}),r.jsx(Ln,{type:"source",position:d,className:"!bg-border-default !w-2 !h-2"}),a&&i&&r.jsx("button",{onClick:h=>{h.stopPropagation(),i()},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:t("work:dag.backToOverview"),children:r.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})})]})}const Ax={task:Tx,requirement:Mx};function Lx({nodeIds:e,rfRef:t}){const n=Cg();return p.useEffect(()=>{if(e.length===0)return;const s=setTimeout(()=>{n(e),requestAnimationFrame(()=>{t.current?.fitView({padding:.2})})},300);return()=>clearTimeout(s)},[e.length]),null}const _x=()=>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,Rx=e=>{const t=new MutationObserver(e);t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]});const n=window.matchMedia("(prefers-color-scheme: light)");return n.addEventListener("change",e),()=>{t.disconnect(),n.removeEventListener("change",e)}};function Dx(){return p.useSyncExternalStore(Rx,_x,()=>!1)}const oo=200,ao=80;function Vl(e,t,n="TB"){const s=a=>{const i=new ql.graphlib.Graph;i.setDefaultEdgeLabel(()=>({})),i.setGraph({rankdir:a,nodesep:40,ranksep:60});for(const l of e)i.setNode(l.id,{width:oo,height:ao});for(const l of t)i.setEdge(l.source,l.target);return ql.layout(i),e.map(l=>{const c=i.node(l.id);return{...l,position:{x:(c?.x??0)-oo/2,y:(c?.y??0)-ao/2}}})},o=s(n);if(t.length>0&&e.length>4){let a=1/0,i=-1/0,l=1/0,c=-1/0;for(const f of o)a=Math.min(a,f.position.x),i=Math.max(i,f.position.x+oo),l=Math.min(l,f.position.y),c=Math.max(c,f.position.y+ao);const d=i-a,h=c-l,u=n==="TB"?"LR":"TB";if(d>h*3)return{nodes:s(u),direction:u}}return{nodes:o,direction:n}}function Ox(e,t){const n=new Map,s=new Map;for(const i of e)s.set(i.id,i),n.set(i.id,new Set);for(const i of t)n.get(i.source)?.add(i.target),n.get(i.target)?.add(i.source);const o=new Set,a=[];for(const i of e){if(o.has(i.id))continue;const l=new Set,c=[i.id];for(;c.length>0;){const d=c.pop();if(!o.has(d)){o.add(d),l.add(d);for(const h of n.get(d)??[])o.has(h)||c.push(h)}}a.push({nodes:e.filter(d=>l.has(d.id)),edges:t.filter(d=>l.has(d.source)&&l.has(d.target))})}return a}function Wl(e,t){if(e.length===0)return{nodes:[],direction:"TB"};const n=Ox(e,t);if(n.length===1)return Vl(e,t);let s="TB";const o=n.map(f=>{const{nodes:m,direction:g}=Vl(f.nodes,f.edges);s=g;let b=1/0,v=-1/0,k=1/0,y=-1/0;for(const x of m)b=Math.min(b,x.position.x),v=Math.max(v,x.position.x+oo),k=Math.min(k,x.position.y),y=Math.max(y,x.position.y+ao);for(const x of m)x.position.x-=b,x.position.y-=k;return{nodes:m,w:v-b,h:y-k}});o.sort((f,m)=>m.h-f.h);const a=60,i=o.reduce((f,m)=>f+(m.w+a)*(m.h+a),0),l=Math.sqrt(i)*1.1,c=[];let d=0,h=0,u=0;for(const f of o){d>0&&d+f.w>l&&(d=0,h+=u+a,u=0);for(const m of f.nodes)c.push({...m,position:{x:m.position.x+d,y:m.position.y+h}});d+=f.w+a,u=Math.max(u,f.h)}return{nodes:c,direction:s}}function $x(e,t,n){const s=new Set,o=[t];for(;o.length>0;){const a=o.pop();if(a===n)return!0;if(s.has(a))continue;s.add(a);const i=e.get(a);if(i?.blockedBy)for(const l of i.blockedBy)o.push(l)}return!1}const vs=[{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(Fc),color:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"}}];new Set(vs.map(e=>e.id));const Yr=new Set(vs.filter(e=>e.id!=="done").map(e=>e.id)),ra=e=>e.status==="archived";function Px(e,t,n,s){const o=new Set,a=[e];for(;a.length>0;){const i=a.pop();if(!o.has(i))if(o.add(i),i.startsWith("req-")){const l=n.get(i.slice(4));if(l)for(const c of l.taskIds)a.push(c)}else{const l=t.get(i);if(l?.blockedBy)for(const c of l.blockedBy)a.push(c);l?.requirementId&&a.push(`req-${l.requirementId}`)}}for(const i of s)i.requirementId&&o.has(i.id)&&o.add(`req-${i.requirementId}`);return o}function Bx({tasks:e,requirements:t=[],agents:n,showArchived:s,onShowArchivedChange:o,onTaskClick:a,onReqClick:i,onCollapseDAG:l,onDependencyChange:c,selectedTaskId:d,selectedReqId:h,hasDetailPanel:u,defaultExpandedNodeId:f,previewMode:m}){const{t:g}=Ve(["work","common"]),b=Dx(),[v,k]=p.useState(null),[y,x]=p.useState(null),[w,S]=p.useState(()=>new Set(Yr)),[j,E]=p.useState(f??null),[C,R]=p.useState(s??!1),P=s??C,T=p.useCallback(ee=>{const ne=typeof ee=="function"?ee(P):ee;R(ne),o?.(ne)},[P,o]);p.useEffect(()=>{s!==void 0&&R(s)},[s]),p.useEffect(()=>{f&&E(f)},[f]);const D=p.useMemo(()=>e.filter(ee=>ra(ee)).length,[e]),z=p.useMemo(()=>{const ee=new Set;for(const ne of vs)if(w.has(ne.id))for(const oe of ne.statuses)ee.add(oe);return ee},[w]),I=p.useMemo(()=>{const ee=new Set;for(const ne of e)for(const oe of vs)if(oe.statuses.has(ne.status)){ee.add(oe.id);break}for(const ne of t){const oe=Hl[ne.status];oe&&ee.add(oe)}return vs.filter(ne=>ee.has(ne.id))},[e,t]),B=p.useCallback(ee=>{S(ne=>{const oe=new Set(ne);return oe.has(ee)?oe.delete(ee):oe.add(ee),oe})},[]),L=p.useCallback((ee,ne="success")=>{k({msg:ee,type:ne}),setTimeout(()=>k(null),2500)},[]),q=p.useMemo(()=>{const ee=new Map;for(const ne of n)ee.set(ne.id,ne.name);return ee},[n]),_=p.useMemo(()=>{const ee=new Map;for(const ne of e)ee.set(ne.id,ne);return ee},[e]),A=p.useMemo(()=>{const ee=new Map;for(const ne of t)ee.set(ne.id,ne);return ee},[t]),$=p.useRef(!1),F=p.useCallback(()=>{$.current=!1,E(null),l?.()},[l]),V=b?"#94a3b8":"#6b7280",X=p.useCallback((ee,ne,oe)=>({id:`${ee}->${ne}`,source:ee,target:ne,animated:oe==="blocked",markerEnd:{type:Ms.ArrowClosed,width:14,height:14,color:oe==="blocked"?"#ef4444":V},style:{stroke:oe==="blocked"?"#ef4444":V,strokeWidth:1.5,cursor:"pointer"}}),[V]),{initialNodes:O,initialEdges:M,topLevelIds:K}=p.useMemo(()=>{const ee=(de,xe)=>{const Ce=new Set,ze=de.map(Fe=>(Ce.add(Fe.id),{id:Fe.id,type:"task",data:{task:Fe,agentName:Fe.assignedAgentId?q.get(Fe.assignedAgentId):void 0,selected:Fe.id===d},position:{x:0,y:0}}));for(const Fe of xe){const dt=`req-${Fe.id}`;Ce.add(dt),ze.push({id:dt,type:"requirement",data:{req:Fe,selected:Fe.id===h},position:{x:0,y:0}})}const vt=[];for(const Fe of de)if(Fe.blockedBy)for(const dt of Fe.blockedBy)Ce.has(dt)&&vt.push(X(dt,Fe.id,Fe.status));const Yt=new Set,jt=(Fe,dt)=>{const It=`${Fe}->${dt}`;Yt.has(It)||(Yt.add(It),vt.push({id:It,source:Fe,target:dt,markerEnd:{type:Ms.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Fe of xe){const dt=`req-${Fe.id}`;for(const It of Fe.taskIds)Ce.has(It)&&jt(dt,It)}for(const Fe of de)if(Fe.requirementId){const dt=`req-${Fe.requirementId}`;Ce.has(dt)&&jt(dt,Fe.id)}return{nodes:ze,edges:vt}},ne=e.filter(de=>z.has(de.status)&&(P||!ra(de))),oe=new Set;for(const de of vs)w.has(de.id)&&oe.add(de.id);const je=t.filter(de=>{const xe=Hl[de.status];return xe&&oe.has(xe)}),ye=new Set(je.filter(de=>!Hc.has(de.status)).map(de=>de.id)),Se=new Set;for(const de of t)if(ye.has(de.id))for(const xe of de.taskIds)Se.add(xe);const Te=e.filter(de=>Se.has(de.id)&&(P||!ra(de))),st=[...new Map([...ne,...Te].map(de=>[de.id,de])).values()],{nodes:qe,edges:te}=ee(st,je),Re=new Set;for(const de of te)Re.add(de.target);const Ue=new Set(qe.filter(de=>!Re.has(de.id)).map(de=>de.id)),mt=(()=>{if(!j)return null;const{nodes:de,edges:xe}=ee(e,t);return de.some(Ce=>Ce.id===j)?{allNodes:de,allEdges:xe}:null})();if(!j||!mt){const de=qe,{nodes:xe,direction:Ce}=Wl(de,te);return{initialNodes:xe.map(vt=>({...vt,data:{...vt.data,direction:Ce}})),initialEdges:te,topLevelIds:Ue}}const{allNodes:Qe,allEdges:Ae}=mt,Pe=Px(j,_,A,e),Ge=Qe.filter(de=>Pe.has(de.id)).map(de=>de.id===j?{...de,data:{...de.data,isExpandedRoot:!0,onCollapse:F}}:de),at=Ae.filter(de=>Pe.has(de.source)&&Pe.has(de.target)),{nodes:G,direction:ie}=Wl(Ge,at);return{initialNodes:G.map(de=>({...de,data:{...de.data,direction:ie}})),initialEdges:at,topLevelIds:Ue}},[e,t,q,_,A,X,z,w,P,d,h,j,F]),[W,H,Z]=Eg(O),[J,le,ue]=Ig(M),pe=p.useRef(null),we=p.useRef({groupFilter:w,showArchived:P});p.useEffect(()=>{const ee=we.current;(ee.groupFilter!==w||ee.showArchived!==P)&&($.current=!1,E(null),we.current={groupFilter:w,showArchived:P})},[w,P]),p.useEffect(()=>{H(O),le(M),$.current||requestAnimationFrame(()=>{pe.current?.fitView({padding:.2,duration:300})})},[O,M,H,le]),p.useEffect(()=>{const ee=setTimeout(()=>{pe.current?.fitView({padding:.2,duration:300})},50);return()=>clearTimeout(ee)},[u]);const Ne=p.useCallback(ee=>{ee&&($.current=!0)},[]),ke=p.useCallback((ee,ne)=>{if(!j&&K.has(ne.id)&&($.current=!1,E(ne.id)),ne.id.startsWith("req-")){const oe=A.get(ne.id.slice(4));oe&&i&&i(oe)}else{const oe=_.get(ne.id);oe&&a&&a(oe)}},[_,A,a,i,K,j]),Be=p.useCallback(async ee=>{const{source:ne,target:oe}=ee;if(!ne||!oe||ne===oe)return;const je=_.get(oe);if(!je)return;if(je.blockedBy?.includes(ne)){L(g("work:dag.toast.dependencyExists"),"error");return}if($x(_,ne,oe)){L(g("work:dag.toast.cycleError"),"error");return}const ye=[...je.blockedBy??[],ne];try{await se.tasks.update(oe,{blockedBy:ye}),L(g("work:dag.toast.dependencyAdded")),c?.()}catch(Se){L(g("work:dag.toast.failed",{message:Se instanceof Error?Se.message:String(Se)}),"error")}},[_,L,c,g]),et=p.useCallback((ee,ne)=>{x(ne)},[]),Ee=p.useCallback(async()=>{if(!y)return;const ee=_.get(y.target);if(!ee){x(null);return}const ne=(ee.blockedBy??[]).filter(oe=>oe!==y.source);try{await se.tasks.update(y.target,{blockedBy:ne}),L(g("work:dag.toast.dependencyRemoved")),c?.()}catch(oe){L(g("work:dag.toast.failed",{message:oe instanceof Error?oe.message:String(oe)}),"error")}x(null)},[y,_,L,c,g]),Ke=p.useRef(null),[ot,_e]=p.useState(null);if(p.useEffect(()=>{let ee=document;const ne=()=>{const ye=Ke.current;if(!ye){_e(null);return}let Se=ye.parentElement;for(;Se;){const Ae=getComputedStyle(Se).overflowY;if((Ae==="auto"||Ae==="scroll")&&Se.clientHeight>0)break;Se=Se.parentElement}if(!document.documentElement.classList.contains("mobile-doc-scroll")&&!(Se!==null)){_e(null);return}const qe=Se?Se.clientHeight:window.innerHeight,te=Se?Se.getBoundingClientRect().top:0,Re=Se?Se.scrollTop:window.scrollY,mt=ye.getBoundingClientRect().top-te+Re,Qe=Math.min(qe,window.innerHeight)-mt-8;_e(Math.max(320,Math.round(Qe))),Se&&ee!==Se&&(oe.disconnect(),oe.observe(Se),ee=Se)},oe=new ResizeObserver(ne);ne(),oe.observe(document.documentElement),window.addEventListener("resize",ne);const je=new MutationObserver(ne);return je.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>{window.removeEventListener("resize",ne),oe.disconnect(),je.disconnect()}},[]),p.useEffect(()=>{if(ot===null)return;const ee=requestAnimationFrame(()=>{pe.current?.fitView({padding:.2})});return()=>cancelAnimationFrame(ee)},[ot]),e.length===0)return r.jsx("div",{className:"doc-scroll-viewport flex-1 flex items-center justify-center",children:r.jsxs("div",{className:"flex flex-col items-center gap-3 max-w-sm text-center",children:[r.jsx("svg",{className:"w-10 h-10 text-fg-muted",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),r.jsx("p",{className:"text-sm font-medium text-fg-secondary",children:g("work:task.dagEmptyTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:g("work:task.dagEmptyDesc")})]})});const re=w.size===Yr.size&&[...Yr].every(ee=>w.has(ee))&&!P,he=y?_.get(y.source):null,ge=y?_.get(y.target):null;return r.jsxs("div",{ref:Ke,className:"doc-scroll-viewport flex-1 min-h-0 relative",style:{height:ot??"100%"},children:[r.jsxs(Sg,{nodes:W,edges:J,onNodesChange:Z,onEdgesChange:ue,onNodeClick:ke,onConnect:Be,onEdgeClick:et,onMoveEnd:Ne,onInit:ee=>{pe.current=ee},nodeTypes:Ax,fitView:!0,minZoom:.08,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[m&&r.jsx(Lx,{nodeIds:W.map(ee=>ee.id),rfRef:pe}),r.jsx(_g,{color:b?"#cbd5e1":"#374151",gap:20,size:1}),r.jsx(qg,{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"}),r.jsx(Jg,{nodeColor:ee=>{const ne=ee.data?.task,oe=ne?.status;return ne?.taskType==="scheduled"?"#8b8fa3":oe==="completed"||oe==="accepted"?"#10b981":oe==="in_progress"?"#f59e0b":oe==="blocked"||oe==="failed"?"#ef4444":b?"#94a3b8":"#6b7280"},maskColor:b?"rgba(255,255,255,0.7)":"rgba(0,0,0,0.7)",className:"!bg-surface-secondary !border-border-default"})]}),r.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:[r.jsxs("div",{className:"flex items-center gap-1 flex-wrap justify-center",children:[I.map(ee=>{const ne=w.has(ee.id);return r.jsx("button",{onClick:()=>B(ee.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${ne?`${ee.color.bg} ${ee.color.border} ${ee.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:g(`work:dag.filter.${ee.id}`)},ee.id)}),D>0&&r.jsx("button",{onClick:()=>T(ee=>!ee),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${P?"bg-surface-overlay/60 border-gray-500/50 text-fg-secondary":"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:g("work:dag.archivedToggle",{count:D})}),!re&&r.jsx("button",{onClick:()=>{S(new Set(Yr)),T(!1)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary px-1",children:g("work:dag.reset")})]}),r.jsxs("div",{className:"text-[10px] text-fg-tertiary select-none flex items-center gap-2",children:[j?r.jsx("button",{onClick:F,className:"text-brand-500 hover:text-brand-400 transition-colors",children:g("work:dag.backToOverview")}):r.jsx("span",{children:g("work:dag.expandHint")}),r.jsx("span",{className:"text-fg-tertiary/50",children:"·"}),r.jsx("span",{children:g("work:dag.dragHint")})]})]}),v&&r.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 ${v.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:v.msg}),y&&r.jsx("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-50 backdrop-blur-[2px]",onClick:()=>x(null),children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:ee=>ee.stopPropagation(),children:[r.jsx("h4",{className:"text-sm font-semibold text-fg-primary mb-2",children:g("work:dag.removeDependencyTitle")}),r.jsx("p",{className:"text-xs text-fg-secondary mb-4 leading-relaxed",children:g("work:dag.removeDependencyBody",{target:ge?.title??y.target.slice(-8),source:he?.title??y.source.slice(-8)})}),r.jsxs("div",{className:"flex justify-end gap-2",children:[r.jsx("button",{onClick:()=>x(null),className:"px-3 py-1.5 text-xs text-fg-secondary hover:text-fg-primary bg-surface-elevated rounded-lg border border-border-default hover:border-gray-600 transition-colors",children:g("common:cancel")}),r.jsx("button",{onClick:Ee,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:g("common:remove")})]})]})})]})}const va="grid grid-cols-[auto_1fr] gap-x-3 gap-y-3.5 items-start",ou="grid grid-cols-[auto_1fr] sm:grid-cols-[auto_1fr_auto_1fr] gap-x-5 gap-y-3 items-start",lt="pt-2 text-sm text-fg-secondary whitespace-nowrap",xn="w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",oa="shrink-0 whitespace-nowrap text-[11px] font-medium text-brand-500 hover:text-brand-400";function qx(e){return/^(https?:\/\/|git@|ssh:\/\/|git:\/\/)/i.test(e)}function Kl({orgId:e,onCreated:t,onClose:n}){const{t:s}=Ve(["work","common"]);If(!0);const[o,a]=p.useState(""),[i,l]=p.useState(""),[c,d]=p.useState(""),[h,u]=p.useState("main"),[f,m]=p.useState(!1),[g,b]=p.useState(""),[v,k]=p.useState(!1),y=gr();p.useEffect(()=>{const S=j=>{j.key==="Escape"&&n()};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[n]);const x=p.useCallback(async S=>{if(S?.preventDefault(),k(!0),!(!o.trim()||f)){m(!0),b("");try{const j=c.trim(),E=j?[{...qx(j)?{url:j}:{localPath:j},defaultBranch:h.trim()||"main",role:"primary"}]:[],C=await se.projects.create({name:o.trim(),description:i.trim()||void 0,repositories:E.length>0?E:void 0,orgId:e??"default"});t(C.project)}catch(j){b(j instanceof Error?j.message:s("project.failedToCreate"))}m(!1)}},[o,i,c,h,e,f,t,s]),w=v&&!o.trim();return Tf.createPortal(r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-3",onClick:n,children:r.jsxs("form",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 shadow-2xl max-h-[90dvh] overflow-y-auto space-y-4 ${y?"w-full":"w-[26rem]"}`,onClick:S=>S.stopPropagation(),onSubmit:x,children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("project.newProject")}),r.jsxs("div",{className:va,children:[r.jsx("label",{className:lt,children:s("project.projectName")}),r.jsxs("div",{children:[r.jsx("input",{value:o,onChange:S=>{a(S.target.value),b("")},onBlur:()=>k(!0),placeholder:s("project.projectNamePlaceholder"),className:`${xn} ${w?"!border-red-500":""}`,autoFocus:!y}),w&&r.jsx("p",{className:"text-[11px] text-red-400 mt-1",children:s("project.projectNameRequired")})]}),r.jsx("label",{className:lt,children:s("project.description")}),r.jsx("textarea",{value:i,onChange:S=>l(S.target.value),placeholder:s("project.descriptionPlaceholder"),className:`${xn} resize-none`,rows:2}),r.jsx("label",{className:lt,children:s("project.repositoryUrl")}),r.jsx("input",{value:c,onChange:S=>d(S.target.value),placeholder:s("project.repositoryPlaceholder"),className:`${xn} placeholder:text-[11px]`}),c.trim()&&r.jsxs(r.Fragment,{children:[r.jsx("label",{className:lt,children:s("project.branch")}),r.jsx("input",{value:h,onChange:S=>u(S.target.value),placeholder:s("project.branchPlaceholder"),className:xn})]})]}),g&&r.jsx("div",{className:"text-xs text-red-400 bg-red-500/10 rounded-lg px-3 py-2",children:g}),r.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[r.jsx("button",{type:"button",onClick:n,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:s("common:cancel")}),r.jsx("button",{type:"submit",disabled:!o.trim()||f,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-on-brand",children:s(f?"common:creating":"project.createProject")})]})]})}),document.body)}function zx({projects:e,selectedProjectId:t,allSelected:n,taskCounts:s,totalTaskCount:o,onSelectAll:a,onSelectProject:i,onEditProject:l,onCreateProject:c,onCollapse:d,width:h,onResizeStart:u,hidden:f,focused:m,onActivate:g}){const{t:b}=Ve(["work","common"]),v=n??t==null;return r.jsxs(r.Fragment,{children:[r.jsxs("div",{"data-keyboard-pane":"l1",onPointerDown:()=>g?.(),className:"bg-surface-primary flex flex-col shrink-0 border-r border-border-default/60",style:f?{display:"none"}:h!=null?{width:h}:void 0,children:[r.jsxs("div",{"data-electron-drag":!0,className:"px-3 h-14 flex items-center shrink-0 gap-2",children:[d&&r.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:b("common:shortcuts.toggleLeft"),children:r.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),r.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),r.jsx("h2",{className:"text-sm font-semibold text-fg-primary truncate",children:b("work:task.projects",{defaultValue:"Projects"})}),r.jsx("button",{type:"button","data-no-drag":!0,onClick:c,className:"ml-auto w-7 h-7 flex items-center justify-center rounded-md text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated transition-colors",title:b("work:project.newProject"),children:r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),r.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),r.jsx("div",{className:"flex-1 overflow-y-auto px-2 pb-3 space-y-0.5",children:e.length===0?r.jsxs("div",{className:"px-2 py-8 text-center space-y-3",children:[r.jsx("div",{className:"w-10 h-10 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:r.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:r.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"})})}),r.jsx("p",{className:"text-[11px] text-fg-tertiary leading-relaxed px-1",children:b("work:task.emptyNoProjectsHint")}),r.jsx("button",{type:"button",onClick:c,className:"inline-flex items-center gap-1 px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-on-brand rounded-lg font-medium transition-colors",children:b("work:project.newProject")})]}):r.jsxs(r.Fragment,{children:[a&&r.jsxs("button",{type:"button","data-project-id":"__all__",onClick:a,className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-left transition-colors ${v?m?"bg-brand-500/20 ring-1 ring-brand-500/40 text-brand-500":"bg-brand-500/15 text-brand-600":"text-fg-secondary hover:bg-surface-elevated hover:text-fg-primary"}`,children:[r.jsx("span",{className:`w-7 h-7 rounded-md flex items-center justify-center shrink-0 ${v?"bg-brand-600 text-on-brand":"bg-surface-overlay text-fg-secondary"}`,children:r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),r.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),r.jsx("rect",{x:"14",y:"14",width:"7",height:"7"}),r.jsx("rect",{x:"3",y:"14",width:"7",height:"7"})]})}),r.jsx("span",{className:"min-w-0 flex-1",children:r.jsx("span",{className:"block text-[12px] font-medium truncate",children:b("work:task.all")})}),(o??0)>0&&r.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:o})]}),[...e].sort((k,y)=>{const x=k.status==="archived"?1:0,w=y.status==="archived"?1:0;return x-w}).map(k=>{const y=!v&&k.id===t,x=s[k.id]??0,w=k.status==="paused",S=k.status==="archived";return r.jsxs("div",{role:"button",tabIndex:0,"data-project-id":k.id,onClick:()=>i(k.id),onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),i(k.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?m?"bg-brand-500/20 ring-1 ring-brand-500/40 text-brand-500":"bg-brand-500/15 text-brand-600":"text-fg-secondary hover:bg-surface-elevated hover:text-fg-primary"}`,children:[r.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-on-brand":"bg-surface-overlay text-fg-secondary"}`,children:k.name[0]?.toUpperCase()??"?"}),r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsx("span",{className:"block text-[12px] font-medium truncate",children:k.name}),S&&r.jsx("span",{className:"block text-[10px] text-fg-tertiary italic",children:b("work:project.statusArchived")}),w&&r.jsx("span",{className:"block text-[10px] text-amber-500/80",children:b("work:project.statusPaused")})]}),l&&r.jsx("button",{type:"button","data-no-drag":!0,title:b("work:project.editProject"),"aria-label":b("work:project.editProject"),onClick:j=>{j.stopPropagation(),l(k.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:r.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),x>0&&r.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:x})]},k.id)})]})})]}),!f&&u&&r.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:u,children:r.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 Fx({project:e,onUpdateProject:t}){const{t:n}=Ve(["work","common"]),s=e.knowledgeBasePaths??[],[o,a]=p.useState(""),[i,l]=p.useState(!1),[c,d]=p.useState(!0),[h,u]=p.useState([]),[f,m]=p.useState(null),[g,b]=p.useState(null),v=p.useCallback(async()=>{if(e.id){d(!0);try{const{results:C}=await se.deliverables.search({projectId:e.id,source:"knowledge",limit:200});u(C)}catch(C){m({type:"error",text:`${n("work:project.kbLoadFailed")}: ${String(C)}`})}finally{d(!1)}}},[e.id,n]);p.useEffect(()=>{v()},[v]);const k=async()=>{const C=o.trim();if(!(!C||i))try{const R=[...new Set([...s,C])];await t({knowledgeBasePaths:R}),a(""),await S()}catch(R){m({type:"error",text:`${n("work:project.kbPathsSaveFailed")}: ${String(R)}`})}},y=async()=>{const C=g;if(!C||i)return;b(null);const R=s.filter(P=>P!==C);await t({knowledgeBasePaths:R}),await S(R)},x=typeof window<"u"&&!!window.markusDesktop?.selectDirectory,w=async()=>{try{const C=await window.markusDesktop?.selectDirectory?.(n("work:project.kbBrowseTitle"));C&&a(C)}catch(C){m({type:"error",text:`${n("work:project.kbBrowseFailed")}: ${String(C)}`})}},S=async C=>{if(!i){l(!0),m(null);try{const R=await se.projects.syncKnowledge(e.id,C);m({type:R.errors.length>0?"error":"success",text:n("work:project.kbSyncResult",{scanned:R.scanned,registered:R.registered,updated:R.updated,outdated:R.outdated,errors:R.errors.length})}),await v()}catch(R){m({type:"error",text:`${n("work:project.kbSyncFailed")}: ${String(R)}`})}finally{l(!1)}}},j=async()=>{await S(s.length?s:void 0)},E=C=>{tn.navigate(nt.DELIVERABLES,{projectId:e.id,source:"knowledge",...C?{openDeliverable:C}:{}})};return r.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2 mb-3",children:[r.jsx("h4",{className:"text-xs font-semibold text-fg-secondary",children:n("work:project.kbHeading")}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("button",{type:"button",onClick:()=>E(),className:"text-[10px] px-2 py-1 rounded-md text-fg-tertiary hover:text-brand-500 hover:bg-surface-overlay transition-colors",children:n("work:project.kbOpenInDeliverables")}),r.jsx("button",{type:"button",onClick:j,disabled:i||s.length===0,className:"text-[10px] px-2 py-1 rounded-md bg-brand-600 text-on-brand hover:bg-brand-500 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:n(i?"work:project.kbSyncing":"work:project.kbSync")})]})]}),g&&r.jsxs("div",{className:"mb-3 px-3 py-2 bg-surface-overlay border border-border-default rounded-lg",children:[r.jsx("p",{className:"text-xs text-fg-secondary mb-2",children:n("work:project.kbRemoveConfirm",{path:g})}),r.jsxs("div",{className:"flex gap-2 justify-end",children:[r.jsx("button",{type:"button",onClick:()=>b(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:n("common:cancel")}),r.jsx("button",{type:"button",onClick:()=>{y()},disabled:i,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:n(i?"work:project.kbSyncing":"common:confirm")})]})]}),r.jsxs("div",{className:"space-y-1.5 mb-3",children:[s.length===0&&r.jsx("p",{className:"text-[11px] text-fg-tertiary",children:n("work:project.kbNoPaths")}),s.map((C,R)=>r.jsxs("div",{className:"flex items-center gap-2 group",children:[r.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:r.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"})}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 min-w-0 truncate font-mono",title:C,children:C}),r.jsx("button",{type:"button",onClick:()=>b(C),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:n("work:project.removeRepo"),children:r.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},`${C}-${R}`)),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{value:o,onChange:C=>a(C.target.value),onKeyDown:C=>{C.key==="Enter"&&k()},placeholder:n("work:project.kbPathPlaceholder"),className:"flex-1 min-w-0 px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary font-mono"}),x&&r.jsx("button",{type:"button",onClick:()=>{w()},disabled:i,title:n("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:n("work:project.kbBrowse")}),r.jsx("button",{type:"button",onClick:k,disabled:!o.trim()||i,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:n(i?"work:project.kbSyncing":"work:project.kbAdd")})]})]}),f&&r.jsx("div",{className:`mb-2 px-2.5 py-1.5 text-[11px] rounded-md ${f.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:f.text}),r.jsxs("div",{className:"border-t border-border-default/60 pt-3",children:[r.jsxs("h5",{className:"text-[11px] font-medium text-fg-tertiary mb-2",children:[n("work:project.kbDocsHeading"),h.length>0&&r.jsxs("span",{className:"ml-1 text-fg-muted",children:["(",h.length,")"]})]}),c?r.jsx(Wf,{variant:"text",label:n("work:project.kbLoadingDocs"),className:"px-0"}):h.length===0?r.jsx("p",{className:"text-[11px] text-fg-tertiary",children:n("work:project.kbNoDocs")}):r.jsx("div",{className:"max-h-64 overflow-y-auto space-y-0.5",children:h.map(C=>r.jsxs("button",{type:"button",onClick:()=>E(C.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:C.reference??C.title,children:[r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-overlay text-fg-tertiary shrink-0 uppercase",children:C.format??"file"}),r.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1 min-w-0 group-hover:text-brand-500",children:C.title}),r.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"→"})]},C.id))})]})]})}const Hx=new Set(["rejected","cancelled","archived"]);function Vx(e){return Hx.has(e)}function Wx(e,t){let s=t.showClosed||t.includeClosed===!0?e:e.filter(o=>!Vx(o.status));return t.statusFilter&&(s=s.filter(o=>o.status===t.statusFilter)),t.viewMode==="project"&&t.selectedProjectId&&(s=s.filter(o=>o.projectId===t.selectedProjectId)),t.projectFilter&&t.projectFilter.size>0&&(s=s.filter(o=>o.projectId&&t.projectFilter.has(o.projectId))),t.agentFilter&&t.agentFilter.size>0&&(s=s.filter(o=>o.assignedAgentId&&t.agentFilter.has(o.assignedAgentId))),t.myTasksOnly&&t.currentUserId&&(s=s.filter(o=>o.createdBy===t.currentUserId)),s}function Ka(e,t){if(!e||e.length===0)return[];const n=new Map(t.map(a=>[a.id,a])),s=[],o=new Set;for(const a of e){if(o.has(a))continue;o.add(a);const i=n.get(a);i&&s.push({id:i.id,name:i.name,avatarUrl:i.avatarUrl})}return s}const Ua=Symbol.for("yaml.alias"),ja=Symbol.for("yaml.document"),An=Symbol.for("yaml.map"),au=Symbol.for("yaml.pair"),cn=Symbol.for("yaml.scalar"),Ps=Symbol.for("yaml.seq"),Ut=Symbol.for("yaml.node.type"),Bs=e=>!!e&&typeof e=="object"&&e[Ut]===Ua,kr=e=>!!e&&typeof e=="object"&&e[Ut]===ja,vr=e=>!!e&&typeof e=="object"&&e[Ut]===An,bt=e=>!!e&&typeof e=="object"&&e[Ut]===au,rt=e=>!!e&&typeof e=="object"&&e[Ut]===cn,jr=e=>!!e&&typeof e=="object"&&e[Ut]===Ps;function gt(e){if(e&&typeof e=="object")switch(e[Ut]){case An:case Ps:return!0}return!1}function xt(e){if(e&&typeof e=="object")switch(e[Ut]){case Ua:case An:case cn:case Ps:return!0}return!1}const iu=e=>(rt(e)||gt(e))&&!!e.anchor,Yn=Symbol("break visit"),Kx=Symbol("skip children"),rr=Symbol("remove node");function qs(e,t){const n=Ux(t);kr(e)?js(null,e.contents,n,Object.freeze([e]))===rr&&(e.contents=null):js(null,e,n,Object.freeze([]))}qs.BREAK=Yn;qs.SKIP=Kx;qs.REMOVE=rr;function js(e,t,n,s){const o=Yx(e,t,n,s);if(xt(o)||bt(o))return Gx(e,s,o),js(e,o,n,s);if(typeof o!="symbol"){if(gt(t)){s=Object.freeze(s.concat(t));for(let a=0;a<t.items.length;++a){const i=js(a,t.items[a],n,s);if(typeof i=="number")a=i-1;else{if(i===Yn)return Yn;i===rr&&(t.items.splice(a,1),a-=1)}}}else if(bt(t)){s=Object.freeze(s.concat(t));const a=js("key",t.key,n,s);if(a===Yn)return Yn;a===rr&&(t.key=null);const i=js("value",t.value,n,s);if(i===Yn)return Yn;i===rr&&(t.value=null)}}return o}function Ux(e){return typeof e=="object"&&(e.Collection||e.Node||e.Value)?Object.assign({Alias:e.Node,Map:e.Node,Scalar:e.Node,Seq:e.Node},e.Value&&{Map:e.Value,Scalar:e.Value,Seq:e.Value},e.Collection&&{Map:e.Collection,Seq:e.Collection},e):e}function Yx(e,t,n,s){if(typeof n=="function")return n(e,t,s);if(vr(t))return n.Map?.(e,t,s);if(jr(t))return n.Seq?.(e,t,s);if(bt(t))return n.Pair?.(e,t,s);if(rt(t))return n.Scalar?.(e,t,s);if(Bs(t))return n.Alias?.(e,t,s)}function Gx(e,t,n){const s=t[t.length-1];if(gt(s))s.items[e]=n;else if(bt(s))e==="key"?s.key=n:s.value=n;else if(kr(s))s.contents=n;else{const o=Bs(s)?"alias":"scalar";throw new Error(`Cannot replace node with ${o} parent`)}}const Xx={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"},Zx=e=>e.replace(/[!,[\]{}]/g,t=>Xx[t]);class At{constructor(t,n){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},At.defaultYaml,t),this.tags=Object.assign({},At.defaultTags,n)}clone(){const t=new At(this.yaml,this.tags);return t.docStart=this.docStart,t}atDocument(){const t=new At(this.yaml,this.tags);switch(this.yaml.version){case"1.1":this.atNextDocument=!0;break;case"1.2":this.atNextDocument=!1,this.yaml={explicit:At.defaultYaml.explicit,version:"1.2"},this.tags=Object.assign({},At.defaultTags);break}return t}add(t,n){this.atNextDocument&&(this.yaml={explicit:At.defaultYaml.explicit,version:"1.1"},this.tags=Object.assign({},At.defaultTags),this.atNextDocument=!1);const s=t.trim().split(/[ \t]+/),o=s.shift();switch(o){case"%TAG":{if(s.length!==2&&(n(0,"%TAG directive should contain exactly two parts"),s.length<2))return!1;const[a,i]=s;return this.tags[a]=i,!0}case"%YAML":{if(this.yaml.explicit=!0,s.length!==1)return n(0,"%YAML directive should contain exactly one part"),!1;const[a]=s;if(a==="1.1"||a==="1.2")return this.yaml.version=a,!0;{const i=/^\d+\.\d+$/.test(a);return n(6,`Unsupported YAML version ${a}`,i),!1}}default:return n(0,`Unknown directive ${o}`,!0),!1}}tagName(t,n){if(t==="!")return"!";if(t[0]!=="!")return n(`Not a valid tag: ${t}`),null;if(t[1]==="<"){const i=t.slice(2,-1);return i==="!"||i==="!!"?(n(`Verbatim tags aren't resolved, so ${t} is invalid.`),null):(t[t.length-1]!==">"&&n("Verbatim tags must end with a >"),i)}const[,s,o]=t.match(/^(.*!)([^!]*)$/s);o||n(`The ${t} tag has no suffix`);const a=this.tags[s];if(a)try{return a+decodeURIComponent(o)}catch(i){return n(String(i)),null}return s==="!"?t:(n(`Could not resolve tag: ${t}`),null)}tagString(t){for(const[n,s]of Object.entries(this.tags))if(t.startsWith(s))return n+Zx(t.substring(s.length));return t[0]==="!"?t:`!<${t}>`}toString(t){const n=this.yaml.explicit?[`%YAML ${this.yaml.version||"1.2"}`]:[],s=Object.entries(this.tags);let o;if(t&&s.length>0&&xt(t.contents)){const a={};qs(t.contents,(i,l)=>{xt(l)&&l.tag&&(a[l.tag]=!0)}),o=Object.keys(a)}else o=[];for(const[a,i]of s)a==="!!"&&i==="tag:yaml.org,2002:"||(!t||o.some(l=>l.startsWith(i)))&&n.push(`%TAG ${a} ${i}`);return n.join(`
|
|
8
|
-
`)}}At.defaultYaml={explicit:!1,version:"1.2"};At.defaultTags={"!!":"tag:yaml.org,2002:"};function lu(e){if(/[\x00-\x19\s,[\]{}]/.test(e)){const n=`Anchor must not contain whitespace or control characters: ${JSON.stringify(e)}`;throw new Error(n)}return!0}function cu(e){const t=new Set;return qs(e,{Value(n,s){s.anchor&&t.add(s.anchor)}}),t}function du(e,t){for(let n=1;;++n){const s=`${e}${n}`;if(!t.has(s))return s}}function Qx(e,t){const n=[],s=new Map;let o=null;return{onAnchor:a=>{n.push(a),o??(o=cu(e));const i=du(t,o);return o.add(i),i},setAnchors:()=>{for(const a of n){const i=s.get(a);if(typeof i=="object"&&i.anchor&&(rt(i.node)||gt(i.node)))i.node.anchor=i.anchor;else{const l=new Error("Failed to resolve repeated object (this should not happen)");throw l.source=a,l}}},sourceObjects:s}}function Ns(e,t,n,s){if(s&&typeof s=="object")if(Array.isArray(s))for(let o=0,a=s.length;o<a;++o){const i=s[o],l=Ns(e,s,String(o),i);l===void 0?delete s[o]:l!==i&&(s[o]=l)}else if(s instanceof Map)for(const o of Array.from(s.keys())){const a=s.get(o),i=Ns(e,s,o,a);i===void 0?s.delete(o):i!==a&&s.set(o,i)}else if(s instanceof Set)for(const o of Array.from(s)){const a=Ns(e,s,o,o);a===void 0?s.delete(o):a!==o&&(s.delete(o),s.add(a))}else for(const[o,a]of Object.entries(s)){const i=Ns(e,s,o,a);i===void 0?delete s[o]:i!==a&&(s[o]=i)}return e.call(t,n,s)}function Kt(e,t,n){if(Array.isArray(e))return e.map((s,o)=>Kt(s,String(o),n));if(e&&typeof e.toJSON=="function"){if(!n||!iu(e))return e.toJSON(t,n);const s={aliasCount:0,count:1,res:void 0};n.anchors.set(e,s),n.onCreate=a=>{s.res=a,delete n.onCreate};const o=e.toJSON(t,n);return n.onCreate&&n.onCreate(o),o}return typeof e=="bigint"&&!n?.keep?Number(e):e}class Ya{constructor(t){Object.defineProperty(this,Ut,{value:t})}clone(){const t=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(t.range=this.range.slice()),t}toJS(t,{mapAsMap:n,maxAliasCount:s,onAnchor:o,reviver:a}={}){if(!kr(t))throw new TypeError("A document argument is required");const i={anchors:new Map,doc:t,keep:!0,mapAsMap:n===!0,mapKeyWarned:!1,maxAliasCount:typeof s=="number"?s:100},l=Kt(this,"",i);if(typeof o=="function")for(const{count:c,res:d}of i.anchors.values())o(d,c);return typeof a=="function"?Ns(a,{"":l},"",l):l}}class Ga extends Ya{constructor(t){super(Ua),this.source=t,Object.defineProperty(this,"tag",{set(){throw new Error("Alias nodes cannot have tags")}})}resolve(t,n){if(n?.maxAliasCount===0)throw new ReferenceError("Alias resolution is disabled");let s;n?.aliasResolveCache?s=n.aliasResolveCache:(s=[],qs(t,{Node:(a,i)=>{(Bs(i)||iu(i))&&s.push(i)}}),n&&(n.aliasResolveCache=s));let o;for(const a of s){if(a===this)break;a.anchor===this.source&&(o=a)}return o}toJSON(t,n){if(!n)return{source:this.source};const{anchors:s,doc:o,maxAliasCount:a}=n,i=this.resolve(o,n);if(!i){const c=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new ReferenceError(c)}let l=s.get(i);if(l||(Kt(i,null,n),l=s.get(i)),l?.res===void 0){const c="This should not happen: Alias anchor was not resolved?";throw new ReferenceError(c)}if(a>=0&&(l.count+=1,l.aliasCount===0&&(l.aliasCount=io(o,i,s)),l.count*l.aliasCount>a)){const c="Excessive alias count indicates a resource exhaustion attack";throw new ReferenceError(c)}return l.res}toString(t,n,s){const o=`*${this.source}`;if(t){if(lu(this.source),t.options.verifyAliasOrder&&!t.anchors.has(this.source)){const a=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new Error(a)}if(t.implicitKey)return`${o} `}return o}}function io(e,t,n){if(Bs(t)){const s=t.resolve(e),o=n&&s&&n.get(s);return o?o.count*o.aliasCount:0}else if(gt(t)){let s=0;for(const o of t.items){const a=io(e,o,n);a>s&&(s=a)}return s}else if(bt(t)){const s=io(e,t.key,n),o=io(e,t.value,n);return Math.max(s,o)}return 1}const uu=e=>!e||typeof e!="function"&&typeof e!="object";class Oe extends Ya{constructor(t){super(cn),this.value=t}toJSON(t,n){return n?.keep?this.value:Kt(this.value,t,n)}toString(){return String(this.value)}}Oe.BLOCK_FOLDED="BLOCK_FOLDED";Oe.BLOCK_LITERAL="BLOCK_LITERAL";Oe.PLAIN="PLAIN";Oe.QUOTE_DOUBLE="QUOTE_DOUBLE";Oe.QUOTE_SINGLE="QUOTE_SINGLE";const Jx="tag:yaml.org,2002:";function e0(e,t,n){if(t){const s=n.filter(a=>a.tag===t),o=s.find(a=>!a.format)??s[0];if(!o)throw new Error(`Tag ${t} not found`);return o}return n.find(s=>s.identify?.(e)&&!s.format)}function mr(e,t,n){if(kr(e)&&(e=e.contents),xt(e))return e;if(bt(e)){const u=n.schema[An].createNode?.(n.schema,null,n);return u.items.push(e),u}(e instanceof String||e instanceof Number||e instanceof Boolean||typeof BigInt<"u"&&e instanceof BigInt)&&(e=e.valueOf());const{aliasDuplicateObjects:s,onAnchor:o,onTagObj:a,schema:i,sourceObjects:l}=n;let c;if(s&&e&&typeof e=="object"){if(c=l.get(e),c)return c.anchor??(c.anchor=o(e)),new Ga(c.anchor);c={anchor:null,node:null},l.set(e,c)}t?.startsWith("!!")&&(t=Jx+t.slice(2));let d=e0(e,t,i.tags);if(!d){if(e&&typeof e.toJSON=="function"&&(e=e.toJSON()),!e||typeof e!="object"){const u=new Oe(e);return c&&(c.node=u),u}d=e instanceof Map?i[An]:Symbol.iterator in Object(e)?i[Ps]:i[An]}a&&(a(d),delete n.onTagObj);const h=d?.createNode?d.createNode(n.schema,e,n):typeof d?.nodeClass?.from=="function"?d.nodeClass.from(n.schema,e,n):new Oe(e);return t?h.tag=t:d.default||(h.tag=d.tag),c&&(c.node=h),h}function go(e,t,n){let s=n;for(let o=t.length-1;o>=0;--o){const a=t[o];if(typeof a=="number"&&Number.isInteger(a)&&a>=0){const i=[];i[a]=s,s=i}else s=new Map([[a,s]])}return mr(s,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw new Error("This should not happen, please report a bug.")},schema:e,sourceObjects:new Map})}const tr=e=>e==null||typeof e=="object"&&!!e[Symbol.iterator]().next().done;class fu extends Ya{constructor(t,n){super(t),Object.defineProperty(this,"schema",{value:n,configurable:!0,enumerable:!1,writable:!0})}clone(t){const n=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return t&&(n.schema=t),n.items=n.items.map(s=>xt(s)||bt(s)?s.clone(t):s),this.range&&(n.range=this.range.slice()),n}addIn(t,n){if(tr(t))this.add(n);else{const[s,...o]=t,a=this.get(s,!0);if(gt(a))a.addIn(o,n);else if(a===void 0&&this.schema)this.set(s,go(this.schema,o,n));else throw new Error(`Expected YAML collection at ${s}. Remaining path: ${o}`)}}deleteIn(t){const[n,...s]=t;if(s.length===0)return this.delete(n);const o=this.get(n,!0);if(gt(o))return o.deleteIn(s);throw new Error(`Expected YAML collection at ${n}. Remaining path: ${s}`)}getIn(t,n){const[s,...o]=t,a=this.get(s,!0);return o.length===0?!n&&rt(a)?a.value:a:gt(a)?a.getIn(o,n):void 0}hasAllNullValues(t){return this.items.every(n=>{if(!bt(n))return!1;const s=n.value;return s==null||t&&rt(s)&&s.value==null&&!s.commentBefore&&!s.comment&&!s.tag})}hasIn(t){const[n,...s]=t;if(s.length===0)return this.has(n);const o=this.get(n,!0);return gt(o)?o.hasIn(s):!1}setIn(t,n){const[s,...o]=t;if(o.length===0)this.set(s,n);else{const a=this.get(s,!0);if(gt(a))a.setIn(o,n);else if(a===void 0&&this.schema)this.set(s,go(this.schema,o,n));else throw new Error(`Expected YAML collection at ${s}. Remaining path: ${o}`)}}}const t0=e=>e.replace(/^(?!$)(?: $)?/gm,"#");function bn(e,t){return/^\n+$/.test(e)?e.substring(1):t?e.replace(/^(?! *$)/gm,t):e}const Xn=(e,t,n)=>e.endsWith(`
|
|
9
|
-
`)?bn(n,t):n.includes(`
|
|
10
|
-
`)?`
|
|
11
|
-
`+bn(n,t):(e.endsWith(" ")?"":" ")+n,hu="flow",Na="block",lo="quoted";function Mo(e,t,n="flow",{indentAtStart:s,lineWidth:o=80,minContentWidth:a=20,onFold:i,onOverflow:l}={}){if(!o||o<0)return e;o<a&&(a=0);const c=Math.max(1+a,1+o-t.length);if(e.length<=c)return e;const d=[],h={};let u=o-t.length;typeof s=="number"&&(s>o-Math.max(2,a)?d.push(0):u=o-s);let f,m,g=!1,b=-1,v=-1,k=-1;n===Na&&(b=Ul(e,b,t.length),b!==-1&&(u=b+c));for(let x;x=e[b+=1];){if(n===lo&&x==="\\"){switch(v=b,e[b+1]){case"x":b+=3;break;case"u":b+=5;break;case"U":b+=9;break;default:b+=1}k=b}if(x===`
|
|
12
|
-
`)n===Na&&(b=Ul(e,b,t.length)),u=b+t.length+c,f=void 0;else{if(x===" "&&m&&m!==" "&&m!==`
|
|
13
|
-
`&&m!==" "){const w=e[b+1];w&&w!==" "&&w!==`
|
|
14
|
-
`&&w!==" "&&(f=b)}if(b>=u)if(f)d.push(f),u=f+c,f=void 0;else if(n===lo){for(;m===" "||m===" ";)m=x,x=e[b+=1],g=!0;const w=b>k+1?b-2:v-1;if(h[w])return e;d.push(w),h[w]=!0,u=w+c,f=void 0}else g=!0}m=x}if(g&&l&&l(),d.length===0)return e;i&&i();let y=e.slice(0,d[0]);for(let x=0;x<d.length;++x){const w=d[x],S=d[x+1]||e.length;w===0?y=`
|
|
15
|
-
${t}${e.slice(0,S)}`:(n===lo&&h[w]&&(y+=`${e[w]}\\`),y+=`
|
|
16
|
-
${t}${e.slice(w+1,S)}`)}return y}function Ul(e,t,n){let s=t,o=t+1,a=e[o];for(;a===" "||a===" ";)if(t<o+n)a=e[++t];else{do a=e[++t];while(a&&a!==`
|
|
17
|
-
`);s=t,o=t+1,a=e[o]}return s}const Ao=(e,t)=>({indentAtStart:t?e.indent.length:e.indentAtStart,lineWidth:e.options.lineWidth,minContentWidth:e.options.minContentWidth}),Lo=e=>/^(%|---|\.\.\.)/m.test(e);function n0(e,t,n){if(!t||t<0)return!1;const s=t-n,o=e.length;if(o<=s)return!1;for(let a=0,i=0;a<o;++a)if(e[a]===`
|
|
18
|
-
`){if(a-i>s)return!0;if(i=a+1,o-i<=s)return!1}return!0}function or(e,t){const n=JSON.stringify(e);if(t.options.doubleQuotedAsJSON)return n;const{implicitKey:s}=t,o=t.options.doubleQuotedMinMultiLineLength,a=t.indent||(Lo(e)?" ":"");let i="",l=0;for(let c=0,d=n[c];d;d=n[++c])if(d===" "&&n[c+1]==="\\"&&n[c+2]==="n"&&(i+=n.slice(l,c)+"\\ ",c+=1,l=c,d="\\"),d==="\\")switch(n[c+1]){case"u":{i+=n.slice(l,c);const h=n.substr(c+2,4);switch(h){case"0000":i+="\\0";break;case"0007":i+="\\a";break;case"000b":i+="\\v";break;case"001b":i+="\\e";break;case"0085":i+="\\N";break;case"00a0":i+="\\_";break;case"2028":i+="\\L";break;case"2029":i+="\\P";break;default:h.substr(0,2)==="00"?i+="\\x"+h.substr(2):i+=n.substr(c,6)}c+=5,l=c+1}break;case"n":if(s||n[c+2]==='"'||n.length<o)c+=1;else{for(i+=n.slice(l,c)+`
|
|
19
|
-
|
|
20
|
-
`;n[c+2]==="\\"&&n[c+3]==="n"&&n[c+4]!=='"';)i+=`
|
|
21
|
-
`,c+=2;i+=a,n[c+2]===" "&&(i+="\\"),c+=1,l=c+1}break;default:c+=1}return i=l?i+n.slice(l):n,s?i:Mo(i,a,lo,Ao(t,!1))}function Sa(e,t){if(t.options.singleQuote===!1||t.implicitKey&&e.includes(`
|
|
22
|
-
`)||/[ \t]\n|\n[ \t]/.test(e))return or(e,t);const n=t.indent||(Lo(e)?" ":""),s="'"+e.replace(/'/g,"''").replace(/\n+/g,`$&
|
|
23
|
-
${n}`)+"'";return t.implicitKey?s:Mo(s,n,hu,Ao(t,!1))}function Ss(e,t){const{singleQuote:n}=t.options;let s;if(n===!1)s=or;else{const o=e.includes('"'),a=e.includes("'");o&&!a?s=Sa:a&&!o?s=or:s=n?Sa:or}return s(e,t)}let Ca;try{Ca=new RegExp(`(^|(?<!
|
|
24
|
-
))
|
|
25
|
-
+(?!
|
|
26
|
-
|$)`,"g")}catch{Ca=/\n+(?!\n|$)/g}function co({comment:e,type:t,value:n},s,o,a){const{blockQuote:i,commentString:l,lineWidth:c}=s.options;if(!i||/\n[\t ]+$/.test(n))return Ss(n,s);const d=s.indent||(s.forceBlockIndent||Lo(n)?" ":""),h=i==="literal"?!0:i==="folded"||t===Oe.BLOCK_FOLDED?!1:t===Oe.BLOCK_LITERAL?!0:!n0(n,c,d.length);if(!n)return h?`|
|
|
27
|
-
`:`>
|
|
28
|
-
`;let u,f;for(f=n.length;f>0;--f){const S=n[f-1];if(S!==`
|
|
29
|
-
`&&S!==" "&&S!==" ")break}let m=n.substring(f);const g=m.indexOf(`
|
|
30
|
-
`);g===-1?u="-":n===m||g!==m.length-1?(u="+",a&&a()):u="",m&&(n=n.slice(0,-m.length),m[m.length-1]===`
|
|
31
|
-
`&&(m=m.slice(0,-1)),m=m.replace(Ca,`$&${d}`));let b=!1,v,k=-1;for(v=0;v<n.length;++v){const S=n[v];if(S===" ")b=!0;else if(S===`
|
|
32
|
-
`)k=v;else break}let y=n.substring(0,k<v?k+1:v);y&&(n=n.substring(y.length),y=y.replace(/\n+/g,`$&${d}`));let w=(b?d?"2":"1":"")+u;if(e&&(w+=" "+l(e.replace(/ ?[\r\n]+/g," ")),o&&o()),!h){const S=n.replace(/\n+/g,`
|
|
33
|
-
$&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,"$1$2").replace(/\n+/g,`$&${d}`);let j=!1;const E=Ao(s,!0);i!=="folded"&&t!==Oe.BLOCK_FOLDED&&(E.onOverflow=()=>{j=!0});const C=Mo(`${y}${S}${m}`,d,Na,E);if(!j)return`>${w}
|
|
34
|
-
${d}${C}`}return n=n.replace(/\n+/g,`$&${d}`),`|${w}
|
|
35
|
-
${d}${y}${n}${m}`}function s0(e,t,n,s){const{type:o,value:a}=e,{actualString:i,implicitKey:l,indent:c,indentStep:d,inFlow:h}=t;if(l&&a.includes(`
|
|
36
|
-
`)||h&&/[[\]{},]/.test(a))return Ss(a,t);if(/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(a))return l||h||!a.includes(`
|
|
37
|
-
`)?Ss(a,t):co(e,t,n,s);if(!l&&!h&&o!==Oe.PLAIN&&a.includes(`
|
|
38
|
-
`))return co(e,t,n,s);if(Lo(a)){if(c==="")return t.forceBlockIndent=!0,co(e,t,n,s);if(l&&c===d)return Ss(a,t)}const u=a.replace(/\n+/g,`$&
|
|
39
|
-
${c}`);if(i){const f=b=>b.default&&b.tag!=="tag:yaml.org,2002:str"&&b.test?.test(u),{compat:m,tags:g}=t.doc.schema;if(g.some(f)||m?.some(f))return Ss(a,t)}return l?u:Mo(u,c,hu,Ao(t,!1))}function Xa(e,t,n,s){const{implicitKey:o,inFlow:a}=t,i=typeof e.value=="string"?e:Object.assign({},e,{value:String(e.value)});let{type:l}=e;l!==Oe.QUOTE_DOUBLE&&/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(i.value)&&(l=Oe.QUOTE_DOUBLE);const c=h=>{switch(h){case Oe.BLOCK_FOLDED:case Oe.BLOCK_LITERAL:return o||a?Ss(i.value,t):co(i,t,n,s);case Oe.QUOTE_DOUBLE:return or(i.value,t);case Oe.QUOTE_SINGLE:return Sa(i.value,t);case Oe.PLAIN:return s0(i,t,n,s);default:return null}};let d=c(l);if(d===null){const{defaultKeyType:h,defaultStringType:u}=t.options,f=o&&h||u;if(d=c(f),d===null)throw new Error(`Unsupported default string type ${f}`)}return d}function mu(e,t){const n=Object.assign({blockQuote:!0,commentString:t0,defaultKeyType:null,defaultStringType:"PLAIN",directives:null,doubleQuotedAsJSON:!1,doubleQuotedMinMultiLineLength:40,falseStr:"false",flowCollectionPadding:!0,indentSeq:!0,lineWidth:80,minContentWidth:20,nullStr:"null",simpleKeys:!1,singleQuote:null,trailingComma:!1,trueStr:"true",verifyAliasOrder:!0},e.schema.toStringOptions,t);let s;switch(n.collectionStyle){case"block":s=!1;break;case"flow":s=!0;break;default:s=null}return{anchors:new Set,doc:e,flowCollectionPadding:n.flowCollectionPadding?" ":"",indent:"",indentStep:typeof n.indent=="number"?" ".repeat(n.indent):" ",inFlow:s,options:n}}function r0(e,t){if(t.tag){const o=e.filter(a=>a.tag===t.tag);if(o.length>0)return o.find(a=>a.format===t.format)??o[0]}let n,s;if(rt(t)){s=t.value;let o=e.filter(a=>a.identify?.(s));if(o.length>1){const a=o.filter(i=>i.test);a.length>0&&(o=a)}n=o.find(a=>a.format===t.format)??o.find(a=>!a.format)}else s=t,n=e.find(o=>o.nodeClass&&s instanceof o.nodeClass);if(!n){const o=s?.constructor?.name??(s===null?"null":typeof s);throw new Error(`Tag not resolved for ${o} value`)}return n}function o0(e,t,{anchors:n,doc:s}){if(!s.directives)return"";const o=[],a=(rt(e)||gt(e))&&e.anchor;a&&lu(a)&&(n.add(a),o.push(`&${a}`));const i=e.tag??(t.default?null:t.tag);return i&&o.push(s.directives.tagString(i)),o.join(" ")}function Ds(e,t,n,s){if(bt(e))return e.toString(t,n,s);if(Bs(e)){if(t.doc.directives)return e.toString(t);if(t.resolvedAliases?.has(e))throw new TypeError("Cannot stringify circular structure without alias nodes");t.resolvedAliases?t.resolvedAliases.add(e):t.resolvedAliases=new Set([e]),e=e.resolve(t.doc)}let o;const a=xt(e)?e:t.doc.createNode(e,{onTagObj:c=>o=c});o??(o=r0(t.doc.schema.tags,a));const i=o0(a,o,t);i.length>0&&(t.indentAtStart=(t.indentAtStart??0)+i.length+1);const l=typeof o.stringify=="function"?o.stringify(a,t,n,s):rt(a)?Xa(a,t,n,s):a.toString(t,n,s);return i?rt(a)||l[0]==="{"||l[0]==="["?`${i} ${l}`:`${i}
|
|
40
|
-
${t.indent}${l}`:l}function a0({key:e,value:t},n,s,o){const{allNullValues:a,doc:i,indent:l,indentStep:c,options:{commentString:d,indentSeq:h,simpleKeys:u}}=n;let f=xt(e)&&e.comment||null;if(u){if(f)throw new Error("With simple keys, key nodes cannot have comments");if(gt(e)||!xt(e)&&typeof e=="object"){const E="With simple keys, collection cannot be used as a key value";throw new Error(E)}}let m=!u&&(!e||f&&t==null&&!n.inFlow||gt(e)||(rt(e)?e.type===Oe.BLOCK_FOLDED||e.type===Oe.BLOCK_LITERAL:typeof e=="object"));n=Object.assign({},n,{allNullValues:!1,implicitKey:!m&&(u||!a),indent:l+c});let g=!1,b=!1,v=Ds(e,n,()=>g=!0,()=>b=!0);if(!m&&!n.inFlow&&v.length>1024){if(u)throw new Error("With simple keys, single line scalar must not span more than 1024 characters");m=!0}if(n.inFlow){if(a||t==null)return g&&s&&s(),v===""?"?":m?`? ${v}`:v}else if(a&&!u||t==null&&m)return v=`? ${v}`,f&&!g?v+=Xn(v,n.indent,d(f)):b&&o&&o(),v;g&&(f=null),m?(f&&(v+=Xn(v,n.indent,d(f))),v=`? ${v}
|
|
41
|
-
${l}:`):(v=`${v}:`,f&&(v+=Xn(v,n.indent,d(f))));let k,y,x;xt(t)?(k=!!t.spaceBefore,y=t.commentBefore,x=t.comment):(k=!1,y=null,x=null,t&&typeof t=="object"&&(t=i.createNode(t))),n.implicitKey=!1,!m&&!f&&rt(t)&&(n.indentAtStart=v.length+1),b=!1,!h&&c.length>=2&&!n.inFlow&&!m&&jr(t)&&!t.flow&&!t.tag&&!t.anchor&&(n.indent=n.indent.substring(2));let w=!1;const S=Ds(t,n,()=>w=!0,()=>b=!0);let j=" ";if(f||k||y){if(j=k?`
|
|
42
|
-
`:"",y){const E=d(y);j+=`
|
|
43
|
-
${bn(E,n.indent)}`}S===""&&!n.inFlow?j===`
|
|
44
|
-
`&&x&&(j=`
|
|
45
|
-
|
|
46
|
-
`):j+=`
|
|
47
|
-
${n.indent}`}else if(!m&>(t)){const E=S[0],C=S.indexOf(`
|
|
48
|
-
`),R=C!==-1,P=n.inFlow??t.flow??t.items.length===0;if(R||!P){let T=!1;if(R&&(E==="&"||E==="!")){let D=S.indexOf(" ");E==="&"&&D!==-1&&D<C&&S[D+1]==="!"&&(D=S.indexOf(" ",D+1)),(D===-1||C<D)&&(T=!0)}T||(j=`
|
|
49
|
-
${n.indent}`)}}else(S===""||S[0]===`
|
|
50
|
-
`)&&(j="");return v+=j+S,n.inFlow?w&&s&&s():x&&!w?v+=Xn(v,n.indent,d(x)):b&&o&&o(),v}function pu(e,t){(e==="debug"||e==="warn")&&console.warn(t)}const Gr="<<",yn={identify:e=>e===Gr||typeof e=="symbol"&&e.description===Gr,default:"key",tag:"tag:yaml.org,2002:merge",test:/^<<$/,resolve:()=>Object.assign(new Oe(Symbol(Gr)),{addToJSMap:gu}),stringify:()=>Gr},i0=(e,t)=>(yn.identify(t)||rt(t)&&(!t.type||t.type===Oe.PLAIN)&&yn.identify(t.value))&&e?.doc.schema.tags.some(n=>n.tag===yn.tag&&n.default);function gu(e,t,n){const s=xu(e,n);if(jr(s))for(const o of s.items)aa(e,t,o);else if(Array.isArray(s))for(const o of s)aa(e,t,o);else aa(e,t,s)}function aa(e,t,n){const s=xu(e,n);if(!vr(s))throw new Error("Merge sources must be maps or map aliases");const o=s.toJSON(null,e,Map);for(const[a,i]of o)t instanceof Map?t.has(a)||t.set(a,i):t instanceof Set?t.add(a):Object.prototype.hasOwnProperty.call(t,a)||Object.defineProperty(t,a,{value:i,writable:!0,enumerable:!0,configurable:!0});return t}function xu(e,t){return e&&Bs(t)?t.resolve(e.doc,e):t}function bu(e,t,{key:n,value:s}){if(xt(n)&&n.addToJSMap)n.addToJSMap(e,t,s);else if(i0(e,n))gu(e,t,s);else{const o=Kt(n,"",e);if(t instanceof Map)t.set(o,Kt(s,o,e));else if(t instanceof Set)t.add(o);else{const a=l0(n,o,e),i=Kt(s,a,e);a in t?Object.defineProperty(t,a,{value:i,writable:!0,enumerable:!0,configurable:!0}):t[a]=i}}return t}function l0(e,t,n){if(t===null)return"";if(typeof t!="object")return String(t);if(xt(e)&&n?.doc){const s=mu(n.doc,{});s.anchors=new Set;for(const a of n.anchors.keys())s.anchors.add(a.anchor);s.inFlow=!0,s.inStringifyKey=!0;const o=e.toString(s);if(!n.mapKeyWarned){let a=JSON.stringify(o);a.length>40&&(a=a.substring(0,36)+'..."'),pu(n.doc.options.logLevel,`Keys with collection values will be stringified due to JS Object restrictions: ${a}. Set mapAsMap: true to use object keys.`),n.mapKeyWarned=!0}return o}return JSON.stringify(t)}function Za(e,t,n){const s=mr(e,void 0,n),o=mr(t,void 0,n);return new Lt(s,o)}class Lt{constructor(t,n=null){Object.defineProperty(this,Ut,{value:au}),this.key=t,this.value=n}clone(t){let{key:n,value:s}=this;return xt(n)&&(n=n.clone(t)),xt(s)&&(s=s.clone(t)),new Lt(n,s)}toJSON(t,n){const s=n?.mapAsMap?new Map:{};return bu(n,s,this)}toString(t,n,s){return t?.doc?a0(this,t,n,s):JSON.stringify(this)}}function yu(e,t,n){return(t.inFlow??e.flow?d0:c0)(e,t,n)}function c0({comment:e,items:t},n,{blockItemPrefix:s,flowChars:o,itemIndent:a,onChompKeep:i,onComment:l}){const{indent:c,options:{commentString:d}}=n,h=Object.assign({},n,{indent:a,type:null});let u=!1;const f=[];for(let g=0;g<t.length;++g){const b=t[g];let v=null;if(xt(b))!u&&b.spaceBefore&&f.push(""),xo(n,f,b.commentBefore,u),b.comment&&(v=b.comment);else if(bt(b)){const y=xt(b.key)?b.key:null;y&&(!u&&y.spaceBefore&&f.push(""),xo(n,f,y.commentBefore,u))}u=!1;let k=Ds(b,h,()=>v=null,()=>u=!0);v&&(k+=Xn(k,a,d(v))),u&&v&&(u=!1),f.push(s+k)}let m;if(f.length===0)m=o.start+o.end;else{m=f[0];for(let g=1;g<f.length;++g){const b=f[g];m+=b?`
|
|
51
|
-
${c}${b}`:`
|
|
52
|
-
`}}return e?(m+=`
|
|
53
|
-
`+bn(d(e),c),l&&l()):u&&i&&i(),m}function d0({items:e},t,{flowChars:n,itemIndent:s}){const{indent:o,indentStep:a,flowCollectionPadding:i,options:{commentString:l}}=t;s+=a;const c=Object.assign({},t,{indent:s,inFlow:!0,type:null});let d=!1,h=0;const u=[];for(let g=0;g<e.length;++g){const b=e[g];let v=null;if(xt(b))b.spaceBefore&&u.push(""),xo(t,u,b.commentBefore,!1),b.comment&&(v=b.comment);else if(bt(b)){const y=xt(b.key)?b.key:null;y&&(y.spaceBefore&&u.push(""),xo(t,u,y.commentBefore,!1),y.comment&&(d=!0));const x=xt(b.value)?b.value:null;x?(x.comment&&(v=x.comment),x.commentBefore&&(d=!0)):b.value==null&&y?.comment&&(v=y.comment)}v&&(d=!0);let k=Ds(b,c,()=>v=null);d||(d=u.length>h||k.includes(`
|
|
54
|
-
`)),g<e.length-1?k+=",":t.options.trailingComma&&(t.options.lineWidth>0&&(d||(d=u.reduce((y,x)=>y+x.length+2,2)+(k.length+2)>t.options.lineWidth)),d&&(k+=",")),v&&(k+=Xn(k,s,l(v))),u.push(k),h=u.length}const{start:f,end:m}=n;if(u.length===0)return f+m;if(!d){const g=u.reduce((b,v)=>b+v.length+2,2);d=t.options.lineWidth>0&&g>t.options.lineWidth}if(d){let g=f;for(const b of u)g+=b?`
|
|
55
|
-
${a}${o}${b}`:`
|
|
56
|
-
`;return`${g}
|
|
57
|
-
${o}${m}`}else return`${f}${i}${u.join(" ")}${i}${m}`}function xo({indent:e,options:{commentString:t}},n,s,o){if(s&&o&&(s=s.replace(/^\n+/,"")),s){const a=bn(t(s),e);n.push(a.trimStart())}}function Zn(e,t){const n=rt(t)?t.value:t;for(const s of e)if(bt(s)&&(s.key===t||s.key===n||rt(s.key)&&s.key.value===n))return s}class Wt extends fu{static get tagName(){return"tag:yaml.org,2002:map"}constructor(t){super(An,t),this.items=[]}static from(t,n,s){const{keepUndefined:o,replacer:a}=s,i=new this(t),l=(c,d)=>{if(typeof a=="function")d=a.call(n,c,d);else if(Array.isArray(a)&&!a.includes(c))return;(d!==void 0||o)&&i.items.push(Za(c,d,s))};if(n instanceof Map)for(const[c,d]of n)l(c,d);else if(n&&typeof n=="object")for(const c of Object.keys(n))l(c,n[c]);return typeof t.sortMapEntries=="function"&&i.items.sort(t.sortMapEntries),i}add(t,n){let s;bt(t)?s=t:!t||typeof t!="object"||!("key"in t)?s=new Lt(t,t?.value):s=new Lt(t.key,t.value);const o=Zn(this.items,s.key),a=this.schema?.sortMapEntries;if(o){if(!n)throw new Error(`Key ${s.key} already set`);rt(o.value)&&uu(s.value)?o.value.value=s.value:o.value=s.value}else if(a){const i=this.items.findIndex(l=>a(s,l)<0);i===-1?this.items.push(s):this.items.splice(i,0,s)}else this.items.push(s)}delete(t){const n=Zn(this.items,t);return n?this.items.splice(this.items.indexOf(n),1).length>0:!1}get(t,n){const o=Zn(this.items,t)?.value;return(!n&&rt(o)?o.value:o)??void 0}has(t){return!!Zn(this.items,t)}set(t,n){this.add(new Lt(t,n),!0)}toJSON(t,n,s){const o=s?new s:n?.mapAsMap?new Map:{};n?.onCreate&&n.onCreate(o);for(const a of this.items)bu(n,o,a);return o}toString(t,n,s){if(!t)return JSON.stringify(this);for(const o of this.items)if(!bt(o))throw new Error(`Map items must all be pairs; found ${JSON.stringify(o)} instead`);return!t.allNullValues&&this.hasAllNullValues(!1)&&(t=Object.assign({},t,{allNullValues:!0})),yu(this,t,{blockItemPrefix:"",flowChars:{start:"{",end:"}"},itemIndent:t.indent||"",onChompKeep:s,onComment:n})}}const zs={collection:"map",default:!0,nodeClass:Wt,tag:"tag:yaml.org,2002:map",resolve(e,t){return vr(e)||t("Expected a mapping for this tag"),e},createNode:(e,t,n)=>Wt.from(e,t,n)};class ns extends fu{static get tagName(){return"tag:yaml.org,2002:seq"}constructor(t){super(Ps,t),this.items=[]}add(t){this.items.push(t)}delete(t){const n=Xr(t);return typeof n!="number"?!1:this.items.splice(n,1).length>0}get(t,n){const s=Xr(t);if(typeof s!="number")return;const o=this.items[s];return!n&&rt(o)?o.value:o}has(t){const n=Xr(t);return typeof n=="number"&&n<this.items.length}set(t,n){const s=Xr(t);if(typeof s!="number")throw new Error(`Expected a valid index, not ${t}.`);const o=this.items[s];rt(o)&&uu(n)?o.value=n:this.items[s]=n}toJSON(t,n){const s=[];n?.onCreate&&n.onCreate(s);let o=0;for(const a of this.items)s.push(Kt(a,String(o++),n));return s}toString(t,n,s){return t?yu(this,t,{blockItemPrefix:"- ",flowChars:{start:"[",end:"]"},itemIndent:(t.indent||"")+" ",onChompKeep:s,onComment:n}):JSON.stringify(this)}static from(t,n,s){const{replacer:o}=s,a=new this(t);if(n&&Symbol.iterator in Object(n)){let i=0;for(let l of n){if(typeof o=="function"){const c=n instanceof Set?l:String(i++);l=o.call(n,c,l)}a.items.push(mr(l,void 0,s))}}return a}}function Xr(e){let t=rt(e)?e.value:e;return t&&typeof t=="string"&&(t=Number(t)),typeof t=="number"&&Number.isInteger(t)&&t>=0?t:null}const Fs={collection:"seq",default:!0,nodeClass:ns,tag:"tag:yaml.org,2002:seq",resolve(e,t){return jr(e)||t("Expected a sequence for this tag"),e},createNode:(e,t,n)=>ns.from(e,t,n)},_o={identify:e=>typeof e=="string",default:!0,tag:"tag:yaml.org,2002:str",resolve:e=>e,stringify(e,t,n,s){return t=Object.assign({actualString:!0},t),Xa(e,t,n,s)}},Ro={identify:e=>e==null,createNode:()=>new Oe(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^(?:~|[Nn]ull|NULL)?$/,resolve:()=>new Oe(null),stringify:({source:e},t)=>typeof e=="string"&&Ro.test.test(e)?e:t.options.nullStr},Qa={identify:e=>typeof e=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,resolve:e=>new Oe(e[0]==="t"||e[0]==="T"),stringify({source:e,value:t},n){if(e&&Qa.test.test(e)){const s=e[0]==="t"||e[0]==="T";if(t===s)return e}return t?n.options.trueStr:n.options.falseStr}};function sn({format:e,minFractionDigits:t,tag:n,value:s}){if(typeof s=="bigint")return String(s);const o=typeof s=="number"?s:Number(s);if(!isFinite(o))return isNaN(o)?".nan":o<0?"-.inf":".inf";let a=Object.is(s,-0)?"-0":JSON.stringify(s);if(!e&&t&&(!n||n==="tag:yaml.org,2002:float")&&/^-?\d/.test(a)&&!a.includes("e")){let i=a.indexOf(".");i<0&&(i=a.length,a+=".");let l=t-(a.length-i-1);for(;l-- >0;)a+="0"}return a}const wu={identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:e=>e.slice(-3).toLowerCase()==="nan"?NaN:e[0]==="-"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,stringify:sn},ku={identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",format:"EXP",test:/^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,resolve:e=>parseFloat(e),stringify(e){const t=Number(e.value);return isFinite(t)?t.toExponential():sn(e)}},vu={identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,resolve(e){const t=new Oe(parseFloat(e)),n=e.indexOf(".");return n!==-1&&e[e.length-1]==="0"&&(t.minFractionDigits=e.length-n-1),t},stringify:sn},Do=e=>typeof e=="bigint"||Number.isInteger(e),Ja=(e,t,n,{intAsBigInt:s})=>s?BigInt(e):parseInt(e.substring(t),n);function ju(e,t,n){const{value:s}=e;return Do(s)&&s>=0?n+s.toString(t):sn(e)}const Nu={identify:e=>Do(e)&&e>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^0o[0-7]+$/,resolve:(e,t,n)=>Ja(e,2,8,n),stringify:e=>ju(e,8,"0o")},Su={identify:Do,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9]+$/,resolve:(e,t,n)=>Ja(e,0,10,n),stringify:sn},Cu={identify:e=>Do(e)&&e>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^0x[0-9a-fA-F]+$/,resolve:(e,t,n)=>Ja(e,2,16,n),stringify:e=>ju(e,16,"0x")},u0=[zs,Fs,_o,Ro,Qa,Nu,Su,Cu,wu,ku,vu];function Yl(e){return typeof e=="bigint"||Number.isInteger(e)}const Zr=({value:e})=>JSON.stringify(e),f0=[{identify:e=>typeof e=="string",default:!0,tag:"tag:yaml.org,2002:str",resolve:e=>e,stringify:Zr},{identify:e=>e==null,createNode:()=>new Oe(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^null$/,resolve:()=>null,stringify:Zr},{identify:e=>typeof e=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^true$|^false$/,resolve:e=>e==="true",stringify:Zr},{identify:Yl,default:!0,tag:"tag:yaml.org,2002:int",test:/^-?(?:0|[1-9][0-9]*)$/,resolve:(e,t,{intAsBigInt:n})=>n?BigInt(e):parseInt(e,10),stringify:({value:e})=>Yl(e)?e.toString():JSON.stringify(e)},{identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,resolve:e=>parseFloat(e),stringify:Zr}],h0={default:!0,tag:"",test:/^/,resolve(e,t){return t(`Unresolved plain scalar ${JSON.stringify(e)}`),e}},m0=[zs,Fs].concat(f0,h0),ei={identify:e=>e instanceof Uint8Array,default:!1,tag:"tag:yaml.org,2002:binary",resolve(e,t){if(typeof atob=="function"){const n=atob(e.replace(/[\n\r]/g,"")),s=new Uint8Array(n.length);for(let o=0;o<n.length;++o)s[o]=n.charCodeAt(o);return s}else return t("This environment does not support reading binary tags; either Buffer or atob is required"),e},stringify({comment:e,type:t,value:n},s,o,a){if(!n)return"";const i=n;let l;if(typeof btoa=="function"){let c="";for(let d=0;d<i.length;++d)c+=String.fromCharCode(i[d]);l=btoa(c)}else throw new Error("This environment does not support writing binary tags; either Buffer or btoa is required");if(t??(t=Oe.BLOCK_LITERAL),t!==Oe.QUOTE_DOUBLE){const c=Math.max(s.options.lineWidth-s.indent.length,s.options.minContentWidth),d=Math.ceil(l.length/c),h=new Array(d);for(let u=0,f=0;u<d;++u,f+=c)h[u]=l.substr(f,c);l=h.join(t===Oe.BLOCK_LITERAL?`
|
|
58
|
-
`:" ")}return Xa({comment:e,type:t,value:l},s,o,a)}};function Eu(e,t){if(jr(e))for(let n=0;n<e.items.length;++n){let s=e.items[n];if(!bt(s)){if(vr(s)){s.items.length>1&&t("Each pair must have its own sequence indicator");const o=s.items[0]||new Lt(new Oe(null));if(s.commentBefore&&(o.key.commentBefore=o.key.commentBefore?`${s.commentBefore}
|
|
59
|
-
${o.key.commentBefore}`:s.commentBefore),s.comment){const a=o.value??o.key;a.comment=a.comment?`${s.comment}
|
|
60
|
-
${a.comment}`:s.comment}s=o}e.items[n]=bt(s)?s:new Lt(s)}}else t("Expected a sequence for this tag");return e}function Iu(e,t,n){const{replacer:s}=n,o=new ns(e);o.tag="tag:yaml.org,2002:pairs";let a=0;if(t&&Symbol.iterator in Object(t))for(let i of t){typeof s=="function"&&(i=s.call(t,String(a++),i));let l,c;if(Array.isArray(i))if(i.length===2)l=i[0],c=i[1];else throw new TypeError(`Expected [key, value] tuple: ${i}`);else if(i&&i instanceof Object){const d=Object.keys(i);if(d.length===1)l=d[0],c=i[l];else throw new TypeError(`Expected tuple with one key, not ${d.length} keys`)}else l=i;o.items.push(Za(l,c,n))}return o}const ti={collection:"seq",default:!1,tag:"tag:yaml.org,2002:pairs",resolve:Eu,createNode:Iu};class Es extends ns{constructor(){super(),this.add=Wt.prototype.add.bind(this),this.delete=Wt.prototype.delete.bind(this),this.get=Wt.prototype.get.bind(this),this.has=Wt.prototype.has.bind(this),this.set=Wt.prototype.set.bind(this),this.tag=Es.tag}toJSON(t,n){if(!n)return super.toJSON(t);const s=new Map;n?.onCreate&&n.onCreate(s);for(const o of this.items){let a,i;if(bt(o)?(a=Kt(o.key,"",n),i=Kt(o.value,a,n)):a=Kt(o,"",n),s.has(a))throw new Error("Ordered maps must not include duplicate keys");s.set(a,i)}return s}static from(t,n,s){const o=Iu(t,n,s),a=new this;return a.items=o.items,a}}Es.tag="tag:yaml.org,2002:omap";const ni={collection:"seq",identify:e=>e instanceof Map,nodeClass:Es,default:!1,tag:"tag:yaml.org,2002:omap",resolve(e,t){const n=Eu(e,t),s=[];for(const{key:o}of n.items)rt(o)&&(s.includes(o.value)?t(`Ordered maps must not include duplicate keys: ${o.value}`):s.push(o.value));return Object.assign(new Es,n)},createNode:(e,t,n)=>Es.from(e,t,n)};function Tu({value:e,source:t},n){return t&&(e?Mu:Au).test.test(t)?t:e?n.options.trueStr:n.options.falseStr}const Mu={identify:e=>e===!0,default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,resolve:()=>new Oe(!0),stringify:Tu},Au={identify:e=>e===!1,default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,resolve:()=>new Oe(!1),stringify:Tu},p0={identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:e=>e.slice(-3).toLowerCase()==="nan"?NaN:e[0]==="-"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,stringify:sn},g0={identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",format:"EXP",test:/^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,resolve:e=>parseFloat(e.replace(/_/g,"")),stringify(e){const t=Number(e.value);return isFinite(t)?t.toExponential():sn(e)}},x0={identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,resolve(e){const t=new Oe(parseFloat(e.replace(/_/g,""))),n=e.indexOf(".");if(n!==-1){const s=e.substring(n+1).replace(/_/g,"");s[s.length-1]==="0"&&(t.minFractionDigits=s.length)}return t},stringify:sn},Nr=e=>typeof e=="bigint"||Number.isInteger(e);function Oo(e,t,n,{intAsBigInt:s}){const o=e[0];if((o==="-"||o==="+")&&(t+=1),e=e.substring(t).replace(/_/g,""),s){switch(n){case 2:e=`0b${e}`;break;case 8:e=`0o${e}`;break;case 16:e=`0x${e}`;break}const i=BigInt(e);return o==="-"?BigInt(-1)*i:i}const a=parseInt(e,n);return o==="-"?-1*a:a}function si(e,t,n){const{value:s}=e;if(Nr(s)){const o=s.toString(t);return s<0?"-"+n+o.substr(1):n+o}return sn(e)}const b0={identify:Nr,default:!0,tag:"tag:yaml.org,2002:int",format:"BIN",test:/^[-+]?0b[0-1_]+$/,resolve:(e,t,n)=>Oo(e,2,2,n),stringify:e=>si(e,2,"0b")},y0={identify:Nr,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^[-+]?0[0-7_]+$/,resolve:(e,t,n)=>Oo(e,1,8,n),stringify:e=>si(e,8,"0")},w0={identify:Nr,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9][0-9_]*$/,resolve:(e,t,n)=>Oo(e,0,10,n),stringify:sn},k0={identify:Nr,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^[-+]?0x[0-9a-fA-F_]+$/,resolve:(e,t,n)=>Oo(e,2,16,n),stringify:e=>si(e,16,"0x")};class Is extends Wt{constructor(t){super(t),this.tag=Is.tag}add(t){let n;bt(t)?n=t:t&&typeof t=="object"&&"key"in t&&"value"in t&&t.value===null?n=new Lt(t.key,null):n=new Lt(t,null),Zn(this.items,n.key)||this.items.push(n)}get(t,n){const s=Zn(this.items,t);return!n&&bt(s)?rt(s.key)?s.key.value:s.key:s}set(t,n){if(typeof n!="boolean")throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof n}`);const s=Zn(this.items,t);s&&!n?this.items.splice(this.items.indexOf(s),1):!s&&n&&this.items.push(new Lt(t))}toJSON(t,n){return super.toJSON(t,n,Set)}toString(t,n,s){if(!t)return JSON.stringify(this);if(this.hasAllNullValues(!0))return super.toString(Object.assign({},t,{allNullValues:!0}),n,s);throw new Error("Set items must all have null values")}static from(t,n,s){const{replacer:o}=s,a=new this(t);if(n&&Symbol.iterator in Object(n))for(let i of n)typeof o=="function"&&(i=o.call(n,i,i)),a.items.push(Za(i,null,s));return a}}Is.tag="tag:yaml.org,2002:set";const ri={collection:"map",identify:e=>e instanceof Set,nodeClass:Is,default:!1,tag:"tag:yaml.org,2002:set",createNode:(e,t,n)=>Is.from(e,t,n),resolve(e,t){if(vr(e)){if(e.hasAllNullValues(!0))return Object.assign(new Is,e);t("Set items must all have null values")}else t("Expected a mapping for this tag");return e}};function oi(e,t){const n=e[0],s=n==="-"||n==="+"?e.substring(1):e,o=i=>t?BigInt(i):Number(i),a=s.replace(/_/g,"").split(":").reduce((i,l)=>i*o(60)+o(l),o(0));return n==="-"?o(-1)*a:a}function Lu(e){let{value:t}=e,n=i=>i;if(typeof t=="bigint")n=i=>BigInt(i);else if(isNaN(t)||!isFinite(t))return sn(e);let s="";t<0&&(s="-",t*=n(-1));const o=n(60),a=[t%o];return t<60?a.unshift(0):(t=(t-a[0])/o,a.unshift(t%o),t>=60&&(t=(t-a[0])/o,a.unshift(t))),s+a.map(i=>String(i).padStart(2,"0")).join(":").replace(/000000\d*$/,"")}const _u={identify:e=>typeof e=="bigint"||Number.isInteger(e),default:!0,tag:"tag:yaml.org,2002:int",format:"TIME",test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,resolve:(e,t,{intAsBigInt:n})=>oi(e,n),stringify:Lu},Ru={identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",format:"TIME",test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,resolve:e=>oi(e,!1),stringify:Lu},$o={identify:e=>e instanceof Date,default:!0,tag:"tag:yaml.org,2002:timestamp",test:RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$"),resolve(e){const t=e.match($o.test);if(!t)throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");const[,n,s,o,a,i,l]=t.map(Number),c=t[7]?Number((t[7]+"00").substr(1,3)):0;let d=Date.UTC(n,s-1,o,a||0,i||0,l||0,c);const h=t[8];if(h&&h!=="Z"){let u=oi(h,!1);Math.abs(u)<30&&(u*=60),d-=6e4*u}return new Date(d)},stringify:({value:e})=>e?.toISOString().replace(/(T00:00:00)?\.000Z$/,"")??""},Gl=[zs,Fs,_o,Ro,Mu,Au,b0,y0,w0,k0,p0,g0,x0,ei,yn,ni,ti,ri,_u,Ru,$o],Xl=new Map([["core",u0],["failsafe",[zs,Fs,_o]],["json",m0],["yaml11",Gl],["yaml-1.1",Gl]]),Zl={binary:ei,bool:Qa,float:vu,floatExp:ku,floatNaN:wu,floatTime:Ru,int:Su,intHex:Cu,intOct:Nu,intTime:_u,map:zs,merge:yn,null:Ro,omap:ni,pairs:ti,seq:Fs,set:ri,timestamp:$o},v0={"tag:yaml.org,2002:binary":ei,"tag:yaml.org,2002:merge":yn,"tag:yaml.org,2002:omap":ni,"tag:yaml.org,2002:pairs":ti,"tag:yaml.org,2002:set":ri,"tag:yaml.org,2002:timestamp":$o};function ia(e,t,n){const s=Xl.get(t);if(s&&!e)return n&&!s.includes(yn)?s.concat(yn):s.slice();let o=s;if(!o)if(Array.isArray(e))o=[];else{const a=Array.from(Xl.keys()).filter(i=>i!=="yaml11").map(i=>JSON.stringify(i)).join(", ");throw new Error(`Unknown schema "${t}"; use one of ${a} or define customTags array`)}if(Array.isArray(e))for(const a of e)o=o.concat(a);else typeof e=="function"&&(o=e(o.slice()));return n&&(o=o.concat(yn)),o.reduce((a,i)=>{const l=typeof i=="string"?Zl[i]:i;if(!l){const c=JSON.stringify(i),d=Object.keys(Zl).map(h=>JSON.stringify(h)).join(", ");throw new Error(`Unknown custom tag ${c}; use one of ${d}`)}return a.includes(l)||a.push(l),a},[])}const j0=(e,t)=>e.key<t.key?-1:e.key>t.key?1:0;class ai{constructor({compat:t,customTags:n,merge:s,resolveKnownTags:o,schema:a,sortMapEntries:i,toStringDefaults:l}){this.compat=Array.isArray(t)?ia(t,"compat"):t?ia(null,t):null,this.name=typeof a=="string"&&a||"core",this.knownTags=o?v0:{},this.tags=ia(n,this.name,s),this.toStringOptions=l??null,Object.defineProperty(this,An,{value:zs}),Object.defineProperty(this,cn,{value:_o}),Object.defineProperty(this,Ps,{value:Fs}),this.sortMapEntries=typeof i=="function"?i:i===!0?j0:null}clone(){const t=Object.create(ai.prototype,Object.getOwnPropertyDescriptors(this));return t.tags=this.tags.slice(),t}}function N0(e,t){const n=[];let s=t.directives===!0;if(t.directives!==!1&&e.directives){const c=e.directives.toString(e);c?(n.push(c),s=!0):e.directives.docStart&&(s=!0)}s&&n.push("---");const o=mu(e,t),{commentString:a}=o.options;if(e.commentBefore){n.length!==1&&n.unshift("");const c=a(e.commentBefore);n.unshift(bn(c,""))}let i=!1,l=null;if(e.contents){if(xt(e.contents)){if(e.contents.spaceBefore&&s&&n.push(""),e.contents.commentBefore){const h=a(e.contents.commentBefore);n.push(bn(h,""))}o.forceBlockIndent=!!e.comment,l=e.contents.comment}const c=l?void 0:()=>i=!0;let d=Ds(e.contents,o,()=>l=null,c);l&&(d+=Xn(d,"",a(l))),(d[0]==="|"||d[0]===">")&&n[n.length-1]==="---"?n[n.length-1]=`--- ${d}`:n.push(d)}else n.push(Ds(e.contents,o));if(e.directives?.docEnd)if(e.comment){const c=a(e.comment);c.includes(`
|
|
61
|
-
`)?(n.push("..."),n.push(bn(c,""))):n.push(`... ${c}`)}else n.push("...");else{let c=e.comment;c&&i&&(c=c.replace(/^\n+/,"")),c&&((!i||l)&&n[n.length-1]!==""&&n.push(""),n.push(bn(a(c),"")))}return n.join(`
|
|
62
|
-
`)+`
|
|
63
|
-
`}class Sr{constructor(t,n,s){this.commentBefore=null,this.comment=null,this.errors=[],this.warnings=[],Object.defineProperty(this,Ut,{value:ja});let o=null;typeof n=="function"||Array.isArray(n)?o=n:s===void 0&&n&&(s=n,n=void 0);const a=Object.assign({intAsBigInt:!1,keepSourceTokens:!1,logLevel:"warn",prettyErrors:!0,strict:!0,stringKeys:!1,uniqueKeys:!0,version:"1.2"},s);this.options=a;let{version:i}=a;s?._directives?(this.directives=s._directives.atDocument(),this.directives.yaml.explicit&&(i=this.directives.yaml.version)):this.directives=new At({version:i}),this.setSchema(i,s),this.contents=t===void 0?null:this.createNode(t,o,s)}clone(){const t=Object.create(Sr.prototype,{[Ut]:{value:ja}});return t.commentBefore=this.commentBefore,t.comment=this.comment,t.errors=this.errors.slice(),t.warnings=this.warnings.slice(),t.options=Object.assign({},this.options),this.directives&&(t.directives=this.directives.clone()),t.schema=this.schema.clone(),t.contents=xt(this.contents)?this.contents.clone(t.schema):this.contents,this.range&&(t.range=this.range.slice()),t}add(t){xs(this.contents)&&this.contents.add(t)}addIn(t,n){xs(this.contents)&&this.contents.addIn(t,n)}createAlias(t,n){if(!t.anchor){const s=cu(this);t.anchor=!n||s.has(n)?du(n||"a",s):n}return new Ga(t.anchor)}createNode(t,n,s){let o;if(typeof n=="function")t=n.call({"":t},"",t),o=n;else if(Array.isArray(n)){const v=y=>typeof y=="number"||y instanceof String||y instanceof Number,k=n.filter(v).map(String);k.length>0&&(n=n.concat(k)),o=n}else s===void 0&&n&&(s=n,n=void 0);const{aliasDuplicateObjects:a,anchorPrefix:i,flow:l,keepUndefined:c,onTagObj:d,tag:h}=s??{},{onAnchor:u,setAnchors:f,sourceObjects:m}=Qx(this,i||"a"),g={aliasDuplicateObjects:a??!0,keepUndefined:c??!1,onAnchor:u,onTagObj:d,replacer:o,schema:this.schema,sourceObjects:m},b=mr(t,h,g);return l&>(b)&&(b.flow=!0),f(),b}createPair(t,n,s={}){const o=this.createNode(t,null,s),a=this.createNode(n,null,s);return new Lt(o,a)}delete(t){return xs(this.contents)?this.contents.delete(t):!1}deleteIn(t){return tr(t)?this.contents==null?!1:(this.contents=null,!0):xs(this.contents)?this.contents.deleteIn(t):!1}get(t,n){return gt(this.contents)?this.contents.get(t,n):void 0}getIn(t,n){return tr(t)?!n&&rt(this.contents)?this.contents.value:this.contents:gt(this.contents)?this.contents.getIn(t,n):void 0}has(t){return gt(this.contents)?this.contents.has(t):!1}hasIn(t){return tr(t)?this.contents!==void 0:gt(this.contents)?this.contents.hasIn(t):!1}set(t,n){this.contents==null?this.contents=go(this.schema,[t],n):xs(this.contents)&&this.contents.set(t,n)}setIn(t,n){tr(t)?this.contents=n:this.contents==null?this.contents=go(this.schema,Array.from(t),n):xs(this.contents)&&this.contents.setIn(t,n)}setSchema(t,n={}){typeof t=="number"&&(t=String(t));let s;switch(t){case"1.1":this.directives?this.directives.yaml.version="1.1":this.directives=new At({version:"1.1"}),s={resolveKnownTags:!1,schema:"yaml-1.1"};break;case"1.2":case"next":this.directives?this.directives.yaml.version=t:this.directives=new At({version:t}),s={resolveKnownTags:!0,schema:"core"};break;case null:this.directives&&delete this.directives,s=null;break;default:{const o=JSON.stringify(t);throw new Error(`Expected '1.1', '1.2' or null as first argument, but found: ${o}`)}}if(n.schema instanceof Object)this.schema=n.schema;else if(s)this.schema=new ai(Object.assign(s,n));else throw new Error("With a null YAML version, the { schema: Schema } option is required")}toJS({json:t,jsonArg:n,mapAsMap:s,maxAliasCount:o,onAnchor:a,reviver:i}={}){const l={anchors:new Map,doc:this,keep:!t,mapAsMap:s===!0,mapKeyWarned:!1,maxAliasCount:typeof o=="number"?o:100},c=Kt(this.contents,n??"",l);if(typeof a=="function")for(const{count:d,res:h}of l.anchors.values())a(h,d);return typeof i=="function"?Ns(i,{"":c},"",c):c}toJSON(t,n){return this.toJS({json:!0,jsonArg:t,mapAsMap:!1,onAnchor:n})}toString(t={}){if(this.errors.length>0)throw new Error("Document with errors cannot be stringified");if("indent"in t&&(!Number.isInteger(t.indent)||Number(t.indent)<=0)){const n=JSON.stringify(t.indent);throw new Error(`"indent" option must be a positive integer, not ${n}`)}return N0(this,t)}}function xs(e){if(gt(e))return!0;throw new Error("Expected a YAML collection as document contents")}class Du extends Error{constructor(t,n,s,o){super(),this.name=t,this.code=s,this.message=o,this.pos=n}}class nr extends Du{constructor(t,n,s){super("YAMLParseError",t,n,s)}}class S0 extends Du{constructor(t,n,s){super("YAMLWarning",t,n,s)}}const Ql=(e,t)=>n=>{if(n.pos[0]===-1)return;n.linePos=n.pos.map(l=>t.linePos(l));const{line:s,col:o}=n.linePos[0];n.message+=` at line ${s}, column ${o}`;let a=o-1,i=e.substring(t.lineStarts[s-1],t.lineStarts[s]).replace(/[\n\r]+$/,"");if(a>=60&&i.length>80){const l=Math.min(a-39,i.length-79);i="…"+i.substring(l),a-=l-1}if(i.length>80&&(i=i.substring(0,79)+"…"),s>1&&/^ *$/.test(i.substring(0,a))){let l=e.substring(t.lineStarts[s-2],t.lineStarts[s-1]);l.length>80&&(l=l.substring(0,79)+`…
|
|
64
|
-
`),i=l+i}if(/[^ ]/.test(i)){let l=1;const c=n.linePos[1];c?.line===s&&c.col>o&&(l=Math.max(1,Math.min(c.col-o,80-a)));const d=" ".repeat(a)+"^".repeat(l);n.message+=`:
|
|
65
|
-
|
|
66
|
-
${i}
|
|
67
|
-
${d}
|
|
68
|
-
`}};function Os(e,{flow:t,indicator:n,next:s,offset:o,onError:a,parentIndent:i,startOnNewline:l}){let c=!1,d=l,h=l,u="",f="",m=!1,g=!1,b=null,v=null,k=null,y=null,x=null,w=null,S=null;for(const C of e)switch(g&&(C.type!=="space"&&C.type!=="newline"&&C.type!=="comma"&&a(C.offset,"MISSING_CHAR","Tags and anchors must be separated from the next token by white space"),g=!1),b&&(d&&C.type!=="comment"&&C.type!=="newline"&&a(b,"TAB_AS_INDENT","Tabs are not allowed as indentation"),b=null),C.type){case"space":!t&&(n!=="doc-start"||s?.type!=="flow-collection")&&C.source.includes(" ")&&(b=C),h=!0;break;case"comment":{h||a(C,"MISSING_CHAR","Comments must be separated from other tokens by white space characters");const R=C.source.substring(1)||" ";u?u+=f+R:u=R,f="",d=!1;break}case"newline":d?u?u+=C.source:(!w||n!=="seq-item-ind")&&(c=!0):f+=C.source,d=!0,m=!0,(v||k)&&(y=C),h=!0;break;case"anchor":v&&a(C,"MULTIPLE_ANCHORS","A node can have at most one anchor"),C.source.endsWith(":")&&a(C.offset+C.source.length-1,"BAD_ALIAS","Anchor ending in : is ambiguous",!0),v=C,S??(S=C.offset),d=!1,h=!1,g=!0;break;case"tag":{k&&a(C,"MULTIPLE_TAGS","A node can have at most one tag"),k=C,S??(S=C.offset),d=!1,h=!1,g=!0;break}case n:(v||k)&&a(C,"BAD_PROP_ORDER",`Anchors and tags must be after the ${C.source} indicator`),w&&a(C,"UNEXPECTED_TOKEN",`Unexpected ${C.source} in ${t??"collection"}`),w=C,d=n==="seq-item-ind"||n==="explicit-key-ind",h=!1;break;case"comma":if(t){x&&a(C,"UNEXPECTED_TOKEN",`Unexpected , in ${t}`),x=C,d=!1,h=!1;break}default:a(C,"UNEXPECTED_TOKEN",`Unexpected ${C.type} token`),d=!1,h=!1}const j=e[e.length-1],E=j?j.offset+j.source.length:o;return g&&s&&s.type!=="space"&&s.type!=="newline"&&s.type!=="comma"&&(s.type!=="scalar"||s.source!=="")&&a(s.offset,"MISSING_CHAR","Tags and anchors must be separated from the next token by white space"),b&&(d&&b.indent<=i||s?.type==="block-map"||s?.type==="block-seq")&&a(b,"TAB_AS_INDENT","Tabs are not allowed as indentation"),{comma:x,found:w,spaceBefore:c,comment:u,hasNewline:m,anchor:v,tag:k,newlineAfterProp:y,end:E,start:S??E}}function pr(e){if(!e)return null;switch(e.type){case"alias":case"scalar":case"double-quoted-scalar":case"single-quoted-scalar":if(e.source.includes(`
|
|
69
|
-
`))return!0;if(e.end){for(const t of e.end)if(t.type==="newline")return!0}return!1;case"flow-collection":for(const t of e.items){for(const n of t.start)if(n.type==="newline")return!0;if(t.sep){for(const n of t.sep)if(n.type==="newline")return!0}if(pr(t.key)||pr(t.value))return!0}return!1;default:return!0}}function Ea(e,t,n){if(t?.type==="flow-collection"){const s=t.end[0];s.indent===e&&(s.source==="]"||s.source==="}")&&pr(t)&&n(s,"BAD_INDENT","Flow end indicator should be more indented than parent",!0)}}function Ou(e,t,n){const{uniqueKeys:s}=e.options;if(s===!1)return!1;const o=typeof s=="function"?s:(a,i)=>a===i||rt(a)&&rt(i)&&a.value===i.value;return t.some(a=>o(a.key,n))}const Jl="All mapping items must start at the same column";function C0({composeNode:e,composeEmptyNode:t},n,s,o,a){const i=a?.nodeClass??Wt,l=new i(n.schema);n.atRoot&&(n.atRoot=!1);let c=s.offset,d=null;for(const h of s.items){const{start:u,key:f,sep:m,value:g}=h,b=Os(u,{indicator:"explicit-key-ind",next:f??m?.[0],offset:c,onError:o,parentIndent:s.indent,startOnNewline:!0}),v=!b.found;if(v){if(f&&(f.type==="block-seq"?o(c,"BLOCK_AS_IMPLICIT_KEY","A block sequence may not be used as an implicit map key"):"indent"in f&&f.indent!==s.indent&&o(c,"BAD_INDENT",Jl)),!b.anchor&&!b.tag&&!m){d=b.end,b.comment&&(l.comment?l.comment+=`
|
|
70
|
-
`+b.comment:l.comment=b.comment);continue}(b.newlineAfterProp||pr(f))&&o(f??u[u.length-1],"MULTILINE_IMPLICIT_KEY","Implicit keys need to be on a single line")}else b.found?.indent!==s.indent&&o(c,"BAD_INDENT",Jl);n.atKey=!0;const k=b.end,y=f?e(n,f,b,o):t(n,k,u,null,b,o);n.schema.compat&&Ea(s.indent,f,o),n.atKey=!1,Ou(n,l.items,y)&&o(k,"DUPLICATE_KEY","Map keys must be unique");const x=Os(m??[],{indicator:"map-value-ind",next:g,offset:y.range[2],onError:o,parentIndent:s.indent,startOnNewline:!f||f.type==="block-scalar"});if(c=x.end,x.found){v&&(g?.type==="block-map"&&!x.hasNewline&&o(c,"BLOCK_AS_IMPLICIT_KEY","Nested mappings are not allowed in compact mappings"),n.options.strict&&b.start<x.found.offset-1024&&o(y.range,"KEY_OVER_1024_CHARS","The : indicator must be at most 1024 chars after the start of an implicit block mapping key"));const w=g?e(n,g,x,o):t(n,c,m,null,x,o);n.schema.compat&&Ea(s.indent,g,o),c=w.range[2];const S=new Lt(y,w);n.options.keepSourceTokens&&(S.srcToken=h),l.items.push(S)}else{v&&o(y.range,"MISSING_CHAR","Implicit map keys need to be followed by map values"),x.comment&&(y.comment?y.comment+=`
|
|
71
|
-
`+x.comment:y.comment=x.comment);const w=new Lt(y);n.options.keepSourceTokens&&(w.srcToken=h),l.items.push(w)}}return d&&d<c&&o(d,"IMPOSSIBLE","Map comment with trailing content"),l.range=[s.offset,c,d??c],l}function E0({composeNode:e,composeEmptyNode:t},n,s,o,a){const i=a?.nodeClass??ns,l=new i(n.schema);n.atRoot&&(n.atRoot=!1),n.atKey&&(n.atKey=!1);let c=s.offset,d=null;for(const{start:h,value:u}of s.items){const f=Os(h,{indicator:"seq-item-ind",next:u,offset:c,onError:o,parentIndent:s.indent,startOnNewline:!0});if(!f.found)if(f.anchor||f.tag||u)u?.type==="block-seq"?o(f.end,"BAD_INDENT","All sequence items must start at the same column"):o(c,"MISSING_CHAR","Sequence item without - indicator");else{d=f.end,f.comment&&(l.comment=f.comment);continue}const m=u?e(n,u,f,o):t(n,f.end,h,null,f,o);n.schema.compat&&Ea(s.indent,u,o),c=m.range[2],l.items.push(m)}return l.range=[s.offset,c,d??c],l}function Cr(e,t,n,s){let o="";if(e){let a=!1,i="";for(const l of e){const{source:c,type:d}=l;switch(d){case"space":a=!0;break;case"comment":{n&&!a&&s(l,"MISSING_CHAR","Comments must be separated from other tokens by white space characters");const h=c.substring(1)||" ";o?o+=i+h:o=h,i="";break}case"newline":o&&(i+=c),a=!0;break;default:s(l,"UNEXPECTED_TOKEN",`Unexpected ${d} at node end`)}t+=c.length}}return{comment:o,offset:t}}const la="Block collections are not allowed within flow collections",ca=e=>e&&(e.type==="block-map"||e.type==="block-seq");function I0({composeNode:e,composeEmptyNode:t},n,s,o,a){const i=s.start.source==="{",l=i?"flow map":"flow sequence",c=a?.nodeClass??(i?Wt:ns),d=new c(n.schema);d.flow=!0;const h=n.atRoot;h&&(n.atRoot=!1),n.atKey&&(n.atKey=!1);let u=s.offset+s.start.source.length;for(let v=0;v<s.items.length;++v){const k=s.items[v],{start:y,key:x,sep:w,value:S}=k,j=Os(y,{flow:l,indicator:"explicit-key-ind",next:x??w?.[0],offset:u,onError:o,parentIndent:s.indent,startOnNewline:!1});if(!j.found){if(!j.anchor&&!j.tag&&!w&&!S){v===0&&j.comma?o(j.comma,"UNEXPECTED_TOKEN",`Unexpected , in ${l}`):v<s.items.length-1&&o(j.start,"UNEXPECTED_TOKEN",`Unexpected empty item in ${l}`),j.comment&&(d.comment?d.comment+=`
|
|
72
|
-
`+j.comment:d.comment=j.comment),u=j.end;continue}!i&&n.options.strict&&pr(x)&&o(x,"MULTILINE_IMPLICIT_KEY","Implicit keys of flow sequence pairs need to be on a single line")}if(v===0)j.comma&&o(j.comma,"UNEXPECTED_TOKEN",`Unexpected , in ${l}`);else if(j.comma||o(j.start,"MISSING_CHAR",`Missing , between ${l} items`),j.comment){let E="";e:for(const C of y)switch(C.type){case"comma":case"space":break;case"comment":E=C.source.substring(1);break e;default:break e}if(E){let C=d.items[d.items.length-1];bt(C)&&(C=C.value??C.key),C.comment?C.comment+=`
|
|
73
|
-
`+E:C.comment=E,j.comment=j.comment.substring(E.length+1)}}if(!i&&!w&&!j.found){const E=S?e(n,S,j,o):t(n,j.end,w,null,j,o);d.items.push(E),u=E.range[2],ca(S)&&o(E.range,"BLOCK_IN_FLOW",la)}else{n.atKey=!0;const E=j.end,C=x?e(n,x,j,o):t(n,E,y,null,j,o);ca(x)&&o(C.range,"BLOCK_IN_FLOW",la),n.atKey=!1;const R=Os(w??[],{flow:l,indicator:"map-value-ind",next:S,offset:C.range[2],onError:o,parentIndent:s.indent,startOnNewline:!1});if(R.found){if(!i&&!j.found&&n.options.strict){if(w)for(const D of w){if(D===R.found)break;if(D.type==="newline"){o(D,"MULTILINE_IMPLICIT_KEY","Implicit keys of flow sequence pairs need to be on a single line");break}}j.start<R.found.offset-1024&&o(R.found,"KEY_OVER_1024_CHARS","The : indicator must be at most 1024 chars after the start of an implicit flow sequence key")}}else S&&("source"in S&&S.source?.[0]===":"?o(S,"MISSING_CHAR",`Missing space after : in ${l}`):o(R.start,"MISSING_CHAR",`Missing , or : between ${l} items`));const P=S?e(n,S,R,o):R.found?t(n,R.end,w,null,R,o):null;P?ca(S)&&o(P.range,"BLOCK_IN_FLOW",la):R.comment&&(C.comment?C.comment+=`
|
|
74
|
-
`+R.comment:C.comment=R.comment);const T=new Lt(C,P);if(n.options.keepSourceTokens&&(T.srcToken=k),i){const D=d;Ou(n,D.items,C)&&o(E,"DUPLICATE_KEY","Map keys must be unique"),D.items.push(T)}else{const D=new Wt(n.schema);D.flow=!0,D.items.push(T);const z=(P??C).range;D.range=[C.range[0],z[1],z[2]],d.items.push(D)}u=P?P.range[2]:R.end}}const f=i?"}":"]",[m,...g]=s.end;let b=u;if(m?.source===f)b=m.offset+m.source.length;else{const v=l[0].toUpperCase()+l.substring(1),k=h?`${v} must end with a ${f}`:`${v} in block collection must be sufficiently indented and end with a ${f}`;o(u,h?"MISSING_CHAR":"BAD_INDENT",k),m&&m.source.length!==1&&g.unshift(m)}if(g.length>0){const v=Cr(g,b,n.options.strict,o);v.comment&&(d.comment?d.comment+=`
|
|
75
|
-
`+v.comment:d.comment=v.comment),d.range=[s.offset,b,v.offset]}else d.range=[s.offset,b,b];return d}function da(e,t,n,s,o,a){const i=n.type==="block-map"?C0(e,t,n,s,a):n.type==="block-seq"?E0(e,t,n,s,a):I0(e,t,n,s,a),l=i.constructor;return o==="!"||o===l.tagName?(i.tag=l.tagName,i):(o&&(i.tag=o),i)}function T0(e,t,n,s,o){const a=s.tag,i=a?t.directives.tagName(a.source,f=>o(a,"TAG_RESOLVE_FAILED",f)):null;if(n.type==="block-seq"){const{anchor:f,newlineAfterProp:m}=s,g=f&&a?f.offset>a.offset?f:a:f??a;g&&(!m||m.offset<g.offset)&&o(g,"MISSING_CHAR","Missing newline after block sequence props")}const l=n.type==="block-map"?"map":n.type==="block-seq"?"seq":n.start.source==="{"?"map":"seq";if(!a||!i||i==="!"||i===Wt.tagName&&l==="map"||i===ns.tagName&&l==="seq")return da(e,t,n,o,i);let c=t.schema.tags.find(f=>f.tag===i&&f.collection===l);if(!c){const f=t.schema.knownTags[i];if(f?.collection===l)t.schema.tags.push(Object.assign({},f,{default:!1})),c=f;else return f?o(a,"BAD_COLLECTION_TYPE",`${f.tag} used for ${l} collection, but expects ${f.collection??"scalar"}`,!0):o(a,"TAG_RESOLVE_FAILED",`Unresolved tag: ${i}`,!0),da(e,t,n,o,i)}const d=da(e,t,n,o,i,c),h=c.resolve?.(d,f=>o(a,"TAG_RESOLVE_FAILED",f),t.options)??d,u=xt(h)?h:new Oe(h);return u.range=d.range,u.tag=i,c?.format&&(u.format=c.format),u}function M0(e,t,n){const s=t.offset,o=A0(t,e.options.strict,n);if(!o)return{value:"",type:null,comment:"",range:[s,s,s]};const a=o.mode===">"?Oe.BLOCK_FOLDED:Oe.BLOCK_LITERAL,i=t.source?L0(t.source):[];let l=i.length;for(let b=i.length-1;b>=0;--b){const v=i[b][1];if(v===""||v==="\r")l=b;else break}if(l===0){const b=o.chomp==="+"&&i.length>0?`
|
|
76
|
-
`.repeat(Math.max(1,i.length-1)):"";let v=s+o.length;return t.source&&(v+=t.source.length),{value:b,type:a,comment:o.comment,range:[s,v,v]}}let c=t.indent+o.indent,d=t.offset+o.length,h=0;for(let b=0;b<l;++b){const[v,k]=i[b];if(k===""||k==="\r")o.indent===0&&v.length>c&&(c=v.length);else{v.length<c&&n(d+v.length,"MISSING_CHAR","Block scalars with more-indented leading empty lines must use an explicit indentation indicator"),o.indent===0&&(c=v.length),h=b,c===0&&!e.atRoot&&n(d,"BAD_INDENT","Block scalar values in collections must be indented");break}d+=v.length+k.length+1}for(let b=i.length-1;b>=l;--b)i[b][0].length>c&&(l=b+1);let u="",f="",m=!1;for(let b=0;b<h;++b)u+=i[b][0].slice(c)+`
|
|
77
|
-
`;for(let b=h;b<l;++b){let[v,k]=i[b];d+=v.length+k.length+1;const y=k[k.length-1]==="\r";if(y&&(k=k.slice(0,-1)),k&&v.length<c){const w=`Block scalar lines must not be less indented than their ${o.indent?"explicit indentation indicator":"first line"}`;n(d-k.length-(y?2:1),"BAD_INDENT",w),v=""}a===Oe.BLOCK_LITERAL?(u+=f+v.slice(c)+k,f=`
|
|
78
|
-
`):v.length>c||k[0]===" "?(f===" "?f=`
|
|
79
|
-
`:!m&&f===`
|
|
80
|
-
`&&(f=`
|
|
81
|
-
|
|
82
|
-
`),u+=f+v.slice(c)+k,f=`
|
|
83
|
-
`,m=!0):k===""?f===`
|
|
84
|
-
`?u+=`
|
|
85
|
-
`:f=`
|
|
86
|
-
`:(u+=f+k,f=" ",m=!1)}switch(o.chomp){case"-":break;case"+":for(let b=l;b<i.length;++b)u+=`
|
|
87
|
-
`+i[b][0].slice(c);u[u.length-1]!==`
|
|
88
|
-
`&&(u+=`
|
|
89
|
-
`);break;default:u+=`
|
|
90
|
-
`}const g=s+o.length+t.source.length;return{value:u,type:a,comment:o.comment,range:[s,g,g]}}function A0({offset:e,props:t},n,s){if(t[0].type!=="block-scalar-header")return s(t[0],"IMPOSSIBLE","Block scalar header not found"),null;const{source:o}=t[0],a=o[0];let i=0,l="",c=-1;for(let f=1;f<o.length;++f){const m=o[f];if(!l&&(m==="-"||m==="+"))l=m;else{const g=Number(m);!i&&g?i=g:c===-1&&(c=e+f)}}c!==-1&&s(c,"UNEXPECTED_TOKEN",`Block scalar header includes extra characters: ${o}`);let d=!1,h="",u=o.length;for(let f=1;f<t.length;++f){const m=t[f];switch(m.type){case"space":d=!0;case"newline":u+=m.source.length;break;case"comment":n&&!d&&s(m,"MISSING_CHAR","Comments must be separated from other tokens by white space characters"),u+=m.source.length,h=m.source.substring(1);break;case"error":s(m,"UNEXPECTED_TOKEN",m.message),u+=m.source.length;break;default:{const g=`Unexpected token in block scalar header: ${m.type}`;s(m,"UNEXPECTED_TOKEN",g);const b=m.source;b&&typeof b=="string"&&(u+=b.length)}}}return{mode:a,indent:i,chomp:l,comment:h,length:u}}function L0(e){const t=e.split(/\n( *)/),n=t[0],s=n.match(/^( *)/),a=[s?.[1]?[s[1],n.slice(s[1].length)]:["",n]];for(let i=1;i<t.length;i+=2)a.push([t[i],t[i+1]]);return a}function _0(e,t,n){const{offset:s,type:o,source:a,end:i}=e;let l,c;const d=(f,m,g)=>n(s+f,m,g);switch(o){case"scalar":l=Oe.PLAIN,c=R0(a,d);break;case"single-quoted-scalar":l=Oe.QUOTE_SINGLE,c=D0(a,d);break;case"double-quoted-scalar":l=Oe.QUOTE_DOUBLE,c=O0(a,d);break;default:return n(e,"UNEXPECTED_TOKEN",`Expected a flow scalar value, but found: ${o}`),{value:"",type:null,comment:"",range:[s,s+a.length,s+a.length]}}const h=s+a.length,u=Cr(i,h,t,n);return{value:c,type:l,comment:u.comment,range:[s,h,u.offset]}}function R0(e,t){let n="";switch(e[0]){case" ":n="a tab character";break;case",":n="flow indicator character ,";break;case"%":n="directive indicator character %";break;case"|":case">":{n=`block scalar indicator ${e[0]}`;break}case"@":case"`":{n=`reserved character ${e[0]}`;break}}return n&&t(0,"BAD_SCALAR_START",`Plain value cannot start with ${n}`),$u(e)}function D0(e,t){return(e[e.length-1]!=="'"||e.length===1)&&t(e.length,"MISSING_CHAR","Missing closing 'quote"),$u(e.slice(1,-1)).replace(/''/g,"'")}function $u(e){let t,n;try{t=new RegExp(`(.*?)(?<![ ])[ ]*\r?
|
|
91
|
-
`,"sy"),n=new RegExp(`[ ]*(.*?)(?:(?<![ ])[ ]*)?\r?
|
|
92
|
-
`,"sy")}catch{t=/(.*?)[ \t]*\r?\n/sy,n=/[ \t]*(.*?)[ \t]*\r?\n/sy}let s=t.exec(e);if(!s)return e;let o=s[1],a=" ",i=t.lastIndex;for(n.lastIndex=i;s=n.exec(e);)s[1]===""?a===`
|
|
93
|
-
`?o+=a:a=`
|
|
94
|
-
`:(o+=a+s[1],a=" "),i=n.lastIndex;const l=/[ \t]*(.*)/sy;return l.lastIndex=i,s=l.exec(e),o+a+(s?.[1]??"")}function O0(e,t){let n="";for(let s=1;s<e.length-1;++s){const o=e[s];if(!(o==="\r"&&e[s+1]===`
|
|
95
|
-
`))if(o===`
|
|
96
|
-
`){const{fold:a,offset:i}=$0(e,s);n+=a,s=i}else if(o==="\\"){let a=e[++s];const i=P0[a];if(i)n+=i;else if(a===`
|
|
97
|
-
`)for(a=e[s+1];a===" "||a===" ";)a=e[++s+1];else if(a==="\r"&&e[s+1]===`
|
|
98
|
-
`)for(a=e[++s+1];a===" "||a===" ";)a=e[++s+1];else if(a==="x"||a==="u"||a==="U"){const l=a==="x"?2:a==="u"?4:8;n+=B0(e,s+1,l,t),s+=l}else{const l=e.substr(s-1,2);t(s-1,"BAD_DQ_ESCAPE",`Invalid escape sequence ${l}`),n+=l}}else if(o===" "||o===" "){const a=s;let i=e[s+1];for(;i===" "||i===" ";)i=e[++s+1];i!==`
|
|
99
|
-
`&&!(i==="\r"&&e[s+2]===`
|
|
100
|
-
`)&&(n+=s>a?e.slice(a,s+1):o)}else n+=o}return(e[e.length-1]!=='"'||e.length===1)&&t(e.length,"MISSING_CHAR",'Missing closing "quote'),n}function $0(e,t){let n="",s=e[t+1];for(;(s===" "||s===" "||s===`
|
|
101
|
-
`||s==="\r")&&!(s==="\r"&&e[t+2]!==`
|
|
102
|
-
`);)s===`
|
|
103
|
-
`&&(n+=`
|
|
104
|
-
`),t+=1,s=e[t+1];return n||(n=" "),{fold:n,offset:t}}const P0={0:"\0",a:"\x07",b:"\b",e:"\x1B",f:"\f",n:`
|
|
105
|
-
`,r:"\r",t:" ",v:"\v",N:"
",_:" ",L:"\u2028",P:"\u2029"," ":" ",'"':'"',"/":"/","\\":"\\"," ":" "};function B0(e,t,n,s){const o=e.substr(t,n),i=o.length===n&&/^[0-9a-fA-F]+$/.test(o)?parseInt(o,16):NaN;try{return String.fromCodePoint(i)}catch{const l=e.substr(t-2,n+2);return s(t-2,"BAD_DQ_ESCAPE",`Invalid escape sequence ${l}`),l}}function Pu(e,t,n,s){const{value:o,type:a,comment:i,range:l}=t.type==="block-scalar"?M0(e,t,s):_0(t,e.options.strict,s),c=n?e.directives.tagName(n.source,u=>s(n,"TAG_RESOLVE_FAILED",u)):null;let d;e.options.stringKeys&&e.atKey?d=e.schema[cn]:c?d=q0(e.schema,o,c,n,s):t.type==="scalar"?d=z0(e,o,t,s):d=e.schema[cn];let h;try{const u=d.resolve(o,f=>s(n??t,"TAG_RESOLVE_FAILED",f),e.options);h=rt(u)?u:new Oe(u)}catch(u){const f=u instanceof Error?u.message:String(u);s(n??t,"TAG_RESOLVE_FAILED",f),h=new Oe(o)}return h.range=l,h.source=o,a&&(h.type=a),c&&(h.tag=c),d.format&&(h.format=d.format),i&&(h.comment=i),h}function q0(e,t,n,s,o){if(n==="!")return e[cn];const a=[];for(const l of e.tags)if(!l.collection&&l.tag===n)if(l.default&&l.test)a.push(l);else return l;for(const l of a)if(l.test?.test(t))return l;const i=e.knownTags[n];return i&&!i.collection?(e.tags.push(Object.assign({},i,{default:!1,test:void 0})),i):(o(s,"TAG_RESOLVE_FAILED",`Unresolved tag: ${n}`,n!=="tag:yaml.org,2002:str"),e[cn])}function z0({atKey:e,directives:t,schema:n},s,o,a){const i=n.tags.find(l=>(l.default===!0||e&&l.default==="key")&&l.test?.test(s))||n[cn];if(n.compat){const l=n.compat.find(c=>c.default&&c.test?.test(s))??n[cn];if(i.tag!==l.tag){const c=t.tagString(i.tag),d=t.tagString(l.tag),h=`Value may be parsed as either ${c} or ${d}`;a(o,"TAG_RESOLVE_FAILED",h,!0)}}return i}function F0(e,t,n){if(t){n??(n=t.length);for(let s=n-1;s>=0;--s){let o=t[s];switch(o.type){case"space":case"comment":case"newline":e-=o.source.length;continue}for(o=t[++s];o?.type==="space";)e+=o.source.length,o=t[++s];break}}return e}const H0={composeNode:Bu,composeEmptyNode:ii};function Bu(e,t,n,s){const o=e.atKey,{spaceBefore:a,comment:i,anchor:l,tag:c}=n;let d,h=!0;switch(t.type){case"alias":d=V0(e,t,s),(l||c)&&s(t,"ALIAS_PROPS","An alias node must not specify any properties");break;case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":case"block-scalar":d=Pu(e,t,c,s),l&&(d.anchor=l.source.substring(1));break;case"block-map":case"block-seq":case"flow-collection":try{d=T0(H0,e,t,n,s),l&&(d.anchor=l.source.substring(1))}catch(u){const f=u instanceof Error?u.message:String(u);s(t,"RESOURCE_EXHAUSTION",f)}break;default:{const u=t.type==="error"?t.message:`Unsupported token (type: ${t.type})`;s(t,"UNEXPECTED_TOKEN",u),h=!1}}return d??(d=ii(e,t.offset,void 0,null,n,s)),l&&d.anchor===""&&s(l,"BAD_ALIAS","Anchor cannot be an empty string"),o&&e.options.stringKeys&&(!rt(d)||typeof d.value!="string"||d.tag&&d.tag!=="tag:yaml.org,2002:str")&&s(c??t,"NON_STRING_KEY","With stringKeys, all keys must be strings"),a&&(d.spaceBefore=!0),i&&(t.type==="scalar"&&t.source===""?d.comment=i:d.commentBefore=i),e.options.keepSourceTokens&&h&&(d.srcToken=t),d}function ii(e,t,n,s,{spaceBefore:o,comment:a,anchor:i,tag:l,end:c},d){const h={type:"scalar",offset:F0(t,n,s),indent:-1,source:""},u=Pu(e,h,l,d);return i&&(u.anchor=i.source.substring(1),u.anchor===""&&d(i,"BAD_ALIAS","Anchor cannot be an empty string")),o&&(u.spaceBefore=!0),a&&(u.comment=a,u.range[2]=c),u}function V0({options:e},{offset:t,source:n,end:s},o){const a=new Ga(n.substring(1));a.source===""&&o(t,"BAD_ALIAS","Alias cannot be an empty string"),a.source.endsWith(":")&&o(t+n.length-1,"BAD_ALIAS","Alias ending in : is ambiguous",!0);const i=t+n.length,l=Cr(s,i,e.strict,o);return a.range=[t,i,l.offset],l.comment&&(a.comment=l.comment),a}function W0(e,t,{offset:n,start:s,value:o,end:a},i){const l=Object.assign({_directives:t},e),c=new Sr(void 0,l),d={atKey:!1,atRoot:!0,directives:c.directives,options:c.options,schema:c.schema},h=Os(s,{indicator:"doc-start",next:o??a?.[0],offset:n,onError:i,parentIndent:0,startOnNewline:!0});h.found&&(c.directives.docStart=!0,o&&(o.type==="block-map"||o.type==="block-seq")&&!h.hasNewline&&i(h.end,"MISSING_CHAR","Block collection cannot start on same line with directives-end marker")),c.contents=o?Bu(d,o,h,i):ii(d,h.end,s,null,h,i);const u=c.contents.range[2],f=Cr(a,u,!1,i);return f.comment&&(c.comment=f.comment),c.range=[n,u,f.offset],c}function er(e){if(typeof e=="number")return[e,e+1];if(Array.isArray(e))return e.length===2?e:[e[0],e[1]];const{offset:t,source:n}=e;return[t,t+(typeof n=="string"?n.length:1)]}function ec(e){let t="",n=!1,s=!1;for(let o=0;o<e.length;++o){const a=e[o];switch(a[0]){case"#":t+=(t===""?"":s?`
|
|
106
|
-
|
|
107
|
-
`:`
|
|
108
|
-
`)+(a.substring(1)||" "),n=!0,s=!1;break;case"%":e[o+1]?.[0]!=="#"&&(o+=1),n=!1;break;default:n||(s=!0),n=!1}}return{comment:t,afterEmptyLine:s}}class K0{constructor(t={}){this.doc=null,this.atDirectives=!1,this.prelude=[],this.errors=[],this.warnings=[],this.onError=(n,s,o,a)=>{const i=er(n);a?this.warnings.push(new S0(i,s,o)):this.errors.push(new nr(i,s,o))},this.directives=new At({version:t.version||"1.2"}),this.options=t}decorate(t,n){const{comment:s,afterEmptyLine:o}=ec(this.prelude);if(s){const a=t.contents;if(n)t.comment=t.comment?`${t.comment}
|
|
109
|
-
${s}`:s;else if(o||t.directives.docStart||!a)t.commentBefore=s;else if(gt(a)&&!a.flow&&a.items.length>0){let i=a.items[0];bt(i)&&(i=i.key);const l=i.commentBefore;i.commentBefore=l?`${s}
|
|
110
|
-
${l}`:s}else{const i=a.commentBefore;a.commentBefore=i?`${s}
|
|
111
|
-
${i}`:s}}if(n){for(let a=0;a<this.errors.length;++a)t.errors.push(this.errors[a]);for(let a=0;a<this.warnings.length;++a)t.warnings.push(this.warnings[a])}else t.errors=this.errors,t.warnings=this.warnings;this.prelude=[],this.errors=[],this.warnings=[]}streamInfo(){return{comment:ec(this.prelude).comment,directives:this.directives,errors:this.errors,warnings:this.warnings}}*compose(t,n=!1,s=-1){for(const o of t)yield*this.next(o);yield*this.end(n,s)}*next(t){switch(t.type){case"directive":this.directives.add(t.source,(n,s,o)=>{const a=er(t);a[0]+=n,this.onError(a,"BAD_DIRECTIVE",s,o)}),this.prelude.push(t.source),this.atDirectives=!0;break;case"document":{const n=W0(this.options,this.directives,t,this.onError);this.atDirectives&&!n.directives.docStart&&this.onError(t,"MISSING_CHAR","Missing directives-end/doc-start indicator line"),this.decorate(n,!1),this.doc&&(yield this.doc),this.doc=n,this.atDirectives=!1;break}case"byte-order-mark":case"space":break;case"comment":case"newline":this.prelude.push(t.source);break;case"error":{const n=t.source?`${t.message}: ${JSON.stringify(t.source)}`:t.message,s=new nr(er(t),"UNEXPECTED_TOKEN",n);this.atDirectives||!this.doc?this.errors.push(s):this.doc.errors.push(s);break}case"doc-end":{if(!this.doc){const s="Unexpected doc-end without preceding document";this.errors.push(new nr(er(t),"UNEXPECTED_TOKEN",s));break}this.doc.directives.docEnd=!0;const n=Cr(t.end,t.offset+t.source.length,this.doc.options.strict,this.onError);if(this.decorate(this.doc,!0),n.comment){const s=this.doc.comment;this.doc.comment=s?`${s}
|
|
112
|
-
${n.comment}`:n.comment}this.doc.range[2]=n.offset;break}default:this.errors.push(new nr(er(t),"UNEXPECTED_TOKEN",`Unsupported token ${t.type}`))}}*end(t=!1,n=-1){if(this.doc)this.decorate(this.doc,!0),yield this.doc,this.doc=null;else if(t){const s=Object.assign({_directives:this.directives},this.options),o=new Sr(void 0,s);this.atDirectives&&this.onError(n,"MISSING_CHAR","Missing directives-end indicator line"),o.range=[0,n,n],this.decorate(o,!1),yield o}}}const qu="\uFEFF",zu="",Fu="",Ia="";function U0(e){switch(e){case qu:return"byte-order-mark";case zu:return"doc-mode";case Fu:return"flow-error-end";case Ia:return"scalar";case"---":return"doc-start";case"...":return"doc-end";case"":case`
|
|
113
|
-
`:case`\r
|
|
114
|
-
`:return"newline";case"-":return"seq-item-ind";case"?":return"explicit-key-ind";case":":return"map-value-ind";case"{":return"flow-map-start";case"}":return"flow-map-end";case"[":return"flow-seq-start";case"]":return"flow-seq-end";case",":return"comma"}switch(e[0]){case" ":case" ":return"space";case"#":return"comment";case"%":return"directive-line";case"*":return"alias";case"&":return"anchor";case"!":return"tag";case"'":return"single-quoted-scalar";case'"':return"double-quoted-scalar";case"|":case">":return"block-scalar-header"}return null}function Zt(e){switch(e){case void 0:case" ":case`
|
|
115
|
-
`:case"\r":case" ":return!0;default:return!1}}const tc=new Set("0123456789ABCDEFabcdef"),Y0=new Set("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()"),Qr=new Set(",[]{}"),G0=new Set(` ,[]{}
|
|
116
|
-
\r `),ua=e=>!e||G0.has(e);class X0{constructor(){this.atEnd=!1,this.blockScalarIndent=-1,this.blockScalarKeep=!1,this.buffer="",this.flowKey=!1,this.flowLevel=0,this.indentNext=0,this.indentValue=0,this.lineEndPos=null,this.next=null,this.pos=0}*lex(t,n=!1){if(t){if(typeof t!="string")throw TypeError("source is not a string");this.buffer=this.buffer?this.buffer+t:t,this.lineEndPos=null}this.atEnd=!n;let s=this.next??"stream";for(;s&&(n||this.hasChars(1));)s=yield*this.parseNext(s)}atLineEnd(){let t=this.pos,n=this.buffer[t];for(;n===" "||n===" ";)n=this.buffer[++t];return!n||n==="#"||n===`
|
|
117
|
-
`?!0:n==="\r"?this.buffer[t+1]===`
|
|
118
|
-
`:!1}charAt(t){return this.buffer[this.pos+t]}continueScalar(t){let n=this.buffer[t];if(this.indentNext>0){let s=0;for(;n===" ";)n=this.buffer[++s+t];if(n==="\r"){const o=this.buffer[s+t+1];if(o===`
|
|
119
|
-
`||!o&&!this.atEnd)return t+s+1}return n===`
|
|
120
|
-
`||s>=this.indentNext||!n&&!this.atEnd?t+s:-1}if(n==="-"||n==="."){const s=this.buffer.substr(t,3);if((s==="---"||s==="...")&&Zt(this.buffer[t+3]))return-1}return t}getLine(){let t=this.lineEndPos;return(typeof t!="number"||t!==-1&&t<this.pos)&&(t=this.buffer.indexOf(`
|
|
121
|
-
`,this.pos),this.lineEndPos=t),t===-1?this.atEnd?this.buffer.substring(this.pos):null:(this.buffer[t-1]==="\r"&&(t-=1),this.buffer.substring(this.pos,t))}hasChars(t){return this.pos+t<=this.buffer.length}setNext(t){return this.buffer=this.buffer.substring(this.pos),this.pos=0,this.lineEndPos=null,this.next=t,null}peek(t){return this.buffer.substr(this.pos,t)}*parseNext(t){switch(t){case"stream":return yield*this.parseStream();case"line-start":return yield*this.parseLineStart();case"block-start":return yield*this.parseBlockStart();case"doc":return yield*this.parseDocument();case"flow":return yield*this.parseFlowCollection();case"quoted-scalar":return yield*this.parseQuotedScalar();case"block-scalar":return yield*this.parseBlockScalar();case"plain-scalar":return yield*this.parsePlainScalar()}}*parseStream(){let t=this.getLine();if(t===null)return this.setNext("stream");if(t[0]===qu&&(yield*this.pushCount(1),t=t.substring(1)),t[0]==="%"){let n=t.length,s=t.indexOf("#");for(;s!==-1;){const a=t[s-1];if(a===" "||a===" "){n=s-1;break}else s=t.indexOf("#",s+1)}for(;;){const a=t[n-1];if(a===" "||a===" ")n-=1;else break}const o=(yield*this.pushCount(n))+(yield*this.pushSpaces(!0));return yield*this.pushCount(t.length-o),this.pushNewline(),"stream"}if(this.atLineEnd()){const n=yield*this.pushSpaces(!0);return yield*this.pushCount(t.length-n),yield*this.pushNewline(),"stream"}return yield zu,yield*this.parseLineStart()}*parseLineStart(){const t=this.charAt(0);if(!t&&!this.atEnd)return this.setNext("line-start");if(t==="-"||t==="."){if(!this.atEnd&&!this.hasChars(4))return this.setNext("line-start");const n=this.peek(3);if((n==="---"||n==="...")&&Zt(this.charAt(3)))return yield*this.pushCount(3),this.indentValue=0,this.indentNext=0,n==="---"?"doc":"stream"}return this.indentValue=yield*this.pushSpaces(!1),this.indentNext>this.indentValue&&!Zt(this.charAt(1))&&(this.indentNext=this.indentValue),yield*this.parseBlockStart()}*parseBlockStart(){const[t,n]=this.peek(2);if(!n&&!this.atEnd)return this.setNext("block-start");if((t==="-"||t==="?"||t===":")&&Zt(n)){const s=(yield*this.pushCount(1))+(yield*this.pushSpaces(!0));return this.indentNext=this.indentValue+1,this.indentValue+=s,"block-start"}return"doc"}*parseDocument(){yield*this.pushSpaces(!0);const t=this.getLine();if(t===null)return this.setNext("doc");let n=yield*this.pushIndicators();switch(t[n]){case"#":yield*this.pushCount(t.length-n);case void 0:return yield*this.pushNewline(),yield*this.parseLineStart();case"{":case"[":return yield*this.pushCount(1),this.flowKey=!1,this.flowLevel=1,"flow";case"}":case"]":return yield*this.pushCount(1),"doc";case"*":return yield*this.pushUntil(ua),"doc";case'"':case"'":return yield*this.parseQuotedScalar();case"|":case">":return n+=yield*this.parseBlockScalarHeader(),n+=yield*this.pushSpaces(!0),yield*this.pushCount(t.length-n),yield*this.pushNewline(),yield*this.parseBlockScalar();default:return yield*this.parsePlainScalar()}}*parseFlowCollection(){let t,n,s=-1;do t=yield*this.pushNewline(),t>0?(n=yield*this.pushSpaces(!1),this.indentValue=s=n):n=0,n+=yield*this.pushSpaces(!0);while(t+n>0);const o=this.getLine();if(o===null)return this.setNext("flow");if((s!==-1&&s<this.indentNext&&o[0]!=="#"||s===0&&(o.startsWith("---")||o.startsWith("..."))&&Zt(o[3]))&&!(s===this.indentNext-1&&this.flowLevel===1&&(o[0]==="]"||o[0]==="}")))return this.flowLevel=0,yield Fu,yield*this.parseLineStart();let a=0;for(;o[a]===",";)a+=yield*this.pushCount(1),a+=yield*this.pushSpaces(!0),this.flowKey=!1;switch(a+=yield*this.pushIndicators(),o[a]){case void 0:return"flow";case"#":return yield*this.pushCount(o.length-a),"flow";case"{":case"[":return yield*this.pushCount(1),this.flowKey=!1,this.flowLevel+=1,"flow";case"}":case"]":return yield*this.pushCount(1),this.flowKey=!0,this.flowLevel-=1,this.flowLevel?"flow":"doc";case"*":return yield*this.pushUntil(ua),"flow";case'"':case"'":return this.flowKey=!0,yield*this.parseQuotedScalar();case":":{const i=this.charAt(1);if(this.flowKey||Zt(i)||i===",")return this.flowKey=!1,yield*this.pushCount(1),yield*this.pushSpaces(!0),"flow"}default:return this.flowKey=!1,yield*this.parsePlainScalar()}}*parseQuotedScalar(){const t=this.charAt(0);let n=this.buffer.indexOf(t,this.pos+1);if(t==="'")for(;n!==-1&&this.buffer[n+1]==="'";)n=this.buffer.indexOf("'",n+2);else for(;n!==-1;){let a=0;for(;this.buffer[n-1-a]==="\\";)a+=1;if(a%2===0)break;n=this.buffer.indexOf('"',n+1)}const s=this.buffer.substring(0,n);let o=s.indexOf(`
|
|
122
|
-
`,this.pos);if(o!==-1){for(;o!==-1;){const a=this.continueScalar(o+1);if(a===-1)break;o=s.indexOf(`
|
|
123
|
-
`,a)}o!==-1&&(n=o-(s[o-1]==="\r"?2:1))}if(n===-1){if(!this.atEnd)return this.setNext("quoted-scalar");n=this.buffer.length}return yield*this.pushToIndex(n+1,!1),this.flowLevel?"flow":"doc"}*parseBlockScalarHeader(){this.blockScalarIndent=-1,this.blockScalarKeep=!1;let t=this.pos;for(;;){const n=this.buffer[++t];if(n==="+")this.blockScalarKeep=!0;else if(n>"0"&&n<="9")this.blockScalarIndent=Number(n)-1;else if(n!=="-")break}return yield*this.pushUntil(n=>Zt(n)||n==="#")}*parseBlockScalar(){let t=this.pos-1,n=0,s;e:for(let a=this.pos;s=this.buffer[a];++a)switch(s){case" ":n+=1;break;case`
|
|
124
|
-
`:t=a,n=0;break;case"\r":{const i=this.buffer[a+1];if(!i&&!this.atEnd)return this.setNext("block-scalar");if(i===`
|
|
125
|
-
`)break}default:break e}if(!s&&!this.atEnd)return this.setNext("block-scalar");if(n>=this.indentNext){this.blockScalarIndent===-1?this.indentNext=n:this.indentNext=this.blockScalarIndent+(this.indentNext===0?1:this.indentNext);do{const a=this.continueScalar(t+1);if(a===-1)break;t=this.buffer.indexOf(`
|
|
126
|
-
`,a)}while(t!==-1);if(t===-1){if(!this.atEnd)return this.setNext("block-scalar");t=this.buffer.length}}let o=t+1;for(s=this.buffer[o];s===" ";)s=this.buffer[++o];if(s===" "){for(;s===" "||s===" "||s==="\r"||s===`
|
|
127
|
-
`;)s=this.buffer[++o];t=o-1}else if(!this.blockScalarKeep)do{let a=t-1,i=this.buffer[a];i==="\r"&&(i=this.buffer[--a]);const l=a;for(;i===" ";)i=this.buffer[--a];if(i===`
|
|
128
|
-
`&&a>=this.pos&&a+1+n>l)t=a;else break}while(!0);return yield Ia,yield*this.pushToIndex(t+1,!0),yield*this.parseLineStart()}*parsePlainScalar(){const t=this.flowLevel>0;let n=this.pos-1,s=this.pos-1,o;for(;o=this.buffer[++s];)if(o===":"){const a=this.buffer[s+1];if(Zt(a)||t&&Qr.has(a))break;n=s}else if(Zt(o)){let a=this.buffer[s+1];if(o==="\r"&&(a===`
|
|
129
|
-
`?(s+=1,o=`
|
|
130
|
-
`,a=this.buffer[s+1]):n=s),a==="#"||t&&Qr.has(a))break;if(o===`
|
|
131
|
-
`){const i=this.continueScalar(s+1);if(i===-1)break;s=Math.max(s,i-2)}}else{if(t&&Qr.has(o))break;n=s}return!o&&!this.atEnd?this.setNext("plain-scalar"):(yield Ia,yield*this.pushToIndex(n+1,!0),t?"flow":"doc")}*pushCount(t){return t>0?(yield this.buffer.substr(this.pos,t),this.pos+=t,t):0}*pushToIndex(t,n){const s=this.buffer.slice(this.pos,t);return s?(yield s,this.pos+=s.length,s.length):(n&&(yield""),0)}*pushIndicators(){let t=0;e:for(;;){switch(this.charAt(0)){case"!":t+=yield*this.pushTag(),t+=yield*this.pushSpaces(!0);continue e;case"&":t+=yield*this.pushUntil(ua),t+=yield*this.pushSpaces(!0);continue e;case"-":case"?":case":":{const n=this.flowLevel>0,s=this.charAt(1);if(Zt(s)||n&&Qr.has(s)){n?this.flowKey&&(this.flowKey=!1):this.indentNext=this.indentValue+1,t+=yield*this.pushCount(1),t+=yield*this.pushSpaces(!0);continue e}}}break e}return t}*pushTag(){if(this.charAt(1)==="<"){let t=this.pos+2,n=this.buffer[t];for(;!Zt(n)&&n!==">";)n=this.buffer[++t];return yield*this.pushToIndex(n===">"?t+1:t,!1)}else{let t=this.pos+1,n=this.buffer[t];for(;n;)if(Y0.has(n))n=this.buffer[++t];else if(n==="%"&&tc.has(this.buffer[t+1])&&tc.has(this.buffer[t+2]))n=this.buffer[t+=3];else break;return yield*this.pushToIndex(t,!1)}}*pushNewline(){const t=this.buffer[this.pos];return t===`
|
|
132
|
-
`?yield*this.pushCount(1):t==="\r"&&this.charAt(1)===`
|
|
133
|
-
`?yield*this.pushCount(2):0}*pushSpaces(t){let n=this.pos-1,s;do s=this.buffer[++n];while(s===" "||t&&s===" ");const o=n-this.pos;return o>0&&(yield this.buffer.substr(this.pos,o),this.pos=n),o}*pushUntil(t){let n=this.pos,s=this.buffer[n];for(;!t(s);)s=this.buffer[++n];return yield*this.pushToIndex(n,!1)}}class Z0{constructor(){this.lineStarts=[],this.addNewLine=t=>this.lineStarts.push(t),this.linePos=t=>{let n=0,s=this.lineStarts.length;for(;n<s;){const a=n+s>>1;this.lineStarts[a]<t?n=a+1:s=a}if(this.lineStarts[n]===t)return{line:n+1,col:1};if(n===0)return{line:0,col:t};const o=this.lineStarts[n-1];return{line:n,col:t-o+1}}}}function En(e,t){for(let n=0;n<e.length;++n)if(e[n].type===t)return!0;return!1}function nc(e){for(let t=0;t<e.length;++t)switch(e[t].type){case"space":case"comment":case"newline":break;default:return t}return-1}function Hu(e){switch(e?.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":case"flow-collection":return!0;default:return!1}}function Jr(e){switch(e.type){case"document":return e.start;case"block-map":{const t=e.items[e.items.length-1];return t.sep??t.start}case"block-seq":return e.items[e.items.length-1].start;default:return[]}}function bs(e){if(e.length===0)return[];let t=e.length;e:for(;--t>=0;)switch(e[t].type){case"doc-start":case"explicit-key-ind":case"map-value-ind":case"seq-item-ind":case"newline":break e}for(;e[++t]?.type==="space";);return e.splice(t,e.length)}function bo(e,t){if(t.length<1e5)Array.prototype.push.apply(e,t);else for(let n=0;n<t.length;++n)e.push(t[n])}function sc(e){if(e.start.type==="flow-seq-start")for(const t of e.items)t.sep&&!t.value&&!En(t.start,"explicit-key-ind")&&!En(t.sep,"map-value-ind")&&(t.key&&(t.value=t.key),delete t.key,Hu(t.value)?t.value.end?bo(t.value.end,t.sep):t.value.end=t.sep:bo(t.start,t.sep),delete t.sep)}class Q0{constructor(t){this.atNewLine=!0,this.atScalar=!1,this.indent=0,this.offset=0,this.onKeyLine=!1,this.stack=[],this.source="",this.type="",this.lexer=new X0,this.onNewLine=t}*parse(t,n=!1){this.onNewLine&&this.offset===0&&this.onNewLine(0);for(const s of this.lexer.lex(t,n))yield*this.next(s);n||(yield*this.end())}*next(t){if(this.source=t,this.atScalar){this.atScalar=!1,yield*this.step(),this.offset+=t.length;return}const n=U0(t);if(n)if(n==="scalar")this.atNewLine=!1,this.atScalar=!0,this.type="scalar";else{switch(this.type=n,yield*this.step(),n){case"newline":this.atNewLine=!0,this.indent=0,this.onNewLine&&this.onNewLine(this.offset+t.length);break;case"space":this.atNewLine&&t[0]===" "&&(this.indent+=t.length);break;case"explicit-key-ind":case"map-value-ind":case"seq-item-ind":this.atNewLine&&(this.indent+=t.length);break;case"doc-mode":case"flow-error-end":return;default:this.atNewLine=!1}this.offset+=t.length}else{const s=`Not a YAML token: ${t}`;yield*this.pop({type:"error",offset:this.offset,message:s,source:t}),this.offset+=t.length}}*end(){for(;this.stack.length>0;)yield*this.pop()}get sourceToken(){return{type:this.type,offset:this.offset,indent:this.indent,source:this.source}}*step(){const t=this.peek(1);if(this.type==="doc-end"&&t?.type!=="doc-end"){for(;this.stack.length>0;)yield*this.pop();this.stack.push({type:"doc-end",offset:this.offset,source:this.source});return}if(!t)return yield*this.stream();switch(t.type){case"document":return yield*this.document(t);case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return yield*this.scalar(t);case"block-scalar":return yield*this.blockScalar(t);case"block-map":return yield*this.blockMap(t);case"block-seq":return yield*this.blockSequence(t);case"flow-collection":return yield*this.flowCollection(t);case"doc-end":return yield*this.documentEnd(t)}yield*this.pop()}peek(t){return this.stack[this.stack.length-t]}*pop(t){const n=t??this.stack.pop();if(!n)yield{type:"error",offset:this.offset,source:"",message:"Tried to pop an empty stack"};else if(this.stack.length===0)yield n;else{const s=this.peek(1);switch(n.type==="block-scalar"?n.indent="indent"in s?s.indent:0:n.type==="flow-collection"&&s.type==="document"&&(n.indent=0),n.type==="flow-collection"&&sc(n),s.type){case"document":s.value=n;break;case"block-scalar":s.props.push(n);break;case"block-map":{const o=s.items[s.items.length-1];if(o.value){s.items.push({start:[],key:n,sep:[]}),this.onKeyLine=!0;return}else if(o.sep)o.value=n;else{Object.assign(o,{key:n,sep:[]}),this.onKeyLine=!o.explicitKey;return}break}case"block-seq":{const o=s.items[s.items.length-1];o.value?s.items.push({start:[],value:n}):o.value=n;break}case"flow-collection":{const o=s.items[s.items.length-1];!o||o.value?s.items.push({start:[],key:n,sep:[]}):o.sep?o.value=n:Object.assign(o,{key:n,sep:[]});return}default:yield*this.pop(),yield*this.pop(n)}if((s.type==="document"||s.type==="block-map"||s.type==="block-seq")&&(n.type==="block-map"||n.type==="block-seq")){const o=n.items[n.items.length-1];o&&!o.sep&&!o.value&&o.start.length>0&&nc(o.start)===-1&&(n.indent===0||o.start.every(a=>a.type!=="comment"||a.indent<n.indent))&&(s.type==="document"?s.end=o.start:s.items.push({start:o.start}),n.items.splice(-1,1))}}}*stream(){switch(this.type){case"directive-line":yield{type:"directive",offset:this.offset,source:this.source};return;case"byte-order-mark":case"space":case"comment":case"newline":yield this.sourceToken;return;case"doc-mode":case"doc-start":{const t={type:"document",offset:this.offset,start:[]};this.type==="doc-start"&&t.start.push(this.sourceToken),this.stack.push(t);return}}yield{type:"error",offset:this.offset,message:`Unexpected ${this.type} token in YAML stream`,source:this.source}}*document(t){if(t.value)return yield*this.lineEnd(t);switch(this.type){case"doc-start":{nc(t.start)!==-1?(yield*this.pop(),yield*this.step()):t.start.push(this.sourceToken);return}case"anchor":case"tag":case"space":case"comment":case"newline":t.start.push(this.sourceToken);return}const n=this.startBlockValue(t);n?this.stack.push(n):yield{type:"error",offset:this.offset,message:`Unexpected ${this.type} token in YAML document`,source:this.source}}*scalar(t){if(this.type==="map-value-ind"){const n=Jr(this.peek(2)),s=bs(n);let o;t.end?(o=t.end,o.push(this.sourceToken),delete t.end):o=[this.sourceToken];const a={type:"block-map",offset:t.offset,indent:t.indent,items:[{start:s,key:t,sep:o}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=a}else yield*this.lineEnd(t)}*blockScalar(t){switch(this.type){case"space":case"comment":case"newline":t.props.push(this.sourceToken);return;case"scalar":if(t.source=this.source,this.atNewLine=!0,this.indent=0,this.onNewLine){let n=this.source.indexOf(`
|
|
134
|
-
`)+1;for(;n!==0;)this.onNewLine(this.offset+n),n=this.source.indexOf(`
|
|
135
|
-
`,n)+1}yield*this.pop();break;default:yield*this.pop(),yield*this.step()}}*blockMap(t){const n=t.items[t.items.length-1];switch(this.type){case"newline":if(this.onKeyLine=!1,n.value){const s="end"in n.value?n.value.end:void 0;(Array.isArray(s)?s[s.length-1]:void 0)?.type==="comment"?s?.push(this.sourceToken):t.items.push({start:[this.sourceToken]})}else n.sep?n.sep.push(this.sourceToken):n.start.push(this.sourceToken);return;case"space":case"comment":if(n.value)t.items.push({start:[this.sourceToken]});else if(n.sep)n.sep.push(this.sourceToken);else{if(this.atIndentedComment(n.start,t.indent)){const o=t.items[t.items.length-2]?.value?.end;if(Array.isArray(o)){bo(o,n.start),o.push(this.sourceToken),t.items.pop();return}}n.start.push(this.sourceToken)}return}if(this.indent>=t.indent){const s=!this.onKeyLine&&this.indent===t.indent,o=s&&(n.sep||n.explicitKey)&&this.type!=="seq-item-ind";let a=[];if(o&&n.sep&&!n.value){const i=[];for(let l=0;l<n.sep.length;++l){const c=n.sep[l];switch(c.type){case"newline":i.push(l);break;case"space":break;case"comment":c.indent>t.indent&&(i.length=0);break;default:i.length=0}}i.length>=2&&(a=n.sep.splice(i[1]))}switch(this.type){case"anchor":case"tag":o||n.value?(a.push(this.sourceToken),t.items.push({start:a}),this.onKeyLine=!0):n.sep?n.sep.push(this.sourceToken):n.start.push(this.sourceToken);return;case"explicit-key-ind":!n.sep&&!n.explicitKey?(n.start.push(this.sourceToken),n.explicitKey=!0):o||n.value?(a.push(this.sourceToken),t.items.push({start:a,explicitKey:!0})):this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken],explicitKey:!0}]}),this.onKeyLine=!0;return;case"map-value-ind":if(n.explicitKey)if(n.sep)if(n.value)t.items.push({start:[],key:null,sep:[this.sourceToken]});else if(En(n.sep,"map-value-ind"))this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:a,key:null,sep:[this.sourceToken]}]});else if(Hu(n.key)&&!En(n.sep,"newline")){const i=bs(n.start),l=n.key,c=n.sep;c.push(this.sourceToken),delete n.key,delete n.sep,this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:i,key:l,sep:c}]})}else a.length>0?n.sep=n.sep.concat(a,this.sourceToken):n.sep.push(this.sourceToken);else if(En(n.start,"newline"))Object.assign(n,{key:null,sep:[this.sourceToken]});else{const i=bs(n.start);this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:i,key:null,sep:[this.sourceToken]}]})}else n.sep?n.value||o?t.items.push({start:a,key:null,sep:[this.sourceToken]}):En(n.sep,"map-value-ind")?this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[],key:null,sep:[this.sourceToken]}]}):n.sep.push(this.sourceToken):Object.assign(n,{key:null,sep:[this.sourceToken]});this.onKeyLine=!0;return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{const i=this.flowScalar(this.type);o||n.value?(t.items.push({start:a,key:i,sep:[]}),this.onKeyLine=!0):n.sep?this.stack.push(i):(Object.assign(n,{key:i,sep:[]}),this.onKeyLine=!0);return}default:{const i=this.startBlockValue(t);if(i){if(i.type==="block-seq"){if(!n.explicitKey&&n.sep&&!En(n.sep,"newline")){yield*this.pop({type:"error",offset:this.offset,message:"Unexpected block-seq-ind on same line with key",source:this.source});return}}else s&&t.items.push({start:a});this.stack.push(i);return}}}}yield*this.pop(),yield*this.step()}*blockSequence(t){const n=t.items[t.items.length-1];switch(this.type){case"newline":if(n.value){const s="end"in n.value?n.value.end:void 0;(Array.isArray(s)?s[s.length-1]:void 0)?.type==="comment"?s?.push(this.sourceToken):t.items.push({start:[this.sourceToken]})}else n.start.push(this.sourceToken);return;case"space":case"comment":if(n.value)t.items.push({start:[this.sourceToken]});else{if(this.atIndentedComment(n.start,t.indent)){const o=t.items[t.items.length-2]?.value?.end;if(Array.isArray(o)){bo(o,n.start),o.push(this.sourceToken),t.items.pop();return}}n.start.push(this.sourceToken)}return;case"anchor":case"tag":if(n.value||this.indent<=t.indent)break;n.start.push(this.sourceToken);return;case"seq-item-ind":if(this.indent!==t.indent)break;n.value||En(n.start,"seq-item-ind")?t.items.push({start:[this.sourceToken]}):n.start.push(this.sourceToken);return}if(this.indent>t.indent){const s=this.startBlockValue(t);if(s){this.stack.push(s);return}}yield*this.pop(),yield*this.step()}*flowCollection(t){const n=t.items[t.items.length-1];if(this.type==="flow-error-end"){let s;do yield*this.pop(),s=this.peek(1);while(s?.type==="flow-collection")}else if(t.end.length===0){switch(this.type){case"comma":case"explicit-key-ind":!n||n.sep?t.items.push({start:[this.sourceToken]}):n.start.push(this.sourceToken);return;case"map-value-ind":!n||n.value?t.items.push({start:[],key:null,sep:[this.sourceToken]}):n.sep?n.sep.push(this.sourceToken):Object.assign(n,{key:null,sep:[this.sourceToken]});return;case"space":case"comment":case"newline":case"anchor":case"tag":!n||n.value?t.items.push({start:[this.sourceToken]}):n.sep?n.sep.push(this.sourceToken):n.start.push(this.sourceToken);return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{const o=this.flowScalar(this.type);!n||n.value?t.items.push({start:[],key:o,sep:[]}):n.sep?this.stack.push(o):Object.assign(n,{key:o,sep:[]});return}case"flow-map-end":case"flow-seq-end":t.end.push(this.sourceToken);return}const s=this.startBlockValue(t);s?this.stack.push(s):(yield*this.pop(),yield*this.step())}else{const s=this.peek(2);if(s.type==="block-map"&&(this.type==="map-value-ind"&&s.indent===t.indent||this.type==="newline"&&!s.items[s.items.length-1].sep))yield*this.pop(),yield*this.step();else if(this.type==="map-value-ind"&&s.type!=="flow-collection"){const o=Jr(s),a=bs(o);sc(t);const i=t.end.splice(1,t.end.length);i.push(this.sourceToken);const l={type:"block-map",offset:t.offset,indent:t.indent,items:[{start:a,key:t,sep:i}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=l}else yield*this.lineEnd(t)}}flowScalar(t){if(this.onNewLine){let n=this.source.indexOf(`
|
|
136
|
-
`)+1;for(;n!==0;)this.onNewLine(this.offset+n),n=this.source.indexOf(`
|
|
137
|
-
`,n)+1}return{type:t,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(t){switch(this.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return this.flowScalar(this.type);case"block-scalar-header":return{type:"block-scalar",offset:this.offset,indent:this.indent,props:[this.sourceToken],source:""};case"flow-map-start":case"flow-seq-start":return{type:"flow-collection",offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case"seq-item-ind":return{type:"block-seq",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case"explicit-key-ind":{this.onKeyLine=!0;const n=Jr(t),s=bs(n);return s.push(this.sourceToken),{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:s,explicitKey:!0}]}}case"map-value-ind":{this.onKeyLine=!0;const n=Jr(t),s=bs(n);return{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:s,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(t,n){return this.type!=="comment"||this.indent<=n?!1:t.every(s=>s.type==="newline"||s.type==="space")}*documentEnd(t){this.type!=="doc-mode"&&(t.end?t.end.push(this.sourceToken):t.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop()))}*lineEnd(t){switch(this.type){case"comma":case"doc-start":case"doc-end":case"flow-seq-end":case"flow-map-end":case"map-value-ind":yield*this.pop(),yield*this.step();break;case"newline":this.onKeyLine=!1;default:t.end?t.end.push(this.sourceToken):t.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop())}}}function J0(e){const t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new Z0||null,prettyErrors:t}}function eb(e,t={}){const{lineCounter:n,prettyErrors:s}=J0(t),o=new Q0(n?.addNewLine),a=new K0(t);let i=null;for(const l of a.compose(o.parse(e),!0,e.length))if(!i)i=l;else if(i.options.logLevel!=="silent"){i.errors.push(new nr(l.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}return s&&n&&(i.errors.forEach(Ql(e,n)),i.warnings.forEach(Ql(e,n))),i}function rc(e,t,n){let s;typeof t=="function"?s=t:n===void 0&&t&&typeof t=="object"&&(n=t);const o=eb(e,n);if(!o)return null;if(o.warnings.forEach(a=>pu(o.options.logLevel,a)),o.errors.length>0){if(o.options.logLevel!=="silent")throw o.errors[0];o.errors=[]}return o.toJS(Object.assign({reviver:s},n))}function oc(e,t,n){let s=null;if(typeof t=="function"||Array.isArray(t)?s=t:n===void 0&&t&&(n=t),typeof n=="string"&&(n=n.length),typeof n=="number"){const o=Math.round(n);n=o<1?void 0:o>8?{indent:8}:{indent:o}}if(e===void 0){const{keepUndefined:o}=n??t??{};if(!o)return}return kr(e)&&!s?e.toString(n):new Sr(e,s,n).toString(n)}function tb({expanded:e,onToggle:t,summary:n,actions:s,children:o,className:a="",summaryClassName:i="",panelClassName:l="",testId:c,disabled:d=!1,panelLabel:h}){const u=p.useId(),f=`${u}-toggle`,m=`${u}-panel`,[g,b]=p.useState(e);p.useEffect(()=>{e&&b(!0)},[e]);const v=p.useCallback(()=>{d||t()},[d,t]);return r.jsxs("div",{className:a,children:[r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsxs("button",{type:"button",id:f,"aria-expanded":e,"aria-controls":m,"aria-disabled":d||void 0,onClick:v,"data-testid":c?`${c}-toggle`:void 0,className:`group flex min-h-[44px] flex-1 min-w-0 items-start gap-2 rounded-lg px-1 py-2 text-left transition-colors sm:min-h-[36px] hover:bg-surface-elevated/40 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60 ${d?"cursor-default opacity-70":"cursor-pointer"} ${i}`,children:[r.jsx("svg",{"aria-hidden":"true",className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-fg-tertiary transition-transform duration-200 ${e?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),r.jsx("span",{className:"min-w-0 flex-1",children:n})]}),s?r.jsx("div",{className:"flex shrink-0 items-center gap-1.5 pt-1",children:s}):null]}),r.jsx("div",{className:`grid transition-[grid-template-rows] duration-200 ease-out ${e?"grid-rows-[1fr]":"grid-rows-[0fr]"}`,children:r.jsx("div",{className:"overflow-hidden",inert:!e||void 0,"aria-hidden":!e||void 0,children:r.jsx("div",{id:m,role:"region","aria-labelledby":f,"aria-label":h,"data-testid":c?`${c}-panel`:void 0,className:l,children:g?o:null})})})]})}function nb({step:e,index:t,total:n,dependsOnNames:s,roleOptions:o,onClose:a,onSave:i}){const{t:l}=Ve(["work","common"]),[c,d]=p.useState(null),[h,u]=p.useState(e.name),[f,m]=p.useState(e.prompt),[g,b]=p.useState(!1),[v,k]=p.useState(null),y=p.useRef(null);p.useEffect(()=>{u(e.name)},[e.name]),p.useEffect(()=>{m(e.prompt)},[e.prompt]),p.useEffect(()=>{const j=E=>{if(E.key==="Escape"){if(c){E.stopPropagation(),d(null),u(e.name),m(e.prompt);return}a()}};return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[c,a,e.name,e.prompt]);const x=async j=>{b(!0),k(null);try{await i(j)}catch(E){k(E instanceof Error?E.message:String(E))}finally{b(!1)}},w=async()=>{d(null);const j=h.trim();if(!j||j===e.name){u(e.name);return}await x({name:j})},S=async()=>{d(null),f!==e.prompt&&await x({prompt:f})};return r.jsxs("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[r.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:a,"aria-hidden":"true"}),r.jsxs("div",{ref:y,role:"dialog","aria-modal":"true","aria-labelledby":"workflow-step-title",className:"relative flex max-h-[88vh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-border-default bg-surface-secondary shadow-2xl","data-testid":"workflow-step-modal",children:[r.jsxs("header",{className:"flex items-start justify-between gap-3 border-b border-border-default/50 px-5 py-3",children:[r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"text-[10px] font-medium uppercase tracking-wider text-fg-muted",children:l("work:task.workflowStepOf","步骤 {{index}} / {{total}}",{index:t+1,total:n})}),c==="name"?r.jsx("input",{autoFocus:!0,value:h,onChange:j=>u(j.target.value),onBlur:()=>{w()},onKeyDown:j=>{j.key==="Enter"&&w()},"aria-label":l("work:task.workflowStepName","步骤名称"),className:"input-field mt-0.5 w-full text-sm"}):r.jsx("h2",{id:"workflow-step-title",onClick:()=>d("name"),title:l("work:task.workflowClickToEdit","点击编辑"),className:"mt-0.5 cursor-text truncate rounded px-1 -mx-1 text-sm font-semibold text-fg-primary hover:bg-surface-elevated/60","data-testid":"workflow-step-name",children:e.name}),r.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-[11px] text-fg-tertiary",children:[r.jsx("select",{value:e.role,onChange:j=>{x({role:j.target.value})},"aria-label":l("work:task.workflowStepRole","角色"),"data-testid":"workflow-step-role",className:"rounded border border-border-default/60 bg-surface px-1.5 py-0.5 text-[11px] text-fg-secondary focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60",children:[...new Set([e.role,...o])].filter(Boolean).map(j=>r.jsx("option",{value:j,children:j},j))}),s.length>0?r.jsx("span",{children:l("work:task.workflowDependsOn","依赖 {{steps}}",{steps:s.join("、")})}):null,g?r.jsx("span",{className:"text-fg-muted",children:l("work:task.workflowSaving","保存中…")}):null]})]}),r.jsx("button",{type:"button",onClick:a,"aria-label":l("common:close","关闭"),className:"rounded-lg p-1.5 text-fg-tertiary transition-colors hover:bg-surface-elevated hover:text-fg-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60",children:r.jsx("svg",{className:"h-4 w-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:r.jsx("path",{strokeLinecap:"round",d:"M6 6l12 12M18 6L6 18"})})})]}),r.jsxs("div",{className:"flex-1 space-y-2 overflow-y-auto px-5 py-3",children:[r.jsx("p",{className:"text-[10px] font-medium uppercase tracking-wider text-fg-muted",children:l("work:task.workflowStepPrompt","提示词")}),c==="prompt"?r.jsx("textarea",{autoFocus:!0,value:f,onChange:j=>m(j.target.value),onBlur:()=>{S()},"aria-label":l("work:task.workflowStepPrompt","提示词"),spellCheck:!1,rows:14,className:"input-field w-full resize-y font-mono text-[11px] leading-relaxed"}):r.jsx("pre",{onClick:()=>d("prompt"),title:l("work:task.workflowClickToEdit","点击编辑"),"data-testid":"workflow-step-prompt",className:"max-h-[45vh] cursor-text overflow-auto whitespace-pre-wrap break-words rounded-lg bg-surface px-3 py-2.5 font-mono text-[11px] leading-relaxed text-fg-secondary hover:bg-surface-elevated/40",children:e.prompt||"—"}),r.jsx("p",{className:"text-[10px] text-fg-muted",children:l("work:task.workflowStepPromptHint","失焦即保存,Esc 放弃本次编辑;保存时服务端会重新校验模板。")}),v?r.jsx("p",{className:"text-[11px] text-red-500",children:v}):null]})]})]})}const sb={running:{tone:"info",key:"runStatusRunning",label:"运行中"},paused:{tone:"warning",key:"runStatusPaused",label:"已暂停"},completed:{tone:"success",key:"runStatusCompleted",label:"已完成"},failed:{tone:"danger",key:"runStatusFailed",label:"失败"},cancelled:{tone:"neutral",key:"runStatusCancelled",label:"已取消"}},ac={tone:"neutral",key:"runStatusUnknown",label:"未知"};function Vu(e){return e?sb[e]??{...ac,label:e}:ac}const Tn={info:{chip:"bg-blue-500/15 text-blue-600 dark:text-blue-400",dot:"bg-blue-500",bar:"bg-blue-500",text:"text-blue-600 dark:text-blue-400"},warning:{chip:"bg-amber-500/15 text-amber-600 dark:text-amber-400",dot:"bg-amber-500",bar:"bg-amber-500",text:"text-amber-600 dark:text-amber-400"},success:{chip:"bg-green-500/15 text-green-600 dark:text-green-400",dot:"bg-green-500",bar:"bg-green-500",text:"text-green-600 dark:text-green-400"},danger:{chip:"bg-red-500/15 text-red-600 dark:text-red-400",dot:"bg-red-500",bar:"bg-red-500",text:"text-red-600 dark:text-red-400"},neutral:{chip:"bg-surface-elevated text-fg-tertiary",dot:"bg-fg-muted",bar:"bg-fg-muted",text:"text-fg-tertiary"}},Wu=new Set(["completed","archived"]),Ku=new Set(["failed","rejected"]),Uu=new Set(["in_progress","review"]);function li(e){return e==="running"||e==="paused"}function ci(e){const t=new Map;for(const n of e)t.set(n.id,n);return t}function rb(e,t){return t.get(e)?.name??e}function di(e,t){return(e.depends_on??[]).map(n=>rb(n,t))}function ob(e){const t=new Set(e.map(i=>i.id)),n={},s=[];for(const i of e)for(const l of i.depends_on??[])t.has(l)&&s.push({from:l,to:i.id});for(const i of e)n[i.id]=0;for(let i=0;i<e.length;i++){let l=!1;for(const c of e)for(const d of c.depends_on??[]){if(!t.has(d))continue;const h=(n[d]??0)+1;h>(n[c.id]??0)&&(n[c.id]=h,l=!0)}if(!l)break}const o=e.reduce((i,l)=>Math.max(i,n[l.id]??0),0),a=Array.from({length:o+1},()=>[]);for(const i of e)a[n[i.id]??0].push(i.id);return{layers:a,depth:n,edges:s}}function Yu(e,t){const n={},s=new Set;for(const o of t)o.workflowStepId&&(n[o.workflowStepId]||(n[o.workflowStepId]=o,s.add(o.id)));for(const o of e)o.id in n||(n[o.id]=void 0);return n}function Gu(e,t){let n=0,s=0,o=0,a=0;const i=[],l=[];for(const c of e){const d=t[c.id];d&&(n++,Wu.has(d.status)?s++:Ku.has(d.status)?(o++,i.push(c)):Uu.has(d.status)&&(a++,l.push(c)))}return{total:n,done:s,failed:o,active:a,percent:n>0?Math.round(s/n*100):0,failedSteps:i,activeSteps:l}}function eo(e){return e?Wu.has(e.status)?"done":Ku.has(e.status)?"failed":Uu.has(e.status)?"active":"pending":"unknown"}const Xu="markus_workflows_expanded";function ab(e){try{const t=e(Xu);if(!t)return new Set;const n=JSON.parse(t);return Array.isArray(n)?new Set(n.filter(s=>typeof s=="string")):new Set}catch{return new Set}}function ib(e,t){try{t(Xu,JSON.stringify([...e]))}catch{}}function lb(e,t,n,s){const o=n(e);if(!o||typeof o!="object")throw new Error("模板 YAML 无法解析");o.name=t;const a=o.displayName;return typeof a=="string"&&a.length>0&&(o.displayName=`${a}(副本)`),s(o)}function ic({status:e,className:t=""}){const{t:n}=Ve(["work"]),s=Vu(e),o=Tn[s.tone];return r.jsxs("span",{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${o.chip} ${t}`,"data-status":e,children:[r.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${o.dot}`,"aria-hidden":"true"}),n(`work:task.${s.key}`,s.label)]})}function cb({items:e}){const{t}=Ve(["work"]),[n,s]=p.useState(!1),o=p.useRef(null);return p.useEffect(()=>{if(!n)return;const a=l=>{o.current?.contains(l.target)||s(!1)},i=l=>{l.key==="Escape"&&s(!1)};return document.addEventListener("mousedown",a),document.addEventListener("keydown",i),()=>{document.removeEventListener("mousedown",a),document.removeEventListener("keydown",i)}},[n]),r.jsxs("div",{className:"relative",ref:o,children:[r.jsx("button",{type:"button","aria-haspopup":"menu","aria-expanded":n,"aria-label":t("work:task.workflowMoreActions","更多操作"),title:t("work:task.workflowMoreActions","更多操作"),onClick:()=>s(a=>!a),className:"flex h-8 w-8 items-center justify-center rounded-lg text-fg-tertiary transition-colors hover:bg-surface-elevated hover:text-fg-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60",children:r.jsx(db,{})}),n?r.jsx("div",{role:"menu",className:"absolute right-0 z-20 mt-1 w-44 overflow-hidden rounded-xl border border-border-default bg-surface-secondary py-1 shadow-xl",children:e.map(a=>r.jsx("button",{role:"menuitem",type:"button",onClick:()=>{s(!1),a.onSelect()},className:`flex w-full items-center px-3 py-2 text-left text-xs transition-colors hover:bg-surface-elevated focus:bg-surface-elevated focus:outline-none ${a.danger?"text-red-500":"text-fg-secondary"}`,children:a.label},a.key))}):null]})}function db({className:e="h-4 w-4"}){return r.jsxs("svg",{className:e,viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[r.jsx("circle",{cx:"5",cy:"12",r:"1.8"}),r.jsx("circle",{cx:"12",cy:"12",r:"1.8"}),r.jsx("circle",{cx:"19",cy:"12",r:"1.8"})]})}function ub(){return r.jsxs("div",{className:"space-y-2 pt-3","data-testid":"workflow-detail-skeleton","aria-busy":"true",children:[r.jsx("div",{className:"h-2.5 w-2/3 animate-pulse rounded bg-surface-elevated"}),r.jsx("div",{className:"h-2.5 w-full animate-pulse rounded bg-surface-elevated"}),r.jsx("div",{className:"h-2.5 w-5/6 animate-pulse rounded bg-surface-elevated"})]})}function fb({steps:e,roleAgentName:t,onOpenStep:n}){const{t:s}=Ve(["work"]),o=ci(e),{layers:a}=ob(e),i=new Map(e.map((c,d)=>[c.id,d]));let l=0;return r.jsxs("ol",{className:"space-y-1","data-testid":"workflow-step-flow",children:[a.map((c,d)=>{const h=c.length>1;return r.jsxs("li",{children:[h?r.jsx("p",{className:"mb-1 pl-5 text-[10px] font-medium uppercase tracking-wider text-fg-muted",children:s("work:task.workflowParallel","并行 {{count}} 步",{count:c.length})}):null,r.jsx("div",{className:h?"ml-1 space-y-0.5 border-l border-brand-500/30 pl-2":"space-y-0.5",children:c.map(u=>{const f=o.get(u);if(!f)return null;const m=di(f,o),g=t?.(f.role),b=(i.get(u)??0)+1;return l+=1,r.jsx("li",{children:r.jsxs("button",{type:"button",onClick:()=>n(f,i.get(u)??0),"data-testid":`workflow-step-${u}`,className:"group flex w-full items-center gap-2 rounded-lg px-1.5 py-1.5 text-left transition-colors hover:bg-surface-elevated/60 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60",children:[r.jsx("span",{className:"w-4 shrink-0 text-right text-[10px] tabular-nums text-fg-muted",children:b}),r.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-primary",children:f.name}),m.length>1?r.jsxs("span",{className:"shrink-0 rounded bg-surface-elevated px-1 py-0.5 text-[9px] text-fg-muted",title:m.join("、"),children:["↑",m.length]}):null,r.jsx("span",{className:"hidden shrink-0 text-[10px] text-fg-muted sm:inline",title:f.role,children:g??f.role}),r.jsx("svg",{className:"h-3 w-3 shrink-0 text-fg-muted opacity-0 transition-opacity group-hover:opacity-100",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})})]})},u)})})]},d)}),l===0?r.jsx("li",{className:"text-[11px] text-fg-muted",children:s("work:task.workflowNoSteps","该模板没有步骤")}):null]})}function hb({workflow:e,detail:t,detailState:n,onRetryDetail:s,expanded:o,onToggle:a,runs:i,runTasks:l,onRun:c,onOpenRun:d,onSaveStep:h,roleAgentName:u,onSendToAgent:f,onEdit:m,onDuplicate:g,onDelete:b}){const{t:v}=Ve(["work","common"]),[k,y]=p.useState(null),x=i[0],w=i.some(C=>li(C.status)),S=t?.steps??[],j=r.jsxs("span",{className:"block",children:[r.jsxs("span",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[r.jsx("span",{className:"truncate text-sm font-semibold text-fg-primary",children:e.displayName||e.name}),r.jsx("span",{className:"text-[11px] text-fg-tertiary",children:v("work:task.workflowStepsCount","{{count}} 步骤",{count:e.stepCount})}),e.hasSchedule?r.jsx("span",{className:"rounded bg-purple-500/15 px-1.5 py-0.5 text-[10px] font-medium text-purple-500",children:v("work:task.workflowScheduled","定时")}):null,r.jsxs("span",{className:"text-[10px] text-fg-muted",children:["v",e.version]}),x?r.jsx(ic,{status:x.status}):null]}),e.description?r.jsx("span",{className:"mt-0.5 line-clamp-1 block text-[11px] text-fg-tertiary",children:e.description}):null]}),E=r.jsxs(r.Fragment,{children:[w?r.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-lg bg-blue-500/15 px-2.5 py-1 text-xs font-medium text-blue-600 dark:text-blue-400",children:[r.jsx("span",{className:"h-1.5 w-1.5 animate-pulse rounded-full bg-blue-500","aria-hidden":"true"}),v("work:task.workflowRunning","运行中")]}):r.jsx("button",{type:"button",onClick:c,className:"rounded-lg bg-brand-600 px-3 py-1.5 text-xs font-medium text-on-brand transition-colors hover:bg-brand-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60",children:v("work:task.workflowRun","运行")}),r.jsx(cb,{items:[{key:"edit",label:v("work:task.workflowEditYaml","编辑 YAML"),onSelect:m},{key:"duplicate",label:v("work:task.workflowDuplicate","复制为新工作流"),onSelect:g},{key:"send",label:v("work:task.workflowSendToAgent","发送到智能体对话"),onSelect:f},{key:"delete",label:v("work:task.workflowDelete","删除工作流"),onSelect:b,danger:!0}]})]});return r.jsxs("div",{className:"min-w-0 rounded-xl border border-border-default/50 bg-surface-secondary p-4","data-testid":`workflow-card-${e.name}`,children:[r.jsx(tb,{expanded:o,onToggle:a,summary:j,actions:E,testId:`workflow-${e.name}`,panelLabel:e.displayName||e.name,panelClassName:"pt-3",children:n==="error"?r.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg bg-red-500/5 px-3 py-2",children:[r.jsx("span",{className:"text-xs text-red-500",children:v("work:task.workflowDetailFailed","详情加载失败")}),r.jsx("button",{type:"button",onClick:s,className:"rounded-lg bg-surface-elevated px-2.5 py-1 text-[11px] font-medium text-fg-secondary transition-colors hover:text-fg-primary",children:v("work:task.workflowRetry","重试")})]}):t?r.jsxs("div",{className:"space-y-4",children:[S.length>0?r.jsx(fb,{steps:S,roleAgentName:u,onOpenStep:(C,R)=>y({step:C,index:R})}):null,t.params&&t.params.length>0?r.jsxs("div",{children:[r.jsx("p",{className:"mb-1.5 text-[10px] font-medium uppercase tracking-wider text-fg-tertiary",children:v("work:task.workflowParamsCount","参数 ({{count}})",{count:t.params.length})}),r.jsx("div",{className:"flex flex-wrap gap-2",children:t.params.map(C=>r.jsxs("span",{className:"inline-flex items-center gap-1 rounded border border-border-default/40 bg-surface-elevated px-2 py-0.5 text-[10px]",children:[r.jsx("span",{className:"font-medium text-fg-secondary",children:C.label||C.name}),r.jsx("span",{className:"text-fg-muted",children:C.type||"string"}),C.required?r.jsx("span",{className:"text-red-500",children:"*"}):null]},C.name))})]}):null,t.schedule?r.jsxs("p",{className:"text-[11px] text-fg-tertiary",children:[v("work:task.workflowScheduled","定时"),":"," ",t.schedule.cron?`cron ${t.schedule.cron}`:t.schedule.interval]}):null,r.jsxs("div",{children:[r.jsx("p",{className:"mb-1.5 text-[10px] font-medium uppercase tracking-wider text-fg-tertiary",children:v("work:task.workflowRecentRuns","最近运行")}),i.length===0?r.jsx("p",{className:"text-[11px] text-fg-muted",children:v("work:task.workflowNoRecentRuns","暂无运行记录")}):r.jsx("ul",{className:"space-y-0.5",children:i.map(C=>{const R=Yu(S,l[C.id]??[]),P=Gu(S,R);return r.jsx("li",{children:r.jsxs("button",{type:"button",onClick:()=>d(C),"aria-label":v("work:task.workflowRunDetails","运行详情"),"data-testid":`workflow-run-open-${C.id}`,className:"group flex w-full flex-wrap items-center gap-x-2 gap-y-1 rounded-lg px-1.5 py-1.5 text-left text-xs transition-colors hover:bg-surface-elevated/60 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60",children:[r.jsxs("span",{className:"shrink-0 font-medium tabular-nums text-fg-secondary",children:["#",C.runNumber]}),r.jsx(ic,{status:C.status}),r.jsx("span",{className:"shrink-0 text-[11px] tabular-nums text-fg-tertiary",children:P.total>0?`${P.done}/${P.total}`:v("work:task.workflowStepCountShort","{{count}} 个任务",{count:C.taskIds.length})}),r.jsx("span",{className:"text-[11px] text-fg-muted",children:Rc(C.startedAt,v)}),C.triggeredBy==="schedule"?r.jsx("span",{className:"shrink-0 text-[10px] text-purple-500",children:v("work:task.workflowScheduled","定时")}):null,r.jsx("svg",{className:"ml-auto h-3.5 w-3.5 shrink-0 text-fg-muted opacity-0 transition-opacity group-hover:opacity-100",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})})]})},C.id)})})]})]}):r.jsx(ub,{})}),k?r.jsx(nb,{step:k.step,index:k.index,total:S.length,dependsOnNames:di(k.step,ci(S)),roleOptions:[...new Set([...S.map(C=>C.role),...Object.keys(x?.roleMapping??{})])],onClose:()=>y(null),onSave:C=>h?.(k.step.id,C)??Promise.resolve()}):null]})}const lc={done:Tn.success.bar,failed:Tn.danger.bar,active:Tn.info.bar,pending:"bg-fg-muted/50",unknown:"bg-border-default"},fa={done:{key:"runStatusCompleted",label:"已完成"},failed:{key:"runStatusFailed",label:"失败"},active:{key:"runStatusRunning",label:"进行中"},pending:{key:"workflowStepPending",label:"待处理"},unknown:{key:"workflowStepNoTask",label:"未创建任务"}};function mb({workflow:e,run:t,detail:n,tasks:s,tasksLoading:o,onClose:a,onPauseResume:i,onCancel:l,onViewTasks:c,pausing:d,roleAgentName:h,onOpenTask:u}){const{t:f}=Ve(["work","common"]),m=p.useRef(null);p.useEffect(()=>{m.current?.focus();const j=E=>{E.key==="Escape"&&a()};return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[a]);const g=t.templateSnapshot?.steps??n?.steps??[],b=ci(g),v=Yu(g,s??[]),k=Gu(g,v),y=Vu(t.status),x=(s??[]).filter(j=>!Object.values(v).some(E=>E?.id===j.id)),w=(s?.length??0)>0&&Object.values(v).every(j=>!j),S=j=>w&&j==="unknown"?{key:"workflowStepUnmatched",label:"未匹配(历史运行)"}:fa[j];return r.jsxs("div",{className:"fixed inset-0 z-50 flex justify-end",role:"presentation",children:[r.jsx("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm",onClick:a,"aria-hidden":"true"}),r.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"workflow-run-drawer-title",className:"relative flex h-full w-full max-w-md flex-col border-l border-border-default bg-surface-secondary shadow-2xl","data-testid":"workflow-run-drawer",children:[r.jsxs("header",{className:"flex items-start justify-between gap-3 border-b border-border-default/50 px-4 py-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsxs("h2",{id:"workflow-run-drawer-title",className:"truncate text-sm font-semibold text-fg-primary",children:[e.displayName||e.name," · #",t.runNumber]}),r.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-[11px] text-fg-tertiary",children:[r.jsxs("span",{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 font-medium ${Tn[y.tone].chip}`,children:[r.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${Tn[y.tone].dot}`,"aria-hidden":"true"}),f(`work:task.${y.key}`,y.label)]}),r.jsx("span",{children:Rc(t.startedAt,f)}),t.triggeredBy==="schedule"?r.jsx("span",{className:"text-purple-500",children:f("work:task.workflowScheduled","定时")}):null]})]}),r.jsx("button",{ref:m,type:"button",onClick:a,"aria-label":f("common:close","关闭"),className:"rounded-lg p-1.5 text-fg-tertiary transition-colors hover:bg-surface-elevated hover:text-fg-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60",children:r.jsx("svg",{className:"h-4 w-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:r.jsx("path",{strokeLinecap:"round",d:"M6 6l12 12M18 6L6 18"})})})]}),r.jsxs("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[r.jsxs("div",{className:"mb-4",children:[r.jsxs("div",{className:"mb-1 flex items-center justify-between text-[11px] text-fg-tertiary",children:[r.jsx("span",{children:f("work:task.workflowProgress","{{done}}/{{total}} 个任务完成",{done:k.done,total:k.total||t.taskIds.length})}),k.failed>0?r.jsx("span",{className:"text-red-500",children:f("work:task.workflowFailedCount","{{count}} 步失败",{count:k.failed})}):null]}),r.jsx("div",{className:"h-1.5 w-full overflow-hidden rounded-full bg-surface-elevated",children:r.jsx("div",{className:`h-full rounded-full transition-all ${k.failed>0?Tn.danger.bar:Tn.success.bar}`,style:{width:`${k.total>0?k.percent:0}%`}})})]}),r.jsxs("section",{className:"mb-4",children:[r.jsx("h3",{className:"mb-2 text-[10px] font-medium uppercase tracking-wider text-fg-tertiary",children:f("work:task.workflowSteps","步骤")}),o&&g.length===0?r.jsxs("div",{className:"space-y-2","aria-busy":"true",children:[r.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-elevated"}),r.jsx("div",{className:"h-3 w-full animate-pulse rounded bg-surface-elevated"}),r.jsx("div",{className:"h-3 w-1/2 animate-pulse rounded bg-surface-elevated"})]}):g.length===0?r.jsx("p",{className:"text-[11px] text-fg-muted",children:f("work:task.workflowLoading","加载中…")}):r.jsx("ol",{className:"space-y-1",children:g.map((j,E)=>{const C=v[j.id],R=eo(C),P=S(R),T=di(j,b),D=h?.(j.role),z=r.jsxs(r.Fragment,{children:[r.jsx("span",{className:`mt-1.5 h-2 w-2 shrink-0 rounded-full ${lc[R]}`,"aria-hidden":"true"}),r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsxs("span",{className:"flex flex-wrap items-center gap-x-2 gap-y-0.5",children:[r.jsxs("span",{className:"text-xs font-medium text-fg-primary",children:[E+1,". ",j.name]}),r.jsx("span",{className:"text-[10px] text-fg-muted",children:f(`work:task.${P.key}`,P.label)})]}),r.jsxs("span",{className:"mt-0.5 flex flex-wrap gap-x-2 text-[10px] text-fg-muted",children:[r.jsx("span",{children:D??j.role}),T.length>0?r.jsx("span",{children:f("work:task.workflowDependsOn","依赖 {{steps}}",{steps:T.join("、")})}):null,C?r.jsx("span",{className:"max-w-[16rem] truncate",children:C.title}):null]})]}),C&&u?r.jsx("svg",{className:"mt-1 h-3 w-3 shrink-0 text-fg-muted opacity-0 transition-opacity group-hover:opacity-100",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})}):null]});return r.jsx("li",{children:C&&u?r.jsx("button",{type:"button",onClick:()=>u(C.id),"data-testid":`workflow-run-step-${j.id}`,title:f("work:task.workflowOpenTask","查看对应任务"),className:"group flex w-full items-start gap-2 rounded-lg px-1 py-1 text-left transition-colors hover:bg-surface-elevated/60 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60",children:z}):r.jsx("div",{className:"flex items-start gap-2 rounded-lg px-1 py-1",children:z})},j.id)})}),x.length>0?r.jsxs("div",{className:"mt-3 rounded-lg border border-border-default/50 bg-surface px-2.5 py-2",children:[r.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary",children:f("work:task.workflowUnmatchedTitle","该运行的任务(未能对应到步骤)")}),r.jsx("p",{className:"mt-0.5 text-[10px] leading-relaxed text-fg-muted",children:f("work:task.workflowUnmatchedHint","这是 2026-10-27 之前的运行:任务没有记录步骤身份,历史无法反推。下列任务仍可直接打开。")}),r.jsx("ul",{className:"mt-1.5 space-y-0.5",children:x.map(j=>r.jsx("li",{children:u?r.jsxs("button",{type:"button",onClick:()=>u(j.id),className:"flex w-full items-center gap-2 rounded px-1 py-1 text-left transition-colors hover:bg-surface-elevated/60 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60",children:[r.jsx("span",{className:`h-2 w-2 shrink-0 rounded-full ${lc[eo(j)]}`,"aria-hidden":"true"}),r.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] text-fg-secondary",children:j.title}),r.jsx("span",{className:"shrink-0 text-[10px] text-fg-muted",children:f(`work:task.${fa[eo(j)].key}`,fa[eo(j)].label)})]}):r.jsx("span",{className:"block truncate px-1 py-1 text-[11px] text-fg-secondary",children:j.title})},j.id))})]}):null]}),Object.keys(t.params??{}).length>0?r.jsxs("section",{className:"mb-4",children:[r.jsx("h3",{className:"mb-1.5 text-[10px] font-medium uppercase tracking-wider text-fg-tertiary",children:f("work:task.workflowParamsCount","参数 ({{count}})",{count:Object.keys(t.params).length})}),r.jsx("dl",{className:"space-y-1",children:Object.entries(t.params).map(([j,E])=>r.jsxs("div",{className:"flex gap-2 text-[11px]",children:[r.jsx("dt",{className:"w-24 shrink-0 truncate text-fg-tertiary",children:j}),r.jsx("dd",{className:"min-w-0 flex-1 break-words text-fg-secondary",children:E||"—"})]},j))})]}):null,Object.keys(t.roleMapping??{}).length>0?r.jsxs("section",{className:"mb-4",children:[r.jsx("h3",{className:"mb-1.5 text-[10px] font-medium uppercase tracking-wider text-fg-tertiary",children:f("work:task.workflowRoleAssignments","角色分配")}),r.jsx("dl",{className:"space-y-1",children:Object.entries(t.roleMapping).map(([j,E])=>r.jsxs("div",{className:"flex gap-2 text-[11px]",children:[r.jsx("dt",{className:"w-24 shrink-0 truncate text-fg-tertiary",children:j}),r.jsx("dd",{className:"min-w-0 flex-1 truncate text-fg-secondary",children:h?.(j)??E})]},j))})]}):null]}),r.jsxs("footer",{className:"flex flex-wrap items-center justify-end gap-2 border-t border-border-default/50 px-4 py-3",children:[li(t.status)?r.jsxs(r.Fragment,{children:[r.jsx("button",{type:"button",onClick:i,disabled:d,className:"rounded-lg bg-amber-500/15 px-3 py-1.5 text-xs font-medium text-amber-600 transition-colors hover:bg-amber-500/25 disabled:opacity-60 dark:text-amber-400",children:d?"…":t.status==="running"?f("work:task.workflowPause","暂停"):f("work:task.workflowResume","恢复")}),r.jsx("button",{type:"button",onClick:l,className:"rounded-lg bg-red-500/15 px-3 py-1.5 text-xs font-medium text-red-500 transition-colors hover:bg-red-500/25",children:f("work:task.workflowCancelRun","取消运行")})]}):null,r.jsx("button",{type:"button",onClick:c,className:"rounded-lg bg-brand-600 px-3 py-1.5 text-xs font-medium text-on-brand transition-colors hover:bg-brand-500",children:f("work:task.workflowViewTasks","查看任务")})]})]})]})}function pb({mode:e,workflow:t,yaml:n,yamlLoading:s,busy:o,error:a,onClose:i,onSubmit:l}){const{t:c}=Ve(["work","common"]),[d,h]=p.useState(`${t.name}-copy`),[u,f]=p.useState(n??""),m=p.useRef(null);p.useEffect(()=>{f(n??"")},[n]),p.useEffect(()=>{m.current?.focus();const v=k=>{k.key==="Escape"&&i()};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[i]);const g=e==="edit"?c("work:task.workflowEditTitle","编辑工作流"):e==="duplicate"?c("work:task.workflowDuplicateTitle","复制为新工作流"):c("work:task.workflowDeleteConfirmTitle","删除工作流"),b=e==="duplicate"&&!/^[a-z0-9][a-z0-9-]*$/.test(d.trim());return r.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[r.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:i,"aria-hidden":"true"}),r.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"workflow-manage-title",className:"relative flex max-h-[85vh] w-full max-w-lg flex-col rounded-xl border border-border-default bg-surface-secondary p-5 shadow-2xl","data-testid":`workflow-manage-${e}`,children:[r.jsx("h2",{id:"workflow-manage-title",className:"text-sm font-semibold text-fg-primary",children:g}),r.jsx("p",{className:"mt-1 text-[11px] text-fg-tertiary",children:e==="delete"?c("work:task.workflowDeleteConfirmDesc","将删除「{{name}}」。已产生的运行记录与任务会保留,此操作不可撤销。",{name:t.displayName||t.name}):e==="duplicate"?c("work:task.workflowDuplicateDesc","基于当前模板创建一份副本,之后可以独立编辑。"):c("work:task.workflowEditDesc","直接编辑模板 YAML。保存时服务端会做校验。")}),e==="delete"?null:r.jsxs("div",{className:"mt-3 flex-1 space-y-3 overflow-y-auto",children:[e==="duplicate"?r.jsxs("div",{children:[r.jsx("label",{className:"mb-1 block text-[11px] font-medium text-fg-secondary",htmlFor:"workflow-new-name",children:c("work:task.workflowNewName","新工作流名称")}),r.jsx("input",{id:"workflow-new-name",ref:m,value:d,onChange:v=>h(v.target.value),placeholder:c("work:task.workflowNewNamePlaceholder","例如 feature-development-v2"),className:"input-field w-full font-mono text-xs"}),b?r.jsx("p",{className:"mt-1 text-[10px] text-red-500",children:c("work:task.workflowNameInvalid","只能使用小写字母、数字和连字符")}):null]}):null,r.jsxs("div",{children:[r.jsx("label",{className:"mb-1 block text-[11px] font-medium text-fg-secondary",htmlFor:"workflow-yaml",children:c("work:task.workflowYaml","YAML")}),s?r.jsxs("div",{className:"space-y-1.5","aria-busy":"true",children:[r.jsx("div",{className:"h-3 w-full animate-pulse rounded bg-surface-elevated"}),r.jsx("div",{className:"h-3 w-5/6 animate-pulse rounded bg-surface-elevated"}),r.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-elevated"})]}):r.jsx("textarea",{id:"workflow-yaml",value:u,onChange:v=>f(v.target.value),spellCheck:!1,rows:16,className:"input-field w-full resize-y font-mono text-[11px] leading-relaxed"})]})]}),a?r.jsx("p",{className:"mt-2 text-[11px] text-red-500",children:a}):null,r.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[r.jsx("button",{type:"button",onClick:i,className:"btn-secondary px-4 py-1.5 text-xs",children:c("work:task.workflowCancel","取消")}),r.jsx("button",{type:"button",disabled:o||s||e==="duplicate"&&b,onClick:()=>l({name:e==="duplicate"?d.trim():void 0,yaml:u}),className:`px-4 py-1.5 text-xs font-medium text-white transition-colors disabled:opacity-60 ${e==="delete"?"rounded-lg bg-red-600 hover:bg-red-500":"btn-primary"}`,children:o?c("work:task.workflowSaving","保存中…"):e==="delete"?c("work:task.workflowDelete","删除工作流"):e==="duplicate"?c("work:task.workflowDuplicateBtn","创建副本"):c("work:task.workflowSave","保存")})]})]})]})}const cc={pending:new Set(["in_progress","blocked","rejected","cancelled","completed"]),in_progress:new Set(["review","blocked","failed","cancelled"]),blocked:new Set(["in_progress","cancelled","failed"]),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","in_progress"]),archived:new Set([])},Ta={pending:new Set(["in_progress","blocked","rejected","cancelled"]),in_progress:new Set(["completed","blocked","rejected","cancelled"]),blocked:new Set(["in_progress","rejected","cancelled"]),review:new Set(["completed","in_progress","cancelled"]),completed:new Set(["archived","in_progress"]),failed:new Set(["in_progress","archived","pending"]),rejected:new Set(["in_progress","archived","pending"]),cancelled:new Set(["in_progress","archived","pending"]),archived:new Set([])},dc="markus_work_l1_collapsed",uc="markus_workflows_team",fc="__all__",hc=["backlog","kanban","dag","workflows"];function yo(e){const t=e.agentId,n=e.activityId;return!t||!n?null:_a({seq:e.seq,type:e.type,content:e.content??"",metadata:e.metadata,createdAt:e.createdAt??new Date().toISOString()},n,t)}function ui(e,t,n){const s=e.get(t)??[];if(s.some(a=>a.id===n.id))return e;const o=new Map(e);return o.set(t,[...s,n]),o}function fi({entries:e}){const[t,n]=p.useState("compact");return e.length===0?null:r.jsx("div",{onClick:s=>s.stopPropagation(),children:t==="compact"?r.jsx(Gf,{entries:e,isActive:!0,onExpand:()=>n("full"),embedded:!0}):r.jsx(Oc,{entries:e,isActive:!0,onCollapse:()=>n("compact"),embedded:!0})})}function hi(e,t){const[n,s]=p.useState(null);return p.useEffect(()=>{if(!t||!e.current){s(null);return}const o=()=>{const a=e.current?.getBoundingClientRect();if(!a)return;const i=240,l=window.innerHeight-a.bottom-8,c=a.top-8,d=l<i&&c>l;s(d?{top:a.top-4,left:a.left,width:a.width,flipUp:!0}:{top:a.bottom+4,left:a.left,width:a.width,flipUp:!1})};return o(),window.addEventListener("scroll",o,!0),window.addEventListener("resize",o),()=>{window.removeEventListener("scroll",o,!0),window.removeEventListener("resize",o)}},[t,e]),n}function Ft({options:e,value:t,onChange:n,placeholder:s,noMatchesText:o,className:a,disabled:i,size:l}){const[c,d]=p.useState(!1),[h,u]=p.useState(""),f=p.useRef(null),m=p.useRef(null),g=p.useRef(null),b=p.useRef(null),v=hi(m,c);p.useEffect(()=>{const w=S=>{f.current&&!f.current.contains(S.target)&&b.current&&!b.current.contains(S.target)&&d(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[]);const k=l==="sm"?"px-2 py-1.5 text-xs":"px-3 py-2 text-sm",y=e.find(w=>w.value===t)?.label??"",x=h?e.filter(w=>w.label.toLowerCase().includes(h.toLowerCase())):e;return r.jsxs("div",{ref:f,className:a??"",children:[r.jsxs("div",{ref:m,onClick:()=>{i||(d(!c),u(""),setTimeout(()=>g.current?.focus(),0))},className:`w-full ${k} bg-surface-elevated border border-border-default rounded-lg focus-within:border-brand-500 outline-none flex items-center ${i?"opacity-50 cursor-not-allowed pointer-events-none":"cursor-pointer"}`,children:[c?r.jsx("input",{ref:g,value:h,onChange:w=>u(w.target.value),onClick:w=>w.stopPropagation(),className:`w-full bg-transparent outline-none text-fg-primary ${k.split(" ").slice(2).join(" ")}`,placeholder:y||s,autoFocus:!0}):r.jsx("span",{className:y?"text-fg-primary":"text-fg-tertiary",children:y||s}),r.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),c&&v&&r.jsx("div",{ref:b,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:v.flipUp?{bottom:window.innerHeight-v.top,left:v.left,width:v.width}:{top:v.top,left:v.left,width:v.width},children:x.length===0?r.jsx("div",{className:`${k} text-fg-tertiary`,children:o??"No matches"}):x.map(w=>r.jsx("div",{onClick:()=>{n(w.value),d(!1),u("")},className:`${k} cursor-pointer hover:bg-brand-500/10 ${w.value===t?"bg-brand-500/10 text-brand-500 font-medium":"text-fg-primary"}`,children:w.label},w.value))})]})}const gb=[{value:"low",labelKey:"work:priority.low",dot:"bg-slate-400",active:"bg-slate-500/15 text-slate-500 border-slate-500/40"},{value:"medium",labelKey:"work:priority.medium",dot:"bg-blue-500",active:"bg-blue-500/15 text-blue-500 border-blue-500/40"},{value:"high",labelKey:"work:priority.high",dot:"bg-amber-500",active:"bg-amber-500/15 text-amber-600 border-amber-500/40"},{value:"urgent",labelKey:"work:priority.urgent",dot:"bg-red-500",active:"bg-red-500/15 text-red-500 border-red-500/40"}];function wo({value:e,onChange:t}){const{t:n}=Ve("work");return r.jsx("div",{className:"flex flex-wrap gap-2",children:gb.map(s=>{const o=e===s.value;return r.jsxs("button",{type:"button",onClick:()=>t(s.value),"aria-pressed":o,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-lg border transition-all ${o?`${s.active} font-medium`:"border-border-default text-fg-secondary hover:bg-surface-elevated"}`,children:[r.jsx("span",{className:`w-2 h-2 rounded-full ${s.dot}`}),n(s.labelKey)]},s.value)})})}function Zu({kind:e,entity:t,agents:n,users:s,projects:o,onClose:a}){const i=t.title?.trim()||t.id,l=Vf(i),c=t.projectId?o.find(u=>u.id===t.projectId)?.name??t.projectId:"",d=`${e==="requirement"?"📋":"✅"} ${l}`,h=[`@[${i}](${e}:${t.id})`,`[${e}]`,`ID: ${t.id}`,`Title: ${i}`,t.status?`Status: ${t.status}`:"",t.priority?`Priority: ${t.priority}`:"",c?`Project: ${c}`:""].filter(Boolean).join(`
|
|
138
|
-
`);return r.jsx(Ac,{chipKind:e,chipLabel:d,chipContent:h,agents:n,users:s,defaultTarget:_c(t.createdBy,n,s),onClose:a})}function xb({options:e,selected:t,onAdd:n,placeholder:s,noMatchesText:o,className:a}){const[i,l]=p.useState(!1),[c,d]=p.useState(""),h=p.useRef(null),u=p.useRef(null),f=p.useRef(null),m=p.useRef(null),g=hi(u,i);p.useEffect(()=>{const k=y=>{h.current&&!h.current.contains(y.target)&&m.current&&!m.current.contains(y.target)&&l(!1)};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[]);const b=e.filter(k=>!t.includes(k.value)),v=c?b.filter(k=>k.label.toLowerCase().includes(c.toLowerCase())):b;return r.jsxs("div",{ref:h,className:a??"",children:[r.jsxs("div",{ref:u,onClick:()=>{l(!i),d(""),setTimeout(()=>f.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:[i?r.jsx("input",{ref:f,value:c,onChange:k=>d(k.target.value),onClick:k=>k.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-sm",placeholder:s,autoFocus:!0}):r.jsx("span",{className:"text-fg-tertiary",children:s}),r.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),i&&g&&r.jsx("div",{ref:m,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:g.flipUp?{bottom:window.innerHeight-g.top,left:g.left,width:g.width}:{top:g.top,left:g.left,width:g.width},children:v.length===0?r.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:o??"No matches"}):v.map(k=>r.jsx("div",{onClick:()=>{n(k.value),d("")},className:"px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 text-fg-primary",children:k.label},k.value))})]})}function bb({options:e,onSelect:t,placeholder:n,noMatchesText:s,className:o,itemSuffix:a}){const[i,l]=p.useState(!1),[c,d]=p.useState(""),h=p.useRef(null),u=p.useRef(null),f=p.useRef(null),m=p.useRef(null),g=hi(u,i);p.useEffect(()=>{const v=k=>{h.current&&!h.current.contains(k.target)&&m.current&&!m.current.contains(k.target)&&l(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]);const b=c?e.filter(v=>v.label.toLowerCase().includes(c.toLowerCase())):e;return r.jsxs("div",{ref:h,className:o??"",children:[r.jsxs("div",{ref:u,onClick:()=>{l(!i),d(""),setTimeout(()=>f.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:[i?r.jsx("input",{ref:f,value:c,onChange:v=>d(v.target.value),onClick:v=>v.stopPropagation(),className:"w-full bg-transparent outline-none text-fg-primary text-[11px]",placeholder:n,autoFocus:!0}):r.jsx("span",{className:"text-fg-tertiary",children:n}),r.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:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),i&&g&&r.jsx("div",{ref:m,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:g.flipUp?{bottom:window.innerHeight-g.top,left:g.left,width:g.width}:{top:g.top,left:g.left,width:g.width},children:b.length===0?r.jsx("div",{className:"px-3 py-2 text-xs text-fg-tertiary",children:s??"No matches"}):b.map(v=>r.jsxs("div",{onClick:()=>{t(v.value),l(!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:[r.jsx("span",{className:"truncate",children:v.label}),a?.(v)]},v.value))})]})}function $s(e,t,n,s="Admin"){if(!e)return null;const o=t.find(i=>i.id===e);if(o)return o.name;const a=n.find(i=>i.id===e);return a?a.name:e==="anonymous"?s:null}function yb({value:e,onSave:t,className:n,placeholder:s}){const{t:o}=Ve(["work","common"]),[a,i]=p.useState(!1),[l,c]=p.useState(e),d=p.useRef(null);p.useEffect(()=>{c(e)},[e]),p.useEffect(()=>{a&&d.current?.focus()},[a]);const h=async()=>{i(!1);const u=l.trim();if(u&&u!==e)try{await t(u)}catch{c(e)}else c(e)};return a?r.jsx("input",{ref:d,value:l,onChange:u=>c(u.target.value),onBlur:()=>{h()},onKeyDown:u=>{u.key==="Enter"&&h(),u.key==="Escape"&&(c(e),i(!1))},className:`bg-transparent border-b border-brand-500/50 outline-none ${n??""}`,placeholder:s}):r.jsx("span",{onClick:()=>i(!0),className:`cursor-pointer hover:border-b hover:border-gray-600 transition-colors ${n??""}`,title:o("work:task.clickToEdit"),children:e||r.jsx("span",{className:"text-fg-tertiary italic",children:s??o("work:task.clickToEdit")})})}function wb({value:e,onSave:t,className:n,placeholder:s}){const{t:o}=Ve(["work","common"]),[a,i]=p.useState(!1),[l,c]=p.useState(e),d=p.useRef(null);p.useEffect(()=>{c(e)},[e]),p.useEffect(()=>{a&&d.current&&(d.current.focus(),d.current.style.height="auto",d.current.style.height=d.current.scrollHeight+"px")},[a]);const h=async()=>{i(!1);const u=l.trim();if(u!==e)try{await t(u)}catch{c(e)}else c(e)};return a?r.jsx("textarea",{ref:d,value:l,onChange:u=>{c(u.target.value),u.target.style.height="auto",u.target.style.height=u.target.scrollHeight+"px"},onBlur:()=>{h()},onKeyDown:u=>{u.key==="Escape"&&(c(e),i(!1))},className:`bg-transparent border border-brand-500/30 rounded-lg p-2 outline-none resize-none w-full ${n??""}`,placeholder:s,rows:2}):r.jsx("p",{onClick:()=>i(!0),className:`cursor-pointer hover:bg-surface-elevated/50 rounded-lg transition-colors px-2 py-1 -mx-2 -my-1 ${n??""}`,title:o("work:task.clickToEdit"),children:e||r.jsx("span",{className:"text-fg-tertiary italic",children:s??o("work:task.addDescription")})})}const kb=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function Qu(e){const t=e.match(kb);return t?{timestamp:t[1].trim(),author:t[2]?.trim()??"System",content:t[3].trim()}:{timestamp:"",author:"",content:e}}function vb(e,t){if(!e)return"";const n=e.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);if(!n)return e;const s=new Date,o=+n[1],a=+n[2]-1,i=+n[3],l=+n[4],c=+n[5],d=new Date(o,a,i,l,c),h=s.getTime()-d.getTime();return h<6e4?t("work:relative.justNow"):h<36e5?t("work:relative.minutesAgo",{count:Math.floor(h/6e4)}):h<864e5?t("work:relative.hoursAgo",{count:Math.floor(h/36e5)}):h<6048e5?t("work:relative.daysAgo",{count:Math.floor(h/864e5)}):`${o}-${String(a+1).padStart(2,"0")}-${String(i).padStart(2,"0")}`}const mc=[{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 jb(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return mc[Math.abs(t)%mc.length]}function Nb({note:e,compact:t}){const{t:n}=Ve(["work","common"]),s=Qu(e),o=n("work:task.systemAuthor"),a=jb(s.author||o),i=s.author?s.author.split(/[\s_-]+/).map(d=>d[0]).join("").slice(0,2).toUpperCase():"SY",l=vb(s.timestamp,n),c=!s.author||s.author==="System";return t?r.jsxs("div",{className:"flex gap-2.5 group",children:[r.jsx("div",{className:`w-6 h-6 rounded-full ${a.bg} flex items-center justify-center text-[9px] font-bold ${a.text} shrink-0 mt-0.5`,children:i}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[r.jsx("span",{className:`text-[11px] font-medium ${c?"text-fg-tertiary":a.text}`,children:c?o:s.author}),l&&r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:l})]}),r.jsx("div",{className:"text-xs text-fg-secondary",children:r.jsx(ar,{content:s.content,className:"text-xs text-fg-secondary"})})]})]}):r.jsxs("div",{className:"flex gap-3 group",children:[r.jsxs("div",{className:"flex flex-col items-center shrink-0",children:[r.jsx("div",{className:`w-7 h-7 rounded-full ${a.bg} flex items-center justify-center text-[10px] font-bold ${a.text}`,children:i}),r.jsx("div",{className:"w-px flex-1 bg-border-default/60 mt-1.5"})]}),r.jsx("div",{className:"flex-1 min-w-0 pb-4",children:r.jsxs("div",{className:`border ${a.border} rounded-lg overflow-hidden`,children:[r.jsxs("div",{className:`flex items-center gap-2 px-3 py-1.5 ${a.bg} border-b ${a.border}`,children:[r.jsx("span",{className:`text-[11px] font-medium ${c?"text-fg-secondary":a.text}`,children:c?o:s.author}),l&&r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:l})]}),r.jsx("div",{className:"px-3 py-2.5",children:r.jsx(ar,{content:s.content,className:"text-xs text-fg-secondary"})})]})})]})}const Sb=new Set(["rejected","cancelled","archived"]),ko=[{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"}],pc={pending:Gn.neutral.chip,blocked:Gn.blocked.chip,failed:Gn.danger.chip,rejected:Gn.danger.chip},gc=Object.fromEntries(["pending","in_progress","blocked","review","revision","completed","failed","rejected","cancelled","archived"].map(e=>[e,Gn[Hf(e)].chip])),xc={low:"bg-gray-500/15 text-fg-tertiary",medium:"bg-surface-overlay text-fg-secondary",high:"bg-surface-overlay text-fg-secondary font-semibold",urgent:Gn.danger.chip},bc=Object.fromEntries(["pending","in_progress","completed","rejected","cancelled","archived"].map(e=>[e,Gn[zf(e)].chip]));function Ju(e){return Object.keys(gc).reduce((t,n)=>(t[n]={label:e(`work:status.task.${n}`),cls:gc[n]},t),{})}function ef(e){return Object.keys(pc).reduce((t,n)=>(t[n]={label:e(`work:status.sub.${n}`),cls:pc[n]},t),{})}function Cb(e){return Object.keys(xc).reduce((t,n)=>(t[n]={label:e(`work:priority.${n}`),cls:xc[n]},t),{})}function mi(e){return Object.keys(bc).reduce((t,n)=>(t[n]={label:e(`work:status.requirement.${n}`),cls:bc[n]},t),{})}const yc=["low","medium","high","urgent"],wc=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],kc=["pending","in_progress","blocked","completed","rejected","cancelled"],Qn={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"},vc={idle:"text-green-500",working:"text-blue-500",error:"text-red-500",paused:"text-amber-500",offline:"text-fg-muted"};function Eb({agent:e,anchorRect:t,onClose:n}){const{t:s}=Ve(["work","common"]),o=p.useRef(null);p.useEffect(()=>{const l=c=>{o.current&&!o.current.contains(c.target)&&n()};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[n]);const a=e.status==="idle"?"bg-green-400":e.status==="working"?"bg-blue-400 animate-pulse":e.status==="error"?"bg-red-400":"bg-gray-500",i=e.status==="idle"?s("work:task.online"):e.status==="working"?s("work:task.working"):e.status==="error"?s("work:task.error"):s("work:task.offline");return r.jsxs("div",{ref:o,className:"fixed z-50 w-56 bg-surface-secondary border border-border-default rounded-xl shadow-2xl p-3 space-y-2",style:{top:t.top+4,left:t.left},children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.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()}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"text-xs text-fg-primary font-medium truncate",children:e.name}),r.jsx("div",{className:"text-[10px] text-fg-tertiary",children:e.role}),r.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${a}`}),r.jsx("span",{className:"text-[10px] text-fg-secondary",children:i})]})]})]}),r.jsx("button",{onClick:()=>{n(),tn.navigate(nt.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:s("work:task.viewProfile")})]})}function Po({comment:e,agents:t,onReply:n}){const{t:s}=Ve(["work","common"]),o=e.authorType==="agent"||e.authorType==="system",a=new Date(e.createdAt),i=a.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),l=a.toLocaleDateString([],{month:"short",day:"numeric"}),[c,d]=p.useState(null),[h,u]=p.useState(!1),[f,m]=p.useState([]),[g,b]=p.useState(!1),v=p.useCallback((S,j)=>{const E=t.find(C=>C.name.toLowerCase()===S.toLowerCase());if(E){const C=j.target.getBoundingClientRect();d({agent:E,top:C.bottom,left:C.left})}},[t]),k=p.useMemo(()=>t.map(S=>S.name),[t]),y=p.useCallback(S=>{const j=t.find(E=>E.name.toLowerCase()===e.authorName.toLowerCase());if(j){const E=S.currentTarget.getBoundingClientRect();d({agent:j,top:E.bottom,left:E.left})}},[t,e.authorName]),x=p.useCallback(async()=>{if(h){u(!1);return}const S=e.activityId;if(S&&(u(!0),!(f.length>0))){b(!0);try{const{logs:j}=await se.agents.getActivityLogs(e.authorId,S),E=j.map(C=>_a(C,S,e.authorId)).filter(C=>C!==null).map(C=>({...C,ts:new Date(C.createdAt).getTime()}));m(E)}catch{}b(!1)}},[h,f.length,e]),w=p.useMemo(()=>Uf(f.map(Yf).filter(S=>S!==null)),[f]);return r.jsxs("div",{className:"flex gap-2.5 group py-1",id:`comment-${e.id}`,children:[r.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 ${o?"bg-indigo-500/20 text-indigo-400":"bg-blue-500/20 text-blue-400"}`,children:e.authorName.slice(0,2).toUpperCase()}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[r.jsx("span",{className:`text-[11px] font-medium cursor-pointer hover:underline ${o?"text-indigo-400":"text-blue-400"}`,onClick:y,children:e.authorName}),r.jsxs("span",{className:"text-fg-tertiary text-[10px]",children:[l," ",i]}),n&&r.jsx("button",{onClick:()=>n(e),className:"text-fg-tertiary hover:text-fg-secondary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:s("work:task.reply")}),e.activityId&&o&&r.jsx("button",{onClick:x,className:"text-fg-tertiary hover:text-brand-400 text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:s(h?"work:task.hideLog":"work:task.viewLog")})]}),e.replyTo&&e.replyToAuthor&&r.jsxs("button",{onClick:()=>{const S=document.getElementById(`comment-${e.replyTo}`);S&&(S.scrollIntoView({behavior:"smooth",block:"center"}),S.classList.add("bg-brand-500/10"),setTimeout(()=>S.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:[r.jsx("span",{className:"font-medium text-brand-500/70",children:e.replyToAuthor}),r.jsx("span",{className:"truncate max-w-[200px]",children:e.replyToContent??"..."})]}),r.jsx(ar,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:v,knownNames:k}),e.attachments?.map((S,j)=>S.type==="image"?r.jsx("img",{src:S.url,alt:S.name,className:"mt-1 max-w-[200px] rounded"},j):null),h&&r.jsx("div",{className:"mt-2 border border-border-subtle rounded-lg overflow-hidden bg-surface-secondary/30",children:g?r.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:s("work:task.loadingExecutionLog")}):w.length===0?r.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:s("work:task.noExecutionLogAvailable")}):r.jsx(Oc,{entries:f,isActive:!1,onCollapse:()=>u(!1),embedded:!0})})]}),c&&r.jsx(Eb,{agent:c.agent,anchorRect:{top:c.top,left:c.left},onClose:()=>d(null)})]})}function Ib({task:e,agents:t,users:n,authUser:s}){const{t:o}=Ve(["work","common"]),[a,i]=p.useState([]),[l,c]=p.useState([]),d=p.useRef(null),[h,u]=p.useState(new Map);p.useEffect(()=>{c([]),u(new Map),d.current&&(clearTimeout(d.current),d.current=null),se.tasks.getComments(e.id).then(k=>i(k.comments)).catch(()=>{})},[e.id]),p.useEffect(()=>Dt.on("task:comment",y=>{if(y.payload?.taskId===e.id&&y.payload.comment){const x=y.payload.comment;i(w=>w.some(S=>S.id===x.id)?w:[...w,x]),(x.authorType==="agent"||x.authorId?.startsWith("agt_"))&&(c(w=>{const S=w.filter(j=>j.id!==x.authorId);return S.length===0&&d.current&&(clearTimeout(d.current),d.current=null),S}),u(w=>{const S=new Map(w);return S.delete(x.authorId),S}))}}),[e.id]),p.useEffect(()=>{if(l.length===0)return;const k=new Set(l.map(x=>x.id));return Dt.on("agent:activity_log",x=>{const w=x.payload;if(!w)return;const S=w.agentId;if(!k.has(S))return;const j=yo(w);j&&u(E=>ui(E,S,j))})},[l]);const f=p.useMemo(()=>{const k=[];for(const y of e.notes??[]){const x=Qu(y);let w;if(x.timestamp){const S=x.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);w=S?new Date(+S[1],+S[2]-1,+S[3],+S[4],+S[5],+(S[6]??0)):new Date(0)}else w=new Date(0);k.push({type:"note",note:y,ts:w})}for(const y of a)k.push({type:"comment",comment:y,ts:new Date(y.createdAt)});return k.sort((y,x)=>y.ts.getTime()-x.ts.getTime()),k},[e.notes,a]),[m,g]=p.useState(null),b=async(k,y,x,w)=>{let S;x.length>0&&(S=(await se.uploads.upload(x.map(R=>({dataUrl:R.dataUrl,name:R.name})),"comments")).files.map(R=>({type:"image",url:R.url,name:R.name})));const j=await se.tasks.addComment(e.id,k,s?.name,S,s?.id,y.length>0?y:void 0,w),E=Ka(j.notifiedAgentIds,t);E.length>0&&(d.current&&clearTimeout(d.current),c(E),d.current=setTimeout(()=>c([]),12e4))},v=p.useCallback(k=>{g({id:k.id,authorName:k.authorName,content:k.content.slice(0,100)})},[]);return r.jsxs("div",{className:"mt-5",children:[r.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:o("work:task.activityCommentsHeading")}),r.jsxs("div",{className:"space-y-0.5 mb-3",children:[f.length===0&&r.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:o("work:task.noActivityYet")}),f.map((k,y)=>k.type==="note"?r.jsx(Nb,{note:k.note,compact:!0},`n-${y}`):r.jsx(Po,{comment:k.comment,agents:t,onReply:v},`c-${k.comment.id}`)),l.length>0&&r.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:l.map(k=>{const y=h.get(k.id)??[];return r.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>tn.navigate(nt.TEAM,{agentId:k.id,profileTab:"mind"}),children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"relative shrink-0",children:[r.jsx(La,{name:k.name,avatarUrl:k.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),r.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"})]}),r.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:k.name}),y.length===0&&r.jsxs("span",{className:"flex items-center gap-0.5",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.agentProcessing")}),r.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),y.length>0&&r.jsx("div",{className:"ml-8 mt-1",children:r.jsx(fi,{entries:y})})]},k.id)})})]}),r.jsx(Dc,{agents:t,humans:n,onSubmit:b,replyTo:m,onCancelReply:()=>g(null),placeholder:o("work:task.commentPlaceholder")})]})}function ha({entries:e,comments:t,agents:n,isExecuting:s}){const o=p.useMemo(()=>{const i=[...e.map(l=>({kind:"entry",entry:l,ts:l.createdAt?new Date(l.createdAt).getTime():0})),...t.map(l=>({kind:"comment",comment:l,ts:new Date(l.createdAt).getTime()}))];return i.sort((l,c)=>l.ts-c.ts),i},[e,t]),a=p.useMemo(()=>{const i=[];let l=[];const c=()=>{l.length!==0&&(i.push({kind:"entries",key:`entries-${i.length}`,entries:l}),l=[])};return o.forEach(d=>{d.kind==="comment"?(c(),i.push({kind:"comment",key:`c-${d.comment.id}`,comment:d.comment})):l.push(d.entry)}),c(),i},[o]);return r.jsx(r.Fragment,{children:a.map(i=>i.kind==="comment"?r.jsx(Po,{comment:i.comment,agents:n},i.key):r.jsx(Xf,{entries:i.entries,isStreaming:s},i.key))})}function Tb({task:e,isRunning:t,authUser:n,agents:s,reviewSessions:o=[]}){const a=e.id,{t:i}=Ve(["work","common"]),[l,c]=p.useState([]),[d,h]=p.useState(new Map),[u,f]=p.useState(new Set),[m,g]=p.useState([]),[b,v]=p.useState(""),[k,y]=p.useState(t),[x,w]=p.useState(!0),[S,j]=p.useState(new Set),[E,C]=p.useState(""),[R,P]=p.useState(!1),[T,D]=p.useState([]),z=p.useRef(null),[I,B]=p.useState(new Map),[L,q]=p.useState([]),[_,A]=p.useState([]),[$,F]=p.useState(!1),V=p.useRef(null),X=p.useRef(null),[O,M]=p.useState(new Map),[K,W]=p.useState(new Set),[H,Z]=p.useState(new Set),J=p.useCallback(async re=>{W(he=>new Set(he).add(re.id));try{const{activities:he}=await se.agents.getActivities(re.reviewerId,{limit:200}),ge=wh(he,{taskId:a,queuedAt:re.queuedAt,completedAt:re.completedAt}),ee=[];for(const ne of ge){const{logs:oe}=await se.agents.getActivityLogs(re.reviewerId,ne.id);for(const je of oe){const ye=_a(je,ne.id,re.reviewerId);ye&&ee.push(ye)}}M(ne=>new Map(ne).set(re.id,ee))}catch{M(he=>new Map(he).set(re.id,[]))}finally{W(he=>{const ge=new Set(he);return ge.delete(re.id),ge})}},[a]),le=re=>{Z(he=>{const ge=new Set(he);return ge.has(re.id)?(ge.delete(re.id),ge):(ge.add(re.id),ge)}),!O.has(re.id)&&!K.has(re.id)&&J(re)},ue=p.useMemo(()=>xh(l,o,"all").map(re=>{if(re.kind==="review")return{kind:"review",session:re.session};const he=l.findIndex(ge=>ge.round===re.round);return{kind:"execution",rs:l[he],rsIdx:he}}),[l,o]);p.useEffect(()=>{const re=o.filter(ge=>ge.status==="reviewing"&&H.has(ge.id));return re.length===0?void 0:Dt.on("agent:activity_log",ge=>{const ee=ge.payload;if(!ee)return;const ne=ee.agentId;if(!ne)return;const oe=yo(ee);if(oe)for(const je of re)je.reviewerId===ne&&Vc(oe.createdAt,{queuedAt:je.queuedAt,completedAt:je.completedAt})&&M(ye=>{const Se=ye.get(je.id)??[];if(Se.some(st=>st.sourceId===oe.sourceId&&st.seq===oe.seq))return ye;const Te=new Map(ye);return Te.set(je.id,[...Se,oe]),Te})})},[o,H,a]),p.useEffect(()=>{y(t)},[t]),p.useEffect(()=>{D([]),B(new Map),z.current&&(clearTimeout(z.current),z.current=null)},[a]),p.useEffect(()=>{w(!0),Promise.all([se.tasks.getLogsSummary(a).catch(()=>({rounds:[]})),se.tasks.getComments(a).catch(()=>({comments:[]}))]).then(([re,he])=>{const ge=re.rounds;if(c(ge),g(he.comments),ge.length===0){w(!1);return}const ee=ge[ge.length-1].round;j(new Set([ee])),se.tasks.getLogs(a,ee).catch(()=>({logs:[]})).then(ne=>{h(new Map([[ee,ne.logs]])),w(!1)})})},[a]),p.useEffect(()=>{const re=e.assignedAgentId;re&&(F(!0),se.agents.getActivities(re,{taskId:a,limit:20}).then(he=>A(he.activities)).catch(()=>A([])).finally(()=>F(!1)))},[a,e.assignedAgentId]);const pe=p.useCallback(re=>{d.has(re)||u.has(re)||(f(he=>new Set(he).add(re)),se.tasks.getLogs(a,re).catch(()=>({logs:[]})).then(he=>{h(ge=>new Map(ge).set(re,he.logs)),f(ge=>{const ee=new Set(ge);return ee.delete(re),ee})}))},[a,d,u]),we=p.useCallback(re=>{j(he=>{const ge=new Set(he);return ge.has(re)?ge.delete(re):(ge.add(re),d.has(re)||pe(re)),ge})},[d,pe]);p.useEffect(()=>{const re=Dt.on("task:log",ee=>{const ne=ee.payload;if(ne.taskId!==a)return;const oe={id:ne.id,taskId:ne.taskId,agentId:ne.agentId,seq:ne.seq,type:ne.logType,content:ne.content,metadata:ne.metadata,executionRound:ne.executionRound,createdAt:ne.createdAt},je=oe.executionRound??1;c(ye=>ye.find(Te=>Te.round===je)?ye:[...ye,{round:je,logCount:0,toolCount:0,firstAt:oe.createdAt,lastAt:oe.createdAt,status:"running"}]),j(ye=>ye.has(je)?ye:new Set(ye).add(je)),h(ye=>{const Se=ye.get(je)??[];return oe.id&&Se.some(Te=>Te.id===oe.id)?ye:new Map(ye).set(je,[...Se,oe])}),oe.type==="text"&&v(""),oe.type==="status"&&(oe.content==="started"||oe.content==="resumed"?y(!0):["completed","failed","cancelled","execution_finished"].includes(oe.content)&&(y(!1),c(ye=>ye.map(Se=>Se.round===je?{...Se,status:oe.content}:Se)))),oe.type==="error"&&y(!1)}),he=Dt.on("task:log:delta",ee=>{const ne=ee.payload;ne.taskId===a&&v(oe=>oe+ne.text)}),ge=Dt.on("task:comment",ee=>{const ne=ee.payload;if(ne.taskId!==a)return;const oe=ne.comment;g(je=>je.some(ye=>ye.id===oe.id)?je:[...je,oe]),(oe.authorType==="agent"||oe.authorId?.startsWith("agt_"))&&(D(je=>{const ye=je.filter(Se=>Se.id!==oe.authorId);return ye.length===0&&z.current&&(clearTimeout(z.current),z.current=null),ye}),B(je=>{const ye=new Map(je);return ye.delete(oe.authorId),ye}))});return()=>{re(),he(),ge()}},[a]),p.useEffect(()=>{if(T.length===0)return;const re=new Set(T.map(ge=>ge.id));return Dt.on("agent:activity_log",ge=>{const ee=ge.payload;if(!ee)return;const ne=ee.agentId;if(!re.has(ne))return;const oe=yo(ee);oe&&B(je=>ui(je,ne,oe))})},[T]);const Ne=p.useMemo(()=>{const re=[];for(const[,he]of d)re.push(...he);return re.sort((he,ge)=>he.seq-ge.seq),re},[d]),ke=p.useMemo(()=>Ne.map(re=>Wi(re)),[Ne]),Be=l.length>1||o.length>0,et=re=>{const he=re.target.files;if(he){for(const ge of Array.from(he)){if(!ge.type.startsWith("image/"))continue;const ee=new FileReader;ee.onload=()=>{q(ne=>[...ne,{type:"image",url:ee.result,name:ge.name}])},ee.readAsDataURL(ge)}re.target.value=""}},Ee=async()=>{if(!(!E.trim()&&L.length===0)){P(!0);try{let re;L.length>0&&(re=(await se.uploads.upload(L.map(ne=>({dataUrl:ne.url,name:ne.name})),"comments")).files.map(ne=>({type:"image",url:ne.url,name:ne.name})));const he=await se.tasks.addComment(a,E,n?.name,re,n?.id);he.comment&&g(ee=>ee.some(ne=>ne.id===he.comment.id)?ee:[...ee,he.comment]),C(""),q([]);const ge=Ka(he.notifiedAgentIds,s);ge.length>0&&(z.current&&clearTimeout(z.current),D(ge),z.current=setTimeout(()=>D([]),12e4))}catch{}P(!1)}},Ke=r.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-primary z-10",children:[L.length>0&&r.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:L.map((re,he)=>r.jsxs("div",{className:"relative group",children:[r.jsx("img",{src:re.url,alt:re.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),r.jsx("button",{onClick:()=>q(ge=>ge.filter((ee,ne)=>ne!==he)),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:"×"})]},he))}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"text",value:E,onChange:re=>C(re.target.value),onKeyDown:re=>{re.key==="Enter"&&!re.shiftKey&&(re.preventDefault(),Ee())},placeholder:i("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"}),r.jsx("input",{type:"file",ref:V,accept:"image/*",multiple:!0,onChange:et,className:"hidden"}),r.jsx("button",{onClick:()=>V.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:i("work:task.attachImage"),children:"📎"}),r.jsx("button",{onClick:()=>{Ee()},disabled:R||!E.trim()&&L.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:i("common:send")})]})]});if(x)return r.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-fg-tertiary",children:i("work:task.loadingLogs")});if(l.length===0&&!b){const re=e.assignedAgentId?s.find(Te=>Te.id===e.assignedAgentId):void 0,he=_.length>0,ge=re&&re.currentTaskId&&re.currentTaskId!==e.id,ee=e.status==="pending",ne=e.status==="in_progress",oe=!e.assignedAgentId;let je="📋",ye=i("work:task.emptyLogs.default"),Se=i("work:task.emptyLogs.defaultHint");return oe?(je="👤",ye=i("work:task.emptyLogs.noAgent"),Se=i("work:task.emptyLogs.noAgentHint")):ee?(je="⏳",ye=i("work:task.emptyLogs.pending"),Se=i("work:task.emptyLogs.pendingHint")):ne&&ge?(je="🔄",ye=i("work:task.emptyLogs.agentBusy",{agent:re?.name??e.assignedAgentId}),Se=i("work:task.emptyLogs.agentBusyHint")):ne&&(je="⏳",ye=i("work:task.emptyLogs.starting"),Se=i("work:task.emptyLogs.startingHint")),r.jsxs("div",{className:"flex flex-col min-h-full",children:[r.jsx("div",{className:"flex-1 overflow-y-auto",children:$?r.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-fg-tertiary",children:i("work:task.loadingLogs")}):he?r.jsxs("div",{className:"px-4 py-4",children:[r.jsxs("div",{className:"text-xs text-fg-secondary mb-3 flex items-center gap-1.5",children:[r.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-blue-500"}),i("work:task.relatedSessions",{agent:re?.name??i("work:task.agent"),count:_.length})]}),r.jsx("div",{className:"space-y-1.5",children:_.map(Te=>{const st=!Te.endedAt,qe=Te.type==="task"?"🔧":Te.type==="chat"||Te.type==="respond_in_session"?"💬":Te.type==="heartbeat"?"💓":"📋";return r.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:()=>tn.navigate(nt.TEAM,{agentId:e.assignedAgentId}),children:[r.jsx("span",{className:"text-sm shrink-0",children:qe}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"text-xs text-fg-primary truncate",children:Te.label}),r.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[new Date(Te.startedAt).toLocaleString(),Te.endedAt?` — ${Te.totalTools} tools, ${Te.totalTokens.toLocaleString()} tokens`:""]})]}),st&&r.jsxs("span",{className:"shrink-0 flex items-center gap-1 text-[10px] text-green-500 font-medium",children:[r.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 animate-pulse"}),i("work:task.sessionLive")]}),!st&&r.jsx("span",{className:`shrink-0 text-[10px] ${Te.success?"text-fg-tertiary":"text-red-400"}`,children:Te.success?"✓":"✗"}),r.jsx("span",{className:"shrink-0 text-fg-tertiary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity",children:"→"})]},Te.id)})})]}):r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsxs("div",{className:"text-center text-fg-tertiary",children:[r.jsx("div",{className:"text-2xl mb-2",children:je}),r.jsxs("div",{className:"text-xs",children:[ye,r.jsx("br",{}),r.jsx("span",{className:"text-fg-muted",children:Se})]})]})})}),Ke]})}if(!Be)return r.jsxs("div",{className:"flex flex-col min-h-full",children:[r.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[r.jsx(ha,{entries:ke,comments:m,agents:s,isExecuting:k}),k&&b&&r.jsx(Ki,{content:b}),k&&!b&&ke.length>0&&r.jsx(Ui,{})]}),Ke]});const ot=(re,he)=>{const ge=re.firstAt?new Date(re.firstAt).getTime():0,ee=he?.firstAt?new Date(he.firstAt).getTime():1/0;return m.filter(ne=>{const oe=new Date(ne.createdAt).getTime();return oe>=ge&&oe<ee})},_e=l.length>0?m.filter(re=>new Date(re.createdAt).getTime()<new Date(l[0].firstAt).getTime()):[];return r.jsxs("div",{className:"flex flex-col min-h-full",children:[r.jsx("div",{ref:X}),r.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[_e.length>0&&r.jsx("div",{className:"space-y-0.5",children:_e.map(re=>r.jsx(Po,{comment:re,agents:s},re.id))}),ue.map(re=>{if(re.kind==="review"){const qe=re.session,te=H.has(qe.id),Re=qe.status==="reviewing",Ue=O.get(qe.id),mt=K.has(qe.id),Qe=Re?"🔄":qe.outcome==="approved"?"✅":qe.outcome==="revision_requested"?"↩️":"⏹";return r.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[r.jsxs("button",{onClick:()=>le(qe),className:"w-full flex items-center justify-between px-3 py-2 bg-surface-elevated/30 hover:bg-surface-elevated/50 transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm",children:Qe}),r.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:i("work:task.reviewRoundLabel",{round:qe.round})}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:qe.reviewerName}),Re&&r.jsx("span",{className:"text-[10px] text-purple-400",children:i("work:task.reviewLive")})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:new Date(qe.queuedAt).toLocaleString()}),r.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${te?"rotate-180":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:r.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"})})]})]}),te&&r.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[qe.note&&r.jsx("p",{className:"whitespace-pre-wrap break-words text-[11px] leading-relaxed text-fg-secondary",children:qe.note}),mt&&r.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:i("work:task.reviewLoading")}),Ue&&Ue.length>0&&r.jsx(ha,{entries:Ue,comments:[],agents:s,isExecuting:!1}),Ue&&Ue.length===0&&r.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:i("work:task.reviewNoTurns")})]})]},qe.id)}const he=re.rs,ge=re.rsIdx,ee=S.has(he.round),ne=he.round===l[l.length-1].round,oe=d.get(he.round),je=u.has(he.round),ye=ot(he,l[ge+1]),Se=he.status==="completed"||he.status==="execution_finished"?"✅":he.status==="failed"?"❌":he.status==="cancelled"?"⏹":"🔄",Te=he.lastAt&&he.firstAt?Math.max(0,new Date(he.lastAt).getTime()-new Date(he.firstAt).getTime()):0,st=Te>=6e4?`${Math.floor(Te/6e4)}m ${Math.floor(Te%6e4/1e3)}s`:Te>=1e3?`${Math.floor(Te/1e3)}s`:"";return r.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[r.jsxs("button",{onClick:()=>we(he.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:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm",children:Se}),r.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:i("work:task.roundHeader",{n:he.round})}),ye.length>0&&r.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",ye.length]}),ne&&k&&r.jsxs("svg",{className:"w-3 h-3 animate-spin text-brand-500",viewBox:"0 0 24 24",fill:"none",children:[r.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),r.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("work:task.toolCount",{count:he.toolCount})}),st&&r.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:st}),r.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${ee?"rotate-180":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:r.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"})})]})]}),ee&&r.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[je&&r.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:i("work:task.loadingRound",{n:he.round})}),oe&&r.jsx(ha,{entries:oe.map(qe=>Wi(qe)),comments:ye,agents:s,isExecuting:ne&&k}),ne&&k&&b&&r.jsx(Ki,{content:b}),ne&&k&&!b&&!je&&r.jsx(Ui,{})]})]},he.round)}),T.length>0&&r.jsx("div",{className:"flex flex-col gap-1.5 mt-2",children:T.map(re=>{const he=I.get(re.id)??[];return r.jsxs("div",{className:"px-3 py-2 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>tn.navigate(nt.TEAM,{agentId:re.id,profileTab:"mind"}),children:[r.jsxs("div",{className:"flex items-center gap-2.5",children:[r.jsxs("div",{className:"relative shrink-0",children:[r.jsx(La,{name:re.name,avatarUrl:re.avatarUrl,size:24,bgClass:"bg-brand-500/15 text-brand-600"}),r.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"})]}),r.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[r.jsx("span",{className:"text-xs font-medium text-fg-secondary truncate",children:re.name}),he.length===0&&r.jsxs("span",{className:"flex items-center gap-0.5",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("work:task.agentProcessing")})]}),r.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),he.length>0&&r.jsx("div",{className:"ml-9 mt-1",children:r.jsx(fi,{entries:he})})]},re.id)})})]}),Ke]})}const jc=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 to(e){return e==null?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Mb({filePath:e,onClose:t,onOpenExternal:n}){const{t:s}=Ve(["work","common"]),[o,a]=p.useState([e]),i=o[o.length-1],[l,c]=p.useState(null),[d,h]=p.useState(null),[u,f]=p.useState(!0),[m,g]=p.useState(!1);p.useEffect(()=>{f(!0),h(null),c(null),se.files.preview(i).then(C=>c(C)).catch(C=>h(String(C))).finally(()=>f(!1))},[i]);const b=C=>a(R=>[...R,C]),v=()=>a(C=>C.length>1?C.slice(0,-1):C),k=o.length>1,y=C=>{se.files.reveal(C).catch(()=>{})},x=()=>{navigator.clipboard?.writeText(i).then(()=>{g(!0),setTimeout(()=>g(!1),1500)}).catch(()=>{})},w=C=>{C.isDirectory||jc.has(C.ext)?b(C.path):y(C.path)},S=i.split("/").pop()??i,j=l?.type==="directory",E=(C,R)=>{if(R)return"📁";const P=[".md",".markdown"],T=[".png",".jpg",".jpeg",".gif",".webp",".svg"];return P.includes(C)?"📝":T.includes(C)?"🖼":[".json",".yaml",".yml",".toml",".xml"].includes(C)?"⚙":[".js",".ts",".jsx",".tsx",".py",".sh"].includes(C)?"💻":"📄"};return r.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",onClick:t,children:r.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:C=>C.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-default shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[k&&r.jsx("button",{onClick:v,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:s("common:back"),children:r.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"15 18 9 12 15 6"})})}),j?r.jsx("svg",{className:"w-4 h-4 text-amber-500 shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:r.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"})}):r.jsxs("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[r.jsx("path",{d:"M3 1h7l4 4v10H3V1zm7 1H4v12h10V5.5L10 2z"}),r.jsx("path",{d:"M10 1v4h4",fill:"none",stroke:"currentColor",strokeWidth:"1"})]}),r.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:S}),j&&l.entries&&r.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",l.entries.length,")"]})]}),r.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-3",children:[r.jsx("button",{onClick:x,className:"text-fg-tertiary hover:text-fg-primary px-2 py-1.5 rounded hover:bg-surface-elevated/60 transition-colors text-xs",title:s("common:copyPath",{defaultValue:"复制路径"}),children:m?`${s("common:copied",{defaultValue:"已复制"})} ✓`:s("common:copyPath",{defaultValue:"复制路径"})}),r.jsx("button",{onClick:()=>n?n():y(i),className:"text-fg-tertiary hover:text-fg-primary p-1.5 rounded hover:bg-surface-elevated/60 transition-colors",title:s(n?"work:task.openInDeliverables":"work:task.openInFinder"),children:r.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:[r.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"}),r.jsx("polyline",{points:"15 3 21 3 21 9"}),r.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}),r.jsx("button",{onClick:t,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0",children:"×"})]})]}),r.jsx("div",{className:"px-4 py-1 border-b border-border-default/60",children:r.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:i})}),r.jsxs("div",{className:"flex-1 overflow-auto min-h-0",children:[u&&r.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:s("work:task.filePreviewLoading")}),d&&r.jsx("div",{className:"text-sm text-red-500 text-center py-8",children:d}),l?.type==="directory"&&l.entries&&r.jsxs("div",{className:"divide-y divide-border-default/50",children:[l.entries.length===0&&r.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:s("work:task.emptyDirectory")}),l.entries.map(C=>r.jsxs("button",{onClick:()=>w(C),className:"w-full flex items-center gap-3 px-5 py-2.5 hover:bg-surface-elevated/40 transition-colors text-left group",children:[r.jsx("span",{className:"text-sm shrink-0",children:E(C.ext,C.isDirectory)}),r.jsx("span",{className:"flex-1 min-w-0 truncate text-sm text-fg-primary group-hover:text-brand-400 transition-colors",children:C.name}),!C.isDirectory&&C.size!=null&&r.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:to(C.size)}),C.isDirectory&&r.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:r.jsx("polyline",{points:"9 18 15 12 9 6"})}),!C.isDirectory&&!jc.has(C.ext)&&r.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:[r.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"}),r.jsx("polyline",{points:"15 3 21 3 21 9"}),r.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})]},C.path))]}),l&&l.type!=="directory"&&r.jsx("div",{className:"p-5",children:l.type==="office"&&l.streamUrl?r.jsx(Ff,{data:{format:(l.extension||"").replace(/^\./,"")||"pdf",streamUrl:l.streamUrl||(l.path?se.files.streamUrl(l.path):se.files.streamUrl(i)),name:l.name,size:l.size},reference:l.path||i,onFallback:()=>y(i)}):l.type==="image"&&l.content?r.jsx("div",{className:"flex justify-center",children:r.jsx("img",{src:`data:${l.mimeType};base64,${l.content}`,alt:l.name,className:"max-w-full max-h-[60vh] rounded-lg"})}):l.type==="audio"?r.jsxs("div",{className:"flex flex-col gap-3",children:[r.jsx("audio",{controls:!0,preload:"metadata",src:l.streamUrl||(l.path?se.files.streamUrl(l.path):se.files.streamUrl(i)),className:"w-full"}),r.jsxs("span",{className:"text-xs text-fg-tertiary",children:[l.name,l.size!=null?` · ${to(l.size)}`:""]})]}):l.type==="video"?r.jsxs("div",{className:"flex flex-col gap-3",children:[r.jsx("video",{controls:!0,preload:"metadata",src:l.streamUrl||(l.path?se.files.streamUrl(l.path):se.files.streamUrl(i)),className:"w-full max-h-[60vh] rounded-lg bg-black"}),r.jsxs("span",{className:"text-xs text-fg-tertiary",children:[l.name,l.size!=null?` · ${to(l.size)}`:""]})]}):l.type==="binary"||l.content==null?r.jsxs("div",{className:"space-y-3 text-center py-6",children:[r.jsx("p",{className:"text-sm text-fg-secondary",children:s("work:task.cannotPreviewFile",{defaultValue:"This file type cannot be previewed."})}),r.jsxs("p",{className:"text-xs text-fg-tertiary font-mono",children:[l.name,l.extension?` (${l.extension})`:"",l.size!=null?` · ${to(l.size)}`:""]}),r.jsx("button",{onClick:()=>y(i),className:"px-3 py-2 text-xs rounded-lg bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors",children:s("work:task.openInFinder")})]}):r.jsx(Zf,{content:l.content,format:l.type==="text"?"text":l.type,className:"text-sm text-fg-secondary leading-relaxed",copyVariant:"preview"})})]})]})})}function Nc({task:e,agents:t,projects:n,requirements:s,allTasks:o,users:a,onClose:i,onRefresh:l,authUser:c,scrollToComments:d,onScrollToCommentsDone:h,onReqClick:u,onProjectClick:f}){const{t:m}=Ve(["work","common"]),g=p.useMemo(()=>Ju(m),[m]),[b,v]=p.useState([]),[k,y]=p.useState(""),[x,w]=p.useState(!1),[S,j]=p.useState(!1),[E,C]=p.useState(null),[R,P]=p.useState(null),[T,D]=p.useState(!1),[z,I]=p.useState(!1),[B,L]=p.useState(!1),[q,_]=p.useState(null),[A,$]=p.useState(!1),[F,V]=p.useState(!1),[X,O]=p.useState("details"),M=p.useRef(null),[K,W]=p.useState("none"),[H,Z]=p.useState(1),[J,le]=p.useState([]),ue=p.useCallback(async()=>{try{const{results:U}=await se.deliverables.search({taskId:e.id,limit:200});le(U.filter(fe=>fe.status!=="outdated"))}catch{}},[e.id]),pe=p.useCallback(U=>{O(U),U==="deliverables"&&ue(),requestAnimationFrame(()=>{M.current?.scrollTo({top:0,behavior:"instant"})})},[ue]),we=p.useMemo(()=>[{id:"details"},{id:"activity"},{id:"deliverables"},{id:"history"}],[]),Ne=$f(we,X,pe),[ke,Be]=p.useState([]);p.useEffect(()=>{let U=!0;return se.tasks.getHistory(e.id).then(fe=>{U&&Be(mh(fe.history,{reviewerId:e.reviewerId,reviewerName:t.find(Le=>Le.id===e.reviewerId)?.name}))}).catch(()=>{U&&Be([])}),()=>{U=!1}},[e.id,e.status,e.reviewerId,t]),p.useEffect(()=>{const U=M.current;if(!U)return;const fe=()=>{const{scrollTop:$e,scrollHeight:He,clientHeight:Rt}=U;if(!(He>Rt+50)){W("none");return}const ss=$e<30,_n=$e+Rt>=He-30;W(ss?"top":_n?"bottom":"middle")};fe(),U.addEventListener("scroll",fe,{passive:!0});const Le=new ResizeObserver(fe);return Le.observe(U),()=>{U.removeEventListener("scroll",fe),Le.disconnect()}},[X]),p.useEffect(()=>{if(!d)return;O("details");const U=setTimeout(()=>{const fe=M.current;fe&&fe.scrollTo({top:fe.scrollHeight,behavior:"smooth"}),h?.()},300);return()=>clearTimeout(U)},[d,h]);const[et,Ee]=p.useState(null),[Ke,ot]=p.useState(!1),[_e,re]=p.useState(null),[he,ge]=p.useState(!1),[ee,ne]=p.useState(e.description),oe=p.useRef(null),je=p.useRef(null),ye=p.useRef(80);p.useEffect(()=>{if(he&&je.current){const U=je.current;U.style.height="auto",U.style.height=Math.max(U.scrollHeight,ye.current)+"px",U.focus()}},[he]);const[Se,Te]=p.useState(!1),[st,qe]=p.useState("");p.useEffect(()=>{ue()},[ue,e.updatedAt]),p.useEffect(()=>{const U=["created","updated","removed"].map(fe=>Dt.on(`deliverable:${fe}`,Le=>{const $e=Le.payload;!$e||$e.taskId!==e.id||ue()}));return()=>{U.forEach(fe=>fe())}},[e.id,ue]);const[te,Re]=p.useState(!1),Ue=gr(),mt=20,Qe=p.useCallback(async()=>{try{const U=await se.tasks.listSubtasks(e.id);v(U.subtasks)}catch{}},[e.id]);p.useEffect(()=>{Qe()},[Qe,e.updatedAt]);const Ae=async U=>{if(!A){$(!0);try{await U(),l(),await Qe()}catch(fe){Ee(String(fe).replace("Error: ",""))}finally{$(!1)}}},Pe=U=>Ae(()=>se.tasks.update(e.id,{priority:U})),Ge=U=>Ae(()=>se.tasks.assign(e.id,U||null)),at=U=>Ae(()=>se.tasks.update(e.id,{projectId:U||null})),G=async()=>{if(!A){$(!0);try{await se.tasks.pause(e.id),l()}finally{$(!1)}}},ie=U=>{if(U instanceof Mc){if(U.code==="TASK_BLOCKED"){const fe=U.data?.dependencyTitles??[];return fe.length?m("work:task.errorBlockedDeps",{deps:fe.join("、")}):m("work:task.errorBlocked")}if(U.code==="TASK_NOT_BLOCKED")return m("work:task.errorNotBlocked");if(U.code==="TASK_NOT_RETRYABLE")return m("work:task.errorNotRetryable")}return String(U).replace("Error: API error: 400","Server error").replace("Error: ","")},be=async()=>{if(!A){$(!0),Ee(null),pe("activity");try{await se.tasks.resume(e.id),l()}catch(U){Ee(ie(U))}finally{$(!1)}}},de=async()=>{k.trim()&&(await se.tasks.createSubtask(e.id,k.trim()),y(""),w(!1),Qe(),l())},xe=async U=>{U.status==="completed"||U.status==="cancelled"?await se.tasks.cancelSubtask(e.id,U.id):await se.tasks.completeSubtask(e.id,U.id),Qe(),l()},Ce=async U=>{await se.tasks.deleteSubtask(e.id,U.id),C(null),Qe(),l()},ze=async()=>{if(!A){$(!0),Ee(null);try{await se.tasks.updateStatus(e.id,"in_progress"),l()}catch(U){Ee(ie(U))}finally{$(!1)}}},vt=async()=>{if(!A){$(!0),Ee(null),pe("activity");try{await se.tasks.retry(e.id),l()}catch(U){Ee(ie(U))}finally{$(!1)}}},Yt=async()=>{if(!A){$(!0),Ee(null),pe("activity");try{await se.tasks.runNow(e.id),l()}catch(U){Ee(ie(U)),l()}finally{$(!1)}}},jt=p.useRef(l);jt.current=l,p.useEffect(()=>Dt.on("task:update",fe=>{fe.payload.taskId===e.id&&(Qe(),ue(),jt.current())}),[e.id,Qe,ue]);const Fe=b.filter(U=>U.status==="completed").length,dt=b.filter(U=>U.status==="cancelled").length,It=Fe+dt,_t=e.status==="in_progress",kn=e.status==="blocked",yt=kn&&Aa(e,U=>o.find(fe=>fe.id===U)),Xe=e.status==="completed",tt=e.status==="failed",Ze=e.status==="rejected",ut=e.status==="cancelled",Ht=e.status==="archived",Nt=lr(e.status),St=e.taskType==="scheduled"&&!!e.scheduleConfig,Tt=St&&!!e.scheduleConfig?.paused,Ot=(()=>{const U=n.find(fe=>fe.id===e.projectId);return U&&U.name!=="default"?U:void 0})(),Gt=s.find(U=>U.id===e.requirementId);return t.find(U=>U.id===e.assignedAgentId),r.jsxs("div",{className:`flex flex-col w-full overflow-hidden bg-surface-primary shadow-xl shadow-black/8 ring-1 ring-border-default/20 ${Ue?"h-dvh":"h-full"}`,children:[r.jsxs("div",{className:"flex items-start justify-between gap-4 px-6 pt-5 pb-3 border-b border-border-default shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[Ue&&r.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"15 18 9 12 15 6"})})}),r.jsxs("h3",{className:"flex-1 min-w-0 text-base font-semibold leading-snug text-fg-primary",children:[e.title," ",(()=>{if(e.status==="blocked"){const fe=Pf(e.status,m,Bf(e));return r.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle ${fe.tone?.chip??"bg-gray-500/15 text-fg-tertiary"}`,children:fe.label})}const U=g[e.status];return U?r.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle ${U.cls}`,children:U.label}):r.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:qf(e.status,m)})})(),yt&&r.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:m("work:task.abnormalBlock")})]})]}),r.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[r.jsx(Lc,{onClick:()=>V(!0),label:m("work:task.sendToChat",{defaultValue:"发送到对话"})}),r.jsx("button",{onClick:i,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0 mt-1",children:"×"})]})]}),F&&r.jsx(Zu,{kind:"task",entity:e,agents:t,users:a,projects:n,onClose:()=>V(!1)}),r.jsxs("div",{className:"flex gap-1 px-6 pt-2 pb-0 shrink-0",children:[r.jsx("button",{onClick:()=>pe("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${X==="details"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:m("work:task.detailsTab")}),r.jsxs("button",{onClick:()=>pe("activity"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${X==="activity"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:[m("work:task.activityTab"),(_t||gh(ke))&&r.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),r.jsx("button",{onClick:()=>pe("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${X==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:(()=>{const U=J.filter(fe=>typeof fe.reference=="string"&&fe.reference.length>0).length;return U>0?m("work:task.deliverablesCount",{count:U}):m("work:task.deliverables")})()}),r.jsx("button",{onClick:()=>pe("history"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${X==="history"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:m("work:task.historyTab")})]}),r.jsxs("div",{className:"flex-1 min-h-0 relative",children:[r.jsxs("div",{ref:M,"data-swipe-owner":!0,className:"h-full overflow-y-auto overflow-x-hidden",onTouchStart:Ne.onTouchStart,onTouchEnd:Ne.onTouchEnd,children:[r.jsxs("div",{className:X==="activity"?"min-w-0 min-h-full":"hidden",children:[et&&r.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:[r.jsx("span",{className:"font-medium",children:m("work:task.failedToStart")})," ",et]}),r.jsx(Tb,{task:e,isRunning:e.status==="in_progress",authUser:c,agents:t,reviewSessions:ke})]}),r.jsxs("div",{className:X==="details"?"":"hidden",children:[r.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:he?r.jsx("textarea",{ref:je,value:ee,onChange:U=>{ne(U.target.value);const fe=U.target;fe.style.height="auto",fe.style.height=fe.scrollHeight+"px"},onBlur:()=>{ee!==e.description&&Ae(()=>se.tasks.update(e.id,{description:ee})),ge(!1)},onKeyDown:U=>{U.key==="Escape"&&(U.preventDefault(),ne(e.description),ge(!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:m("work:task.addDescription")}):r.jsx("div",{ref:oe,className:"group relative cursor-pointer rounded-lg -mx-2 px-2 -my-1 py-1 hover:bg-surface-elevated/50 transition-colors",onClick:U=>{U.target.closest("a, button, [data-entity-link]")||(ye.current=Math.max(oe.current?.offsetHeight??80,60),ne(e.description),ge(!0))},role:"button",tabIndex:0,onKeyDown:U=>U.key==="Enter"&&(ne(e.description),ge(!0)),children:e.description?r.jsxs("div",{children:[r.jsx("div",{className:Ue&&!te?"line-clamp-3":"",children:r.jsx(ar,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),Ue&&e.description.length>150&&r.jsx("button",{onClick:U=>{U.stopPropagation(),Re(!te)},className:"text-[11px] text-brand-500 mt-1 font-medium",children:m(te?"work:task.collapse":"common:showMore")})]}):r.jsx("p",{className:"text-sm text-fg-tertiary italic",children:m("work:task.noDescription")})})}),(Ot||Gt)&&r.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[Ot&&r.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(Ot.id):void 0,role:f?"button":void 0,tabIndex:f?0:void 0,onKeyDown:f?U=>U.key==="Enter"&&f(Ot.id):void 0,children:[r.jsx("span",{className:"text-[9px] text-brand-500/60",children:m("work:task.projectLabel")}),Ot.name]}),Gt&&r.jsxs("span",{className:`flex items-center gap-1 text-[11px] px-2 py-0.5 bg-brand-500/10 text-brand-500 rounded-full ${u?"cursor-pointer hover:bg-brand-500/20 transition-colors":""}`,onClick:u?()=>u(Gt):void 0,role:u?"button":void 0,tabIndex:u?0:void 0,onKeyDown:u?U=>U.key==="Enter"&&u(Gt):void 0,children:[r.jsx("span",{className:"text-[9px] text-brand-500/60",children:m("work:task.requirementLabel")}),Gt.title.length>40?Gt.title.slice(0,40)+"…":Gt.title]})]}),r.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default",children:[r.jsx("div",{className:"flex items-center justify-between mb-1.5",children:r.jsx("span",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:m("work:task.dependencies")})}),e.blockedBy&&e.blockedBy.length>0?r.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:e.blockedBy.map(U=>{const fe=o.find($e=>$e.id===U),Le=fe&&(fe.status==="completed"||fe.status==="cancelled");return r.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${Le?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[r.jsx("span",{className:"text-[9px]",children:Le?"✓":"⏳"}),r.jsx("span",{className:`font-mono ${Le?"line-through opacity-60":""}`,children:fe?fe.title.slice(0,30):U.slice(-8)}),!Nt&&r.jsx("button",{onClick:async()=>{const $e=(e.blockedBy??[]).filter(He=>He!==U);await se.tasks.update(e.id,{blockedBy:$e}),l()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:m("work:task.removeDependency"),children:"×"})]},U)})}):r.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:m("work:task.noDependencies")}),yt&&r.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:[r.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:[r.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"}),r.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),r.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),r.jsx("span",{children:m("work:task.abnormalBlockHint")})]}),!Nt&&r.jsx(bb,{options:o.filter(U=>U.id!==e.id&&!(e.blockedBy??[]).includes(U.id)).map(U=>({value:U.id,label:U.title,status:U.status})),placeholder:m("work:task.addDependency"),noMatchesText:m("work:task.noMatches"),itemSuffix:U=>U.status==="completed"||U.status==="archived"?r.jsx("span",{className:"text-[9px] text-green-600 shrink-0",children:"✓"}):U.status==="cancelled"?r.jsx("span",{className:"text-[9px] text-fg-tertiary shrink-0",children:"✕"}):null,onSelect:async U=>{if(!U)return;const fe=[...e.blockedBy??[],U];await se.tasks.update(e.id,{blockedBy:fe}),l()}})]}),r.jsx("div",{className:"px-6 py-4 border-b border-border-default/60",children:r.jsxs("div",{className:ou,children:[r.jsx("label",{className:lt,children:m("work:task.projectLabel")}),r.jsx(Ft,{size:"sm",disabled:A,options:[{value:"",label:m("work:task.noProject")},...n.map(U=>({value:U.id,label:U.name}))],value:e.projectId??"",onChange:U=>{at(U)},placeholder:m("work:task.noProject"),noMatchesText:m("work:task.noMatches")}),r.jsx("label",{className:lt,children:m("work:task.requirementLabel")}),r.jsx(Ft,{size:"sm",disabled:A,options:[{value:"",label:m("work:task.noRequirement")},...s.filter(U=>!e.projectId||U.projectId===e.projectId).map(U=>({value:U.id,label:U.title}))],value:e.requirementId??"",onChange:U=>Ae(()=>se.tasks.update(e.id,{requirementId:U||null})),placeholder:m("work:task.noRequirement"),noMatchesText:m("work:task.noMatches")}),r.jsx("label",{className:lt,children:m("work:task.assignee")}),r.jsx(Ft,{size:"sm",disabled:A,options:[{value:"",label:m("work:task.unassigned")},...t.map(U=>({value:U.id,label:`${U.name} (${U.status})`}))],value:e.assignedAgentId??"",onChange:U=>{Ge(U)},placeholder:m("work:task.unassigned"),noMatchesText:m("work:task.noMatches")}),r.jsx("label",{className:lt,children:m("work:task.reviewer")}),r.jsx(Ft,{size:"sm",disabled:A,options:[...a.map(U=>({value:`human:${U.id}`,label:U.name})),...t.map(U=>({value:`agent:${U.id}`,label:`${U.name} (${U.status})`}))],value:`${e.reviewerType??"agent"}:${e.reviewerId??""}`,onChange:U=>{if(!U)return;const fe=U.startsWith("human:"),Le=U.replace(/^(human|agent):/,"");(Le!==e.reviewerId||(fe?"human":"agent")!==(e.reviewerType??"agent"))&&Ae(()=>se.tasks.update(e.id,{reviewerId:Le,reviewerType:fe?"human":"agent"}))},placeholder:m("work:task.selectReviewer"),noMatchesText:m("work:task.noMatches")}),r.jsx("label",{className:lt,children:m("work:task.priority")}),r.jsx(wo,{value:e.priority,onChange:U=>{Pe(U)}})]})}),r.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&&r.jsx("span",{children:m("work:task.createdBy",{name:$s(e.createdBy,t,a)??e.createdBy})}),e.updatedBy&&r.jsx("span",{children:m("work:task.updatedBy",{name:$s(e.updatedBy,t,a)??e.updatedBy})}),e.createdAt&&r.jsx("span",{children:new Date(e.createdAt).toLocaleDateString()}),e.startedAt&&r.jsx("span",{children:m("work:task.started",{date:new Date(e.startedAt).toLocaleDateString()})}),e.updatedAt&&r.jsx("span",{children:m("work:task.updatedMeta",{date:new Date(e.updatedAt).toLocaleDateString()})}),e.projectId&&r.jsxs("span",{className:"font-mono text-blue-600/70",children:["task/",e.id]}),(e.executionRound??1)>1&&r.jsx("span",{className:"text-amber-600",children:m("work:task.executionRound",{n:e.executionRound})})]}),r.jsxs("div",{className:"px-6 py-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsxs("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:[m("work:task.subtasks")," ",b.length>0&&r.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal normal-case",children:[m("work:task.subtasksProgress",{done:Fe,total:b.length-dt}),dt>0?` · ${dt} cancelled`:""]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[It>0&&r.jsx("button",{onClick:()=>j(U=>!U),className:`text-[10px] px-2 py-0.5 rounded-full border transition-colors ${S?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-tertiary border-border-default hover:text-fg-secondary"}`,children:S?m("work:task.hideCompleted"):m("work:task.showCompleted",{count:It})}),r.jsx("button",{onClick:()=>w(!0),className:"text-xs text-brand-500 hover:text-brand-500 transition-colors",children:m("work:task.addSubtask")})]})]}),(()=>{const U=S?b:b.filter(fe=>fe.status!=="completed"&&fe.status!=="cancelled");return U.length>0?r.jsx("div",{className:"space-y-1.5 mb-3",children:U.map(fe=>r.jsxs("div",{className:`group flex items-center gap-2.5 py-1.5 px-2 rounded-lg hover:bg-surface-elevated/50 transition-colors ${fe.status==="cancelled"?"opacity-50":""}`,children:[r.jsxs("button",{onClick:()=>{xe(fe)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${fe.status==="completed"?"bg-green-600 border-green-600 text-white":fe.status==="cancelled"?"bg-gray-500 border-gray-500 text-white":"border-gray-600 hover:border-brand-500"}`,children:[fe.status==="completed"&&r.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 12 12",fill:"none",children:r.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),fe.status==="cancelled"&&r.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 12 12",fill:"none",children:r.jsx("path",{d:"M3 3l6 6M9 3l-6 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})]}),r.jsx("span",{className:`flex-1 text-sm ${fe.status==="completed"?"line-through text-fg-tertiary":fe.status==="cancelled"?"line-through text-fg-muted":"text-fg-secondary"}`,children:fe.title}),r.jsx("button",{onClick:()=>C(fe),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},fe.id))}):null})(),b.length===0&&!x&&r.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:m("work:task.noSubtasksYet")}),x&&r.jsxs("div",{className:"flex gap-2 mt-2",children:[r.jsx("input",{autoFocus:!0,value:k,onChange:U=>y(U.target.value),onKeyDown:U=>{U.key==="Enter"&&de(),U.key==="Escape"&&(w(!1),y(""))},placeholder:m("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"}),r.jsx("button",{onClick:()=>{de()},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-on-brand text-xs rounded-lg",children:m("work:task.add")}),r.jsx("button",{onClick:()=>{w(!1),y("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:m("common:cancel")})]}),(()=>{const U=J.filter($e=>typeof $e.reference=="string"&&$e.reference.length>0);if(U.length===0)return null;const fe={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"},Le=U.slice(0,3);return r.jsxs("div",{className:"mt-5",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:m("work:task.deliverablesCount",{count:U.length})}),U.length>3&&r.jsx("button",{onClick:()=>pe("deliverables"),className:"text-[10px] text-brand-500 hover:text-brand-500",children:m("work:task.viewAll")})]}),r.jsx("div",{className:"space-y-1.5",children:Le.map($e=>{const He=/^https?:\/\//i.test($e.reference),Rt=He?$e.summary||$e.reference:$e.reference.split("/").pop()??$e.reference;return r.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:[r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${fe[$e.type]??"bg-gray-500/15 text-fg-secondary"}`,children:$e.type}),r.jsxs("div",{className:"flex-1 min-w-0",children:[He?r.jsxs("a",{href:$e.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:$e.reference,children:[Rt," ",r.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:[r.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"}),r.jsx("path",{d:"M7 2h3v3"}),r.jsx("path",{d:"M5 7 10 2"})]})]}):r.jsx("button",{onClick:()=>re($e.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:$e.reference,children:Rt}),$e.summary&&!He&&r.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:$e.summary}),r.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:$e.reference})]})]},$e.id)})})]})})(),r.jsx(Ib,{task:e,agents:t,users:a,authUser:c})]})]}),r.jsx("div",{className:X==="history"?"":"hidden",children:r.jsx(sf,{entityType:"task",entityId:e.id})}),r.jsx("div",{className:X==="deliverables"?"px-6 py-4":"hidden",children:(()=>{const U=J.filter(He=>typeof He.reference=="string"&&He.reference.length>0);if(U.length===0)return r.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:m("work:task.noDeliverablesYet")});const fe={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"},Le=Math.ceil(U.length/mt),$e=U.slice((H-1)*mt,H*mt);return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:m("work:task.deliverablesCount",{count:U.length})}),Le>1&&r.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[r.jsx("button",{disabled:H<=1,onClick:()=>Z(He=>He-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),r.jsxs("span",{children:[H,"/",Le]}),r.jsx("button",{disabled:H>=Le,onClick:()=>Z(He=>He+1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"›"})]})]}),r.jsx("div",{className:"space-y-1.5",children:$e.map(He=>{const Rt=/^https?:\/\//i.test(He.reference),dn=Rt?He.summary||He.reference:He.reference.split("/").pop()??He.reference;return r.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:[r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${fe[He.type]??"bg-gray-500/15 text-fg-secondary"}`,children:He.type}),r.jsxs("div",{className:"flex-1 min-w-0",children:[Rt?r.jsxs("a",{href:He.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:He.reference,children:[dn," ",r.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:[r.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"}),r.jsx("path",{d:"M7 2h3v3"}),r.jsx("path",{d:"M5 7 10 2"})]})]}):r.jsx("button",{onClick:()=>re(He.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:He.reference,children:dn}),He.summary&&!Rt&&r.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:He.summary}),r.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:He.reference})]})]},He.id)})})]})})()})]}),K!=="none"&&K!=="top"&&r.jsx("button",{onClick:()=>M.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-on-brand hover:bg-brand-400 transition-colors backdrop-blur-sm",title:m("work:task.scrollToTop"),children:r.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:r.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"})})}),K!=="none"&&K!=="bottom"&&r.jsx("button",{onClick:()=>{const U=M.current;U&&U.scrollTo({top:U.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-on-brand hover:bg-brand-400 transition-colors backdrop-blur-sm",title:m("work:task.scrollToBottom"),children:r.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:r.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"})})})]}),St&&e.scheduleConfig&&r.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${Tt?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"} ${!_t&&!B&&!e.scheduleConfig.runAt?"cursor-pointer hover:border-brand-500/40 transition-colors":""}`,onClick:()=>{_t||B||e.scheduleConfig?.runAt||(_(Eh(e.scheduleConfig)),L(!0))},children:[r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.jsx("span",{className:Tt?"text-amber-600":"text-brand-500",children:Tt?m("work:task.schedulePaused"):r.jsxs(r.Fragment,{children:[r.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:r.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"})})," ",m("work:task.scheduled")]})}),r.jsx("span",{className:"text-fg-tertiary",children:"·"}),r.jsx("span",{className:"text-fg-secondary",children:e.scheduleConfig.every?m("work:task.scheduleEvery",{interval:e.scheduleConfig.every}):e.scheduleConfig.cron?m("work:task.scheduleCron",{expr:e.scheduleConfig.cron}):e.scheduleConfig.runAt?m("work:task.scheduleOneShot"):m("work:task.scheduleNA")}),!Tt&&e.scheduleConfig.nextRunAt&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"text-fg-tertiary",children:"·"}),r.jsx("span",{className:"text-fg-secondary",children:m("work:task.scheduleNext",{when:(()=>{const U=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(U<=0)return m("work:task.scheduleDueNow");const fe=Math.floor(U/6e4);if(fe<60)return m("work:task.scheduleInMinutes",{count:fe});const Le=Math.floor(fe/60);return Le<24?m("work:task.scheduleInHoursMinutes",{h:Le,m:fe%60}):m("work:task.scheduleInDaysHours",{d:Math.floor(Le/24),h:Le%24})})()})})]}),!_t&&!B&&!e.scheduleConfig.runAt&&r.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:[r.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),r.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})]}),B&&q?r.jsxs("div",{className:"mt-2 pt-2 border-t border-border-default/50 space-y-2",onClick:U=>U.stopPropagation(),children:[r.jsx(Uc,{value:q,onChange:_,compact:!0}),r.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[r.jsx("button",{onClick:async()=>{await Ae(()=>se.tasks.updateSchedule(e.id,Kc(q))),L(!1)},disabled:A,className:"px-3 py-1 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-on-brand disabled:opacity-50",children:m("common:save")}),r.jsx("button",{onClick:()=>L(!1),className:"px-3 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:m("common:cancel")})]})]}):r.jsxs("div",{className:"flex items-center gap-2 mt-1 text-fg-tertiary",children:[r.jsx("span",{children:m("work:task.scheduleRuns",{current:e.scheduleConfig.currentRuns??0,max:e.scheduleConfig.maxRuns&&e.scheduleConfig.maxRuns>0?m("work:task.scheduleRunsMax",{max:e.scheduleConfig.maxRuns}):""})}),e.scheduleConfig.lastRunAt&&r.jsxs(r.Fragment,{children:[r.jsx("span",{children:"·"}),r.jsx("span",{children:m("work:task.scheduleLast",{when:(()=>{const U=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),fe=Math.floor(U/6e4);if(fe<1)return m("work:task.noteTimeJustNow");if(fe<60)return m("work:task.noteTimeMinutes",{count:fe});const Le=Math.floor(fe/60);return Le<24?m("work:task.noteTimeHours",{count:Le}):m("work:task.noteTimeDays",{count:Math.floor(Le/24)})})()})})]})]})]}),e.status==="review"&&Xi(ke)&&r.jsxs("div",{className:"mx-6 mt-3 flex items-start gap-2.5 rounded-lg border border-purple-500/30 bg-purple-500/8 px-3 py-2",children:[r.jsx("span",{className:"mt-1 w-1.5 h-1.5 shrink-0 rounded-full bg-purple-400 animate-pulse"}),r.jsx("div",{className:"min-w-0 flex-1 text-xs text-fg-primary",children:m("work:task.reviewInProgressBy",{agent:Xi(ke).reviewerName})}),r.jsx("button",{onClick:()=>pe("activity"),className:"shrink-0 rounded-md border border-purple-500/30 px-2 py-1 text-[11px] font-medium text-purple-400 hover:bg-purple-500/10 transition-colors",children:m("work:task.reviewViewSession")})]}),r.jsx("div",{className:"px-6 py-4 border-t border-border-default flex items-center justify-between gap-2",children:r.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.status==="pending"&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{if(St){ot(!0);return}Ae(()=>se.tasks.approve(e.id))},disabled:A,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_")?m("work:task.startExecution"):m("work:task.approve")}),e.createdBy&&!e.createdBy.startsWith("agt_")?r.jsx("button",{onClick:async()=>{const{count:U}=await se.tasks.getDependentCount(e.id);P({dependentCount:U})},disabled:A,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:m("work:task.cancelTask")}):r.jsx("button",{onClick:()=>D(!0),disabled:A,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:m("work:task.reject")})]}),e.status==="review"&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{Ae(()=>se.tasks.accept(e.id,c?.id))},disabled:A,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:m("work:task.approveCheck")}),Se?r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("input",{type:"text",value:st,onChange:U=>qe(U.target.value),onKeyDown:U=>{U.key==="Enter"&&st.trim()&&(Ae(()=>se.tasks.revision(e.id,st.trim(),c?.id)),Te(!1),qe(""))},placeholder:m("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"}),r.jsx("button",{onClick:()=>{Ae(()=>se.tasks.revision(e.id,st.trim()||m("work:task.revisionsNeededDefault"),c?.id)),Te(!1),qe("")},disabled:A,className:"px-2.5 py-1 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:m("common:send")}),r.jsx("button",{onClick:()=>{Te(!1),qe("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):r.jsx("button",{onClick:()=>Te(!0),disabled:A,className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 rounded-lg text-white disabled:opacity-50",children:m("work:task.requestRevision")})]}),_t&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>{G()},disabled:A,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:[r.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:[r.jsx("rect",{x:"2",y:"1.5",width:"3",height:"9",rx:"0.5"}),r.jsx("rect",{x:"7",y:"1.5",width:"3",height:"9",rx:"0.5"})]}),m("work:task.pause")]}),r.jsxs("button",{onClick:()=>{vt()},disabled:A,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:[r.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[r.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),r.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),m("work:task.retry")]})]}),kn&&r.jsx("button",{onClick:()=>{be()},disabled:A,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:A?r.jsx(r.Fragment,{children:m("work:task.resuming")}):r.jsxs(r.Fragment,{children:[r.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:r.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),m("work:task.resume")]})}),tt&&!St&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>{vt()},disabled:A,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:[r.jsxs("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[r.jsx("path",{d:"M1.5 6a4.5 4.5 0 1 1 1.3 3.2",strokeLinecap:"round"}),r.jsx("path",{d:"M1 3.5V6h2.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),m("work:task.retry")]}),r.jsxs("button",{onClick:()=>{ze()},disabled:A,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:[r.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:r.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),m("work:task.continueTask")]})]}),St&&(Xe||tt||ut)&&!Ht&&r.jsx("button",{onClick:()=>{Yt()},disabled:A,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-on-brand disabled:opacity-50 flex items-center gap-1.5",children:A?r.jsx(r.Fragment,{children:m("work:task.running")}):r.jsxs(r.Fragment,{children:[r.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 12 12",fill:"currentColor",children:r.jsx("path",{d:"M3 1.5v9l7-4.5-7-4.5z"})}),m("work:task.runNow")]})}),St&&!_t&&!Ht&&!Ze&&(Tt?r.jsx("button",{onClick:()=>{Ae(()=>se.tasks.resumeSchedule(e.id))},disabled:A,className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 rounded-lg text-white disabled:opacity-50",children:m("work:task.resumeSchedule")}):r.jsx("button",{onClick:()=>{Ae(()=>se.tasks.pauseSchedule(e.id))},disabled:A,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:m("work:task.pauseSchedule")})),(Xe||tt||Ze||ut)&&r.jsx("button",{onClick:()=>I(!0),disabled:A,className:"px-3 py-1.5 text-xs bg-gray-600 hover:bg-gray-500 rounded-lg text-white disabled:opacity-50",children:m("work:task.archive")}),Xe&&!St&&r.jsx("button",{onClick:()=>{ze()},disabled:A,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:m("work:task.reopen")}),!Nt&&e.status!=="pending"&&r.jsx("button",{onClick:async()=>{const{count:U}=await se.tasks.getDependentCount(e.id);P({dependentCount:U})},disabled:A,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:m("work:task.cancelTask")})]})}),E&&r.jsx(ys,{title:m("work:task.deleteSubtaskTitle",{title:E.title}),message:m("work:task.deleteSubtaskMessage"),confirmLabel:m("common:delete"),onConfirm:()=>{Ce(E)},onCancel:()=>C(null)}),T&&r.jsx(ys,{title:m("work:task.rejectConfirmTitle"),message:m("work:task.rejectConfirmMessage"),confirmLabel:m("work:task.reject"),onConfirm:()=>{D(!1),Ae(()=>se.tasks.reject(e.id))},onCancel:()=>D(!1)}),z&&r.jsx(ys,{title:m("work:task.archiveConfirmTitle"),message:m(St?"work:task.archiveScheduledConfirmMessage":"work:task.archiveConfirmMessage"),confirmLabel:m("work:task.archive"),onConfirm:()=>{I(!1),Ae(()=>se.tasks.archive(e.id))},onCancel:()=>I(!1)}),R&&R.dependentCount>0?r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>P(null),children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 max-w-md w-full shadow-2xl",onClick:U=>U.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-2",children:m("work:task.cancelTaskModalTitle")}),r.jsxs("p",{className:"text-sm text-fg-secondary mb-4",children:[St&&r.jsx(r.Fragment,{children:r.jsx("span",{className:"block mb-1 text-amber-600",children:m("work:task.cancelScheduledConfirmMessage")})}),m("work:task.cancelTaskDependent",{count:R.dependentCount})]}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsxs("button",{onClick:()=>{P(null),Ae(()=>se.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:[r.jsx("span",{className:"font-medium",children:m("work:task.cancelTaskOnly")}),r.jsx("span",{className:"block text-xs text-fg-tertiary mt-0.5",children:m("work:task.cancelTaskOnlyHint")})]}),r.jsxs("button",{onClick:()=>{P(null),Ae(()=>se.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:[r.jsx("span",{className:"font-medium",children:m("work:task.cancelWithDependents")}),r.jsx("span",{className:"block text-xs text-red-500/70 mt-0.5",children:m("work:task.cancelWithDependentsHint",{count:R.dependentCount})})]}),r.jsx("button",{onClick:()=>P(null),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:m("work:task.keepTaskRunning")})]})]})}):R&&r.jsx(ys,{title:m("work:task.cancelTaskModalTitle"),message:m(St?"work:task.cancelScheduledConfirmMessage":"work:task.cancelConfirmMessage"),confirmLabel:m("work:task.cancelTask"),onConfirm:()=>{P(null),Ae(()=>se.tasks.cancel(e.id))},onCancel:()=>P(null)}),_e&&r.jsx(Mb,{filePath:_e,onClose:()=>re(null),onOpenExternal:()=>{re(null),se.deliverables.search({taskId:e.id,limit:100}).then(({results:U})=>{const fe=U.find(Le=>Le.reference===_e);fe?tn.navigate(nt.DELIVERABLES,{openDeliverable:fe.id}):tn.navigate(nt.DELIVERABLES)}).catch(()=>tn.navigate(nt.DELIVERABLES))}}),Ke&&e.scheduleConfig&&r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>ot(!1),children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[380px] shadow-2xl",onClick:U=>U.stopPropagation(),children:[r.jsx("h3",{className:"font-semibold text-base mb-2",children:m("work:task.scheduleApproveTitle")}),r.jsx("p",{className:"text-sm text-fg-secondary mb-5 leading-relaxed",children:m("work:task.scheduleApproveDesc",{schedule:e.scheduleConfig.cron?`Cron: ${e.scheduleConfig.cron}`:e.scheduleConfig.every?m("work:task.scheduleEvery",{interval:e.scheduleConfig.every}):"",nextRun:e.scheduleConfig.nextRunAt?new Date(e.scheduleConfig.nextRunAt).toLocaleString():m("work:task.scheduleNA")})}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsx("button",{disabled:A,onClick:()=>{ot(!1),Ae(()=>se.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:m("work:task.scheduleApproveRunNow")}),r.jsx("button",{disabled:A,onClick:()=>{ot(!1),Ae(()=>se.tasks.approve(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-brand-600 hover:bg-brand-500 text-on-brand rounded-lg font-medium transition-colors disabled:opacity-50",children:m("work:task.scheduleApproveWait")}),r.jsx("button",{onClick:()=>ot(!1),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:m("common:cancel")})]})]})})]})}function Ab({project:e,tasks:t,requirements:n,agents:s,onDeleteProject:o,onUpdateProject:a,onRefresh:i}){const l=p.useMemo(()=>t.filter(T=>T.projectId===e.id),[t,e.id]),c=p.useMemo(()=>n.filter(T=>T.projectId===e.id),[n,e.id]),d=p.useMemo(()=>{const T={total:l.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:c.length,reqsDone:0};for(const D of l)D.status==="completed"||D.status==="accepted"?T.completed++:D.status==="in_progress"?T.inProgress++:D.status==="review"||D.status==="revision"?T.inReview++:D.status==="blocked"?T.blocked++:D.status==="failed"?T.failed++:T.pending++;for(const D of c)D.status==="completed"&&T.reqsDone++;return T},[l,c]),h=p.useMemo(()=>new Set(l.map(T=>T.assignedAgentId).filter(Boolean)),[l]),u=p.useMemo(()=>s.filter(T=>h.has(T.id)),[s,h]),[f,m]=p.useState(!1),[g,b]=p.useState(""),[v,k]=p.useState("main"),[y,x]=p.useState(!1),[w,S]=p.useState(!1),{t:j}=Ve(["work","common"]),E=[{value:"active",label:j("work:project.statusActive"),desc:j("work:project.statusActiveDesc")},{value:"paused",label:j("work:project.statusPaused"),desc:j("work:project.statusPausedDesc")},{value:"archived",label:j("work:project.statusArchived"),desc:j("work:project.statusArchivedDesc")}],C=async T=>{if(T!==e.status){x(!0);try{await a({status:T}),i()}finally{x(!1)}}},R=async()=>{const T=g.trim();if(!T)return;const D=[...e.repositories??[],{url:"",localPath:T,defaultBranch:v||"main"}];await a({repositories:D}),b(""),k("main"),m(!1),i()},P=async T=>{const D=(e.repositories??[]).filter((z,I)=>I!==T);await a({repositories:D}),i()};return r.jsxs("div",{className:"p-5 space-y-5 max-w-3xl",children:[r.jsxs("div",{className:"space-y-3",children:[r.jsx(wb,{value:e.description??"",onSave:async T=>{await a({description:T}),i()},className:"text-sm text-fg-secondary",placeholder:j("work:project.descriptionPlaceholderLong")}),r.jsxs("div",{className:"flex items-center gap-3 text-xs text-fg-tertiary",children:[e.createdAt&&r.jsxs("span",{children:[j("work:project.createdLabel")," ",new Date(e.createdAt).toLocaleDateString()]}),e.updatedAt&&r.jsxs("span",{children:[j("work:project.updatedLabel")," ",new Date(e.updatedAt).toLocaleDateString()]})]})]}),r.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[r.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:j("work:project.projectStatusHeading")}),r.jsx("div",{className:"flex gap-2",children:E.map(T=>r.jsxs("button",{disabled:y,onClick:()=>C(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:[r.jsx("div",{children:T.label}),r.jsx("div",{className:"text-[10px] opacity-70 mt-0.5",children:T.desc})]},T.value))})]}),r.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[r.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:j("work:project.taskOverview")}),r.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-3",children:[r.jsx(gn,{label:j("work:project.statTotal"),value:d.total,color:"text-fg-primary"}),r.jsx(gn,{label:j("work:project.statCompleted"),value:d.completed,color:"text-green-600"}),r.jsx(gn,{label:j("work:project.statInProgress"),value:d.inProgress,color:"text-brand-500"}),r.jsx(gn,{label:j("work:project.statInReview"),value:d.inReview,color:"text-brand-500"}),r.jsx(gn,{label:j("work:project.statBlocked"),value:d.blocked,color:"text-amber-600"}),r.jsx(gn,{label:j("work:project.statFailed"),value:d.failed,color:"text-red-500"})]}),d.total>0&&r.jsxs("div",{className:"mt-3 flex h-2 rounded-full overflow-hidden bg-surface-elevated",children:[d.completed>0&&r.jsx("div",{className:"bg-green-500",style:{width:`${d.completed/d.total*100}%`}}),d.inProgress>0&&r.jsx("div",{className:"bg-brand-500",style:{width:`${d.inProgress/d.total*100}%`}}),d.inReview>0&&r.jsx("div",{className:"bg-brand-500",style:{width:`${d.inReview/d.total*100}%`}}),d.blocked>0&&r.jsx("div",{className:"bg-amber-500",style:{width:`${d.blocked/d.total*100}%`}}),d.pending>0&&r.jsx("div",{className:"bg-blue-500/40",style:{width:`${d.pending/d.total*100}%`}}),d.failed>0&&r.jsx("div",{className:"bg-red-500",style:{width:`${d.failed/d.total*100}%`}})]})]}),r.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[r.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:j("work:project.requirementsHeading")}),r.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[r.jsx(gn,{label:j("work:project.statTotal"),value:d.reqs,color:"text-fg-primary"}),r.jsx(gn,{label:j("work:project.statCompleted"),value:d.reqsDone,color:"text-green-600"}),r.jsx(gn,{label:j("work:project.statActive"),value:d.reqs-d.reqsDone,color:"text-brand-500"})]})]}),u.length>0&&r.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[r.jsx("h4",{className:"text-xs font-semibold text-fg-secondary mb-3",children:j("work:project.agentsHeading",{count:u.length})}),r.jsx("div",{className:"flex flex-wrap gap-2",children:u.map(T=>{const D=l.filter(I=>I.assignedAgentId===T.id),z=D.filter(I=>!lr(I.status));return r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-surface-elevated/60 rounded-lg",children:[r.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"}`}),r.jsx("span",{className:"text-xs text-fg-secondary",children:T.name}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:j("work:project.agentTaskCounts",{active:z.length,total:D.length})})]},T.id)})})]}),r.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsx("h4",{className:"text-xs font-semibold text-fg-secondary",children:j("work:project.repositories")}),r.jsx("button",{onClick:()=>m(!f),className:"text-[10px] text-brand-500 hover:text-brand-500",children:j(f?"common:cancel":"work:project.addRepo")})]}),(e.repositories??[]).length===0&&!f&&r.jsx("p",{className:"text-xs text-fg-tertiary",children:j("work:project.noReposLinked")}),(e.repositories??[]).map((T,D)=>r.jsxs("div",{className:"flex items-center gap-2 py-1.5 group",children:[r.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:[r.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"}),r.jsx("path",{d:"M9 18c-4.51 2-5-2-7-2"})]}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 min-w-0 truncate",children:T.url||T.localPath}),r.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:T.defaultBranch}),r.jsx("button",{onClick:()=>P(D),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:j("work:project.removeRepo"),children:r.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},D)),f&&r.jsxs("div",{className:"mt-2 space-y-2 p-3 bg-surface-elevated rounded-lg border border-border-default",children:[r.jsx("input",{value:g,onChange:T=>b(T.target.value),placeholder:j("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"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{value:v,onChange:T=>k(T.target.value),placeholder:j("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"}),r.jsx("button",{onClick:R,disabled:!g.trim(),className:"px-3 py-1.5 text-xs bg-brand-600 text-on-brand rounded-md hover:bg-brand-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:j("work:task.add")})]})]})]}),r.jsx(Fx,{project:e,onUpdateProject:a}),r.jsxs("div",{className:"border border-red-500/20 rounded-xl p-4",children:[r.jsx("h4",{className:"text-xs font-semibold text-red-500/80 mb-2",children:j("work:project.dangerZone")}),r.jsx("p",{className:"text-[11px] text-fg-tertiary mb-3",children:j("work:project.dangerZoneDeleteHint")}),r.jsx("button",{onClick:()=>S(!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:j("work:project.deleteProject")})]}),w&&r.jsx(ys,{title:j("work:project.deleteProjectConfirmTitle"),message:j("work:project.deleteProjectConfirmBody",{name:e.name,tasks:d.total,reqs:d.reqs}),confirmLabel:j("work:project.deleteProject"),onConfirm:()=>{S(!1),o()},onCancel:()=>S(!1)})]})}function gn({label:e,value:t,color:n}){return r.jsxs("div",{className:"text-center py-2",children:[r.jsx("div",{className:`text-xl font-bold ${n}`,children:t}),r.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:e})]})}const uo={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed",archived:"closed"},tf={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},Lb={urgent:0,high:1,medium:2,low:3},vo={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},Sc={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"},_b={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"};function nf(e){for(const t of ko)if(t.statuses.includes(e))return t.id;return"closed"}function Cc(e,t){const n=Date.now()-new Date(e).getTime(),s=Math.floor(n/6e4);if(s<1)return t("work:relative.justNow");if(s<60)return t("work:relative.minutesAgo",{count:s});const o=Math.floor(s/60);if(o<24)return t("work:relative.hoursAgo",{count:o});const a=Math.floor(o/24);return t("work:relative.daysAgo",{count:a})}function no({value:e,options:t,onSelect:n,allowedValues:s}){const[o,a]=p.useState(!1),i=p.useRef(null),l=p.useRef(null),c=t.find(d=>d.value===e);return p.useEffect(()=>{if(!o)return;const d=h=>{l.current&&!l.current.contains(h.target)&&i.current&&!i.current.contains(h.target)&&a(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[o]),r.jsxs("div",{className:"relative",children:[r.jsx("button",{ref:i,onClick:()=>a(d=>!d),className:`text-[11px] px-2 py-0.5 rounded-full font-medium transition-colors cursor-pointer hover:ring-1 hover:ring-current/30 ${c?.cls??"bg-gray-500/15 text-fg-tertiary"}`,children:c?.label??e}),o&&r.jsx("div",{ref:l,className:"absolute top-full left-0 mt-1 w-40 bg-surface-overlay border border-border-default rounded-lg shadow-xl z-50 py-1 max-h-64 overflow-y-auto",children:t.map(d=>{const h=d.value===e,u=h||!s||s.has(d.value);return r.jsxs("button",{disabled:!u,onClick:()=>{!h&&u&&n(d.value),a(!1)},className:`w-full text-left px-3 py-1.5 text-[11px] flex items-center gap-2 transition-colors ${h?"bg-surface-elevated":u?"hover:bg-surface-elevated/60":"opacity-35 cursor-not-allowed"}`,children:[r.jsx("span",{className:`inline-block w-2 h-2 rounded-full shrink-0 ${u?d.cls.split(" ")[0]:"bg-gray-600"}`}),r.jsx("span",{className:`font-medium ${h?"text-fg-primary":u?"text-fg-secondary":"text-fg-muted"}`,children:d.label}),h&&r.jsx("svg",{className:"w-3 h-3 ml-auto text-brand-500",viewBox:"0 0 12 12",fill:"none",children:r.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]},d.value)})})]})}function Rb({onQuickCreateReq:e,onQuickCreateTask:t}){const{t:n}=Ve(["work","common"]),[s,o]=p.useState("req"),[a,i]=p.useState(!1),[l,c]=p.useState(""),d=p.useRef(null),h=p.useRef(null);p.useEffect(()=>{a&&(d.current?.focus({preventScroll:!0}),h.current?.scrollIntoView({block:"nearest",inline:"start"}))},[a]);const u=()=>{const f=l.trim();c(""),i(!1),f&&(s==="req"?e(f):t(f))};return r.jsxs("div",{ref:h,className:"flex items-center gap-2 px-3 md:px-6 py-2.5 md:py-2 border-l-2 border-l-transparent hover:bg-surface-elevated/30 transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx("button",{type:"button",onMouseDown:f=>f.preventDefault(),onClick:()=>o("req"),className:`text-[9px] px-1.5 py-0.5 rounded font-semibold transition-colors ${s==="req"?"bg-amber-500/20 text-amber-600":"bg-surface-elevated text-fg-tertiary hover:text-fg-secondary"}`,children:n("work:task.requirementShort")}),r.jsx("button",{type:"button",onMouseDown:f=>f.preventDefault(),onClick:()=>o("task"),className:`text-[9px] px-1.5 py-0.5 rounded font-semibold transition-colors ${s==="task"?"bg-brand-500/20 text-brand-600":"bg-surface-elevated text-fg-tertiary hover:text-fg-secondary"}`,children:n("work:task.taskShort")})]}),a?r.jsx("input",{ref:d,value:l,onChange:f=>c(f.target.value),onKeyDown:f=>{f.key==="Enter"?u():f.key==="Escape"&&(c(""),i(!1))},onBlur:u,placeholder:n("work:task.quickAddPlaceholder"),className:"flex-1 min-w-0 bg-transparent border-none outline-none text-base md:text-xs text-fg-primary placeholder:text-fg-tertiary"}):r.jsxs("button",{type:"button",onClick:()=>i(!0),className:"flex-1 min-w-0 text-left text-base md:text-xs text-fg-tertiary hover:text-fg-secondary truncate",children:["+ ",n("work:task.quickAddHint")]})]})}function Ec({row:e,idx:t,dragIdx:n,agentMap:s,projMap:o,onTaskClick:a,onReqClick:i,onRowDragStart:l,onRowDragEnd:c,handleStatusChange:d,handlePriorityChange:h,selected:u,isMobile:f,isAbnormalBlocked:m}){const{t:g}=Ve(["work","common"]),b=p.useMemo(()=>Ju(g),[g]),v=p.useMemo(()=>mi(g),[g]),k=p.useMemo(()=>Cb(g),[g]),y=e.data.status,x=e.data.priority,w=e.kind==="task"?s.get(e.data.assignedAgentId??""):void 0,S=(()=>{const E=o.get((e.kind==="task",e.data.projectId??""));return E&&E.name!=="default"?E:void 0})(),j=e.kind==="req"?r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-amber-500/15 text-amber-600",children:g("work:task.requirementShort")}):e.data.taskType==="scheduled"?r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-blue-500/15 text-blue-600",children:g("work:task.schedShort")}):r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-gray-500/15 text-fg-secondary",children:g("work:task.taskShort")});return f?r.jsxs("div",{"data-work-item-id":e.data.id,onClick:()=>e.kind==="task"?a(e.data):i(e.data),className:`px-3 py-2 border-b border-border-default/40 cursor-pointer transition-colors border-l-2 ${Sc[e.group]??"border-l-gray-700"} ${u?"bg-brand-500/25 border-l-brand-500 ring-1 ring-inset ring-brand-500/35":"active:bg-surface-elevated/50"}`,children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[j,m&&r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500",children:"⚠"}),r.jsx("span",{className:"text-sm text-fg-primary truncate flex-1",children:e.data.title})]}),r.jsxs("div",{className:"flex items-center gap-2 mt-1.5 flex-wrap",children:[r.jsx("div",{onClick:E=>E.stopPropagation(),children:r.jsx(no,{value:y,options:e.kind==="task"?wc.map(E=>({value:E,label:b[E]?.label??E,cls:b[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})):kc.map(E=>({value:E,label:v[E]?.label??E,cls:v[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?cc[y]:Ta[y],onSelect:E=>{d(e,E)}})}),r.jsx("div",{onClick:E=>E.stopPropagation(),children:r.jsx(no,{value:x,options:yc.map(E=>({value:E,label:k[E]?.label??E,cls:k[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:E=>{h(e,E)}})}),w&&r.jsxs("span",{className:"flex items-center gap-1 text-[10px]",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Qn[w.status]??"bg-gray-500"}`}),r.jsx("span",{className:`${vc[w.status]??"text-fg-secondary"}`,children:w.name})]}),S?.name&&r.jsx("span",{className:"text-[10px] text-brand-400/70 truncate max-w-[80px]",children:S.name}),r.jsx("span",{className:"text-[9px] text-fg-muted ml-auto",children:Cc(e.data.updatedAt??"",g)})]})]}):r.jsxs("div",{"data-work-item-id":e.data.id,draggable:!0,onDragStart:E=>l(E,t),onDragEnd:c,onClick:()=>e.kind==="task"?a(e.data):i(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 ${Sc[e.group]??"border-l-gray-700"} ${n===t?"opacity-40":""} ${u?"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:[r.jsx("div",{className:"w-12 shrink-0",children:j}),r.jsxs("div",{className:"flex-1 min-w-[200px] text-sm text-fg-primary truncate flex items-center gap-1.5",children:[r.jsx("span",{className:"truncate",children:e.data.title}),m&&r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded font-semibold bg-red-500/15 text-red-500 shrink-0",children:"⚠"})]}),r.jsx("div",{className:"w-[130px] shrink-0",onClick:E=>E.stopPropagation(),children:r.jsx(no,{value:y,options:e.kind==="task"?wc.map(E=>({value:E,label:b[E]?.label??E,cls:b[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})):kc.map(E=>({value:E,label:v[E]?.label??E,cls:v[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?cc[y]:Ta[y],onSelect:E=>{d(e,E)}})}),r.jsx("div",{className:"w-[100px] shrink-0",onClick:E=>E.stopPropagation(),children:r.jsx(no,{value:x,options:yc.map(E=>({value:E,label:k[E]?.label??E,cls:k[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:E=>{h(e,E)}})}),r.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:w?r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Qn[w.status]??"bg-gray-500"}`}),r.jsx("span",{className:`font-medium ${vc[w.status]??"text-fg-secondary"}`,children:w.name})]}):r.jsx("span",{className:"text-fg-muted",children:"—"})}),r.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:S?.name?r.jsx("span",{className:"text-brand-400/70",children:S.name}):r.jsx("span",{className:"text-fg-muted",children:"—"})}),r.jsx("div",{className:"w-[90px] shrink-0 text-[10px] text-fg-muted text-right",children:Cc(e.data.updatedAt??"",g)})]})}function Db({tasks:e,requirements:t,agents:n,projects:s,onTaskClick:o,onReqClick:a,onRefresh:i,selectedTaskId:l,selectedReqId:c,onQuickCreateReq:d,onQuickCreateTask:h}){const{t:u}=Ve(["work","common"]),f=gr(),[m,g]=p.useState("status"),[b,v]=p.useState(null),[k,y]=p.useState(null),x=p.useMemo(()=>{const A=new Map;for(const $ of e)A.set($.id,$);return A},[e]),w=p.useCallback(A=>A.status!=="blocked"?!1:Aa(A,$=>x.get($)),[x]),S=p.useMemo(()=>{const A=[];for(const $ of e){const F=nf($.status);A.push({kind:"task",data:$,group:F,groupOrder:vo[F]??5})}for(const $ of t){const F=uo[$.status]??"todo";A.push({kind:"req",data:$,group:F,groupOrder:vo[F]??5})}if(m==="status")A.sort(($,F)=>{if($.groupOrder!==F.groupOrder)return $.groupOrder-F.groupOrder;const V=new Date($.data.updatedAt??0).getTime();return new Date(F.data.updatedAt??0).getTime()-V});else{const $=F=>Lb[F.data.priority]??2;A.sort((F,V)=>{const X=$(F),O=$(V);return X!==O?X-O:new Date(V.data.updatedAt??0).getTime()-new Date(F.data.updatedAt??0).getTime()})}return A},[e,t,m]),j=async(A,$)=>{try{A.kind==="task"?await se.tasks.updateStatus(A.data.id,$):await se.requirements.updateStatus(A.data.id,$),i()}catch{}},E=async(A,$)=>{try{A.kind==="task"?await se.tasks.update(A.data.id,{priority:$}):await se.requirements.update(A.data.id,{priority:$}),i()}catch{}},C=(A,$)=>{v($),A.dataTransfer.effectAllowed="move",A.dataTransfer.setData("text/plain",String($)),A.currentTarget.style.opacity="0.4"},R=A=>{A.currentTarget.style.opacity="1",v(null),y(null)},P=(A,$)=>{A.preventDefault(),A.dataTransfer.dropEffect="move",k!==$&&y($)},T=async(A,$)=>{if(A.preventDefault(),y(null),b==null)return;const F=S[b];if(!F||F.group===$)return;const V=ko.find(X=>X.id===$);if(V){try{if(F.kind==="task"){if(F.data.status==="pending")return;await se.tasks.updateStatus(F.data.id,V.dropStatus)}else{const X=tf[$];X&&await se.requirements.updateStatus(F.data.id,X)}i()}catch{}v(null)}},D=p.useMemo(()=>new Map(n.map(A=>[A.id,A])),[n]),z=p.useMemo(()=>new Map(s.map(A=>[A.id,A])),[s]),I=["todo","in_progress","review","done"],B=p.useMemo(()=>{const A={};for(const $ of S)A[$.group]=(A[$.group]??0)+1;return A},[S]),{rowsByGroup:L,rowIndexMap:q}=p.useMemo(()=>{const A=new Map,$=new Map;for(let F=0;F<S.length;F++){const V=S[F];$.set(V,F);const X=A.get(V.group)??[];X.push(V),A.set(V.group,X)}return{rowsByGroup:A,rowIndexMap:$}},[S]),_=p.useMemo(()=>{if(m!=="status")return null;const A=new Set(S.map(V=>V.group)),$=[],F=new Set;A.has("failed")&&($.push("failed"),F.add("failed"));for(const V of I)$.push(V),F.add(V);for(const V of S)F.has(V.group)||($.push(V.group),F.add(V.group));return $},[S,m]);return r.jsx("div",{className:`flex-1 min-h-0 overflow-auto bg-surface-primary ${f?"overflow-x-hidden w-full":""}`,children:r.jsxs("div",{className:f?"w-full":"w-fit min-w-full",children:[!f&&r.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:[r.jsx("div",{className:"w-12 shrink-0 text-fg-muted normal-case font-normal",children:S.length}),r.jsx("div",{className:"flex-1 min-w-[200px]",children:u("work:task.backlogTitle")}),r.jsxs("button",{onClick:()=>g("status"),className:`w-[130px] shrink-0 text-left flex items-center gap-1 transition-colors ${m==="status"?"text-brand-500":"hover:text-fg-secondary"}`,children:[u("work:filters.status")," ",m==="status"&&r.jsx("span",{className:"text-[8px]",children:"▼"})]}),r.jsxs("button",{onClick:()=>g("priority"),className:`w-[100px] shrink-0 text-left flex items-center gap-1 transition-colors ${m==="priority"?"text-brand-500":"hover:text-fg-secondary"}`,children:[u("work:filters.priority")," ",m==="priority"&&r.jsx("span",{className:"text-[8px]",children:"▼"})]}),r.jsx("div",{className:"w-[120px] shrink-0",children:u("work:filters.assignee")}),r.jsx("div",{className:"w-[120px] shrink-0",children:u("work:task.projectLabel")}),r.jsx("div",{className:"w-[90px] shrink-0 text-right",children:u("work:task.backlogUpdated")})]}),r.jsxs("div",{children:[m==="status"&&_?_.map(A=>{const $=L.get(A)??[];return r.jsxs("div",{children:[r.jsxs("div",{className:`flex items-center gap-2 px-6 py-2 border-l-2 bg-surface-primary/80 sticky top-0 z-10 ${_b[A]??""} ${k===A?"ring-1 ring-brand-500/40":""}`,onDragOver:F=>P(F,A),onDragLeave:()=>y(null),onDrop:F=>{T(F,A)},children:[r.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:u(`work:boardColumn.${A}`)}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:B[A]??0})]}),$.map(F=>r.jsx(Ec,{row:F,idx:q.get(F)??0,dragIdx:b,agentMap:D,projMap:z,onTaskClick:o,onReqClick:a,onRowDragStart:C,onRowDragEnd:R,handleStatusChange:j,handlePriorityChange:E,selected:F.kind==="task"?F.data.id===l:F.data.id===c,isMobile:f,isAbnormalBlocked:F.kind==="task"?w(F.data):!1},`${F.kind}-${F.data.id}`)),A==="todo"&&r.jsx(Rb,{onQuickCreateReq:d,onQuickCreateTask:h})]},A)}):S.map((A,$)=>r.jsx(Ec,{row:A,idx:$,dragIdx:b,agentMap:D,projMap:z,onTaskClick:o,onReqClick:a,onRowDragStart:C,onRowDragEnd:R,handleStatusChange:j,handlePriorityChange:E,selected:A.kind==="task"?A.data.id===l:A.data.id===c,isMobile:f,isAbnormalBlocked:A.kind==="task"?w(A.data):!1},`${A.kind}-${A.data.id}`)),S.length===0&&r.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-3 max-w-sm mx-auto text-center",children:[r.jsx("svg",{className:"w-10 h-10 text-fg-muted",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.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"})}),r.jsx("p",{className:"text-sm font-medium text-fg-secondary",children:u("work:task.backlogEmptyTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:u("work:task.backlogEmptyDesc")})]})]})]})})}function Ma(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,60)||"workflow"}function Ob(e,t){const n=new Map,s=new Map(e.map(l=>[l.id,l])),o=new Set;for(const l of e){let c=Ma(l.title).replace(/[^a-z0-9-]/g,"").slice(0,30)||"step";o.has(c)&&(c=`${c}-${l.id.slice(-4)}`),o.add(c),n.set(l.id,c)}const a=new Map,i=new Set;for(const l of e){const c=l.assignedAgentId;if(c&&!a.has(c)){const d=t[c]??"worker";let h=Ma(d).replace(/[^a-z0-9-]/g,"")||"worker";i.has(h)&&(h=`${h}-${c.slice(-4)}`),i.add(h),a.set(c,h)}}return e.map(l=>({id:n.get(l.id),name:l.title,role:a.get(l.assignedAgentId)??"worker",prompt:l.description||l.title,depends_on:(l.blockedBy??[]).filter(c=>s.has(c)).map(c=>n.get(c)).filter(Boolean)}))}function so(e){return/[:#\[\]{}&*!|>'"%@`\n]/.test(e)||e.startsWith(" ")||e.endsWith(" ")?JSON.stringify(e):e}function $b(e,t,n){const s=[];s.push(`name: ${so(e)}`),s.push(`description: ${so(t.replace(/\n/g," ").slice(0,200))}`),s.push('version: "1.0.0"'),s.push(""),s.push("steps:");for(const o of n){if(s.push(` - id: ${o.id}`),s.push(` name: ${so(o.name)}`),s.push(" type: agent_task"),s.push(` role: ${so(o.role)}`),o.depends_on.length>0&&s.push(` depends_on: [${o.depends_on.join(", ")}]`),o.depends_on.length>0){s.push(" inputs:");for(const a of o.depends_on)s.push(` - from: ${a}`),s.push(` as: ${a}_output`)}s.push(" prompt: |");for(const a of o.prompt.split(`
|
|
139
|
-
`))s.push(` ${a}`);s.push("")}return s.join(`
|
|
140
|
-
`)}function Pb({req:e,tasks:t,agents:n,teamId:s,onClose:o,onSaved:a}){const{t:i}=Ve(["work"]),l=p.useMemo(()=>{const R={};for(const P of n)R[P.id]=P.name;return R},[n]),c=p.useMemo(()=>Ob(t,l),[t,l]),[d,h]=p.useState(()=>Ma(e.title)),[u,f]=p.useState(e.description||e.title),[m,g]=p.useState(c),[b,v]=p.useState(!1),[k,y]=p.useState(null),x=(R,P,T)=>{g(D=>D.map((z,I)=>I===R?{...z,[P]:T}:z))},w=R=>{const P=m[R]?.id;g(T=>T.filter((D,z)=>z!==R).map(D=>({...D,depends_on:D.depends_on.filter(z=>z!==P)})))},[S,j]=p.useState(!1),E=async()=>{if(d.trim()){v(!0),y(null);try{const R=$b(d.trim(),u,m);await se.workflows.create(s,d.trim(),R),j(!0),setTimeout(()=>a(),800)}catch(R){y(String(R))}v(!1)}},C=p.useMemo(()=>[...new Set(m.map(R=>R.role))],[m]);return r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",onClick:o,children:r.jsxs("div",{className:"bg-surface-primary border border-border-default rounded-2xl shadow-2xl w-full max-w-[640px] mx-4 max-h-[85vh] flex flex-col",onClick:R=>R.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-6 py-4 border-b border-border-default",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-base font-semibold text-fg-primary",children:i("work:task.saveAsWorkflow","Save as Workflow")}),r.jsx("p",{className:"text-xs text-fg-tertiary mt-0.5",children:i("work:task.saveAsWorkflowDesc","Turn this task structure into a reusable workflow template")})]}),r.jsx("button",{onClick:o,className:"text-fg-tertiary hover:text-fg-secondary p-1 rounded-lg hover:bg-surface-elevated transition-colors",children:r.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),r.jsxs("div",{className:"flex-1 overflow-auto px-4 sm:px-6 py-4 space-y-4",children:[r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:i("work:task.workflowName","Name")}),r.jsx("input",{value:d,onChange:R=>h(R.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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:i("work:task.roles","Roles")}),r.jsx("div",{className:"flex flex-wrap gap-1 py-2",children:C.map(R=>r.jsx("span",{className:"px-2 py-0.5 text-[10px] font-medium bg-brand-500/10 text-brand-500 rounded-full",children:R},R))})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:i("work:task.description","Description")}),r.jsx("input",{value:u,onChange:R=>f(R.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"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:[i("work:task.workflowSteps","Steps")," (",m.length,")"]}),r.jsx("div",{className:"space-y-2",children:m.map((R,P)=>r.jsx("div",{className:"bg-surface-secondary border border-border-default/40 rounded-xl p-3 group",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.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:P+1}),r.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{value:R.name,onChange:T=>x(P,"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"}),r.jsx("input",{value:R.role,onChange:T=>x(P,"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:i("work:task.role","Role")})]}),R.depends_on.length>0&&r.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[r.jsxs("span",{children:[i("work:task.dependsOn","Depends on"),":"]}),R.depends_on.map(T=>{const D=m.find(z=>z.id===T);return r.jsx("span",{className:"px-1.5 py-0.5 bg-surface-elevated rounded text-fg-secondary",children:D?.name??T},T)})]}),r.jsx("div",{className:"text-xs text-fg-tertiary line-clamp-2 leading-relaxed",children:R.prompt})]}),r.jsx("button",{onClick:()=>w(P),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-muted hover:text-red-500 p-1 rounded transition-all",title:i("work:task.removeStep","Remove step"),children:r.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})},R.id))})]}),k&&r.jsx("p",{className:"text-xs text-red-500",children:k}),S&&r.jsx("p",{className:"text-xs text-green-500 font-medium",children:i("work:task.workflowSavedSuccess","Workflow saved successfully")})]}),r.jsxs("div",{className:"flex items-center justify-end gap-2 px-6 py-4 border-t border-border-default",children:[r.jsx("button",{onClick:o,className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary hover:bg-surface-elevated rounded-lg transition-colors",children:i("work:task.cancel","Cancel")}),r.jsx("button",{onClick:E,disabled:b||S||!d.trim()||m.length===0,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 disabled:cursor-not-allowed text-on-brand text-sm rounded-lg font-medium transition-colors",children:b?i("work:task.saving","Saving..."):S?i("work:task.workflowSavedSuccess","Saved!"):i("work:task.saveWorkflow","Save Workflow")})]})]})})}function Ic({teamId:e,agents:t,compact:n}){const{t:s}=Ve(["work"]),o=p.useMemo(()=>e?t.find(i=>i.teamId===e&&i.agentRole==="manager"):t.find(i=>i.agentRole==="manager"),[t,e]),a=()=>{o&&tn.navigate(nt.TEAM,{agentId:o.id,prefillMessage:s("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 r.jsxs("div",{className:`min-w-0 ${n?"max-w-4xl space-y-3":"max-w-lg w-full text-center space-y-5"}`,children:[!n&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-brand-500/10",children:r.jsx("svg",{className:"w-8 h-8 text-brand-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.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"})})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-1.5",children:s("work:task.workflowEmptyTitle","No workflow templates yet")}),r.jsx("p",{className:"text-sm text-fg-secondary leading-relaxed",children:s("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.")})]})]}),r.jsxs("details",{className:n?"group":"",open:!n,children:[r.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 ${n?"py-1":"sr-only"}`,children:[r.jsx("svg",{className:"w-3 h-3 transition-transform group-open:rotate-90",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),s("work:task.workflowHowItWorks","How it works")]}),r.jsxs("div",{className:`bg-surface-secondary border border-border-default/40 rounded-xl p-4 text-left space-y-3 ${n?"mt-2":""}`,children:[!n&&r.jsx("p",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:s("work:task.workflowHowItWorks","How it works")}),r.jsxs("div",{className:"flex items-start gap-3",children:[r.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"}),r.jsxs("div",{className:"text-xs text-fg-secondary leading-relaxed",children:[r.jsx("span",{className:"font-medium text-fg-primary",children:s("work:task.workflowStep1Title","Requirement")})," — ",s("work:task.workflowStep1Desc","A workflow run creates a Requirement to group all its tasks under one trackable goal.")]})]}),r.jsxs("div",{className:"flex items-start gap-3",children:[r.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"}),r.jsxs("div",{className:"text-xs text-fg-secondary leading-relaxed",children:[r.jsx("span",{className:"font-medium text-fg-primary",children:s("work:task.workflowStep2Title","Task DAG")})," — ",s("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.")]})]}),r.jsxs("div",{className:"flex items-start gap-3",children:[r.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"}),r.jsxs("div",{className:"text-xs text-fg-secondary leading-relaxed",children:[r.jsx("span",{className:"font-medium text-fg-primary",children:s("work:task.workflowStep3Title","Auto-execution")})," — ",s("work:task.workflowStep3Desc","Agents pick up tasks, pass deliverables downstream, and the workflow completes automatically. Optionally, schedule it to run on a recurring basis.")]})]})]})]}),o&&r.jsx("div",{className:n?"":"text-center",children:r.jsxs("button",{onClick:a,className:"inline-flex items-center gap-2 px-4 py-2 bg-brand-600 hover:bg-brand-500 text-on-brand text-sm rounded-lg font-medium transition-colors",children:[r.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.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"})}),s("work:task.workflowAskManager","Ask {{name}} to create a workflow",{name:o.name})]})})]})}function Bb({teamId:e,defaultTeamId:t,projectId:n,agents:s,users:o,projects:a,onViewRunTasks:i}){const{t:l}=Ve(["work"]),[c,d]=p.useState([]),[h,u]=p.useState({}),[f,m]=p.useState(!1),[g,b]=p.useState(null),[v,k]=p.useState({}),[y,x]=p.useState(!1),[w,S]=p.useState(null),[j,E]=p.useState([]),[C,R]=p.useState(()=>{try{const G=localStorage.getItem(uc);if(G)return G===fc?null:G}catch{}return t??null}),[P,T]=p.useState(()=>ab(G=>{try{return localStorage.getItem(G)}catch{return null}})),[D,z]=p.useState({}),[I,B]=p.useState({}),[L,q]=p.useState({}),[_,A]=p.useState({}),[$,F]=p.useState(null),[V,X]=p.useState(null),[O,M]=p.useState(null),[K,W]=p.useState(null),[H,Z]=p.useState(null),[J,le]=p.useState(null),[ue,pe]=p.useState([]),[we,Ne]=p.useState({}),[ke,Be]=p.useState(null),[et,Ee]=p.useState({}),Ke=e??C,ot=G=>{if(G!==C){R(G),d([]),u({});try{localStorage.setItem(uc,G??fc)}catch{}}};p.useEffect(()=>{e||se.teams.list().then(({teams:G})=>{E(G.map(ie=>({id:ie.id,name:ie.name})))}).catch(()=>{})},[e]),p.useMemo(()=>{const G={};for(const ie of s)G[ie.id]=ie.name;return G},[s]);const _e=p.useCallback(async()=>{const G=Ke?[Ke]:j.map(ie=>ie.id);if(G.length!==0){m(!0);try{const ie=[],be={},de={};await Promise.all(G.map(async xe=>{try{const{workflows:Ce}=await se.workflows.list(xe);for(const ze of Ce)de[ze.name]=xe;ie.push(...Ce),await Promise.all(Ce.map(async ze=>{try{const{runs:vt}=await se.workflows.listRuns(xe,ze.name,5);be[ze.name]=vt}catch{}}))}catch{}})),d(ie),u(be),Ee(de)}catch{}m(!1)}},[Ke,j]);p.useEffect(()=>{_e()},[_e]);const re=G=>Ke??et[G],he=p.useCallback(G=>{T(G),ib(G,(ie,be)=>{try{localStorage.setItem(ie,be)}catch{}})},[]),ge=G=>{const ie=new Set(P);ie.has(G)?ie.delete(G):ie.add(G),he(ie)},ee=G=>B(ie=>({...ie,[G]:"idle"}));p.useEffect(()=>{for(const G of P){if(D[G]||I[G]==="loading"||I[G]==="error")continue;const ie=re(G);ie&&(B(be=>({...be,[G]:"loading"})),se.workflows.get(ie,G).then(({template:be,yaml:de})=>{z(xe=>({...xe,[G]:{...be,yaml:de}})),B(xe=>({...xe,[G]:"ready"}))}).catch(()=>B(be=>({...be,[G]:"error"}))))}},[P,D,I,Ke,et]);const ne=p.useRef(new Set),oe=p.useCallback(async G=>{if(!(!G.requirementId||ne.current.has(G.id))){ne.current.add(G.id),A(ie=>({...ie,[G.id]:!0}));try{const{tasks:ie}=await se.tasks.list({requirementId:G.requirementId,pageSize:200}),be=new Set(G.taskIds),de=be.size>0?ie.filter(xe=>be.has(xe.id)):ie;q(xe=>({...xe,[G.id]:de.map(Ce=>({id:Ce.id,title:Ce.title,status:Ce.status,workflowStepId:Ce.workflowStepId,workflowRunId:Ce.workflowRunId}))}))}catch{q(ie=>({...ie,[G.id]:[]}))}finally{ne.current.delete(G.id),A(ie=>({...ie,[G.id]:!1}))}}},[]);p.useEffect(()=>{for(const G of c){const ie=(h[G.name]??[])[0];ie&&L[ie.id]===void 0&&!_[ie.id]&&oe(ie)}},[c,h,L,_,oe]);const je=p.useMemo(()=>{const G=[];for(const ie of Object.values(h))for(const be of ie)li(be.status)&&G.push(be.id);return G.sort().join(",")},[h]);p.useEffect(()=>{if(!je)return;const G=window.setInterval(()=>{document.hidden||_e()},4e3);return()=>window.clearInterval(G)},[je,_e]);const ye=async(G,ie)=>{const be=D[ie.name]?.yaml;if(M({mode:G,workflow:ie,yaml:be,yamlLoading:G!=="delete"&&!be,error:null}),G==="delete"||be)return;const de=re(ie.name);if(!de){M(xe=>xe&&{...xe,yamlLoading:!1,error:l("work:task.workflowNoTeam","无法确定此工作流所属的团队")});return}try{const{template:xe,yaml:Ce}=await se.workflows.get(de,ie.name);z(ze=>({...ze,[ie.name]:{...xe,yaml:Ce}})),B(ze=>({...ze,[ie.name]:"ready"})),M(ze=>ze&&ze.workflow.name===ie.name?{...ze,yaml:Ce,yamlLoading:!1}:ze)}catch(xe){M(Ce=>Ce&&{...Ce,yamlLoading:!1,error:xe instanceof Error?xe.message:String(xe)})}},Se=async({name:G,yaml:ie})=>{if(!O)return;const be=re(O.workflow.name);if(!be){M(de=>de&&{...de,error:l("work:task.workflowNoTeam","无法确定此工作流所属的团队")});return}M(de=>de&&{...de,busy:!0,error:null});try{if(O.mode==="edit")await se.workflows.update(be,O.workflow.name,ie??"");else if(O.mode==="duplicate"){const xe=G??"",Ce=lb(ie??"",xe,rc,oc);await se.workflows.create(be,xe,Ce)}else await se.workflows.remove(be,O.workflow.name);const de=O.workflow.name;M(null),z(xe=>{const Ce={...xe};return delete Ce[de],Ce}),B(xe=>({...xe,[de]:"idle"})),qt(),await _e()}catch(de){M(xe=>xe&&{...xe,busy:!1,error:de instanceof Error?de.message:String(de)})}},Te=G=>{const ie={};for(const Ce of G.params??[])Ce.default&&(ie[Ce.name]=Ce.default);k(ie),S(null),pe([]),Ne({});const be=localStorage.getItem(`markus_wf_project_${G.name}`)??localStorage.getItem("markus_wf_project_last"),de=be&&a.some(Ce=>Ce.id===be)?be:null;Be(n??de??a[0]?.id??null),b(G);const xe=re(G.name);xe&&se.workflows.roles(xe,G.name).then(({roles:Ce})=>pe(Ce)).catch(()=>{})},st=async()=>{const G=ke??a[0]?.id,ie=g?re(g.name):void 0;if(!g||!ie||!G){S(G?l("work:task.workflowNoTeam","Cannot determine team for this workflow"):l("work:task.workflowNoProject","Please select a project"));return}x(!0),S(null);try{let be;if(ue.length>0){be={};for(const de of ue)be[de.role]=we[de.role]??de.recommended??""}await se.workflows.startRun(ie,g.name,G,v,be),localStorage.setItem(`markus_wf_project_${g.name}`,G),localStorage.setItem("markus_wf_project_last",G),b(null),_e()}catch(be){S(String(be))}x(!1)};if(!Ke&&j.length===0&&!e)return r.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:l("work:task.selectProjectForWorkflows","Select a project with a team to view workflows")});if(f&&c.length===0)return r.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:l("work:task.workflowLoading","Loading...")});const qe=async G=>{W(G),Z(null);try{await se.workflows.cancelRun(G),_e()}catch{}W(null)},te=async G=>{le(G.id);try{G.status==="running"?await se.workflows.pauseRun(G.id):G.status==="paused"&&await se.workflows.resumeRun(G.id),_e()}catch{}le(null)},Re=G=>{G.requirementId&&i&&i(G.requirementId)},Ue=g&&(g.params??[]).some(G=>G.required&&!v[G.name]?.trim()),mt=G=>{tn.navigate(nt.WORK,{openTask:G})},Qe=async(G,ie,be)=>{const de=re(G);if(!de)throw new Error(l("work:task.workflowNoTeam","无法确定此工作流所属的团队"));let xe=D[G]?.yaml;if(!xe&&(xe=(await se.workflows.get(de,G)).yaml,!xe))throw new Error(l("work:task.workflowNoYaml","模板缺少原始 YAML,无法编辑"));const Ce=rc(xe),ze=Ce?.steps?.find(jt=>jt?.id===ie);if(!Ce||!ze)throw new Error(`找不到步骤 ${ie}`);be.name!==void 0&&(ze.name=be.name),be.role!==void 0&&(ze.role=be.role),be.prompt!==void 0&&(ze.prompt=be.prompt),await se.workflows.update(de,G,oc(Ce)),qt();const{template:vt,yaml:Yt}=await se.workflows.get(de,G);z(jt=>({...jt,[G]:{...vt,yaml:Yt}})),B(jt=>({...jt,[G]:"ready"}))},Ae=G=>X(G),Pe=G=>G.displayName||G.name,Ge=G=>`@[${G.displayName||G.name}](workflow:${G.name})`,at=G=>{const ie=re(G.name),be=ie?s.find(de=>de.teamId===ie&&de.agentRole==="manager"):void 0;return _c(be?.id,s,o)};return r.jsxs("div",{className:"flex-1 min-h-0 overflow-auto px-4 py-5","data-testid":"workflows-panel",children:[!e&&j.length>0&&r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-4",children:[r.jsx("button",{onClick:()=>ot(null),className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${C===null?"bg-brand-600 text-on-brand":"bg-surface-secondary border border-border-default/50 text-fg-secondary hover:text-fg-primary hover:border-border-default"}`,children:l("work:task.all","All")}),j.map(G=>r.jsx("button",{onClick:()=>ot(G.id),className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${C===G.id?"bg-brand-600 text-on-brand":"bg-surface-secondary border border-border-default/50 text-fg-secondary hover:text-fg-primary hover:border-border-default"}`,children:G.name},G.id))]}),c.length===0&&!f?r.jsx("div",{className:"flex-1 flex items-center justify-center px-4",children:r.jsx(Ic,{teamId:Ke,agents:s})}):r.jsxs("div",{className:"grid grid-cols-1 gap-4 max-w-4xl min-w-0","data-testid":"workflows-list",children:[c.map(G=>{const ie=h[G.name]??[],be=ie[0],de=xe=>{const Ce=be?.roleMapping?.[xe];return Ce?s.find(ze=>ze.id===Ce)?.name:void 0};return r.jsx(hb,{workflow:G,detail:D[G.name],detailState:I[G.name]??"idle",onRetryDetail:()=>ee(G.name),expanded:P.has(G.name),onToggle:()=>ge(G.name),runs:ie,runTasks:L,onRun:()=>Te(G),onOpenRun:xe=>{F(xe),oe(xe)},onSaveStep:(xe,Ce)=>Qe(G.name,xe,Ce),roleAgentName:de,onSendToAgent:()=>Ae(G),onEdit:()=>{ye("edit",G)},onDuplicate:()=>{ye("duplicate",G)},onDelete:()=>{ye("delete",G)}},G.name)}),r.jsx(Ic,{teamId:Ke,agents:s,compact:!0})]}),$&&r.jsx(mb,{workflow:c.find(G=>G.name===$.workflowName)??{name:$.workflowName,displayName:$.workflowName,description:"",version:"",roles:[],hasSchedule:!1,stepCount:0},run:$,detail:D[$.workflowName],tasks:L[$.id],tasksLoading:_[$.id],onClose:()=>F(null),onPauseResume:()=>{te($)},onCancel:()=>Z($.id),onViewTasks:()=>{Re($),F(null)},pausing:J===$.id,onOpenTask:G=>{F(null),mt(G)},roleAgentName:G=>{const ie=$.roleMapping?.[G];return ie?s.find(be=>be.id===ie)?.name:void 0}}),O&&r.jsx(pb,{mode:O.mode,workflow:O.workflow,yaml:O.yaml,yamlLoading:O.yamlLoading,busy:O.busy,error:O.error,onClose:()=>M(null),onSubmit:Se}),V&&r.jsx(Ac,{chipKind:"workflow",chipLabel:Pe(V),chipContent:Ge(V),agents:s,users:o,defaultTarget:at(V),onClose:()=>X(null)}),g&&r.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50",onClick:()=>b(null),children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-full max-w-md shadow-2xl",onClick:G=>G.stopPropagation(),children:[r.jsx("h3",{className:"text-sm font-semibold text-fg-primary mb-1",children:l("work:task.workflowRunTitle","Run: {{name}}",{name:g.displayName||g.name})}),r.jsx("p",{className:"text-xs text-fg-tertiary mb-4",children:g.description}),(g.params??[]).length>0&&r.jsx("div",{className:"space-y-3 mb-4",children:(g.params??[]).map(G=>r.jsxs("div",{children:[r.jsxs("label",{className:"block text-xs text-fg-secondary mb-1",children:[G.label||G.name,G.required&&r.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),G.type==="enum"&&G.options?r.jsx(Ft,{options:[{value:"",label:"—"},...G.options.map(ie=>({value:ie,label:ie}))],value:v[G.name]??"",onChange:ie=>k(be=>({...be,[G.name]:ie})),placeholder:"—",className:"w-full"}):r.jsx("textarea",{value:v[G.name]??"",onChange:ie=>{k(xe=>({...xe,[G.name]:ie.target.value}));const be=ie.target;be.style.height="auto";const de=parseFloat(getComputedStyle(be).lineHeight)||18;be.style.height=Math.min(be.scrollHeight,de*7)+"px"},placeholder:G.default??"",rows:1,className:"input-field text-xs w-full resize-none overflow-y-auto",style:{maxHeight:`${7*1.5}em`}})]},G.name))}),ue.length>0&&r.jsxs("div",{className:"mb-4",children:[r.jsx("p",{className:"text-[10px] text-fg-tertiary font-medium mb-2 uppercase tracking-wider",children:l("work:task.roles","Roles")}),r.jsx("div",{className:"space-y-2",children:ue.map(G=>r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-xs text-fg-secondary w-24 shrink-0 font-medium",children:G.role}),r.jsx(Ft,{options:G.candidates.map(ie=>({value:ie.agentId,label:ie.agentName+(ie.agentId===G.recommended?" ★":"")})),value:we[G.role]??G.recommended??"",onChange:ie=>Ne(be=>({...be,[G.role]:ie})),className:"flex-1"})]},G.role))})]}),r.jsxs("div",{className:"mb-4",children:[r.jsx("label",{className:"block text-xs text-fg-secondary mb-1",children:l("work:task.workflowProject","Project")}),r.jsx(Ft,{options:[{value:"",label:l("work:task.workflowSelectProject","— Select a project —")},...a.map(G=>({value:G.id,label:G.name}))],value:ke??"",onChange:G=>{const ie=G||null;Be(ie),S(null),ie&&localStorage.setItem("markus_wf_project_last",ie)},placeholder:l("work:task.workflowSelectProject","— Select a project —"),className:"w-full"})]}),w&&r.jsx("p",{className:"text-xs text-red-400 mb-3",children:w}),r.jsxs("div",{className:"flex justify-end gap-2",children:[r.jsx("button",{onClick:()=>b(null),className:"btn-secondary text-xs px-4 py-1.5",children:l("work:task.workflowCancel","Cancel")}),r.jsx("button",{onClick:st,disabled:y||!!Ue,className:"btn-primary text-xs px-4 py-1.5",children:y?l("work:task.workflowStarting","Starting..."):l("work:task.workflowStartRun","Start Run")})]})]})}),H&&(()=>{const G=Object.values(h).flat().find(xe=>xe.id===H),ie=G?L[G.id]:void 0,be=G?.taskIds.length??0,de=ie?ie.filter(xe=>!lr(xe.status)).length:null;return r.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50",onClick:()=>Z(null),children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-full max-w-sm shadow-2xl",onClick:xe=>xe.stopPropagation(),children:[r.jsx("h3",{className:"text-sm font-semibold text-fg-primary mb-2",children:l("work:task.workflowConfirmCancelTitle","Cancel Workflow Run")}),r.jsx("p",{className:"text-xs text-fg-secondary mb-2",children:l("work:task.workflowConfirmCancelDesc","This will cancel all running and pending tasks in this workflow run. This action cannot be undone.")}),de!==null?r.jsx("p",{className:"text-xs font-medium text-fg-primary mb-5",children:l("work:task.workflowCancelScope","将取消 {{count}} 个未完成任务(该运行共 {{total}} 个)",{count:de,total:be})}):r.jsx("p",{className:"text-xs text-fg-tertiary mb-5",children:l("work:task.workflowCancelScopeUnknown","该运行共有 {{total}} 个任务(正在统计其中未完成的数量)",{total:be})}),r.jsxs("div",{className:"flex justify-end gap-2",children:[r.jsx("button",{onClick:()=>Z(null),className:"btn-secondary text-xs px-4 py-1.5",children:l("work:task.workflowNo","No")}),r.jsx("button",{onClick:()=>qe(H),disabled:K===H,className:"px-4 py-1.5 bg-red-600 hover:bg-red-500 text-white text-xs rounded-lg font-medium transition-colors",children:K===H?l("work:task.workflowCancelling","Cancelling..."):l("work:task.workflowConfirmCancelBtn","Confirm Cancel")})]})]})})})()]})}function Xb({authUser:e,previewMode:t,previewData:n}={}){const{t:s}=Ve(["work","common"]),o=Mf(nt.WORK),a=p.useMemo(()=>ko.map(N=>({...N,label:s(`work:boardColumn.${N.id}`)})),[s]),i=p.useMemo(()=>ef(s),[s]),l=p.useMemo(()=>mi(s),[s]),c=gr(),d=Af(),h=d?.leftCollapsed??!1,u=p.useRef(null),[f,m]=p.useState(0);p.useEffect(()=>{const N=u.current;if(!N)return;const Y=new ResizeObserver(([Q])=>m(Q.contentRect.width));return Y.observe(N),m(N.clientWidth),()=>Y.disconnect()},[]);const[g,b]=p.useState(()=>{if(t)return!1;try{return localStorage.getItem(dc)==="1"}catch{return!1}}),v=p.useCallback(N=>{b(N);try{localStorage.setItem(dc,N?"1":"0")}catch{}},[]),k=p.useRef(h);p.useEffect(()=>{t||c||k.current!==h&&(k.current=h,b(h))},[h,t,c]);const y=Lf({side:"left",defaultWidth:240,minWidth:180,maxWidth:360,storageKey:"markus_work_l1"}),x=6,w=!c&&!g?y.width+x:0,S=Math.max(0,(f||window.innerWidth)-w-x-8),j=Math.max(320,Math.round(S/2)),[E,C]=p.useState("auto"),R=Math.max(320,S-280),P=E==="auto"?Math.min(j,R):E,T=Math.max(320,Math.min(P,R)),D=p.useRef(T);D.current=T;const z=p.useRef(R);z.current=R;const I=p.useCallback(N=>{N.preventDefault();const Y=N.clientX,Q=D.current,ce=De=>{const Ie=Math.max(320,Math.min(z.current,Q+(Y-De.clientX)));C(Ie)},me=()=>{document.removeEventListener("mousemove",ce),document.removeEventListener("mouseup",me),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",ce),document.addEventListener("mouseup",me),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]),[B,L]=p.useState(!1),q=p.useRef(B);q.current=B,p.useEffect(()=>(Vi(nt.WORK,c&&B?1:0),()=>Vi(nt.WORK,0)),[c,B]);const[_,A]=p.useState(n?.projects??[]),[$,F]=p.useState("all"),[V,X]=p.useState(null),[O,M]=p.useState("closed"),[K,W]=p.useState("projects"),[H,Z]=p.useState(n?.board??{}),[J,le]=p.useState(n?.agents??[]),[ue,pe]=p.useState([]),[we,Ne]=p.useState(n?.users??[]),[ke,Be]=p.useState(n?.allRequirements??[]),[et,Ee]=p.useState(!n),[Ke,ot]=p.useState(""),_e=p.useCallback(()=>{qo(V??""),$n(!0)},[V]),re=async N=>{if(!V){rn(N),_e();return}try{const{requirement:Y}=await se.requirements.create({title:N,description:N,priority:"medium",projectId:V});pt(s("work:task.quickAddReqDone",{title:N})),Pt(),Y&&Nn(Y)}catch(Y){pt(s("work:task.errorGeneric",{message:String(Y)}))}},he=N=>{ye(N),Ae(V??""),oe(!0),pt(s("work:task.quickAddTaskHint"))},[ge,ee]=p.useState(!1),[ne,oe]=p.useState(!1),[je,ye]=p.useState(""),[Se,Te]=p.useState(""),[st,qe]=p.useState("medium"),[te,Re]=p.useState(""),[Ue,mt]=p.useState(""),[Qe,Ae]=p.useState(""),[Pe,Ge]=p.useState(""),[at,G]=p.useState([]),[ie,be]=p.useState("standard"),[de,xe]=p.useState(()=>pa()),[Ce,ze]=p.useState(""),[vt,Yt]=p.useState(!1),[jt,Fe]=p.useState(null),[dt,It]=p.useState(!1),[_t,kn]=p.useState(""),[yt,Xe]=p.useState(null),[tt,Ze]=p.useState(()=>n?.initialSelectedReqId&&n.allRequirements?n.allRequirements.find(N=>N.id===n.initialSelectedReqId)??null:null);p.useEffect(()=>{n?.initialSelectedReqId&&tt&&M("item")},[]);const[ut,Ht]=p.useState(new Set),[Nt,St]=p.useState(!1),[Tt,Ot]=p.useState(new Set),Gt=p.useRef(new Set),[U,fe]=p.useState(null),[Le,$e]=p.useState(n?.initialBoardType??"backlog"),[He,Rt]=p.useState(null),[dn,ss]=p.useState(null),[_n,Hs]=p.useState([]);p.useEffect(()=>_f(nt.WORK,()=>Ar.current),[]),p.useEffect(()=>Rf((N,Y)=>{N===nt.WORK&&hc.includes(Y)&&$e(Y)}),[]);const Bo=p.useRef(null),[$t,Rn]=p.useState(!1),[Dn,Vs]=p.useState(null),[Ws,vn]=p.useState(!1),On=p.useRef(null),rs=p.useRef(null),[os,$n]=p.useState(!1),[Pn,rn]=p.useState(""),[as,Bn]=p.useState(""),[Ks,rf]=p.useState("medium"),[Er,qo]=p.useState(""),[is,qn]=p.useState(null),[pi,gi]=p.useState(""),[xi,jn]=p.useState(""),[zo,bi]=p.useState(!1),[yi,ls]=p.useState(""),pt=p.useCallback(N=>{ot(N),setTimeout(()=>ot(""),3e3)},[]);p.useEffect(()=>{const N=Y=>{Y.key==="Escape"&&(jt?Fe(null):dt?(It(!1),kn("")):is?(qn(null),ls("")):ne?(oe(!1),ze("")):os?($n(!1),rn(""),Bn(""),jn("")):Ws?vn(!1):O!=="closed"&&(M("closed"),Xe(null),Ze(null),c&&q.current&&L(!1)))};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[jt,dt,is,ne,os,Ws,O,c]);const Vt=_.find(N=>N.id===V)??null,of=Vt?.teamIds?.[0]??null,af=p.useMemo(()=>_.filter(N=>N.status!=="archived"),[_]),wi=p.useCallback(()=>{V&&(Xe(null),Ze(null),M("project"),C("auto"),c&&L(!0))},[V,c]),Ir=p.useCallback(()=>{if(O==="project"){M("closed"),c&&L(!1);return}wi()},[O,wi,c]);p.useEffect(()=>{Gt.current=Tt},[Tt]);const zn=p.useCallback(async()=>{try{const{projects:N}=await se.projects.list();A(N)}catch{}},[]),Et=p.useCallback(async()=>{const N={};$==="project"&&V&&(N.projectId=V);try{const{board:Y}=await se.tasks.board(N);Z(Y)}catch{}},[$,V]),Us=p.useCallback(async()=>{try{const{agents:N}=await se.agents.list();le(N)}catch{}},[]),ki=p.useCallback(async()=>{try{const{teams:N}=await se.teams.list();pe(N.map(Y=>({id:Y.id,name:Y.name})))}catch{}},[]),vi=p.useCallback(async()=>{try{const{users:N}=await se.users.list(e?.orgId);Ne(N)}catch{}},[e?.orgId]),Pt=p.useCallback(async()=>{try{const{requirements:N}=await se.requirements.list({});Be(N)}catch{}},[]),ji=p.useCallback(async()=>{await Promise.all([zn(),Et(),Us(),vi(),Pt(),ki()]),Ee(!1)},[zn,Et,Us,vi,Pt,ki]);p.useEffect(()=>{t||ji()},[t,ji]),p.useEffect(()=>{!t||!n||(A(n.projects??[]),Z(n.board??{}),le(n.agents??[]),Ne(n.users??[]),Be(n.allRequirements??[]))},[t,n]);const Tr=p.useCallback(N=>{W("items"),Xe(Y=>Y?.id===N.id&&O==="item"?(M("closed"),c&&q.current&&L(!1),null):(M("item"),C("auto"),c&&(L(!0),history.pushState({mobileDetail:nt.WORK},"",window.location.hash)),N)),Ze(null)},[c,O]),Mr=p.useCallback(N=>{W("items"),Ze(Y=>Y?.id===N.id&&O==="item"?(M("closed"),c&&q.current&&L(!1),null):(M("item"),C("auto"),c&&(L(!0),history.pushState({mobileDetail:nt.WORK},"",window.location.hash)),N)),Xe(null)},[c,O]),Fn=p.useCallback(()=>{Xe(null),Ze(null),M("closed"),c&&q.current&&L(!1)},[c]),un=p.useRef(yt);un.current=yt;const fn=p.useRef(tt);fn.current=tt;const Hn=p.useRef(O);Hn.current=O;const cs=p.useRef(K);cs.current=K;const ds=p.useRef(g);ds.current=g;const Ar=p.useRef(Le);Ar.current=Le;const lf=p.useCallback(()=>{Xe(null),fn.current||(M("closed"),c&&q.current&&L(!1))},[c]);p.useEffect(()=>{if(!c)return;const N=()=>{q.current&&(L(!1),Xe(null),Ze(null),M("closed"))};return window.addEventListener("popstate",N),()=>window.removeEventListener("popstate",N)},[c]),p.useEffect(()=>{if(t||!o)return;Et(),Us(),Pt();const N=un.current?12e4:45e3,Y=setInterval(()=>{Et(),Us(),Pt()},N);let Q=null;const ce=()=>{Q||(Q=setTimeout(()=>{Q=null,Et()},800))};let me=null;const De=()=>{me||(me=setTimeout(()=>{me=null,Pt()},800))},Ie=Dt.on("task:update",it=>{qt("/taskboard"),ce();const Me=it?.payload;Me?.taskId&&(Xe(ht=>{if(!ht||ht.id!==Me.taskId)return ht;const Ye={};return typeof Me.status=="string"&&(Ye.status=Me.status),Array.isArray(Me.deliverables)&&(Ye.deliverables=Me.deliverables),Array.isArray(Me.notes)&&(Ye.notes=Me.notes),Me.result!==void 0&&(Ye.result=Me.result),{...ht,...Ye}}),un.current?.id===Me.taskId&&(qt("/tasks/"+Me.taskId),se.tasks.get(Me.taskId).then(ht=>{ht.task&&Xe(Ye=>Ye?.id===ht.task.id?ht.task:Ye)}).catch(()=>{})))}),ae=Dt.on("task:create",()=>{ce()}),mn=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(it=>Dt.on(it,Me=>{qt("/requirements"),De();const ht=Me?.payload,Ye=ht?.id??ht?.requirementId;Ye&&fn.current?.id===Ye&&(qt("/requirements/"+Ye),se.requirements.get(Ye).then(pn=>{pn.requirement&&Ze(Kn=>Kn?.id===pn.requirement.id?pn.requirement:Kn)}).catch(()=>{}))})),Bt=()=>{qt("/taskboard"),qt("/tasks"),qt("/requirements"),Et(),Pt(),un.current&&se.tasks.get(un.current.id).then(it=>{it.task&&Xe(Me=>Me?.id===it.task.id?it.task:Me)}).catch(()=>{}),fn.current&&se.requirements.get(fn.current.id).then(it=>{it.requirement&&Ze(Me=>Me?.id===it.requirement.id?it.requirement:Me)}).catch(()=>{})};return window.addEventListener("markus:data-changed",Bt),()=>{clearInterval(Y),Ie(),ae(),mn.forEach(it=>it()),window.removeEventListener("markus:data-changed",Bt),Q&&clearTimeout(Q),me&&clearTimeout(me)}},[t,o,Et,Us,Pt]);const Ni=p.useRef(H);Ni.current=H;const Si=p.useRef(ke);Si.current=ke,p.useEffect(()=>{const N=un.current;if(!N)return;const Q=Object.values(H).flat().find(ce=>ce.id===N.id);Q&&Q.updatedAt!==N.updatedAt&&Xe(Q)},[H]),p.useEffect(()=>{const N=fn.current;if(!N)return;const Y=ke.find(Q=>Q.id===N.id);Y&&Y.updatedAt!==N.updatedAt&&Ze(Y)},[ke]);const on=p.useCallback(N=>{if(!N){Ot(new Set),X(null),F("all"),history.replaceState(null,"",Br(nt.WORK)),se.tasks.board({}).then(Y=>Z(Y.board)).catch(()=>{});return}X(N),F("project"),Ot(new Set),history.replaceState(null,"",Br(nt.WORK,N)),se.tasks.board({projectId:N}).then(Y=>Z(Y.board)).catch(()=>{})},[]),[Fo,Ys]=p.useState(!1),Gs=p.useCallback((N,Y)=>{Xe(N),Ze(null),M("item"),W("items"),C("auto"),Y?.scrollToComments&&Ys(!0),c&&L(!0)},[c]),Nn=p.useCallback((N,Y)=>{Ze(N),Xe(null),M("item"),W("items"),C("auto"),Y?.scrollToComments&&Ys(!0),c&&L(!0)},[c]),Ci=p.useCallback(N=>{on(N.projectId),Vs(null),Ht(new Set),Ot(new Set),St(!1),Rn(!0),ss(N),Hs([]),se.tasks.list({requirementId:N.id,pageSize:200}).then(({tasks:Y})=>{Y?.length&&Hs(Y)}).catch(()=>{}),Nn(N),Rt(`req-${N.id}`),$e("dag")},[on,Nn]),us=p.useRef(null);p.useEffect(()=>{const N=us.current||localStorage.getItem("markus_nav_openTask");if(!N)return;const Q=Object.values(H).flat().find(ce=>ce.id===N);Q?(us.current=null,on(Q.projectId),Gs(Q),localStorage.removeItem("markus_nav_openTask")):us.current||(us.current=N,localStorage.removeItem("markus_nav_openTask"),se.tasks.get(N).then(ce=>{ce.task&&(us.current=null,on(ce.task.projectId),Gs(ce.task))}).catch(()=>{us.current=null,pt(s("work:task.notFound",{id:N}))}))},[H,Gs,on,o,pt,s]);const fs=p.useRef(null);p.useEffect(()=>{const N=fs.current||localStorage.getItem("markus_nav_openRequirement");if(!N)return;const Y=ke.find(Q=>Q.id===N);Y?(fs.current=null,on(Y.projectId),Nn(Y),localStorage.removeItem("markus_nav_openRequirement")):fs.current||(fs.current=N,localStorage.removeItem("markus_nav_openRequirement"),se.requirements.get(N).then(Q=>{Q.requirement&&(fs.current=null,on(Q.requirement.projectId),Nn(Q.requirement))}).catch(()=>{fs.current=null}))},[ke,Nn,on,o]);const Xt=p.useCallback((N,Y)=>{Ot(new Set),X(N),F("project"),W(g?"items":"projects"),Y?.keepItemDetail||(Xe(null),Ze(null),M(Q=>Q==="closed"?Q:"project")),history.replaceState(null,"",Br(nt.WORK,N))},[g]),an=p.useCallback(N=>{Ot(new Set),X(null),F("all"),W(g?"items":"projects"),N?.keepItemDetail||(Xe(null),Ze(null),M(Y=>Y==="closed"?Y:Y==="project"?"closed":"empty")),history.replaceState(null,"",Br(nt.WORK))},[g]),Vn=p.useRef(!1);p.useEffect(()=>{if(Vn.current)return;const N=window.location.hash.slice(1).split("/");if(qr(N[0])===nt.WORK&&N[1]){Vn.current=!0,Xt(N[1],{keepItemDetail:!0});return}const Y=localStorage.getItem("markus_nav_projectId");if(Y){Vn.current=!0,localStorage.removeItem("markus_nav_projectId"),Xt(Y,{keepItemDetail:!0});return}Vn.current=!0,an({keepItemDetail:!0})},[]),p.useEffect(()=>{if(!et){if(!V){Vn.current=!0,$!=="all"&&F("all");return}if(_.some(N=>N.id===V)){Vn.current=!0;return}Vn.current=!0,an({keepItemDetail:!0})}},[et,_,V,an,$]);const cf=p.useRef(qr(window.location.hash.slice(1).split("/")[0]));p.useEffect(()=>{if(t)return;const N=()=>{const Q=window.location.hash.slice(1).split("/"),ce=qr(Q[0]);cf.current=ce,ce===nt.WORK&&(Q[1]?Xt(Q[1],{keepItemDetail:!0}):an({keepItemDetail:!0}))},Y=async Q=>{const ce=Q.detail;if(qr(ce.page)===nt.WORK){if(ce.params?.openTask){const me=ce.params.openTask,De=ce.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let Ie=Object.values(Ni.current).flat().find(ae=>ae.id===me);if(!Ie)try{Ie=(await se.tasks.get(me)).task}catch{}Ie?(on(Ie.projectId),Gs(Ie,{scrollToComments:De})):pt(s("work:task.notFound",{id:me}))}if(ce.params?.openRequirement){const me=ce.params.openRequirement,De=ce.params.scrollToComments==="true";let Ie=Si.current.find(ae=>ae.id===me);if(!Ie)try{Ie=(await se.requirements.get(me)).requirement}catch{}Ie&&(on(Ie.projectId),Nn(Ie,{scrollToComments:De}))}if(ce.params?.projectId&&Xt(ce.params.projectId),ce.params?.statusFilter){const me=ce.params.statusFilter;localStorage.removeItem("markus_nav_statusFilter"),Sb.has(me)&&Rn(!0),Vs(me)}}};return window.addEventListener("markus:navigate",Y),window.addEventListener("hashchange",N),()=>{window.removeEventListener("markus:navigate",Y),window.removeEventListener("hashchange",N)}},[t]);const df=N=>{ee(!1),pt(s("work:task.projectCreated")),A(Y=>Y.some(Q=>Q.id===N.id)?Y:[...Y,N]),Xt(N.id),zn()},uf=async N=>{try{await se.projects.delete(N),V===N&&an(),pt(s("work:task.projectDeleted")),zn(),Et()}catch(Y){pt(s("work:task.errorGeneric",{message:String(Y)}))}},Ei=async()=>{if(!je||!te||!Ue||vt)return;ze("");const N=Ue.startsWith("human:"),Y=Ue.replace(/^(human|agent):/,"");if(te===Y&&!N){pt(s("work:task.assignedReviewerDifferent"));return}const Q=Qe||void 0,ce=Pe||void 0;Yt(!0);try{const{task:me}=await se.tasks.create(je,Se,te,Y,st,Q,at.length>0?at:void 0,ce,ie!=="standard"?ie:void 0,ie==="scheduled"?Kc(de):void 0,N?"human":"agent");ye(""),Te(""),G([]),Ge(""),be("standard"),xe(pa()),oe(!1),Et(),me&&Gs(me)}catch(me){const Ie=`work:task.errorCode_${(me instanceof Mc?me.code:void 0)||"unknown"}`,ae=s(Ie,{defaultValue:""});ze(ae||s("work:task.errorCreatingTask",{message:me instanceof Error?me.message:String(me)}))}finally{Yt(!1)}},Ii=async()=>{if(!(!_t.trim()||!Qe))try{const{requirement:N}=await se.requirements.create({title:_t.trim(),description:_t.trim(),priority:"medium",projectId:Qe});kn(""),It(!1),pt(s("work:task.requirementCreated")),Pt(),N&&Ge(N.id)}catch(N){ze(N instanceof Error?N.message:String(N))}},hs=N=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:N}))},Ti=()=>{qt("/taskboard"),Et(),yt&&(hs({taskId:yt.id}),qt("/tasks/"+yt.id),se.tasks.get(yt.id).then(N=>{N.task&&Xe(Y=>Y?.id===N.task.id?N.task:Y)}).catch(()=>{}))},Wn=()=>{qt("/requirements"),Pt(),tt&&(qt("/requirements/"+tt.id),se.requirements.get(tt.id).then(N=>{N.requirement&&Ze(Y=>Y?.id===N.requirement.id?N.requirement:Y)}).catch(()=>{}))},Mi=async()=>{if(!zo){if(!Pn.trim()){jn(s("work:task.pleaseReqTitle"));return}if(!as.trim()){jn(s("work:task.pleaseReqDesc"));return}if(!Er){jn(s("work:task.pleaseReqProject"));return}jn(""),bi(!0);try{const{requirement:N}=await se.requirements.create({title:Pn.trim(),description:as.trim(),priority:Ks,projectId:Er});pt(s("work:task.requirementCreated")),rn(""),Bn(""),$n(!1),Pt(),N&&Nn(N)}catch(N){jn(N instanceof Error?N.message:String(N))}finally{bi(!1)}}},Ho=async N=>{try{await se.requirements.approve(N),pt(s("work:task.requirementApproved")),hs({requirementId:N}),Wn(),Et()}catch(Y){pt(s("work:task.errorGeneric",{message:String(Y)}))}},ff=async()=>{if(is){ls("");try{await se.requirements.reject(is,pi),pt(s("work:task.requirementRejected")),hs({requirementId:is}),qn(null),gi(""),ls(""),Wn()}catch(N){ls(N instanceof Error?N.message:String(N))}}},Ai=async N=>{try{await se.requirements.cancel(N),pt(s("work:task.requirementCancelled")),hs({requirementId:N}),Wn()}catch(Y){pt(s("work:task.errorGeneric",{message:String(Y)}))}},hf=(N,Y)=>{On.current=Y,rs.current=null,N.dataTransfer.effectAllowed="move",N.dataTransfer.setData("text/plain",`task:${Y.id}`),N.currentTarget.style.opacity="0.4"},mf=(N,Y)=>{rs.current=Y,On.current=null,N.dataTransfer.effectAllowed="move",N.dataTransfer.setData("text/plain",`req:${Y.id}`),N.currentTarget.style.opacity="0.4"},Li=N=>{N.currentTarget.style.opacity="1",On.current=null,rs.current=null,fe(null)},pf=(N,Y)=>{N.preventDefault(),N.dataTransfer.dropEffect="move",U!==Y&&fe(Y)},gf=(N,Y)=>{const Q=N.currentTarget.getBoundingClientRect(),{clientX:ce,clientY:me}=N;(ce<Q.left||ce>Q.right||me<Q.top||me>Q.bottom)&&U===Y&&fe(null)},xf=async(N,Y)=>{N.preventDefault(),fe(null);const Q=On.current,ce=rs.current;if(Q){const me=a.find(Ie=>Ie.id===Y);if(!me)return;const De=me.dropStatus;if(Q.status===De||Q.status==="pending")return;try{await se.tasks.updateStatus(Q.id,De),Et()}catch{}}else if(ce){const me=tf[Y];if(!me||ce.status===me)return;try{await se.requirements.updateStatus(ce.id,me),Pt()}catch{}}},_i=N=>{Ht(Y=>{const Q=new Set(Y);return Q.has(N)?Q.delete(N):Q.add(N),Q})},Lr=N=>{Xt(N)},bf=new Set(["rejected","cancelled","archived"]),Vo=N=>bf.has(N.status),Xs=(N,Y=!1)=>Wx(N,{showClosed:$t,includeClosed:Y,statusFilter:Dn,viewMode:$,selectedProjectId:V,projectFilter:Tt,agentFilter:ut,myTasksOnly:Nt,currentUserId:e?.id}),yf=p.useMemo(()=>{const N=new Map;for(const Y of Object.values(H))for(const Q of Y)N.set(Q.id,Q);return N},[H]),wf=p.useMemo(()=>new Set(J.map(N=>N.id)),[J]),Ri=N=>N.statuses.flatMap(Y=>Xs(H[Y]??[])),hn=p.useMemo(()=>{let N=ke;return $t||(N=N.filter(Y=>!Vo(Y))),$==="project"&&V&&(N=N.filter(Y=>Y.projectId===V)),Tt.size>0&&(N=N.filter(Y=>Y.projectId&&Tt.has(Y.projectId))),ut.size>0&&(N=N.filter(Y=>ut.has(Y.createdBy))),Nt&&e?.id&&(N=N.filter(Y=>Y.createdBy===e.id)),N},[ke,$t,$,V,Tt,ut,Nt,e?.id,wf]),Di=p.useCallback(N=>hn.filter(Y=>uo[Y.status]===N.id),[hn]),kf=a.filter(N=>{if(N.id==="failed"||N.id==="closed"){const Y=Ri(N),Q=Di(N);return Y.length+Q.length>0}return!0}),Zs=Object.values(H).flat().filter(N=>Vo(N)).length+ke.filter(N=>Vo(N)).length,Oi=p.useMemo(()=>{const N=Object.values(H).flat(),Y=new Set;for(const Q of N)Q.assignedAgentId&&!lr(Q.status)&&(!V||Q.projectId===V)&&Y.add(Q.assignedAgentId);return[...J].sort((Q,ce)=>{const me=Y.has(Q.id)?0:1,De=Y.has(ce.id)?0:1;return me-De})},[J,H,V]),_r=p.useMemo(()=>{const N=new Map,Y=[];for(const ce of Oi)if(ce.teamId){const me=N.get(ce.teamId)??[];me.push(ce.id),N.set(ce.teamId,me)}else Y.push(ce);const Q=[];for(const ce of Y)Q.push({kind:"agent",agent:ce});for(const ce of ue){const me=N.get(ce.id);me&&me.length>0&&Q.push({kind:"team",id:ce.id,name:ce.name,agentIds:me})}return Q},[Oi,ue]);p.useMemo(()=>{const N=Object.values(H).flat(),Y=new Set;for(const ce of N)ce.projectId&&!lr(ce.status)&&Y.add(ce.projectId);return[...$t?_:_.filter(ce=>ce.status!=="archived")].sort((ce,me)=>{const De=ce.status==="archived"?1:0,Ie=me.status==="archived"?1:0;if(De!==Ie)return De-Ie;const ae=Y.has(ce.id)?0:1,Ct=Y.has(me.id)?0:1;return ae!==Ct?ae-Ct:ce.name.localeCompare(me.name)})},[_,H,$t]);const Rr=p.useMemo(()=>[..._].sort((N,Y)=>{const Q=N.status==="archived"?1:0,ce=Y.status==="archived"?1:0;return Q!==ce?Q-ce:N.name.localeCompare(Y.name)}),[_]),Dr=p.useMemo(()=>{const N={};for(const Y of Object.values(H))for(const Q of Y){const ce=Q.projectId??"__none__";N[ce]=(N[ce]??0)+1}return N},[H]),Or=Object.values(Dr).reduce((N,Y)=>N+Y,0),vf=V?Dr[V]??0:Or,$i=p.useMemo(()=>{const N=Xs(Object.values(H).flat()),Y=[];if(Le==="kanban"){for(const ce of ko){const me=ce.statuses.flatMap(ae=>N.filter(Ct=>Ct.status===ae)),Ie=[...hn.filter(ae=>uo[ae.status]===ce.id).map(ae=>({kind:"req",data:ae,time:new Date(ae.updatedAt??ae.createdAt).getTime()})),...me.map(ae=>({kind:"task",data:ae,time:new Date(ae.updatedAt??ae.createdAt??0).getTime()}))];Ie.sort((ae,Ct)=>Ct.time-ae.time);for(const ae of Ie)ae.kind==="req"?Y.push({kind:"req",data:ae.data}):Y.push({kind:"task",data:ae.data})}return Y}const Q=[];for(const ce of N){const me=nf(ce.status);Q.push({kind:"task",data:ce,groupOrder:vo[me]??5,time:new Date(ce.updatedAt??ce.createdAt??0).getTime()})}for(const ce of hn){const me=uo[ce.status]??"todo";Q.push({kind:"req",data:ce,groupOrder:vo[me]??5,time:new Date(ce.updatedAt??ce.createdAt).getTime()})}return Q.sort((ce,me)=>ce.groupOrder!==me.groupOrder?ce.groupOrder-me.groupOrder:me.time-ce.time),Q.map(ce=>ce.kind==="req"?{kind:"req",data:ce.data}:{kind:"task",data:ce.data})},[H,hn,Le,$t,Dn,V,Tt,ut,Nt,e?.id,$]),$r=p.useRef($i);$r.current=$i;const Pi=p.useRef(Rr);Pi.current=Rr;const Wo=p.useRef(V);Wo.current=V;const ms=p.useCallback(N=>{N.kind==="req"?(Ze(N.data),Xe(null)):(Xe(N.data),Ze(null)),M("item"),C("auto"),W("items")},[]),Bi=p.useCallback(()=>{if(Hn.current==="item"||Hn.current==="empty"){M("closed"),Xe(null),Ze(null);return}if(un.current||fn.current){M("item"),C("auto"),W("items");return}const N=$r.current;if(N.length>0){ms(N[0]);return}Xe(null),Ze(null),M("empty"),C("auto")},[ms]);p.useEffect(()=>{if(!c)if(g){if(W("items"),Hn.current==="project")if(un.current||fn.current)M("item");else{const N=$r.current;N.length>0?ms(N[0]):M("closed")}}else cs.current==="items"&&Hn.current==="closed"||!g&&Hn.current==="closed"&&W("projects")},[g,c,ms]);const Qs=d?.keyboardPane??"content",qi=p.useRef(Qs);if(p.useEffect(()=>{if(t||c||!o)return;const N=qi.current;qi.current=Qs,Qs==="l1"&&(W("projects"),N!=="l1"&&ds.current&&(v(!1),d?.setLeftCollapsed(!1)))},[Qs,t,c,o,v,d]),p.useEffect(()=>{if(t||c||!o)return;const N=navigator.platform.toUpperCase().includes("MAC"),Y=Q=>{if(d?.keyboardPane==="l0")return;const ce=N?Q.metaKey&&!Q.ctrlKey:Q.ctrlKey&&!Q.metaKey;if(Q.ctrlKey&&!Q.metaKey&&Q.key==="Tab"){Q.preventDefault();const Me=hc,ht=Me.indexOf(Ar.current),Ye=Q.shiftKey?Me[(ht-1+Me.length)%Me.length]:Me[(ht+1)%Me.length];$e(Ye);return}if(ce&&!Q.altKey&&!Q.shiftKey){const Me=Q.key.toLowerCase();if(Me==="j"){Q.preventDefault(),Ir();return}if(Me==="l"){Q.preventDefault(),Bi();return}}if(ce||Q.altKey||Q.ctrlKey||Q.metaKey||Of(Q.target))return;const me=Q.key.length===1?Q.key.toLowerCase():Q.key;if(me==="h"||me==="ArrowLeft"){if(ds.current){Q.preventDefault(),v(!1),d?.setLeftCollapsed(!1),W("projects"),d?.setKeyboardPane("l1");return}if(cs.current==="items"){Q.preventDefault(),W("projects"),d?.setKeyboardPane("l1");return}Q.preventDefault(),d?.setL0FocusPageId(nt.WORK),d?.setLeftCollapsed(!1),d?.setKeyboardPane("l0");return}if((me==="l"||me==="ArrowRight"||me==="Tab"&&!Q.shiftKey)&&!ds.current&&cs.current==="projects"){Q.preventDefault(),W("items"),d?.setKeyboardPane("content");return}if((me==="l"||me==="ArrowRight")&&(ds.current||cs.current==="items")){Q.preventDefault();return}const De=me==="j"||me==="ArrowDown"?1:me==="k"||me==="ArrowUp"?-1:0;if(!De)return;if((ds.current?"items":cs.current)==="projects"){Q.preventDefault(),d?.setKeyboardPane("l1");const Me=Pi.current,ht=Me.length+1;if(Me.length===0)return;const Ye=Wo.current==null?0:Me.findIndex(ps=>ps.id===Wo.current)+1,pn=Ye<0?0:Ye,Kn=Math.max(0,Math.min(ht-1,pn+De));if(Kn===0)an(),requestAnimationFrame(()=>{document.querySelector('[data-project-id="__all__"]')?.scrollIntoView({block:"nearest"})});else{const ps=Me[Kn-1];Xt(ps.id),Hn.current!=="closed"&&(M("project"),Xe(null),Ze(null)),requestAnimationFrame(()=>{document.querySelector(`[data-project-id="${ps.id}"]`)?.scrollIntoView({block:"nearest"})})}return}const ae=Ar.current;if(ae!=="backlog"&&ae!=="kanban")return;Q.preventDefault(),d?.setKeyboardPane("content");const Ct=$r.current;if(Ct.length===0){M(Me=>Me==="closed"?"empty":Me);return}const mn=un.current?.id??fn.current?.id??null;let Bt=mn?Ct.findIndex(Me=>Me.data.id===mn):-1;Bt<0&&(Bt=De>0?-1:0);const it=Math.max(0,Math.min(Ct.length-1,Bt+De));ms(Ct[it]),requestAnimationFrame(()=>{document.querySelector(`[data-work-item-id="${Ct[it].data.id}"]`)?.scrollIntoView({block:"nearest"})})};return document.addEventListener("keydown",Y,!0),()=>document.removeEventListener("keydown",Y,!0)},[t,c,o,Ir,Bi,Xt,an,ms,v,d]),et)return r.jsx(Kf,{label:s("work:task.loadingPage")});const zi=O!=="closed"||!!(yt||tt),Pr=!c&&!!(yt&&tt)&&O==="item",Fi=c?B:zi;return r.jsxs("div",{ref:u,className:"flex-1 overflow-hidden flex bg-surface-primary",children:[!c&&r.jsx(zx,{projects:Rr,selectedProjectId:V,allSelected:$==="all"&&!V,taskCounts:Dr,totalTaskCount:Or,onSelectAll:()=>{an(),W("projects")},onSelectProject:N=>{Xt(N),W("projects")},onEditProject:N=>{Xt(N),Xe(null),Ze(null),M("project"),W("projects")},onCreateProject:()=>ee(!0),onCollapse:()=>{const N=!g;v(N),d?.setLeftCollapsed(N)},width:y.width,onResizeStart:y.onResizeStart,hidden:g,focused:Qs==="l1"&&K==="projects"&&!g,onActivate:()=>W("projects")}),r.jsxs("div",{"data-keyboard-pane":"content",onPointerDown:()=>W("items"),className:`${c?"flex-1 min-w-0":Pr?"w-0 shrink-0 overflow-hidden":"flex-1 min-w-0"} overflow-hidden flex flex-col bg-surface-primary`,style:c&&B?{display:"none"}:void 0,children:[Ke&&r.jsx("div",{className:"mx-6 mt-2 px-3 py-1.5 bg-green-500/15 text-green-600 text-xs rounded-lg",children:Ke}),c?r.jsxs("div",{className:"shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[r.jsx(Df,{}),Vt?r.jsxs("div",{className:"flex items-center gap-1 min-w-0 flex-1",children:[r.jsx("span",{className:"text-sm font-semibold text-fg-primary truncate",children:Vt.name}),r.jsx("button",{onClick:Ir,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${O==="project"?"bg-surface-overlay text-fg-primary":"text-fg-tertiary"}`,children:r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3"}),r.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"})]})})]}):r.jsx("h2",{className:"text-sm font-semibold text-fg-primary min-w-0 flex-1 truncate",children:s("work:task.projectsCount",{count:_.length})}),r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx("button",{onClick:()=>ee(!0),className:"px-2 py-1 text-[11px] bg-brand-600 text-on-brand rounded-md",children:s("work:task.shortProject")}),r.jsx("button",{onClick:_e,className:"px-2 py-1 text-[11px] bg-brand-600 text-on-brand rounded-md",children:s("work:task.shortReq")}),r.jsx("button",{onClick:()=>{Ae(V??""),oe(!0)},className:"px-2 py-1 text-[11px] border border-amber-500/60 text-amber-600 rounded-md",children:s("work:task.shortTask")})]})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 px-3 py-1.5 min-h-9",children:[r.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag","workflows"].map(N=>r.jsx("button",{onClick:()=>$e(N),className:`px-2 py-0.5 text-[10px] font-medium whitespace-nowrap transition-colors ${Le===N?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:N==="backlog"?s("work:task.backlog"):N==="kanban"?s("work:task.kanban"):N==="dag"?s("work:task.dag"):s("work:task.workflows","Workflows")},N))}),Zs>0&&r.jsx("button",{onClick:()=>Rn(N=>!N),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${$t?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:$t?s("work:task.hideArchived"):s("work:task.archivedCount",{count:Zs})}),r.jsx("div",{className:"flex-1"}),Dn&&r.jsxs("button",{onClick:()=>Vs(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:[s(`common:status.${Dn==="in_progress"?"inProgress":Dn}`),r.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})]}),(af.length>1||J.length>0||e?.id)&&r.jsxs("button",{onClick:()=>vn(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${ut.size>0||Nt?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/30":"border border-border-default text-fg-secondary"}`,children:[r.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),r.jsx("span",{children:ut.size+(Nt?1:0)>0?s("work:task.filterWithCount",{count:ut.size+(Nt?1:0)}):s("work:task.filter")})]})]})]}):r.jsxs("div",{"data-electron-drag":!0,className:"flex items-center gap-3 px-6 h-14 shrink-0",children:[r.jsx("button",{"data-no-drag":!0,type:"button",onClick:()=>{const N=!g;v(N),d?.setLeftCollapsed(N),W("projects")},className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors shrink-0 ${g?"bg-brand-500/15 text-brand-500 hover:bg-brand-500/25":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,title:s(g?"work:task.expand":"work:task.collapse"),children:r.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),r.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),Vt?r.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1 shrink-0 min-w-0",children:[r.jsx(yb,{value:Vt.name,onSave:async N=>{await se.projects.update(Vt.id,{name:N}),zn()},className:"text-sm font-semibold text-fg-primary"}),r.jsx("button",{onClick:Ir,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${O==="project"?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:`${s("work:project.settingsTitle")} (⌘J)`,children:r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3"}),r.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"})]})})]}):r.jsx("h2",{className:"text-sm font-semibold text-fg-primary shrink-0",children:s("work:task.projectsCount",{count:_.length})}),Zs>0&&r.jsx("button",{onClick:()=>Rn(N=>!N),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${$t?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:$t?s("work:task.hideArchivedWithCount",{count:Zs}):s("work:task.archivedCount",{count:Zs})}),r.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(N=>r.jsx("button",{onClick:()=>$e(N),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${Le===N?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:N==="backlog"?s("work:task.backlog"):N==="kanban"?s("work:task.kanban"):N==="dag"?s("work:task.dag"):s("work:task.workflows","Workflows")},N))}),r.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1.5 shrink-0",children:[r.jsx("button",{onClick:()=>ee(!0),className:"px-3 py-1.5 border border-border-default text-fg-secondary hover:bg-surface-elevated text-xs rounded-lg font-medium transition-colors",children:s("work:task.newProjectBtn")}),r.jsx("button",{onClick:_e,className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-on-brand text-xs rounded-lg font-medium transition-colors",children:s("work:task.newRequirement")}),r.jsx("button",{onClick:()=>{Ae(V??""),oe(!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:s("work:task.newTaskBtn")})]}),r.jsx("div",{className:"flex-1"})]}),!c&&Le!=="workflows"&&(_r.length>0||e?.id)&&(vf>0||hn.length>0||ut.size>0||Nt)&&r.jsxs("div",{className:"px-6 py-1.5 flex items-center gap-1.5 overflow-x-auto scrollbar-hide shrink-0",children:[r.jsx("button",{type:"button",onClick:()=>{Ht(new Set),St(!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 ${ut.size>0||Nt?"visible opacity-100":"invisible opacity-0"}`,children:s("work:task.clear")}),e?.id&&r.jsx("button",{type:"button",onClick:()=>St(N=>!N),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Nt?"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:s("work:task.myTasks")}),_r.map(N=>{if(N.kind==="team"){const ce=N.agentIds.every(De=>ut.has(De)),me=!ce&&N.agentIds.some(De=>ut.has(De));return r.jsxs("button",{onClick:()=>{Ht(De=>{const Ie=new Set(De);if(ce)for(const ae of N.agentIds)Ie.delete(ae);else for(const ae of N.agentIds)Ie.add(ae);return Ie})},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${ce?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":me?"bg-brand-600/10 text-brand-400 ring-1 ring-brand-500/20":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[r.jsx("svg",{className:"w-3.5 h-3.5 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:r.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"})}),N.name,r.jsx("span",{className:"text-[9px] text-fg-muted",children:N.agentIds.length})]},`team-${N.id}`)}const Y=N.agent,Q=ut.has(Y.id);return r.jsxs("button",{onClick:()=>_i(Y.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Q?"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:[r.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${Q?"bg-brand-600 text-on-brand":"bg-surface-overlay text-fg-secondary"}`,children:Y.name[0]?.toUpperCase()}),Y.name]},Y.id)})]}),_.length===0?r.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:r.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[r.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:r.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:r.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"})})}),r.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:s("work:task.emptyNoProjectsTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:s("work:task.emptyNoProjectsHint")}),r.jsx("button",{onClick:()=>ee(!0),className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-on-brand rounded-lg font-medium transition-colors",children:s("work:project.newProject")})]})}):Xs(Object.values(H).flat()).length===0&&hn.length===0?r.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:r.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[r.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:r.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:[r.jsx("path",{d:"M9 11l3 3L22 4"}),r.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})}),ut.size>0||Nt?r.jsxs(r.Fragment,{children:[r.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:s("work:task.emptyFilteredTitle",{defaultValue:"No matching work"})}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:s("work:task.emptyFilteredHint",{defaultValue:"Nothing matches the current assignee filter. Clear filters to see all items in this project."})}),r.jsx("button",{type:"button",onClick:()=>{Ht(new Set),St(!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:s("work:task.clear")})]}):r.jsxs(r.Fragment,{children:[r.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:s("work:task.emptyNoReqsTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed whitespace-pre-line",children:s("work:task.emptyNoReqsHint")}),r.jsxs("div",{className:"flex items-center justify-center gap-2 pt-1",children:[r.jsx("button",{onClick:_e,className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-on-brand rounded-lg font-medium transition-colors",children:s("work:task.createRequirementCta")}),r.jsx("button",{onClick:()=>{Ae(V??""),oe(!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:s("work:task.newTaskBtn")})]}),$==="project"&&r.jsxs("p",{className:"pt-3 text-[11px] text-fg-tertiary leading-relaxed",children:[s("work:task.emptyNoReqsUnassignedHint")," ",r.jsx("button",{type:"button",onClick:()=>an(),className:"inline text-brand-500 hover:text-brand-500 hover:underline",children:s("work:allProjects")})]})]})]})}):Le==="backlog"?r.jsx("div",{className:"flex-1 min-h-0 flex flex-col",children:r.jsx(Db,{tasks:Xs(Object.values(H).flat()),requirements:hn,agents:J,projects:_,onTaskClick:N=>Tr(N),onReqClick:N=>Mr(N),onRefresh:()=>{Et(),Pt()},selectedTaskId:yt?.id,selectedReqId:tt?.id,onQuickCreateReq:re,onQuickCreateTask:he})}):Le==="workflows"?r.jsx("div",{className:"flex-1 min-h-0 flex flex-col relative",children:r.jsx(Bb,{teamId:null,defaultTeamId:of,projectId:V,agents:J,users:we,projects:_,onViewRunTasks:N=>{const Y=ke.find(Q=>Q.id===N);Y?Ci(Y):se.requirements.get(N).then(Q=>{Q.requirement&&(Be(ce=>[...ce,Q.requirement]),Ci(Q.requirement))}).catch(()=>{})}})}):Le==="dag"?r.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",children:[r.jsx(Bx,{tasks:(()=>{const N=Xs(Object.values(H).flat(),!0);if(t&&tt){const Q=new Set(tt.taskIds??[]);return N.filter(ce=>Q.has(ce.id))}if(_n.length===0)return N;const Y=new Map(N.map(Q=>[Q.id,Q]));for(const Q of _n)Y.set(Q.id,Q);return[...Y.values()]})(),requirements:(()=>{const N=t&&tt?[tt]:hn;return!dn||N.some(Y=>Y.id===dn.id)?N:[dn,...N]})(),agents:J,showArchived:$t,onShowArchivedChange:Rn,onTaskClick:N=>Tr(N),onReqClick:N=>Mr(N),onCollapseDAG:()=>{Xe(null),Ze(null),Rt(null),ss(null),Hs([])},onDependencyChange:Et,selectedTaskId:yt?.id,selectedReqId:tt?.id,hasDetailPanel:zi,defaultExpandedNodeId:He??(t&&tt?`req-${tt.id}`:void 0),previewMode:t}),c&&r.jsx("button",{onClick:()=>$e("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-on-brand active:bg-brand-400 backdrop-blur-sm z-10",title:s("work:task.backToKanban"),children:r.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 20 20",fill:"currentColor",children:r.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"})})}),c&&r.jsx("button",{onClick:()=>$e("workflows"),className:"absolute right-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-on-brand active:bg-brand-400 backdrop-blur-sm z-10",title:s("work:task.toWorkflows","Workflows"),children:r.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"9 18 15 12 9 6"})})})]}):r.jsx("div",{ref:Bo,className:"flex-1 min-h-0 overflow-auto px-4 py-5",children:r.jsx("div",{className:"flex gap-3 items-stretch",children:kf.map(N=>{const Y=Ri(N),Q=Di(N),ce=Y.length+Q.length,me=U===N.id;return r.jsxs("div",{className:`w-[280px] shrink-0 rounded-xl flex flex-col transition-colors ${me?"bg-surface-elevated/60 ring-1 ring-brand-500/30":"bg-surface-secondary/50"}`,onDragOver:De=>pf(De,N.id),onDragLeave:De=>gf(De,N.id),onDrop:De=>{xf(De,N.id)},children:[r.jsxs("div",{className:`flex justify-between items-center px-3 py-2.5 shrink-0 border-b border-border-default/30 sticky top-0 z-10 rounded-t-xl ${me?"bg-surface-elevated/60":"bg-surface-secondary/50"}`,children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`w-2 h-2 rounded-full ${N.accent.replace("border-t-","bg-")}`}),r.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:N.label})]}),r.jsx("span",{className:"text-[11px] text-fg-tertiary font-medium tabular-nums",children:ce})]}),r.jsx("div",{className:"space-y-2 px-2 py-2",children:(()=>{const De=[...Q.map(Ie=>({kind:"req",data:Ie,time:new Date(Ie.updatedAt??Ie.createdAt).getTime()})),...Y.map(Ie=>({kind:"task",data:Ie,time:new Date(Ie.updatedAt??Ie.createdAt??0).getTime()}))];return De.sort((Ie,ae)=>ae.time-Ie.time),De.map(Ie=>{if(Ie.kind==="req"){const ae=Ie.data,Ct=l[ae.status]??{label:ae.status,cls:"bg-gray-500/15 text-fg-secondary"},Bt=ae.source==="agent"&&ae.status==="pending",it=$==="all"&&ae.projectId?_.find(Ye=>Ye.id===ae.projectId):null,Me=$s(ae.createdBy,J,we)??ae.createdBy.slice(0,10),ht=tt?.id===ae.id;return r.jsxs("div",{"data-work-item-id":ae.id,role:"button",tabIndex:0,draggable:!0,onDragStart:Ye=>mf(Ye,ae),onDragEnd:Li,onClick:()=>Mr(ae),onKeyDown:Ye=>Ye.key==="Enter"&&Mr(ae),className:`group rounded-lg p-2.5 border border-transparent transition-all cursor-grab active:cursor-grabbing
|
|
141
|
-
${Bt?"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"}
|
|
142
|
-
${ht?"!bg-brand-500/25 !border-brand-500/50 ring-1 ring-brand-500/40":""}`,children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-purple-500 shrink-0"}),r.jsx("span",{className:"text-[10px] font-semibold text-purple-500 uppercase tracking-wide shrink-0",children:s("work:task.requirementShort")}),r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md shrink-0 ml-auto ${Ct.cls}`,children:Ct.label})]}),r.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:ae.title}),ae.description&&r.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:ae.description}),r.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[it&&r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-overlay/60 text-fg-secondary rounded truncate max-w-[90px]",title:it.name,children:it.name}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:ae.priority}),r.jsxs("span",{className:"text-[10px] text-fg-muted",children:["by ",Me]})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[ae.goalConfig?.loopEnabled&&r.jsxs("span",{className:"text-[10px] text-brand-500/70 bg-brand-500/8 px-1.5 py-0.5 rounded-md",title:ae.goalConfig.completionCriteria,children:["🎯 ",ae.goalConfig.currentIteration,"/",ae.goalConfig.maxIterations]}),ae.taskIds.length>0&&r.jsxs("span",{className:"text-[10px] text-brand-500/70 bg-brand-500/8 px-1.5 py-0.5 rounded-md",children:["📋 ",ae.taskIds.length]})]})]}),Bt&&r.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[r.jsx("button",{onClick:Ye=>{Ye.stopPropagation(),Ho(ae.id)},className:"flex-1 py-1 bg-green-600 hover:bg-green-500 text-white text-[10px] rounded-md font-medium transition-colors",children:s("work:task.approve")}),r.jsx("button",{onClick:Ye=>{Ye.stopPropagation(),qn(ae.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:s("work:task.reject")})]})]},`req-${ae.id}`)}else{const ae=Ie.data,Ct=ae.subtasks?.length??0,mn=i[ae.status],Bt=ae.status==="pending",it=ae.taskType==="scheduled"&&!!ae.scheduleConfig,Me=it?ae.scheduleConfig.every?s("work:task.everyInterval",{interval:ae.scheduleConfig.every}):ae.scheduleConfig.cron?s("work:task.cronLabel"):s("work:task.scheduledShort"):null,ht=$==="all"&&ae.projectId?(()=>{const Mt=_.find(jf=>jf.id===ae.projectId)?.name;return Mt&&Mt!=="default"?Mt:null})():null,Ye=ae.requirementId?ke.find(Mt=>Mt.id===ae.requirementId)?.title:null,pn=ae.createdBy?$s(ae.createdBy,J,we)??ae.createdBy:null,Kn=yt?.id===ae.id,ps={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"},Hi=ae.status==="blocked"&&Aa(ae,Mt=>yf.get(Mt));return r.jsxs("div",{"data-work-item-id":ae.id,role:"button",tabIndex:0,"aria-label":ae.title,draggable:!Bt,onDragStart:Mt=>!Bt&&hf(Mt,ae),onDragEnd:Li,onClick:()=>Tr(ae),onKeyDown:Mt=>Mt.key==="Enter"&&Tr(ae),className:`group rounded-lg p-2.5 border border-transparent transition-all ${Hi?"bg-red-500/[0.06] border-red-500/30 ring-1 ring-red-500/15 cursor-pointer":Bt?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":it?"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"} ${Kn?"!bg-brand-500/25 !border-brand-500/50 ring-1 ring-brand-500/40":""}`,children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${ps[ae.priority]??"bg-gray-400"}`,title:ae.priority}),it&&r.jsx("span",{className:"text-blue-500 shrink-0",title:Me??"Scheduled",children:r.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.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"})})}),it&&Me&&r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:Me}),mn&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${mn.cls}`,children:mn.label}),Hi&&r.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:"⚠"})]}),r.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:ae.title}),ae.description&&r.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:ae.description}),(ht||Ye||ae.blockedBy&&ae.blockedBy.length>0)&&r.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[ht&&r.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:ht,children:ht}),Ye&&r.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:Ye,children:["# ",Ye]}),ae.blockedBy&&ae.blockedBy.length>0&&r.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/10 text-amber-600 rounded-md",children:["⏳ ",ae.blockedBy.length," dep",ae.blockedBy.length>1?"s":""]})]}),r.jsxs("div",{className:"flex items-center justify-between mt-auto pt-1.5 border-t border-border-default/20",children:[r.jsx("div",{className:"flex items-center gap-1.5",children:pn&&r.jsxs("span",{className:"text-[10px] text-fg-muted",title:`by ${pn}`,children:["by ",pn]})}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[Ct>0&&r.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",Ct]}),ae.notes&&ae.notes.length>0&&r.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",ae.notes.length]}),ae.assignedAgentId&&r.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:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Qn[J.find(Mt=>Mt.id===ae.assignedAgentId)?.status??""]??"bg-gray-500"}`}),J.find(Mt=>Mt.id===ae.assignedAgentId)?.name??ae.assignedAgentId.slice(0,8)]})]})]})]},ae.id)}})})()}),me&&r.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:r.jsx("span",{className:"text-[11px] text-brand-500/50",children:s("work:task.dropHere")})})]},N.id)})})})]}),!c&&Fi&&r.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:I,children:r.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"})}),Fi&&r.jsx("div",{className:`${c||Pr?"flex-1":"shrink-0"} overflow-hidden min-w-0 flex border-l border-border-default/60`,style:c||Pr?void 0:{width:T},children:O==="project"&&Vt?r.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[r.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:[r.jsx("h3",{className:"text-sm font-semibold text-fg-primary truncate flex-1",children:s("work:project.settingsTitle")}),r.jsx("button",{type:"button",onClick:Fn,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":s("common:close"),children:r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),r.jsx(Ab,{project:Vt,tasks:Object.values(H).flat().filter(N=>N.projectId===Vt.id),requirements:ke.filter(N=>N.projectId===Vt.id),agents:J,onDeleteProject:()=>uf(Vt.id),onUpdateProject:async N=>{await se.projects.update(Vt.id,N),zn()},onRefresh:()=>{zn()}})]}):O==="empty"?r.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:r.jsxs("div",{className:"max-w-xs w-full text-center space-y-3",children:[r.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-surface-elevated flex items-center justify-center",children:r.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:[r.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),r.jsx("path",{d:"M9 12h6"})]})}),r.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:s("work:task.emptyDetailTitle",{defaultValue:"No item selected"})}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:s("work:task.emptyDetailHint",{defaultValue:"Select a requirement or task from the list, or create one to get started."})}),r.jsxs("div",{className:"flex items-center justify-center gap-2",children:[r.jsx("button",{onClick:_e,className:"px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-on-brand rounded-lg font-medium",children:s("work:task.newRequirement")}),r.jsx("button",{onClick:()=>{Ae(V??""),oe(!0)},className:"px-3 py-1.5 text-[11px] border border-amber-500/60 text-amber-600 rounded-lg font-medium",children:s("work:task.newTaskBtn")})]}),r.jsx("button",{type:"button",onClick:Fn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:s("common:close")})]})}):Pr?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:r.jsx(Tc,{req:tt,agents:J,projects:_,allTasks:Object.values(H).flat(),users:we,onClose:()=>{Ze(null),yt||Fn()},onApprove:N=>{Ho(N)},onReject:N=>{qn(N)},onCancel:N=>{Ai(N),Ze(null)},onStatusChange:async(N,Y)=>{try{await se.requirements.updateStatus(N,Y),pt(`Requirement status → ${Y}`),hs({requirementId:N}),Wn(),Et()}catch(Q){pt(`Error: ${Q}`)}},onRefresh:Wn,authUser:e,onTaskClick:N=>{Xe(N),M("item")},onCreateTask:(N,Y)=>{Ge(N),Y&&Ae(Y),oe(!0)},onProjectClick:Lr,previewMode:t})}),r.jsx("div",{className:"w-px shrink-0 bg-border-default"}),r.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:r.jsx(Nc,{task:yt,agents:J,projects:_,requirements:ke,allTasks:Object.values(H).flat(),users:we,onClose:lf,onRefresh:Ti,authUser:e,scrollToComments:Fo,onScrollToCommentsDone:()=>Ys(!1),onReqClick:N=>{Ze(Y=>Y?.id===N.id?null:N),M("item")},onProjectClick:Lr})})]}):yt?r.jsx(Nc,{task:yt,agents:J,projects:_,requirements:ke,allTasks:Object.values(H).flat(),users:we,onClose:Fn,onRefresh:Ti,authUser:e,scrollToComments:Fo,onScrollToCommentsDone:()=>Ys(!1),onReqClick:N=>{Ze(N),Xe(null),M("item")},onProjectClick:Lr}):tt?r.jsx(Tc,{req:tt,agents:J,projects:_,allTasks:Object.values(H).flat(),users:we,onClose:Fn,onApprove:N=>{Ho(N)},onReject:N=>{qn(N)},onCancel:N=>{Ai(N),Fn()},onStatusChange:async(N,Y)=>{try{await se.requirements.updateStatus(N,Y),pt(`Requirement status → ${Y}`),hs({requirementId:N}),Wn(),Et()}catch(Q){pt(`Error: ${Q}`)}},scrollToComments:Fo,onScrollToCommentsDone:()=>Ys(!1),onRefresh:Wn,authUser:e,onTaskClick:N=>{Xe(N),Ze(null),M("item"),c&&(L(!0),history.pushState({mobileDetail:nt.WORK},"",window.location.hash))},onCreateTask:(N,Y)=>{Ge(N),Y&&Ae(Y),oe(!0)},onProjectClick:Lr,previewMode:t}):r.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:r.jsxs("div",{className:"max-w-xs w-full text-center space-y-3",children:[r.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:s("work:task.emptyDetailTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:s("work:task.emptyDetailHint")}),r.jsx("button",{type:"button",onClick:Fn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:s("common:close")})]})})}),ge&&r.jsx(Kl,{orgId:e?.orgId,onCreated:df,onClose:()=>ee(!1)}),jt&&r.jsx(Kl,{orgId:e?.orgId,onCreated:N=>{A(Y=>Y.some(Q=>Q.id===N.id)?Y:[...Y,N]),jt==="task"?(Ae(N.id),Ge("")):qo(N.id),Fe(null),pt(s("work:task.projectCreated"))},onClose:()=>Fe(null)}),ne&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{oe(!1),ze("")},children:r.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${c?"w-full":"w-[28rem]"}`,onClick:N=>N.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("work:task.newTask")}),r.jsxs("div",{className:va,children:[r.jsx("label",{className:lt,children:s("work:task.taskType")}),r.jsx("div",{className:"inline-flex w-full p-0.5 bg-surface-elevated border border-border-default rounded-lg",children:["standard","scheduled"].map(N=>r.jsx("button",{type:"button",onClick:()=>be(N),"aria-pressed":ie===N,className:`flex-1 px-3 py-1.5 text-sm rounded-md transition-colors ${ie===N?"bg-brand-600 text-on-brand font-medium":"text-fg-secondary hover:text-fg-primary"}`,children:s(N==="standard"?"work:task.taskTypeStandard":"work:task.taskTypeScheduled")},N))}),r.jsx("label",{className:lt,children:s("work:task.titleLabel")}),r.jsx("input",{autoFocus:!c,value:je,onChange:N=>ye(N.target.value),onKeyDown:N=>{N.key==="Enter"&&Ei()},className:xn}),r.jsx("label",{className:lt,children:s("work:task.descriptionField")}),r.jsx("textarea",{value:Se,onChange:N=>Te(N.target.value),rows:2,className:`${xn} resize-none`}),r.jsx("label",{className:lt,children:s("work:task.priorityField")}),r.jsx(wo,{value:st,onChange:qe}),r.jsx("label",{className:lt,children:s("work:task.projectLabel")}),r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx(Ft,{className:"flex-1",options:[{value:"",label:s("work:task.noProject")},..._.map(N=>({value:N.id,label:N.name}))],value:Qe,onChange:N=>{Ae(N),Ge("")},placeholder:s("work:task.noProject"),noMatchesText:s("work:task.noMatches")}),r.jsx("button",{type:"button",onClick:()=>Fe("task"),className:oa,children:s("work:task.newProjectInline")})]}),r.jsx("label",{className:lt,children:s("work:task.requirementLabel")}),r.jsxs("div",{className:"min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Ft,{className:"flex-1",options:[{value:"",label:s("work:task.selectRequirement")},...ke.filter(N=>N.status==="in_progress"&&(!Qe||N.projectId===Qe)).map(N=>({value:N.id,label:N.title}))],value:Pe,onChange:Ge,placeholder:s("work:task.selectRequirement"),noMatchesText:s("work:task.noMatches")}),r.jsx("button",{type:"button",onClick:()=>{It(!0),ze("")},className:oa,children:s("work:task.newRequirementInline")})]}),dt&&r.jsxs("div",{className:"mt-2 space-y-1.5",children:[r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{autoFocus:!0,value:_t,onChange:N=>kn(N.target.value),placeholder:s("work:task.newReqInlinePlaceholder"),onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),Ii())},className:"flex-1 px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"}),r.jsx("button",{type:"button",onClick:()=>{Ii()},disabled:!_t.trim(),className:"px-3 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-on-brand disabled:opacity-40",children:s("common:create")})]}),r.jsx("p",{className:"text-[11px] text-fg-tertiary",children:s(Qe?"work:task.newReqInlineHint":"work:task.newReqInlineNeedProject")})]})]}),r.jsxs("label",{className:lt,children:[s("work:task.assignToRequired"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx(Ft,{options:J.map(N=>({value:N.id,label:`${N.name} (${N.status})`})),value:te,onChange:Re,placeholder:s("work:task.selectAgent"),noMatchesText:s("work:task.noMatches")}),r.jsxs("label",{className:lt,children:[s("work:task.reviewerRequired"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx(Ft,{options:[...we.map(N=>({value:`human:${N.id}`,label:N.name})),...J.filter(N=>N.id!==te).map(N=>({value:`agent:${N.id}`,label:`${N.name} (${N.status})`}))],value:Ue,onChange:mt,placeholder:s("work:task.selectReviewer"),noMatchesText:s("work:task.noMatches")}),ie==="scheduled"&&r.jsx("div",{className:"col-span-2",children:r.jsx(Uc,{value:de,onChange:xe})}),r.jsx("label",{className:lt,children:s("work:task.blockedBy")}),r.jsxs("div",{className:"min-w-0",children:[r.jsx(xb,{options:Object.values(H).flat().filter(N=>N.status!=="completed"&&N.status!=="cancelled").map(N=>({value:N.id,label:N.title})),selected:at,onAdd:N=>G([...at,N]),placeholder:s("work:task.selectDependency"),noMatchesText:s("work:task.noMatches")}),at.length>0&&r.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:at.map(N=>{const Y=Object.values(H).flat().find(Q=>Q.id===N);return r.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:[Y?Y.title.slice(0,30):N.slice(-8),r.jsx("button",{onClick:()=>G(at.filter(Q=>Q!==N)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},N)})})]})]}),Ce&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Ce}),r.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[r.jsx("button",{onClick:()=>{oe(!1),ze("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:s("common:cancel")}),r.jsx("button",{onClick:()=>{Ei()},disabled:!je.trim()||!te||!Ue||vt,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-on-brand disabled:opacity-50",children:s(vt?"common:creating":"common:create")})]})]})}),os&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{$n(!1),rn(""),Bn(""),jn("")},children:r.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${c?"w-full":"w-[28rem]"}`,onClick:N=>N.stopPropagation(),children:[r.jsxs("div",{children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("work:task.newRequirementModalTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:s("work:task.newRequirementModalHint")})]}),r.jsxs("div",{className:va,children:[r.jsxs("label",{className:lt,children:[s("work:task.projectLabel"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx(Ft,{className:"flex-1",options:_.map(N=>({value:N.id,label:N.name})),value:Er,onChange:qo,placeholder:s("work:task.selectProject"),noMatchesText:s("work:task.noMatches")}),r.jsx("button",{type:"button",onClick:()=>Fe("req"),className:oa,children:s("work:task.newProjectInline")})]}),r.jsxs("label",{className:lt,children:[s("work:task.titleField"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx("input",{value:Pn,onChange:N=>rn(N.target.value),placeholder:s("work:task.reqTitleExample"),className:xn,autoFocus:!c,onKeyDown:N=>{N.key==="Enter"&&Pn.trim()&&Mi()}}),r.jsxs("label",{className:lt,children:[s("work:task.descriptionField"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx("textarea",{value:as,onChange:N=>Bn(N.target.value),placeholder:s("work:task.reqDescPlaceholder"),rows:3,className:`${xn} resize-none`}),r.jsx("label",{className:lt,children:s("work:task.priorityField")}),r.jsx(wo,{value:Ks,onChange:rf})]}),xi&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:xi}),r.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[r.jsx("button",{onClick:()=>{$n(!1),rn(""),Bn(""),jn("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:s("common:cancel")}),r.jsx("button",{onClick:()=>{Mi()},disabled:!Pn.trim()||!as.trim()||!Er||zo,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-on-brand disabled:opacity-40 disabled:cursor-not-allowed",children:s(zo?"common:creating":"common:create")})]})]})}),is&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{qn(null),ls("")},children:r.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${c?"w-full":"w-96"}`,onClick:N=>N.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("work:task.rejectRequirementTitle")}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.rejectReasonLabel")}),r.jsx("textarea",{value:pi,onChange:N=>gi(N.target.value),placeholder:s("work:task.rejectReasonPlaceholder"),rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-red-500 outline-none resize-none",autoFocus:!c})]}),yi&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:yi}),r.jsxs("div",{className:"flex justify-end gap-3",children:[r.jsx("button",{onClick:()=>{qn(null),ls("")},className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated text-fg-secondary",children:s("common:cancel")}),r.jsx("button",{onClick:()=>{ff()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:s("work:task.reject")})]})]})}),Ws&&r.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>vn(!1),children:[r.jsx("div",{className:"absolute inset-0 bg-black/50"}),r.jsxs("div",{className:"relative bg-surface-secondary rounded-t-2xl border-t border-border-default max-h-[70vh] overflow-y-auto pb-16",onClick:N=>N.stopPropagation(),children:[r.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:[r.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:s("work:task.filtersSheetTitle")}),r.jsxs("div",{className:"flex items-center gap-2",children:[(ut.size>0||Nt)&&r.jsx("button",{onClick:()=>{Ht(new Set),St(!1)},className:"text-[11px] text-brand-500 font-medium",children:s("work:task.clearAll")}),r.jsx("button",{onClick:()=>vn(!1),className:"w-7 h-7 flex items-center justify-center rounded-full bg-surface-elevated text-fg-tertiary",children:r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),_.length>0&&r.jsxs("div",{className:"px-4 py-3",children:[r.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:s("work:task.projectsFilterGroup")}),r.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[r.jsxs("button",{type:"button",onClick:()=>{an(),vn(!1)},className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-lg transition-all ${$==="all"&&!V?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[s("work:task.all"),Or>0&&r.jsx("span",{className:"text-[9px] text-fg-tertiary",children:Or})]}),Rr.map(N=>{const Y=V===N.id,Q=Dr[N.id]??0;return r.jsxs("button",{type:"button",onClick:()=>{Xt(N.id),vn(!1)},className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-lg transition-all ${Y?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[r.jsx("span",{className:`w-4 h-4 rounded-sm flex items-center justify-center text-[9px] font-bold shrink-0 ${Y?"bg-brand-600 text-on-brand":"bg-surface-overlay text-fg-tertiary"}`,children:N.name[0]?.toUpperCase()}),N.name,Q>0&&r.jsx("span",{className:"text-[9px] text-fg-tertiary",children:Q})]},N.id)})]})]}),e?.id&&r.jsx("div",{className:"px-4 py-3 border-t border-border-default/40",children:r.jsx("button",{type:"button",onClick:()=>St(N=>!N),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Nt?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:s("work:task.myTasks")})}),_r.length>0&&r.jsxs("div",{className:"px-4 py-3 border-t border-border-default/40",children:[r.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:s("work:task.agentsFilterGroup")}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:_r.map(N=>{if(N.kind==="team"){const ce=N.agentIds.every(De=>ut.has(De)),me=!ce&&N.agentIds.some(De=>ut.has(De));return r.jsxs("button",{onClick:()=>{Ht(De=>{const Ie=new Set(De);if(ce)for(const ae of N.agentIds)Ie.delete(ae);else for(const ae of N.agentIds)Ie.add(ae);return Ie})},className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ce?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":me?"bg-brand-600/10 text-brand-400 ring-1 ring-brand-500/20":"bg-surface-elevated text-fg-secondary"}`,children:[r.jsx("svg",{className:"w-3.5 h-3.5 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:r.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"})}),N.name,r.jsx("span",{className:"text-[9px] text-fg-muted",children:N.agentIds.length})]},`team-${N.id}`)}const Y=N.agent,Q=ut.has(Y.id);return r.jsxs("button",{onClick:()=>_i(Y.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Q?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"bg-surface-elevated text-fg-secondary"}`,children:[r.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${Q?"bg-brand-600 text-on-brand":"bg-surface-overlay text-fg-tertiary"}`,children:Y.name[0]?.toUpperCase()}),Y.name]},Y.id)})})]}),r.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function qb({requirementId:e,createdBy:t,agents:n,users:s,authUser:o}){const{t:a}=Ve(["work","common"]),[i,l]=p.useState([]),[c,d]=p.useState([]),h=p.useRef(null),[u,f]=p.useState(new Map);p.useEffect(()=>{d([]),f(new Map),h.current&&(clearTimeout(h.current),h.current=null),se.requirements.getComments(e).then(k=>l(k.comments)).catch(()=>{})},[e]),p.useEffect(()=>Dt.on("requirement:comment",y=>{if(y.payload?.requirementId===e&&y.payload.comment){const x=y.payload.comment;l(w=>w.some(S=>S.id===x.id)?w:[...w,x]),(x.authorType==="agent"||x.authorId?.startsWith("agt_"))&&(d(w=>{const S=w.filter(j=>j.id!==x.authorId);return S.length===0&&h.current&&(clearTimeout(h.current),h.current=null),S}),f(w=>{const S=new Map(w);return S.delete(x.authorId),S}))}}),[e]),p.useEffect(()=>{if(c.length===0)return;const k=new Set(c.map(x=>x.id));return Dt.on("agent:activity_log",x=>{const w=x.payload;if(!w)return;const S=w.agentId;if(!k.has(S))return;const j=yo(w);j&&f(E=>ui(E,S,j))})},[c]);const[m,g]=p.useState(null),b=async(k,y,x,w)=>{let S;x.length>0&&(S=(await se.uploads.upload(x.map(R=>({dataUrl:R.dataUrl,name:R.name})),"comments")).files.map(R=>({type:"image",url:R.url,name:R.name})));const j=await se.requirements.addComment(e,k,o?.name,S,o?.id,y.length>0?y:void 0,w),E=Ka(j.notifiedAgentIds,n);E.length>0&&(h.current&&clearTimeout(h.current),d(E),h.current=setTimeout(()=>d([]),12e4))},v=p.useCallback(k=>{g({id:k.id,authorName:k.authorName,content:k.content.slice(0,100)})},[]);return r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:i.length>0?a("work:task.commentsWithCount",{count:i.length}):a("work:task.comments")}),r.jsxs("div",{className:"space-y-0.5 mb-3",children:[i.length===0&&r.jsx("p",{className:"text-xs text-fg-tertiary text-center py-4",children:a("work:task.noCommentsYet")}),i.map(k=>r.jsx(Po,{comment:k,agents:n,onReply:v},k.id)),c.length>0&&r.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:c.map(k=>{const y=u.get(k.id)??[];return r.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>tn.navigate(nt.TEAM,{agentId:k.id,profileTab:"mind"}),children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"relative shrink-0",children:[r.jsx(La,{name:k.name,avatarUrl:k.avatarUrl,size:22,bgClass:"bg-brand-500/15 text-brand-600"}),r.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"})]}),r.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:k.name}),y.length===0&&r.jsxs("span",{className:"flex items-center gap-0.5",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:a("work:task.agentProcessing")}),r.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),y.length>0&&r.jsx("div",{className:"ml-8 mt-1",children:r.jsx(fi,{entries:y})})]},k.id)})})]}),r.jsx(Dc,{agents:n,humans:s,onSubmit:b,replyTo:m,onCancelReply:()=>g(null)})]})}function Tc({req:e,agents:t,projects:n,allTasks:s,users:o,onClose:a,onApprove:i,onReject:l,onCancel:c,onStatusChange:d,onRefresh:h,authUser:u,scrollToComments:f,onScrollToCommentsDone:m,onTaskClick:g,onCreateTask:b,onProjectClick:v,previewMode:k}){const{t:y}=Ve(["work","common"]),x=p.useMemo(()=>mi(y),[y]),w=p.useMemo(()=>ef(y),[y]),S=gr(),[j,E]=p.useState(!1),[C,R]=p.useState(e.description),[P,T]=p.useState(!1),[D,z]=p.useState(!1),[I,B]=p.useState(!1);p.useEffect(()=>{if(!I)return;const te=Re=>{Re.key==="Escape"&&B(!1)};return document.addEventListener("keydown",te),()=>document.removeEventListener("keydown",te)},[I]);const[L,q]=p.useState(!1),[_,A]=p.useState(null),[$,F]=p.useState(!1),[V,X]=p.useState(null),O=p.useMemo(()=>s.filter(te=>te.requirementId===e.id&&te.status==="pending").length,[s,e.id]),M=async()=>{X(null),F(!0);try{const te=await se.requirements.approveTasksBulk(e.id,{dryRun:!0});A({phase:"preview",...te})}catch(te){X(te instanceof Error?te.message:String(te))}finally{F(!1)}},K=async()=>{X(null),F(!0);try{const te=await se.requirements.approveTasksBulk(e.id,{runNow:!0});A({phase:"result",...te}),h?.()}catch(te){X(te instanceof Error?te.message:String(te))}finally{F(!1)}},[W,H]=p.useState(!1),Z=p.useRef(null),[J,le]=p.useState("none"),ue=p.useRef(null),pe=p.useRef(null),we=p.useRef(80);p.useEffect(()=>{const te=Z.current;if(!te)return;const Re=()=>{const{scrollTop:mt,scrollHeight:Qe,clientHeight:Ae}=te;if(!(Qe>Ae+50)){le("none");return}const Ge=mt<30,at=mt+Ae>=Qe-30;le(Ge?"top":at?"bottom":"middle")};Re(),te.addEventListener("scroll",Re,{passive:!0});const Ue=new ResizeObserver(Re);return Ue.observe(te),()=>{te.removeEventListener("scroll",Re),Ue.disconnect()}},[]),p.useEffect(()=>{if(j&&pe.current){const te=pe.current;te.style.height="auto",te.style.height=Math.max(te.scrollHeight,we.current)+"px",te.focus()}},[j]),p.useEffect(()=>{if(!f)return;const te=setTimeout(()=>{const Re=Z.current;Re&&Re.scrollTo({top:Re.scrollHeight,behavior:"smooth"}),m?.()},300);return()=>clearTimeout(te)},[f,m]);const Ne=x[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},ke=e.source==="agent",Be=ke&&e.status==="pending",et=e.status==="pending"||e.status==="in_progress",Ee=Hc.has(e.status),Ke=e.projectId?n.find(te=>te.id===e.projectId):null,ot=$s(e.createdBy,t,o)??e.createdBy.slice(0,12),_e=s.filter(te=>e.taskIds.includes(te.id)),re=Ke?.teamIds?.[0]??null;p.useMemo(()=>new Map(_e.map(te=>[te.id,te])),[_e]);const he=_e.length>=2;p.useEffect(()=>{R(e.description),E(!1)},[e.id,e.description]);const[ge,ee]=p.useState(!1),[ne,oe]=p.useState(e.title),[je,ye]=p.useState(!1),[Se,Te]=p.useState((e.tags??[]).join(", ")),st=p.useRef(null);p.useEffect(()=>{oe(e.title),ee(!1)},[e.id,e.title]),p.useEffect(()=>{Te((e.tags??[]).join(", ")),ye(!1)},[e.id,e.tags]),p.useEffect(()=>{ge&&st.current?.focus()},[ge]);const qe=async te=>{try{await se.requirements.update(e.id,te),h?.()}catch{}};return r.jsxs("div",{className:`flex flex-col w-full overflow-hidden bg-surface-primary shadow-xl shadow-black/8 ring-1 ring-border-default/20 ${S?"h-dvh":"h-full"}`,children:[r.jsxs("div",{className:"flex items-start justify-between gap-4 p-5 pb-0 border-b border-border-default",children:[r.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[S&&r.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"15 18 9 12 15 6"})})}),r.jsxs("h2",{className:"flex-1 min-w-0 pb-4 text-lg font-semibold text-fg-primary leading-snug",children:[ge?r.jsx("input",{ref:st,value:ne,onChange:te=>oe(te.target.value),onBlur:()=>{const te=ne.trim();te&&te!==e.title&&qe({title:te}),ee(!1)},onKeyDown:te=>{te.key==="Enter"&&te.target.blur(),te.key==="Escape"&&(oe(e.title),ee(!1))},className:"w-full bg-transparent border-b border-brand-500/40 text-lg font-semibold text-fg-primary focus:border-brand-500 outline-none"}):r.jsx("span",{className:`align-middle rounded px-0.5 -mx-0.5 transition-colors ${Ee?"":"cursor-text hover:bg-surface-elevated/60"}`,onClick:Ee?void 0:()=>ee(!0),role:Ee?void 0:"button",tabIndex:Ee?void 0:0,onKeyDown:Ee?void 0:te=>te.key==="Enter"&&ee(!0),title:Ee?void 0:y("work:task.clickToEdit",{defaultValue:"点击编辑"}),children:e.title})," ",r.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")})," ",r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium align-middle ${Ne.cls}`,children:Ne.label})," ",e.priority==="high"||e.priority==="urgent"?r.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})}):r.jsx("span",{className:"text-[10px] text-fg-tertiary align-middle",children:y("common:priority."+e.priority,{defaultValue:e.priority})})]})]}),r.jsxs("div",{className:"flex items-center gap-2 shrink-0 mb-4",children:[r.jsx(Lc,{onClick:()=>H(!0),label:y("work:task.sendToChat",{defaultValue:"发送到对话"})}),r.jsx("button",{onClick:a,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0",children:"×"})]})]}),W&&r.jsx(Zu,{kind:"requirement",entity:e,agents:t,users:o,projects:n,onClose:()=>H(!1)}),r.jsxs("div",{className:"flex-1 min-h-0 relative",children:[r.jsxs("div",{ref:Z,className:"h-full overflow-y-auto p-5 space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:y("work:task.requirementDetailDescription")}),j?r.jsx("textarea",{ref:pe,value:C,onChange:te=>{R(te.target.value);const Re=te.target;Re.style.height="auto",Re.style.height=Re.scrollHeight+"px"},onBlur:async()=>{if(C!==e.description){T(!0);try{await se.requirements.update(e.id,{description:C}),h?.()}catch{}finally{T(!1)}}E(!1)},onKeyDown:te=>{te.key==="Escape"&&(te.preventDefault(),R(e.description),E(!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")}):r.jsx("div",{ref:ue,className:`group relative rounded-lg -mx-2 px-2 -my-1 py-1 transition-colors ${Ee?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:Ee?void 0:te=>{te.target.closest("a, button, [data-entity-link]")||(we.current=Math.max(ue.current?.offsetHeight??80,60),R(e.description),E(!0))},role:Ee?void 0:"button",tabIndex:Ee?void 0:0,onKeyDown:Ee?void 0:te=>te.key==="Enter"&&(R(e.description),E(!0)),children:e.description?r.jsx(ar,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):r.jsx("p",{className:"text-sm text-fg-tertiary italic",children:y("work:task.requirementNoDescription")})})]}),r.jsxs("div",{className:"border-t border-border-default/60 pt-4",children:[r.jsxs("div",{className:ou,children:[r.jsx("label",{className:lt,children:y("work:task.projectLabel")}),r.jsx(Ft,{size:"sm",disabled:Ee,options:[{value:"",label:y("work:task.noProject")},...n.map(te=>({value:te.id,label:te.name}))],value:e.projectId??"",onChange:te=>{qe({projectId:te||null})},placeholder:y("work:task.noProject"),noMatchesText:y("work:task.noMatches")}),r.jsx("label",{className:lt,children:y("work:task.priority")}),r.jsx(wo,{value:e.priority,onChange:te=>{qe({priority:te})}}),r.jsx("label",{className:lt,children:y("work:task.tagsLabel")}),je&&!Ee?r.jsx("input",{autoFocus:!0,value:Se,onChange:te=>Te(te.target.value),onBlur:()=>{const te=Se.split(",").map(Ue=>Ue.trim()).filter(Boolean),Re=e.tags??[];te.join("\0")!==Re.join("\0")&&qe({tags:te}),ye(!1)},onKeyDown:te=>{te.key==="Enter"&&te.target.blur(),te.key==="Escape"&&(Te((e.tags??[]).join(", ")),ye(!1))},placeholder:y("work:task.tagsPlaceholder"),className:`${xn} !py-1.5 !text-xs`}):r.jsx("div",{className:`flex flex-wrap items-center gap-1.5 rounded-lg -mx-2 px-2 py-1 transition-colors ${Ee?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:Ee?void 0:()=>ye(!0),role:Ee?void 0:"button",tabIndex:Ee?void 0:0,onKeyDown:Ee?void 0:te=>te.key==="Enter"&&ye(!0),children:e.tags&&e.tags.length>0?e.tags.map(te=>r.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",te]},te)):r.jsx("span",{className:"text-xs text-fg-tertiary italic",children:y("work:task.noTags")})})]}),r.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-x-4 gap-y-1 text-[11px] text-fg-tertiary",children:[r.jsxs("span",{children:[y("work:task.createdByLabel"),": ",r.jsx("span",{className:"text-fg-secondary",children:ot}),ke&&r.jsx("span",{className:"text-brand-500 ml-1",children:y("work:task.agentTag")})]}),r.jsx("span",{children:new Date(e.createdAt).toLocaleString()}),v&&Ke&&r.jsxs("button",{onClick:()=>v(Ke.id),className:"hover:text-fg-secondary transition-colors",children:[y("work:task.projectLabel"),": ",Ke.name]}),e.approvedBy&&r.jsxs("span",{children:[y("work:task.approvedBy"),": ",r.jsx("span",{className:"text-fg-secondary",children:$s(e.approvedBy,t,o)??e.approvedBy.slice(0,12)}),e.approvedAt&&r.jsx("span",{className:"ml-1",children:new Date(e.approvedAt).toLocaleDateString()})]})]})]}),e.rejectedReason&&r.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[r.jsx("span",{className:"text-[10px] font-semibold text-red-500 uppercase tracking-wider block mb-1",children:y("work:task.rejectionReason")}),r.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),e.goalConfig?.loopEnabled&&r.jsxs("div",{className:"bg-brand-500/8 border border-brand-500/20 rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx("span",{className:"text-[10px] font-semibold text-brand-500 uppercase tracking-wider",children:y("work:requirement.goal")}),r.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")})]}),r.jsx("p",{className:"text-xs text-fg-secondary mb-2",children:e.goalConfig.completionCriteria}),r.jsxs("div",{className:"flex items-center gap-4 text-[10px] text-fg-tertiary",children:[r.jsx("span",{children:y("work:requirement.goalIteration",{current:e.goalConfig.currentIteration,max:e.goalConfig.maxIterations})}),e.goalConfig.lastCheckedAt&&r.jsx("span",{children:y("work:requirement.goalLastChecked",{time:new Date(e.goalConfig.lastCheckedAt).toLocaleString()})}),e.goalConfig.autoResume&&r.jsx("span",{className:"text-brand-500",children:y("work:requirement.goalAutoResume")})]})]}),Array.isArray(e.tags)&&e.tags.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(te=>r.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",te]},te))}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:y("work:task.linkedTasks",{count:_e.length})}),r.jsxs("div",{className:"flex items-center gap-2",children:[he&&re&&r.jsxs("button",{onClick:()=>q(!0),className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium flex items-center gap-1",children:[r.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.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")]}),!Ee&&b&&r.jsxs("button",{onClick:()=>b(e.id,e.projectId),className:"text-[11px] text-amber-500 hover:text-amber-400 font-medium flex items-center gap-1",children:[r.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),y("work:requirement.createTask")]})]})]}),_e.length>0?(()=>{const te=new Map(_e.map(Pe=>[Pe.id,Pe]));if(!_e.some(Pe=>Pe.blockedBy?.some(Ge=>te.has(Ge))))return r.jsx("div",{className:"space-y-1.5",children:_e.map(Pe=>{const Ge=w[Pe.status];return r.jsxs("div",{onClick:()=>g?.(Pe),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${g?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Qn[Pe.status]??"bg-gray-500"}`}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:Pe.title}),Ge&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Ge.cls}`,children:Ge.label})]},Pe.id)})});const Ue=new Map,mt=new Set;for(const Pe of _e)for(const Ge of Pe.blockedBy??[])if(te.has(Ge)){mt.add(Pe.id);const at=Ue.get(Ge)??[];at.push(Pe.id),Ue.set(Ge,at)}const Qe=_e.filter(Pe=>!mt.has(Pe.id)),Ae=(Pe,Ge)=>{const at=w[Pe.status],G=(Ue.get(Pe.id)??[]).map(ie=>te.get(ie)).filter(Boolean);return r.jsxs("div",{children:[r.jsxs("div",{onClick:()=>g?.(Pe),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${g?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,style:Ge>0?{marginLeft:Ge*20}:void 0,children:[Ge>0&&r.jsx("span",{className:"text-fg-muted text-[10px] shrink-0",children:"↳"}),r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Qn[Pe.status]??"bg-gray-500"}`}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:Pe.title}),at&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${at.cls}`,children:at.label})]}),G.map(ie=>Ae(ie,Ge+1))]},Pe.id)};return r.jsx("div",{className:"space-y-1.5",children:Qe.map(Pe=>Ae(Pe,0))})})():r.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:y("work:requirement.noLinkedTasks")})]}),!k&&r.jsx(qb,{requirementId:e.id,createdBy:e.createdBy,agents:t,users:o,authUser:u}),!k&&r.jsx(sf,{entityType:"requirement",entityId:e.id})]}),J!=="none"&&J!=="top"&&r.jsx("button",{onClick:()=>Z.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-on-brand hover:bg-brand-400 transition-colors backdrop-blur-sm",title:y("work:task.scrollToTop"),children:r.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:r.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),J!=="none"&&J!=="bottom"&&r.jsx("button",{onClick:()=>{const te=Z.current;te&&te.scrollTo({top:te.scrollHeight,behavior:"smooth"})},className:"absolute bottom-6 right-4 md:bottom-4 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-on-brand hover:bg-brand-400 transition-colors backdrop-blur-sm",title:y("work:task.scrollToBottom"),children:r.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:r.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"})})})]}),r.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[O>0&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{M()},disabled:$,className:"px-3 py-2 bg-brand-600 hover:bg-brand-500 text-on-brand text-sm rounded-lg font-medium transition-colors disabled:opacity-60",children:y("work:requirement.bulkApprove","批量批准待批任务 ({{count}})",{count:O})}),_&&r.jsx("div",{className:"fixed inset-0 z-[10050] flex items-center justify-center bg-black/60 p-4",onClick:()=>{$||A(null)},children:r.jsxs("div",{className:"w-full max-w-lg max-h-[80vh] flex flex-col rounded-2xl border border-border-default bg-surface-primary shadow-2xl overflow-hidden",onClick:te=>te.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":y("work:requirement.bulkApproveTitle","批量批准待批任务"),children:[r.jsxs("div",{className:"px-5 pt-4 pb-3 border-b border-border-default shrink-0",children:[r.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:_.phase==="preview"?y("work:requirement.bulkApproveTitle","批量批准待批任务"):y("work:requirement.bulkApproveDone","批量批准结果")}),_.phase==="preview"&&r.jsx("p",{className:"mt-1 text-xs text-amber-600 dark:text-amber-400 leading-relaxed",children:y("work:requirement.bulkApproveWarning","批准后立即开始执行:将同时启动 {{count}} 个任务,各自占用对应 agent。",{count:_.approved.length})}),_.phase==="result"&&r.jsx("p",{className:"mt-1 text-xs text-fg-secondary",children:y("work:requirement.bulkApproveSummary","成功 {{ok}} · 跳过 {{skip}} · 失败 {{fail}}",{ok:_.approved.length,skip:_.skipped.length,fail:_.failed.length})})]}),r.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-3 space-y-3",children:[_.approved.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary mb-1",children:_.phase==="preview"?y("work:requirement.bulkApproveWillApprove","将批准"):y("work:requirement.bulkApproveApproved","已批准")}),r.jsx("ul",{className:"space-y-0.5",children:_.approved.map(te=>r.jsxs("li",{className:"text-xs text-fg-secondary truncate",children:["· ",te.title]},te.id))})]}),_.skipped.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary mb-1",children:y("work:requirement.bulkApproveSkipped","跳过(不满足批准条件)")}),r.jsx("ul",{className:"space-y-0.5",children:_.skipped.map(te=>r.jsxs("li",{className:"text-xs text-fg-tertiary truncate",children:["· ",te.title||te.id," — ",te.reason]},te.id))})]}),_.failed.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-red-500 mb-1",children:y("work:requirement.bulkApproveFailed","失败")}),r.jsx("ul",{className:"space-y-0.5",children:_.failed.map(te=>r.jsxs("li",{className:"text-xs text-red-500 truncate",children:["· ",te.title," — ",te.error]},te.id))})]}),_.approved.length===0&&_.skipped.length===0&&r.jsx("p",{className:"text-xs text-fg-tertiary",children:y("work:requirement.bulkApproveNothing","没有可批准的待批任务。")}),V&&r.jsx("p",{className:"text-xs text-red-500",children:V})]}),r.jsxs("div",{className:"px-5 py-3 border-t border-border-default flex justify-end gap-2 shrink-0",children:[r.jsx("button",{onClick:()=>A(null),disabled:$,className:"px-3 py-1.5 text-xs rounded-lg border border-border-default text-fg-secondary hover:bg-surface-elevated transition-colors disabled:opacity-60",children:_.phase==="preview"?y("common:cancel"):y("common:close")}),_.phase==="preview"&&r.jsx("button",{onClick:()=>{K()},disabled:$||_.approved.length===0,className:"px-3 py-1.5 text-xs rounded-lg bg-green-600 hover:bg-green-500 text-white font-medium transition-colors disabled:opacity-60",children:$?y("work:requirement.bulkApproving","批准中…"):y("work:requirement.bulkApproveConfirm","确认批准并开始")})]})]})})]}),Be&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>i(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")}),r.jsx("button",{onClick:()=>l(e.id),className:"px-4 py-2 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-sm rounded-lg font-medium transition-colors",children:y("work:requirement.rejectRequirement")})]}),!Be&&d&&!Ee&&r.jsxs("div",{className:"relative",children:[r.jsxs("button",{type:"button",onClick:()=>B(te=>!te),"aria-haspopup":"menu","aria-expanded":I,"aria-label":y("work:requirement.changeStatus","切换状态"),"data-testid":"requirement-status-menu",className:"inline-flex items-center gap-1.5 px-2.5 py-1.5 text-xs rounded-lg bg-surface-elevated border border-border-default text-fg-secondary hover:border-gray-500 hover:text-fg-primary transition-colors",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Qn[e.status]??"bg-fg-muted"}`,"aria-hidden":"true"}),x[e.status]?.label??e.status,r.jsx("svg",{className:"w-3 h-3 text-fg-tertiary",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M18 15l-6-6-6 6"})})]}),I&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fixed inset-0 z-20",onClick:()=>B(!1),"aria-hidden":"true"}),r.jsx("div",{role:"menu",className:"absolute bottom-full left-0 mb-1 z-30 w-52 overflow-hidden rounded-xl border border-border-default bg-surface-secondary py-1 shadow-xl",children:(()=>{const te=[...Ta[e.status]??[]].filter(Re=>Re!=="cancelled"&&!(Be&&Re==="rejected"));return te.length===0?r.jsx("p",{className:"px-3 py-2 text-[11px] text-fg-tertiary",children:y("work:requirement.noStatusChange","暂无可用状态变更")}):te.map(Re=>r.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{B(!1),d(e.id,Re)},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-secondary transition-colors hover:bg-surface-elevated hover:text-fg-primary focus:bg-surface-elevated focus:outline-none",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Qn[Re]??"bg-fg-muted"}`,"aria-hidden":"true"}),r.jsx("span",{className:"flex-1",children:x[Re]?.label??Re}),Re==="completed"&&r.jsx("span",{className:"text-[10px] text-fg-muted",children:y("work:requirement.terminalHint","终态")})]},Re))})()})]})]}),Ee&&d&&r.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")}),r.jsx("div",{className:"flex-1"}),et&&!Be&&r.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")})]}),D&&r.jsx(ys,{title:y("work:requirement.cancelConfirmTitle","Cancel Requirement"),message:y("work:requirement.cancelConfirmMessage","Are you sure you want to cancel this requirement? This action cannot be undone."),confirmLabel:y("work:requirement.cancelConfirmLabel","Cancel Requirement"),onConfirm:()=>{z(!1),c(e.id)},onCancel:()=>z(!1)}),L&&re&&r.jsx(Pb,{req:e,tasks:_e,agents:t,teamId:re,onClose:()=>q(!1),onSaved:()=>q(!1)})]})}function sf({entityType:e,entityId:t}){const{t:n}=Ve(["work"]),[s,o]=p.useState([]),[a,i]=p.useState(!0),[l,c]=p.useState(!1);if(p.useEffect(()=>{i(!0),(e==="task"?se.tasks.getHistory:se.requirements.getHistory)(t).then(m=>o(m.history)).catch(()=>o([])).finally(()=>i(!1))},[e,t]),a)return r.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary",children:n("work:task.loadingHistory","Loading history...")});if(s.length===0)return r.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary italic",children:n("work:task.noHistory","No status change history.")});const d=l?s:s.slice(-5),h=s.length>5&&!l,u=f=>{const m=f.changedByName||f.changedById||(f.changedByType==="human"?"User":f.changedByType==="agent"?"Agent":"System"),g=f.changedByType==="human"?"bg-blue-500/20 text-blue-500":f.changedByType==="agent"?"bg-brand-500/20 text-brand-500":"bg-gray-500/20 text-fg-tertiary";return r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium shrink-0 ${g}`,children:m})};return r.jsxs("div",{className:"px-6 py-4",children:[r.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider mb-3",children:n("work:task.statusHistory","Status History")}),h&&r.jsx("button",{onClick:()=>c(!0),className:"text-[11px] text-brand-500 hover:underline mb-2",children:n("work:task.showAllHistory",{count:s.length})}),r.jsxs("div",{className:"relative ml-2",children:[r.jsx("div",{className:"absolute left-[2.5px] top-1 bottom-1 w-px bg-border-default"}),r.jsx("div",{className:"space-y-3",children:d.map(f=>r.jsxs("div",{className:"flex items-start gap-3 relative",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full mt-[7px] shrink-0 relative z-10",style:{background:f.changedByType==="human"?"#3b82f6":f.changedByType==="agent"?"var(--color-brand-500)":"#6b7280"}}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[u(f),r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary line-through",children:f.fromStatus}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"→"}),r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-brand-500/15 text-brand-500 font-medium",children:f.toStatus})]}),f.reason&&r.jsx("p",{className:"text-[10px] text-fg-secondary mt-0.5 leading-snug",children:f.reason}),r.jsx("p",{className:"text-[9px] text-fg-tertiary mt-0.5",children:new Date(f.createdAt).toLocaleString()})]})]},f.id))})]})]})}export{Xb as WorkPage,Bb as WorkflowsPanel};
|