@markus-global/cli 0.12.0 → 0.12.1-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/approval-card.d.ts +22 -1
- package/dist/commands/approval-card.d.ts.map +1 -1
- package/dist/commands/approval-card.js +25 -1
- package/dist/commands/approval-card.js.map +1 -1
- package/dist/commands/outbound.d.ts +8 -1
- package/dist/commands/outbound.d.ts.map +1 -1
- package/dist/commands/outbound.js +1 -0
- package/dist/commands/outbound.js.map +1 -1
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +93 -7
- package/dist/commands/start.js.map +1 -1
- package/dist/markus.mjs +1906 -964
- package/dist/web-ui/assets/{AsyncState-Czik5FUM.js → AsyncState-BE4ycfHk.js} +1 -1
- package/dist/web-ui/assets/{CommentInput-BsaOrj2g.js → CommentInput-DQIh2AYB.js} +1 -1
- package/dist/web-ui/assets/{ContentRenderer-Cl9-dJ-4.js → ContentRenderer-C0L1YkNl.js} +2 -2
- package/dist/web-ui/assets/{DeliverableShareModal-wgdeaboz.js → DeliverableShareModal-KlLlP9Fe.js} +1 -1
- package/dist/web-ui/assets/{Deliverables-Czrn3ezy.js → Deliverables-CiqT2Ipg.js} +1 -1
- package/dist/web-ui/assets/{Notifications-BoxombIH.js → Notifications-82rU7lAf.js} +1 -1
- package/dist/web-ui/assets/{Search-D9FOOaVc.js → Search-CNNN3duL.js} +1 -1
- package/dist/web-ui/assets/SendToChat-EsNVdiYI.js +1 -0
- package/dist/web-ui/assets/Settings-COmJTMaX.js +8 -0
- package/dist/web-ui/assets/{Store-CVTUuEyr.js → Store-Cb-RBY68.js} +1 -1
- package/dist/web-ui/assets/{Switch-CJm0Y6Ab.js → Switch-SqNs6-fd.js} +1 -1
- package/dist/web-ui/assets/{Team-CnQniCUA.js → Team-DA5MQ-20.js} +31 -31
- package/dist/web-ui/assets/Work-D4noaLBo.js +142 -0
- package/dist/web-ui/assets/{arc-BLg_pCBM.js → arc-BOFJ1EJN.js} +1 -1
- package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-Cmx-kPk8.js → architectureDiagram-3BPJPVTR-BQ0qr0Vl.js} +1 -1
- package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-C7M18dlD.js → blockDiagram-GPEHLZMM-kSXlCE5q.js} +1 -1
- package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-Cfwl8fbI.js → c4Diagram-AAUBKEIU-kCxqEGe5.js} +1 -1
- package/dist/web-ui/assets/channel-MEPTI8rz.js +1 -0
- package/dist/web-ui/assets/{chunk-2J33WTMH-C5mU_TTU.js → chunk-2J33WTMH-BgMluOvE.js} +1 -1
- package/dist/web-ui/assets/{chunk-4BX2VUAB-CQCbo-ag.js → chunk-4BX2VUAB-tu9bzY5y.js} +1 -1
- package/dist/web-ui/assets/{chunk-55IACEB6-4c3wqJwT.js → chunk-55IACEB6-DK9D0I2N.js} +1 -1
- package/dist/web-ui/assets/{chunk-727SXJPM-DXdlGwqz.js → chunk-727SXJPM-D_5Cdc0d.js} +1 -1
- package/dist/web-ui/assets/{chunk-AQP2D5EJ-K192souI.js → chunk-AQP2D5EJ-BUmO_w99.js} +1 -1
- package/dist/web-ui/assets/{chunk-FMBD7UC4-D5Q3CYrz.js → chunk-FMBD7UC4-Ck9FWl7n.js} +1 -1
- package/dist/web-ui/assets/{chunk-ND2GUHAM-qNuRMI8p.js → chunk-ND2GUHAM-Mvxy6fm4.js} +1 -1
- package/dist/web-ui/assets/{chunk-QZHKN3VN-BkmKoVv4.js → chunk-QZHKN3VN-C9xMd3WM.js} +1 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-C-iFEC5t.js +1 -0
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-C-iFEC5t.js +1 -0
- package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-Cc-LCylz.js → cose-bilkent-S5V4N54A-CUTkidkC.js} +1 -1
- package/dist/web-ui/assets/{dagre-BM42HDAG-CcbGFoMh.js → dagre-BM42HDAG-CGLda2Em.js} +1 -1
- package/dist/web-ui/assets/{diagram-2AECGRRQ-BMK1aNmF.js → diagram-2AECGRRQ-DRl88ns2.js} +1 -1
- package/dist/web-ui/assets/{diagram-5GNKFQAL-DLZ1Dlob.js → diagram-5GNKFQAL-rf4YhM9A.js} +1 -1
- package/dist/web-ui/assets/{diagram-KO2AKTUF-DgF4N3Vp.js → diagram-KO2AKTUF-BD8mjYi6.js} +1 -1
- package/dist/web-ui/assets/{diagram-LMA3HP47-Dj6Rsgtz.js → diagram-LMA3HP47-DiZICe4t.js} +1 -1
- package/dist/web-ui/assets/{diagram-OG6HWLK6-B33vd8GS.js → diagram-OG6HWLK6-Dj0Mw95G.js} +1 -1
- package/dist/web-ui/assets/{docx-preview-Cbe9vyIJ.js → docx-preview-DQSKxlsK.js} +1 -1
- package/dist/web-ui/assets/{erDiagram-TEJ5UH35-C0ArR1aG.js → erDiagram-TEJ5UH35-BQq31SZZ.js} +1 -1
- package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-wdN-ujEZ.js → flowDiagram-I6XJVG4X-Cc82cW20.js} +1 -1
- package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-BUKw6wm1.js → ganttDiagram-6RSMTGT7-D1MzI2Uw.js} +1 -1
- package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-DU3TBBvN.js → gitGraphDiagram-PVQCEYII-D1v-40GN.js} +1 -1
- package/dist/web-ui/assets/index-B0GCqbye.css +1 -0
- package/dist/web-ui/assets/{index-Ci5bUF3m.js → index-BXWHxoXp.js} +61 -61
- package/dist/web-ui/assets/{infoDiagram-5YYISTIA-Dk634Bq4.js → infoDiagram-5YYISTIA-COPRgK1x.js} +1 -1
- package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-BE5upFcq.js → ishikawaDiagram-YF4QCWOH-BmrWPE_9.js} +1 -1
- package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-C_fU89IU.js → journeyDiagram-JHISSGLW-C7WKxQjK.js} +1 -1
- package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-DCPTTiVV.js → kanban-definition-UN3LZRKU-yNU5HtNI.js} +1 -1
- package/dist/web-ui/assets/{linear-D1g5s_fh.js → linear-BITZw-sC.js} +1 -1
- package/dist/web-ui/assets/{mermaid.core-CwgDshh9.js → mermaid.core-B-JixiD0.js} +5 -5
- package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-B1O4o7mE.js → mindmap-definition-RKZ34NQL-CIC2Ov1E.js} +1 -1
- package/dist/web-ui/assets/{pieDiagram-4H26LBE5-HKc1yZ37.js → pieDiagram-4H26LBE5-CJn4Ut9d.js} +1 -1
- package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-DSJ8Nt1Y.js → quadrantDiagram-W4KKPZXB-DcRyVlzO.js} +1 -1
- package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-Bnk4zXkX.js → requirementDiagram-4Y6WPE33-DiNbCJGt.js} +1 -1
- package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-DW5T8bfU.js → sankeyDiagram-5OEKKPKP-RHicfbUP.js} +1 -1
- package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-D80T-VQ2.js → sequenceDiagram-3UESZ5HK-P1XTa1MM.js} +1 -1
- package/dist/web-ui/assets/{stateDiagram-AJRCARHV-DbMI2WnT.js → stateDiagram-AJRCARHV-Dbu2PX-0.js} +1 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-BVoD4Uz4.js +1 -0
- package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-m1796nxN.js → timeline-definition-PNZ67QCA-DGJ5VfHk.js} +1 -1
- package/dist/web-ui/assets/{transform-CpIVI4vC.js → transform-BqqRT-Iy.js} +1 -1
- package/dist/web-ui/assets/{value-DIujSiJ7.js → value-wA6veExk.js} +1 -1
- package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-uQ9kkGtM.js → vennDiagram-CIIHVFJN-B9fLD2oz.js} +1 -1
- package/dist/web-ui/assets/{wardley-L42UT6IY-Bwp548d-.js → wardley-L42UT6IY-CH2NYUlK.js} +1 -1
- package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-D1Dcm5Tb.js → wardleyDiagram-YWT4CUSO-efQZMvBj.js} +1 -1
- package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-CRhoH3Re.js → xychartDiagram-2RQKCTM6-BNcrfIXF.js} +1 -1
- package/dist/web-ui/index.html +2 -2
- package/docs/analysis/2026-10-29-a2a-cache-hit-rate.md +347 -0
- package/docs/architecture/concurrent-processing.md +9 -1
- package/docs/architecture/notify-user-context-truth.md +91 -0
- package/package.json +1 -1
- package/dist/web-ui/assets/SendToChat-D95-I-fu.js +0 -1
- package/dist/web-ui/assets/Settings-DvknF2D-.js +0 -8
- package/dist/web-ui/assets/Work-Dmxua6PP.js +0 -12
- package/dist/web-ui/assets/channel-0w5HoIsN.js +0 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-C7BIpwAA.js +0 -1
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-C7BIpwAA.js +0 -1
- package/dist/web-ui/assets/index-D4zDaGe4.css +0 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-BxYWXdlm.js +0 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import{u as ze,j as r,b9 as mf,ba as pf,y as gf,bb as xf,r as p,l as ne,Y as bf,a as hr,k as yf,n as en,P as Ze,Z as jc,b as wf,c as kf,m as vf,s as Pi,bc as jf,bd as Nf,w as Ht,aN as zt,be as Pr,p as Br,M as Sf,i as Cf,C as gs,q as rr,d as Ef,bf as Nc,A as Ea,af as Bi,bg as zi,bh as qi,O as Tf,ad as Sc,bi as If,bj as Mf,bk as Cc,bl as Af,ae as Lf}from"./index-BXWHxoXp.js";import{S as Ec,a as Tc,r as Ic,s as _f}from"./SendToChat-EsNVdiYI.js";import{L as Rf,P as Df}from"./AsyncState-BE4ycfHk.js";import{ContentRenderer as Of}from"./ContentRenderer-C0L1YkNl.js";import{s as qt,g as Mc,j as Ta,T as Ho,k as Wo,t as $f}from"./transform-BqqRT-Iy.js";import{i as Vo}from"./value-wA6veExk.js";import{C as Ac}from"./CommentInput-DQIh2AYB.js";function Pf(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Zt(e,t){if(e=Pf(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 Bf={passive:!1},or={capture:!0,passive:!1};function Ko(e){e.stopImmediatePropagation()}function js(e){e.preventDefault(),e.stopImmediatePropagation()}function Lc(e){var t=e.document.documentElement,n=qt(e).on("dragstart.drag",js,or);"onselectstart"in t?n.on("selectstart.drag",js,or):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function _c(e,t){var n=e.document.documentElement,s=qt(e).on("dragstart.drag",null);t&&(s.on("click.drag",js,or),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 da(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}})}da.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function zf(e){return!e.ctrlKey&&!e.button}function qf(){return this.parentNode}function Ff(e,t){return t??{x:e.x,y:e.y}}function Hf(){return navigator.maxTouchPoints||"ontouchstart"in this}function Rc(){var e=zf,t=qf,n=Ff,s=Hf,o={},a=Mc("start","drag","end"),i=0,l,c,d,h,u=0;function f(w){w.on("mousedown.drag",m).filter(s).on("touchstart.drag",k).on("touchmove.drag",v,Bf).on("touchend.drag touchcancel.drag",b).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function m(w,N){if(!(h||!e.call(this,w,N))){var j=x(this,t.call(this,w,N),w,N,"mouse");j&&(qt(w.view).on("mousemove.drag",g,or).on("mouseup.drag",y,or),Lc(w.view),Ko(w),d=!1,l=w.clientX,c=w.clientY,j("start",w))}}function g(w){if(js(w),!d){var N=w.clientX-l,j=w.clientY-c;d=N*N+j*j>u}o.mouse("drag",w)}function y(w){qt(w.view).on("mousemove.drag mouseup.drag",null),_c(w.view,d),js(w),o.mouse("end",w)}function k(w,N){if(e.call(this,w,N)){var j=w.changedTouches,E=t.call(this,w,N),C=j.length,D,_;for(D=0;D<C;++D)(_=x(this,E,w,N,j[D].identifier,j[D]))&&(Ko(w),_("start",w,j[D]))}}function v(w){var N=w.changedTouches,j=N.length,E,C;for(E=0;E<j;++E)(C=o[N[E].identifier])&&(js(w),C("drag",w,N[E]))}function b(w){var N=w.changedTouches,j=N.length,E,C;for(h&&clearTimeout(h),h=setTimeout(function(){h=null},500),E=0;E<j;++E)(C=o[N[E].identifier])&&(Ko(w),C("end",w,N[E]))}function x(w,N,j,E,C,D){var _=a.copy(),I=Zt(D||j,N),O,q,T;if((T=n.call(w,new da("beforestart",{sourceEvent:j,target:f,identifier:C,active:i,x:I[0],y:I[1],dx:0,dy:0,dispatch:_}),E))!=null)return O=T.x-I[0]||0,q=T.y-I[1]||0,function B(L,z,R){var A=I,$;switch(L){case"start":o[C]=B,$=i++;break;case"end":delete o[C],--i;case"drag":I=Zt(R||z,N),$=i;break}_.call(L,w,new da(L,{sourceEvent:z,subject:T,target:f,identifier:C,active:$,x:I[0]+O,y:I[1]+q,dx:I[0]-A[0],dy:I[1]-A[1],dispatch:_}),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 Wf=1e-12;function Fi(e){return((e=Math.exp(e))+1/e)/2}function Vf(e){return((e=Math.exp(e))-1/e)/2}function Kf(e){return((e=Math.exp(2*e))-1)/(e+1)}const no=(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,y=m*m+g*g,k,v;if(y<Wf)v=Math.log(f/d)/t,k=function(E){return[l+E*m,c+E*g,d*Math.exp(t*E*v)]};else{var b=Math.sqrt(y),x=(f*f-d*d+s*y)/(2*d*n*b),w=(f*f-d*d-s*y)/(2*f*n*b),N=Math.log(Math.sqrt(x*x+1)-x),j=Math.log(Math.sqrt(w*w+1)-w);v=(j-N)/t,k=function(E){var C=E*v,D=Fi(N),_=d/(n*b)*(D*Kf(t*C+N)-Vf(N));return[l+_*m,c+_*g,d*D/Fi(t*C+N)]}}return k.duration=v*1e3*t/Math.SQRT2,k}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),qr=e=>()=>e;function Uf(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 Uo(e){e.stopImmediatePropagation()}function Zs(e){e.preventDefault(),e.stopImmediatePropagation()}function Yf(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Gf(){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 Hi(){return this.__zoom||Ta}function Xf(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Zf(){return navigator.maxTouchPoints||"ontouchstart"in this}function Qf(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 Dc(){var e=Yf,t=Gf,n=Qf,s=Xf,o=Zf,a=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],l=250,c=no,d=Mc("start","zoom","end"),h,u,f,m=500,g=150,y=0,k=10;function v(T){T.property("__zoom",Hi).on("wheel.zoom",C,{passive:!1}).on("mousedown.zoom",D).on("dblclick.zoom",_).filter(o).on("touchstart.zoom",I).on("touchmove.zoom",O).on("touchend.zoom touchcancel.zoom",q).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}v.transform=function(T,B,L,z){var R=T.selection?T.selection():T;R.property("__zoom",Hi),T!==R?N(T,B,L,z):R.interrupt().each(function(){j(this,arguments).event(z).start().zoom(null,typeof B=="function"?B.apply(this,arguments):B).end()})},v.scaleBy=function(T,B,L,z){v.scaleTo(T,function(){var R=this.__zoom.k,A=typeof B=="function"?B.apply(this,arguments):B;return R*A},L,z)},v.scaleTo=function(T,B,L,z){v.transform(T,function(){var R=t.apply(this,arguments),A=this.__zoom,$=L==null?w(R):typeof L=="function"?L.apply(this,arguments):L,F=A.invert($),W=typeof B=="function"?B.apply(this,arguments):B;return n(x(b(A,W),$,F),R,i)},L,z)},v.translateBy=function(T,B,L,z){v.transform(T,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,z)},v.translateTo=function(T,B,L,z,R){v.transform(T,function(){var A=t.apply(this,arguments),$=this.__zoom,F=z==null?w(A):typeof z=="function"?z.apply(this,arguments):z;return n(Ta.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)},z,R)};function b(T,B){return B=Math.max(a[0],Math.min(a[1],B)),B===T.k?T:new Ho(B,T.x,T.y)}function x(T,B,L){var z=B[0]-L[0]*T.k,R=B[1]-L[1]*T.k;return z===T.x&&R===T.y?T:new Ho(T.k,z,R)}function w(T){return[(+T[0][0]+ +T[1][0])/2,(+T[0][1]+ +T[1][1])/2]}function N(T,B,L,z){T.on("start.zoom",function(){j(this,arguments).event(z).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event(z).end()}).tween("zoom",function(){var R=this,A=arguments,$=j(R,A).event(z),F=t.apply(R,A),W=L==null?w(F):typeof L=="function"?L.apply(R,A):L,X=Math.max(F[1][0]-F[0][0],F[1][1]-F[0][1]),P=R.__zoom,M=typeof B=="function"?B.apply(R,A):B,K=c(P.invert(W).concat(X/P.k),M.invert(W).concat(X/M.k));return function(V){if(V===1)V=M;else{var H=K(V),Z=X/H[2];V=new Ho(Z,W[0]-H[0]*Z,W[1]-H[1]*Z)}$.zoom(null,V)}})}function j(T,B,L){return!L&&T.__zooming||new E(T,B)}function E(T,B){this.that=T,this.args=B,this.active=0,this.sourceEvent=null,this.extent=t.apply(T,B),this.taps=0}E.prototype={event:function(T){return T&&(this.sourceEvent=T),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(T,B){return this.mouse&&T!=="mouse"&&(this.mouse[1]=B.invert(this.mouse[0])),this.touch0&&T!=="touch"&&(this.touch0[1]=B.invert(this.touch0[0])),this.touch1&&T!=="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(T){var B=qt(this.that).datum();d.call(T,this.that,new Uf(T,{sourceEvent:this.sourceEvent,target:v,transform:this.that.__zoom,dispatch:d}),B)}};function C(T,...B){if(!e.apply(this,arguments))return;var L=j(this,B).event(T),z=this.__zoom,R=Math.max(a[0],Math.min(a[1],z.k*Math.pow(2,s.apply(this,arguments)))),A=Zt(T);if(L.wheel)(L.mouse[0][0]!==A[0]||L.mouse[0][1]!==A[1])&&(L.mouse[1]=z.invert(L.mouse[0]=A)),clearTimeout(L.wheel);else{if(z.k===R)return;L.mouse=[A,z.invert(A)],Wo(this),L.start()}Zs(T),L.wheel=setTimeout($,g),L.zoom("mouse",n(x(b(z,R),L.mouse[0],L.mouse[1]),L.extent,i));function $(){L.wheel=null,L.end()}}function D(T,...B){if(f||!e.apply(this,arguments))return;var L=T.currentTarget,z=j(this,B,!0).event(T),R=qt(T.view).on("mousemove.zoom",W,!0).on("mouseup.zoom",X,!0),A=Zt(T,L),$=T.clientX,F=T.clientY;Lc(T.view),Uo(T),z.mouse=[A,this.__zoom.invert(A)],Wo(this),z.start();function W(P){if(Zs(P),!z.moved){var M=P.clientX-$,K=P.clientY-F;z.moved=M*M+K*K>y}z.event(P).zoom("mouse",n(x(z.that.__zoom,z.mouse[0]=Zt(P,L),z.mouse[1]),z.extent,i))}function X(P){R.on("mousemove.zoom mouseup.zoom",null),_c(P.view,z.moved),Zs(P),z.event(P).end()}}function _(T,...B){if(e.apply(this,arguments)){var L=this.__zoom,z=Zt(T.changedTouches?T.changedTouches[0]:T,this),R=L.invert(z),A=L.k*(T.shiftKey?.5:2),$=n(x(b(L,A),z,R),t.apply(this,B),i);Zs(T),l>0?qt(this).transition().duration(l).call(N,$,z,T):qt(this).call(v.transform,$,z,T)}}function I(T,...B){if(e.apply(this,arguments)){var L=T.touches,z=L.length,R=j(this,B,T.changedTouches.length===z).event(T),A,$,F,W;for(Uo(T),$=0;$<z;++$)F=L[$],W=Zt(F,this),W=[W,this.__zoom.invert(W),F.identifier],R.touch0?!R.touch1&&R.touch0[2]!==W[2]&&(R.touch1=W,R.taps=0):(R.touch0=W,A=!0,R.taps=1+!!h);h&&(h=clearTimeout(h)),A&&(R.taps<2&&(u=W[0],h=setTimeout(function(){h=null},m)),Wo(this),R.start())}}function O(T,...B){if(this.__zooming){var L=j(this,B).event(T),z=T.changedTouches,R=z.length,A,$,F,W;for(Zs(T),A=0;A<R;++A)$=z[A],F=Zt($,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],P=L.touch0[1],M=L.touch1[0],K=L.touch1[1],V=(V=M[0]-X[0])*V+(V=M[1]-X[1])*V,H=(H=K[0]-P[0])*H+(H=K[1]-P[1])*H;$=b($,Math.sqrt(V/H)),F=[(X[0]+M[0])/2,(X[1]+M[1])/2],W=[(P[0]+K[0])/2,(P[1]+K[1])/2]}else if(L.touch0)F=L.touch0[0],W=L.touch0[1];else return;L.zoom("touch",n(x($,F,W),L.extent,i))}}function q(T,...B){if(this.__zooming){var L=j(this,B).event(T),z=T.changedTouches,R=z.length,A,$;for(Uo(T),f&&clearTimeout(f),f=setTimeout(function(){f=null},m),A=0;A<R;++A)$=z[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&&($=Zt($,this),Math.hypot(u[0]-$[0],u[1]-$[1])<k)){var F=qt(this).on("dblclick.zoom");F&&F.apply(this,arguments)}}}return v.wheelDelta=function(T){return arguments.length?(s=typeof T=="function"?T:qr(+T),v):s},v.filter=function(T){return arguments.length?(e=typeof T=="function"?T:qr(!!T),v):e},v.touchable=function(T){return arguments.length?(o=typeof T=="function"?T:qr(!!T),v):o},v.extent=function(T){return arguments.length?(t=typeof T=="function"?T:qr([[+T[0][0],+T[0][1]],[+T[1][0],+T[1][1]]]),v):t},v.scaleExtent=function(T){return arguments.length?(a[0]=+T[0],a[1]=+T[1],v):[a[0],a[1]]},v.translateExtent=function(T){return arguments.length?(i[0][0]=+T[0][0],i[1][0]=+T[1][0],i[0][1]=+T[0][1],i[1][1]=+T[1][1],v):[[i[0][0],i[0][1]],[i[1][0],i[1][1]]]},v.constrain=function(T){return arguments.length?(n=T,v):n},v.duration=function(T){return arguments.length?(l=+T,v):l},v.interpolate=function(T){return arguments.length?(c=T,v):c},v.on=function(){var T=d.on.apply(d,arguments);return T===d?v:T},v.clickDistance=function(T){return arguments.length?(y=(T=+T)*T,v):Math.sqrt(y)},v.tapDistance=function(T){return arguments.length?(k=+T,v):k},v}const Jf=["30m","1h","2h","4h","8h","12h","1d","1w"],eh={"30m":"freq30m","1h":"freq1h","2h":"freq2h","4h":"freq4h","8h":"freq8h","12h":"freq12h","1d":"freq1d","1w":"freq1w"};function Wi(e){return eh[e]??"freq4h"}function th(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function ua(){return{mode:"calendar",every:"4h",calendar:"daily",weekdays:[1,2,3,4,5],time:"09:00",cron:"",maxRuns:"",timezone:th()}}function Oc(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]=Oc(e);return`${String(t).padStart(2,"0")}:${String(n).padStart(2,"0")}`}function sh(e,t,n){if(e==="cron")return"";const[s,o]=Oc(n),a=e==="daily"?"*":e==="weekdays"?"1-5":t.length>0?[...t].sort((i,l)=>i-l).join(","):"*";return`${o} ${s} * * ${a}`}function rh(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 oh(e){const t=ua();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=rh(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 $c(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 ah=[1,2,3,4,5,6,0];function ih({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-white":"bg-surface-elevated text-fg-secondary hover:text-fg-primary"}`,children:a.label},a.value))})}function Pc({value:e,onChange:t,compact:n=!1}){const{t:s}=ze(),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.${Wi(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(ih,{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:Jf.map(h=>r.jsx("option",{value:h,children:s(`work:task.${Wi(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:ah.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-white":"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 yt(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=yt(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."},ar=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],Bc=["Enter"," ","Escape"],zc={"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 Cs;(function(e){e.Strict="strict",e.Loose="loose"})(Cs||(Cs={}));var Xn;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Xn||(Xn={}));var ir;(function(e){e.Partial="partial",e.Full="full"})(ir||(ir={}));const qc={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Sn;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Sn||(Sn={}));var Es;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Es||(Es={}));var Ne;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(Ne||(Ne={}));const Vi={[Ne.Left]:Ne.Right,[Ne.Right]:Ne.Left,[Ne.Top]:Ne.Bottom,[Ne.Bottom]:Ne.Top};function Fc(e){return e===null?null:e?"valid":"invalid"}const Hc=e=>"id"in e&&"source"in e&&"target"in e,lh=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Ia=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),mr=(e,t=[0,0])=>{const{width:n,height:s}=bn(e),o=e.origin??t,a=n*o[0],i=s*o[1];return{x:e.position.x-a,y:e.position.y-i}},ch=(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):Ia(o)?o:t.nodeLookup.get(o.id));const l=i?co(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return wo(s,l)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return ko(n)},pr=(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=wo(n,co(o)),s=!0)}),s?ko(n):{x:0,y:0,width:0,height:0}},Ma=(e,t,[n,s,o]=[0,0,1],a=!1,i=!1)=>{const l={...xr(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,y=lr(l,Is(d)),k=(m??0)*(g??0),v=a&&y>0;(!d.internals.handleBounds||v||y>=k||d.dragging)&&c.push(d)}return c},dh=(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 uh(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 fh({nodes:e,width:t,height:n,panZoom:s,minZoom:o,maxZoom:a},i){if(e.size===0)return Promise.resolve(!0);const l=uh(e,i),c=pr(l),d=Aa(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 Wc({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&&Ms(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=Ms(u)?Zn(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 hh({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(y=>y.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=dh(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 Ts=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Zn=(e={x:0,y:0},t,n)=>({x:Ts(e.x,t[0][0],t[1][0]-(n?.width??0)),y:Ts(e.y,t[0][1],t[1][1]-(n?.height??0))});function Vc(e,t,n){const{width:s,height:o}=bn(n),{x:a,y:i}=n.internals.positionAbsolute;return Zn(e,[[a,i],[a+s,i+o]],t)}const Ki=(e,t,n)=>e<t?Ts(Math.abs(e-t),1,t)/t:e>n?-Ts(Math.abs(e-n),1,t)/t:0,Kc=(e,t,n=15,s=40)=>{const o=Ki(e.x,s,t.width-s)*n,a=Ki(e.y,s,t.height-s)*n;return[o,a]},wo=(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)}),fa=({x:e,y:t,width:n,height:s})=>({x:e,y:t,x2:e+n,y2:t+s}),ko=({x:e,y:t,x2:n,y2:s})=>({x:e,y:t,width:n-e,height:s-t}),Is=(e,t=[0,0])=>{const{x:n,y:s}=Ia(e)?e.internals.positionAbsolute:mr(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}},co=(e,t=[0,0])=>{const{x:n,y:s}=Ia(e)?e.internals.positionAbsolute:mr(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)}},Uc=(e,t)=>ko(wo(fa(e),fa(t))),lr=(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)},Ui=e=>Qt(e.width)&&Qt(e.height)&&Qt(e.x)&&Qt(e.y),Qt=e=>!isNaN(e)&&isFinite(e),mh=(e,t)=>{},gr=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),xr=({x:e,y:t},[n,s,o],a=!1,i=[1,1])=>{const l={x:(e-n)/o,y:(t-s)/o};return a?gr(l,i):l},uo=({x:e,y:t},[n,s,o])=>({x:e*o+n,y:t*o+s});function hs(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 ph(e,t,n){if(typeof e=="string"||typeof e=="number"){const s=hs(e,n),o=hs(e,t);return{top:s,right:o,bottom:s,left:o,x:o*2,y:s*2}}if(typeof e=="object"){const s=hs(e.top??e.y??0,n),o=hs(e.bottom??e.y??0,n),a=hs(e.left??e.x??0,t),i=hs(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 gh(e,t,n,s,o,a){const{x:i,y:l}=uo(e,[t,n,s]),{x:c,y:d}=uo({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 Aa=(e,t,n,s,o,a)=>{const i=ph(a,t,n),l=(t-i.x)/e.width,c=(n-i.y)/e.height,d=Math.min(l,c),h=Ts(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,y=gh(e,m,g,h,t,n),k={left:Math.min(y.left-i.left,0),top:Math.min(y.top-i.top,0),right:Math.min(y.right-i.right,0),bottom:Math.min(y.bottom-i.bottom,0)};return{x:m-k.left+k.right,y:g-k.top+k.bottom,zoom:h}},cr=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Ms(e){return e!=null&&e!=="parent"}function bn(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function Yc(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function Gc(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 Yi(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function xh(){let e,t;return{promise:new Promise((s,o)=>{e=s,t=o}),resolve:e,reject:t}}function bh(e){return{...zc,...e||{}}}function tr(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:s,containerBounds:o}){const{x:a,y:i}=Jt(e),l=xr({x:a-(o?.left??0),y:i-(o?.top??0)},s),{x:c,y:d}=n?gr(l,t):l;return{xSnapped:c,ySnapped:d,...l}}const La=e=>({width:e.offsetWidth,height:e.offsetHeight}),Xc=e=>e?.getRootNode?.()||window?.document,yh=["INPUT","SELECT","TEXTAREA"];function Zc(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:yh.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const Qc=e=>"clientX"in e,Jt=(e,t)=>{const n=Qc(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)}},Gi=(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,...La(i)}})};function Jc({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 Fr(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Xi({pos:e,x1:t,y1:n,x2:s,y2:o,c:a}){switch(e){case Ne.Left:return[t-Fr(t-s,a),n];case Ne.Right:return[t+Fr(s-t,a),n];case Ne.Top:return[t,n-Fr(n-o,a)];case Ne.Bottom:return[t,n+Fr(o-n,a)]}}function ed({sourceX:e,sourceY:t,sourcePosition:n=Ne.Bottom,targetX:s,targetY:o,targetPosition:a=Ne.Top,curvature:i=.25}){const[l,c]=Xi({pos:n,x1:e,y1:t,x2:s,y2:o,c:i}),[d,h]=Xi({pos:a,x1:s,y1:o,x2:e,y2:t,c:i}),[u,f,m,g]=Jc({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 td({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 wh({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 kh({sourceNode:e,targetNode:t,width:n,height:s,transform:o}){const a=wo(co(e),co(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 lr(i,ko(a))>0}const vh=({source:e,sourceHandle:t,target:n,targetHandle:s})=>`xy-edge__${e}${t||""}-${n}${s||""}`,jh=(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)),Nh=(e,t,n={})=>{if(!e.source||!e.target)return t;const s=n.getEdgeId||vh;let o;return Hc(e)?o={...e}:o={...e,id:s(e)},jh(o,t)?t:(o.sourceHandle===null&&delete o.sourceHandle,o.targetHandle===null&&delete o.targetHandle,t.concat(o))};function nd({sourceX:e,sourceY:t,targetX:n,targetY:s}){const[o,a,i,l]=td({sourceX:e,sourceY:t,targetX:n,targetY:s});return[`M ${e},${t}L ${n},${s}`,o,a,i,l]}const Zi={[Ne.Left]:{x:-1,y:0},[Ne.Right]:{x:1,y:0},[Ne.Top]:{x:0,y:-1},[Ne.Bottom]:{x:0,y:1}},Sh=({source:e,sourcePosition:t=Ne.Bottom,target:n})=>t===Ne.Left||t===Ne.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},Qi=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function Ch({source:e,sourcePosition:t=Ne.Bottom,target:n,targetPosition:s=Ne.Top,center:o,offset:a,stepPosition:i}){const l=Zi[t],c=Zi[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=Sh({source:d,sourcePosition:t,target:h}),f=u.x!==0?"x":"y",m=u[f];let g=[],y,k;const v={x:0,y:0},b={x:0,y:0},[,,x,w]=td({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(l[f]*c[f]===-1){f==="x"?(y=o.x??d.x+(h.x-d.x)*i,k=o.y??(d.y+h.y)/2):(y=o.x??(d.x+h.x)/2,k=o.y??d.y+(h.y-d.y)*i);const j=[{x:y,y:d.y},{x:y,y:h.y}],E=[{x:d.x,y:k},{x:h.x,y:k}];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 O=Math.abs(e[f]-n[f]);if(O<=a){const q=Math.min(a-1,a-O);l[f]===m?v[f]=(d[f]>e[f]?-1:1)*q:b[f]=(h[f]>n[f]?-1:1)*q}}if(t!==s){const O=f==="x"?"y":"x",q=l[f]===c[O],T=d[O]>h[O],B=d[O]<h[O];(l[f]===1&&(!q&&T||q&&B)||l[f]!==1&&(!q&&B||q&&T))&&(g=f==="x"?j:E)}const C={x:d.x+v.x,y:d.y+v.y},D={x:h.x+b.x,y:h.y+b.y},_=Math.max(Math.abs(C.x-g[0].x),Math.abs(D.x-g[0].x)),I=Math.max(Math.abs(C.y-g[0].y),Math.abs(D.y-g[0].y));_>=I?(y=(C.x+D.x)/2,k=g[0].y):(y=g[0].x,k=(C.y+D.y)/2)}return[[e,{x:d.x+v.x,y:d.y+v.y},...g,{x:h.x+b.x,y:h.y+b.y},n],y,k,x,w]}function Eh(e,t,n,s){const o=Math.min(Qi(e,t)/2,Qi(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 ha({sourceX:e,sourceY:t,sourcePosition:n=Ne.Bottom,targetX:s,targetY:o,targetPosition:a=Ne.Top,borderRadius:i=5,centerX:l,centerY:c,offset:d=20,stepPosition:h=.5}){const[u,f,m,g,y]=Ch({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((v,b,x)=>{let w="";return x>0&&x<u.length-1?w=Eh(u[x-1],b,u[x+1],i):w=`${x===0?"M":"L"}${b.x} ${b.y}`,v+=w,v},""),f,m,g,y]}function Ji(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Th(e){const{sourceNode:t,targetNode:n}=e;if(!Ji(t)||!Ji(n))return null;const s=t.internals.handleBounds||el(t.handles),o=n.internals.handleBounds||el(n.handles),a=tl(s?.source??[],e.sourceHandle),i=tl(e.connectionMode===Cs.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||Ne.Bottom,c=i?.position||Ne.Top,d=Qn(t,a,l),h=Qn(n,i,c);return{sourceX:d.x,sourceY:d.y,targetX:h.x,targetY:h.y,sourcePosition:l,targetPosition:c}}function el(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 Qn(e,t,n=Ne.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??bn(e);if(s)return{x:o+i/2,y:a+l/2};switch(t?.position??n){case Ne.Top:return{x:o+i/2,y:a};case Ne.Right:return{x:o+i,y:a+l/2};case Ne.Bottom:return{x:o+i/2,y:a+l};case Ne.Left:return{x:o,y:a+l/2}}}function tl(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function ma(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(s=>`${s}=${e[s]}`).join("&")}`:""}function Ih(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=ma(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 sd=1e3,Mh=10,_a={nodeOrigin:[0,0],nodeExtent:ar,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},Ah={..._a,checkEquality:!0};function Ra(e,t){const n={...e};for(const s in t)t[s]!==void 0&&(n[s]=t[s]);return n}function Lh(e,t,n){const s=Ra(_a,n);for(const o of e.values())if(o.parentId)Oa(o,e,t,s);else{const a=mr(o,s.nodeOrigin),i=Ms(o.extent)?o.extent:s.nodeExtent,l=Zn(a,i,bn(o));o.internals.positionAbsolute=l}}function _h(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 Da(e){return e==="manual"}function pa(e,t,n,s={}){const o=Ra(Ah,s),a={i:0},i=new Map(t),l=o?.elevateNodesOnSelect&&!Da(o.zIndexMode)?sd: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=mr(d,o.nodeOrigin),f=Ms(d.extent)?d.extent:o.nodeExtent,m=Zn(u,f,bn(d));h={...o.defaults,...d,measured:{width:d.measured?.width,height:d.measured?.height},internals:{positionAbsolute:m,handleBounds:_h(d,h),z:rd(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&&Oa(h,t,n,s,a)}return c}function Rh(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 Oa(e,t,n,s,o){const{elevateNodesOnSelect:a,nodeOrigin:i,nodeExtent:l,zIndexMode:c}=Ra(_a,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}Rh(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*Mh),o&&h.internals.rootParentIndex!==void 0&&(o.i=h.internals.rootParentIndex);const u=a&&!Da(c)?sd:0,{x:f,y:m,z:g}=Dh(e,h,i,l,u,c),{positionAbsolute:y}=e.internals,k=f!==y.x||m!==y.y;(k||g!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:k?{x:f,y:m}:y,z:g}})}function rd(e,t,n){const s=Qt(e.zIndex)?e.zIndex:0;return Da(n)?s:s+(e.selected?t:0)}function Dh(e,t,n,s,o,a){const{x:i,y:l}=t.internals.positionAbsolute,c=bn(e),d=mr(e,n),h=Ms(e.extent)?Zn(d,e.extent,c):d;let u=Zn({x:i+h.x,y:l+h.y},s,c);e.extent==="parent"&&(u=Vc(u,c,t));const f=rd(e,o,a),m=t.internals.z??0;return{x:u.x,y:u.y,z:m>=f?m+1:f}}function $a(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??Is(l),d=Uc(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=bn(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)),y=Math.max(h.height,Math.round(i.height)),k=(g-h.width)*u[0],v=(y-h.height)*u[1];(f>0||m>0||k||v)&&(o.push({id:c,type:"position",position:{x:l.position.x-f+k,y:l.position.y-m+v}}),n.get(c)?.forEach(b=>{e.some(x=>x.id===b.id)||o.push({id:b.id,type:"position",position:{x:b.position.x+f,y:b.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-k:0),height:y+(m?u[1]*m-v:0)}})}),o}function Oh(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 y=La(m.nodeElement),k=g.measured.width!==y.width||g.measured.height!==y.height;if(!!(y.width&&y.height&&(k||!g.internals.handleBounds||m.force))){const b=m.nodeElement.getBoundingClientRect(),x=Ms(g.extent)?g.extent:a;let{positionAbsolute:w}=g.internals;g.parentId&&g.extent==="parent"?w=Vc(w,y,t.get(g.parentId)):x&&(w=Zn(w,x,y));const N={...g,measured:y,internals:{...g.internals,positionAbsolute:w,handleBounds:{source:Gi("source",m.nodeElement,b,u,g.id),target:Gi("target",m.nodeElement,b,u,g.id)}}};t.set(g.id,N),g.parentId&&Oa(N,t,n,{nodeOrigin:o,zIndexMode:i}),c=!0,k&&(d.push({id:g.id,type:"dimensions",dimensions:y}),g.expandParent&&g.parentId&&f.push({id:g.id,parentId:g.parentId,rect:Is(N,o)}))}}if(f.length>0){const m=$a(f,t,n,o);d.push(...m)}return{changes:d,updatedInternals:c}}async function $h({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 nl(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 od(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}`;nl("source",c,h,e,o,i),nl("target",c,d,e,a,l),t.set(s.id,s)}}function ad(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:ad(n,t):!1}function sl(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 Ph(e,t,n,s){const o=new Map;for(const[a,i]of e)if((i.selected||i.id===s)&&(!i.parentId||!ad(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 Yo({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 Bh({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=gr(a,t);return{x:i.x-a.x,y:i.y-a.y}}function zh({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,y=null;function k({noDragClassName:b,handleSelector:x,domNode:w,isSelectable:N,nodeId:j,nodeClickDistance:E=0}){f=qt(w);function C({x:O,y:q}){const{nodeLookup:T,nodeExtent:B,snapGrid:L,snapToGrid:z,nodeOrigin:R,onNodeDrag:A,onSelectionDrag:$,onError:F,updateNodePositions:W}=t();a={x:O,y:q};let X=!1;const P=l.size>1,M=P&&B?fa(pr(l)):null,K=P&&z?Bh({dragItems:l,snapGrid:L,x:O,y:q}):null;for(const[V,H]of l){if(!T.has(V))continue;let Z={x:O-H.distance.x,y:q-H.distance.y};z&&(Z=K?{x:Math.round(Z.x+K.x),y:Math.round(Z.y+K.y)}:gr(Z,L));let ee=null;if(P&&B&&!H.extent&&M){const{positionAbsolute:Q}=H.internals,le=Q.x-M.x+B[0][0],ue=Q.x+H.measured.width-M.x2+B[1][0],fe=Q.y-M.y+B[0][1],ge=Q.y+H.measured.height-M.y2+B[1][1];ee=[[le,fe],[ue,ge]]}const{position:oe,positionAbsolute:de}=Wc({nodeId:V,nextPosition:Z,nodeLookup:T,nodeExtent:ee||B,nodeOrigin:R,onError:F});X=X||H.position.x!==oe.x||H.position.y!==oe.y,H.position=oe,H.internals.positionAbsolute=de}if(g=g||X,!!X&&(W(l,!0),y&&(s||A||!j&&$))){const[V,H]=Yo({nodeId:j,dragItems:l,nodeLookup:T});s?.(y,l,V,H),A?.(y,V,H),j||$?.(y,H)}}async function D(){if(!h)return;const{transform:O,panBy:q,autoPanSpeed:T,autoPanOnNodeDrag:B}=t();if(!B){c=!1,cancelAnimationFrame(i);return}const[L,z]=Kc(d,h,T);(L!==0||z!==0)&&(a.x=(a.x??0)-L/O[2],a.y=(a.y??0)-z/O[2],await q({x:L,y:z})&&C(a)),i=requestAnimationFrame(D)}function _(O){const{nodeLookup:q,multiSelectionActive:T,nodesDraggable:B,transform:L,snapGrid:z,snapToGrid:R,selectNodesOnDrag:A,onNodeDragStart:$,onSelectionDragStart:F,unselectNodesAndEdges:W}=t();u=!0,(!A||!N)&&!T&&j&&(q.get(j)?.selected||W()),N&&A&&j&&e?.(j);const X=tr(O.sourceEvent,{transform:L,snapGrid:z,snapToGrid:R,containerBounds:h});if(a=X,l=Ph(q,B,X,j),l.size>0&&(n||$||!j&&F)){const[P,M]=Yo({nodeId:j,dragItems:l,nodeLookup:q});n?.(O.sourceEvent,l,P,M),$?.(O.sourceEvent,P,M),j||F?.(O.sourceEvent,M)}}const I=Rc().clickDistance(E).on("start",O=>{const{domNode:q,nodeDragThreshold:T,transform:B,snapGrid:L,snapToGrid:z}=t();h=q?.getBoundingClientRect()||null,m=!1,g=!1,y=O.sourceEvent,T===0&&_(O),a=tr(O.sourceEvent,{transform:B,snapGrid:L,snapToGrid:z,containerBounds:h}),d=Jt(O.sourceEvent,h)}).on("drag",O=>{const{autoPanOnNodeDrag:q,transform:T,snapGrid:B,snapToGrid:L,nodeDragThreshold:z,nodeLookup:R}=t(),A=tr(O.sourceEvent,{transform:T,snapGrid:B,snapToGrid:L,containerBounds:h});if(y=O.sourceEvent,(O.sourceEvent.type==="touchmove"&&O.sourceEvent.touches.length>1||j&&!R.has(j))&&(m=!0),!m){if(!c&&q&&u&&(c=!0,D()),!u){const $=Jt(O.sourceEvent,h),F=$.x-d.x,W=$.y-d.y;Math.sqrt(F*F+W*W)>z&&_(O)}(a.x!==A.xSnapped||a.y!==A.ySnapped)&&l&&u&&(d=Jt(O.sourceEvent,h),C(A))}}).on("end",O=>{if(!(!u||m)&&(c=!1,u=!1,cancelAnimationFrame(i),l.size>0)){const{nodeLookup:q,updateNodePositions:T,onNodeDragStop:B,onSelectionDragStop:L}=t();if(g&&(T(l,!1),g=!1),o||B||!j&&L){const[z,R]=Yo({nodeId:j,dragItems:l,nodeLookup:q,dragging:!1});o?.(O.sourceEvent,l,z,R),B?.(O.sourceEvent,z,R),j||L?.(O.sourceEvent,R)}}}).filter(O=>{const q=O.target;return!O.button&&(!b||!sl(q,`.${b}`,w))&&(!x||sl(q,x,w))});f.call(I)}function v(){f?.on(".drag",null)}return{update:k,destroy:v}}function qh(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())lr(o,Is(a))>0&&s.push(a);return s}const Fh=250;function Hh(e,t,n,s){let o=[],a=1/0;const i=qh(e,n,t+Fh);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}=Qn(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 id(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,...Qn(i,c,c.position,!0)}:c}function ld(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function Wh(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const cd=()=>!0;function Vh(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:y,onConnectEnd:k,isValidConnection:v=cd,onReconnectEnd:b,updateConnection:x,getTransform:w,getFromHandle:N,autoPanSpeed:j,dragThreshold:E=1,handleDomNode:C}){const D=Xc(e.target);let _=0,I;const{x:O,y:q}=Jt(e),T=ld(a,C),B=l?.getBoundingClientRect();let L=!1;if(!B||!T)return;const z=id(o,T,s,c,t);if(!z)return;let R=Jt(e,B),A=!1,$=null,F=!1,W=null;function X(){if(!h||!B)return;const[oe,de]=Kc(R,B,j);f({x:oe,y:de}),_=requestAnimationFrame(X)}const P={...z,nodeId:o,type:T,position:z.position},M=c.get(o);let V={inProgress:!0,isValid:null,from:Qn(M,P,Ne.Left,!0),fromHandle:P,fromPosition:P.position,fromNode:M,to:R,toHandle:null,toPosition:Vi[P.position],toNode:null,pointer:R};function H(){L=!0,x(V),g?.(e,{nodeId:o,handleId:s,handleType:T})}E===0&&H();function Z(oe){if(!L){const{x:ge,y:we}=Jt(oe),me=ge-O,ve=we-q;if(!(me*me+ve*ve>E*E))return;H()}if(!N()||!P){ee(oe);return}const de=w();R=Jt(oe,B),I=Hh(xr(R,de,!1,[1,1]),n,c,P),A||(X(),A=!0);const Q=dd(oe,{handle:I,connectionMode:t,fromNodeId:o,fromHandleId:s,fromType:i?"target":"source",isValidConnection:v,doc:D,lib:d,flowId:u,nodeLookup:c});W=Q.handleDomNode,$=Q.connection,F=Wh(!!I,Q.isValid);const le=c.get(o),ue=le?Qn(le,P,Ne.Left,!0):V.from,fe={...V,from:ue,isValid:F,to:Q.toHandle&&F?uo({x:Q.toHandle.x,y:Q.toHandle.y},de):R,toHandle:Q.toHandle,toPosition:F&&Q.toHandle?Q.toHandle.position:Vi[P.position],toNode:Q.toHandle?c.get(Q.toHandle.nodeId):null,pointer:R};x(fe),V=fe}function ee(oe){if(!("touches"in oe&&oe.touches.length>0)){if(L){(I||W)&&$&&F&&y?.($);const{inProgress:de,...Q}=V,le={...Q,toPosition:V.toHandle?V.toPosition:null};k?.(oe,le),a&&b?.(oe,le)}m(),cancelAnimationFrame(_),A=!1,F=!1,$=null,W=null,D.removeEventListener("mousemove",Z),D.removeEventListener("mouseup",ee),D.removeEventListener("touchmove",Z),D.removeEventListener("touchend",ee)}}D.addEventListener("mousemove",Z),D.addEventListener("mouseup",ee),D.addEventListener("touchmove",Z),D.addEventListener("touchend",ee)}function dd(e,{handle:t,connectionMode:n,fromNodeId:s,fromHandleId:o,fromType:a,doc:i,lib:l,flowId:c,isValidConnection:d=cd,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}=Jt(e),y=i.elementFromPoint(m,g),k=y?.classList.contains(`${l}-flow__handle`)?y:f,v={handleDomNode:k,isValid:!1,connection:null,toHandle:null};if(k){const b=ld(void 0,k),x=k.getAttribute("data-nodeid"),w=k.getAttribute("data-handleid"),N=k.classList.contains("connectable"),j=k.classList.contains("connectableend");if(!x||!b)return v;const E={source:u?x:s,sourceHandle:u?w:o,target:u?s:x,targetHandle:u?o:w};v.connection=E;const D=N&&j&&(n===Cs.Strict?u&&b==="source"||!u&&b==="target":x!==s||w!==o);v.isValid=D&&d(E),v.toHandle=id(x,b,w,h,n,!0)}return v}const ga={onPointerDown:Vh,isValid:dd};function Kh({domNode:e,panZoom:t,getTransform:n,getViewScale:s}){const o=qt(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(),N=x.sourceEvent.ctrlKey&&cr()?10:1,j=-x.sourceEvent.deltaY*(x.sourceEvent.deltaMode===1?.05:x.sourceEvent.deltaMode?1:.002)*h,E=w[2]*Math.pow(2,j*N);t.scaleTo(E)};let y=[0,0];const k=x=>{(x.sourceEvent.type==="mousedown"||x.sourceEvent.type==="touchstart")&&(y=[x.sourceEvent.clientX??x.sourceEvent.touches[0].clientX,x.sourceEvent.clientY??x.sourceEvent.touches[0].clientY])},v=x=>{const w=n();if(x.sourceEvent.type!=="mousemove"&&x.sourceEvent.type!=="touchmove"||!t)return;const N=[x.sourceEvent.clientX??x.sourceEvent.touches[0].clientX,x.sourceEvent.clientY??x.sourceEvent.touches[0].clientY],j=[N[0]-y[0],N[1]-y[1]];y=N;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},D=[[0,0],[c,d]];t.setViewportConstrained({x:C.x,y:C.y,zoom:w[2]},D,l)},b=Dc().on("start",k).on("zoom",u?v:null).on("zoom.wheel",f?g:null);o.call(b,{})}function i(){o.on("zoom",null)}return{update:a,destroy:i,pointer:Zt}}const vo=e=>({x:e.x,y:e.y,zoom:e.k}),Go=({x:e,y:t,zoom:n})=>Ta.translate(e,t).scale(n),xs=(e,t)=>e.target.closest(`.${t}`),ud=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Uh=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Xo=(e,t=0,n=Uh,s=()=>{})=>{const o=typeof t=="number"&&t>0;return o||s(),o?e.transition().duration(t).ease(n).on("end",s):e},fd=e=>{const t=e.ctrlKey&&cr()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function Yh({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:s,panOnScrollMode:o,panOnScrollSpeed:a,zoomOnPinch:i,onPanZoomStart:l,onPanZoom:c,onPanZoomEnd:d}){return h=>{if(xs(h,t))return h.ctrlKey&&h.preventDefault(),!1;h.preventDefault(),h.stopImmediatePropagation();const u=n.property("__zoom").k||1;if(h.ctrlKey&&i){const k=Zt(h),v=fd(h),b=u*Math.pow(2,v);s.scaleTo(n,b,k,h);return}const f=h.deltaMode===1?20:1;let m=o===Xn.Vertical?0:h.deltaX*f,g=o===Xn.Horizontal?0:h.deltaY*f;!cr()&&h.shiftKey&&o!==Xn.Vertical&&(m=h.deltaY*f,g=0),s.translateBy(n,-(m/u)*a,-(g/u)*a,{internal:!0});const y=vo(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(h,y),e.panScrollTimeout=setTimeout(()=>{d?.(h,y),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,l?.(h,y))}}function Gh({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(s,o){const a=s.type==="wheel",i=!t&&a&&!s.ctrlKey,l=xs(s,e);if(s.ctrlKey&&a&&l&&s.preventDefault(),i||l)return null;s.preventDefault(),n.call(this,s,o)}}function Xh({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return s=>{if(s.sourceEvent?.internal)return;const o=vo(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 Zh({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:s,onPanZoom:o}){return a=>{e.usedRightMouseButton=!!(n&&ud(t,e.mouseButton??0)),a.sourceEvent?.sync||s([a.transform.x,a.transform.y,a.transform.k]),o&&!a.sourceEvent?.internal&&o?.(a.sourceEvent,vo(a.transform))}}function Qh({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:s,onPanZoomEnd:o,onPaneContextMenu:a}){return i=>{if(!i.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&ud(t,e.mouseButton??0)&&!e.usedRightMouseButton&&i.sourceEvent&&a(i.sourceEvent),e.usedRightMouseButton=!1,s(!1),o)){const l=vo(i.transform);e.prevViewport=l,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{o?.(i.sourceEvent,l)},n?150:0)}}}function Jh({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"&&(xs(u,`${d}-flow__node`)||xs(u,`${d}-flow__edge`)))return!0;if(!s&&!f&&!o&&!a&&!n||i||h&&!g||xs(u,l)&&g||xs(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 y=Array.isArray(s)&&s.includes(u.button)||!u.button||u.button<=1;return(!u.ctrlKey||g)&&y}}function em({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=Dc().scaleExtent([t,n]).translateExtent(s),f=qt(e).call(u);b({x:o.x,y:o.y,zoom:Ts(o.zoom,t,n)},[[0,0],[h.width,h.height]],s);const m=f.on("wheel.zoom"),g=f.on("dblclick.zoom");u.wheelDelta(fd);function y(I,O){return f?new Promise(q=>{u?.interpolate(O?.interpolate==="linear"?Vo:no).transform(Xo(f,O?.duration,O?.ease,()=>q(!0)),I)}):Promise.resolve(!1)}function k({noWheelClassName:I,noPanClassName:O,onPaneContextMenu:q,userSelectionActive:T,panOnScroll:B,panOnDrag:L,panOnScrollMode:z,panOnScrollSpeed:R,preventScrolling:A,zoomOnPinch:$,zoomOnScroll:F,zoomOnDoubleClick:W,zoomActivationKeyPressed:X,lib:P,onTransformChange:M,connectionInProgress:K,paneClickDistance:V,selectionOnDrag:H}){T&&!d.isZoomingOrPanning&&v();const Z=B&&!X&&!T;u.clickDistance(H?1/0:!Qt(V)||V<0?0:V);const ee=Z?Yh({zoomPanValues:d,noWheelClassName:I,d3Selection:f,d3Zoom:u,panOnScrollMode:z,panOnScrollSpeed:R,zoomOnPinch:$,onPanZoomStart:i,onPanZoom:a,onPanZoomEnd:l}):Gh({noWheelClassName:I,preventScrolling:A,d3ZoomHandler:m});if(f.on("wheel.zoom",ee,{passive:!1}),!T){const de=Xh({zoomPanValues:d,onDraggingChange:c,onPanZoomStart:i});u.on("start",de);const Q=Zh({zoomPanValues:d,panOnDrag:L,onPaneContextMenu:!!q,onPanZoom:a,onTransformChange:M});u.on("zoom",Q);const le=Qh({zoomPanValues:d,panOnDrag:L,panOnScroll:B,onPaneContextMenu:q,onPanZoomEnd:l,onDraggingChange:c});u.on("end",le)}const oe=Jh({zoomActivationKeyPressed:X,panOnDrag:L,zoomOnScroll:F,panOnScroll:B,zoomOnDoubleClick:W,zoomOnPinch:$,userSelectionActive:T,noPanClassName:O,noWheelClassName:I,lib:P,connectionInProgress:K});u.filter(oe),W?f.on("dblclick.zoom",g):f.on("dblclick.zoom",null)}function v(){u.on("zoom",null)}async function b(I,O,q){const T=Go(I),B=u?.constrain()(T,O,q);return B&&await y(B),new Promise(L=>L(B))}async function x(I,O){const q=Go(I);return await y(q,O),new Promise(T=>T(q))}function w(I){if(f){const O=Go(I),q=f.property("__zoom");(q.k!==I.zoom||q.x!==I.x||q.y!==I.y)&&u?.transform(f,O,null,{sync:!0})}}function N(){const I=f?$f(f.node()):{x:0,y:0,k:1};return{x:I.x,y:I.y,zoom:I.k}}function j(I,O){return f?new Promise(q=>{u?.interpolate(O?.interpolate==="linear"?Vo:no).scaleTo(Xo(f,O?.duration,O?.ease,()=>q(!0)),I)}):Promise.resolve(!1)}function E(I,O){return f?new Promise(q=>{u?.interpolate(O?.interpolate==="linear"?Vo:no).scaleBy(Xo(f,O?.duration,O?.ease,()=>q(!0)),I)}):Promise.resolve(!1)}function C(I){u?.scaleExtent(I)}function D(I){u?.translateExtent(I)}function _(I){const O=!Qt(I)||I<0?0:I;u?.clickDistance(O)}return{update:k,destroy:v,setViewport:x,setViewportConstrained:b,getViewport:N,scaleTo:j,scaleBy:E,setScaleExtent:C,setTranslateExtent:D,syncViewport:w,setClickDistance:_}}var As;(function(e){e.Line="line",e.Handle="handle"})(As||(As={}));function tm({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 rl(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 vn(e,t){return Math.max(0,t-e)}function jn(e,t){return Math.max(0,e-t)}function Hr(e,t,n){return Math.max(0,t-e,e-n)}function ol(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:y,maxWidth:k,minHeight:v,maxHeight:b}=s,{x,y:w,width:N,height:j,aspectRatio:E}=e;let C=Math.floor(h?m-e.pointerX:0),D=Math.floor(u?g-e.pointerY:0);const _=N+(c?-C:C),I=j+(d?-D:D),O=-a[0]*N,q=-a[1]*j;let T=Hr(_,y,k),B=Hr(I,v,b);if(i){let R=0,A=0;c&&C<0?R=vn(x+C+O,i[0][0]):!c&&C>0&&(R=jn(x+_+O,i[1][0])),d&&D<0?A=vn(w+D+q,i[0][1]):!d&&D>0&&(A=jn(w+I+q,i[1][1])),T=Math.max(T,R),B=Math.max(B,A)}if(l){let R=0,A=0;c&&C>0?R=jn(x+C,l[0][0]):!c&&C<0&&(R=vn(x+_,l[1][0])),d&&D>0?A=jn(w+D,l[0][1]):!d&&D<0&&(A=vn(w+I,l[1][1])),T=Math.max(T,R),B=Math.max(B,A)}if(o){if(h){const R=Hr(_/E,v,b)*E;if(T=Math.max(T,R),i){let A=0;!c&&!d||c&&!d&&f?A=jn(w+q+_/E,i[1][1])*E:A=vn(w+q+(c?C:-C)/E,i[0][1])*E,T=Math.max(T,A)}if(l){let A=0;!c&&!d||c&&!d&&f?A=vn(w+_/E,l[1][1])*E:A=jn(w+(c?C:-C)/E,l[0][1])*E,T=Math.max(T,A)}}if(u){const R=Hr(I*E,y,k)/E;if(B=Math.max(B,R),i){let A=0;!c&&!d||d&&!c&&f?A=jn(x+I*E+O,i[1][0])/E:A=vn(x+(d?D:-D)*E+O,i[0][0])/E,B=Math.max(B,A)}if(l){let A=0;!c&&!d||d&&!c&&f?A=vn(x+I*E,l[1][0])/E:A=jn(x+(d?D:-D)*E,l[0][0])/E,B=Math.max(B,A)}}}D=D+(D<0?B:-B),C=C+(C<0?T:-T),o&&(f?_>I*E?D=(ol(c,d)?-C:C)/E:C=(ol(c,d)?-D:D)*E:h?(D=C/E,d=c):(C=D*E,c=d));const L=c?x+C:x,z=d?w+D:w;return{width:N+(c?-C:C),height:j+(d?-D:D),x:a[0]*C*(c?-1:1)+L,y:a[1]*D*(d?-1:1)+z}}const hd={width:0,height:0,x:0,y:0},sm={...hd,pointerX:0,pointerY:0,aspectRatio:1};function rm(e){return[[0,0],[e.measured.width,e.measured.height]]}function om(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 am({domNode:e,nodeId:t,getStoreItems:n,onChange:s,onEnd:o}){const a=qt(e);let i={controlDirection:rl("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:y,shouldResize:k}){let v={...hd},b={...sm};i={boundaries:h,resizeDirection:f,keepAspectRatio:u,controlDirection:rl(d)};let x,w=null,N=[],j,E,C,D=!1;const _=Rc().on("start",I=>{const{nodeLookup:O,transform:q,snapGrid:T,snapToGrid:B,nodeOrigin:L,paneDomNode:z}=n();if(x=O.get(t),!x)return;w=z?.getBoundingClientRect()??null;const{xSnapped:R,ySnapped:A}=tr(I.sourceEvent,{transform:q,snapGrid:T,snapToGrid:B,containerBounds:w});v={width:x.measured.width??0,height:x.measured.height??0,x:x.position.x??0,y:x.position.y??0},b={...v,pointerX:R,pointerY:A,aspectRatio:v.width/v.height},j=void 0,x.parentId&&(x.extent==="parent"||x.expandParent)&&(j=O.get(x.parentId),E=j&&x.extent==="parent"?rm(j):void 0),N=[],C=void 0;for(const[$,F]of O)if(F.parentId===t&&(N.push({id:$,position:{...F.position},extent:F.extent}),F.extent==="parent"||F.expandParent)){const W=om(F,x,F.origin??L);C?C=[[Math.min(W[0][0],C[0][0]),Math.min(W[0][1],C[0][1])],[Math.max(W[1][0],C[1][0]),Math.max(W[1][1],C[1][1])]]:C=W}m?.(I,{...v})}).on("drag",I=>{const{transform:O,snapGrid:q,snapToGrid:T,nodeOrigin:B}=n(),L=tr(I.sourceEvent,{transform:O,snapGrid:q,snapToGrid:T,containerBounds:w}),z=[];if(!x)return;const{x:R,y:A,width:$,height:F}=v,W={},X=x.origin??B,{width:P,height:M,x:K,y:V}=nm(b,i.controlDirection,L,i.boundaries,i.keepAspectRatio,X,E,C),H=P!==$,Z=M!==F,ee=K!==R&&H,oe=V!==A&&Z;if(!ee&&!oe&&!H&&!Z)return;if((ee||oe||X[0]===1||X[1]===1)&&(W.x=ee?K:v.x,W.y=oe?V:v.y,v.x=W.x,v.y=W.y,N.length>0)){const ue=K-R,fe=V-A;for(const ge of N)ge.position={x:ge.position.x-ue+X[0]*(P-$),y:ge.position.y-fe+X[1]*(M-F)},z.push(ge)}if((H||Z)&&(W.width=H&&(!i.resizeDirection||i.resizeDirection==="horizontal")?P:v.width,W.height=Z&&(!i.resizeDirection||i.resizeDirection==="vertical")?M:v.height,v.width=W.width,v.height=W.height),j&&x.expandParent){const ue=X[0]*(W.width??0);W.x&&W.x<ue&&(v.x=ue,b.x=b.x-(W.x-ue));const fe=X[1]*(W.height??0);W.y&&W.y<fe&&(v.y=fe,b.y=b.y-(W.y-fe))}const de=tm({width:v.width,prevWidth:$,height:v.height,prevHeight:F,affectsX:i.controlDirection.affectsX,affectsY:i.controlDirection.affectsY}),Q={...v,direction:de};k?.(I,Q)!==!1&&(D=!0,g?.(I,Q),s(W,z))}).on("end",I=>{D&&(y?.(I,{...v}),o?.({...v}),D=!1)});a.call(_)}function c(){a.on(".drag",null)}return{update:l,destroy:c}}var Zo={exports:{}},Qo={};var al;function im(){if(al)return Qo;al=1;var e=mf(),t=pf();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 Qo.useSyncExternalStoreWithSelector=function(d,h,u,f,m){var g=a(null);if(g.current===null){var y={hasValue:!1,value:null};g.current=y}else y=g.current;g=l(function(){function v(j){if(!b){if(b=!0,x=j,j=f(j),m!==void 0&&y.hasValue){var E=y.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 b=!1,x,w,N=u===void 0?null:u;return[function(){return v(h())},N===null?void 0:function(){return v(N())}]},[h,u,f,m]);var k=o(d,g[0],g[1]);return i(function(){y.hasValue=!0,y.value=k},[k]),c(k),k},Qo}var il;function lm(){return il||(il=1,Zo.exports=im()),Zo.exports}var cm=lm();const dm=gf(cm),um={},ll=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:()=>{(um?"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},fm=e=>e?ll(e):ll,{useDebugValue:hm}=xf,{useSyncExternalStoreWithSelector:mm}=dm,pm=e=>e;function md(e,t=pm,n){const s=mm(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return hm(s),s}const cl=(e,t)=>{const n=fm(e),s=(o,a=t)=>md(n,o,a);return Object.assign(s,n),s},gm=(e,t)=>e?cl(e,t):cl;function ot(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 jo=p.createContext(null),xm=jo.Provider,pd=ln.error001();function Fe(e,t){const n=p.useContext(jo);if(n===null)throw new Error(pd);return md(n,e,t)}function rt(){const e=p.useContext(jo);if(e===null)throw new Error(pd);return p.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const dl={display:"none"},bm={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},gd="react-flow__node-desc",xd="react-flow__edge-desc",ym="react-flow__aria-live",wm=e=>e.ariaLiveMessage,km=e=>e.ariaLabelConfig;function vm({rfId:e}){const t=Fe(wm);return r.jsx("div",{id:`${ym}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:bm,children:t})}function jm({rfId:e,disableKeyboardA11y:t}){const n=Fe(km);return r.jsxs(r.Fragment,{children:[r.jsx("div",{id:`${gd}-${e}`,style:dl,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),r.jsx("div",{id:`${xd}-${e}`,style:dl,children:n["edge.a11yDescription.default"]}),!t&&r.jsx(vm,{rfId:e})]})}const No=p.forwardRef(({position:e="top-left",children:t,className:n,style:s,...o},a)=>{const i=`${e}`.split("-");return r.jsx("div",{className:yt(["react-flow__panel",n,...i]),style:s,ref:a,...o,children:t})});No.displayName="Panel";function Nm({proOptions:e,position:t="bottom-right"}){return e?.hideAttribution?null:r.jsx(No,{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 Sm=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}},Wr=e=>e.id;function Cm(e,t){return ot(e.selectedNodes.map(Wr),t.selectedNodes.map(Wr))&&ot(e.selectedEdges.map(Wr),t.selectedEdges.map(Wr))}function Em({onSelectionChange:e}){const t=rt(),{selectedNodes:n,selectedEdges:s}=Fe(Sm,Cm);return p.useEffect(()=>{const o={nodes:n,edges:s};e?.(o),t.getState().onSelectionChangeHandlers.forEach(a=>a(o))},[n,s,e]),null}const Tm=e=>!!e.onSelectionChangeHandlers;function Im({onSelectionChange:e}){const t=Fe(Tm);return e||t?r.jsx(Em,{onSelectionChange:e}):null}const bd=[0,0],Mm={x:0,y:0,zoom:1},Am=["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"],ul=[...Am,"rfId"],Lm=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}),fl={translateExtent:ar,nodeOrigin:bd,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function _m(e){const{setNodes:t,setEdges:n,setMinZoom:s,setMaxZoom:o,setTranslateExtent:a,setNodeExtent:i,reset:l,setDefaultNodesAndEdges:c}=Fe(Lm,ot),d=rt();p.useEffect(()=>(c(e.defaultNodes,e.defaultEdges),()=>{h.current=fl,l()}),[]);const h=p.useRef(fl);return p.useEffect(()=>{for(const u of ul){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:bh(f)}):u==="fitView"?d.setState({fitViewQueued:f}):u==="fitViewOptions"?d.setState({fitViewOptions:f}):d.setState({[u]:f})))}h.current=e},ul.map(u=>e[u])),null}function hl(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function Rm(e){const[t,n]=p.useState(e==="system"?null:e);return p.useEffect(()=>{if(e!=="system"){n(e);return}const s=hl(),o=()=>n(s?.matches?"dark":"light");return o(),s?.addEventListener("change",o),()=>{s?.removeEventListener("change",o)}},[e]),t!==null?t:hl()?.matches?"dark":"light"}const ml=typeof document<"u"?document:null;function dr(e=null,t={target:ml,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??ml,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)&&Zc(m))return!1;const y=gl(m.code,l);if(a.current.add(m[y]),pl(i,a.current,!1)){const k=m.composedPath?.()?.[0]||m.target,v=k?.nodeName==="BUTTON"||k?.nodeName==="A";t.preventDefault!==!1&&(o.current||!v)&&m.preventDefault(),s(!0)}},u=m=>{const g=gl(m.code,l);pl(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 pl(e,t,n){return e.filter(s=>n||s.length===t.size).some(s=>s.every(o=>t.has(o)))}function gl(e,t){return t.includes(e)?"code":"key"}const Dm=()=>{const e=rt();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=Aa(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 xr(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=uo(t,n);return{x:i.x+o,y:i.y+a}}}),[])};function yd(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)Om(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 Om(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 wd(e,t){return yd(e,t)}function kd(e,t){return yd(e,t)}function Vn(e,t){return{id:e,type:"select",selected:t}}function bs(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(Vn(a.id,i)))}return s}function xl({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 bl(e){return{id:e.id,type:"remove"}}const yl=e=>lh(e),$m=e=>Hc(e);function vd(e){return p.forwardRef(e)}const Pm=typeof window<"u"?p.useLayoutEffect:p.useEffect;function wl(e){const[t,n]=p.useState(BigInt(0)),[s]=p.useState(()=>Bm(()=>n(o=>o+BigInt(1))));return Pm(()=>{const o=s.get();o.length&&(e(o),s.reset())},[t]),s}function Bm(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const jd=p.createContext(null);function zm({children:e}){const t=rt(),n=p.useCallback(l=>{const{nodes:c=[],setNodes:d,hasDefaultNodes:h,onNodesChange:u,nodeLookup:f,fitViewQueued:m,onNodesChangeMiddlewareMap:g}=t.getState();let y=c;for(const v of l)y=typeof v=="function"?v(y):v;let k=xl({items:y,lookup:f});for(const v of g.values())k=v(k);h&&d(y),k.length>0?u?.(k):m&&window.requestAnimationFrame(()=>{const{fitViewQueued:v,nodes:b,setNodes:x}=t.getState();v&&x(b)})},[]),s=wl(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(xl({items:m,lookup:f}))},[]),a=wl(o),i=p.useMemo(()=>({nodeQueue:s,edgeQueue:a}),[]);return r.jsx(jd.Provider,{value:i,children:e})}function qm(){const e=p.useContext(jd);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const Fm=e=>!!e.panZoom;function Pa(){const e=Dm(),t=rt(),n=qm(),s=Fe(Fm),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=yl(u)?u:f.get(u.id),y=g.parentId?Gc(g.position,g.measured,g.parentId,f,m):g.position,k={...g,position:y,width:g.measured?.width??g.width,height:g.measured?.height??g.height};return Is(k)},d=(u,f,m={replace:!1})=>{i(g=>g.map(y=>{if(y.id===u){const k=typeof f=="function"?f(y):f;return m.replace&&yl(k)?k:{...y,...k}}return y}))},h=(u,f,m={replace:!1})=>{l(g=>g.map(y=>{if(y.id===u){const k=typeof f=="function"?f(y):f;return m.replace&&$m(k)?k:{...y,...k}}return y}))};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,y,k]=m;return{nodes:u.map(v=>({...v})),edges:f.map(v=>({...v})),viewport:{x:g,y,zoom:k}}},deleteElements:async({nodes:u=[],edges:f=[]})=>{const{nodes:m,edges:g,onNodesDelete:y,onEdgesDelete:k,triggerNodeChanges:v,triggerEdgeChanges:b,onDelete:x,onBeforeDelete:w}=t.getState(),{nodes:N,edges:j}=await hh({nodesToRemove:u,edgesToRemove:f,nodes:m,edges:g,onBeforeDelete:w}),E=j.length>0,C=N.length>0;if(E){const D=j.map(bl);k?.(j),b(D)}if(C){const D=N.map(bl);y?.(N),v(D)}return(C||E)&&x?.({nodes:N,edges:j}),{deletedNodes:N,deletedEdges:j}},getIntersectingNodes:(u,f=!0,m)=>{const g=Ui(u),y=g?u:c(u),k=m!==void 0;return y?(m||t.getState().nodes).filter(v=>{const b=t.getState().nodeLookup.get(v.id);if(b&&!g&&(v.id===u.id||!b.internals.positionAbsolute))return!1;const x=Is(k?v:b),w=lr(x,y);return f&&w>0||w>=x.width*x.height||w>=y.width*y.height}):[]},isNodeIntersecting:(u,f,m=!0)=>{const y=Ui(u)?u:c(u);if(!y)return!1;const k=lr(y,f);return m&&k>0||k>=f.width*f.height||k>=y.width*y.height},updateNode:d,updateNodeData:(u,f,m={replace:!1})=>{d(u,g=>{const y=typeof f=="function"?f(g):f;return m.replace?{...g,data:y}:{...g,data:{...g.data,...y}}},m)},updateEdge:h,updateEdgeData:(u,f,m={replace:!1})=>{h(u,g=>{const y=typeof f=="function"?f(g):f;return m.replace?{...g,data:y}:{...g,data:{...g.data,...y}}},m)},getNodesBounds:u=>{const{nodeLookup:f,nodeOrigin:m}=t.getState();return ch(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??xh();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 kl=e=>e.selected,Hm=typeof window<"u"?window:void 0;function Wm({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=rt(),{deleteElements:s}=Pa(),o=dr(e,{actInsideInputWithModifier:!1}),a=dr(t,{target:Hm});p.useEffect(()=>{if(o){const{edges:i,nodes:l}=n.getState();s({nodes:l.filter(kl),edges:i.filter(kl)}),n.setState({nodesSelectionActive:!1})}},[o]),p.useEffect(()=>{n.setState({multiSelectionActive:a})},[a])}function Vm(e){const t=rt();p.useEffect(()=>{const n=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const s=La(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 So={position:"absolute",width:"100%",height:"100%",top:0,left:0},Km=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function Um({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:s=!1,panOnScrollSpeed:o=.5,panOnScrollMode:a=Xn.Free,zoomOnDoubleClick:i=!0,panOnDrag:l=!0,defaultViewport:c,translateExtent:d,minZoom:h,maxZoom:u,zoomActivationKeyCode:f,preventScrolling:m=!0,children:g,noWheelClassName:y,noPanClassName:k,onViewportChange:v,isControlledViewport:b,paneClickDistance:x,selectionOnDrag:w}){const N=rt(),j=p.useRef(null),{userSelectionActive:E,lib:C,connectionInProgress:D}=Fe(Km,ot),_=dr(f),I=p.useRef();Vm(j);const O=p.useCallback(q=>{v?.({x:q[0],y:q[1],zoom:q[2]}),b||N.setState({transform:q})},[v,b]);return p.useEffect(()=>{if(j.current){I.current=em({domNode:j.current,minZoom:h,maxZoom:u,translateExtent:d,viewport:c,onDraggingChange:L=>N.setState(z=>z.paneDragging===L?z:{paneDragging:L}),onPanZoomStart:(L,z)=>{const{onViewportChangeStart:R,onMoveStart:A}=N.getState();A?.(L,z),R?.(z)},onPanZoom:(L,z)=>{const{onViewportChange:R,onMove:A}=N.getState();A?.(L,z),R?.(z)},onPanZoomEnd:(L,z)=>{const{onViewportChangeEnd:R,onMoveEnd:A}=N.getState();A?.(L,z),R?.(z)}});const{x:q,y:T,zoom:B}=I.current.getViewport();return N.setState({panZoom:I.current,transform:[q,T,B],domNode:j.current.closest(".react-flow")}),()=>{I.current?.destroy()}}},[]),p.useEffect(()=>{I.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:s,panOnScrollSpeed:o,panOnScrollMode:a,zoomOnDoubleClick:i,panOnDrag:l,zoomActivationKeyPressed:_,preventScrolling:m,noPanClassName:k,userSelectionActive:E,noWheelClassName:y,lib:C,onTransformChange:O,connectionInProgress:D,selectionOnDrag:w,paneClickDistance:x})},[e,t,n,s,o,a,i,l,_,m,k,E,y,C,O,D,w,x]),r.jsx("div",{className:"react-flow__renderer",ref:j,style:So,children:g})}const Ym=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function Gm(){const{userSelectionActive:e,userSelectionRect:t}=Fe(Ym,ot);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 Jo=(e,t)=>n=>{n.target===t.current&&e?.(n)},Xm=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function Zm({isSelecting:e,selectionKeyPressed:t,selectionMode:n=ir.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 y=rt(),{userSelectionActive:k,elementsSelectable:v,dragging:b,connectionInProgress:x}=Fe(Xm,ot),w=v&&(e||k),N=p.useRef(null),j=p.useRef(),E=p.useRef(new Set),C=p.useRef(new Set),D=p.useRef(!1),_=R=>{if(D.current||x){D.current=!1;return}c?.(R),y.getState().resetSelectedElements(),y.setState({nodesSelectionActive:!1})},I=R=>{if(Array.isArray(s)&&s?.includes(2)){R.preventDefault();return}d?.(R)},O=h?R=>h(R):void 0,q=R=>{D.current&&(R.stopPropagation(),D.current=!1)},T=R=>{const{domNode:A}=y.getState();if(j.current=A?.getBoundingClientRect(),!j.current)return;const $=R.target===N.current;if(!$&&!!R.target.closest(".nokey")||!e||!(a&&$||t)||R.button!==0||!R.isPrimary)return;R.target?.setPointerCapture?.(R.pointerId),D.current=!1;const{x:X,y:P}=Jt(R.nativeEvent,j.current);y.setState({userSelectionRect:{width:0,height:0,startX:X,startY:P,x:X,y:P}}),$||(R.stopPropagation(),R.preventDefault())},B=R=>{const{userSelectionRect:A,transform:$,nodeLookup:F,edgeLookup:W,connectionLookup:X,triggerNodeChanges:P,triggerEdgeChanges:M,defaultEdgeOptions:K,resetSelectedElements:V}=y.getState();if(!j.current||!A)return;const{x:H,y:Z}=Jt(R.nativeEvent,j.current),{startX:ee,startY:oe}=A;if(!D.current){const fe=t?0:o;if(Math.hypot(H-ee,Z-oe)<=fe)return;V(),i?.(R)}D.current=!0;const de={startX:ee,startY:oe,x:H<ee?H:ee,y:Z<oe?Z:oe,width:Math.abs(H-ee),height:Math.abs(Z-oe)},Q=E.current,le=C.current;E.current=new Set(Ma(F,de,$,n===ir.Partial,!0).map(fe=>fe.id)),C.current=new Set;const ue=K?.selectable??!0;for(const fe of E.current){const ge=X.get(fe);if(ge)for(const{edgeId:we}of ge.values()){const me=W.get(we);me&&(me.selectable??ue)&&C.current.add(we)}}if(!Yi(Q,E.current)){const fe=bs(F,E.current,!0);P(fe)}if(!Yi(le,C.current)){const fe=bs(W,C.current);M(fe)}y.setState({userSelectionRect:de,userSelectionActive:!0,nodesSelectionActive:!1})},L=R=>{R.button===0&&(R.target?.releasePointerCapture?.(R.pointerId),!k&&R.target===N.current&&y.getState().userSelectionRect&&_?.(R),y.setState({userSelectionActive:!1,userSelectionRect:null}),D.current&&(l?.(R),y.setState({nodesSelectionActive:E.current.size>0})))},z=s===!0||Array.isArray(s)&&s.includes(0);return r.jsxs("div",{className:yt(["react-flow__pane",{draggable:z,dragging:b,selection:e}]),onClick:w?void 0:Jo(_,N),onContextMenu:Jo(I,N),onWheel:Jo(O,N),onPointerEnter:w?void 0:u,onPointerMove:w?B:f,onPointerUp:w?L:void 0,onPointerDownCapture:w?T:void 0,onClickCapture:w?q:void 0,onPointerLeave:m,ref:N,style:So,children:[g,r.jsx(Gm,{})]})}function xa({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 Nd({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:s,nodeId:o,isSelectable:a,nodeClickDistance:i}){const l=rt(),[c,d]=p.useState(!1),h=p.useRef();return p.useEffect(()=>{h.current=zh({getStoreItems:()=>l.getState(),onNodeMouseDown:u=>{xa({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 Qm=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function Sd(){const e=rt();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=Qm(i),m=o?a[0]:5,g=o?a[1]:5,y=n.direction.x*m*n.factor,k=n.direction.y*g*n.factor;for(const[,v]of d){if(!f(v))continue;let b={x:v.internals.positionAbsolute.x+y,y:v.internals.positionAbsolute.y+k};o&&(b=gr(b,a));const{position:x,positionAbsolute:w}=Wc({nodeId:v.id,nextPosition:b,nodeLookup:d,nodeExtent:s,nodeOrigin:h,onError:l});v.position=x,v.internals.positionAbsolute=w,u.set(v.id,v)}c(u)},[])}const Ba=p.createContext(null),Jm=Ba.Provider;Ba.Consumer;const Cd=()=>p.useContext(Ba),ep=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),tp=(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===Cs.Strict?l?.type!==n:e!==l?.nodeId||t!==l?.id,connectionInProcess:!!l,clickConnectionInProcess:!!o,valid:h&&d}};function np({type:e="source",position:t=Ne.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,y=e==="target",k=rt(),v=Cd(),{connectOnClick:b,noPanClassName:x,rfId:w}=Fe(ep,ot),{connectingFrom:N,connectingTo:j,clickConnecting:E,isPossibleEndHandle:C,connectionInProcess:D,clickConnectionInProcess:_,valid:I}=Fe(tp(v,g,e),ot);v||k.getState().onError?.("010",ln.error010());const O=B=>{const{defaultEdgeOptions:L,onConnect:z,hasDefaultEdges:R}=k.getState(),A={...L,...B};if(R){const{edges:$,setEdges:F}=k.getState();F(Nh(A,$))}z?.(A),l?.(A)},q=B=>{if(!v)return;const L=Qc(B.nativeEvent);if(o&&(L&&B.button===0||!L)){const z=k.getState();ga.onPointerDown(B.nativeEvent,{handleDomNode:B.currentTarget,autoPanOnConnect:z.autoPanOnConnect,connectionMode:z.connectionMode,connectionRadius:z.connectionRadius,domNode:z.domNode,nodeLookup:z.nodeLookup,lib:z.lib,isTarget:y,handleId:g,nodeId:v,flowId:z.rfId,panBy:z.panBy,cancelConnection:z.cancelConnection,onConnectStart:z.onConnectStart,onConnectEnd:(...R)=>k.getState().onConnectEnd?.(...R),updateConnection:z.updateConnection,onConnect:O,isValidConnection:n||((...R)=>k.getState().isValidConnection?.(...R)??!0),getTransform:()=>k.getState().transform,getFromHandle:()=>k.getState().connection.fromHandle,autoPanSpeed:z.autoPanSpeed,dragThreshold:z.connectionDragThreshold})}L?h?.(B):u?.(B)},T=B=>{const{onClickConnectStart:L,onClickConnectEnd:z,connectionClickStartHandle:R,connectionMode:A,isValidConnection:$,lib:F,rfId:W,nodeLookup:X,connection:P}=k.getState();if(!v||!R&&!o)return;if(!R){L?.(B.nativeEvent,{nodeId:v,handleId:g,handleType:e}),k.setState({connectionClickStartHandle:{nodeId:v,type:e,id:g}});return}const M=Xc(B.target),K=n||$,{connection:V,isValid:H}=ga.isValid(B.nativeEvent,{handle:{nodeId:v,id:g,type:e},connectionMode:A,fromNodeId:R.nodeId,fromHandleId:R.id||null,fromType:R.type,isValidConnection:K,flowId:W,doc:M,lib:F,nodeLookup:X});H&&V&&O(V);const Z=structuredClone(P);delete Z.inProgress,Z.toPosition=Z.toHandle?Z.toHandle.position:null,z?.(B,Z),k.setState({connectionClickStartHandle:null})};return r.jsx("div",{"data-handleid":g,"data-nodeid":v,"data-handlepos":t,"data-id":`${w}-${v}-${g}-${e}`,className:yt(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",x,d,{source:!y,target:y,connectable:s,connectablestart:o,connectableend:a,clickconnecting:E,connectingfrom:N,connectingto:j,valid:I,connectionindicator:s&&(!D||C)&&(D||_?a:o)}]),onMouseDown:q,onTouchStart:q,onClick:b?T:void 0,ref:m,...f,children:c})}const In=p.memo(vd(np));function sp({data:e,isConnectable:t,sourcePosition:n=Ne.Bottom}){return r.jsxs(r.Fragment,{children:[e?.label,r.jsx(In,{type:"source",position:n,isConnectable:t})]})}function rp({data:e,isConnectable:t,targetPosition:n=Ne.Top,sourcePosition:s=Ne.Bottom}){return r.jsxs(r.Fragment,{children:[r.jsx(In,{type:"target",position:n,isConnectable:t}),e?.label,r.jsx(In,{type:"source",position:s,isConnectable:t})]})}function op(){return null}function ap({data:e,isConnectable:t,targetPosition:n=Ne.Top}){return r.jsxs(r.Fragment,{children:[r.jsx(In,{type:"target",position:n,isConnectable:t}),e?.label]})}const fo={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},vl={input:sp,default:rp,output:ap,group:op};function ip(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 lp=e=>{const{width:t,height:n,x:s,y:o}=pr(e.nodeLookup,{filter:a=>!!a.selected});return{width:Qt(t)?t:null,height:Qt(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 cp({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const s=rt(),{width:o,height:a,transformString:i,userSelectionActive:l}=Fe(lp,ot),c=Sd(),d=p.useRef(null);p.useEffect(()=>{n||d.current?.focus({preventScroll:!0})},[n]);const h=!l&&o!==null&&a!==null;if(Nd({nodeRef:d,disabled:!h}),!h)return null;const u=e?m=>{const g=s.getState().nodes.filter(y=>y.selected);e(m,g)}:void 0,f=m=>{Object.prototype.hasOwnProperty.call(fo,m.key)&&(m.preventDefault(),c({direction:fo[m.key],factor:m.shiftKey?4:1}))};return r.jsx("div",{className:yt(["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 jl=typeof window<"u"?window:void 0,dp=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Ed({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:y,zoomActivationKeyCode:k,elementsSelectable:v,zoomOnScroll:b,zoomOnPinch:x,panOnScroll:w,panOnScrollSpeed:N,panOnScrollMode:j,zoomOnDoubleClick:E,panOnDrag:C,defaultViewport:D,translateExtent:_,minZoom:I,maxZoom:O,preventScrolling:q,onSelectionContextMenu:T,noWheelClassName:B,noPanClassName:L,disableKeyboardA11y:z,onViewportChange:R,isControlledViewport:A}){const{nodesSelectionActive:$,userSelectionActive:F}=Fe(dp,ot),W=dr(d,{target:jl}),X=dr(y,{target:jl}),P=X||C,M=X||w,K=h&&P!==!0,V=W||F||K;return Wm({deleteKeyCode:c,multiSelectionKeyCode:g}),r.jsx(Um,{onPaneContextMenu:a,elementsSelectable:v,zoomOnScroll:b,zoomOnPinch:x,panOnScroll:M,panOnScrollSpeed:N,panOnScrollMode:j,zoomOnDoubleClick:E,panOnDrag:!W&&P,defaultViewport:D,translateExtent:_,minZoom:I,maxZoom:O,zoomActivationKeyCode:k,preventScrolling:q,noWheelClassName:B,noPanClassName:L,onViewportChange:R,isControlledViewport:A,paneClickDistance:l,selectionOnDrag:K,children:r.jsxs(Zm,{onSelectionStart:f,onSelectionEnd:m,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:s,onPaneMouseLeave:o,onPaneContextMenu:a,onPaneScroll:i,panOnDrag:P,isSelecting:!!V,selectionMode:u,selectionKeyPressed:W,paneClickDistance:l,selectionOnDrag:K,children:[e,$&&r.jsx(cp,{onSelectionContextMenu:T,noPanClassName:L,disableKeyboardA11y:z})]})})}Ed.displayName="FlowRenderer";const up=p.memo(Ed),fp=e=>t=>e?Ma(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 hp(e){return Fe(p.useCallback(fp(e),[e]),ot)}const mp=e=>e.updateNodeInternals;function pp(){const e=Fe(mp),[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 gp({node:e,nodeType:t,hasDimensions:n,resizeObserver:s}){const o=rt(),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 xp({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:y,nodeTypes:k,nodeClickDistance:v,onError:b}){const{node:x,internals:w,isParent:N}=Fe(H=>{const Z=H.nodeLookup.get(e),ee=H.parentLookup.has(e);return{node:Z,internals:Z.internals,isParent:ee}},ot);let j=x.type||"default",E=k?.[j]||vl[j];E===void 0&&(b?.("003",ln.error003(j)),j="default",E=k?.default||vl.default);const C=!!(x.draggable||l&&typeof x.draggable>"u"),D=!!(x.selectable||c&&typeof x.selectable>"u"),_=!!(x.connectable||d&&typeof x.connectable>"u"),I=!!(x.focusable||h&&typeof x.focusable>"u"),O=rt(),q=Yc(x),T=gp({node:x,nodeType:j,hasDimensions:q,resizeObserver:u}),B=Nd({nodeRef:T,disabled:x.hidden||!C,noDragClassName:f,handleSelector:x.dragHandle,nodeId:e,isSelectable:D,nodeClickDistance:v}),L=Sd();if(x.hidden)return null;const z=bn(x),R=ip(x),A=D||C||t||n||s||o,$=n?H=>n(H,{...w.userNode}):void 0,F=s?H=>s(H,{...w.userNode}):void 0,W=o?H=>o(H,{...w.userNode}):void 0,X=a?H=>a(H,{...w.userNode}):void 0,P=i?H=>i(H,{...w.userNode}):void 0,M=H=>{const{selectNodesOnDrag:Z,nodeDragThreshold:ee}=O.getState();D&&(!Z||!C||ee>0)&&xa({id:e,store:O,nodeRef:T}),t&&t(H,{...w.userNode})},K=H=>{if(!(Zc(H.nativeEvent)||g)){if(Bc.includes(H.key)&&D){const Z=H.key==="Escape";xa({id:e,store:O,unselect:Z,nodeRef:T})}else if(C&&x.selected&&Object.prototype.hasOwnProperty.call(fo,H.key)){H.preventDefault();const{ariaLabelConfig:Z}=O.getState();O.setState({ariaLiveMessage:Z["node.a11yDescription.ariaLiveMessage"]({direction:H.key.replace("Arrow","").toLowerCase(),x:~~w.positionAbsolute.x,y:~~w.positionAbsolute.y})}),L({direction:fo[H.key],factor:H.shiftKey?4:1})}}},V=()=>{if(g||!T.current?.matches(":focus-visible"))return;const{transform:H,width:Z,height:ee,autoPanOnNodeFocus:oe,setCenter:de}=O.getState();if(!oe)return;Ma(new Map([[e,x]]),{x:0,y:0,width:Z,height:ee},H,!0).length>0||de(x.position.x+z.width/2,x.position.y+z.height/2,{zoom:H[2]})};return r.jsx("div",{className:yt(["react-flow__node",`react-flow__node-${j}`,{[m]:C},x.className,{selected:x.selected,selectable:D,parent:N,draggable:C,dragging:B}]),ref:T,style:{zIndex:w.z,transform:`translate(${w.positionAbsolute.x}px,${w.positionAbsolute.y}px)`,pointerEvents:A?"all":"none",visibility:q?"visible":"hidden",...x.style,...R},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:$,onMouseMove:F,onMouseLeave:W,onContextMenu:X,onClick:M,onDoubleClick:P,onKeyDown:I?K:void 0,tabIndex:I?0:void 0,onFocus:I?V:void 0,role:x.ariaRole??(I?"group":void 0),"aria-roledescription":"node","aria-describedby":g?void 0:`${gd}-${y}`,"aria-label":x.ariaLabel,...x.domAttributes,children:r.jsx(Jm,{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:D,draggable:C,deletable:x.deletable??!0,isConnectable:_,sourcePosition:x.sourcePosition,targetPosition:x.targetPosition,dragging:B,dragHandle:x.dragHandle,zIndex:w.z,parentId:x.parentId,...z})})})}var bp=p.memo(xp);const yp=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function Td(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:s,elementsSelectable:o,onError:a}=Fe(yp,ot),i=hp(e.onlyRenderVisibleElements),l=pp();return r.jsx("div",{className:"react-flow__nodes",style:So,children:i.map(c=>r.jsx(bp,{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))})}Td.displayName="NodeRenderer";const wp=p.memo(Td);function kp(e){return Fe(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&&kh({sourceNode:a,targetNode:i,width:n.width,height:n.height,transform:n.transform})&&s.push(o.id)}return s},[e]),ot)}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"})},jp=({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"})},Nl={[Es.Arrow]:vp,[Es.ArrowClosed]:jp};function Np(e){const t=rt();return p.useMemo(()=>Object.prototype.hasOwnProperty.call(Nl,e)?Nl[e]:(t.getState().onError?.("009",ln.error009(e)),null),[e])}const Sp=({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=Np(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},Id=({defaultColor:e,rfId:t})=>{const n=Fe(a=>a.edges),s=Fe(a=>a.defaultEdgeOptions),o=p.useMemo(()=>Ih(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(Sp,{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};Id.displayName="MarkerDefinitions";var Cp=p.memo(Id);function Md({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=yt(["react-flow__edge-textwrapper",d]),g=p.useRef(null);return p.useEffect(()=>{if(g.current){const y=g.current.getBBox();f({x:y.x,y:y.y,width:y.width,height:y.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}Md.displayName="EdgeText";const Ep=p.memo(Md);function Co({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:yt(["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&&Qt(t)&&Qt(n)?r.jsx(Ep,{x:t,y:n,label:s,labelStyle:o,labelShowBg:a,labelBgStyle:i,labelBgPadding:l,labelBgBorderRadius:c}):null]})}function Sl({pos:e,x1:t,y1:n,x2:s,y2:o}){return e===Ne.Left||e===Ne.Right?[.5*(t+s),n]:[t,.5*(n+o)]}function Ad({sourceX:e,sourceY:t,sourcePosition:n=Ne.Bottom,targetX:s,targetY:o,targetPosition:a=Ne.Top}){const[i,l]=Sl({pos:n,x1:e,y1:t,x2:s,y2:o}),[c,d]=Sl({pos:a,x1:s,y1:o,x2:e,y2:t}),[h,u,f,m]=Jc({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 Ld(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:y,markerStart:k,interactionWidth:v})=>{const[b,x,w]=Ad({sourceX:n,sourceY:s,sourcePosition:i,targetX:o,targetY:a,targetPosition:l}),N=e.isInternal?void 0:t;return r.jsx(Co,{id:N,path:b,labelX:x,labelY:w,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:m,style:g,markerEnd:y,markerStart:k,interactionWidth:v})})}const Tp=Ld({isInternal:!1}),_d=Ld({isInternal:!0});Tp.displayName="SimpleBezierEdge";_d.displayName="SimpleBezierEdgeInternal";function Rd(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=Ne.Bottom,targetPosition:g=Ne.Top,markerEnd:y,markerStart:k,pathOptions:v,interactionWidth:b})=>{const[x,w,N]=ha({sourceX:n,sourceY:s,sourcePosition:m,targetX:o,targetY:a,targetPosition:g,borderRadius:v?.borderRadius,offset:v?.offset,stepPosition:v?.stepPosition}),j=e.isInternal?void 0:t;return r.jsx(Co,{id:j,path:x,labelX:w,labelY:N,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:u,style:f,markerEnd:y,markerStart:k,interactionWidth:b})})}const Dd=Rd({isInternal:!1}),Od=Rd({isInternal:!0});Dd.displayName="SmoothStepEdge";Od.displayName="SmoothStepEdgeInternal";function $d(e){return p.memo(({id:t,...n})=>{const s=e.isInternal?void 0:t;return r.jsx(Dd,{...n,id:s,pathOptions:p.useMemo(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}const Ip=$d({isInternal:!1}),Pd=$d({isInternal:!0});Ip.displayName="StepEdge";Pd.displayName="StepEdgeInternal";function Bd(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:y})=>{const[k,v,b]=nd({sourceX:n,sourceY:s,targetX:o,targetY:a}),x=e.isInternal?void 0:t;return r.jsx(Co,{id:x,path:k,labelX:v,labelY:b,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:u,style:f,markerEnd:m,markerStart:g,interactionWidth:y})})}const Mp=Bd({isInternal:!1}),zd=Bd({isInternal:!0});Mp.displayName="StraightEdge";zd.displayName="StraightEdgeInternal";function qd(e){return p.memo(({id:t,sourceX:n,sourceY:s,targetX:o,targetY:a,sourcePosition:i=Ne.Bottom,targetPosition:l=Ne.Top,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:m,style:g,markerEnd:y,markerStart:k,pathOptions:v,interactionWidth:b})=>{const[x,w,N]=ed({sourceX:n,sourceY:s,sourcePosition:i,targetX:o,targetY:a,targetPosition:l,curvature:v?.curvature}),j=e.isInternal?void 0:t;return r.jsx(Co,{id:j,path:x,labelX:w,labelY:N,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:m,style:g,markerEnd:y,markerStart:k,interactionWidth:b})})}const Ap=qd({isInternal:!1}),Fd=qd({isInternal:!0});Ap.displayName="BezierEdge";Fd.displayName="BezierEdgeInternal";const Cl={default:Fd,straight:zd,step:Pd,smoothstep:Od,simplebezier:_d},El={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},Lp=(e,t,n)=>n===Ne.Left?e-t:n===Ne.Right?e+t:e,_p=(e,t,n)=>n===Ne.Top?e-t:n===Ne.Bottom?e+t:e,Tl="react-flow__edgeupdater";function Il({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:yt([Tl,`${Tl}-${l}`]),cx:Lp(t,s,e),cy:_p(n,s,e),r:s,stroke:"transparent",fill:"transparent"})}function Rp({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=rt(),y=(w,N)=>{if(w.button!==0)return;const{autoPanOnConnect:j,domNode:E,connectionMode:C,connectionRadius:D,lib:_,onConnectStart:I,cancelConnection:O,nodeLookup:q,rfId:T,panBy:B,updateConnection:L}=g.getState(),z=N.type==="target",R=(F,W)=>{f(!1),u?.(F,n,N.type,W)},A=F=>d?.(n,F),$=(F,W)=>{f(!0),h?.(w,n,N.type),I?.(F,W)};ga.onPointerDown(w.nativeEvent,{autoPanOnConnect:j,connectionMode:C,connectionRadius:D,domNode:E,handleId:N.id,nodeId:N.nodeId,nodeLookup:q,isTarget:z,edgeUpdaterType:N.type,lib:_,flowId:T,cancelConnection:O,panBy:B,isValidConnection:(...F)=>g.getState().isValidConnection?.(...F)??!0,onConnect:A,onConnectStart:$,onConnectEnd:(...F)=>g.getState().onConnectEnd?.(...F),onReconnectEnd:R,updateConnection:L,getTransform:()=>g.getState().transform,getFromHandle:()=>g.getState().connection.fromHandle,dragThreshold:g.getState().connectionDragThreshold,handleDomNode:w.currentTarget})},k=w=>y(w,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),v=w=>y(w,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),b=()=>m(!0),x=()=>m(!1);return r.jsxs(r.Fragment,{children:[(e===!0||e==="source")&&r.jsx(Il,{position:l,centerX:s,centerY:o,radius:t,onMouseDown:k,onMouseEnter:b,onMouseOut:x,type:"source"}),(e===!0||e==="target")&&r.jsx(Il,{position:c,centerX:a,centerY:i,radius:t,onMouseDown:v,onMouseEnter:b,onMouseOut:x,type:"target"})]})}function Dp({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:y,noPanClassName:k,onError:v,disableKeyboardA11y:b}){let x=Fe(de=>de.edgeLookup.get(e));const w=Fe(de=>de.defaultEdgeOptions);x=w?{...w,...x}:x;let N=x.type||"default",j=y?.[N]||Cl[N];j===void 0&&(v?.("011",ln.error011(N)),N="default",j=y?.default||Cl.default);const E=!!(x.focusable||t&&typeof x.focusable>"u"),C=typeof u<"u"&&(x.reconnectable||n&&typeof x.reconnectable>"u"),D=!!(x.selectable||s&&typeof x.selectable>"u"),_=p.useRef(null),[I,O]=p.useState(!1),[q,T]=p.useState(!1),B=rt(),{zIndex:L,sourceX:z,sourceY:R,targetX:A,targetY:$,sourcePosition:F,targetPosition:W}=Fe(p.useCallback(de=>{const Q=de.nodeLookup.get(x.source),le=de.nodeLookup.get(x.target);if(!Q||!le)return{zIndex:x.zIndex,...El};const ue=Th({id:e,sourceNode:Q,targetNode:le,sourceHandle:x.sourceHandle||null,targetHandle:x.targetHandle||null,connectionMode:de.connectionMode,onError:v});return{zIndex:wh({selected:x.selected,zIndex:x.zIndex,sourceNode:Q,targetNode:le,elevateOnSelect:de.elevateEdgesOnSelect,zIndexMode:de.zIndexMode}),...ue||El}},[x.source,x.target,x.sourceHandle,x.targetHandle,x.selected,x.zIndex]),ot),X=p.useMemo(()=>x.markerStart?`url('#${ma(x.markerStart,g)}')`:void 0,[x.markerStart,g]),P=p.useMemo(()=>x.markerEnd?`url('#${ma(x.markerEnd,g)}')`:void 0,[x.markerEnd,g]);if(x.hidden||z===null||R===null||A===null||$===null)return null;const M=de=>{const{addSelectedEdges:Q,unselectNodesAndEdges:le,multiSelectionActive:ue}=B.getState();D&&(B.setState({nodesSelectionActive:!1}),x.selected&&ue?(le({nodes:[],edges:[x]}),_.current?.blur()):Q([e])),o&&o(de,x)},K=a?de=>{a(de,{...x})}:void 0,V=i?de=>{i(de,{...x})}:void 0,H=l?de=>{l(de,{...x})}:void 0,Z=c?de=>{c(de,{...x})}:void 0,ee=d?de=>{d(de,{...x})}:void 0,oe=de=>{if(!b&&Bc.includes(de.key)&&D){const{unselectNodesAndEdges:Q,addSelectedEdges:le}=B.getState();de.key==="Escape"?(_.current?.blur(),Q({edges:[x]})):le([e])}};return r.jsx("svg",{style:{zIndex:L},children:r.jsxs("g",{className:yt(["react-flow__edge",`react-flow__edge-${N}`,x.className,k,{selected:x.selected,animated:x.animated,inactive:!D&&!o,updating:I,selectable:D}]),onClick:M,onDoubleClick:K,onContextMenu:V,onMouseEnter:H,onMouseMove:Z,onMouseLeave:ee,onKeyDown:E?oe: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?`${xd}-${g}`:void 0,ref:_,...x.domAttributes,children:[!q&&r.jsx(j,{id:e,source:x.source,target:x.target,type:x.type,selected:x.selected,animated:x.animated,selectable:D,deletable:x.deletable??!0,label:x.label,labelStyle:x.labelStyle,labelShowBg:x.labelShowBg,labelBgStyle:x.labelBgStyle,labelBgPadding:x.labelBgPadding,labelBgBorderRadius:x.labelBgBorderRadius,sourceX:z,sourceY:R,targetX:A,targetY:$,sourcePosition:F,targetPosition:W,data:x.data,style:x.style,sourceHandleId:x.sourceHandle,targetHandleId:x.targetHandle,markerStart:X,markerEnd:P,pathOptions:"pathOptions"in x?x.pathOptions:void 0,interactionWidth:x.interactionWidth}),C&&r.jsx(Rp,{edge:x,isReconnectable:C,reconnectRadius:h,onReconnect:u,onReconnectStart:f,onReconnectEnd:m,sourceX:z,sourceY:R,targetX:A,targetY:$,sourcePosition:F,targetPosition:W,setUpdateHover:O,setReconnecting:T})]})})}var Op=p.memo(Dp);const $p=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function Hd({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:y}){const{edgesFocusable:k,edgesReconnectable:v,elementsSelectable:b,onError:x}=Fe($p,ot),w=kp(t);return r.jsxs("div",{className:"react-flow__edges",children:[r.jsx(Cp,{defaultColor:e,rfId:n}),w.map(N=>r.jsx(Op,{id:N,edgesFocusable:k,edgesReconnectable:v,elementsSelectable:b,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:y},N))]})}Hd.displayName="EdgeRenderer";const Pp=p.memo(Hd),Bp=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function zp({children:e}){const t=Fe(Bp);return r.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function qp(e){const t=Pa(),n=p.useRef(!1);p.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Fp=e=>e.panZoom?.syncViewport;function Hp(e){const t=Fe(Fp),n=rt();return p.useEffect(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function Wp(e){return e.connection.inProgress?{...e.connection,to:xr(e.connection.to,e.transform)}:{...e.connection}}function Vp(e){return Wp}function Kp(e){const t=Vp();return Fe(t,ot)}const Up=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function Yp({containerStyle:e,style:t,type:n,component:s}){const{nodesConnectable:o,width:a,height:i,isValid:l,inProgress:c}=Fe(Up,ot);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:yt(["react-flow__connection",Fc(l)]),children:r.jsx(Wd,{style:t,type:n,CustomComponent:s,isValid:l})})})}const Wd=({style:e,type:t=Sn.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}=Kp();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:Fc(s),toNode:h,toHandle:u,pointer:m});let g="";const y={sourceX:a.x,sourceY:a.y,sourcePosition:c,targetX:d.x,targetY:d.y,targetPosition:f};switch(t){case Sn.Bezier:[g]=ed(y);break;case Sn.SimpleBezier:[g]=Ad(y);break;case Sn.Step:[g]=ha({...y,borderRadius:0});break;case Sn.SmoothStep:[g]=ha(y);break;default:[g]=nd(y)}return r.jsx("path",{d:g,fill:"none",className:"react-flow__connection-path",style:e})};Wd.displayName="ConnectionLine";const Gp={};function Ml(e=Gp){p.useRef(e),rt(),p.useEffect(()=>{},[e])}function Xp(){rt(),p.useRef(!1),p.useEffect(()=>{},[])}function Vd({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:y,connectionLineComponent:k,connectionLineContainerStyle:v,selectionKeyCode:b,selectionOnDrag:x,selectionMode:w,multiSelectionKeyCode:N,panActivationKeyCode:j,zoomActivationKeyCode:E,deleteKeyCode:C,onlyRenderVisibleElements:D,elementsSelectable:_,defaultViewport:I,translateExtent:O,minZoom:q,maxZoom:T,preventScrolling:B,defaultMarkerColor:L,zoomOnScroll:z,zoomOnPinch:R,panOnScroll:A,panOnScrollSpeed:$,panOnScrollMode:F,zoomOnDoubleClick:W,panOnDrag:X,onPaneClick:P,onPaneMouseEnter:M,onPaneMouseMove:K,onPaneMouseLeave:V,onPaneScroll:H,onPaneContextMenu:Z,paneClickDistance:ee,nodeClickDistance:oe,onEdgeContextMenu:de,onEdgeMouseEnter:Q,onEdgeMouseMove:le,onEdgeMouseLeave:ue,reconnectRadius:fe,onReconnect:ge,onReconnectStart:we,onReconnectEnd:me,noDragClassName:ve,noWheelClassName:Te,noPanClassName:je,disableKeyboardA11y:Ke,nodeExtent:Nt,rfId:wt,viewport:ce,onViewportChange:xe}){return Ml(e),Ml(t),Xp(),qp(n),Hp(ce),r.jsx(up,{onPaneClick:P,onPaneMouseEnter:M,onPaneMouseMove:K,onPaneMouseLeave:V,onPaneContextMenu:Z,onPaneScroll:H,paneClickDistance:ee,deleteKeyCode:C,selectionKeyCode:b,selectionOnDrag:x,selectionMode:w,onSelectionStart:f,onSelectionEnd:m,multiSelectionKeyCode:N,panActivationKeyCode:j,zoomActivationKeyCode:E,elementsSelectable:_,zoomOnScroll:z,zoomOnPinch:R,zoomOnDoubleClick:W,panOnScroll:A,panOnScrollSpeed:$,panOnScrollMode:F,panOnDrag:X,defaultViewport:I,translateExtent:O,minZoom:q,maxZoom:T,onSelectionContextMenu:u,preventScrolling:B,noDragClassName:ve,noWheelClassName:Te,noPanClassName:je,disableKeyboardA11y:Ke,onViewportChange:xe,isControlledViewport:!!ce,children:r.jsxs(zp,{children:[r.jsx(Pp,{edgeTypes:t,onEdgeClick:o,onEdgeDoubleClick:i,onReconnect:ge,onReconnectStart:we,onReconnectEnd:me,onlyRenderVisibleElements:D,onEdgeContextMenu:de,onEdgeMouseEnter:Q,onEdgeMouseMove:le,onEdgeMouseLeave:ue,reconnectRadius:fe,defaultMarkerColor:L,noPanClassName:je,disableKeyboardA11y:Ke,rfId:wt}),r.jsx(Yp,{style:y,type:g,component:k,containerStyle:v}),r.jsx("div",{className:"react-flow__edgelabel-renderer"}),r.jsx(wp,{nodeTypes:e,onNodeClick:s,onNodeDoubleClick:a,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:h,nodeClickDistance:oe,onlyRenderVisibleElements:D,noPanClassName:je,noDragClassName:ve,disableKeyboardA11y:Ke,nodeExtent:Nt,rfId:wt}),r.jsx("div",{className:"react-flow__viewport-portal"})]})})}Vd.displayName="GraphView";const Zp=p.memo(Vd),Al=({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,y=new Map,k=new Map,v=s??t??[],b=n??e??[],x=h??[0,0],w=u??ar;od(y,k,v);const N=pa(b,m,g,{nodeOrigin:x,nodeExtent:w,zIndexMode:f});let j=[0,0,1];if(i&&o&&a){const E=pr(m,{filter:I=>!!((I.width||I.initialWidth)&&(I.height||I.initialHeight))}),{x:C,y:D,zoom:_}=Aa(E,o,a,c,d,l?.padding??.1);j=[C,D,_]}return{rfId:"1",width:o??0,height:a??0,transform:j,nodes:b,nodesInitialized:N,nodeLookup:m,parentLookup:g,edges:v,edgeLookup:k,connectionLookup:y,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:s!==void 0,panZoom:null,minZoom:c,maxZoom:d,translateExtent:ar,nodeExtent:w,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Cs.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:{...qc},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:mh,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:zc,zIndexMode:f,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},Qp=({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})=>gm((m,g)=>{async function y(){const{nodeLookup:k,panZoom:v,fitViewOptions:b,fitViewResolver:x,width:w,height:N,minZoom:j,maxZoom:E}=g();v&&(await fh({nodes:k,width:w,height:N,panZoom:v,minZoom:j,maxZoom:E},b),x?.resolve(!0),m({fitViewResolver:null}))}return{...Al({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:k=>{const{nodeLookup:v,parentLookup:b,nodeOrigin:x,elevateNodesOnSelect:w,fitViewQueued:N,zIndexMode:j}=g(),E=pa(k,v,b,{nodeOrigin:x,nodeExtent:u,elevateNodesOnSelect:w,checkEquality:!0,zIndexMode:j});N&&E?(y(),m({nodes:k,nodesInitialized:E,fitViewQueued:!1,fitViewOptions:void 0})):m({nodes:k,nodesInitialized:E})},setEdges:k=>{const{connectionLookup:v,edgeLookup:b}=g();od(v,b,k),m({edges:k})},setDefaultNodesAndEdges:(k,v)=>{if(k){const{setNodes:b}=g();b(k),m({hasDefaultNodes:!0})}if(v){const{setEdges:b}=g();b(v),m({hasDefaultEdges:!0})}},updateNodeInternals:k=>{const{triggerNodeChanges:v,nodeLookup:b,parentLookup:x,domNode:w,nodeOrigin:N,nodeExtent:j,debug:E,fitViewQueued:C,zIndexMode:D}=g(),{changes:_,updatedInternals:I}=Oh(k,b,x,w,N,j,D);I&&(Lh(b,x,{nodeOrigin:N,nodeExtent:j,zIndexMode:D}),C?(y(),m({fitViewQueued:!1,fitViewOptions:void 0})):m({}),_?.length>0&&(E&&console.log("React Flow: trigger node changes",_),v?.(_)))},updateNodePositions:(k,v=!1)=>{const b=[];let x=[];const{nodeLookup:w,triggerNodeChanges:N,connection:j,updateConnection:E,onNodesChangeMiddlewareMap:C}=g();for(const[D,_]of k){const I=w.get(D),O=!!(I?.expandParent&&I?.parentId&&_?.position),q={id:D,type:"position",position:O?{x:Math.max(0,_.position.x),y:Math.max(0,_.position.y)}:_.position,dragging:v};if(I&&j.inProgress&&j.fromNode.id===I.id){const T=Qn(I,j.fromHandle,Ne.Left,!0);E({...j,from:T})}O&&I.parentId&&b.push({id:D,parentId:I.parentId,rect:{..._.internals.positionAbsolute,width:_.measured.width??0,height:_.measured.height??0}}),x.push(q)}if(b.length>0){const{parentLookup:D,nodeOrigin:_}=g(),I=$a(b,w,D,_);x.push(...I)}for(const D of C.values())x=D(x);N(x)},triggerNodeChanges:k=>{const{onNodesChange:v,setNodes:b,nodes:x,hasDefaultNodes:w,debug:N}=g();if(k?.length){if(w){const j=wd(k,x);b(j)}N&&console.log("React Flow: trigger node changes",k),v?.(k)}},triggerEdgeChanges:k=>{const{onEdgesChange:v,setEdges:b,edges:x,hasDefaultEdges:w,debug:N}=g();if(k?.length){if(w){const j=kd(k,x);b(j)}N&&console.log("React Flow: trigger edge changes",k),v?.(k)}},addSelectedNodes:k=>{const{multiSelectionActive:v,edgeLookup:b,nodeLookup:x,triggerNodeChanges:w,triggerEdgeChanges:N}=g();if(v){const j=k.map(E=>Vn(E,!0));w(j);return}w(bs(x,new Set([...k]),!0)),N(bs(b))},addSelectedEdges:k=>{const{multiSelectionActive:v,edgeLookup:b,nodeLookup:x,triggerNodeChanges:w,triggerEdgeChanges:N}=g();if(v){const j=k.map(E=>Vn(E,!0));N(j);return}N(bs(b,new Set([...k]))),w(bs(x,new Set,!0))},unselectNodesAndEdges:({nodes:k,edges:v}={})=>{const{edges:b,nodes:x,nodeLookup:w,triggerNodeChanges:N,triggerEdgeChanges:j}=g(),E=k||x,C=v||b,D=[];for(const I of E){if(!I.selected)continue;const O=w.get(I.id);O&&(O.selected=!1),D.push(Vn(I.id,!1))}const _=[];for(const I of C)I.selected&&_.push(Vn(I.id,!1));N(D),j(_)},setMinZoom:k=>{const{panZoom:v,maxZoom:b}=g();v?.setScaleExtent([k,b]),m({minZoom:k})},setMaxZoom:k=>{const{panZoom:v,minZoom:b}=g();v?.setScaleExtent([b,k]),m({maxZoom:k})},setTranslateExtent:k=>{g().panZoom?.setTranslateExtent(k),m({translateExtent:k})},resetSelectedElements:()=>{const{edges:k,nodes:v,triggerNodeChanges:b,triggerEdgeChanges:x,elementsSelectable:w}=g();if(!w)return;const N=v.reduce((E,C)=>C.selected?[...E,Vn(C.id,!1)]:E,[]),j=k.reduce((E,C)=>C.selected?[...E,Vn(C.id,!1)]:E,[]);b(N),x(j)},setNodeExtent:k=>{const{nodes:v,nodeLookup:b,parentLookup:x,nodeOrigin:w,elevateNodesOnSelect:N,nodeExtent:j,zIndexMode:E}=g();k[0][0]===j[0][0]&&k[0][1]===j[0][1]&&k[1][0]===j[1][0]&&k[1][1]===j[1][1]||(pa(v,b,x,{nodeOrigin:w,nodeExtent:k,elevateNodesOnSelect:N,checkEquality:!1,zIndexMode:E}),m({nodeExtent:k}))},panBy:k=>{const{transform:v,width:b,height:x,panZoom:w,translateExtent:N}=g();return $h({delta:k,panZoom:w,transform:v,translateExtent:N,width:b,height:x})},setCenter:async(k,v,b)=>{const{width:x,height:w,maxZoom:N,panZoom:j}=g();if(!j)return Promise.resolve(!1);const E=typeof b?.zoom<"u"?b.zoom:N;return await j.setViewport({x:x/2-k*E,y:w/2-v*E,zoom:E},{duration:b?.duration,ease:b?.ease,interpolate:b?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{m({connection:{...qc}})},updateConnection:k=>{m({connection:k})},reset:()=>m({...Al()})}},Object.is);function Jp({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(()=>Qp({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(xm,{value:g,children:r.jsx(zm,{children:m})})}function eg({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(jo)?r.jsx(r.Fragment,{children:e}):r.jsx(Jp,{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 tg={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:y,onClickConnectStart:k,onClickConnectEnd:v,onNodeMouseEnter:b,onNodeMouseMove:x,onNodeMouseLeave:w,onNodeContextMenu:N,onNodeDoubleClick:j,onNodeDragStart:E,onNodeDrag:C,onNodeDragStop:D,onNodesDelete:_,onEdgesDelete:I,onDelete:O,onSelectionChange:q,onSelectionDragStart:T,onSelectionDrag:B,onSelectionDragStop:L,onSelectionContextMenu:z,onSelectionStart:R,onSelectionEnd:A,onBeforeDelete:$,connectionMode:F,connectionLineType:W=Sn.Bezier,connectionLineStyle:X,connectionLineComponent:P,connectionLineContainerStyle:M,deleteKeyCode:K="Backspace",selectionKeyCode:V="Shift",selectionOnDrag:H=!1,selectionMode:Z=ir.Full,panActivationKeyCode:ee="Space",multiSelectionKeyCode:oe=cr()?"Meta":"Control",zoomActivationKeyCode:de=cr()?"Meta":"Control",snapToGrid:Q,snapGrid:le,onlyRenderVisibleElements:ue=!1,selectNodesOnDrag:fe,nodesDraggable:ge,autoPanOnNodeFocus:we,nodesConnectable:me,nodesFocusable:ve,nodeOrigin:Te=bd,edgesFocusable:je,edgesReconnectable:Ke,elementsSelectable:Nt=!0,defaultViewport:wt=Mm,minZoom:ce=.5,maxZoom:xe=2,translateExtent:be=ar,preventScrolling:at=!0,nodeExtent:Ye,defaultMarkerColor:Oe="#b1b1b7",zoomOnScroll:kt=!0,zoomOnPinch:Et=!0,panOnScroll:Tt=!1,panOnScrollSpeed:te=.5,panOnScrollMode:Ae=Xn.Free,zoomOnDoubleClick:Ue=!0,panOnDrag:$e=!0,onPaneClick:it,onPaneMouseEnter:Qe,onPaneMouseMove:Pe,onPaneMouseLeave:qe,onPaneScroll:Je,onPaneContextMenu:G,paneClickDistance:ae=1,nodeClickDistance:ye=0,children:Se,onReconnect:re,onReconnectStart:ke,onReconnectEnd:_e,onEdgeContextMenu:It,onEdgeDoubleClick:Mt,onEdgeMouseEnter:ft,onEdgeMouseMove:Ot,onEdgeMouseLeave:Re,reconnectRadius:ct=10,onNodesChange:St,onEdgesChange:sn,noDragClassName:dt="nodrag",noWheelClassName:Ve="nowheel",noPanClassName:Xe="nopan",fitView:He,fitViewOptions:tt,connectOnClick:xt,attributionPosition:ht,proOptions:Dt,defaultEdgeOptions:Ct,elevateNodesOnSelect:U=!0,elevateEdgesOnSelect:pe=!1,disableKeyboardA11y:De=!1,autoPanOnConnect:Be,autoPanOnNodeDrag:Ie,autoPanSpeed:vt,connectionRadius:Mn,isValidConnection:es,onError:An,style:Nr,id:zs,nodeDragThreshold:qs,connectionDragThreshold:Oo,viewport:$t,onViewportChange:Ln,width:_n,height:Fs,colorMode:Hs="light",debug:yn,onScroll:Rn,ariaLabelConfig:ts,zIndexMode:ns="basic",...Dn},On){const rn=zs||"1",ss=Rm(Hs),$n=p.useCallback(Ws=>{Ws.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),Rn?.(Ws)},[Rn]);return r.jsx("div",{"data-testid":"rf__wrapper",...Dn,onScroll:$n,style:{...Nr,...tg},ref:On,className:yt(["react-flow",o,ss]),id:zs,role:"application",children:r.jsxs(eg,{nodes:e,edges:t,width:_n,height:Fs,fitView:He,fitViewOptions:tt,minZoom:ce,maxZoom:xe,nodeOrigin:Te,nodeExtent:Ye,zIndexMode:ns,children:[r.jsx(Zp,{onInit:d,onNodeClick:l,onEdgeClick:c,onNodeMouseEnter:b,onNodeMouseMove:x,onNodeMouseLeave:w,onNodeContextMenu:N,onNodeDoubleClick:j,nodeTypes:a,edgeTypes:i,connectionLineType:W,connectionLineStyle:X,connectionLineComponent:P,connectionLineContainerStyle:M,selectionKeyCode:V,selectionOnDrag:H,selectionMode:Z,deleteKeyCode:K,multiSelectionKeyCode:oe,panActivationKeyCode:ee,zoomActivationKeyCode:de,onlyRenderVisibleElements:ue,defaultViewport:wt,translateExtent:be,minZoom:ce,maxZoom:xe,preventScrolling:at,zoomOnScroll:kt,zoomOnPinch:Et,zoomOnDoubleClick:Ue,panOnScroll:Tt,panOnScrollSpeed:te,panOnScrollMode:Ae,panOnDrag:$e,onPaneClick:it,onPaneMouseEnter:Qe,onPaneMouseMove:Pe,onPaneMouseLeave:qe,onPaneScroll:Je,onPaneContextMenu:G,paneClickDistance:ae,nodeClickDistance:ye,onSelectionContextMenu:z,onSelectionStart:R,onSelectionEnd:A,onReconnect:re,onReconnectStart:ke,onReconnectEnd:_e,onEdgeContextMenu:It,onEdgeDoubleClick:Mt,onEdgeMouseEnter:ft,onEdgeMouseMove:Ot,onEdgeMouseLeave:Re,reconnectRadius:ct,defaultMarkerColor:Oe,noDragClassName:dt,noWheelClassName:Ve,noPanClassName:Xe,rfId:rn,disableKeyboardA11y:De,nodeExtent:Ye,viewport:$t,onViewportChange:Ln}),r.jsx(_m,{nodes:e,edges:t,defaultNodes:n,defaultEdges:s,onConnect:m,onConnectStart:g,onConnectEnd:y,onClickConnectStart:k,onClickConnectEnd:v,nodesDraggable:ge,autoPanOnNodeFocus:we,nodesConnectable:me,nodesFocusable:ve,edgesFocusable:je,edgesReconnectable:Ke,elementsSelectable:Nt,elevateNodesOnSelect:U,elevateEdgesOnSelect:pe,minZoom:ce,maxZoom:xe,nodeExtent:Ye,onNodesChange:St,onEdgesChange:sn,snapToGrid:Q,snapGrid:le,connectionMode:F,translateExtent:be,connectOnClick:xt,defaultEdgeOptions:Ct,fitView:He,fitViewOptions:tt,onNodesDelete:_,onEdgesDelete:I,onDelete:O,onNodeDragStart:E,onNodeDrag:C,onNodeDragStop:D,onSelectionDrag:B,onSelectionDragStart:T,onSelectionDragStop:L,onMove:h,onMoveStart:u,onMoveEnd:f,noPanClassName:Xe,nodeOrigin:Te,rfId:rn,autoPanOnConnect:Be,autoPanOnNodeDrag:Ie,autoPanSpeed:vt,onError:An,connectionRadius:Mn,isValidConnection:es,selectNodesOnDrag:fe,nodeDragThreshold:qs,connectionDragThreshold:Oo,onBeforeDelete:$,debug:yn,ariaLabelConfig:ts,zIndexMode:ns}),r.jsx(Im,{onSelectionChange:q}),Se,r.jsx(Nm,{proOptions:Dt,position:ht}),r.jsx(jm,{rfId:rn,disableKeyboardA11y:De})]})})}var sg=vd(ng);function rg(){const e=rt();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 og(e){const[t,n]=p.useState(e),s=p.useCallback(o=>n(a=>wd(o,a)),[]);return[t,n,s]}function ag(e){const[t,n]=p.useState(e),s=p.useCallback(o=>n(a=>kd(o,a)),[]);return[t,n,s]}function ig({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:yt(["react-flow__background-pattern",n,s])})}function lg({radius:e,className:t}){return r.jsx("circle",{cx:e,cy:e,r:e,className:yt(["react-flow__background-pattern","dots",t])})}var En;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(En||(En={}));const cg={[En.Dots]:1,[En.Lines]:1,[En.Cross]:6},dg=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function Kd({id:e,variant:t=En.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}=Fe(dg,ot),g=s||cg[t],y=t===En.Dots,k=t===En.Cross,v=Array.isArray(n)?n:[n,n],b=[v[0]*f[2]||1,v[1]*f[2]||1],x=g*f[2],w=Array.isArray(a)?a:[a,a],N=k?[x,x]:b,j=[w[0]*f[2]||1+N[0]/2,w[1]*f[2]||1+N[1]/2],E=`${m}${e||""}`;return r.jsxs("svg",{className:yt(["react-flow__background",d]),style:{...c,...So,"--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]%b[0],y:f[1]%b[1],width:b[0],height:b[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${j[0]},-${j[1]})`,children:y?r.jsx(lg,{radius:x/2,className:h}):r.jsx(ig,{dimensions:N,lineWidth:o,variant:t,className:h})}),r.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${E})`})]})}Kd.displayName="Background";const ug=p.memo(Kd);function fg(){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 hg(){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 mg(){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 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 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 gg(){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 Vr({children:e,className:t,...n}){return r.jsx("button",{type:"button",className:yt(["react-flow__controls-button",t]),...n,children:e})}const xg=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function Ud({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=rt(),{isInteractive:y,minZoomReached:k,maxZoomReached:v,ariaLabelConfig:b}=Fe(xg,ot),{zoomIn:x,zoomOut:w,fitView:N}=Pa(),j=()=>{x(),a?.()},E=()=>{w(),i?.()},C=()=>{N(o),l?.()},D=()=>{g.setState({nodesDraggable:!y,nodesConnectable:!y,elementsSelectable:!y}),c?.(!y)},_=f==="horizontal"?"horizontal":"vertical";return r.jsxs(No,{className:yt(["react-flow__controls",_,d]),position:u,style:e,"data-testid":"rf__controls","aria-label":m??b["controls.ariaLabel"],children:[t&&r.jsxs(r.Fragment,{children:[r.jsx(Vr,{onClick:j,className:"react-flow__controls-zoomin",title:b["controls.zoomIn.ariaLabel"],"aria-label":b["controls.zoomIn.ariaLabel"],disabled:v,children:r.jsx(fg,{})}),r.jsx(Vr,{onClick:E,className:"react-flow__controls-zoomout",title:b["controls.zoomOut.ariaLabel"],"aria-label":b["controls.zoomOut.ariaLabel"],disabled:k,children:r.jsx(hg,{})})]}),n&&r.jsx(Vr,{className:"react-flow__controls-fitview",onClick:C,title:b["controls.fitView.ariaLabel"],"aria-label":b["controls.fitView.ariaLabel"],children:r.jsx(mg,{})}),s&&r.jsx(Vr,{className:"react-flow__controls-interactive",onClick:D,title:b["controls.interactive.ariaLabel"],"aria-label":b["controls.interactive.ariaLabel"],children:y?r.jsx(gg,{}):r.jsx(pg,{})}),h]})}Ud.displayName="Controls";const bg=p.memo(Ud);function yg({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:y}=a||{},k=i||g||y;return r.jsx("rect",{className:yt(["react-flow__minimap-node",{selected:f},d]),x:t,y:n,rx:h,ry:h,width:s,height:o,style:{fill:k,stroke:l,strokeWidth:c},shapeRendering:u,onClick:m?v=>m(v,e):void 0})}const wg=p.memo(yg),kg=e=>e.nodes.map(t=>t.id),ea=e=>e instanceof Function?e:()=>e;function vg({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:s=5,nodeStrokeWidth:o,nodeComponent:a=wg,onClick:i}){const l=Fe(kg,ot),c=ea(t),d=ea(e),h=ea(n),u=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return r.jsx(r.Fragment,{children:l.map(f=>r.jsx(Ng,{id:f,nodeColorFunc:c,nodeStrokeColorFunc:d,nodeClassNameFunc:h,nodeBorderRadius:s,nodeStrokeWidth:o,NodeComponent:a,onClick:i,shapeRendering:u},f))})}function jg({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}=Fe(g=>{const y=g.nodeLookup.get(e);if(!y)return{node:void 0,x:0,y:0,width:0,height:0};const k=y.internals.userNode,{x:v,y:b}=y.internals.positionAbsolute,{width:x,height:w}=bn(k);return{node:k,x:v,y:b,width:x,height:w}},ot);return!d||d.hidden||!Yc(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 Ng=p.memo(jg);var Sg=p.memo(vg);const Cg=200,Eg=150,Tg=e=>!e.hidden,Ig=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?Uc(pr(e.nodeLookup,{filter:Tg}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},Mg="react-flow__minimap-desc";function Yd({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:y=!1,zoomable:k=!1,ariaLabel:v,inversePan:b,zoomStep:x=1,offsetScale:w=5}){const N=rt(),j=p.useRef(null),{boundingRect:E,viewBB:C,rfId:D,panZoom:_,translateExtent:I,flowWidth:O,flowHeight:q,ariaLabelConfig:T}=Fe(Ig,ot),B=e?.width??Cg,L=e?.height??Eg,z=E.width/B,R=E.height/L,A=Math.max(z,R),$=A*B,F=A*L,W=w*A,X=E.x-($-E.width)/2-W,P=E.y-(F-E.height)/2-W,M=$+W*2,K=F+W*2,V=`${Mg}-${D}`,H=p.useRef(0),Z=p.useRef();H.current=A,p.useEffect(()=>{if(j.current&&_)return Z.current=Kh({domNode:j.current,panZoom:_,getTransform:()=>N.getState().transform,getViewScale:()=>H.current}),()=>{Z.current?.destroy()}},[_]),p.useEffect(()=>{Z.current?.update({translateExtent:I,width:O,height:q,inversePan:b,pannable:y,zoomStep:x,zoomable:k})},[y,k,b,x,I,O,q]);const ee=m?Q=>{const[le,ue]=Z.current?.pointer(Q)||[0,0];m(Q,{x:le,y:ue})}:void 0,oe=g?p.useCallback((Q,le)=>{const ue=N.getState().nodeLookup.get(le).internals.userNode;g(Q,ue)},[]):void 0,de=v??T["minimap.ariaLabel"];return r.jsx(No,{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:yt(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:r.jsxs("svg",{width:B,height:L,viewBox:`${X} ${P} ${M} ${K}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":V,ref:j,onClick:ee,children:[de&&r.jsx("title",{id:V,children:de}),r.jsx(Sg,{onClick:oe,nodeColor:s,nodeStrokeColor:n,nodeBorderRadius:a,nodeClassName:o,nodeStrokeWidth:i,nodeComponent:l}),r.jsx("path",{className:"react-flow__minimap-mask",d:`M${X-W},${P-W}h${M+W*2}v${K+W*2}h${-M-W*2}z
|
|
7
|
+
M${C.x},${C.y}h${C.width}v${C.height}h${-C.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}Yd.displayName="MiniMap";const Ag=p.memo(Yd),Lg=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,_g={[As.Line]:"right",[As.Handle]:"bottom-right"};function Rg({nodeId:e,position:t,variant:n=As.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:y,onResize:k,onResizeEnd:v}){const b=Cd(),x=typeof e=="string"?e:b,w=rt(),N=p.useRef(null),j=n===As.Handle,E=Fe(p.useCallback(Lg(j&&m),[j,m]),ot),C=p.useRef(null),D=t??_g[n];p.useEffect(()=>{if(!(!N.current||!x))return C.current||(C.current=am({domNode:N.current,nodeId:x,getStoreItems:()=>{const{nodeLookup:I,transform:O,snapGrid:q,snapToGrid:T,nodeOrigin:B,domNode:L}=w.getState();return{nodeLookup:I,transform:O,snapGrid:q,snapToGrid:T,nodeOrigin:B,paneDomNode:L}},onChange:(I,O)=>{const{triggerNodeChanges:q,nodeLookup:T,parentLookup:B,nodeOrigin:L}=w.getState(),z=[],R={x:I.x,y:I.y},A=T.get(x);if(A&&A.expandParent&&A.parentId){const $=A.origin??L,F=I.width??A.measured.width??0,W=I.height??A.measured.height??0,X={id:A.id,parentId:A.parentId,rect:{width:F,height:W,...Gc({x:I.x??A.position.x,y:I.y??A.position.y},{width:F,height:W},A.parentId,T,$)}},P=$a([X],T,B,L);z.push(...P),R.x=I.x?Math.max($[0]*F,I.x):void 0,R.y=I.y?Math.max($[1]*W,I.y):void 0}if(R.x!==void 0&&R.y!==void 0){const $={id:x,type:"position",position:{...R}};z.push($)}if(I.width!==void 0&&I.height!==void 0){const F={id:x,type:"dimensions",resizing:!0,setAttributes:f?f==="horizontal"?"width":"height":!0,dimensions:{width:I.width,height:I.height}};z.push(F)}for(const $ of O){const F={...$,type:"position"};z.push(F)}q(z)},onEnd:({width:I,height:O})=>{const q={id:x,type:"dimensions",resizing:!1,dimensions:{width:I,height:O}};w.getState().triggerNodeChanges([q])}})),C.current.update({controlPosition:D,boundaries:{minWidth:l,minHeight:c,maxWidth:d,maxHeight:h},keepAspectRatio:u,resizeDirection:f,onResizeStart:y,onResize:k,onResizeEnd:v,shouldResize:g}),()=>{C.current?.destroy()}},[D,l,c,d,h,u,y,k,v,g]);const _=D.split("-");return r.jsx("div",{className:yt(["react-flow__resize-control","nodrag",..._,n,s]),ref:N,style:{...o,scale:E,...i&&{[j?"backgroundColor":"borderColor"]:i}},children:a})}p.memo(Rg);var Ge=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),tn=Ge((e,t)=>{var n=Object.defineProperty,s=(q,T,B)=>T in q?n(q,T,{enumerable:!0,configurable:!0,writable:!0,value:B}):q[T]=B,o=(q,T)=>()=>(T||q((T={exports:{}}).exports,T),T.exports),a=(q,T,B)=>s(q,typeof T!="symbol"?T+"":T,B),i=o((q,T)=>{var B="\0",L="\0",z="",R=class{constructor(P){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"),P&&(this._isDirected=Object.hasOwn(P,"directed")?P.directed:!0,this._isMultigraph=Object.hasOwn(P,"multigraph")?P.multigraph:!1,this._isCompound=Object.hasOwn(P,"compound")?P.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[L]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(P){return this._label=P,this}graph(){return this._label}setDefaultNodeLabel(P){return this._defaultNodeLabelFn=P,typeof P!="function"&&(this._defaultNodeLabelFn=()=>P),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var P=this;return this.nodes().filter(M=>Object.keys(P._in[M]).length===0)}sinks(){var P=this;return this.nodes().filter(M=>Object.keys(P._out[M]).length===0)}setNodes(P,M){var K=arguments,V=this;return P.forEach(function(H){K.length>1?V.setNode(H,M):V.setNode(H)}),this}setNode(P,M){return Object.hasOwn(this._nodes,P)?(arguments.length>1&&(this._nodes[P]=M),this):(this._nodes[P]=arguments.length>1?M:this._defaultNodeLabelFn(P),this._isCompound&&(this._parent[P]=L,this._children[P]={},this._children[L][P]=!0),this._in[P]={},this._preds[P]={},this._out[P]={},this._sucs[P]={},++this._nodeCount,this)}node(P){return this._nodes[P]}hasNode(P){return Object.hasOwn(this._nodes,P)}removeNode(P){var M=this;if(Object.hasOwn(this._nodes,P)){var K=V=>M.removeEdge(M._edgeObjs[V]);delete this._nodes[P],this._isCompound&&(this._removeFromParentsChildList(P),delete this._parent[P],this.children(P).forEach(function(V){M.setParent(V)}),delete this._children[P]),Object.keys(this._in[P]).forEach(K),delete this._in[P],delete this._preds[P],Object.keys(this._out[P]).forEach(K),delete this._out[P],delete this._sucs[P],--this._nodeCount}return this}setParent(P,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===P)throw new Error("Setting "+M+" as parent of "+P+" would create a cycle");this.setNode(M)}return this.setNode(P),this._removeFromParentsChildList(P),this._parent[P]=M,this._children[M][P]=!0,this}_removeFromParentsChildList(P){delete this._children[this._parent[P]][P]}parent(P){if(this._isCompound){var M=this._parent[P];if(M!==L)return M}}children(P=L){if(this._isCompound){var M=this._children[P];if(M)return Object.keys(M)}else{if(P===L)return this.nodes();if(this.hasNode(P))return[]}}predecessors(P){var M=this._preds[P];if(M)return Object.keys(M)}successors(P){var M=this._sucs[P];if(M)return Object.keys(M)}neighbors(P){var M=this.predecessors(P);if(M){let V=new Set(M);for(var K of this.successors(P))V.add(K);return Array.from(V.values())}}isLeaf(P){var M;return this.isDirected()?M=this.successors(P):M=this.neighbors(P),M.length===0}filterNodes(P){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,ee]){P(Z)&&M.setNode(Z,ee)}),Object.values(this._edgeObjs).forEach(function(Z){M.hasNode(Z.v)&&M.hasNode(Z.w)&&M.setEdge(Z,K.edge(Z))});var V={};function H(Z){var ee=K.parent(Z);return ee===void 0||M.hasNode(ee)?(V[Z]=ee,ee):ee in V?V[ee]:H(ee)}return this._isCompound&&M.nodes().forEach(Z=>M.setParent(Z,H(Z))),M}setDefaultEdgeLabel(P){return this._defaultEdgeLabelFn=P,typeof P!="function"&&(this._defaultEdgeLabelFn=()=>P),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(P,M){var K=this,V=arguments;return P.reduce(function(H,Z){return V.length>1?K.setEdge(H,Z,M):K.setEdge(H,Z),Z}),this}setEdge(){var P,M,K,V,H=!1,Z=arguments[0];typeof Z=="object"&&Z!==null&&"v"in Z?(P=Z.v,M=Z.w,K=Z.name,arguments.length===2&&(V=arguments[1],H=!0)):(P=Z,M=arguments[1],K=arguments[3],arguments.length>2&&(V=arguments[2],H=!0)),P=""+P,M=""+M,K!==void 0&&(K=""+K);var ee=F(this._isDirected,P,M,K);if(Object.hasOwn(this._edgeLabels,ee))return H&&(this._edgeLabels[ee]=V),this;if(K!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(P),this.setNode(M),this._edgeLabels[ee]=H?V:this._defaultEdgeLabelFn(P,M,K);var oe=W(this._isDirected,P,M,K);return P=oe.v,M=oe.w,Object.freeze(oe),this._edgeObjs[ee]=oe,A(this._preds[M],P),A(this._sucs[P],M),this._in[M][ee]=oe,this._out[P][ee]=oe,this._edgeCount++,this}edge(P,M,K){var V=arguments.length===1?X(this._isDirected,arguments[0]):F(this._isDirected,P,M,K);return this._edgeLabels[V]}edgeAsObj(){let P=this.edge(...arguments);return typeof P!="object"?{label:P}:P}hasEdge(P,M,K){var V=arguments.length===1?X(this._isDirected,arguments[0]):F(this._isDirected,P,M,K);return Object.hasOwn(this._edgeLabels,V)}removeEdge(P,M,K){var V=arguments.length===1?X(this._isDirected,arguments[0]):F(this._isDirected,P,M,K),H=this._edgeObjs[V];return H&&(P=H.v,M=H.w,delete this._edgeLabels[V],delete this._edgeObjs[V],$(this._preds[M],P),$(this._sucs[P],M),delete this._in[M][V],delete this._out[P][V],this._edgeCount--),this}inEdges(P,M){return this.isDirected()?this.filterEdges(this._in[P],P,M):this.nodeEdges(P,M)}outEdges(P,M){return this.isDirected()?this.filterEdges(this._out[P],P,M):this.nodeEdges(P,M)}nodeEdges(P,M){if(P in this._nodes)return this.filterEdges({...this._in[P],...this._out[P]},P,M)}filterEdges(P,M,K){if(P){var V=Object.values(P);return K?V.filter(function(H){return H.v===M&&H.w===K||H.v===K&&H.w===M}):V}}};function A(P,M){P[M]?P[M]++:P[M]=1}function $(P,M){--P[M]||delete P[M]}function F(P,M,K,V){var H=""+M,Z=""+K;if(!P&&H>Z){var ee=H;H=Z,Z=ee}return H+z+Z+z+(V===void 0?B:V)}function W(P,M,K,V){var H=""+M,Z=""+K;if(!P&&H>Z){var ee=H;H=Z,Z=ee}var oe={v:H,w:Z};return V&&(oe.name=V),oe}function X(P,M){return F(P,M.v,M.w,M.name)}T.exports=R}),l=o((q,T)=>{T.exports="3.0.2"}),c=o((q,T)=>{T.exports={Graph:i(),version:l()}}),d=o((q,T)=>{var B=i();T.exports={write:L,read:A};function L($){var F={options:{directed:$.isDirected(),multigraph:$.isMultigraph(),compound:$.isCompound()},nodes:z($),edges:R($)};return $.graph()!==void 0&&(F.value=structuredClone($.graph())),F}function z($){return $.nodes().map(function(F){var W=$.node(F),X=$.parent(F),P={v:F};return W!==void 0&&(P.value=W),X!==void 0&&(P.parent=X),P})}function R($){return $.edges().map(function(F){var W=$.edge(F),X={v:F.v,w:F.w};return F.name!==void 0&&(X.name=F.name),W!==void 0&&(X.value=W),X})}function A($){var F=new B($.options).setGraph($.value);return $.nodes.forEach(function(W){F.setNode(W.v,W.value),W.parent&&F.setParent(W.v,W.parent)}),$.edges.forEach(function(W){F.setEdge({v:W.v,w:W.w,name:W.name},W.value)}),F}}),h=o((q,T)=>{T.exports=L;var B=()=>1;function L(R,A,$,F){return z(R,String(A),$||B,F||function(W){return R.outEdges(W)})}function z(R,A,$,F){var W={},X=!0,P=0,M=R.nodes(),K=function(ee){var oe=$(ee);W[ee.v].distance+oe<W[ee.w].distance&&(W[ee.w]={distance:W[ee.v].distance+oe,predecessor:ee.v},X=!0)},V=function(){M.forEach(function(ee){F(ee).forEach(function(oe){var de=oe.v===ee?oe.v:oe.w,Q=de===oe.v?oe.w:oe.v;K({v:de,w:Q})})})};M.forEach(function(ee){var oe=ee===A?0:Number.POSITIVE_INFINITY;W[ee]={distance:oe}});for(var H=M.length,Z=1;Z<H&&(X=!1,P++,V(),!!X);Z++);if(P===H-1&&(X=!1,V(),X))throw new Error("The graph contains a negative weight cycle");return W}}),u=o((q,T)=>{T.exports=B;function B(L){var z={},R=[],A;function $(F){Object.hasOwn(z,F)||(z[F]=!0,A.push(F),L.successors(F).forEach($),L.predecessors(F).forEach($))}return L.nodes().forEach(function(F){A=[],$(F),A.length&&R.push(A)}),R}}),f=o((q,T)=>{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 z=this._keyIndices[L];if(z!==void 0)return this._arr[z].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(L,z){var R=this._keyIndices;if(L=String(L),!Object.hasOwn(R,L)){var A=this._arr,$=A.length;return R[L]=$,A.push({key:L,priority:z}),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,z){var R=this._keyIndices[L];if(z>this._arr[R].priority)throw new Error("New priority is greater than current priority. Key: "+L+" Old: "+this._arr[R].priority+" New: "+z);this._arr[R].priority=z,this._decrease(R)}_heapify(L){var z=this._arr,R=2*L,A=R+1,$=L;R<z.length&&($=z[R].priority<z[$].priority?R:$,A<z.length&&($=z[A].priority<z[$].priority?A:$),$!==L&&(this._swap(L,$),this._heapify($)))}_decrease(L){for(var z=this._arr,R=z[L].priority,A;L!==0&&(A=L>>1,!(z[A].priority<R));)this._swap(L,A),L=A}_swap(L,z){var R=this._arr,A=this._keyIndices,$=R[L],F=R[z];R[L]=F,R[z]=$,A[F.key]=L,A[$.key]=z}};T.exports=B}),m=o((q,T)=>{var B=f();T.exports=z;var L=()=>1;function z(A,$,F,W){var X=function(P){return A.outEdges(P)};return R(A,String($),F||L,W||X)}function R(A,$,F,W){var X={},P=new B,M,K,V=function(H){var Z=H.v!==M?H.v:H.w,ee=X[Z],oe=F(H),de=K.distance+oe;if(oe<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+H+" Weight: "+oe);de<ee.distance&&(ee.distance=de,ee.predecessor=M,P.decrease(Z,de))};for(A.nodes().forEach(function(H){var Z=H===$?0:Number.POSITIVE_INFINITY;X[H]={distance:Z},P.add(H,Z)});P.size()>0&&(M=P.removeMin(),K=X[M],K.distance!==Number.POSITIVE_INFINITY);)W(M).forEach(V);return X}}),g=o((q,T)=>{var B=m();T.exports=L;function L(z,R,A){return z.nodes().reduce(function($,F){return $[F]=B(z,F,R,A),$},{})}}),y=o((q,T)=>{T.exports=B;function B(z,R,A){if(z[R].predecessor!==void 0)throw new Error("Invalid source vertex");if(z[A].predecessor===void 0&&A!==R)throw new Error("Invalid destination vertex");return{weight:z[A].distance,path:L(z,R,A)}}function L(z,R,A){for(var $=[],F=A;F!==R;)$.push(F),F=z[F].predecessor;return $.push(R),$.reverse()}}),k=o((q,T)=>{T.exports=B;function B(L){var z=0,R=[],A={},$=[];function F(W){var X=A[W]={onStack:!0,lowlink:z,index:z++};if(R.push(W),L.successors(W).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 P=[],M;do M=R.pop(),A[M].onStack=!1,P.push(M);while(W!==M);$.push(P)}}return L.nodes().forEach(function(W){Object.hasOwn(A,W)||F(W)}),$}}),v=o((q,T)=>{var B=k();T.exports=L;function L(z){return B(z).filter(function(R){return R.length>1||R.length===1&&z.hasEdge(R[0],R[0])})}}),b=o((q,T)=>{T.exports=L;var B=()=>1;function L(R,A,$){return z(R,A||B,$||function(F){return R.outEdges(F)})}function z(R,A,$){var F={},W=R.nodes();return W.forEach(function(X){F[X]={},F[X][X]={distance:0},W.forEach(function(P){X!==P&&(F[X][P]={distance:Number.POSITIVE_INFINITY})}),$(X).forEach(function(P){var M=P.v===X?P.w:P.v,K=A(P);F[X][M]={distance:K,predecessor:X}})}),W.forEach(function(X){var P=F[X];W.forEach(function(M){var K=F[M];W.forEach(function(V){var H=K[X],Z=P[V],ee=K[V],oe=H.distance+Z.distance;oe<ee.distance&&(ee.distance=oe,ee.predecessor=Z.predecessor)})})}),F}}),x=o((q,T)=>{function B(z){var R={},A={},$=[];function F(W){if(Object.hasOwn(A,W))throw new L;Object.hasOwn(R,W)||(A[W]=!0,R[W]=!0,z.predecessors(W).forEach(F),delete A[W],$.push(W))}if(z.sinks().forEach(F),Object.keys(R).length!==z.nodeCount())throw new L;return $}var L=class extends Error{constructor(){super(...arguments)}};T.exports=B,B.CycleException=L}),w=o((q,T)=>{var B=x();T.exports=L;function L(z){try{B(z)}catch(R){if(R instanceof B.CycleException)return!1;throw R}return!0}}),N=o((q,T)=>{T.exports=B;function B(z,R,A,$,F){Array.isArray(R)||(R=[R]);var W=(z.isDirected()?z.successors:z.neighbors).bind(z),X={};return R.forEach(function(P){if(!z.hasNode(P))throw new Error("Graph does not have node: "+P);F=L(z,P,A==="post",X,W,$,F)}),F}function L(z,R,A,$,F,W,X){return Object.hasOwn($,R)||($[R]=!0,A||(X=W(X,R)),F(R).forEach(function(P){X=L(z,P,A,$,F,W,X)}),A&&(X=W(X,R))),X}}),j=o((q,T)=>{var B=N();T.exports=L;function L(z,R,A){return B(z,R,A,function($,F){return $.push(F),$},[])}}),E=o((q,T)=>{var B=j();T.exports=L;function L(z,R){return B(z,R,"post")}}),C=o((q,T)=>{var B=j();T.exports=L;function L(z,R){return B(z,R,"pre")}}),D=o((q,T)=>{var B=i(),L=f();T.exports=z;function z(R,A){var $=new B,F={},W=new L,X;function P(K){var V=K.v===X?K.w:K.v,H=W.priority(V);if(H!==void 0){var Z=A(K);Z<H&&(F[V]=X,W.decrease(V,Z))}}if(R.nodeCount()===0)return $;R.nodes().forEach(function(K){W.add(K,Number.POSITIVE_INFINITY),$.setNode(K)}),W.decrease(R.nodes()[0],0);for(var M=!1;W.size()>0;){if(X=W.removeMin(),Object.hasOwn(F,X))$.setEdge(X,F[X]);else{if(M)throw new Error("Input graph is not connected: "+R);M=!0}R.nodeEdges(X).forEach(P)}return $}}),_=o((q,T)=>{var B=m(),L=h();T.exports=z;function z(A,$,F,W){return R(A,$,F,W||function(X){return A.outEdges(X)})}function R(A,$,F,W){if(F===void 0)return B(A,$,F,W);for(var X=!1,P=A.nodes(),M=0;M<P.length;M++){for(var K=W(P[M]),V=0;V<K.length;V++){var H=K[V],Z=H.v===P[M]?H.v:H.w,ee=Z===H.v?H.w:H.v;F({v:Z,w:ee})<0&&(X=!0)}if(X)return L(A,$,F,W)}return B(A,$,F,W)}}),I=o((q,T)=>{T.exports={bellmanFord:h(),components:u(),dijkstra:m(),dijkstraAll:g(),extractPath:y(),findCycles:v(),floydWarshall:b(),isAcyclic:w(),postorder:E(),preorder:C(),prim:D(),shortestPaths:_(),reduce:N(),tarjan:k(),topsort:x()}}),O=c();t.exports={Graph:O.Graph,json:d(),alg:I(),version:O.version}}),Dg=Ge((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}),Og=Ge((e,t)=>{var n=tn().Graph,s=Dg();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=[],y=f[f.length-1],k=f[0],v;for(;u.nodeCount();){for(;v=k.dequeue();)l(u,f,m,v);for(;v=y.dequeue();)l(u,f,m,v);if(u.nodeCount()){for(let b=f.length-2;b>0;--b)if(v=f[b].dequeue(),v){g=g.concat(l(u,f,m,v,!0));break}}}return g}function l(u,f,m,g,y){let k=y?[]:void 0;return u.inEdges(g.v).forEach(v=>{let b=u.edge(v),x=u.node(v.v);y&&k.push({v:v.v,w:v.w}),x.out-=b,d(f,m,x)}),u.outEdges(g.v).forEach(v=>{let b=u.edge(v),x=v.w,w=u.node(x);w.in-=b,d(f,m,w)}),u.removeNode(g.v),k}function c(u,f){let m=new n,g=0,y=0;u.nodes().forEach(b=>{m.setNode(b,{v:b,in:0,out:0})}),u.edges().forEach(b=>{let x=m.edge(b.v,b.w)||0,w=f(b),N=x+w;m.setEdge(b.v,b.w,N),y=Math.max(y,m.node(b.v).out+=w),g=Math.max(g,m.node(b.w).in+=w)});let k=h(y+g+3).map(()=>new s),v=g+1;return m.nodes().forEach(b=>{d(k,v,m.node(b))}),{graph:m,buckets:k,zeroIdx:v}}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}}),bt=Ge((e,t)=>{var n=tn().Graph;t.exports={addBorderNode:f,addDummyNode:s,applyWithChunking:y,asNonCompoundGraph:a,buildLayerMatrix:d,intersectRect:c,mapValues:C,maxRank:k,normalizeRanks:h,notime:x,partition:v,pick:E,predecessorWeights:l,range:j,removeEmptyRanks:u,simplify:o,successorWeights:i,time:b,uniqueId:N,zipObject:D};function s(_,I,O,q){for(var T=q;_.hasNode(T);)T=N(q);return O.dummy=I,_.setNode(T,O),T}function o(_){let I=new n().setGraph(_.graph());return _.nodes().forEach(O=>I.setNode(O,_.node(O))),_.edges().forEach(O=>{let q=I.edge(O.v,O.w)||{weight:0,minlen:1},T=_.edge(O);I.setEdge(O.v,O.w,{weight:q.weight+T.weight,minlen:Math.max(q.minlen,T.minlen)})}),I}function a(_){let I=new n({multigraph:_.isMultigraph()}).setGraph(_.graph());return _.nodes().forEach(O=>{_.children(O).length||I.setNode(O,_.node(O))}),_.edges().forEach(O=>{I.setEdge(O,_.edge(O))}),I}function i(_){let I=_.nodes().map(O=>{let q={};return _.outEdges(O).forEach(T=>{q[T.w]=(q[T.w]||0)+_.edge(T).weight}),q});return D(_.nodes(),I)}function l(_){let I=_.nodes().map(O=>{let q={};return _.inEdges(O).forEach(T=>{q[T.v]=(q[T.v]||0)+_.edge(T).weight}),q});return D(_.nodes(),I)}function c(_,I){let O=_.x,q=_.y,T=I.x-O,B=I.y-q,L=_.width/2,z=_.height/2;if(!T&&!B)throw new Error("Not possible to find intersection inside of the rectangle");let R,A;return Math.abs(B)*L>Math.abs(T)*z?(B<0&&(z=-z),R=z*T/B,A=z):(T<0&&(L=-L),R=L,A=L*B/T),{x:O+R,y:q+A}}function d(_){let I=j(k(_)+1).map(()=>[]);return _.nodes().forEach(O=>{let q=_.node(O),T=q.rank;T!==void 0&&(I[T][q.order]=O)}),I}function h(_){let I=_.nodes().map(q=>{let T=_.node(q).rank;return T===void 0?Number.MAX_VALUE:T}),O=y(Math.min,I);_.nodes().forEach(q=>{let T=_.node(q);Object.hasOwn(T,"rank")&&(T.rank-=O)})}function u(_){let I=_.nodes().map(L=>_.node(L).rank).filter(L=>L!==void 0),O=y(Math.min,I),q=[];_.nodes().forEach(L=>{let z=_.node(L).rank-O;q[z]||(q[z]=[]),q[z].push(L)});let T=0,B=_.graph().nodeRankFactor;Array.from(q).forEach((L,z)=>{L===void 0&&z%B!==0?--T:L!==void 0&&T&&L.forEach(R=>_.node(R).rank+=T)})}function f(_,I,O,q){let T={width:0,height:0};return arguments.length>=4&&(T.rank=O,T.order=q),s(_,"border",T,I)}function m(_,I=g){let O=[];for(let q=0;q<_.length;q+=I){let T=_.slice(q,q+I);O.push(T)}return O}var g=65535;function y(_,I){if(I.length>g){let O=m(I);return _.apply(null,O.map(q=>_.apply(null,q)))}else return _.apply(null,I)}function k(_){let I=_.nodes().map(O=>{let q=_.node(O).rank;return q===void 0?Number.MIN_VALUE:q});return y(Math.max,I)}function v(_,I){let O={lhs:[],rhs:[]};return _.forEach(q=>{I(q)?O.lhs.push(q):O.rhs.push(q)}),O}function b(_,I){let O=Date.now();try{return I()}finally{console.log(_+" time: "+(Date.now()-O)+"ms")}}function x(_,I){return I()}var w=0;function N(_){var I=++w;return _+(""+I)}function j(_,I,O=1){I==null&&(I=_,_=0);let q=B=>B<I;O<0&&(q=B=>I<B);let T=[];for(let B=_;q(B);B+=O)T.push(B);return T}function E(_,I){let O={};for(let q of I)_[q]!==void 0&&(O[q]=_[q]);return O}function C(_,I){let O=I;return typeof I=="string"&&(O=q=>q[I]),Object.entries(_).reduce((q,[T,B])=>(q[T]=O(B,T),q),{})}function D(_,I){return _.reduce((O,q,T)=>(O[q]=I[T],O),{})}}),$g=Ge((e,t)=>{var n=Og(),s=bt().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)}})}}),Pg=Ge((e,t)=>{var n=bt();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 y,k,v;for(v=0,++d;d<u;++v,++d)m.points=[],k={width:0,height:0,edgeLabel:m,edgeObj:l,rank:d},y=n.addDummyNode(i,"edge",k,"_d"),d===g&&(k.width=m.width,k.height=m.height,k.dummy="edge-label",k.labelpos=m.labelpos),i.setEdge(c,y,{weight:m.weight},f),v===0&&i.graph().dummyChains.push(y),c=y;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)})}}),ho=Ge((e,t)=>{var{applyWithChunking:n}=bt();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}}),Gd=Ge((e,t)=>{var n=tn().Graph,s=ho().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)}}),Bg=Ge((e,t)=>{var n=Gd(),s=ho().slack,o=ho().longestPath,a=tn().alg.preorder,i=tn().alg.postorder,l=bt().simplify;t.exports=c,c.initLowLimValues=f,c.initCutValues=d,c.calcCutValue=u,c.leaveEdge=g,c.enterEdge=y,c.exchangeEdges=k;function c(w){w=l(w),o(w);var N=n(w);f(N),d(N,w);for(var j,E;j=g(N);)E=y(N,w,j),k(N,w,j,E)}function d(w,N){var j=i(w,w.nodes());j=j.slice(0,j.length-1),j.forEach(E=>h(w,N,E))}function h(w,N,j){var E=w.node(j),C=E.parent;w.edge(j,C).cutvalue=u(w,N,j)}function u(w,N,j){var E=w.node(j),C=E.parent,D=!0,_=N.edge(j,C),I=0;return _||(D=!1,_=N.edge(C,j)),I=_.weight,N.nodeEdges(j).forEach(O=>{var q=O.v===j,T=q?O.w:O.v;if(T!==C){var B=q===D,L=N.edge(O).weight;if(I+=B?L:-L,b(w,j,T)){var z=w.edge(j,T).cutvalue;I+=B?-z:z}}}),I}function f(w,N){arguments.length<2&&(N=w.nodes()[0]),m(w,{},1,N)}function m(w,N,j,E,C){var D=j,_=w.node(E);return N[E]=!0,w.neighbors(E).forEach(I=>{Object.hasOwn(N,I)||(j=m(w,N,j,I,E))}),_.low=D,_.lim=j++,C?_.parent=C:delete _.parent,j}function g(w){return w.edges().find(N=>w.edge(N).cutvalue<0)}function y(w,N,j){var E=j.v,C=j.w;N.hasEdge(E,C)||(E=j.w,C=j.v);var D=w.node(E),_=w.node(C),I=D,O=!1;D.lim>_.lim&&(I=_,O=!0);var q=N.edges().filter(T=>O===x(w,w.node(T.v),I)&&O!==x(w,w.node(T.w),I));return q.reduce((T,B)=>s(N,B)<s(N,T)?B:T)}function k(w,N,j,E){var C=j.v,D=j.w;w.removeEdge(C,D),w.setEdge(E.v,E.w,{}),f(w),d(w,N),v(w,N)}function v(w,N){var j=w.nodes().find(C=>!N.node(C).parent),E=a(w,j);E=E.slice(1),E.forEach(C=>{var D=w.node(C).parent,_=N.edge(C,D),I=!1;_||(_=N.edge(D,C),I=!0),N.node(C).rank=N.node(D).rank+(I?_.minlen:-_.minlen)})}function b(w,N,j){return w.hasEdge(N,j)}function x(w,N,j){return j.low<=N.lim&&N.lim<=j.lim}}),zg=Ge((e,t)=>{var n=ho(),s=n.longestPath,o=Gd(),a=Bg();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)}}),qg=Ge((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],y=!0;for(;l!==d.w;){if(c=a.node(l),y){for(;(g=u[m])!==f&&a.node(g).maxRank<c.rank;)m++;g===f&&(y=!1)}if(!y){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}}),Fg=Ge((e,t)=>{var n=bt();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(y=>c.edge(y).minlen*=m);let g=i(c)+1;c.children().forEach(y=>o(c,d,m,g,f,h,y)),c.graph().nodeRankFactor=m}function o(c,d,h,u,f,m,g){let y=c.children(g);if(!y.length){g!==d&&c.setEdge(d,g,{weight:0,minlen:h});return}let k=n.addBorderNode(c,"_bt"),v=n.addBorderNode(c,"_bb"),b=c.node(g);c.setParent(k,g),b.borderTop=k,c.setParent(v,g),b.borderBottom=v,y.forEach(x=>{o(c,d,h,u,f,m,x);let w=c.node(x),N=w.borderTop?w.borderTop:x,j=w.borderBottom?w.borderBottom:x,E=w.borderTop?u:2*u,C=N!==j?1:f-m[g]+1;c.setEdge(k,N,{weight:E,minlen:C,nestingEdge:!0}),c.setEdge(j,v,{weight:E,minlen:C,nestingEdge:!0})}),c.parent(g)||c.setEdge(d,k,{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)})}}),Hg=Ge((e,t)=>{var n=bt();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})}}),Wg=Ge((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}}),Vg=Ge((e,t)=>{var n=bt();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}}),Kg=Ge((e,t)=>{var n=bt().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,y)=>y)),d=i.flatMap(g=>a.outEdges(g).map(y=>({pos:c[y.w],weight:a.edge(y).weight})).sort((y,k)=>y.pos-k.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 y=g.pos+h;f[y]+=g.weight;let k=0;for(;y>0;)y%2&&(k+=f[y+1]),y=y-1>>1,f[y]+=g.weight;m+=g.weight*k}),m}}),Ug=Ge((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}})}}),Yg=Ge((e,t)=>{var n=bt();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}}),Gg=Ge((e,t)=>{var n=bt();t.exports=s;function s(i,l){let c=n.partition(i,k=>Object.hasOwn(k,"barycenter")),d=c.lhs,h=c.rhs.sort((k,v)=>v.i-k.i),u=[],f=0,m=0,g=0;d.sort(a(!!l)),g=o(u,h,g),d.forEach(k=>{g+=k.vs.length,u.push(k.vs),f+=k.barycenter*k.weight,m+=k.weight,g=o(u,h,g)});let y={vs:u.flat(!0)};return m&&(y.barycenter=f/m,y.weight=m),y}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}}),Xg=Ge((e,t)=>{var n=Ug(),s=Yg(),o=Gg();t.exports=a;function a(c,d,h,u){let f=c.children(d),m=c.node(d),g=m?m.borderLeft:void 0,y=m?m.borderRight:void 0,k={};g&&(f=f.filter(w=>w!==g&&w!==y));let v=n(c,f);v.forEach(w=>{if(c.children(w.v).length){let N=a(c,w.v,h,u);k[w.v]=N,Object.hasOwn(N,"barycenter")&&l(w,N)}});let b=s(v,h);i(b,k);let x=o(b,u);if(g&&(x.vs=[g,x.vs,y].flat(!0),c.predecessors(g).length)){let w=c.node(c.predecessors(g)[0]),N=c.node(c.predecessors(y)[0]);Object.hasOwn(x,"barycenter")||(x.barycenter=0,x.weight=0),x.barycenter=(x.barycenter*x.weight+w.order+N.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)}}),Zg=Ge((e,t)=>{var n=tn().Graph,s=bt();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(y=>{let k=y.v===f?y.w:y.v,v=u.edge(k,f),b=v!==void 0?v.weight:0;u.setEdge(k,f,{weight:i.edge(y).weight+b})}),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}}),Qg=Ge((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}})}}),Jg=Ge((e,t)=>{var n=Vg(),s=Kg(),o=Xg(),a=Zg(),i=Qg(),l=tn().Graph,c=bt();t.exports=d;function d(m,g={}){if(typeof g.customOrder=="function"){g.customOrder(m,d);return}let y=c.maxRank(m),k=h(m,c.range(1,y+1),"inEdges"),v=h(m,c.range(y-1,-1,-1),"outEdges"),b=n(m);if(f(m,b),g.disableOptimalOrderHeuristic)return;let x=Number.POSITIVE_INFINITY,w,N=g.constraints||[];for(let j=0,E=0;E<4;++j,++E){u(j%2?k:v,j%4>=2,N),b=c.buildLayerMatrix(m);let C=s(m,b);C<x?(E=0,w=Object.assign({},b),x=C):C===x&&(w=structuredClone(b))}f(m,w)}function h(m,g,y){let k=new Map,v=(b,x)=>{k.has(b)||k.set(b,[]),k.get(b).push(x)};for(let b of m.nodes()){let x=m.node(b);if(typeof x.rank=="number"&&v(x.rank,b),typeof x.minRank=="number"&&typeof x.maxRank=="number")for(let w=x.minRank;w<=x.maxRank;w++)w!==x.rank&&v(w,b)}return g.map(function(b){return a(m,b,y,k.get(b)||[])})}function u(m,g,y){let k=new l;m.forEach(function(v){y.forEach(w=>k.setEdge(w.left,w.right));let b=v.graph().root,x=o(v,b,k,g);x.vs.forEach((w,N)=>v.node(w).order=N),i(v,k,x.vs)})}function f(m,g){Object.values(g).forEach(y=>y.forEach((k,v)=>m.node(k).order=v))}}),ex=Ge((e,t)=>{var n=tn().Graph,s=bt();t.exports={positionX:y,findType1Conflicts:o,findType2Conflicts:a,addConflict:l,hasConflict:c,verticalAlignment:d,horizontalCompaction:h,alignCoordinates:m,findSmallestWidthAlignment:f,balance:g};function o(b,x){let w={};function N(j,E){let C=0,D=0,_=j.length,I=E[E.length-1];return E.forEach((O,q)=>{let T=i(b,O),B=T?b.node(T).order:_;(T||O===I)&&(E.slice(D,q+1).forEach(L=>{b.predecessors(L).forEach(z=>{let R=b.node(z),A=R.order;(A<C||B<A)&&!(R.dummy&&b.node(L).dummy)&&l(w,z,L)})}),D=q+1,C=B)}),E}return x.length&&x.reduce(N),w}function a(b,x){let w={};function N(E,C,D,_,I){let O;s.range(C,D).forEach(q=>{O=E[q],b.node(O).dummy&&b.predecessors(O).forEach(T=>{let B=b.node(T);B.dummy&&(B.order<_||B.order>I)&&l(w,T,O)})})}function j(E,C){let D=-1,_,I=0;return C.forEach((O,q)=>{if(b.node(O).dummy==="border"){let T=b.predecessors(O);T.length&&(_=b.node(T[0]).order,N(C,I,q,D,_),I=q,D=_)}N(C,I,C.length,_,E.length)}),C}return x.length&&x.reduce(j),w}function i(b,x){if(b.node(x).dummy)return b.predecessors(x).find(w=>b.node(w).dummy)}function l(b,x,w){if(x>w){let j=x;x=w,w=j}let N=b[x];N||(b[x]=N={}),N[w]=!0}function c(b,x,w){if(x>w){let N=x;x=w,w=N}return!!b[x]&&Object.hasOwn(b[x],w)}function d(b,x,w,N){let j={},E={},C={};return x.forEach(D=>{D.forEach((_,I)=>{j[_]=_,E[_]=_,C[_]=I})}),x.forEach(D=>{let _=-1;D.forEach(I=>{let O=N(I);if(O.length){O=O.sort((T,B)=>C[T]-C[B]);let q=(O.length-1)/2;for(let T=Math.floor(q),B=Math.ceil(q);T<=B;++T){let L=O[T];E[I]===I&&_<C[L]&&!c(w,I,L)&&(E[L]=I,E[I]=j[I]=j[L],_=C[L])}}})}),{root:j,align:E}}function h(b,x,w,N,j){let E={},C=u(b,x,w,j),D=j?"borderLeft":"borderRight";function _(q,T){let B=C.nodes().slice(),L={},z=B.pop();for(;z;){if(L[z])q(z);else{L[z]=!0,B.push(z);for(let R of T(z))B.push(R)}z=B.pop()}}function I(q){E[q]=C.inEdges(q).reduce((T,B)=>Math.max(T,E[B.v]+C.edge(B)),0)}function O(q){let T=C.outEdges(q).reduce((L,z)=>Math.min(L,E[z.w]-C.edge(z)),Number.POSITIVE_INFINITY),B=b.node(q);T!==Number.POSITIVE_INFINITY&&B.borderType!==D&&(E[q]=Math.max(E[q],T))}return _(I,C.predecessors.bind(C)),_(O,C.successors.bind(C)),Object.keys(N).forEach(q=>E[q]=E[w[q]]),E}function u(b,x,w,N){let j=new n,E=b.graph(),C=k(E.nodesep,E.edgesep,N);return x.forEach(D=>{let _;D.forEach(I=>{let O=w[I];if(j.setNode(O),_){var q=w[_],T=j.edge(q,O);j.setEdge(q,O,Math.max(C(b,I,_),T||0))}_=I})}),j}function f(b,x){return Object.values(x).reduce((w,N)=>{let j=Number.NEGATIVE_INFINITY,E=Number.POSITIVE_INFINITY;Object.entries(N).forEach(([D,_])=>{let I=v(b,D)/2;j=Math.max(_+I,j),E=Math.min(_-I,E)});let C=j-E;return C<w[0]&&(w=[C,N]),w},[Number.POSITIVE_INFINITY,null])[1]}function m(b,x){let w=Object.values(x),N=s.applyWithChunking(Math.min,w),j=s.applyWithChunking(Math.max,w);["u","d"].forEach(E=>{["l","r"].forEach(C=>{let D=E+C,_=b[D];if(_===x)return;let I=Object.values(_),O=N-s.applyWithChunking(Math.min,I);C!=="l"&&(O=j-s.applyWithChunking(Math.max,I)),O&&(b[D]=s.mapValues(_,q=>q+O))})})}function g(b,x){return s.mapValues(b.ul,(w,N)=>{if(x)return b[x.toLowerCase()][N];{let j=Object.values(b).map(E=>E[N]).sort((E,C)=>E-C);return(j[1]+j[2])/2}})}function y(b){let x=s.buildLayerMatrix(b),w=Object.assign(o(b,x),a(b,x)),N={},j;["u","d"].forEach(C=>{j=C==="u"?x:Object.values(x).reverse(),["l","r"].forEach(D=>{D==="r"&&(j=j.map(q=>Object.values(q).reverse()));let _=(C==="u"?b.predecessors:b.successors).bind(b),I=d(b,j,w,_),O=h(b,j,I.root,I.align,D==="r");D==="r"&&(O=s.mapValues(O,q=>-q)),N[C+D]=O})});let E=f(b,N);return m(N,E),g(N,b.graph().align)}function k(b,x,w){return(N,j,E)=>{let C=N.node(j),D=N.node(E),_=0,I;if(_+=C.width/2,Object.hasOwn(C,"labelpos"))switch(C.labelpos.toLowerCase()){case"l":I=-C.width/2;break;case"r":I=C.width/2;break}if(I&&(_+=w?I:-I),I=0,_+=(C.dummy?x:b)/2,_+=(D.dummy?x:b)/2,_+=D.width/2,Object.hasOwn(D,"labelpos"))switch(D.labelpos.toLowerCase()){case"l":I=D.width/2;break;case"r":I=-D.width/2;break}return I&&(_+=w?I:-I),I=0,_}}function v(b,x){return b.node(x).width}}),tx=Ge((e,t)=>{var n=bt(),s=ex().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 y=i.node(g).height;return m>y?m:y},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=Ge((e,t)=>{var n=$g(),s=Pg(),o=zg(),a=bt().normalizeRanks,i=qg(),l=bt().removeEmptyRanks,c=Fg(),d=Hg(),h=Wg(),u=Jg(),f=tx(),m=bt(),g=tn().Graph;t.exports=y;function y(M,K={}){let V=K.debugTiming?m.time:m.notime;return V("layout",()=>{let H=V(" buildLayoutGraph",()=>_(M));return V(" runLayout",()=>k(H,V,K)),V(" updateInputGraph",()=>v(M,H)),H})}function k(M,K,V){K(" makeSpaceForEdgeLabels",()=>I(M)),K(" removeSelfEdges",()=>$(M)),K(" acyclic",()=>n.run(M)),K(" nestingGraph.run",()=>c.run(M)),K(" rank",()=>o(m.asNonCompoundGraph(M))),K(" injectEdgeLabelProxies",()=>O(M)),K(" removeEmptyRanks",()=>l(M)),K(" nestingGraph.cleanup",()=>c.cleanup(M)),K(" normalizeRanks",()=>a(M)),K(" assignRankMinMax",()=>q(M)),K(" removeEdgeLabelProxies",()=>T(M)),K(" normalize.run",()=>s.run(M)),K(" parentDummyChains",()=>i(M)),K(" addBorderSegments",()=>d(M)),K(" order",()=>u(M,V)),K(" insertSelfEdges",()=>F(M)),K(" adjustCoordinateSystem",()=>h.adjust(M)),K(" position",()=>f(M)),K(" positionSelfEdges",()=>W(M)),K(" removeBorderNodes",()=>A(M)),K(" normalize.undo",()=>s.undo(M)),K(" fixupEdgeLabelCoords",()=>z(M)),K(" undoCoordinateSystem",()=>h.undo(M)),K(" translateGraph",()=>B(M)),K(" assignNodeIntersects",()=>L(M)),K(" reversePoints",()=>R(M)),K(" acyclic.undo",()=>n.undo(M))}function v(M,K){M.nodes().forEach(V=>{let H=M.node(V),Z=K.node(V);H&&(H.x=Z.x,H.y=Z.y,H.order=Z.order,H.rank=Z.rank,K.children(V).length&&(H.width=Z.width,H.height=Z.height))}),M.edges().forEach(V=>{let H=M.edge(V),Z=K.edge(V);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 b=["nodesep","edgesep","ranksep","marginx","marginy"],x={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},w=["acyclicer","ranker","rankdir","align","rankalign"],N=["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"},D=["labelpos"];function _(M){let K=new g({multigraph:!0,compound:!0}),V=P(M.graph());return K.setGraph(Object.assign({},x,X(V,b),m.pick(V,w))),M.nodes().forEach(H=>{let Z=P(M.node(H)),ee=X(Z,N);Object.keys(j).forEach(oe=>{ee[oe]===void 0&&(ee[oe]=j[oe])}),K.setNode(H,ee),K.setParent(H,M.parent(H))}),M.edges().forEach(H=>{let Z=P(M.edge(H));K.setEdge(H,Object.assign({},C,X(Z,E),m.pick(Z,D)))}),K}function I(M){let K=M.graph();K.ranksep/=2,M.edges().forEach(V=>{let H=M.edge(V);H.minlen*=2,H.labelpos.toLowerCase()!=="c"&&(K.rankdir==="TB"||K.rankdir==="BT"?H.width+=H.labeloffset:H.height+=H.labeloffset)})}function O(M){M.edges().forEach(K=>{let V=M.edge(K);if(V.width&&V.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 q(M){let K=0;M.nodes().forEach(V=>{let H=M.node(V);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 T(M){M.nodes().forEach(K=>{let V=M.node(K);V.dummy==="edge-proxy"&&(M.edge(V.e).labelRank=V.rank,M.removeNode(K))})}function B(M){let K=Number.POSITIVE_INFINITY,V=0,H=Number.POSITIVE_INFINITY,Z=0,ee=M.graph(),oe=ee.marginx||0,de=ee.marginy||0;function Q(le){let ue=le.x,fe=le.y,ge=le.width,we=le.height;K=Math.min(K,ue-ge/2),V=Math.max(V,ue+ge/2),H=Math.min(H,fe-we/2),Z=Math.max(Z,fe+we/2)}M.nodes().forEach(le=>Q(M.node(le))),M.edges().forEach(le=>{let ue=M.edge(le);Object.hasOwn(ue,"x")&&Q(ue)}),K-=oe,H-=de,M.nodes().forEach(le=>{let ue=M.node(le);ue.x-=K,ue.y-=H}),M.edges().forEach(le=>{let ue=M.edge(le);ue.points.forEach(fe=>{fe.x-=K,fe.y-=H}),Object.hasOwn(ue,"x")&&(ue.x-=K),Object.hasOwn(ue,"y")&&(ue.y-=H)}),ee.width=V-K+oe,ee.height=Z-H+de}function L(M){M.edges().forEach(K=>{let V=M.edge(K),H=M.node(K.v),Z=M.node(K.w),ee,oe;V.points?(ee=V.points[0],oe=V.points[V.points.length-1]):(V.points=[],ee=Z,oe=H),V.points.unshift(m.intersectRect(H,ee)),V.points.push(m.intersectRect(Z,oe))})}function z(M){M.edges().forEach(K=>{let V=M.edge(K);if(Object.hasOwn(V,"x"))switch((V.labelpos==="l"||V.labelpos==="r")&&(V.width-=V.labeloffset),V.labelpos){case"l":V.x-=V.width/2+V.labeloffset;break;case"r":V.x+=V.width/2+V.labeloffset;break}})}function R(M){M.edges().forEach(K=>{let V=M.edge(K);V.reversed&&V.points.reverse()})}function A(M){M.nodes().forEach(K=>{if(M.children(K).length){let V=M.node(K),H=M.node(V.borderTop),Z=M.node(V.borderBottom),ee=M.node(V.borderLeft[V.borderLeft.length-1]),oe=M.node(V.borderRight[V.borderRight.length-1]);V.width=Math.abs(oe.x-ee.x),V.height=Math.abs(Z.y-H.y),V.x=ee.x+V.width/2,V.y=H.y+V.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 V=M.node(K.v);V.selfEdges||(V.selfEdges=[]),V.selfEdges.push({e:K,label:M.edge(K)}),M.removeEdge(K)}})}function F(M){var K=m.buildLayerMatrix(M);K.forEach(V=>{var H=0;V.forEach((Z,ee)=>{var oe=M.node(Z);oe.order=ee+H,(oe.selfEdges||[]).forEach(de=>{m.addDummyNode(M,"selfedge",{width:de.label.width,height:de.label.height,rank:oe.rank,order:ee+ ++H,e:de.e,label:de.label},"_se")}),delete oe.selfEdges})})}function W(M){M.nodes().forEach(K=>{var V=M.node(K);if(V.dummy==="selfedge"){var H=M.node(V.e.v),Z=H.x+H.width/2,ee=H.y,oe=V.x-Z,de=H.height/2;M.setEdge(V.e,V.label),M.removeNode(K),V.label.points=[{x:Z+2*oe/3,y:ee-de},{x:Z+5*oe/6,y:ee-de},{x:Z+oe,y:ee},{x:Z+5*oe/6,y:ee+de},{x:Z+2*oe/3,y:ee+de}],V.label.x=V.x,V.label.y=V.y}})}function X(M,K){return m.mapValues(m.pick(M,K),Number)}function P(M){var K={};return M&&Object.entries(M).forEach(([V,H])=>{typeof V=="string"&&(V=V.toLowerCase()),K[V]=H}),K}}),sx=Ge((e,t)=>{var n=bt(),s=tn().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}}),rx=Ge((e,t)=>{t.exports="2.0.4"}),ox=Ge((e,t)=>{t.exports={graphlib:tn(),layout:nx(),debug:sx(),util:{time:bt().time,notime:bt().notime},version:rx()}});const Ll=ox();const _l={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"}},ax={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function ix({data:e}){const{t}=ze(["work","common"]),{task:n,agentName:s,selected:o,direction:a="TB",isExpandedRoot:i,onCollapse:l}=e,c=_l[n.status]??_l.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"?Ne.Left:Ne.Top,f=a==="LR"?Ne.Right:Ne.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(In,{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 ${ax[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(In,{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 Rl={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"}},Dl={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done",archived:"done"};function lx({data:e}){const{t}=ze(["work","common"]),{req:n,selected:s,direction:o="TB",isExpandedRoot:a,onCollapse:i}=e,l=Rl[n.status]??Rl.pending,c=o==="LR"?Ne.Left:Ne.Top,d=o==="LR"?Ne.Right:Ne.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(In,{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(In,{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 cx={task:ix,requirement:lx};function dx({nodeIds:e,rfRef:t}){const n=rg();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 ux=()=>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,fx=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 hx(){return p.useSyncExternalStore(fx,ux,()=>!1)}const so=200,ro=80;function Ol(e,t,n="TB"){const s=a=>{const i=new Ll.graphlib.Graph;i.setDefaultEdgeLabel(()=>({})),i.setGraph({rankdir:a,nodesep:40,ranksep:60});for(const l of e)i.setNode(l.id,{width:so,height:ro});for(const l of t)i.setEdge(l.source,l.target);return Ll.layout(i),e.map(l=>{const c=i.node(l.id);return{...l,position:{x:(c?.x??0)-so/2,y:(c?.y??0)-ro/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+so),l=Math.min(l,f.position.y),c=Math.max(c,f.position.y+ro);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 mx(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 $l(e,t){if(e.length===0)return{nodes:[],direction:"TB"};const n=mx(e,t);if(n.length===1)return Ol(e,t);let s="TB";const o=n.map(f=>{const{nodes:m,direction:g}=Ol(f.nodes,f.edges);s=g;let y=1/0,k=-1/0,v=1/0,b=-1/0;for(const x of m)y=Math.min(y,x.position.x),k=Math.max(k,x.position.x+so),v=Math.min(v,x.position.y),b=Math.max(b,x.position.y+ro);for(const x of m)x.position.x-=y,x.position.y-=v;return{nodes:m,w:k-y,h:b-v}});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 px(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 ys=[{id:"todo",statuses:new Set(["pending"]),color:{bg:"bg-blue-500/10",border:"border-blue-500/30",text:"text-blue-500"}},{id:"in_progress",statuses:new Set(["in_progress","blocked"]),color:{bg:"bg-amber-500/10",border:"border-amber-500/30",text:"text-amber-600"}},{id:"review",statuses:new Set(["review"]),color:{bg:"bg-brand-500/10",border:"border-brand-500/30",text:"text-brand-500"}},{id:"done",statuses:new Set(["completed","failed","rejected","cancelled","archived"]),color:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"}}];new Set(ys.map(e=>e.id));const Kr=new Set(ys.filter(e=>e.id!=="done").map(e=>e.id)),ta=e=>e.status==="archived";function gx(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 xx({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}=ze(["work","common"]),y=hx(),[k,v]=p.useState(null),[b,x]=p.useState(null),[w,N]=p.useState(()=>new Set(Kr)),[j,E]=p.useState(f??null),[C,D]=p.useState(s??!1),_=s??C,I=p.useCallback(ce=>{const xe=typeof ce=="function"?ce(_):ce;D(xe),o?.(xe)},[_,o]);p.useEffect(()=>{s!==void 0&&D(s)},[s]),p.useEffect(()=>{f&&E(f)},[f]);const O=p.useMemo(()=>e.filter(ce=>ta(ce)).length,[e]),q=p.useMemo(()=>{const ce=new Set;for(const xe of ys)if(w.has(xe.id))for(const be of xe.statuses)ce.add(be);return ce},[w]),T=p.useMemo(()=>{const ce=new Set;for(const xe of e)for(const be of ys)if(be.statuses.has(xe.status)){ce.add(be.id);break}for(const xe of t){const be=Dl[xe.status];be&&ce.add(be)}return ys.filter(xe=>ce.has(xe.id))},[e,t]),B=p.useCallback(ce=>{N(xe=>{const be=new Set(xe);return be.has(ce)?be.delete(ce):be.add(ce),be})},[]),L=p.useCallback((ce,xe="success")=>{v({msg:ce,type:xe}),setTimeout(()=>v(null),2500)},[]),z=p.useMemo(()=>{const ce=new Map;for(const xe of n)ce.set(xe.id,xe.name);return ce},[n]),R=p.useMemo(()=>{const ce=new Map;for(const xe of e)ce.set(xe.id,xe);return ce},[e]),A=p.useMemo(()=>{const ce=new Map;for(const xe of t)ce.set(xe.id,xe);return ce},[t]),$=p.useRef(!1),F=p.useCallback(()=>{$.current=!1,E(null),l?.()},[l]),W=y?"#94a3b8":"#6b7280",X=p.useCallback((ce,xe,be)=>({id:`${ce}->${xe}`,source:ce,target:xe,animated:be==="blocked",markerEnd:{type:Es.ArrowClosed,width:14,height:14,color:be==="blocked"?"#ef4444":W},style:{stroke:be==="blocked"?"#ef4444":W,strokeWidth:1.5,cursor:"pointer"}}),[W]),{initialNodes:P,initialEdges:M,topLevelIds:K}=p.useMemo(()=>{const ce=(re,ke)=>{const _e=new Set,It=re.map(Re=>(_e.add(Re.id),{id:Re.id,type:"task",data:{task:Re,agentName:Re.assignedAgentId?z.get(Re.assignedAgentId):void 0,selected:Re.id===d},position:{x:0,y:0}}));for(const Re of ke){const ct=`req-${Re.id}`;_e.add(ct),It.push({id:ct,type:"requirement",data:{req:Re,selected:Re.id===h},position:{x:0,y:0}})}const Mt=[];for(const Re of re)if(Re.blockedBy)for(const ct of Re.blockedBy)_e.has(ct)&&Mt.push(X(ct,Re.id,Re.status));const ft=new Set,Ot=(Re,ct)=>{const St=`${Re}->${ct}`;ft.has(St)||(ft.add(St),Mt.push({id:St,source:Re,target:ct,markerEnd:{type:Es.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Re of ke){const ct=`req-${Re.id}`;for(const St of Re.taskIds)_e.has(St)&&Ot(ct,St)}for(const Re of re)if(Re.requirementId){const ct=`req-${Re.requirementId}`;_e.has(ct)&&Ot(ct,Re.id)}return{nodes:It,edges:Mt}},xe=e.filter(re=>q.has(re.status)&&(_||!ta(re))),be=new Set;for(const re of ys)w.has(re.id)&&be.add(re.id);const at=t.filter(re=>{const ke=Dl[re.status];return ke&&be.has(ke)}),Ye=new Set(["completed","rejected","cancelled","archived"]),Oe=new Set(at.filter(re=>!Ye.has(re.status)).map(re=>re.id)),kt=new Set;for(const re of t)if(Oe.has(re.id))for(const ke of re.taskIds)kt.add(ke);const Et=e.filter(re=>kt.has(re.id)&&(_||!ta(re))),Tt=[...new Map([...xe,...Et].map(re=>[re.id,re])).values()],{nodes:te,edges:Ae}=ce(Tt,at),Ue=new Set;for(const re of Ae)Ue.add(re.target);const $e=new Set(te.filter(re=>!Ue.has(re.id)).map(re=>re.id)),it=(()=>{if(!j)return null;const{nodes:re,edges:ke}=ce(e,t);return re.some(_e=>_e.id===j)?{allNodes:re,allEdges:ke}:null})();if(!j||!it){const re=te,{nodes:ke,direction:_e}=$l(re,Ae);return{initialNodes:ke.map(Mt=>({...Mt,data:{...Mt.data,direction:_e}})),initialEdges:Ae,topLevelIds:$e}}const{allNodes:Qe,allEdges:Pe}=it,qe=gx(j,R,A,e),Je=Qe.filter(re=>qe.has(re.id)).map(re=>re.id===j?{...re,data:{...re.data,isExpandedRoot:!0,onCollapse:F}}:re),G=Pe.filter(re=>qe.has(re.source)&&qe.has(re.target)),{nodes:ae,direction:ye}=$l(Je,G);return{initialNodes:ae.map(re=>({...re,data:{...re.data,direction:ye}})),initialEdges:G,topLevelIds:$e}},[e,t,z,R,A,X,q,w,_,d,h,j,F]),[V,H,Z]=og(P),[ee,oe,de]=ag(M),Q=p.useRef(null),le=p.useRef({groupFilter:w,showArchived:_});p.useEffect(()=>{const ce=le.current;(ce.groupFilter!==w||ce.showArchived!==_)&&($.current=!1,E(null),le.current={groupFilter:w,showArchived:_})},[w,_]),p.useEffect(()=>{H(P),oe(M),$.current||requestAnimationFrame(()=>{Q.current?.fitView({padding:.2,duration:300})})},[P,M,H,oe]),p.useEffect(()=>{const ce=setTimeout(()=>{Q.current?.fitView({padding:.2,duration:300})},50);return()=>clearTimeout(ce)},[u]);const ue=p.useCallback(ce=>{ce&&($.current=!0)},[]),fe=p.useCallback((ce,xe)=>{if(!j&&K.has(xe.id)&&($.current=!1,E(xe.id)),xe.id.startsWith("req-")){const be=A.get(xe.id.slice(4));be&&i&&i(be)}else{const be=R.get(xe.id);be&&a&&a(be)}},[R,A,a,i,K,j]),ge=p.useCallback(async ce=>{const{source:xe,target:be}=ce;if(!xe||!be||xe===be)return;const at=R.get(be);if(!at)return;if(at.blockedBy?.includes(xe)){L(g("work:dag.toast.dependencyExists"),"error");return}if(px(R,xe,be)){L(g("work:dag.toast.cycleError"),"error");return}const Ye=[...at.blockedBy??[],xe];try{await ne.tasks.update(be,{blockedBy:Ye}),L(g("work:dag.toast.dependencyAdded")),c?.()}catch(Oe){L(g("work:dag.toast.failed",{message:Oe instanceof Error?Oe.message:String(Oe)}),"error")}},[R,L,c,g]),we=p.useCallback((ce,xe)=>{x(xe)},[]),me=p.useCallback(async()=>{if(!b)return;const ce=R.get(b.target);if(!ce){x(null);return}const xe=(ce.blockedBy??[]).filter(be=>be!==b.source);try{await ne.tasks.update(b.target,{blockedBy:xe}),L(g("work:dag.toast.dependencyRemoved")),c?.()}catch(be){L(g("work:dag.toast.failed",{message:be instanceof Error?be.message:String(be)}),"error")}x(null)},[b,R,L,c,g]),ve=p.useRef(null),[Te,je]=p.useState(null);if(p.useEffect(()=>{let ce=document;const xe=()=>{const Ye=ve.current;if(!Ye){je(null);return}let Oe=Ye.parentElement;for(;Oe;){const Qe=getComputedStyle(Oe).overflowY;if((Qe==="auto"||Qe==="scroll")&&Oe.clientHeight>0)break;Oe=Oe.parentElement}if(!document.documentElement.classList.contains("mobile-doc-scroll")&&!(Oe!==null)){je(null);return}const Tt=Oe?Oe.clientHeight:window.innerHeight,te=Oe?Oe.getBoundingClientRect().top:0,Ae=Oe?Oe.scrollTop:window.scrollY,$e=Ye.getBoundingClientRect().top-te+Ae,it=Math.min(Tt,window.innerHeight)-$e-8;je(Math.max(320,Math.round(it))),Oe&&ce!==Oe&&(be.disconnect(),be.observe(Oe),ce=Oe)},be=new ResizeObserver(xe);xe(),be.observe(document.documentElement),window.addEventListener("resize",xe);const at=new MutationObserver(xe);return at.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>{window.removeEventListener("resize",xe),be.disconnect(),at.disconnect()}},[]),p.useEffect(()=>{if(Te===null)return;const ce=requestAnimationFrame(()=>{Q.current?.fitView({padding:.2})});return()=>cancelAnimationFrame(ce)},[Te]),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 Ke=w.size===Kr.size&&[...Kr].every(ce=>w.has(ce))&&!_,Nt=b?R.get(b.source):null,wt=b?R.get(b.target):null;return r.jsxs("div",{ref:ve,className:"doc-scroll-viewport flex-1 min-h-0 relative",style:{height:Te??"100%"},children:[r.jsxs(sg,{nodes:V,edges:ee,onNodesChange:Z,onEdgesChange:de,onNodeClick:fe,onConnect:ge,onEdgeClick:we,onMoveEnd:ue,onInit:ce=>{Q.current=ce},nodeTypes:cx,fitView:!0,minZoom:.08,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[m&&r.jsx(dx,{nodeIds:V.map(ce=>ce.id),rfRef:Q}),r.jsx(ug,{color:y?"#cbd5e1":"#374151",gap:20,size:1}),r.jsx(bg,{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(Ag,{nodeColor:ce=>{const xe=ce.data?.task,be=xe?.status;return xe?.taskType==="scheduled"?"#8b8fa3":be==="completed"||be==="accepted"?"#10b981":be==="in_progress"?"#f59e0b":be==="blocked"||be==="failed"?"#ef4444":y?"#94a3b8":"#6b7280"},maskColor:y?"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:[T.map(ce=>{const xe=w.has(ce.id);return r.jsx("button",{onClick:()=>B(ce.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${xe?`${ce.color.bg} ${ce.color.border} ${ce.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:g(`work:dag.filter.${ce.id}`)},ce.id)}),O>0&&r.jsx("button",{onClick:()=>I(ce=>!ce),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${_?"bg-surface-overlay/60 border-gray-500/50 text-fg-secondary":"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:g("work:dag.archivedToggle",{count:O})}),!Ke&&r.jsx("button",{onClick:()=>{N(new Set(Kr)),I(!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")})]})]}),k&&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 ${k.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:k.msg}),b&&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:ce=>ce.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:wt?.title??b.target.slice(-8),source:Nt?.title??b.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:me,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 ba="grid grid-cols-[auto_1fr] gap-x-3 gap-y-3.5 items-start",Xd="grid grid-cols-[auto_1fr] sm:grid-cols-[auto_1fr_auto_1fr] gap-x-5 gap-y-3 items-start",st="pt-2 text-sm text-fg-secondary whitespace-nowrap",pn="w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",na="shrink-0 whitespace-nowrap text-[11px] font-medium text-brand-500 hover:text-brand-400";function bx(e){return/^(https?:\/\/|git@|ssh:\/\/|git:\/\/)/i.test(e)}function Pl({orgId:e,onCreated:t,onClose:n}){const{t:s}=ze(["work","common"]);bf(!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,y]=p.useState(""),[k,v]=p.useState(!1),b=hr();p.useEffect(()=>{const N=j=>{j.key==="Escape"&&n()};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[n]);const x=p.useCallback(async N=>{if(N?.preventDefault(),v(!0),!(!o.trim()||f)){m(!0),y("");try{const j=c.trim(),E=j?[{...bx(j)?{url:j}:{localPath:j},defaultBranch:h.trim()||"main",role:"primary"}]:[],C=await ne.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){y(j instanceof Error?j.message:s("project.failedToCreate"))}m(!1)}},[o,i,c,h,e,f,t,s]),w=k&&!o.trim();return yf.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 ${b?"w-full":"w-[26rem]"}`,onClick:N=>N.stopPropagation(),onSubmit:x,children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("project.newProject")}),r.jsxs("div",{className:ba,children:[r.jsx("label",{className:st,children:s("project.projectName")}),r.jsxs("div",{children:[r.jsx("input",{value:o,onChange:N=>{a(N.target.value),y("")},onBlur:()=>v(!0),placeholder:s("project.projectNamePlaceholder"),className:`${pn} ${w?"!border-red-500":""}`,autoFocus:!b}),w&&r.jsx("p",{className:"text-[11px] text-red-400 mt-1",children:s("project.projectNameRequired")})]}),r.jsx("label",{className:st,children:s("project.description")}),r.jsx("textarea",{value:i,onChange:N=>l(N.target.value),placeholder:s("project.descriptionPlaceholder"),className:`${pn} resize-none`,rows:2}),r.jsx("label",{className:st,children:s("project.repositoryUrl")}),r.jsx("input",{value:c,onChange:N=>d(N.target.value),placeholder:s("project.repositoryPlaceholder"),className:`${pn} placeholder:text-[11px]`}),c.trim()&&r.jsxs(r.Fragment,{children:[r.jsx("label",{className:st,children:s("project.branch")}),r.jsx("input",{value:h,onChange:N=>u(N.target.value),placeholder:s("project.branchPlaceholder"),className:pn})]})]}),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-white",children:s(f?"common:creating":"project.createProject")})]})]})}),document.body)}function yx({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:y}=ze(["work","common"]),k=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:y("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:y("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:y("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:y("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-white rounded-lg font-medium transition-colors",children:y("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 ${k?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 ${k?"bg-brand-600 text-white":"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:y("work:task.all")})}),(o??0)>0&&r.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:o})]}),[...e].sort((v,b)=>{const x=v.status==="archived"?1:0,w=b.status==="archived"?1:0;return x-w}).map(v=>{const b=!k&&v.id===t,x=s[v.id]??0,w=v.status==="paused",N=v.status==="archived";return r.jsxs("div",{role:"button",tabIndex:0,"data-project-id":v.id,onClick:()=>i(v.id),onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),i(v.id))},className:`group w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-left cursor-pointer transition-colors ${b?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 ${b?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:v.name[0]?.toUpperCase()??"?"}),r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsx("span",{className:"block text-[12px] font-medium truncate",children:v.name}),N&&r.jsx("span",{className:"block text-[10px] text-fg-tertiary italic",children:y("work:project.statusArchived")}),w&&r.jsx("span",{className:"block text-[10px] text-amber-500/80",children:y("work:project.statusPaused")})]}),l&&r.jsx("button",{type:"button","data-no-drag":!0,title:y("work:project.editProject"),"aria-label":y("work:project.editProject"),onClick:j=>{j.stopPropagation(),l(v.id)},className:"w-6 h-6 flex items-center justify-center rounded-md text-fg-tertiary hover:text-brand-500 hover:bg-surface-elevated transition-opacity opacity-0 group-hover:opacity-100 focus:opacity-100 shrink-0",children: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})]},v.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 wx({project:e,onUpdateProject:t}){const{t:n}=ze(["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,y]=p.useState(null),k=p.useCallback(async()=>{if(e.id){d(!0);try{const{results:C}=await ne.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(()=>{k()},[k]);const v=async()=>{const C=o.trim();if(!(!C||i))try{const D=[...new Set([...s,C])];await t({knowledgeBasePaths:D}),a(""),await N()}catch(D){m({type:"error",text:`${n("work:project.kbPathsSaveFailed")}: ${String(D)}`})}},b=async()=>{const C=g;if(!C||i)return;y(null);const D=s.filter(_=>_!==C);await t({knowledgeBasePaths:D}),await N(D)},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)}`})}},N=async C=>{if(!i){l(!0),m(null);try{const D=await ne.projects.syncKnowledge(e.id,C);m({type:D.errors.length>0?"error":"success",text:n("work:project.kbSyncResult",{scanned:D.scanned,registered:D.registered,updated:D.updated,outdated:D.outdated,errors:D.errors.length})}),await k()}catch(D){m({type:"error",text:`${n("work:project.kbSyncFailed")}: ${String(D)}`})}finally{l(!1)}}},j=async()=>{await N(s.length?s:void 0)},E=C=>{en.navigate(Ze.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-white 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:()=>y(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:()=>{b()},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,D)=>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:()=>y(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}-${D}`)),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{value:o,onChange:C=>a(C.target.value),onKeyDown:C=>{C.key==="Enter"&&v()},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:v,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(Rf,{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 kx=new Set(["rejected","cancelled","archived"]);function vx(e){return kx.has(e)}function jx(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}const za=Symbol.for("yaml.alias"),ya=Symbol.for("yaml.document"),Tn=Symbol.for("yaml.map"),Zd=Symbol.for("yaml.pair"),cn=Symbol.for("yaml.scalar"),Ds=Symbol.for("yaml.seq"),Yt=Symbol.for("yaml.node.type"),Os=e=>!!e&&typeof e=="object"&&e[Yt]===za,br=e=>!!e&&typeof e=="object"&&e[Yt]===ya,yr=e=>!!e&&typeof e=="object"&&e[Yt]===Tn,gt=e=>!!e&&typeof e=="object"&&e[Yt]===Zd,et=e=>!!e&&typeof e=="object"&&e[Yt]===cn,wr=e=>!!e&&typeof e=="object"&&e[Yt]===Ds;function mt(e){if(e&&typeof e=="object")switch(e[Yt]){case Tn:case Ds:return!0}return!1}function pt(e){if(e&&typeof e=="object")switch(e[Yt]){case za:case Tn:case cn:case Ds:return!0}return!1}const Qd=e=>(et(e)||mt(e))&&!!e.anchor,Kn=Symbol("break visit"),Nx=Symbol("skip children"),nr=Symbol("remove node");function $s(e,t){const n=Sx(t);br(e)?ws(null,e.contents,n,Object.freeze([e]))===nr&&(e.contents=null):ws(null,e,n,Object.freeze([]))}$s.BREAK=Kn;$s.SKIP=Nx;$s.REMOVE=nr;function ws(e,t,n,s){const o=Cx(e,t,n,s);if(pt(o)||gt(o))return Ex(e,s,o),ws(e,o,n,s);if(typeof o!="symbol"){if(mt(t)){s=Object.freeze(s.concat(t));for(let a=0;a<t.items.length;++a){const i=ws(a,t.items[a],n,s);if(typeof i=="number")a=i-1;else{if(i===Kn)return Kn;i===nr&&(t.items.splice(a,1),a-=1)}}}else if(gt(t)){s=Object.freeze(s.concat(t));const a=ws("key",t.key,n,s);if(a===Kn)return Kn;a===nr&&(t.key=null);const i=ws("value",t.value,n,s);if(i===Kn)return Kn;i===nr&&(t.value=null)}}return o}function Sx(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 Cx(e,t,n,s){if(typeof n=="function")return n(e,t,s);if(yr(t))return n.Map?.(e,t,s);if(wr(t))return n.Seq?.(e,t,s);if(gt(t))return n.Pair?.(e,t,s);if(et(t))return n.Scalar?.(e,t,s);if(Os(t))return n.Alias?.(e,t,s)}function Ex(e,t,n){const s=t[t.length-1];if(mt(s))s.items[e]=n;else if(gt(s))e==="key"?s.key=n:s.value=n;else if(br(s))s.contents=n;else{const o=Os(s)?"alias":"scalar";throw new Error(`Cannot replace node with ${o} parent`)}}const Tx={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"},Ix=e=>e.replace(/[!,[\]{}]/g,t=>Tx[t]);class _t{constructor(t,n){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},_t.defaultYaml,t),this.tags=Object.assign({},_t.defaultTags,n)}clone(){const t=new _t(this.yaml,this.tags);return t.docStart=this.docStart,t}atDocument(){const t=new _t(this.yaml,this.tags);switch(this.yaml.version){case"1.1":this.atNextDocument=!0;break;case"1.2":this.atNextDocument=!1,this.yaml={explicit:_t.defaultYaml.explicit,version:"1.2"},this.tags=Object.assign({},_t.defaultTags);break}return t}add(t,n){this.atNextDocument&&(this.yaml={explicit:_t.defaultYaml.explicit,version:"1.1"},this.tags=Object.assign({},_t.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+Ix(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&&pt(t.contents)){const a={};$s(t.contents,(i,l)=>{pt(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
|
+
`)}}_t.defaultYaml={explicit:!1,version:"1.2"};_t.defaultTags={"!!":"tag:yaml.org,2002:"};function Jd(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 eu(e){const t=new Set;return $s(e,{Value(n,s){s.anchor&&t.add(s.anchor)}}),t}function tu(e,t){for(let n=1;;++n){const s=`${e}${n}`;if(!t.has(s))return s}}function Mx(e,t){const n=[],s=new Map;let o=null;return{onAnchor:a=>{n.push(a),o??(o=eu(e));const i=tu(t,o);return o.add(i),i},setAnchors:()=>{for(const a of n){const i=s.get(a);if(typeof i=="object"&&i.anchor&&(et(i.node)||mt(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 ks(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=ks(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=ks(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=ks(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=ks(e,s,o,a);i===void 0?delete s[o]:i!==a&&(s[o]=i)}return e.call(t,n,s)}function Ut(e,t,n){if(Array.isArray(e))return e.map((s,o)=>Ut(s,String(o),n));if(e&&typeof e.toJSON=="function"){if(!n||!Qd(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 qa{constructor(t){Object.defineProperty(this,Yt,{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(!br(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=Ut(this,"",i);if(typeof o=="function")for(const{count:c,res:d}of i.anchors.values())o(d,c);return typeof a=="function"?ks(a,{"":l},"",l):l}}class Fa extends qa{constructor(t){super(za),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=[],$s(t,{Node:(a,i)=>{(Os(i)||Qd(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||(Ut(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=oo(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(Jd(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 oo(e,t,n){if(Os(t)){const s=t.resolve(e),o=n&&s&&n.get(s);return o?o.count*o.aliasCount:0}else if(mt(t)){let s=0;for(const o of t.items){const a=oo(e,o,n);a>s&&(s=a)}return s}else if(gt(t)){const s=oo(e,t.key,n),o=oo(e,t.value,n);return Math.max(s,o)}return 1}const nu=e=>!e||typeof e!="function"&&typeof e!="object";class Le extends qa{constructor(t){super(cn),this.value=t}toJSON(t,n){return n?.keep?this.value:Ut(this.value,t,n)}toString(){return String(this.value)}}Le.BLOCK_FOLDED="BLOCK_FOLDED";Le.BLOCK_LITERAL="BLOCK_LITERAL";Le.PLAIN="PLAIN";Le.QUOTE_DOUBLE="QUOTE_DOUBLE";Le.QUOTE_SINGLE="QUOTE_SINGLE";const Ax="tag:yaml.org,2002:";function Lx(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 ur(e,t,n){if(br(e)&&(e=e.contents),pt(e))return e;if(gt(e)){const u=n.schema[Tn].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 Fa(c.anchor);c={anchor:null,node:null},l.set(e,c)}t?.startsWith("!!")&&(t=Ax+t.slice(2));let d=Lx(e,t,i.tags);if(!d){if(e&&typeof e.toJSON=="function"&&(e=e.toJSON()),!e||typeof e!="object"){const u=new Le(e);return c&&(c.node=u),u}d=e instanceof Map?i[Tn]:Symbol.iterator in Object(e)?i[Ds]:i[Tn]}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 Le(e);return t?h.tag=t:d.default||(h.tag=d.tag),c&&(c.node=h),h}function mo(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 ur(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 Js=e=>e==null||typeof e=="object"&&!!e[Symbol.iterator]().next().done;class su extends qa{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=>pt(s)||gt(s)?s.clone(t):s),this.range&&(n.range=this.range.slice()),n}addIn(t,n){if(Js(t))this.add(n);else{const[s,...o]=t,a=this.get(s,!0);if(mt(a))a.addIn(o,n);else if(a===void 0&&this.schema)this.set(s,mo(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(mt(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&&et(a)?a.value:a:mt(a)?a.getIn(o,n):void 0}hasAllNullValues(t){return this.items.every(n=>{if(!gt(n))return!1;const s=n.value;return s==null||t&&et(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 mt(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(mt(a))a.setIn(o,n);else if(a===void 0&&this.schema)this.set(s,mo(this.schema,o,n));else throw new Error(`Expected YAML collection at ${s}. Remaining path: ${o}`)}}}const _x=e=>e.replace(/^(?!$)(?: $)?/gm,"#");function gn(e,t){return/^\n+$/.test(e)?e.substring(1):t?e.replace(/^(?! *$)/gm,t):e}const Un=(e,t,n)=>e.endsWith(`
|
|
9
|
+
`)?gn(n,t):n.includes(`
|
|
10
|
+
`)?`
|
|
11
|
+
`+gn(n,t):(e.endsWith(" ")?"":" ")+n,ru="flow",wa="block",ao="quoted";function Eo(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,y=-1,k=-1,v=-1;n===wa&&(y=Bl(e,y,t.length),y!==-1&&(u=y+c));for(let x;x=e[y+=1];){if(n===ao&&x==="\\"){switch(k=y,e[y+1]){case"x":y+=3;break;case"u":y+=5;break;case"U":y+=9;break;default:y+=1}v=y}if(x===`
|
|
12
|
+
`)n===wa&&(y=Bl(e,y,t.length)),u=y+t.length+c,f=void 0;else{if(x===" "&&m&&m!==" "&&m!==`
|
|
13
|
+
`&&m!==" "){const w=e[y+1];w&&w!==" "&&w!==`
|
|
14
|
+
`&&w!==" "&&(f=y)}if(y>=u)if(f)d.push(f),u=f+c,f=void 0;else if(n===ao){for(;m===" "||m===" ";)m=x,x=e[y+=1],g=!0;const w=y>v+1?y-2:k-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 b=e.slice(0,d[0]);for(let x=0;x<d.length;++x){const w=d[x],N=d[x+1]||e.length;w===0?b=`
|
|
15
|
+
${t}${e.slice(0,N)}`:(n===ao&&h[w]&&(b+=`${e[w]}\\`),b+=`
|
|
16
|
+
${t}${e.slice(w+1,N)}`)}return b}function Bl(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 To=(e,t)=>({indentAtStart:t?e.indent.length:e.indentAtStart,lineWidth:e.options.lineWidth,minContentWidth:e.options.minContentWidth}),Io=e=>/^(%|---|\.\.\.)/m.test(e);function Rx(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 sr(e,t){const n=JSON.stringify(e);if(t.options.doubleQuotedAsJSON)return n;const{implicitKey:s}=t,o=t.options.doubleQuotedMinMultiLineLength,a=t.indent||(Io(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:Eo(i,a,ao,To(t,!1))}function ka(e,t){if(t.options.singleQuote===!1||t.implicitKey&&e.includes(`
|
|
22
|
+
`)||/[ \t]\n|\n[ \t]/.test(e))return sr(e,t);const n=t.indent||(Io(e)?" ":""),s="'"+e.replace(/'/g,"''").replace(/\n+/g,`$&
|
|
23
|
+
${n}`)+"'";return t.implicitKey?s:Eo(s,n,ru,To(t,!1))}function vs(e,t){const{singleQuote:n}=t.options;let s;if(n===!1)s=sr;else{const o=e.includes('"'),a=e.includes("'");o&&!a?s=ka:a&&!o?s=sr:s=n?ka:sr}return s(e,t)}let va;try{va=new RegExp(`(^|(?<!
|
|
24
|
+
))
|
|
25
|
+
+(?!
|
|
26
|
+
|$)`,"g")}catch{va=/\n+(?!\n|$)/g}function io({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 vs(n,s);const d=s.indent||(s.forceBlockIndent||Io(n)?" ":""),h=i==="literal"?!0:i==="folded"||t===Le.BLOCK_FOLDED?!1:t===Le.BLOCK_LITERAL?!0:!Rx(n,c,d.length);if(!n)return h?`|
|
|
27
|
+
`:`>
|
|
28
|
+
`;let u,f;for(f=n.length;f>0;--f){const N=n[f-1];if(N!==`
|
|
29
|
+
`&&N!==" "&&N!==" ")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(va,`$&${d}`));let y=!1,k,v=-1;for(k=0;k<n.length;++k){const N=n[k];if(N===" ")y=!0;else if(N===`
|
|
32
|
+
`)v=k;else break}let b=n.substring(0,v<k?v+1:k);b&&(n=n.substring(b.length),b=b.replace(/\n+/g,`$&${d}`));let w=(y?d?"2":"1":"")+u;if(e&&(w+=" "+l(e.replace(/ ?[\r\n]+/g," ")),o&&o()),!h){const N=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=To(s,!0);i!=="folded"&&t!==Le.BLOCK_FOLDED&&(E.onOverflow=()=>{j=!0});const C=Eo(`${b}${N}${m}`,d,wa,E);if(!j)return`>${w}
|
|
34
|
+
${d}${C}`}return n=n.replace(/\n+/g,`$&${d}`),`|${w}
|
|
35
|
+
${d}${b}${n}${m}`}function Dx(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 vs(a,t);if(/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(a))return l||h||!a.includes(`
|
|
37
|
+
`)?vs(a,t):io(e,t,n,s);if(!l&&!h&&o!==Le.PLAIN&&a.includes(`
|
|
38
|
+
`))return io(e,t,n,s);if(Io(a)){if(c==="")return t.forceBlockIndent=!0,io(e,t,n,s);if(l&&c===d)return vs(a,t)}const u=a.replace(/\n+/g,`$&
|
|
39
|
+
${c}`);if(i){const f=y=>y.default&&y.tag!=="tag:yaml.org,2002:str"&&y.test?.test(u),{compat:m,tags:g}=t.doc.schema;if(g.some(f)||m?.some(f))return vs(a,t)}return l?u:Eo(u,c,ru,To(t,!1))}function Ha(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!==Le.QUOTE_DOUBLE&&/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(i.value)&&(l=Le.QUOTE_DOUBLE);const c=h=>{switch(h){case Le.BLOCK_FOLDED:case Le.BLOCK_LITERAL:return o||a?vs(i.value,t):io(i,t,n,s);case Le.QUOTE_DOUBLE:return sr(i.value,t);case Le.QUOTE_SINGLE:return ka(i.value,t);case Le.PLAIN:return Dx(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 ou(e,t){const n=Object.assign({blockQuote:!0,commentString:_x,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 Ox(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(et(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 $x(e,t,{anchors:n,doc:s}){if(!s.directives)return"";const o=[],a=(et(e)||mt(e))&&e.anchor;a&&Jd(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 Ls(e,t,n,s){if(gt(e))return e.toString(t,n,s);if(Os(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=pt(e)?e:t.doc.createNode(e,{onTagObj:c=>o=c});o??(o=Ox(t.doc.schema.tags,a));const i=$x(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):et(a)?Ha(a,t,n,s):a.toString(t,n,s);return i?et(a)||l[0]==="{"||l[0]==="["?`${i} ${l}`:`${i}
|
|
40
|
+
${t.indent}${l}`:l}function Px({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=pt(e)&&e.comment||null;if(u){if(f)throw new Error("With simple keys, key nodes cannot have comments");if(mt(e)||!pt(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||mt(e)||(et(e)?e.type===Le.BLOCK_FOLDED||e.type===Le.BLOCK_LITERAL:typeof e=="object"));n=Object.assign({},n,{allNullValues:!1,implicitKey:!m&&(u||!a),indent:l+c});let g=!1,y=!1,k=Ls(e,n,()=>g=!0,()=>y=!0);if(!m&&!n.inFlow&&k.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(),k===""?"?":m?`? ${k}`:k}else if(a&&!u||t==null&&m)return k=`? ${k}`,f&&!g?k+=Un(k,n.indent,d(f)):y&&o&&o(),k;g&&(f=null),m?(f&&(k+=Un(k,n.indent,d(f))),k=`? ${k}
|
|
41
|
+
${l}:`):(k=`${k}:`,f&&(k+=Un(k,n.indent,d(f))));let v,b,x;pt(t)?(v=!!t.spaceBefore,b=t.commentBefore,x=t.comment):(v=!1,b=null,x=null,t&&typeof t=="object"&&(t=i.createNode(t))),n.implicitKey=!1,!m&&!f&&et(t)&&(n.indentAtStart=k.length+1),y=!1,!h&&c.length>=2&&!n.inFlow&&!m&&wr(t)&&!t.flow&&!t.tag&&!t.anchor&&(n.indent=n.indent.substring(2));let w=!1;const N=Ls(t,n,()=>w=!0,()=>y=!0);let j=" ";if(f||v||b){if(j=v?`
|
|
42
|
+
`:"",b){const E=d(b);j+=`
|
|
43
|
+
${gn(E,n.indent)}`}N===""&&!n.inFlow?j===`
|
|
44
|
+
`&&x&&(j=`
|
|
45
|
+
|
|
46
|
+
`):j+=`
|
|
47
|
+
${n.indent}`}else if(!m&&mt(t)){const E=N[0],C=N.indexOf(`
|
|
48
|
+
`),D=C!==-1,_=n.inFlow??t.flow??t.items.length===0;if(D||!_){let I=!1;if(D&&(E==="&"||E==="!")){let O=N.indexOf(" ");E==="&"&&O!==-1&&O<C&&N[O+1]==="!"&&(O=N.indexOf(" ",O+1)),(O===-1||C<O)&&(I=!0)}I||(j=`
|
|
49
|
+
${n.indent}`)}}else(N===""||N[0]===`
|
|
50
|
+
`)&&(j="");return k+=j+N,n.inFlow?w&&s&&s():x&&!w?k+=Un(k,n.indent,d(x)):y&&o&&o(),k}function au(e,t){(e==="debug"||e==="warn")&&console.warn(t)}const Ur="<<",xn={identify:e=>e===Ur||typeof e=="symbol"&&e.description===Ur,default:"key",tag:"tag:yaml.org,2002:merge",test:/^<<$/,resolve:()=>Object.assign(new Le(Symbol(Ur)),{addToJSMap:iu}),stringify:()=>Ur},Bx=(e,t)=>(xn.identify(t)||et(t)&&(!t.type||t.type===Le.PLAIN)&&xn.identify(t.value))&&e?.doc.schema.tags.some(n=>n.tag===xn.tag&&n.default);function iu(e,t,n){const s=lu(e,n);if(wr(s))for(const o of s.items)sa(e,t,o);else if(Array.isArray(s))for(const o of s)sa(e,t,o);else sa(e,t,s)}function sa(e,t,n){const s=lu(e,n);if(!yr(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 lu(e,t){return e&&Os(t)?t.resolve(e.doc,e):t}function cu(e,t,{key:n,value:s}){if(pt(n)&&n.addToJSMap)n.addToJSMap(e,t,s);else if(Bx(e,n))iu(e,t,s);else{const o=Ut(n,"",e);if(t instanceof Map)t.set(o,Ut(s,o,e));else if(t instanceof Set)t.add(o);else{const a=zx(n,o,e),i=Ut(s,a,e);a in t?Object.defineProperty(t,a,{value:i,writable:!0,enumerable:!0,configurable:!0}):t[a]=i}}return t}function zx(e,t,n){if(t===null)return"";if(typeof t!="object")return String(t);if(pt(e)&&n?.doc){const s=ou(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)+'..."'),au(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 Wa(e,t,n){const s=ur(e,void 0,n),o=ur(t,void 0,n);return new Rt(s,o)}class Rt{constructor(t,n=null){Object.defineProperty(this,Yt,{value:Zd}),this.key=t,this.value=n}clone(t){let{key:n,value:s}=this;return pt(n)&&(n=n.clone(t)),pt(s)&&(s=s.clone(t)),new Rt(n,s)}toJSON(t,n){const s=n?.mapAsMap?new Map:{};return cu(n,s,this)}toString(t,n,s){return t?.doc?Px(this,t,n,s):JSON.stringify(this)}}function du(e,t,n){return(t.inFlow??e.flow?Fx:qx)(e,t,n)}function qx({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 y=t[g];let k=null;if(pt(y))!u&&y.spaceBefore&&f.push(""),po(n,f,y.commentBefore,u),y.comment&&(k=y.comment);else if(gt(y)){const b=pt(y.key)?y.key:null;b&&(!u&&b.spaceBefore&&f.push(""),po(n,f,b.commentBefore,u))}u=!1;let v=Ls(y,h,()=>k=null,()=>u=!0);k&&(v+=Un(v,a,d(k))),u&&k&&(u=!1),f.push(s+v)}let m;if(f.length===0)m=o.start+o.end;else{m=f[0];for(let g=1;g<f.length;++g){const y=f[g];m+=y?`
|
|
51
|
+
${c}${y}`:`
|
|
52
|
+
`}}return e?(m+=`
|
|
53
|
+
`+gn(d(e),c),l&&l()):u&&i&&i(),m}function Fx({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 y=e[g];let k=null;if(pt(y))y.spaceBefore&&u.push(""),po(t,u,y.commentBefore,!1),y.comment&&(k=y.comment);else if(gt(y)){const b=pt(y.key)?y.key:null;b&&(b.spaceBefore&&u.push(""),po(t,u,b.commentBefore,!1),b.comment&&(d=!0));const x=pt(y.value)?y.value:null;x?(x.comment&&(k=x.comment),x.commentBefore&&(d=!0)):y.value==null&&b?.comment&&(k=b.comment)}k&&(d=!0);let v=Ls(y,c,()=>k=null);d||(d=u.length>h||v.includes(`
|
|
54
|
+
`)),g<e.length-1?v+=",":t.options.trailingComma&&(t.options.lineWidth>0&&(d||(d=u.reduce((b,x)=>b+x.length+2,2)+(v.length+2)>t.options.lineWidth)),d&&(v+=",")),k&&(v+=Un(v,s,l(k))),u.push(v),h=u.length}const{start:f,end:m}=n;if(u.length===0)return f+m;if(!d){const g=u.reduce((y,k)=>y+k.length+2,2);d=t.options.lineWidth>0&&g>t.options.lineWidth}if(d){let g=f;for(const y of u)g+=y?`
|
|
55
|
+
${a}${o}${y}`:`
|
|
56
|
+
`;return`${g}
|
|
57
|
+
${o}${m}`}else return`${f}${i}${u.join(" ")}${i}${m}`}function po({indent:e,options:{commentString:t}},n,s,o){if(s&&o&&(s=s.replace(/^\n+/,"")),s){const a=gn(t(s),e);n.push(a.trimStart())}}function Yn(e,t){const n=et(t)?t.value:t;for(const s of e)if(gt(s)&&(s.key===t||s.key===n||et(s.key)&&s.key.value===n))return s}class Kt extends su{static get tagName(){return"tag:yaml.org,2002:map"}constructor(t){super(Tn,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(Wa(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;gt(t)?s=t:!t||typeof t!="object"||!("key"in t)?s=new Rt(t,t?.value):s=new Rt(t.key,t.value);const o=Yn(this.items,s.key),a=this.schema?.sortMapEntries;if(o){if(!n)throw new Error(`Key ${s.key} already set`);et(o.value)&&nu(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=Yn(this.items,t);return n?this.items.splice(this.items.indexOf(n),1).length>0:!1}get(t,n){const o=Yn(this.items,t)?.value;return(!n&&et(o)?o.value:o)??void 0}has(t){return!!Yn(this.items,t)}set(t,n){this.add(new Rt(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)cu(n,o,a);return o}toString(t,n,s){if(!t)return JSON.stringify(this);for(const o of this.items)if(!gt(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})),du(this,t,{blockItemPrefix:"",flowChars:{start:"{",end:"}"},itemIndent:t.indent||"",onChompKeep:s,onComment:n})}}const Ps={collection:"map",default:!0,nodeClass:Kt,tag:"tag:yaml.org,2002:map",resolve(e,t){return yr(e)||t("Expected a mapping for this tag"),e},createNode:(e,t,n)=>Kt.from(e,t,n)};class Jn extends su{static get tagName(){return"tag:yaml.org,2002:seq"}constructor(t){super(Ds,t),this.items=[]}add(t){this.items.push(t)}delete(t){const n=Yr(t);return typeof n!="number"?!1:this.items.splice(n,1).length>0}get(t,n){const s=Yr(t);if(typeof s!="number")return;const o=this.items[s];return!n&&et(o)?o.value:o}has(t){const n=Yr(t);return typeof n=="number"&&n<this.items.length}set(t,n){const s=Yr(t);if(typeof s!="number")throw new Error(`Expected a valid index, not ${t}.`);const o=this.items[s];et(o)&&nu(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(Ut(a,String(o++),n));return s}toString(t,n,s){return t?du(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(ur(l,void 0,s))}}return a}}function Yr(e){let t=et(e)?e.value:e;return t&&typeof t=="string"&&(t=Number(t)),typeof t=="number"&&Number.isInteger(t)&&t>=0?t:null}const Bs={collection:"seq",default:!0,nodeClass:Jn,tag:"tag:yaml.org,2002:seq",resolve(e,t){return wr(e)||t("Expected a sequence for this tag"),e},createNode:(e,t,n)=>Jn.from(e,t,n)},Mo={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),Ha(e,t,n,s)}},Ao={identify:e=>e==null,createNode:()=>new Le(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^(?:~|[Nn]ull|NULL)?$/,resolve:()=>new Le(null),stringify:({source:e},t)=>typeof e=="string"&&Ao.test.test(e)?e:t.options.nullStr},Va={identify:e=>typeof e=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,resolve:e=>new Le(e[0]==="t"||e[0]==="T"),stringify({source:e,value:t},n){if(e&&Va.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 nn({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 uu={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:nn},fu={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():nn(e)}},hu={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 Le(parseFloat(e)),n=e.indexOf(".");return n!==-1&&e[e.length-1]==="0"&&(t.minFractionDigits=e.length-n-1),t},stringify:nn},Lo=e=>typeof e=="bigint"||Number.isInteger(e),Ka=(e,t,n,{intAsBigInt:s})=>s?BigInt(e):parseInt(e.substring(t),n);function mu(e,t,n){const{value:s}=e;return Lo(s)&&s>=0?n+s.toString(t):nn(e)}const pu={identify:e=>Lo(e)&&e>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^0o[0-7]+$/,resolve:(e,t,n)=>Ka(e,2,8,n),stringify:e=>mu(e,8,"0o")},gu={identify:Lo,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9]+$/,resolve:(e,t,n)=>Ka(e,0,10,n),stringify:nn},xu={identify:e=>Lo(e)&&e>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^0x[0-9a-fA-F]+$/,resolve:(e,t,n)=>Ka(e,2,16,n),stringify:e=>mu(e,16,"0x")},Hx=[Ps,Bs,Mo,Ao,Va,pu,gu,xu,uu,fu,hu];function zl(e){return typeof e=="bigint"||Number.isInteger(e)}const Gr=({value:e})=>JSON.stringify(e),Wx=[{identify:e=>typeof e=="string",default:!0,tag:"tag:yaml.org,2002:str",resolve:e=>e,stringify:Gr},{identify:e=>e==null,createNode:()=>new Le(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^null$/,resolve:()=>null,stringify:Gr},{identify:e=>typeof e=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^true$|^false$/,resolve:e=>e==="true",stringify:Gr},{identify:zl,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})=>zl(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:Gr}],Vx={default:!0,tag:"",test:/^/,resolve(e,t){return t(`Unresolved plain scalar ${JSON.stringify(e)}`),e}},Kx=[Ps,Bs].concat(Wx,Vx),Ua={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=Le.BLOCK_LITERAL),t!==Le.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===Le.BLOCK_LITERAL?`
|
|
58
|
+
`:" ")}return Ha({comment:e,type:t,value:l},s,o,a)}};function bu(e,t){if(wr(e))for(let n=0;n<e.items.length;++n){let s=e.items[n];if(!gt(s)){if(yr(s)){s.items.length>1&&t("Each pair must have its own sequence indicator");const o=s.items[0]||new Rt(new Le(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]=gt(s)?s:new Rt(s)}}else t("Expected a sequence for this tag");return e}function yu(e,t,n){const{replacer:s}=n,o=new Jn(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(Wa(l,c,n))}return o}const Ya={collection:"seq",default:!1,tag:"tag:yaml.org,2002:pairs",resolve:bu,createNode:yu};class Ns extends Jn{constructor(){super(),this.add=Kt.prototype.add.bind(this),this.delete=Kt.prototype.delete.bind(this),this.get=Kt.prototype.get.bind(this),this.has=Kt.prototype.has.bind(this),this.set=Kt.prototype.set.bind(this),this.tag=Ns.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(gt(o)?(a=Ut(o.key,"",n),i=Ut(o.value,a,n)):a=Ut(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=yu(t,n,s),a=new this;return a.items=o.items,a}}Ns.tag="tag:yaml.org,2002:omap";const Ga={collection:"seq",identify:e=>e instanceof Map,nodeClass:Ns,default:!1,tag:"tag:yaml.org,2002:omap",resolve(e,t){const n=bu(e,t),s=[];for(const{key:o}of n.items)et(o)&&(s.includes(o.value)?t(`Ordered maps must not include duplicate keys: ${o.value}`):s.push(o.value));return Object.assign(new Ns,n)},createNode:(e,t,n)=>Ns.from(e,t,n)};function wu({value:e,source:t},n){return t&&(e?ku:vu).test.test(t)?t:e?n.options.trueStr:n.options.falseStr}const ku={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 Le(!0),stringify:wu},vu={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 Le(!1),stringify:wu},Ux={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:nn},Yx={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():nn(e)}},Gx={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 Le(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:nn},kr=e=>typeof e=="bigint"||Number.isInteger(e);function _o(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 Xa(e,t,n){const{value:s}=e;if(kr(s)){const o=s.toString(t);return s<0?"-"+n+o.substr(1):n+o}return nn(e)}const Xx={identify:kr,default:!0,tag:"tag:yaml.org,2002:int",format:"BIN",test:/^[-+]?0b[0-1_]+$/,resolve:(e,t,n)=>_o(e,2,2,n),stringify:e=>Xa(e,2,"0b")},Zx={identify:kr,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^[-+]?0[0-7_]+$/,resolve:(e,t,n)=>_o(e,1,8,n),stringify:e=>Xa(e,8,"0")},Qx={identify:kr,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9][0-9_]*$/,resolve:(e,t,n)=>_o(e,0,10,n),stringify:nn},Jx={identify:kr,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^[-+]?0x[0-9a-fA-F_]+$/,resolve:(e,t,n)=>_o(e,2,16,n),stringify:e=>Xa(e,16,"0x")};class Ss extends Kt{constructor(t){super(t),this.tag=Ss.tag}add(t){let n;gt(t)?n=t:t&&typeof t=="object"&&"key"in t&&"value"in t&&t.value===null?n=new Rt(t.key,null):n=new Rt(t,null),Yn(this.items,n.key)||this.items.push(n)}get(t,n){const s=Yn(this.items,t);return!n&>(s)?et(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=Yn(this.items,t);s&&!n?this.items.splice(this.items.indexOf(s),1):!s&&n&&this.items.push(new Rt(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(Wa(i,null,s));return a}}Ss.tag="tag:yaml.org,2002:set";const Za={collection:"map",identify:e=>e instanceof Set,nodeClass:Ss,default:!1,tag:"tag:yaml.org,2002:set",createNode:(e,t,n)=>Ss.from(e,t,n),resolve(e,t){if(yr(e)){if(e.hasAllNullValues(!0))return Object.assign(new Ss,e);t("Set items must all have null values")}else t("Expected a mapping for this tag");return e}};function Qa(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 ju(e){let{value:t}=e,n=i=>i;if(typeof t=="bigint")n=i=>BigInt(i);else if(isNaN(t)||!isFinite(t))return nn(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 Nu={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})=>Qa(e,n),stringify:ju},Su={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=>Qa(e,!1),stringify:ju},Ro={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(Ro.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=Qa(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$/,"")??""},ql=[Ps,Bs,Mo,Ao,ku,vu,Xx,Zx,Qx,Jx,Ux,Yx,Gx,Ua,xn,Ga,Ya,Za,Nu,Su,Ro],Fl=new Map([["core",Hx],["failsafe",[Ps,Bs,Mo]],["json",Kx],["yaml11",ql],["yaml-1.1",ql]]),Hl={binary:Ua,bool:Va,float:hu,floatExp:fu,floatNaN:uu,floatTime:Su,int:gu,intHex:xu,intOct:pu,intTime:Nu,map:Ps,merge:xn,null:Ao,omap:Ga,pairs:Ya,seq:Bs,set:Za,timestamp:Ro},e0={"tag:yaml.org,2002:binary":Ua,"tag:yaml.org,2002:merge":xn,"tag:yaml.org,2002:omap":Ga,"tag:yaml.org,2002:pairs":Ya,"tag:yaml.org,2002:set":Za,"tag:yaml.org,2002:timestamp":Ro};function ra(e,t,n){const s=Fl.get(t);if(s&&!e)return n&&!s.includes(xn)?s.concat(xn):s.slice();let o=s;if(!o)if(Array.isArray(e))o=[];else{const a=Array.from(Fl.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(xn)),o.reduce((a,i)=>{const l=typeof i=="string"?Hl[i]:i;if(!l){const c=JSON.stringify(i),d=Object.keys(Hl).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 t0=(e,t)=>e.key<t.key?-1:e.key>t.key?1:0;class Ja{constructor({compat:t,customTags:n,merge:s,resolveKnownTags:o,schema:a,sortMapEntries:i,toStringDefaults:l}){this.compat=Array.isArray(t)?ra(t,"compat"):t?ra(null,t):null,this.name=typeof a=="string"&&a||"core",this.knownTags=o?e0:{},this.tags=ra(n,this.name,s),this.toStringOptions=l??null,Object.defineProperty(this,Tn,{value:Ps}),Object.defineProperty(this,cn,{value:Mo}),Object.defineProperty(this,Ds,{value:Bs}),this.sortMapEntries=typeof i=="function"?i:i===!0?t0:null}clone(){const t=Object.create(Ja.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=ou(e,t),{commentString:a}=o.options;if(e.commentBefore){n.length!==1&&n.unshift("");const c=a(e.commentBefore);n.unshift(gn(c,""))}let i=!1,l=null;if(e.contents){if(pt(e.contents)){if(e.contents.spaceBefore&&s&&n.push(""),e.contents.commentBefore){const h=a(e.contents.commentBefore);n.push(gn(h,""))}o.forceBlockIndent=!!e.comment,l=e.contents.comment}const c=l?void 0:()=>i=!0;let d=Ls(e.contents,o,()=>l=null,c);l&&(d+=Un(d,"",a(l))),(d[0]==="|"||d[0]===">")&&n[n.length-1]==="---"?n[n.length-1]=`--- ${d}`:n.push(d)}else n.push(Ls(e.contents,o));if(e.directives?.docEnd)if(e.comment){const c=a(e.comment);c.includes(`
|
|
61
|
+
`)?(n.push("..."),n.push(gn(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(gn(a(c),"")))}return n.join(`
|
|
62
|
+
`)+`
|
|
63
|
+
`}class vr{constructor(t,n,s){this.commentBefore=null,this.comment=null,this.errors=[],this.warnings=[],Object.defineProperty(this,Yt,{value:ya});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 _t({version:i}),this.setSchema(i,s),this.contents=t===void 0?null:this.createNode(t,o,s)}clone(){const t=Object.create(vr.prototype,{[Yt]:{value:ya}});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=pt(this.contents)?this.contents.clone(t.schema):this.contents,this.range&&(t.range=this.range.slice()),t}add(t){ms(this.contents)&&this.contents.add(t)}addIn(t,n){ms(this.contents)&&this.contents.addIn(t,n)}createAlias(t,n){if(!t.anchor){const s=eu(this);t.anchor=!n||s.has(n)?tu(n||"a",s):n}return new Fa(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 k=b=>typeof b=="number"||b instanceof String||b instanceof Number,v=n.filter(k).map(String);v.length>0&&(n=n.concat(v)),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}=Mx(this,i||"a"),g={aliasDuplicateObjects:a??!0,keepUndefined:c??!1,onAnchor:u,onTagObj:d,replacer:o,schema:this.schema,sourceObjects:m},y=ur(t,h,g);return l&&mt(y)&&(y.flow=!0),f(),y}createPair(t,n,s={}){const o=this.createNode(t,null,s),a=this.createNode(n,null,s);return new Rt(o,a)}delete(t){return ms(this.contents)?this.contents.delete(t):!1}deleteIn(t){return Js(t)?this.contents==null?!1:(this.contents=null,!0):ms(this.contents)?this.contents.deleteIn(t):!1}get(t,n){return mt(this.contents)?this.contents.get(t,n):void 0}getIn(t,n){return Js(t)?!n&&et(this.contents)?this.contents.value:this.contents:mt(this.contents)?this.contents.getIn(t,n):void 0}has(t){return mt(this.contents)?this.contents.has(t):!1}hasIn(t){return Js(t)?this.contents!==void 0:mt(this.contents)?this.contents.hasIn(t):!1}set(t,n){this.contents==null?this.contents=mo(this.schema,[t],n):ms(this.contents)&&this.contents.set(t,n)}setIn(t,n){Js(t)?this.contents=n:this.contents==null?this.contents=mo(this.schema,Array.from(t),n):ms(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 _t({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 _t({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 Ja(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=Ut(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"?ks(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 ms(e){if(mt(e))return!0;throw new Error("Expected a YAML collection as document contents")}class Cu extends Error{constructor(t,n,s,o){super(),this.name=t,this.code=s,this.message=o,this.pos=n}}class er extends Cu{constructor(t,n,s){super("YAMLParseError",t,n,s)}}class s0 extends Cu{constructor(t,n,s){super("YAMLWarning",t,n,s)}}const Wl=(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 _s(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,y=null,k=null,v=null,b=null,x=null,w=null,N=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),y&&(d&&C.type!=="comment"&&C.type!=="newline"&&a(y,"TAB_AS_INDENT","Tabs are not allowed as indentation"),y=null),C.type){case"space":!t&&(n!=="doc-start"||s?.type!=="flow-collection")&&C.source.includes(" ")&&(y=C),h=!0;break;case"comment":{h||a(C,"MISSING_CHAR","Comments must be separated from other tokens by white space characters");const D=C.source.substring(1)||" ";u?u+=f+D:u=D,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,(k||v)&&(b=C),h=!0;break;case"anchor":k&&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),k=C,N??(N=C.offset),d=!1,h=!1,g=!0;break;case"tag":{v&&a(C,"MULTIPLE_TAGS","A node can have at most one tag"),v=C,N??(N=C.offset),d=!1,h=!1,g=!0;break}case n:(k||v)&&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"),y&&(d&&y.indent<=i||s?.type==="block-map"||s?.type==="block-seq")&&a(y,"TAB_AS_INDENT","Tabs are not allowed as indentation"),{comma:x,found:w,spaceBefore:c,comment:u,hasNewline:m,anchor:k,tag:v,newlineAfterProp:b,end:E,start:N??E}}function fr(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(fr(t.key)||fr(t.value))return!0}return!1;default:return!0}}function ja(e,t,n){if(t?.type==="flow-collection"){const s=t.end[0];s.indent===e&&(s.source==="]"||s.source==="}")&&fr(t)&&n(s,"BAD_INDENT","Flow end indicator should be more indented than parent",!0)}}function Eu(e,t,n){const{uniqueKeys:s}=e.options;if(s===!1)return!1;const o=typeof s=="function"?s:(a,i)=>a===i||et(a)&&et(i)&&a.value===i.value;return t.some(a=>o(a.key,n))}const Vl="All mapping items must start at the same column";function r0({composeNode:e,composeEmptyNode:t},n,s,o,a){const i=a?.nodeClass??Kt,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,y=_s(u,{indicator:"explicit-key-ind",next:f??m?.[0],offset:c,onError:o,parentIndent:s.indent,startOnNewline:!0}),k=!y.found;if(k){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",Vl)),!y.anchor&&!y.tag&&!m){d=y.end,y.comment&&(l.comment?l.comment+=`
|
|
70
|
+
`+y.comment:l.comment=y.comment);continue}(y.newlineAfterProp||fr(f))&&o(f??u[u.length-1],"MULTILINE_IMPLICIT_KEY","Implicit keys need to be on a single line")}else y.found?.indent!==s.indent&&o(c,"BAD_INDENT",Vl);n.atKey=!0;const v=y.end,b=f?e(n,f,y,o):t(n,v,u,null,y,o);n.schema.compat&&ja(s.indent,f,o),n.atKey=!1,Eu(n,l.items,b)&&o(v,"DUPLICATE_KEY","Map keys must be unique");const x=_s(m??[],{indicator:"map-value-ind",next:g,offset:b.range[2],onError:o,parentIndent:s.indent,startOnNewline:!f||f.type==="block-scalar"});if(c=x.end,x.found){k&&(g?.type==="block-map"&&!x.hasNewline&&o(c,"BLOCK_AS_IMPLICIT_KEY","Nested mappings are not allowed in compact mappings"),n.options.strict&&y.start<x.found.offset-1024&&o(b.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&&ja(s.indent,g,o),c=w.range[2];const N=new Rt(b,w);n.options.keepSourceTokens&&(N.srcToken=h),l.items.push(N)}else{k&&o(b.range,"MISSING_CHAR","Implicit map keys need to be followed by map values"),x.comment&&(b.comment?b.comment+=`
|
|
71
|
+
`+x.comment:b.comment=x.comment);const w=new Rt(b);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 o0({composeNode:e,composeEmptyNode:t},n,s,o,a){const i=a?.nodeClass??Jn,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=_s(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&&ja(s.indent,u,o),c=m.range[2],l.items.push(m)}return l.range=[s.offset,c,d??c],l}function jr(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 oa="Block collections are not allowed within flow collections",aa=e=>e&&(e.type==="block-map"||e.type==="block-seq");function a0({composeNode:e,composeEmptyNode:t},n,s,o,a){const i=s.start.source==="{",l=i?"flow map":"flow sequence",c=a?.nodeClass??(i?Kt:Jn),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 k=0;k<s.items.length;++k){const v=s.items[k],{start:b,key:x,sep:w,value:N}=v,j=_s(b,{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&&!N){k===0&&j.comma?o(j.comma,"UNEXPECTED_TOKEN",`Unexpected , in ${l}`):k<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&&fr(x)&&o(x,"MULTILINE_IMPLICIT_KEY","Implicit keys of flow sequence pairs need to be on a single line")}if(k===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 b)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];gt(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=N?e(n,N,j,o):t(n,j.end,w,null,j,o);d.items.push(E),u=E.range[2],aa(N)&&o(E.range,"BLOCK_IN_FLOW",oa)}else{n.atKey=!0;const E=j.end,C=x?e(n,x,j,o):t(n,E,b,null,j,o);aa(x)&&o(C.range,"BLOCK_IN_FLOW",oa),n.atKey=!1;const D=_s(w??[],{flow:l,indicator:"map-value-ind",next:N,offset:C.range[2],onError:o,parentIndent:s.indent,startOnNewline:!1});if(D.found){if(!i&&!j.found&&n.options.strict){if(w)for(const O of w){if(O===D.found)break;if(O.type==="newline"){o(O,"MULTILINE_IMPLICIT_KEY","Implicit keys of flow sequence pairs need to be on a single line");break}}j.start<D.found.offset-1024&&o(D.found,"KEY_OVER_1024_CHARS","The : indicator must be at most 1024 chars after the start of an implicit flow sequence key")}}else N&&("source"in N&&N.source?.[0]===":"?o(N,"MISSING_CHAR",`Missing space after : in ${l}`):o(D.start,"MISSING_CHAR",`Missing , or : between ${l} items`));const _=N?e(n,N,D,o):D.found?t(n,D.end,w,null,D,o):null;_?aa(N)&&o(_.range,"BLOCK_IN_FLOW",oa):D.comment&&(C.comment?C.comment+=`
|
|
74
|
+
`+D.comment:C.comment=D.comment);const I=new Rt(C,_);if(n.options.keepSourceTokens&&(I.srcToken=v),i){const O=d;Eu(n,O.items,C)&&o(E,"DUPLICATE_KEY","Map keys must be unique"),O.items.push(I)}else{const O=new Kt(n.schema);O.flow=!0,O.items.push(I);const q=(_??C).range;O.range=[C.range[0],q[1],q[2]],d.items.push(O)}u=_?_.range[2]:D.end}}const f=i?"}":"]",[m,...g]=s.end;let y=u;if(m?.source===f)y=m.offset+m.source.length;else{const k=l[0].toUpperCase()+l.substring(1),v=h?`${k} must end with a ${f}`:`${k} in block collection must be sufficiently indented and end with a ${f}`;o(u,h?"MISSING_CHAR":"BAD_INDENT",v),m&&m.source.length!==1&&g.unshift(m)}if(g.length>0){const k=jr(g,y,n.options.strict,o);k.comment&&(d.comment?d.comment+=`
|
|
75
|
+
`+k.comment:d.comment=k.comment),d.range=[s.offset,y,k.offset]}else d.range=[s.offset,y,y];return d}function ia(e,t,n,s,o,a){const i=n.type==="block-map"?r0(e,t,n,s,a):n.type==="block-seq"?o0(e,t,n,s,a):a0(e,t,n,s,a),l=i.constructor;return o==="!"||o===l.tagName?(i.tag=l.tagName,i):(o&&(i.tag=o),i)}function i0(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===Kt.tagName&&l==="map"||i===Jn.tagName&&l==="seq")return ia(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),ia(e,t,n,o,i)}const d=ia(e,t,n,o,i,c),h=c.resolve?.(d,f=>o(a,"TAG_RESOLVE_FAILED",f),t.options)??d,u=pt(h)?h:new Le(h);return u.range=d.range,u.tag=i,c?.format&&(u.format=c.format),u}function l0(e,t,n){const s=t.offset,o=c0(t,e.options.strict,n);if(!o)return{value:"",type:null,comment:"",range:[s,s,s]};const a=o.mode===">"?Le.BLOCK_FOLDED:Le.BLOCK_LITERAL,i=t.source?d0(t.source):[];let l=i.length;for(let y=i.length-1;y>=0;--y){const k=i[y][1];if(k===""||k==="\r")l=y;else break}if(l===0){const y=o.chomp==="+"&&i.length>0?`
|
|
76
|
+
`.repeat(Math.max(1,i.length-1)):"";let k=s+o.length;return t.source&&(k+=t.source.length),{value:y,type:a,comment:o.comment,range:[s,k,k]}}let c=t.indent+o.indent,d=t.offset+o.length,h=0;for(let y=0;y<l;++y){const[k,v]=i[y];if(v===""||v==="\r")o.indent===0&&k.length>c&&(c=k.length);else{k.length<c&&n(d+k.length,"MISSING_CHAR","Block scalars with more-indented leading empty lines must use an explicit indentation indicator"),o.indent===0&&(c=k.length),h=y,c===0&&!e.atRoot&&n(d,"BAD_INDENT","Block scalar values in collections must be indented");break}d+=k.length+v.length+1}for(let y=i.length-1;y>=l;--y)i[y][0].length>c&&(l=y+1);let u="",f="",m=!1;for(let y=0;y<h;++y)u+=i[y][0].slice(c)+`
|
|
77
|
+
`;for(let y=h;y<l;++y){let[k,v]=i[y];d+=k.length+v.length+1;const b=v[v.length-1]==="\r";if(b&&(v=v.slice(0,-1)),v&&k.length<c){const w=`Block scalar lines must not be less indented than their ${o.indent?"explicit indentation indicator":"first line"}`;n(d-v.length-(b?2:1),"BAD_INDENT",w),k=""}a===Le.BLOCK_LITERAL?(u+=f+k.slice(c)+v,f=`
|
|
78
|
+
`):k.length>c||v[0]===" "?(f===" "?f=`
|
|
79
|
+
`:!m&&f===`
|
|
80
|
+
`&&(f=`
|
|
81
|
+
|
|
82
|
+
`),u+=f+k.slice(c)+v,f=`
|
|
83
|
+
`,m=!0):v===""?f===`
|
|
84
|
+
`?u+=`
|
|
85
|
+
`:f=`
|
|
86
|
+
`:(u+=f+v,f=" ",m=!1)}switch(o.chomp){case"-":break;case"+":for(let y=l;y<i.length;++y)u+=`
|
|
87
|
+
`+i[y][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 c0({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 y=m.source;y&&typeof y=="string"&&(u+=y.length)}}}return{mode:a,indent:i,chomp:l,comment:h,length:u}}function d0(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 u0(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=Le.PLAIN,c=f0(a,d);break;case"single-quoted-scalar":l=Le.QUOTE_SINGLE,c=h0(a,d);break;case"double-quoted-scalar":l=Le.QUOTE_DOUBLE,c=m0(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=jr(i,h,t,n);return{value:c,type:l,comment:u.comment,range:[s,h,u.offset]}}function f0(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}`),Tu(e)}function h0(e,t){return(e[e.length-1]!=="'"||e.length===1)&&t(e.length,"MISSING_CHAR","Missing closing 'quote"),Tu(e.slice(1,-1)).replace(/''/g,"'")}function Tu(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 m0(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}=p0(e,s);n+=a,s=i}else if(o==="\\"){let a=e[++s];const i=g0[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+=x0(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 p0(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 g0={0:"\0",a:"\x07",b:"\b",e:"\x1B",f:"\f",n:`
|
|
105
|
+
`,r:"\r",t:" ",v:"\v",N:"
",_:" ",L:"\u2028",P:"\u2029"," ":" ",'"':'"',"/":"/","\\":"\\"," ":" "};function x0(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 Iu(e,t,n,s){const{value:o,type:a,comment:i,range:l}=t.type==="block-scalar"?l0(e,t,s):u0(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=b0(e.schema,o,c,n,s):t.type==="scalar"?d=y0(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=et(u)?u:new Le(u)}catch(u){const f=u instanceof Error?u.message:String(u);s(n??t,"TAG_RESOLVE_FAILED",f),h=new Le(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 b0(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 y0({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 w0(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 k0={composeNode:Mu,composeEmptyNode:ei};function Mu(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=Iu(e,t,c,s),l&&(d.anchor=l.source.substring(1));break;case"block-map":case"block-seq":case"flow-collection":try{d=i0(k0,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=ei(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&&(!et(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 ei(e,t,n,s,{spaceBefore:o,comment:a,anchor:i,tag:l,end:c},d){const h={type:"scalar",offset:w0(t,n,s),indent:-1,source:""},u=Iu(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 Fa(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=jr(s,i,e.strict,o);return a.range=[t,i,l.offset],l.comment&&(a.comment=l.comment),a}function j0(e,t,{offset:n,start:s,value:o,end:a},i){const l=Object.assign({_directives:t},e),c=new vr(void 0,l),d={atKey:!1,atRoot:!0,directives:c.directives,options:c.options,schema:c.schema},h=_s(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?Mu(d,o,h,i):ei(d,h.end,s,null,h,i);const u=c.contents.range[2],f=jr(a,u,!1,i);return f.comment&&(c.comment=f.comment),c.range=[n,u,f.offset],c}function Qs(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 Kl(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 N0{constructor(t={}){this.doc=null,this.atDirectives=!1,this.prelude=[],this.errors=[],this.warnings=[],this.onError=(n,s,o,a)=>{const i=Qs(n);a?this.warnings.push(new s0(i,s,o)):this.errors.push(new er(i,s,o))},this.directives=new _t({version:t.version||"1.2"}),this.options=t}decorate(t,n){const{comment:s,afterEmptyLine:o}=Kl(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(mt(a)&&!a.flow&&a.items.length>0){let i=a.items[0];gt(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:Kl(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=Qs(t);a[0]+=n,this.onError(a,"BAD_DIRECTIVE",s,o)}),this.prelude.push(t.source),this.atDirectives=!0;break;case"document":{const n=j0(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 er(Qs(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 er(Qs(t),"UNEXPECTED_TOKEN",s));break}this.doc.directives.docEnd=!0;const n=jr(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 er(Qs(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 vr(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 Au="\uFEFF",Lu="",_u="",Na="";function S0(e){switch(e){case Au:return"byte-order-mark";case Lu:return"doc-mode";case _u:return"flow-error-end";case Na: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 Xt(e){switch(e){case void 0:case" ":case`
|
|
115
|
+
`:case"\r":case" ":return!0;default:return!1}}const Ul=new Set("0123456789ABCDEFabcdef"),C0=new Set("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()"),Xr=new Set(",[]{}"),E0=new Set(` ,[]{}
|
|
116
|
+
\r `),la=e=>!e||E0.has(e);class T0{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==="...")&&Xt(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]===Au&&(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 Lu,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==="...")&&Xt(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&&!Xt(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===":")&&Xt(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(la),"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("..."))&&Xt(o[3]))&&!(s===this.indentNext-1&&this.flowLevel===1&&(o[0]==="]"||o[0]==="}")))return this.flowLevel=0,yield _u,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(la),"flow";case'"':case"'":return this.flowKey=!0,yield*this.parseQuotedScalar();case":":{const i=this.charAt(1);if(this.flowKey||Xt(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=>Xt(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 Na,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(Xt(a)||t&&Xr.has(a))break;n=s}else if(Xt(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&&Xr.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&&Xr.has(o))break;n=s}return!o&&!this.atEnd?this.setNext("plain-scalar"):(yield Na,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(la),t+=yield*this.pushSpaces(!0);continue e;case"-":case"?":case":":{const n=this.flowLevel>0,s=this.charAt(1);if(Xt(s)||n&&Xr.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(;!Xt(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(C0.has(n))n=this.buffer[++t];else if(n==="%"&&Ul.has(this.buffer[t+1])&&Ul.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 I0{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 Nn(e,t){for(let n=0;n<e.length;++n)if(e[n].type===t)return!0;return!1}function Yl(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 Ru(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 Zr(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 ps(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 go(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 Gl(e){if(e.start.type==="flow-seq-start")for(const t of e.items)t.sep&&!t.value&&!Nn(t.start,"explicit-key-ind")&&!Nn(t.sep,"map-value-ind")&&(t.key&&(t.value=t.key),delete t.key,Ru(t.value)?t.value.end?go(t.value.end,t.sep):t.value.end=t.sep:go(t.start,t.sep),delete t.sep)}class M0{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 T0,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=S0(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"&&Gl(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&&Yl(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":{Yl(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=Zr(this.peek(2)),s=ps(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)){go(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(Nn(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(Ru(n.key)&&!Nn(n.sep,"newline")){const i=ps(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(Nn(n.start,"newline"))Object.assign(n,{key:null,sep:[this.sourceToken]});else{const i=ps(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]}):Nn(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&&!Nn(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)){go(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||Nn(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=Zr(s),a=ps(o);Gl(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=Zr(t),s=ps(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=Zr(t),s=ps(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 A0(e){const t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new I0||null,prettyErrors:t}}function L0(e,t={}){const{lineCounter:n,prettyErrors:s}=A0(t),o=new M0(n?.addNewLine),a=new N0(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 er(l.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}return s&&n&&(i.errors.forEach(Wl(e,n)),i.warnings.forEach(Wl(e,n))),i}function Xl(e,t,n){let s;typeof t=="function"?s=t:n===void 0&&t&&typeof t=="object"&&(n=t);const o=L0(e,n);if(!o)return null;if(o.warnings.forEach(a=>au(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 Zl(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 br(e)&&!s?e.toString(n):new vr(e,s,n).toString(n)}function _0({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,y]=p.useState(e);p.useEffect(()=>{e&&y(!0)},[e]);const k=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:k,"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 R0({step:e,index:t,total:n,dependsOnNames:s,roleOptions:o,onClose:a,onSave:i}){const{t:l}=ze(["work","common"]),[c,d]=p.useState(null),[h,u]=p.useState(e.name),[f,m]=p.useState(e.prompt),[g,y]=p.useState(!1),[k,v]=p.useState(null),b=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=>{y(!0),v(null);try{await i(j)}catch(E){v(E instanceof Error?E.message:String(E))}finally{y(!1)}},w=async()=>{d(null);const j=h.trim();if(!j||j===e.name){u(e.name);return}await x({name:j})},N=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:b,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:()=>{N()},"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 放弃本次编辑;保存时服务端会重新校验模板。")}),k?r.jsx("p",{className:"text-[11px] text-red-500",children:k}):null]})]})]})}const D0={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:"已取消"}},Ql={tone:"neutral",key:"runStatusUnknown",label:"未知"};function Du(e){return e?D0[e]??{...Ql,label:e}:Ql}const Cn={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"}},Ou=new Set(["completed","archived"]),$u=new Set(["failed","rejected"]),Pu=new Set(["in_progress","review"]);function ti(e){return e==="running"||e==="paused"}function ni(e){const t=new Map;for(const n of e)t.set(n.id,n);return t}function O0(e,t){return t.get(e)?.name??e}function si(e,t){return(e.depends_on??[]).map(n=>O0(n,t))}function $0(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 Bu(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 zu(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++,Ou.has(d.status)?s++:$u.has(d.status)?(o++,i.push(c)):Pu.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 Qr(e){return e?Ou.has(e.status)?"done":$u.has(e.status)?"failed":Pu.has(e.status)?"active":"pending":"unknown"}const qu="markus_workflows_expanded";function P0(e){try{const t=e(qu);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 B0(e,t){try{t(qu,JSON.stringify([...e]))}catch{}}function z0(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 Jl({status:e,className:t=""}){const{t:n}=ze(["work"]),s=Du(e),o=Cn[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 q0({items:e}){const{t}=ze(["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(F0,{})}),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 F0({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 H0(){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 W0({steps:e,roleAgentName:t,onOpenStep:n}){const{t:s}=ze(["work"]),o=ni(e),{layers:a}=$0(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=si(f,o),g=t?.(f.role),y=(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:y}),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 V0({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:y}){const{t:k}=ze(["work","common"]),[v,b]=p.useState(null),x=i[0],w=i.some(C=>ti(C.status)),N=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:k("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:k("work:task.workflowScheduled","定时")}):null,r.jsxs("span",{className:"text-[10px] text-fg-muted",children:["v",e.version]}),x?r.jsx(Jl,{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"}),k("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-white transition-colors hover:bg-brand-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60",children:k("work:task.workflowRun","运行")}),r.jsx(q0,{items:[{key:"edit",label:k("work:task.workflowEditYaml","编辑 YAML"),onSelect:m},{key:"duplicate",label:k("work:task.workflowDuplicate","复制为新工作流"),onSelect:g},{key:"send",label:k("work:task.workflowSendToAgent","发送到智能体对话"),onSelect:f},{key:"delete",label:k("work:task.workflowDelete","删除工作流"),onSelect:y,danger:!0}]})]});return r.jsxs("div",{className:"rounded-xl border border-border-default/50 bg-surface-secondary p-4","data-testid":`workflow-card-${e.name}`,children:[r.jsx(_0,{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:k("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:k("work:task.workflowRetry","重试")})]}):t?r.jsxs("div",{className:"space-y-4",children:[N.length>0?r.jsx(W0,{steps:N,roleAgentName:u,onOpenStep:(C,D)=>b({step:C,index:D})}):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:k("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:[k("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:k("work:task.workflowRecentRuns","最近运行")}),i.length===0?r.jsx("p",{className:"text-[11px] text-fg-muted",children:k("work:task.workflowNoRecentRuns","暂无运行记录")}):r.jsx("ul",{className:"space-y-0.5",children:i.map(C=>{const D=Bu(N,l[C.id]??[]),_=zu(N,D);return r.jsx("li",{children:r.jsxs("button",{type:"button",onClick:()=>d(C),"aria-label":k("work:task.workflowRunDetails","运行详情"),"data-testid":`workflow-run-open-${C.id}`,className:"group flex w-full items-center gap-2 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(Jl,{status:C.status}),r.jsx("span",{className:"shrink-0 text-[11px] tabular-nums text-fg-tertiary",children:_.total>0?`${_.done}/${_.total}`:k("work:task.workflowStepCountShort","{{count}} 个任务",{count:C.taskIds.length})}),r.jsx("span",{className:"shrink-0 text-[11px] text-fg-muted",children:jc(C.startedAt,k)}),C.triggeredBy==="schedule"?r.jsx("span",{className:"shrink-0 text-[10px] text-purple-500",children:k("work:task.workflowScheduled","定时")}):null,r.jsx("span",{className:"flex-1"}),r.jsx("svg",{className:"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(H0,{})}),v?r.jsx(R0,{step:v.step,index:v.index,total:N.length,dependsOnNames:si(v.step,ni(N)),roleOptions:[...new Set([...N.map(C=>C.role),...Object.keys(x?.roleMapping??{})])],onClose:()=>b(null),onSave:C=>h?.(v.step.id,C)??Promise.resolve()}):null]})}const ec={done:Cn.success.bar,failed:Cn.danger.bar,active:Cn.info.bar,pending:"bg-fg-muted/50",unknown:"bg-border-default"},ca={done:{key:"runStatusCompleted",label:"已完成"},failed:{key:"runStatusFailed",label:"失败"},active:{key:"runStatusRunning",label:"进行中"},pending:{key:"workflowStepPending",label:"待处理"},unknown:{key:"workflowStepNoTask",label:"未创建任务"}};function K0({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}=ze(["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??[],y=ni(g),k=Bu(g,s??[]),v=zu(g,k),b=Du(t.status),x=(s??[]).filter(j=>!Object.values(k).some(E=>E?.id===j.id)),w=(s?.length??0)>0&&Object.values(k).every(j=>!j),N=j=>w&&j==="unknown"?{key:"workflowStepUnmatched",label:"未匹配(历史运行)"}:ca[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 ${Cn[b.tone].chip}`,children:[r.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${Cn[b.tone].dot}`,"aria-hidden":"true"}),f(`work:task.${b.key}`,b.label)]}),r.jsx("span",{children:jc(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:v.done,total:v.total||t.taskIds.length})}),v.failed>0?r.jsx("span",{className:"text-red-500",children:f("work:task.workflowFailedCount","{{count}} 步失败",{count:v.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 ${v.failed>0?Cn.danger.bar:Cn.success.bar}`,style:{width:`${v.total>0?v.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=k[j.id],D=Qr(C),_=N(D),I=si(j,y),O=h?.(j.role),q=r.jsxs(r.Fragment,{children:[r.jsx("span",{className:`mt-1.5 h-2 w-2 shrink-0 rounded-full ${ec[D]}`,"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.${_.key}`,_.label)})]}),r.jsxs("span",{className:"mt-0.5 flex flex-wrap gap-x-2 text-[10px] text-fg-muted",children:[r.jsx("span",{children:O??j.role}),I.length>0?r.jsx("span",{children:f("work:task.workflowDependsOn","依赖 {{steps}}",{steps:I.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:q}):r.jsx("div",{className:"flex items-start gap-2 rounded-lg px-1 py-1",children:q})},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 ${ec[Qr(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.${ca[Qr(j)].key}`,ca[Qr(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:[ti(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-white transition-colors hover:bg-brand-500",children:f("work:task.workflowViewTasks","查看任务")})]})]})]})}function U0({mode:e,workflow:t,yaml:n,yamlLoading:s,busy:o,error:a,onClose:i,onSubmit:l}){const{t:c}=ze(["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 k=v=>{v.key==="Escape"&&i()};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[i]);const g=e==="edit"?c("work:task.workflowEditTitle","编辑工作流"):e==="duplicate"?c("work:task.workflowDuplicateTitle","复制为新工作流"):c("work:task.workflowDeleteConfirmTitle","删除工作流"),y=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:k=>h(k.target.value),placeholder:c("work:task.workflowNewNamePlaceholder","例如 feature-development-v2"),className:"input-field w-full font-mono text-xs"}),y?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:k=>f(k.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"&&y,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 tc="markus_work_l1_collapsed",nc="markus_workflows_team",sc="__all__",rc=["backlog","kanban","dag","workflows"];function ri(e){const t=e.agentId,n=e.activityId;return!t||!n?null:Sc({seq:e.seq,type:e.type,content:e.content??"",metadata:e.metadata,createdAt:e.createdAt??new Date().toISOString()},n,t)}function oi(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 ai({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(Af,{entries:e,isActive:!0,onExpand:()=>n("full"),embedded:!0}):r.jsx(Cc,{entries:e,isActive:!0,onCollapse:()=>n("compact"),embedded:!0})})}function ii(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),y=p.useRef(null),k=ii(m,c);p.useEffect(()=>{const w=N=>{f.current&&!f.current.contains(N.target)&&y.current&&!y.current.contains(N.target)&&d(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[]);const v=l==="sm"?"px-2 py-1.5 text-xs":"px-3 py-2 text-sm",b=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 ${v} 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 ${v.split(" ").slice(2).join(" ")}`,placeholder:b||s,autoFocus:!0}):r.jsx("span",{className:b?"text-fg-primary":"text-fg-tertiary",children:b||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&&k&&r.jsx("div",{ref:y,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:k.flipUp?{bottom:window.innerHeight-k.top,left:k.left,width:k.width}:{top:k.top,left:k.left,width:k.width},children:x.length===0?r.jsx("div",{className:`${v} text-fg-tertiary`,children:o??"No matches"}):x.map(w=>r.jsx("div",{onClick:()=>{n(w.value),d(!1),u("")},className:`${v} 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 Y0=[{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 xo({value:e,onChange:t}){const{t:n}=ze("work");return r.jsx("div",{className:"flex flex-wrap gap-2",children:Y0.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 Fu({kind:e,entity:t,agents:n,users:s,projects:o,onClose:a}){const i=t.title?.trim()||t.id,l=_f(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(Ec,{chipLabel:d,chipContent:h,agents:n,users:s,defaultTarget:Ic(t.createdBy,n,s),onClose:a})}function G0({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=ii(u,i);p.useEffect(()=>{const v=b=>{h.current&&!h.current.contains(b.target)&&m.current&&!m.current.contains(b.target)&&l(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]);const y=e.filter(v=>!t.includes(v.value)),k=c?y.filter(v=>v.label.toLowerCase().includes(c.toLowerCase())):y;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:v=>d(v.target.value),onClick:v=>v.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:k.length===0?r.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:o??"No matches"}):k.map(v=>r.jsx("div",{onClick:()=>{n(v.value),d("")},className:"px-3 py-2 text-sm cursor-pointer hover:bg-brand-500/10 text-fg-primary",children:v.label},v.value))})]})}function X0({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=ii(u,i);p.useEffect(()=>{const k=v=>{h.current&&!h.current.contains(v.target)&&m.current&&!m.current.contains(v.target)&&l(!1)};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[]);const y=c?e.filter(k=>k.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:k=>d(k.target.value),onClick:k=>k.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:y.length===0?r.jsx("div",{className:"px-3 py-2 text-xs text-fg-tertiary",children:s??"No matches"}):y.map(k=>r.jsxs("div",{onClick:()=>{t(k.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:k.label}),a?.(k)]},k.value))})]})}function Rs(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 Z0({value:e,onSave:t,className:n,placeholder:s}){const{t:o}=ze(["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 Q0({value:e,onSave:t,className:n,placeholder:s}){const{t:o}=ze(["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 J0=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function Hu(e){const t=e.match(J0);return t?{timestamp:t[1].trim(),author:t[2]?.trim()??"System",content:t[3].trim()}:{timestamp:"",author:"",content:e}}function eb(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 oc=[{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 tb(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return oc[Math.abs(t)%oc.length]}function nb({note:e,compact:t}){const{t:n}=ze(["work","common"]),s=Hu(e),o=n("work:task.systemAuthor"),a=tb(s.author||o),i=s.author?s.author.split(/[\s_-]+/).map(d=>d[0]).join("").slice(0,2).toUpperCase():"SY",l=eb(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(rr,{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(rr,{content:s.content,className:"text-xs text-fg-secondary"})})]})})]})}const sb=new Set(["rejected","cancelled","archived"]),bo=[{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"}],ac={pending:"bg-amber-500/15 text-amber-600",blocked:"bg-amber-500/15 text-amber-600",failed:"bg-red-500/15 text-red-500",rejected:"bg-red-500/15 text-red-500"},ic={pending:"bg-amber-500/15 text-amber-600",in_progress:"bg-blue-500/15 text-blue-500",blocked:"bg-orange-500/15 text-orange-500",review:"bg-purple-500/15 text-purple-500",revision:"bg-amber-500/15 text-amber-600",completed:"bg-green-500/15 text-green-600",failed:"bg-red-500/15 text-red-500",rejected:"bg-red-500/15 text-red-500",cancelled:"bg-gray-500/15 text-fg-tertiary",archived:"bg-gray-500/15 text-fg-tertiary"},lc={low:"bg-gray-500/15 text-fg-tertiary",medium:"bg-blue-500/15 text-blue-500",high:"bg-amber-500/15 text-amber-600",urgent:"bg-red-500/15 text-red-500"},cc={pending:"bg-amber-500/15 text-amber-600",in_progress:"bg-brand-500/15 text-brand-500",completed:"bg-green-500/15 text-green-600",rejected:"bg-red-500/15 text-red-500",cancelled:"bg-gray-600/15 text-fg-tertiary",archived:"bg-gray-600/10 text-fg-tertiary/60"};function Wu(e){return Object.keys(ic).reduce((t,n)=>(t[n]={label:e(`work:status.task.${n}`),cls:ic[n]},t),{})}function Vu(e){return Object.keys(ac).reduce((t,n)=>(t[n]={label:e(`work:status.sub.${n}`),cls:ac[n]},t),{})}function rb(e){return Object.keys(lc).reduce((t,n)=>(t[n]={label:e(`work:priority.${n}`),cls:lc[n]},t),{})}function li(e){return Object.keys(cc).reduce((t,n)=>(t[n]={label:e(`work:status.requirement.${n}`),cls:cc[n]},t),{})}const dc=["low","medium","high","urgent"],uc=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],fc=["pending","in_progress","completed","rejected","cancelled"],hc={pending:new Set(["in_progress","blocked","rejected","cancelled"]),in_progress:new Set(["review","blocked","failed","cancelled"]),blocked:new Set(["in_progress","cancelled"]),review:new Set(["completed","in_progress","cancelled"]),completed:new Set(["archived","in_progress"]),failed:new Set(["in_progress","archived"]),rejected:new Set(["archived"]),cancelled:new Set(["archived"]),archived:new Set([])},Sa={pending:new Set(["in_progress","rejected","cancelled"]),in_progress:new Set(["completed","cancelled"]),completed:new Set([]),rejected:new Set([]),cancelled:new Set([])},Gn={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"},mc={idle:"text-green-500",working:"text-blue-500",error:"text-red-500",paused:"text-amber-500",offline:"text-fg-muted"};function ob({agent:e,anchorRect:t,onClose:n}){const{t:s}=ze(["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(),en.navigate(Ze.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 Do({comment:e,agents:t,onReply:n}){const{t:s}=ze(["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,y]=p.useState(!1),k=p.useCallback((N,j)=>{const E=t.find(C=>C.name.toLowerCase()===N.toLowerCase());if(E){const C=j.target.getBoundingClientRect();d({agent:E,top:C.bottom,left:C.left})}},[t]),v=p.useMemo(()=>t.map(N=>N.name),[t]),b=p.useCallback(N=>{const j=t.find(E=>E.name.toLowerCase()===e.authorName.toLowerCase());if(j){const E=N.currentTarget.getBoundingClientRect();d({agent:j,top:E.bottom,left:E.left})}},[t,e.authorName]),x=p.useCallback(async()=>{if(h){u(!1);return}const N=e.activityId;if(N&&(u(!0),!(f.length>0))){y(!0);try{const{logs:j}=await ne.agents.getActivityLogs(e.authorId,N),E=j.map(C=>Sc(C,N,e.authorId)).filter(C=>C!==null).map(C=>({...C,ts:new Date(C.createdAt).getTime()}));m(E)}catch{}y(!1)}},[h,f.length,e]),w=p.useMemo(()=>If(f.map(Mf).filter(N=>N!==null)),[f]);return r.jsxs("div",{className:"flex gap-2.5 group py-1",id:`comment-${e.id}`,children:[r.jsx("div",{onClick:b,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:b,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 N=document.getElementById(`comment-${e.replyTo}`);N&&(N.scrollIntoView({behavior:"smooth",block:"center"}),N.classList.add("bg-brand-500/10"),setTimeout(()=>N.classList.remove("bg-brand-500/10"),1500))},className:"flex items-center gap-1.5 mb-1 pl-2 py-0.5 border-l-2 border-brand-500/40 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors cursor-pointer",children:[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(rr,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:k,knownNames:v}),e.attachments?.map((N,j)=>N.type==="image"?r.jsx("img",{src:N.url,alt:N.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(Cc,{entries:f,isActive:!1,onCollapse:()=>u(!1),embedded:!0})})]}),c&&r.jsx(ob,{agent:c.agent,anchorRect:{top:c.top,left:c.left},onClose:()=>d(null)})]})}function ab({task:e,agents:t,users:n,authUser:s}){const{t:o}=ze(["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),ne.tasks.getComments(e.id).then(v=>i(v.comments)).catch(()=>{})},[e.id]),p.useEffect(()=>Ht.on("task:comment",b=>{if(b.payload?.taskId===e.id&&b.payload.comment){const x=b.payload.comment;i(w=>w.some(N=>N.id===x.id)?w:[...w,x]),(x.authorType==="agent"||x.authorId?.startsWith("agt_"))&&(c(w=>{const N=w.filter(j=>j.id!==x.authorId);return N.length===0&&d.current&&(clearTimeout(d.current),d.current=null),N}),u(w=>{const N=new Map(w);return N.delete(x.authorId),N}))}}),[e.id]),p.useEffect(()=>{if(l.length===0)return;const v=new Set(l.map(x=>x.id));return Ht.on("agent:activity_log",x=>{const w=x.payload;if(!w)return;const N=w.agentId;if(!v.has(N))return;const j=ri(w);j&&u(E=>oi(E,N,j))})},[l]);const f=p.useMemo(()=>{const v=[];for(const b of e.notes??[]){const x=Hu(b);let w;if(x.timestamp){const N=x.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);w=N?new Date(+N[1],+N[2]-1,+N[3],+N[4],+N[5],+(N[6]??0)):new Date(0)}else w=new Date(0);v.push({type:"note",note:b,ts:w})}for(const b of a)v.push({type:"comment",comment:b,ts:new Date(b.createdAt)});return v.sort((b,x)=>b.ts.getTime()-x.ts.getTime()),v},[e.notes,a]),[m,g]=p.useState(null),y=async(v,b,x,w)=>{let N;x.length>0&&(N=(await ne.uploads.upload(x.map(_=>({dataUrl:_.dataUrl,name:_.name})),"comments")).files.map(_=>({type:"image",url:_.url,name:_.name}))),await ne.tasks.addComment(e.id,v,s?.name,N,s?.id,b.length>0?b:void 0,w);const j=[],E=new Set,C=D=>{if(E.has(D)||D===s?.id)return;E.add(D);const _=t.find(I=>I.id===D);_&&j.push({id:_.id,name:_.name,avatarUrl:_.avatarUrl})};for(const D of b){const _=t.find(I=>I.name.toLowerCase()===D.toLowerCase());_&&C(_.id)}e.assignedAgentId&&C(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&C(e.createdBy),j.length>0&&(d.current&&clearTimeout(d.current),c(j),d.current=setTimeout(()=>c([]),12e4))},k=p.useCallback(v=>{g({id:v.id,authorName:v.authorName,content:v.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((v,b)=>v.type==="note"?r.jsx(nb,{note:v.note,compact:!0},`n-${b}`):r.jsx(Do,{comment:v.comment,agents:t,onReply:k},`c-${v.comment.id}`)),l.length>0&&r.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:l.map(v=>{const b=h.get(v.id)??[];return r.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>en.navigate(Ze.TEAM,{agentId:v.id,profileTab:"mind"}),children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"relative shrink-0",children:[r.jsx(Ea,{name:v.name,avatarUrl:v.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:v.name}),b.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:"→"})]}),b.length>0&&r.jsx("div",{className:"ml-8 mt-1",children:r.jsx(ai,{entries:b})})]},v.id)})})]}),r.jsx(Ac,{agents:t,humans:n,onSubmit:y,replyTo:m,onCancelReply:()=>g(null),placeholder:o("work:task.commentPlaceholder")})]})}function pc({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(Do,{comment:i.comment,agents:n},i.key):r.jsx(Lf,{entries:i.entries,isStreaming:s},i.key))})}function ib({task:e,isRunning:t,authUser:n,agents:s}){const o=e.id,{t:a}=ze(["work","common"]),[i,l]=p.useState([]),[c,d]=p.useState(new Map),[h,u]=p.useState(new Set),[f,m]=p.useState([]),[g,y]=p.useState(""),[k,v]=p.useState(t),[b,x]=p.useState(!0),[w,N]=p.useState(new Set),[j,E]=p.useState(""),[C,D]=p.useState(!1),[_,I]=p.useState([]),O=p.useRef(null),[q,T]=p.useState(new Map),[B,L]=p.useState([]),[z,R]=p.useState([]),[A,$]=p.useState(!1),F=p.useRef(null),W=p.useRef(null);p.useEffect(()=>{v(t)},[t]),p.useEffect(()=>{I([]),T(new Map),O.current&&(clearTimeout(O.current),O.current=null)},[o]),p.useEffect(()=>{x(!0),Promise.all([ne.tasks.getLogsSummary(o).catch(()=>({rounds:[]})),ne.tasks.getComments(o).catch(()=>({comments:[]}))]).then(([Q,le])=>{const ue=Q.rounds;if(l(ue),m(le.comments),ue.length===0){x(!1);return}const fe=ue[ue.length-1].round;N(new Set([fe])),ne.tasks.getLogs(o,fe).catch(()=>({logs:[]})).then(ge=>{d(new Map([[fe,ge.logs]])),x(!1)})})},[o]),p.useEffect(()=>{const Q=e.assignedAgentId;Q&&($(!0),ne.agents.getActivities(Q,{taskId:o,limit:20}).then(le=>R(le.activities)).catch(()=>R([])).finally(()=>$(!1)))},[o,e.assignedAgentId]);const X=p.useCallback(Q=>{c.has(Q)||h.has(Q)||(u(le=>new Set(le).add(Q)),ne.tasks.getLogs(o,Q).catch(()=>({logs:[]})).then(le=>{d(ue=>new Map(ue).set(Q,le.logs)),u(ue=>{const fe=new Set(ue);return fe.delete(Q),fe})}))},[o,c,h]),P=p.useCallback(Q=>{N(le=>{const ue=new Set(le);return ue.has(Q)?ue.delete(Q):(ue.add(Q),c.has(Q)||X(Q)),ue})},[c,X]);p.useEffect(()=>{const Q=Ht.on("task:log",fe=>{const ge=fe.payload;if(ge.taskId!==o)return;const we={id:ge.id,taskId:ge.taskId,agentId:ge.agentId,seq:ge.seq,type:ge.logType,content:ge.content,metadata:ge.metadata,executionRound:ge.executionRound,createdAt:ge.createdAt},me=we.executionRound??1;l(ve=>ve.find(je=>je.round===me)?ve:[...ve,{round:me,logCount:0,toolCount:0,firstAt:we.createdAt,lastAt:we.createdAt,status:"running"}]),N(ve=>ve.has(me)?ve:new Set(ve).add(me)),d(ve=>{const Te=ve.get(me)??[];return we.id&&Te.some(je=>je.id===we.id)?ve:new Map(ve).set(me,[...Te,we])}),we.type==="text"&&y(""),we.type==="status"&&(we.content==="started"||we.content==="resumed"?v(!0):["completed","failed","cancelled","execution_finished"].includes(we.content)&&(v(!1),l(ve=>ve.map(Te=>Te.round===me?{...Te,status:we.content}:Te)))),we.type==="error"&&v(!1)}),le=Ht.on("task:log:delta",fe=>{const ge=fe.payload;ge.taskId===o&&y(we=>we+ge.text)}),ue=Ht.on("task:comment",fe=>{const ge=fe.payload;if(ge.taskId!==o)return;const we=ge.comment;m(me=>me.some(ve=>ve.id===we.id)?me:[...me,we]),(we.authorType==="agent"||we.authorId?.startsWith("agt_"))&&(I(me=>{const ve=me.filter(Te=>Te.id!==we.authorId);return ve.length===0&&O.current&&(clearTimeout(O.current),O.current=null),ve}),T(me=>{const ve=new Map(me);return ve.delete(we.authorId),ve}))});return()=>{Q(),le(),ue()}},[o]),p.useEffect(()=>{if(_.length===0)return;const Q=new Set(_.map(ue=>ue.id));return Ht.on("agent:activity_log",ue=>{const fe=ue.payload;if(!fe)return;const ge=fe.agentId;if(!Q.has(ge))return;const we=ri(fe);we&&T(me=>oi(me,ge,we))})},[_]);const M=p.useMemo(()=>{const Q=[];for(const[,le]of c)Q.push(...le);return Q.sort((le,ue)=>le.seq-ue.seq),Q},[c]),K=p.useMemo(()=>M.map(Q=>Bi(Q)),[M]),V=i.length>1,H=Q=>{const le=Q.target.files;if(le){for(const ue of Array.from(le)){if(!ue.type.startsWith("image/"))continue;const fe=new FileReader;fe.onload=()=>{L(ge=>[...ge,{type:"image",url:fe.result,name:ue.name}])},fe.readAsDataURL(ue)}Q.target.value=""}},Z=async()=>{if(!(!j.trim()&&B.length===0)){D(!0);try{let Q;B.length>0&&(Q=(await ne.uploads.upload(B.map(me=>({dataUrl:me.url,name:me.name})),"comments")).files.map(me=>({type:"image",url:me.url,name:me.name})));const le=await ne.tasks.addComment(o,j,n?.name,Q,n?.id);le.comment&&m(we=>we.some(me=>me.id===le.comment.id)?we:[...we,le.comment]),E(""),L([]);const ue=[],fe=new Set,ge=we=>{if(fe.has(we)||we===n?.id)return;fe.add(we);const me=s.find(ve=>ve.id===we);me&&ue.push({id:me.id,name:me.name,avatarUrl:me.avatarUrl})};e.assignedAgentId&&ge(e.assignedAgentId),e.createdBy?.startsWith("agt_")&&e.status!=="in_progress"&&ge(e.createdBy),ue.length>0&&(O.current&&clearTimeout(O.current),I(ue),O.current=setTimeout(()=>I([]),12e4))}catch{}D(!1)}},ee=r.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-primary z-10",children:[B.length>0&&r.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:B.map((Q,le)=>r.jsxs("div",{className:"relative group",children:[r.jsx("img",{src:Q.url,alt:Q.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),r.jsx("button",{onClick:()=>L(ue=>ue.filter((fe,ge)=>ge!==le)),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:"×"})]},le))}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"text",value:j,onChange:Q=>E(Q.target.value),onKeyDown:Q=>{Q.key==="Enter"&&!Q.shiftKey&&(Q.preventDefault(),Z())},placeholder:a("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:F,accept:"image/*",multiple:!0,onChange:H,className:"hidden"}),r.jsx("button",{onClick:()=>F.current?.click(),className:"px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-fg-secondary hover:text-fg-primary text-sm",title:a("work:task.attachImage"),children:"📎"}),r.jsx("button",{onClick:()=>{Z()},disabled:C||!j.trim()&&B.length===0,className:"px-3 py-1.5 bg-blue-600 hover:bg-blue-500 rounded-lg text-white text-xs disabled:opacity-50",children:a("common:send")})]})]});if(b)return r.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-fg-tertiary",children:a("work:task.loadingLogs")});if(i.length===0&&!g){const Q=e.assignedAgentId?s.find(je=>je.id===e.assignedAgentId):void 0,le=z.length>0,ue=Q&&Q.currentTaskId&&Q.currentTaskId!==e.id,fe=e.status==="pending",ge=e.status==="in_progress",we=!e.assignedAgentId;let me="📋",ve=a("work:task.emptyLogs.default"),Te=a("work:task.emptyLogs.defaultHint");return we?(me="👤",ve=a("work:task.emptyLogs.noAgent"),Te=a("work:task.emptyLogs.noAgentHint")):fe?(me="⏳",ve=a("work:task.emptyLogs.pending"),Te=a("work:task.emptyLogs.pendingHint")):ge&&ue?(me="🔄",ve=a("work:task.emptyLogs.agentBusy",{agent:Q?.name??e.assignedAgentId}),Te=a("work:task.emptyLogs.agentBusyHint")):ge&&(me="⏳",ve=a("work:task.emptyLogs.starting"),Te=a("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:A?r.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-fg-tertiary",children:a("work:task.loadingLogs")}):le?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"}),a("work:task.relatedSessions",{agent:Q?.name??a("work:task.agent"),count:z.length})]}),r.jsx("div",{className:"space-y-1.5",children:z.map(je=>{const Ke=!je.endedAt,Nt=je.type==="task"?"🔧":je.type==="chat"||je.type==="respond_in_session"?"💬":je.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:()=>en.navigate(Ze.TEAM,{agentId:e.assignedAgentId}),children:[r.jsx("span",{className:"text-sm shrink-0",children:Nt}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"text-xs text-fg-primary truncate",children:je.label}),r.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[new Date(je.startedAt).toLocaleString(),je.endedAt?` — ${je.totalTools} tools, ${je.totalTokens.toLocaleString()} tokens`:""]})]}),Ke&&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"}),a("work:task.sessionLive")]}),!Ke&&r.jsx("span",{className:`shrink-0 text-[10px] ${je.success?"text-fg-tertiary":"text-red-400"}`,children:je.success?"✓":"✗"}),r.jsx("span",{className:"shrink-0 text-fg-tertiary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity",children:"→"})]},je.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:me}),r.jsxs("div",{className:"text-xs",children:[ve,r.jsx("br",{}),r.jsx("span",{className:"text-fg-muted",children:Te})]})]})})}),ee]})}if(!V)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(pc,{entries:K,comments:f,agents:s,isExecuting:k}),k&&g&&r.jsx(zi,{content:g}),k&&!g&&K.length>0&&r.jsx(qi,{})]}),ee]});const oe=(Q,le)=>{const ue=Q.firstAt?new Date(Q.firstAt).getTime():0,fe=le?.firstAt?new Date(le.firstAt).getTime():1/0;return f.filter(ge=>{const we=new Date(ge.createdAt).getTime();return we>=ue&&we<fe})},de=i.length>0?f.filter(Q=>new Date(Q.createdAt).getTime()<new Date(i[0].firstAt).getTime()):[];return r.jsxs("div",{className:"flex flex-col min-h-full",children:[r.jsx("div",{ref:W}),r.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[de.length>0&&r.jsx("div",{className:"space-y-0.5",children:de.map(Q=>r.jsx(Do,{comment:Q,agents:s},Q.id))}),i.map((Q,le)=>{const ue=w.has(Q.round),fe=Q.round===i[i.length-1].round,ge=c.get(Q.round),we=h.has(Q.round),me=oe(Q,i[le+1]),ve=Q.status==="completed"||Q.status==="execution_finished"?"✅":Q.status==="failed"?"❌":Q.status==="cancelled"?"⏹":"🔄",Te=Q.lastAt&&Q.firstAt?Math.max(0,new Date(Q.lastAt).getTime()-new Date(Q.firstAt).getTime()):0,je=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:()=>P(Q.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:ve}),r.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:a("work:task.roundHeader",{n:Q.round})}),me.length>0&&r.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",me.length]}),fe&&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:a("work:task.toolCount",{count:Q.toolCount})}),je&&r.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:je}),r.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${ue?"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"})})]})]}),ue&&r.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[we&&r.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:a("work:task.loadingRound",{n:Q.round})}),ge&&r.jsx(pc,{entries:ge.map(Ke=>Bi(Ke)),comments:me,agents:s,isExecuting:fe&&k}),fe&&k&&g&&r.jsx(zi,{content:g}),fe&&k&&!g&&!we&&r.jsx(qi,{})]})]},Q.round)}),_.length>0&&r.jsx("div",{className:"flex flex-col gap-1.5 mt-2",children:_.map(Q=>{const le=q.get(Q.id)??[];return r.jsxs("div",{className:"px-3 py-2 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>en.navigate(Ze.TEAM,{agentId:Q.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(Ea,{name:Q.name,avatarUrl:Q.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:Q.name}),le.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:"→"})]}),le.length>0&&r.jsx("div",{className:"ml-9 mt-1",children:r.jsx(ai,{entries:le})})]},Q.id)})})]}),ee]})}const gc=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 Jr(e){return e==null?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function lb({filePath:e,onClose:t,onOpenExternal:n}){const{t:s}=ze(["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),ne.files.preview(i).then(C=>c(C)).catch(C=>h(String(C))).finally(()=>f(!1))},[i]);const y=C=>a(D=>[...D,C]),k=()=>a(C=>C.length>1?C.slice(0,-1):C),v=o.length>1,b=C=>{ne.files.reveal(C).catch(()=>{})},x=()=>{navigator.clipboard?.writeText(i).then(()=>{g(!0),setTimeout(()=>g(!1),1500)}).catch(()=>{})},w=C=>{C.isDirectory||gc.has(C.ext)?y(C.path):b(C.path)},N=i.split("/").pop()??i,j=l?.type==="directory",E=(C,D)=>{if(D)return"📁";const _=[".md",".markdown"],I=[".png",".jpg",".jpeg",".gif",".webp",".svg"];return _.includes(C)?"📝":I.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:[v&&r.jsx("button",{onClick:k,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:N}),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():b(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:Jr(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&&!gc.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(Tf,{data:{format:(l.extension||"").replace(/^\./,"")||"pdf",streamUrl:l.streamUrl||(l.path?ne.files.streamUrl(l.path):ne.files.streamUrl(i)),name:l.name,size:l.size},reference:l.path||i,onFallback:()=>b(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?ne.files.streamUrl(l.path):ne.files.streamUrl(i)),className:"w-full"}),r.jsxs("span",{className:"text-xs text-fg-tertiary",children:[l.name,l.size!=null?` · ${Jr(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?ne.files.streamUrl(l.path):ne.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?` · ${Jr(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?` · ${Jr(l.size)}`:""]}),r.jsx("button",{onClick:()=>b(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(Of,{content:l.content,format:l.type==="text"?"text":l.type,className:"text-sm text-fg-secondary leading-relaxed"})})]})]})})}function xc({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}=ze(["work","common"]),g=p.useMemo(()=>Wu(m),[m]),[y,k]=p.useState([]),[v,b]=p.useState(""),[x,w]=p.useState(!1),[N,j]=p.useState(!1),[E,C]=p.useState(null),[D,_]=p.useState(null),[I,O]=p.useState(!1),[q,T]=p.useState(!1),[B,L]=p.useState(!1),[z,R]=p.useState(null),[A,$]=p.useState(!1),[F,W]=p.useState(!1),[X,P]=p.useState("details"),M=p.useRef(null),[K,V]=p.useState("none"),[H,Z]=p.useState(1),[ee,oe]=p.useState([]),de=p.useCallback(async()=>{try{const{results:U}=await ne.deliverables.search({taskId:e.id,limit:200});oe(U.filter(pe=>pe.status!=="outdated"))}catch{}},[e.id]),Q=p.useCallback(U=>{P(U),U==="deliverables"&&de(),requestAnimationFrame(()=>{M.current?.scrollTo({top:0,behavior:"instant"})})},[de]),le=p.useMemo(()=>[{id:"details"},{id:"logs"},{id:"deliverables"},{id:"history"}],[]),ue=Ef(le,X,Q);p.useEffect(()=>{const U=M.current;if(!U)return;const pe=()=>{const{scrollTop:Be,scrollHeight:Ie,clientHeight:vt}=U;if(!(Ie>vt+50)){V("none");return}const es=Be<30,An=Be+vt>=Ie-30;V(es?"top":An?"bottom":"middle")};pe(),U.addEventListener("scroll",pe,{passive:!0});const De=new ResizeObserver(pe);return De.observe(U),()=>{U.removeEventListener("scroll",pe),De.disconnect()}},[X]),p.useEffect(()=>{if(!d)return;P("details");const U=setTimeout(()=>{const pe=M.current;pe&&pe.scrollTo({top:pe.scrollHeight,behavior:"smooth"}),h?.()},300);return()=>clearTimeout(U)},[d,h]);const[fe,ge]=p.useState(null),[we,me]=p.useState(!1),[ve,Te]=p.useState(null),[je,Ke]=p.useState(!1),[Nt,wt]=p.useState(e.description),ce=p.useRef(null),xe=p.useRef(null),be=p.useRef(80);p.useEffect(()=>{if(je&&xe.current){const U=xe.current;U.style.height="auto",U.style.height=Math.max(U.scrollHeight,be.current)+"px",U.focus()}},[je]);const[at,Ye]=p.useState(!1),[Oe,kt]=p.useState("");p.useEffect(()=>{de()},[de,e.updatedAt]),p.useEffect(()=>{const U=["created","updated","removed"].map(pe=>Ht.on(`deliverable:${pe}`,De=>{const Be=De.payload;!Be||Be.taskId!==e.id||de()}));return()=>{U.forEach(pe=>pe())}},[e.id,de]);const[Et,Tt]=p.useState(!1),te=hr(),Ae=20,Ue=p.useCallback(async()=>{try{const U=await ne.tasks.listSubtasks(e.id);k(U.subtasks)}catch{}},[e.id]);p.useEffect(()=>{Ue()},[Ue,e.updatedAt]);const $e=async U=>{if(!A){$(!0);try{await U(),l(),await Ue()}catch(pe){ge(String(pe).replace("Error: ",""))}finally{$(!1)}}},it=U=>$e(()=>ne.tasks.update(e.id,{priority:U})),Qe=U=>$e(()=>ne.tasks.assign(e.id,U||null)),Pe=U=>$e(()=>ne.tasks.update(e.id,{projectId:U||null})),qe=async()=>{if(!A){$(!0);try{await ne.tasks.pause(e.id),l()}finally{$(!1)}}},Je=U=>{if(U instanceof Nc){if(U.code==="TASK_BLOCKED"){const pe=U.data?.dependencyTitles??[];return pe.length?m("work:task.errorBlockedDeps",{deps:pe.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: ","")},G=async()=>{if(!A){$(!0),ge(null),Q("logs");try{await ne.tasks.resume(e.id),l()}catch(U){ge(Je(U))}finally{$(!1)}}},ae=async()=>{v.trim()&&(await ne.tasks.createSubtask(e.id,v.trim()),b(""),w(!1),Ue(),l())},ye=async U=>{U.status==="completed"||U.status==="cancelled"?await ne.tasks.cancelSubtask(e.id,U.id):await ne.tasks.completeSubtask(e.id,U.id),Ue(),l()},Se=async U=>{await ne.tasks.deleteSubtask(e.id,U.id),C(null),Ue(),l()},re=async()=>{if(!A){$(!0);try{await ne.tasks.updateStatus(e.id,"in_progress"),l()}finally{$(!1)}}},ke=async()=>{if(!A){$(!0),ge(null),Q("logs");try{await ne.tasks.retry(e.id),l()}catch(U){ge(Je(U))}finally{$(!1)}}},_e=async()=>{if(!A){$(!0),ge(null),Q("logs");try{await ne.tasks.runNow(e.id),l()}catch(U){ge(Je(U)),l()}finally{$(!1)}}},It=p.useRef(l);It.current=l,p.useEffect(()=>Ht.on("task:update",pe=>{pe.payload.taskId===e.id&&(Ue(),de(),It.current())}),[e.id,Ue,de]);const Mt=y.filter(U=>U.status==="completed").length,ft=y.filter(U=>U.status==="cancelled").length,Ot=Mt+ft,Re=e.status==="in_progress",ct=e.status==="blocked",St=ct&&(!e.blockedBy||e.blockedBy.length===0||e.blockedBy.every(U=>{const pe=o.find(De=>De.id===U);return pe&&pe.status==="completed"})),sn=e.status==="completed",dt=e.status==="failed",Ve=e.status==="rejected",Xe=e.status==="cancelled",He=e.status==="archived",tt=sn||dt||Ve||Xe||He,xt=e.taskType==="scheduled"&&!!e.scheduleConfig,ht=xt&&!!e.scheduleConfig?.paused,Dt=(()=>{const U=n.find(pe=>pe.id===e.projectId);return U&&U.name!=="default"?U:void 0})(),Ct=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 ${te?"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:[te&&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," ",(()=>{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:e.status.replace(/_/g," ")})})(),St&&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(Tc,{onClick:()=>W(!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(Fu,{kind:"task",entity:e,agents:t,users:a,projects:n,onClose:()=>W(!1)}),r.jsxs("div",{className:"flex gap-1 px-6 pt-2 pb-0 shrink-0",children:[r.jsx("button",{onClick:()=>Q("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:()=>Q("logs"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${X==="logs"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:[m("work:task.executionLogTab"),Re&&r.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),r.jsx("button",{onClick:()=>Q("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=ee.filter(pe=>typeof pe.reference=="string"&&pe.reference.length>0).length;return U>0?m("work:task.deliverablesCount",{count:U}):m("work:task.deliverables")})()}),r.jsx("button",{onClick:()=>Q("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:ue.onTouchStart,onTouchEnd:ue.onTouchEnd,children:[r.jsxs("div",{className:X==="logs"?"min-w-0 min-h-full":"hidden",children:[fe&&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")})," ",fe]}),r.jsx(ib,{task:e,isRunning:e.status==="in_progress",authUser:c,agents:t})]}),r.jsxs("div",{className:X==="details"?"":"hidden",children:[r.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:je?r.jsx("textarea",{ref:xe,value:Nt,onChange:U=>{wt(U.target.value);const pe=U.target;pe.style.height="auto",pe.style.height=pe.scrollHeight+"px"},onBlur:()=>{Nt!==e.description&&$e(()=>ne.tasks.update(e.id,{description:Nt})),Ke(!1)},onKeyDown:U=>{U.key==="Escape"&&(U.preventDefault(),wt(e.description),Ke(!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:ce,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]")||(be.current=Math.max(ce.current?.offsetHeight??80,60),wt(e.description),Ke(!0))},role:"button",tabIndex:0,onKeyDown:U=>U.key==="Enter"&&(wt(e.description),Ke(!0)),children:e.description?r.jsxs("div",{children:[r.jsx("div",{className:te&&!Et?"line-clamp-3":"",children:r.jsx(rr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),te&&e.description.length>150&&r.jsx("button",{onClick:U=>{U.stopPropagation(),Tt(!Et)},className:"text-[11px] text-brand-500 mt-1 font-medium",children:m(Et?"work:task.collapse":"common:showMore")})]}):r.jsx("p",{className:"text-sm text-fg-tertiary italic",children:m("work:task.noDescription")})})}),(Dt||Ct)&&r.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[Dt&&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(Dt.id):void 0,role:f?"button":void 0,tabIndex:f?0:void 0,onKeyDown:f?U=>U.key==="Enter"&&f(Dt.id):void 0,children:[r.jsx("span",{className:"text-[9px] text-brand-500/60",children:m("work:task.projectLabel")}),Dt.name]}),Ct&&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(Ct):void 0,role:u?"button":void 0,tabIndex:u?0:void 0,onKeyDown:u?U=>U.key==="Enter"&&u(Ct):void 0,children:[r.jsx("span",{className:"text-[9px] text-brand-500/60",children:m("work:task.requirementLabel")}),Ct.title.length>40?Ct.title.slice(0,40)+"…":Ct.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 pe=o.find(Be=>Be.id===U),De=pe&&(pe.status==="completed"||pe.status==="cancelled");return r.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${De?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[r.jsx("span",{className:"text-[9px]",children:De?"✓":"⏳"}),r.jsx("span",{className:`font-mono ${De?"line-through opacity-60":""}`,children:pe?pe.title.slice(0,30):U.slice(-8)}),!tt&&r.jsx("button",{onClick:async()=>{const Be=(e.blockedBy??[]).filter(Ie=>Ie!==U);await ne.tasks.update(e.id,{blockedBy:Be}),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")}),St&&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")})]}),!tt&&r.jsx(X0,{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 pe=[...e.blockedBy??[],U];await ne.tasks.update(e.id,{blockedBy:pe}),l()}})]}),r.jsx("div",{className:"px-6 py-4 border-b border-border-default/60",children:r.jsxs("div",{className:Xd,children:[r.jsx("label",{className:st,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=>{Pe(U)},placeholder:m("work:task.noProject"),noMatchesText:m("work:task.noMatches")}),r.jsx("label",{className:st,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=>$e(()=>ne.tasks.update(e.id,{requirementId:U||null})),placeholder:m("work:task.noRequirement"),noMatchesText:m("work:task.noMatches")}),r.jsx("label",{className:st,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=>{Qe(U)},placeholder:m("work:task.unassigned"),noMatchesText:m("work:task.noMatches")}),r.jsx("label",{className:st,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 pe=U.startsWith("human:"),De=U.replace(/^(human|agent):/,"");(De!==e.reviewerId||(pe?"human":"agent")!==(e.reviewerType??"agent"))&&$e(()=>ne.tasks.update(e.id,{reviewerId:De,reviewerType:pe?"human":"agent"}))},placeholder:m("work:task.selectReviewer"),noMatchesText:m("work:task.noMatches")}),r.jsx("label",{className:st,children:m("work:task.priority")}),r.jsx(xo,{value:e.priority,onChange:U=>{it(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:Rs(e.createdBy,t,a)??e.createdBy})}),e.updatedBy&&r.jsx("span",{children:m("work:task.updatedBy",{name:Rs(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")," ",y.length>0&&r.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal normal-case",children:[m("work:task.subtasksProgress",{done:Mt,total:y.length-ft}),ft>0?` · ${ft} cancelled`:""]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[Ot>0&&r.jsx("button",{onClick:()=>j(U=>!U),className:`text-[10px] px-2 py-0.5 rounded-full border transition-colors ${N?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-tertiary border-border-default hover:text-fg-secondary"}`,children:N?m("work:task.hideCompleted"):m("work:task.showCompleted",{count:Ot})}),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=N?y:y.filter(pe=>pe.status!=="completed"&&pe.status!=="cancelled");return U.length>0?r.jsx("div",{className:"space-y-1.5 mb-3",children:U.map(pe=>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 ${pe.status==="cancelled"?"opacity-50":""}`,children:[r.jsxs("button",{onClick:()=>{ye(pe)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${pe.status==="completed"?"bg-green-600 border-green-600 text-white":pe.status==="cancelled"?"bg-gray-500 border-gray-500 text-white":"border-gray-600 hover:border-brand-500"}`,children:[pe.status==="completed"&&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"})}),pe.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 ${pe.status==="completed"?"line-through text-fg-tertiary":pe.status==="cancelled"?"line-through text-fg-muted":"text-fg-secondary"}`,children:pe.title}),r.jsx("button",{onClick:()=>C(pe),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},pe.id))}):null})(),y.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:v,onChange:U=>b(U.target.value),onKeyDown:U=>{U.key==="Enter"&&ae(),U.key==="Escape"&&(w(!1),b(""))},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:()=>{ae()},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg",children:m("work:task.add")}),r.jsx("button",{onClick:()=>{w(!1),b("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:m("common:cancel")})]}),(()=>{const U=ee.filter(Be=>typeof Be.reference=="string"&&Be.reference.length>0);if(U.length===0)return null;const pe={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},De=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:()=>Q("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:De.map(Be=>{const Ie=/^https?:\/\//i.test(Be.reference),vt=Ie?Be.summary||Be.reference:Be.reference.split("/").pop()??Be.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 ${pe[Be.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Be.type}),r.jsxs("div",{className:"flex-1 min-w-0",children:[Ie?r.jsxs("a",{href:Be.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:Be.reference,children:[vt," ",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:()=>Te(Be.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Be.reference,children:vt}),Be.summary&&!Ie&&r.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Be.summary}),r.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Be.reference})]})]},Be.id)})})]})})(),r.jsx(ab,{task:e,agents:t,users:a,authUser:c})]})]}),r.jsx("div",{className:X==="history"?"":"hidden",children:r.jsx(Yu,{entityType:"task",entityId:e.id})}),r.jsx("div",{className:X==="deliverables"?"px-6 py-4":"hidden",children:(()=>{const U=ee.filter(Ie=>typeof Ie.reference=="string"&&Ie.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 pe={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},De=Math.ceil(U.length/Ae),Be=U.slice((H-1)*Ae,H*Ae);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})}),De>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(Ie=>Ie-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,"/",De]}),r.jsx("button",{disabled:H>=De,onClick:()=>Z(Ie=>Ie+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:Be.map(Ie=>{const vt=/^https?:\/\//i.test(Ie.reference),Mn=vt?Ie.summary||Ie.reference:Ie.reference.split("/").pop()??Ie.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 ${pe[Ie.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Ie.type}),r.jsxs("div",{className:"flex-1 min-w-0",children:[vt?r.jsxs("a",{href:Ie.reference,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Ie.reference,children:[Mn," ",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:()=>Te(Ie.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Ie.reference,children:Mn}),Ie.summary&&!vt&&r.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Ie.summary}),r.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Ie.reference})]})]},Ie.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-white 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-white 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"})})})]}),xt&&e.scheduleConfig&&r.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${ht?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"} ${!Re&&!B&&!e.scheduleConfig.runAt?"cursor-pointer hover:border-brand-500/40 transition-colors":""}`,onClick:()=>{Re||B||e.scheduleConfig?.runAt||(R(oh(e.scheduleConfig)),L(!0))},children:[r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.jsx("span",{className:ht?"text-amber-600":"text-brand-500",children:ht?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")}),!ht&&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 pe=Math.floor(U/6e4);if(pe<60)return m("work:task.scheduleInMinutes",{count:pe});const De=Math.floor(pe/60);return De<24?m("work:task.scheduleInHoursMinutes",{h:De,m:pe%60}):m("work:task.scheduleInDaysHours",{d:Math.floor(De/24),h:De%24})})()})})]}),!Re&&!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&&z?r.jsxs("div",{className:"mt-2 pt-2 border-t border-border-default/50 space-y-2",onClick:U=>U.stopPropagation(),children:[r.jsx(Pc,{value:z,onChange:R,compact:!0}),r.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[r.jsx("button",{onClick:async()=>{await $e(()=>ne.tasks.updateSchedule(e.id,$c(z))),L(!1)},disabled:A,className:"px-3 py-1 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white 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(),pe=Math.floor(U/6e4);if(pe<1)return m("work:task.noteTimeJustNow");if(pe<60)return m("work:task.noteTimeMinutes",{count:pe});const De=Math.floor(pe/60);return De<24?m("work:task.noteTimeHours",{count:De}):m("work:task.noteTimeDays",{count:Math.floor(De/24)})})()})})]})]})]}),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(xt){me(!0);return}$e(()=>ne.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 ne.tasks.getDependentCount(e.id);_({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:()=>O(!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:()=>{$e(()=>ne.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")}),at?r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("input",{type:"text",value:Oe,onChange:U=>kt(U.target.value),onKeyDown:U=>{U.key==="Enter"&&Oe.trim()&&($e(()=>ne.tasks.revision(e.id,Oe.trim(),c?.id)),Ye(!1),kt(""))},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:()=>{$e(()=>ne.tasks.revision(e.id,Oe.trim()||m("work:task.revisionsNeededDefault"),c?.id)),Ye(!1),kt("")},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:()=>{Ye(!1),kt("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):r.jsx("button",{onClick:()=>Ye(!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")})]}),Re&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>{qe()},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:()=>{ke()},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")]})]}),ct&&r.jsx("button",{onClick:()=>{G()},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")]})}),dt&&!xt&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>{ke()},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:()=>{re()},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")]})]}),xt&&(sn||dt||Xe)&&!He&&r.jsx("button",{onClick:()=>{_e()},disabled:A,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50 flex items-center gap-1.5",children: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")]})}),xt&&!Re&&!He&&!Ve&&(ht?r.jsx("button",{onClick:()=>{$e(()=>ne.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:()=>{$e(()=>ne.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")})),(sn||dt||Ve||Xe)&&r.jsx("button",{onClick:()=>T(!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")}),sn&&!xt&&r.jsx("button",{onClick:()=>{re()},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")}),!tt&&e.status!=="pending"&&r.jsx("button",{onClick:async()=>{const{count:U}=await ne.tasks.getDependentCount(e.id);_({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(gs,{title:m("work:task.deleteSubtaskTitle",{title:E.title}),message:m("work:task.deleteSubtaskMessage"),confirmLabel:m("common:delete"),onConfirm:()=>{Se(E)},onCancel:()=>C(null)}),I&&r.jsx(gs,{title:m("work:task.rejectConfirmTitle"),message:m("work:task.rejectConfirmMessage"),confirmLabel:m("work:task.reject"),onConfirm:()=>{O(!1),$e(()=>ne.tasks.reject(e.id))},onCancel:()=>O(!1)}),q&&r.jsx(gs,{title:m("work:task.archiveConfirmTitle"),message:m(xt?"work:task.archiveScheduledConfirmMessage":"work:task.archiveConfirmMessage"),confirmLabel:m("work:task.archive"),onConfirm:()=>{T(!1),$e(()=>ne.tasks.archive(e.id))},onCancel:()=>T(!1)}),D&&D.dependentCount>0?r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>_(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:[xt&&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:D.dependentCount})]}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsxs("button",{onClick:()=>{_(null),$e(()=>ne.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:()=>{_(null),$e(()=>ne.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:D.dependentCount})})]}),r.jsx("button",{onClick:()=>_(null),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:m("work:task.keepTaskRunning")})]})]})}):D&&r.jsx(gs,{title:m("work:task.cancelTaskModalTitle"),message:m(xt?"work:task.cancelScheduledConfirmMessage":"work:task.cancelConfirmMessage"),confirmLabel:m("work:task.cancelTask"),onConfirm:()=>{_(null),$e(()=>ne.tasks.cancel(e.id))},onCancel:()=>_(null)}),ve&&r.jsx(lb,{filePath:ve,onClose:()=>Te(null),onOpenExternal:()=>{Te(null),ne.deliverables.search({taskId:e.id,limit:100}).then(({results:U})=>{const pe=U.find(De=>De.reference===ve);pe?en.navigate(Ze.DELIVERABLES,{openDeliverable:pe.id}):en.navigate(Ze.DELIVERABLES)}).catch(()=>en.navigate(Ze.DELIVERABLES))}}),we&&e.scheduleConfig&&r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>me(!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:()=>{me(!1),$e(()=>ne.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:()=>{me(!1),$e(()=>ne.tasks.approve(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:m("work:task.scheduleApproveWait")}),r.jsx("button",{onClick:()=>me(!1),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:m("common:cancel")})]})]})})]})}function cb({project:e,tasks:t,requirements:n,agents:s,onDeleteProject:o,onUpdateProject:a,onRefresh:i}){const l=p.useMemo(()=>t.filter(I=>I.projectId===e.id),[t,e.id]),c=p.useMemo(()=>n.filter(I=>I.projectId===e.id),[n,e.id]),d=p.useMemo(()=>{const I={total:l.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:c.length,reqsDone:0};for(const O of l)O.status==="completed"||O.status==="accepted"?I.completed++:O.status==="in_progress"?I.inProgress++:O.status==="review"||O.status==="revision"?I.inReview++:O.status==="blocked"?I.blocked++:O.status==="failed"?I.failed++:I.pending++;for(const O of c)O.status==="completed"&&I.reqsDone++;return I},[l,c]),h=p.useMemo(()=>new Set(l.map(I=>I.assignedAgentId).filter(Boolean)),[l]),u=p.useMemo(()=>s.filter(I=>h.has(I.id)),[s,h]),[f,m]=p.useState(!1),[g,y]=p.useState(""),[k,v]=p.useState("main"),[b,x]=p.useState(!1),[w,N]=p.useState(!1),{t:j}=ze(["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 I=>{if(I!==e.status){x(!0);try{await a({status:I}),i()}finally{x(!1)}}},D=async()=>{const I=g.trim();if(!I)return;const O=[...e.repositories??[],{url:"",localPath:I,defaultBranch:k||"main"}];await a({repositories:O}),y(""),v("main"),m(!1),i()},_=async I=>{const O=(e.repositories??[]).filter((q,T)=>T!==I);await a({repositories:O}),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(Q0,{value:e.description??"",onSave:async I=>{await a({description:I}),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(I=>r.jsxs("button",{disabled:b,onClick:()=>C(I.value),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all ${e.status===I.value?I.value==="active"?"bg-green-500/15 text-green-600 ring-1 ring-green-500/30":I.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"} ${b?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[r.jsx("div",{children:I.label}),r.jsx("div",{className:"text-[10px] opacity-70 mt-0.5",children:I.desc})]},I.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(mn,{label:j("work:project.statTotal"),value:d.total,color:"text-fg-primary"}),r.jsx(mn,{label:j("work:project.statCompleted"),value:d.completed,color:"text-green-600"}),r.jsx(mn,{label:j("work:project.statInProgress"),value:d.inProgress,color:"text-brand-500"}),r.jsx(mn,{label:j("work:project.statInReview"),value:d.inReview,color:"text-brand-500"}),r.jsx(mn,{label:j("work:project.statBlocked"),value:d.blocked,color:"text-amber-600"}),r.jsx(mn,{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(mn,{label:j("work:project.statTotal"),value:d.reqs,color:"text-fg-primary"}),r.jsx(mn,{label:j("work:project.statCompleted"),value:d.reqsDone,color:"text-green-600"}),r.jsx(mn,{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(I=>{const O=l.filter(T=>T.assignedAgentId===I.id),q=O.filter(T=>!["completed","failed","cancelled","archived"].includes(T.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 ${I.status==="working"?"bg-blue-500":I.status==="idle"?"bg-green-500":"bg-gray-500"}`}),r.jsx("span",{className:"text-xs text-fg-secondary",children:I.name}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:j("work:project.agentTaskCounts",{active:q.length,total:O.length})})]},I.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((I,O)=>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:I.url||I.localPath}),r.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:I.defaultBranch}),r.jsx("button",{onClick:()=>_(O),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"})]})})]},O)),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:I=>y(I.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:k,onChange:I=>v(I.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:D,disabled:!g.trim(),className:"px-3 py-1.5 text-xs bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:j("work:task.add")})]})]})]}),r.jsx(wx,{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:()=>N(!0),className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 hover:bg-red-500/10 rounded-lg transition-colors",children:j("work:project.deleteProject")})]}),w&&r.jsx(gs,{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:()=>{N(!1),o()},onCancel:()=>N(!1)})]})}function mn({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 lo={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed",archived:"closed"},Ku={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},db={urgent:0,high:1,medium:2,low:3},yo={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},bc={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"},ub={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 Uu(e){for(const t of bo)if(t.statuses.includes(e))return t.id;return"closed"}function yc(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 eo({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 fb({onQuickCreateReq:e,onQuickCreateTask:t}){const{t:n}=ze(["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 wc({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}=ze(["work","common"]),y=p.useMemo(()=>Wu(g),[g]),k=p.useMemo(()=>li(g),[g]),v=p.useMemo(()=>rb(g),[g]),b=e.data.status,x=e.data.priority,w=e.kind==="task"?s.get(e.data.assignedAgentId??""):void 0,N=(()=>{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 ${bc[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(eo,{value:b,options:e.kind==="task"?uc.map(E=>({value:E,label:y[E]?.label??E,cls:y[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})):fc.map(E=>({value:E,label:k[E]?.label??E,cls:k[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?hc[b]:Sa[b],onSelect:E=>{d(e,E)}})}),r.jsx("div",{onClick:E=>E.stopPropagation(),children:r.jsx(eo,{value:x,options:dc.map(E=>({value:E,label:v[E]?.label??E,cls:v[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 ${Gn[w.status]??"bg-gray-500"}`}),r.jsx("span",{className:`${mc[w.status]??"text-fg-secondary"}`,children:w.name})]}),N?.name&&r.jsx("span",{className:"text-[10px] text-brand-400/70 truncate max-w-[80px]",children:N.name}),r.jsx("span",{className:"text-[9px] text-fg-muted ml-auto",children:yc(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 ${bc[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(eo,{value:b,options:e.kind==="task"?uc.map(E=>({value:E,label:y[E]?.label??E,cls:y[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})):fc.map(E=>({value:E,label:k[E]?.label??E,cls:k[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?hc[b]:Sa[b],onSelect:E=>{d(e,E)}})}),r.jsx("div",{className:"w-[100px] shrink-0",onClick:E=>E.stopPropagation(),children:r.jsx(eo,{value:x,options:dc.map(E=>({value:E,label:v[E]?.label??E,cls:v[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 ${Gn[w.status]??"bg-gray-500"}`}),r.jsx("span",{className:`font-medium ${mc[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:N?.name?r.jsx("span",{className:"text-brand-400/70",children:N.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:yc(e.data.updatedAt??"",g)})]})}function hb({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}=ze(["work","common"]),f=hr(),[m,g]=p.useState("status"),[y,k]=p.useState(null),[v,b]=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:!A.blockedBy||A.blockedBy.length===0?!0:A.blockedBy.every($=>{const F=x.get($);return F&&F.status==="completed"}),[x]),N=p.useMemo(()=>{const A=[];for(const $ of e){const F=Uu($.status);A.push({kind:"task",data:$,group:F,groupOrder:yo[F]??5})}for(const $ of t){const F=lo[$.status]??"todo";A.push({kind:"req",data:$,group:F,groupOrder:yo[F]??5})}if(m==="status")A.sort(($,F)=>{if($.groupOrder!==F.groupOrder)return $.groupOrder-F.groupOrder;const W=new Date($.data.updatedAt??0).getTime();return new Date(F.data.updatedAt??0).getTime()-W});else{const $=F=>db[F.data.priority]??2;A.sort((F,W)=>{const X=$(F),P=$(W);return X!==P?X-P:new Date(W.data.updatedAt??0).getTime()-new Date(F.data.updatedAt??0).getTime()})}return A},[e,t,m]),j=async(A,$)=>{try{A.kind==="task"?await ne.tasks.updateStatus(A.data.id,$):await ne.requirements.updateStatus(A.data.id,$),i()}catch{}},E=async(A,$)=>{try{A.kind==="task"?await ne.tasks.update(A.data.id,{priority:$}):await ne.requirements.update(A.data.id,{priority:$}),i()}catch{}},C=(A,$)=>{k($),A.dataTransfer.effectAllowed="move",A.dataTransfer.setData("text/plain",String($)),A.currentTarget.style.opacity="0.4"},D=A=>{A.currentTarget.style.opacity="1",k(null),b(null)},_=(A,$)=>{A.preventDefault(),A.dataTransfer.dropEffect="move",v!==$&&b($)},I=async(A,$)=>{if(A.preventDefault(),b(null),y==null)return;const F=N[y];if(!F||F.group===$)return;const W=bo.find(X=>X.id===$);if(W){try{if(F.kind==="task"){if(F.data.status==="pending")return;await ne.tasks.updateStatus(F.data.id,W.dropStatus)}else{const X=Ku[$];X&&await ne.requirements.updateStatus(F.data.id,X)}i()}catch{}k(null)}},O=p.useMemo(()=>new Map(n.map(A=>[A.id,A])),[n]),q=p.useMemo(()=>new Map(s.map(A=>[A.id,A])),[s]),T=["todo","in_progress","review","done"],B=p.useMemo(()=>{const A={};for(const $ of N)A[$.group]=(A[$.group]??0)+1;return A},[N]),{rowsByGroup:L,rowIndexMap:z}=p.useMemo(()=>{const A=new Map,$=new Map;for(let F=0;F<N.length;F++){const W=N[F];$.set(W,F);const X=A.get(W.group)??[];X.push(W),A.set(W.group,X)}return{rowsByGroup:A,rowIndexMap:$}},[N]),R=p.useMemo(()=>{if(m!=="status")return null;const A=new Set(N.map(W=>W.group)),$=[],F=new Set;A.has("failed")&&($.push("failed"),F.add("failed"));for(const W of T)$.push(W),F.add(W);for(const W of N)F.has(W.group)||($.push(W.group),F.add(W.group));return $},[N,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:N.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"&&R?R.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 ${ub[A]??""} ${v===A?"ring-1 ring-brand-500/40":""}`,onDragOver:F=>_(F,A),onDragLeave:()=>b(null),onDrop:F=>{I(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(wc,{row:F,idx:z.get(F)??0,dragIdx:y,agentMap:O,projMap:q,onTaskClick:o,onReqClick:a,onRowDragStart:C,onRowDragEnd:D,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(fb,{onQuickCreateReq:d,onQuickCreateTask:h})]},A)}):N.map((A,$)=>r.jsx(wc,{row:A,idx:$,dragIdx:y,agentMap:O,projMap:q,onTaskClick:o,onReqClick:a,onRowDragStart:C,onRowDragEnd:D,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}`)),N.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 Ca(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,60)||"workflow"}function mb(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=Ca(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=Ca(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 to(e){return/[:#\[\]{}&*!|>'"%@`\n]/.test(e)||e.startsWith(" ")||e.endsWith(" ")?JSON.stringify(e):e}function pb(e,t,n){const s=[];s.push(`name: ${to(e)}`),s.push(`description: ${to(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: ${to(o.name)}`),s.push(" type: agent_task"),s.push(` role: ${to(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 gb({req:e,tasks:t,agents:n,teamId:s,onClose:o,onSaved:a}){const{t:i}=ze(["work"]),l=p.useMemo(()=>{const D={};for(const _ of n)D[_.id]=_.name;return D},[n]),c=p.useMemo(()=>mb(t,l),[t,l]),[d,h]=p.useState(()=>Ca(e.title)),[u,f]=p.useState(e.description||e.title),[m,g]=p.useState(c),[y,k]=p.useState(!1),[v,b]=p.useState(null),x=(D,_,I)=>{g(O=>O.map((q,T)=>T===D?{...q,[_]:I}:q))},w=D=>{const _=m[D]?.id;g(I=>I.filter((O,q)=>q!==D).map(O=>({...O,depends_on:O.depends_on.filter(q=>q!==_)})))},[N,j]=p.useState(!1),E=async()=>{if(d.trim()){k(!0),b(null);try{const D=pb(d.trim(),u,m);await ne.workflows.create(s,d.trim(),D),j(!0),setTimeout(()=>a(),800)}catch(D){b(String(D))}k(!1)}},C=p.useMemo(()=>[...new Set(m.map(D=>D.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:D=>D.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:D=>h(D.target.value),className:"w-full text-sm bg-surface-secondary border border-border-default/50 rounded-lg px-3 py-2 text-fg-primary focus:outline-none focus:ring-1 focus:ring-brand-500",placeholder:"content-publishing"})]}),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(D=>r.jsx("span",{className:"px-2 py-0.5 text-[10px] font-medium bg-brand-500/10 text-brand-500 rounded-full",children:D},D))})]})]}),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:D=>f(D.target.value),className:"w-full text-sm bg-surface-secondary border border-border-default/50 rounded-lg px-3 py-2 text-fg-primary focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),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((D,_)=>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:_+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:D.name,onChange:I=>x(_,"name",I.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:D.role,onChange:I=>x(_,"role",I.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")})]}),D.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"),":"]}),D.depends_on.map(I=>{const O=m.find(q=>q.id===I);return r.jsx("span",{className:"px-1.5 py-0.5 bg-surface-elevated rounded text-fg-secondary",children:O?.name??I},I)})]}),r.jsx("div",{className:"text-xs text-fg-tertiary line-clamp-2 leading-relaxed",children:D.prompt})]}),r.jsx("button",{onClick:()=>w(_),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"})})})]})},D.id))})]}),v&&r.jsx("p",{className:"text-xs text-red-500",children:v}),N&&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:y||N||!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-white text-sm rounded-lg font-medium transition-colors",children:y?i("work:task.saving","Saving..."):N?i("work:task.workflowSavedSuccess","Saved!"):i("work:task.saveWorkflow","Save Workflow")})]})]})})}function kc({teamId:e,agents:t,compact:n}){const{t:s}=ze(["work"]),o=p.useMemo(()=>e?t.find(i=>i.teamId===e&&i.agentRole==="manager"):t.find(i=>i.agentRole==="manager"),[t,e]),a=()=>{o&&en.navigate(Ze.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: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-white 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 xb({teamId:e,defaultTeamId:t,projectId:n,agents:s,users:o,projects:a,onViewRunTasks:i}){const{t:l}=ze(["work"]),[c,d]=p.useState([]),[h,u]=p.useState({}),[f,m]=p.useState(!1),[g,y]=p.useState(null),[k,v]=p.useState({}),[b,x]=p.useState(!1),[w,N]=p.useState(null),[j,E]=p.useState([]),[C,D]=p.useState(()=>{try{const G=localStorage.getItem(nc);if(G)return G===sc?null:G}catch{}return t??null}),[_,I]=p.useState(()=>P0(G=>{try{return localStorage.getItem(G)}catch{return null}})),[O,q]=p.useState({}),[T,B]=p.useState({}),[L,z]=p.useState({}),[R,A]=p.useState({}),[$,F]=p.useState(null),[W,X]=p.useState(null),[P,M]=p.useState(null),[K,V]=p.useState(null),[H,Z]=p.useState(null),[ee,oe]=p.useState(null),[de,Q]=p.useState([]),[le,ue]=p.useState({}),[fe,ge]=p.useState(null),[we,me]=p.useState({}),ve=e??C,Te=G=>{if(G!==C){D(G),d([]),u({});try{localStorage.setItem(nc,G??sc)}catch{}}};p.useEffect(()=>{e||ne.teams.list().then(({teams:G})=>{E(G.map(ae=>({id:ae.id,name:ae.name})))}).catch(()=>{})},[e]),p.useMemo(()=>{const G={};for(const ae of s)G[ae.id]=ae.name;return G},[s]);const je=p.useCallback(async()=>{const G=ve?[ve]:j.map(ae=>ae.id);if(G.length!==0){m(!0);try{const ae=[],ye={},Se={};await Promise.all(G.map(async re=>{try{const{workflows:ke}=await ne.workflows.list(re);for(const _e of ke)Se[_e.name]=re;ae.push(...ke),await Promise.all(ke.map(async _e=>{try{const{runs:It}=await ne.workflows.listRuns(re,_e.name,5);ye[_e.name]=It}catch{}}))}catch{}})),d(ae),u(ye),me(Se)}catch{}m(!1)}},[ve,j]);p.useEffect(()=>{je()},[je]);const Ke=G=>ve??we[G],Nt=p.useCallback(G=>{I(G),B0(G,(ae,ye)=>{try{localStorage.setItem(ae,ye)}catch{}})},[]),wt=G=>{const ae=new Set(_);ae.has(G)?ae.delete(G):ae.add(G),Nt(ae)},ce=G=>B(ae=>({...ae,[G]:"idle"}));p.useEffect(()=>{for(const G of _){if(O[G]||T[G]==="loading"||T[G]==="error")continue;const ae=Ke(G);ae&&(B(ye=>({...ye,[G]:"loading"})),ne.workflows.get(ae,G).then(({template:ye,yaml:Se})=>{q(re=>({...re,[G]:{...ye,yaml:Se}})),B(re=>({...re,[G]:"ready"}))}).catch(()=>B(ye=>({...ye,[G]:"error"}))))}},[_,O,T,ve,we]);const xe=p.useRef(new Set),be=p.useCallback(async G=>{if(!(!G.requirementId||xe.current.has(G.id))){xe.current.add(G.id),A(ae=>({...ae,[G.id]:!0}));try{const{tasks:ae}=await ne.tasks.list({requirementId:G.requirementId,pageSize:200}),ye=new Set(G.taskIds),Se=ye.size>0?ae.filter(re=>ye.has(re.id)):ae;z(re=>({...re,[G.id]:Se.map(ke=>({id:ke.id,title:ke.title,status:ke.status,workflowStepId:ke.workflowStepId,workflowRunId:ke.workflowRunId}))}))}catch{z(ae=>({...ae,[G.id]:[]}))}finally{xe.current.delete(G.id),A(ae=>({...ae,[G.id]:!1}))}}},[]);p.useEffect(()=>{for(const G of c){const ae=(h[G.name]??[])[0];ae&&L[ae.id]===void 0&&!R[ae.id]&&be(ae)}},[c,h,L,R,be]);const at=p.useMemo(()=>{const G=[];for(const ae of Object.values(h))for(const ye of ae)ti(ye.status)&&G.push(ye.id);return G.sort().join(",")},[h]);p.useEffect(()=>{if(!at)return;const G=window.setInterval(()=>{document.hidden||je()},4e3);return()=>window.clearInterval(G)},[at,je]);const Ye=async(G,ae)=>{const ye=O[ae.name]?.yaml;if(M({mode:G,workflow:ae,yaml:ye,yamlLoading:G!=="delete"&&!ye,error:null}),G==="delete"||ye)return;const Se=Ke(ae.name);if(!Se){M(re=>re&&{...re,yamlLoading:!1,error:l("work:task.workflowNoTeam","无法确定此工作流所属的团队")});return}try{const{template:re,yaml:ke}=await ne.workflows.get(Se,ae.name);q(_e=>({..._e,[ae.name]:{...re,yaml:ke}})),B(_e=>({..._e,[ae.name]:"ready"})),M(_e=>_e&&_e.workflow.name===ae.name?{..._e,yaml:ke,yamlLoading:!1}:_e)}catch(re){M(ke=>ke&&{...ke,yamlLoading:!1,error:re instanceof Error?re.message:String(re)})}},Oe=async({name:G,yaml:ae})=>{if(!P)return;const ye=Ke(P.workflow.name);if(!ye){M(Se=>Se&&{...Se,error:l("work:task.workflowNoTeam","无法确定此工作流所属的团队")});return}M(Se=>Se&&{...Se,busy:!0,error:null});try{if(P.mode==="edit")await ne.workflows.update(ye,P.workflow.name,ae??"");else if(P.mode==="duplicate"){const re=G??"",ke=z0(ae??"",re,Xl,Zl);await ne.workflows.create(ye,re,ke)}else await ne.workflows.remove(ye,P.workflow.name);const Se=P.workflow.name;M(null),q(re=>{const ke={...re};return delete ke[Se],ke}),B(re=>({...re,[Se]:"idle"})),zt(),await je()}catch(Se){M(re=>re&&{...re,busy:!1,error:Se instanceof Error?Se.message:String(Se)})}},kt=G=>{const ae={};for(const ke of G.params??[])ke.default&&(ae[ke.name]=ke.default);v(ae),N(null),Q([]),ue({});const ye=localStorage.getItem(`markus_wf_project_${G.name}`)??localStorage.getItem("markus_wf_project_last"),Se=ye&&a.some(ke=>ke.id===ye)?ye:null;ge(n??Se??a[0]?.id??null),y(G);const re=Ke(G.name);re&&ne.workflows.roles(re,G.name).then(({roles:ke})=>Q(ke)).catch(()=>{})},Et=async()=>{const G=fe??a[0]?.id,ae=g?Ke(g.name):void 0;if(!g||!ae||!G){N(G?l("work:task.workflowNoTeam","Cannot determine team for this workflow"):l("work:task.workflowNoProject","Please select a project"));return}x(!0),N(null);try{let ye;if(de.length>0){ye={};for(const Se of de)ye[Se.role]=le[Se.role]??Se.recommended??""}await ne.workflows.startRun(ae,g.name,G,k,ye),localStorage.setItem(`markus_wf_project_${g.name}`,G),localStorage.setItem("markus_wf_project_last",G),y(null),je()}catch(ye){N(String(ye))}x(!1)};if(!ve&&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 Tt=async G=>{V(G),Z(null);try{await ne.workflows.cancelRun(G),je()}catch{}V(null)},te=async G=>{oe(G.id);try{G.status==="running"?await ne.workflows.pauseRun(G.id):G.status==="paused"&&await ne.workflows.resumeRun(G.id),je()}catch{}oe(null)},Ae=G=>{G.requirementId&&i&&i(G.requirementId)},Ue=g&&(g.params??[]).some(G=>G.required&&!k[G.name]?.trim()),$e=G=>{en.navigate(Ze.WORK,{openTask:G})},it=async(G,ae,ye)=>{const Se=Ke(G);if(!Se)throw new Error(l("work:task.workflowNoTeam","无法确定此工作流所属的团队"));let re=O[G]?.yaml;if(!re&&(re=(await ne.workflows.get(Se,G)).yaml,!re))throw new Error(l("work:task.workflowNoYaml","模板缺少原始 YAML,无法编辑"));const ke=Xl(re),_e=ke?.steps?.find(ft=>ft?.id===ae);if(!ke||!_e)throw new Error(`找不到步骤 ${ae}`);ye.name!==void 0&&(_e.name=ye.name),ye.role!==void 0&&(_e.role=ye.role),ye.prompt!==void 0&&(_e.prompt=ye.prompt),await ne.workflows.update(Se,G,Zl(ke)),zt();const{template:It,yaml:Mt}=await ne.workflows.get(Se,G);q(ft=>({...ft,[G]:{...It,yaml:Mt}})),B(ft=>({...ft,[G]:"ready"}))},Qe=G=>X(G),Pe=G=>G.displayName||G.name,qe=G=>`@[${G.displayName||G.name}](workflow:${G.name})`,Je=G=>{const ae=Ke(G.name),ye=ae?s.find(Se=>Se.teamId===ae&&Se.agentRole==="manager"):void 0;return Ic(ye?.id,s,o)};return r.jsxs("div",{className:"flex-1 min-h-0 overflow-auto px-4 py-5",children:[!e&&j.length>0&&r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-4",children:[r.jsx("button",{onClick:()=>Te(null),className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${C===null?"bg-brand-600 text-white":"bg-surface-secondary border border-border-default/50 text-fg-secondary hover:text-fg-primary hover:border-border-default"}`,children:l("work:task.all","All")}),j.map(G=>r.jsx("button",{onClick:()=>Te(G.id),className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${C===G.id?"bg-brand-600 text-white":"bg-surface-secondary border border-border-default/50 text-fg-secondary hover:text-fg-primary hover:border-border-default"}`,children:G.name},G.id))]}),c.length===0&&!f?r.jsx("div",{className:"flex-1 flex items-center justify-center px-4",children:r.jsx(kc,{teamId:ve,agents:s})}):r.jsxs("div",{className:"grid gap-4 max-w-4xl",children:[c.map(G=>{const ae=h[G.name]??[],ye=ae[0],Se=re=>{const ke=ye?.roleMapping?.[re];return ke?s.find(_e=>_e.id===ke)?.name:void 0};return r.jsx(V0,{workflow:G,detail:O[G.name],detailState:T[G.name]??"idle",onRetryDetail:()=>ce(G.name),expanded:_.has(G.name),onToggle:()=>wt(G.name),runs:ae,runTasks:L,onRun:()=>kt(G),onOpenRun:re=>{F(re),be(re)},onSaveStep:(re,ke)=>it(G.name,re,ke),roleAgentName:Se,onSendToAgent:()=>Qe(G),onEdit:()=>{Ye("edit",G)},onDuplicate:()=>{Ye("duplicate",G)},onDelete:()=>{Ye("delete",G)}},G.name)}),r.jsx(kc,{teamId:ve,agents:s,compact:!0})]}),$&&r.jsx(K0,{workflow:c.find(G=>G.name===$.workflowName)??{name:$.workflowName,displayName:$.workflowName,description:"",version:"",roles:[],hasSchedule:!1,stepCount:0},run:$,detail:O[$.workflowName],tasks:L[$.id],tasksLoading:R[$.id],onClose:()=>F(null),onPauseResume:()=>{te($)},onCancel:()=>Z($.id),onViewTasks:()=>{Ae($),F(null)},pausing:ee===$.id,onOpenTask:G=>{F(null),$e(G)},roleAgentName:G=>{const ae=$.roleMapping?.[G];return ae?s.find(ye=>ye.id===ae)?.name:void 0}}),P&&r.jsx(U0,{mode:P.mode,workflow:P.workflow,yaml:P.yaml,yamlLoading:P.yamlLoading,busy:P.busy,error:P.error,onClose:()=>M(null),onSubmit:Oe}),W&&r.jsx(Ec,{chipLabel:Pe(W),chipContent:qe(W),agents:s,users:o,defaultTarget:Je(W),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:()=>y(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(ae=>({value:ae,label:ae}))],value:k[G.name]??"",onChange:ae=>v(ye=>({...ye,[G.name]:ae})),placeholder:"—",className:"w-full"}):r.jsx("textarea",{value:k[G.name]??"",onChange:ae=>{v(re=>({...re,[G.name]:ae.target.value}));const ye=ae.target;ye.style.height="auto";const Se=parseFloat(getComputedStyle(ye).lineHeight)||18;ye.style.height=Math.min(ye.scrollHeight,Se*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))}),de.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:de.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(ae=>({value:ae.agentId,label:ae.agentName+(ae.agentId===G.recommended?" ★":"")})),value:le[G.role]??G.recommended??"",onChange:ae=>ue(ye=>({...ye,[G.role]:ae})),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:fe??"",onChange:G=>{const ae=G||null;ge(ae),N(null),ae&&localStorage.setItem("markus_wf_project_last",ae)},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:()=>y(null),className:"btn-secondary text-xs px-4 py-1.5",children:l("work:task.workflowCancel","Cancel")}),r.jsx("button",{onClick:Et,disabled:b||!!Ue,className:"btn-primary text-xs px-4 py-1.5",children:b?l("work:task.workflowStarting","Starting..."):l("work:task.workflowStartRun","Start Run")})]})]})}),H&&(()=>{const G=Object.values(h).flat().find(ke=>ke.id===H),ae=G?L[G.id]:void 0,ye=G?.taskIds.length??0,Se=new Set(["completed","archived","cancelled","rejected","failed"]),re=ae?ae.filter(ke=>!Se.has(ke.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:ke=>ke.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.")}),re!==null?r.jsx("p",{className:"text-xs font-medium text-fg-primary mb-5",children:l("work:task.workflowCancelScope","将取消 {{count}} 个未完成任务(该运行共 {{total}} 个)",{count:re,total:ye})}):r.jsx("p",{className:"text-xs text-fg-tertiary mb-5",children:l("work:task.workflowCancelScopeUnknown","该运行共有 {{total}} 个任务(正在统计其中未完成的数量)",{total:ye})}),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:()=>Tt(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 Cb({authUser:e,previewMode:t,previewData:n}={}){const{t:s}=ze(["work","common"]),o=wf(Ze.WORK),a=p.useMemo(()=>bo.map(S=>({...S,label:s(`work:boardColumn.${S.id}`)})),[s]),i=p.useMemo(()=>Vu(s),[s]),l=p.useMemo(()=>li(s),[s]),c=hr(),d=kf(),h=d?.leftCollapsed??!1,u=p.useRef(null),[f,m]=p.useState(0);p.useEffect(()=>{const S=u.current;if(!S)return;const Y=new ResizeObserver(([J])=>m(J.contentRect.width));return Y.observe(S),m(S.clientWidth),()=>Y.disconnect()},[]);const[g,y]=p.useState(()=>{if(t)return!1;try{return localStorage.getItem(tc)==="1"}catch{return!1}}),k=p.useCallback(S=>{y(S);try{localStorage.setItem(tc,S?"1":"0")}catch{}},[]),v=p.useRef(h);p.useEffect(()=>{t||c||v.current!==h&&(v.current=h,y(h))},[h,t,c]);const b=vf({side:"left",defaultWidth:240,minWidth:180,maxWidth:360,storageKey:"markus_work_l1"}),x=6,w=!c&&!g?b.width+x:0,N=Math.max(0,(f||window.innerWidth)-w-x-8),j=Math.max(320,Math.round(N/2)),[E,C]=p.useState("auto"),D=Math.max(320,N-280),_=E==="auto"?Math.min(j,D):E,I=Math.max(320,Math.min(_,D)),O=p.useRef(I);O.current=I;const q=p.useRef(D);q.current=D;const T=p.useCallback(S=>{S.preventDefault();const Y=S.clientX,J=O.current,ie=Me=>{const Ce=Math.max(320,Math.min(q.current,J+(Y-Me.clientX)));C(Ce)},he=()=>{document.removeEventListener("mousemove",ie),document.removeEventListener("mouseup",he),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",ie),document.addEventListener("mouseup",he),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]),[B,L]=p.useState(!1),z=p.useRef(B);z.current=B,p.useEffect(()=>(Pi(Ze.WORK,c&&B?1:0),()=>Pi(Ze.WORK,0)),[c,B]);const[R,A]=p.useState(n?.projects??[]),[$,F]=p.useState("all"),[W,X]=p.useState(null),[P,M]=p.useState("closed"),[K,V]=p.useState("projects"),[H,Z]=p.useState(n?.board??{}),[ee,oe]=p.useState(n?.agents??[]),[de,Q]=p.useState([]),[le,ue]=p.useState(n?.users??[]),[fe,ge]=p.useState(n?.allRequirements??[]),[we,me]=p.useState(!n),[ve,Te]=p.useState(""),je=p.useCallback(()=>{$o(W??""),Dn(!0)},[W]),Ke=async S=>{if(!W){rn(S),je();return}try{const{requirement:Y}=await ne.requirements.create({title:S,description:S,priority:"medium",projectId:W});ut(s("work:task.quickAddReqDone",{title:S})),Pt(),Y&&kn(Y)}catch(Y){ut(s("work:task.errorGeneric",{message:String(Y)}))}},Nt=S=>{Ye(S),Qe(W??""),be(!0),ut(s("work:task.quickAddTaskHint"))},[wt,ce]=p.useState(!1),[xe,be]=p.useState(!1),[at,Ye]=p.useState(""),[Oe,kt]=p.useState(""),[Et,Tt]=p.useState("medium"),[te,Ae]=p.useState(""),[Ue,$e]=p.useState(""),[it,Qe]=p.useState(""),[Pe,qe]=p.useState(""),[Je,G]=p.useState([]),[ae,ye]=p.useState("standard"),[Se,re]=p.useState(()=>ua()),[ke,_e]=p.useState(""),[It,Mt]=p.useState(!1),[ft,Ot]=p.useState(null),[Re,ct]=p.useState(!1),[St,sn]=p.useState(""),[dt,Ve]=p.useState(null),[Xe,He]=p.useState(()=>n?.initialSelectedReqId&&n.allRequirements?n.allRequirements.find(S=>S.id===n.initialSelectedReqId)??null:null);p.useEffect(()=>{n?.initialSelectedReqId&&Xe&&M("item")},[]);const[tt,xt]=p.useState(new Set),[ht,Dt]=p.useState(!1),[Ct,U]=p.useState(new Set),pe=p.useRef(new Set),[De,Be]=p.useState(null),[Ie,vt]=p.useState(n?.initialBoardType??"backlog"),[Mn,es]=p.useState(null),[An,Nr]=p.useState(null),[zs,qs]=p.useState([]);p.useEffect(()=>jf(Ze.WORK,()=>Ir.current),[]),p.useEffect(()=>Nf((S,Y)=>{S===Ze.WORK&&rc.includes(Y)&&vt(Y)}),[]);const Oo=p.useRef(null),[$t,Ln]=p.useState(!1),[_n,Fs]=p.useState(null),[Hs,yn]=p.useState(!1),Rn=p.useRef(null),ts=p.useRef(null),[ns,Dn]=p.useState(!1),[On,rn]=p.useState(""),[ss,$n]=p.useState(""),[Ws,Gu]=p.useState("medium"),[Sr,$o]=p.useState(""),[rs,Pn]=p.useState(null),[ci,di]=p.useState(""),[ui,wn]=p.useState(""),[Po,fi]=p.useState(!1),[hi,os]=p.useState(""),ut=p.useCallback(S=>{Te(S),setTimeout(()=>Te(""),3e3)},[]);p.useEffect(()=>{const S=Y=>{Y.key==="Escape"&&(ft?Ot(null):Re?(ct(!1),sn("")):rs?(Pn(null),os("")):xe?(be(!1),_e("")):ns?(Dn(!1),rn(""),$n(""),wn("")):Hs?yn(!1):P!=="closed"&&(M("closed"),Ve(null),He(null),c&&z.current&&L(!1)))};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[ft,Re,rs,xe,ns,Hs,P,c]);const Wt=R.find(S=>S.id===W)??null,Xu=Wt?.teamIds?.[0]??null,Zu=p.useMemo(()=>R.filter(S=>S.status!=="archived"),[R]),mi=p.useCallback(()=>{W&&(Ve(null),He(null),M("project"),C("auto"),c&&L(!0))},[W,c]),Cr=p.useCallback(()=>{if(P==="project"){M("closed"),c&&L(!1);return}mi()},[P,mi,c]);p.useEffect(()=>{pe.current=Ct},[Ct]);const Bn=p.useCallback(async()=>{try{const{projects:S}=await ne.projects.list();A(S)}catch{}},[]),At=p.useCallback(async()=>{const S={};$==="project"&&W&&(S.projectId=W);try{const{board:Y}=await ne.tasks.board(S);Z(Y)}catch{}},[$,W]),Vs=p.useCallback(async()=>{try{const{agents:S}=await ne.agents.list();oe(S)}catch{}},[]),pi=p.useCallback(async()=>{try{const{teams:S}=await ne.teams.list();Q(S.map(Y=>({id:Y.id,name:Y.name})))}catch{}},[]),gi=p.useCallback(async()=>{try{const{users:S}=await ne.users.list(e?.orgId);ue(S)}catch{}},[e?.orgId]),Pt=p.useCallback(async()=>{try{const{requirements:S}=await ne.requirements.list({});ge(S)}catch{}},[]),xi=p.useCallback(async()=>{await Promise.all([Bn(),At(),Vs(),gi(),Pt(),pi()]),me(!1)},[Bn,At,Vs,gi,Pt,pi]);p.useEffect(()=>{t||xi()},[t,xi]),p.useEffect(()=>{!t||!n||(A(n.projects??[]),Z(n.board??{}),oe(n.agents??[]),ue(n.users??[]),ge(n.allRequirements??[]))},[t,n]);const Er=p.useCallback(S=>{V("items"),Ve(Y=>Y?.id===S.id&&P==="item"?(M("closed"),c&&z.current&&L(!1),null):(M("item"),C("auto"),c&&(L(!0),history.pushState({mobileDetail:Ze.WORK},"",window.location.hash)),S)),He(null)},[c,P]),Tr=p.useCallback(S=>{V("items"),He(Y=>Y?.id===S.id&&P==="item"?(M("closed"),c&&z.current&&L(!1),null):(M("item"),C("auto"),c&&(L(!0),history.pushState({mobileDetail:Ze.WORK},"",window.location.hash)),S)),Ve(null)},[c,P]),zn=p.useCallback(()=>{Ve(null),He(null),M("closed"),c&&z.current&&L(!1)},[c]),dn=p.useRef(dt);dn.current=dt;const un=p.useRef(Xe);un.current=Xe;const qn=p.useRef(P);qn.current=P;const as=p.useRef(K);as.current=K;const is=p.useRef(g);is.current=g;const Ir=p.useRef(Ie);Ir.current=Ie;const Qu=p.useCallback(()=>{Ve(null),un.current||(M("closed"),c&&z.current&&L(!1))},[c]);p.useEffect(()=>{if(!c)return;const S=()=>{z.current&&(L(!1),Ve(null),He(null),M("closed"))};return window.addEventListener("popstate",S),()=>window.removeEventListener("popstate",S)},[c]),p.useEffect(()=>{if(t||!o)return;At(),Vs(),Pt();const S=dn.current?12e4:45e3,Y=setInterval(()=>{At(),Vs(),Pt()},S);let J=null;const ie=()=>{J||(J=setTimeout(()=>{J=null,At()},800))};let he=null;const Me=()=>{he||(he=setTimeout(()=>{he=null,Pt()},800))},Ce=Ht.on("task:update",nt=>{zt("/taskboard"),ie();const Ee=nt?.payload;Ee?.taskId&&(Ve(lt=>{if(!lt||lt.id!==Ee.taskId)return lt;const We={};return typeof Ee.status=="string"&&(We.status=Ee.status),Array.isArray(Ee.deliverables)&&(We.deliverables=Ee.deliverables),Array.isArray(Ee.notes)&&(We.notes=Ee.notes),Ee.result!==void 0&&(We.result=Ee.result),{...lt,...We}}),dn.current?.id===Ee.taskId&&(zt("/tasks/"+Ee.taskId),ne.tasks.get(Ee.taskId).then(lt=>{lt.task&&Ve(We=>We?.id===lt.task.id?lt.task:We)}).catch(()=>{})))}),se=Ht.on("task:create",()=>{ie()}),Vt=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(nt=>Ht.on(nt,Ee=>{zt("/requirements"),Me();const lt=Ee?.payload,We=lt?.id??lt?.requirementId;We&&un.current?.id===We&&(zt("/requirements/"+We),ne.requirements.get(We).then(hn=>{hn.requirement&&He(Wn=>Wn?.id===hn.requirement.id?hn.requirement:Wn)}).catch(()=>{}))})),Bt=()=>{zt("/taskboard"),zt("/tasks"),zt("/requirements"),At(),Pt(),dn.current&&ne.tasks.get(dn.current.id).then(nt=>{nt.task&&Ve(Ee=>Ee?.id===nt.task.id?nt.task:Ee)}).catch(()=>{}),un.current&&ne.requirements.get(un.current.id).then(nt=>{nt.requirement&&He(Ee=>Ee?.id===nt.requirement.id?nt.requirement:Ee)}).catch(()=>{})};return window.addEventListener("markus:data-changed",Bt),()=>{clearInterval(Y),Ce(),se(),Vt.forEach(nt=>nt()),window.removeEventListener("markus:data-changed",Bt),J&&clearTimeout(J),he&&clearTimeout(he)}},[t,o,At,Vs,Pt]);const bi=p.useRef(H);bi.current=H;const yi=p.useRef(fe);yi.current=fe,p.useEffect(()=>{const S=dn.current;if(!S)return;const J=Object.values(H).flat().find(ie=>ie.id===S.id);J&&J.updatedAt!==S.updatedAt&&Ve(J)},[H]),p.useEffect(()=>{const S=un.current;if(!S)return;const Y=fe.find(J=>J.id===S.id);Y&&Y.updatedAt!==S.updatedAt&&He(Y)},[fe]);const on=p.useCallback(S=>{if(!S){U(new Set),X(null),F("all"),history.replaceState(null,"",Pr(Ze.WORK)),ne.tasks.board({}).then(Y=>Z(Y.board)).catch(()=>{});return}X(S),F("project"),U(new Set),history.replaceState(null,"",Pr(Ze.WORK,S)),ne.tasks.board({projectId:S}).then(Y=>Z(Y.board)).catch(()=>{})},[]),[Bo,Ks]=p.useState(!1),Us=p.useCallback((S,Y)=>{Ve(S),He(null),M("item"),V("items"),C("auto"),Y?.scrollToComments&&Ks(!0),c&&L(!0)},[c]),kn=p.useCallback((S,Y)=>{He(S),Ve(null),M("item"),V("items"),C("auto"),Y?.scrollToComments&&Ks(!0),c&&L(!0)},[c]),wi=p.useCallback(S=>{on(S.projectId),Fs(null),xt(new Set),U(new Set),Dt(!1),Ln(!0),Nr(S),qs([]),ne.tasks.list({requirementId:S.id,pageSize:200}).then(({tasks:Y})=>{Y?.length&&qs(Y)}).catch(()=>{}),kn(S),es(`req-${S.id}`),vt("dag")},[on,kn]),ls=p.useRef(null);p.useEffect(()=>{const S=ls.current||localStorage.getItem("markus_nav_openTask");if(!S)return;const J=Object.values(H).flat().find(ie=>ie.id===S);J?(ls.current=null,on(J.projectId),Us(J),localStorage.removeItem("markus_nav_openTask")):ls.current||(ls.current=S,localStorage.removeItem("markus_nav_openTask"),ne.tasks.get(S).then(ie=>{ie.task&&(ls.current=null,on(ie.task.projectId),Us(ie.task))}).catch(()=>{ls.current=null,ut(s("work:task.notFound",{id:S}))}))},[H,Us,on,o,ut,s]);const cs=p.useRef(null);p.useEffect(()=>{const S=cs.current||localStorage.getItem("markus_nav_openRequirement");if(!S)return;const Y=fe.find(J=>J.id===S);Y?(cs.current=null,on(Y.projectId),kn(Y),localStorage.removeItem("markus_nav_openRequirement")):cs.current||(cs.current=S,localStorage.removeItem("markus_nav_openRequirement"),ne.requirements.get(S).then(J=>{J.requirement&&(cs.current=null,on(J.requirement.projectId),kn(J.requirement))}).catch(()=>{cs.current=null}))},[fe,kn,on,o]);const Gt=p.useCallback((S,Y)=>{U(new Set),X(S),F("project"),V(g?"items":"projects"),Y?.keepItemDetail||(Ve(null),He(null),M(J=>J==="closed"?J:"project")),history.replaceState(null,"",Pr(Ze.WORK,S))},[g]),an=p.useCallback(S=>{U(new Set),X(null),F("all"),V(g?"items":"projects"),S?.keepItemDetail||(Ve(null),He(null),M(Y=>Y==="closed"?Y:Y==="project"?"closed":"empty")),history.replaceState(null,"",Pr(Ze.WORK))},[g]),Fn=p.useRef(!1);p.useEffect(()=>{if(Fn.current)return;const S=window.location.hash.slice(1).split("/");if(Br(S[0])===Ze.WORK&&S[1]){Fn.current=!0,Gt(S[1],{keepItemDetail:!0});return}const Y=localStorage.getItem("markus_nav_projectId");if(Y){Fn.current=!0,localStorage.removeItem("markus_nav_projectId"),Gt(Y,{keepItemDetail:!0});return}Fn.current=!0,an({keepItemDetail:!0})},[]),p.useEffect(()=>{if(!we){if(!W){Fn.current=!0,$!=="all"&&F("all");return}if(R.some(S=>S.id===W)){Fn.current=!0;return}Fn.current=!0,an({keepItemDetail:!0})}},[we,R,W,an,$]);const Ju=p.useRef(Br(window.location.hash.slice(1).split("/")[0]));p.useEffect(()=>{if(t)return;const S=()=>{const J=window.location.hash.slice(1).split("/"),ie=Br(J[0]);Ju.current=ie,ie===Ze.WORK&&(J[1]?Gt(J[1],{keepItemDetail:!0}):an({keepItemDetail:!0}))},Y=async J=>{const ie=J.detail;if(Br(ie.page)===Ze.WORK){if(ie.params?.openTask){const he=ie.params.openTask,Me=ie.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let Ce=Object.values(bi.current).flat().find(se=>se.id===he);if(!Ce)try{Ce=(await ne.tasks.get(he)).task}catch{}Ce?(on(Ce.projectId),Us(Ce,{scrollToComments:Me})):ut(s("work:task.notFound",{id:he}))}if(ie.params?.openRequirement){const he=ie.params.openRequirement,Me=ie.params.scrollToComments==="true";let Ce=yi.current.find(se=>se.id===he);if(!Ce)try{Ce=(await ne.requirements.get(he)).requirement}catch{}Ce&&(on(Ce.projectId),kn(Ce,{scrollToComments:Me}))}if(ie.params?.projectId&&Gt(ie.params.projectId),ie.params?.statusFilter){const he=ie.params.statusFilter;localStorage.removeItem("markus_nav_statusFilter"),sb.has(he)&&Ln(!0),Fs(he)}}};return window.addEventListener("markus:navigate",Y),window.addEventListener("hashchange",S),()=>{window.removeEventListener("markus:navigate",Y),window.removeEventListener("hashchange",S)}},[t]);const ef=S=>{ce(!1),ut(s("work:task.projectCreated")),A(Y=>Y.some(J=>J.id===S.id)?Y:[...Y,S]),Gt(S.id),Bn()},tf=async S=>{try{await ne.projects.delete(S),W===S&&an(),ut(s("work:task.projectDeleted")),Bn(),At()}catch(Y){ut(s("work:task.errorGeneric",{message:String(Y)}))}},ki=async()=>{if(!at||!te||!Ue||It)return;_e("");const S=Ue.startsWith("human:"),Y=Ue.replace(/^(human|agent):/,"");if(te===Y&&!S){ut(s("work:task.assignedReviewerDifferent"));return}const J=it||void 0,ie=Pe||void 0;Mt(!0);try{const{task:he}=await ne.tasks.create(at,Oe,te,Y,Et,J,Je.length>0?Je:void 0,ie,ae!=="standard"?ae:void 0,ae==="scheduled"?$c(Se):void 0,S?"human":"agent");Ye(""),kt(""),G([]),qe(""),ye("standard"),re(ua()),be(!1),At(),he&&Us(he)}catch(he){const Ce=`work:task.errorCode_${(he instanceof Nc?he.code:void 0)||"unknown"}`,se=s(Ce,{defaultValue:""});_e(se||s("work:task.errorCreatingTask",{message:he instanceof Error?he.message:String(he)}))}finally{Mt(!1)}},vi=async()=>{if(!(!St.trim()||!it))try{const{requirement:S}=await ne.requirements.create({title:St.trim(),description:St.trim(),priority:"medium",projectId:it});sn(""),ct(!1),ut(s("work:task.requirementCreated")),Pt(),S&&qe(S.id)}catch(S){_e(S instanceof Error?S.message:String(S))}},ds=S=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:S}))},ji=()=>{zt("/taskboard"),At(),dt&&(ds({taskId:dt.id}),zt("/tasks/"+dt.id),ne.tasks.get(dt.id).then(S=>{S.task&&Ve(Y=>Y?.id===S.task.id?S.task:Y)}).catch(()=>{}))},Hn=()=>{zt("/requirements"),Pt(),Xe&&(zt("/requirements/"+Xe.id),ne.requirements.get(Xe.id).then(S=>{S.requirement&&He(Y=>Y?.id===S.requirement.id?S.requirement:Y)}).catch(()=>{}))},Ni=async()=>{if(!Po){if(!On.trim()){wn(s("work:task.pleaseReqTitle"));return}if(!ss.trim()){wn(s("work:task.pleaseReqDesc"));return}if(!Sr){wn(s("work:task.pleaseReqProject"));return}wn(""),fi(!0);try{const{requirement:S}=await ne.requirements.create({title:On.trim(),description:ss.trim(),priority:Ws,projectId:Sr});ut(s("work:task.requirementCreated")),rn(""),$n(""),Dn(!1),Pt(),S&&kn(S)}catch(S){wn(S instanceof Error?S.message:String(S))}finally{fi(!1)}}},zo=async S=>{try{await ne.requirements.approve(S),ut(s("work:task.requirementApproved")),ds({requirementId:S}),Hn(),At()}catch(Y){ut(s("work:task.errorGeneric",{message:String(Y)}))}},nf=async()=>{if(rs){os("");try{await ne.requirements.reject(rs,ci),ut(s("work:task.requirementRejected")),ds({requirementId:rs}),Pn(null),di(""),os(""),Hn()}catch(S){os(S instanceof Error?S.message:String(S))}}},Si=async S=>{try{await ne.requirements.cancel(S),ut(s("work:task.requirementCancelled")),ds({requirementId:S}),Hn()}catch(Y){ut(s("work:task.errorGeneric",{message:String(Y)}))}},sf=(S,Y)=>{Rn.current=Y,ts.current=null,S.dataTransfer.effectAllowed="move",S.dataTransfer.setData("text/plain",`task:${Y.id}`),S.currentTarget.style.opacity="0.4"},rf=(S,Y)=>{ts.current=Y,Rn.current=null,S.dataTransfer.effectAllowed="move",S.dataTransfer.setData("text/plain",`req:${Y.id}`),S.currentTarget.style.opacity="0.4"},Ci=S=>{S.currentTarget.style.opacity="1",Rn.current=null,ts.current=null,Be(null)},of=(S,Y)=>{S.preventDefault(),S.dataTransfer.dropEffect="move",De!==Y&&Be(Y)},af=(S,Y)=>{const J=S.currentTarget.getBoundingClientRect(),{clientX:ie,clientY:he}=S;(ie<J.left||ie>J.right||he<J.top||he>J.bottom)&&De===Y&&Be(null)},lf=async(S,Y)=>{S.preventDefault(),Be(null);const J=Rn.current,ie=ts.current;if(J){const he=a.find(Ce=>Ce.id===Y);if(!he)return;const Me=he.dropStatus;if(J.status===Me||J.status==="pending")return;try{await ne.tasks.updateStatus(J.id,Me),At()}catch{}}else if(ie){const he=Ku[Y];if(!he||ie.status===he)return;try{await ne.requirements.updateStatus(ie.id,he),Pt()}catch{}}},Ei=S=>{xt(Y=>{const J=new Set(Y);return J.has(S)?J.delete(S):J.add(S),J})},Mr=S=>{Gt(S)},cf=new Set(["rejected","cancelled","archived"]),qo=S=>cf.has(S.status),Ys=(S,Y=!1)=>jx(S,{showClosed:$t,includeClosed:Y,statusFilter:_n,viewMode:$,selectedProjectId:W,projectFilter:Ct,agentFilter:tt,myTasksOnly:ht,currentUserId:e?.id}),df=p.useMemo(()=>{const S=new Map;for(const Y of Object.values(H))for(const J of Y)S.set(J.id,J);return S},[H]),uf=p.useMemo(()=>new Set(ee.map(S=>S.id)),[ee]),Ti=S=>S.statuses.flatMap(Y=>Ys(H[Y]??[])),fn=p.useMemo(()=>{let S=fe;return $t||(S=S.filter(Y=>!qo(Y))),$==="project"&&W&&(S=S.filter(Y=>Y.projectId===W)),Ct.size>0&&(S=S.filter(Y=>Y.projectId&&Ct.has(Y.projectId))),tt.size>0&&(S=S.filter(Y=>tt.has(Y.createdBy))),ht&&e?.id&&(S=S.filter(Y=>Y.createdBy===e.id)),S},[fe,$t,$,W,Ct,tt,ht,e?.id,uf]),Ii=p.useCallback(S=>fn.filter(Y=>lo[Y.status]===S.id),[fn]),ff=a.filter(S=>{if(S.id==="failed"||S.id==="closed"){const Y=Ti(S),J=Ii(S);return Y.length+J.length>0}return!0}),Gs=Object.values(H).flat().filter(S=>qo(S)).length+fe.filter(S=>qo(S)).length,Mi=p.useMemo(()=>{const S=new Set(["completed","failed","cancelled","archived"]),Y=Object.values(H).flat(),J=new Set;for(const ie of Y)ie.assignedAgentId&&!S.has(ie.status)&&(!W||ie.projectId===W)&&J.add(ie.assignedAgentId);return[...ee].sort((ie,he)=>{const Me=J.has(ie.id)?0:1,Ce=J.has(he.id)?0:1;return Me-Ce})},[ee,H,W]),Ar=p.useMemo(()=>{const S=new Map,Y=[];for(const ie of Mi)if(ie.teamId){const he=S.get(ie.teamId)??[];he.push(ie.id),S.set(ie.teamId,he)}else Y.push(ie);const J=[];for(const ie of Y)J.push({kind:"agent",agent:ie});for(const ie of de){const he=S.get(ie.id);he&&he.length>0&&J.push({kind:"team",id:ie.id,name:ie.name,agentIds:he})}return J},[Mi,de]);p.useMemo(()=>{const S=new Set(["completed","failed","cancelled","archived"]),Y=Object.values(H).flat(),J=new Set;for(const he of Y)he.projectId&&!S.has(he.status)&&J.add(he.projectId);return[...$t?R:R.filter(he=>he.status!=="archived")].sort((he,Me)=>{const Ce=he.status==="archived"?1:0,se=Me.status==="archived"?1:0;if(Ce!==se)return Ce-se;const jt=J.has(he.id)?0:1,Vt=J.has(Me.id)?0:1;return jt!==Vt?jt-Vt:he.name.localeCompare(Me.name)})},[R,H,$t]);const Lr=p.useMemo(()=>[...R].sort((S,Y)=>{const J=S.status==="archived"?1:0,ie=Y.status==="archived"?1:0;return J!==ie?J-ie:S.name.localeCompare(Y.name)}),[R]),_r=p.useMemo(()=>{const S={};for(const Y of Object.values(H))for(const J of Y){const ie=J.projectId??"__none__";S[ie]=(S[ie]??0)+1}return S},[H]),Rr=Object.values(_r).reduce((S,Y)=>S+Y,0),hf=W?_r[W]??0:Rr,Ai=p.useMemo(()=>{const S=Ys(Object.values(H).flat()),Y=[];if(Ie==="kanban"){for(const ie of bo){const he=ie.statuses.flatMap(se=>S.filter(jt=>jt.status===se)),Ce=[...fn.filter(se=>lo[se.status]===ie.id).map(se=>({kind:"req",data:se,time:new Date(se.updatedAt??se.createdAt).getTime()})),...he.map(se=>({kind:"task",data:se,time:new Date(se.updatedAt??se.createdAt??0).getTime()}))];Ce.sort((se,jt)=>jt.time-se.time);for(const se of Ce)se.kind==="req"?Y.push({kind:"req",data:se.data}):Y.push({kind:"task",data:se.data})}return Y}const J=[];for(const ie of S){const he=Uu(ie.status);J.push({kind:"task",data:ie,groupOrder:yo[he]??5,time:new Date(ie.updatedAt??ie.createdAt??0).getTime()})}for(const ie of fn){const he=lo[ie.status]??"todo";J.push({kind:"req",data:ie,groupOrder:yo[he]??5,time:new Date(ie.updatedAt??ie.createdAt).getTime()})}return J.sort((ie,he)=>ie.groupOrder!==he.groupOrder?ie.groupOrder-he.groupOrder:he.time-ie.time),J.map(ie=>ie.kind==="req"?{kind:"req",data:ie.data}:{kind:"task",data:ie.data})},[H,fn,Ie,$t,_n,W,Ct,tt,ht,e?.id,$]),Dr=p.useRef(Ai);Dr.current=Ai;const Li=p.useRef(Lr);Li.current=Lr;const Fo=p.useRef(W);Fo.current=W;const us=p.useCallback(S=>{S.kind==="req"?(He(S.data),Ve(null)):(Ve(S.data),He(null)),M("item"),C("auto"),V("items")},[]),_i=p.useCallback(()=>{if(qn.current==="item"||qn.current==="empty"){M("closed"),Ve(null),He(null);return}if(dn.current||un.current){M("item"),C("auto"),V("items");return}const S=Dr.current;if(S.length>0){us(S[0]);return}Ve(null),He(null),M("empty"),C("auto")},[us]);p.useEffect(()=>{if(!c)if(g){if(V("items"),qn.current==="project")if(dn.current||un.current)M("item");else{const S=Dr.current;S.length>0?us(S[0]):M("closed")}}else as.current==="items"&&qn.current==="closed"||!g&&qn.current==="closed"&&V("projects")},[g,c,us]);const Xs=d?.keyboardPane??"content",Ri=p.useRef(Xs);if(p.useEffect(()=>{if(t||c||!o)return;const S=Ri.current;Ri.current=Xs,Xs==="l1"&&(V("projects"),S!=="l1"&&is.current&&(k(!1),d?.setLeftCollapsed(!1)))},[Xs,t,c,o,k,d]),p.useEffect(()=>{if(t||c||!o)return;const S=navigator.platform.toUpperCase().includes("MAC"),Y=J=>{if(d?.keyboardPane==="l0")return;const ie=S?J.metaKey&&!J.ctrlKey:J.ctrlKey&&!J.metaKey;if(J.ctrlKey&&!J.metaKey&&J.key==="Tab"){J.preventDefault();const Ee=rc,lt=Ee.indexOf(Ir.current),We=J.shiftKey?Ee[(lt-1+Ee.length)%Ee.length]:Ee[(lt+1)%Ee.length];vt(We);return}if(ie&&!J.altKey&&!J.shiftKey){const Ee=J.key.toLowerCase();if(Ee==="j"){J.preventDefault(),Cr();return}if(Ee==="l"){J.preventDefault(),_i();return}}if(ie||J.altKey||J.ctrlKey||J.metaKey||Cf(J.target))return;const he=J.key.length===1?J.key.toLowerCase():J.key;if(he==="h"||he==="ArrowLeft"){if(is.current){J.preventDefault(),k(!1),d?.setLeftCollapsed(!1),V("projects"),d?.setKeyboardPane("l1");return}if(as.current==="items"){J.preventDefault(),V("projects"),d?.setKeyboardPane("l1");return}J.preventDefault(),d?.setL0FocusPageId(Ze.WORK),d?.setLeftCollapsed(!1),d?.setKeyboardPane("l0");return}if((he==="l"||he==="ArrowRight"||he==="Tab"&&!J.shiftKey)&&!is.current&&as.current==="projects"){J.preventDefault(),V("items"),d?.setKeyboardPane("content");return}if((he==="l"||he==="ArrowRight")&&(is.current||as.current==="items")){J.preventDefault();return}const Me=he==="j"||he==="ArrowDown"?1:he==="k"||he==="ArrowUp"?-1:0;if(!Me)return;if((is.current?"items":as.current)==="projects"){J.preventDefault(),d?.setKeyboardPane("l1");const Ee=Li.current,lt=Ee.length+1;if(Ee.length===0)return;const We=Fo.current==null?0:Ee.findIndex(fs=>fs.id===Fo.current)+1,hn=We<0?0:We,Wn=Math.max(0,Math.min(lt-1,hn+Me));if(Wn===0)an(),requestAnimationFrame(()=>{document.querySelector('[data-project-id="__all__"]')?.scrollIntoView({block:"nearest"})});else{const fs=Ee[Wn-1];Gt(fs.id),qn.current!=="closed"&&(M("project"),Ve(null),He(null)),requestAnimationFrame(()=>{document.querySelector(`[data-project-id="${fs.id}"]`)?.scrollIntoView({block:"nearest"})})}return}const se=Ir.current;if(se!=="backlog"&&se!=="kanban")return;J.preventDefault(),d?.setKeyboardPane("content");const jt=Dr.current;if(jt.length===0){M(Ee=>Ee==="closed"?"empty":Ee);return}const Vt=dn.current?.id??un.current?.id??null;let Bt=Vt?jt.findIndex(Ee=>Ee.data.id===Vt):-1;Bt<0&&(Bt=Me>0?-1:0);const nt=Math.max(0,Math.min(jt.length-1,Bt+Me));us(jt[nt]),requestAnimationFrame(()=>{document.querySelector(`[data-work-item-id="${jt[nt].data.id}"]`)?.scrollIntoView({block:"nearest"})})};return document.addEventListener("keydown",Y,!0),()=>document.removeEventListener("keydown",Y,!0)},[t,c,o,Cr,_i,Gt,an,us,k,d]),we)return r.jsx(Df,{label:s("work:task.loadingPage")});const Di=P!=="closed"||!!(dt||Xe),Or=!c&&!!(dt&&Xe)&&P==="item",Oi=c?B:Di;return r.jsxs("div",{ref:u,className:"flex-1 overflow-hidden flex bg-surface-primary",children:[!c&&r.jsx(yx,{projects:Lr,selectedProjectId:W,allSelected:$==="all"&&!W,taskCounts:_r,totalTaskCount:Rr,onSelectAll:()=>{an(),V("projects")},onSelectProject:S=>{Gt(S),V("projects")},onEditProject:S=>{Gt(S),Ve(null),He(null),M("project"),V("projects")},onCreateProject:()=>ce(!0),onCollapse:()=>{const S=!g;k(S),d?.setLeftCollapsed(S)},width:b.width,onResizeStart:b.onResizeStart,hidden:g,focused:Xs==="l1"&&K==="projects"&&!g,onActivate:()=>V("projects")}),r.jsxs("div",{"data-keyboard-pane":"content",onPointerDown:()=>V("items"),className:`${c?"flex-1 min-w-0":Or?"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:[ve&&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:ve}),c?r.jsxs("div",{className:"shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[r.jsx(Sf,{}),Wt?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:Wt.name}),r.jsx("button",{onClick:Cr,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${P==="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:R.length})}),r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx("button",{onClick:()=>ce(!0),className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:s("work:task.shortProject")}),r.jsx("button",{onClick:je,className:"px-2 py-1 text-[11px] bg-brand-600 text-white rounded-md",children:s("work:task.shortReq")}),r.jsx("button",{onClick:()=>{Qe(W??""),be(!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(S=>r.jsx("button",{onClick:()=>vt(S),className:`px-2 py-0.5 text-[10px] font-medium whitespace-nowrap transition-colors ${Ie===S?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:S==="backlog"?s("work:task.backlog"):S==="kanban"?s("work:task.kanban"):S==="dag"?s("work:task.dag"):s("work:task.workflows","Workflows")},S))}),Gs>0&&r.jsx("button",{onClick:()=>Ln(S=>!S),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:Gs})}),r.jsx("div",{className:"flex-1"}),_n&&r.jsxs("button",{onClick:()=>Fs(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.${_n==="in_progress"?"inProgress":_n}`),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"})]})]}),(Zu.length>1||ee.length>0||e?.id)&&r.jsxs("button",{onClick:()=>yn(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${tt.size>0||ht?"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:tt.size+(ht?1:0)>0?s("work:task.filterWithCount",{count:tt.size+(ht?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 S=!g;k(S),d?.setLeftCollapsed(S),V("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"})]})}),Wt?r.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1 shrink-0 min-w-0",children:[r.jsx(Z0,{value:Wt.name,onSave:async S=>{await ne.projects.update(Wt.id,{name:S}),Bn()},className:"text-sm font-semibold text-fg-primary"}),r.jsx("button",{onClick:Cr,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${P==="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:R.length})}),Gs>0&&r.jsx("button",{onClick:()=>Ln(S=>!S),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:Gs}):s("work:task.archivedCount",{count:Gs})}),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(S=>r.jsx("button",{onClick:()=>vt(S),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${Ie===S?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:S==="backlog"?s("work:task.backlog"):S==="kanban"?s("work:task.kanban"):S==="dag"?s("work:task.dag"):s("work:task.workflows","Workflows")},S))}),r.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1.5 shrink-0",children:[r.jsx("button",{onClick:()=>ce(!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:je,className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs rounded-lg font-medium transition-colors",children:s("work:task.newRequirement")}),r.jsx("button",{onClick:()=>{Qe(W??""),be(!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&&Ie!=="workflows"&&(Ar.length>0||e?.id)&&(hf>0||fn.length>0||tt.size>0||ht)&&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:()=>{xt(new Set),Dt(!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 ${tt.size>0||ht?"visible opacity-100":"invisible opacity-0"}`,children:s("work:task.clear")}),e?.id&&r.jsx("button",{type:"button",onClick:()=>Dt(S=>!S),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${ht?"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")}),Ar.map(S=>{if(S.kind==="team"){const ie=S.agentIds.every(Me=>tt.has(Me)),he=!ie&&S.agentIds.some(Me=>tt.has(Me));return r.jsxs("button",{onClick:()=>{xt(Me=>{const Ce=new Set(Me);if(ie)for(const se of S.agentIds)Ce.delete(se);else for(const se of S.agentIds)Ce.add(se);return Ce})},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${ie?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":he?"bg-brand-600/10 text-brand-400 ring-1 ring-brand-500/20":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[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"})}),S.name,r.jsx("span",{className:"text-[9px] text-fg-muted",children:S.agentIds.length})]},`team-${S.id}`)}const Y=S.agent,J=tt.has(Y.id);return r.jsxs("button",{onClick:()=>Ei(Y.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${J?"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 ${J?"bg-brand-600 text-white":"bg-surface-overlay text-fg-secondary"}`,children:Y.name[0]?.toUpperCase()}),Y.name]},Y.id)})]}),R.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:()=>ce(!0),className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:s("work:project.newProject")})]})}):Ys(Object.values(H).flat()).length===0&&fn.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"})]})}),tt.size>0||ht?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:()=>{xt(new Set),Dt(!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:je,className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium transition-colors",children:s("work:task.createRequirementCta")}),r.jsx("button",{onClick:()=>{Qe(W??""),be(!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")})]})]})]})}):Ie==="backlog"?r.jsx("div",{className:"flex-1 min-h-0 flex flex-col",children:r.jsx(hb,{tasks:Ys(Object.values(H).flat()),requirements:fn,agents:ee,projects:R,onTaskClick:S=>Er(S),onReqClick:S=>Tr(S),onRefresh:()=>{At(),Pt()},selectedTaskId:dt?.id,selectedReqId:Xe?.id,onQuickCreateReq:Ke,onQuickCreateTask:Nt})}):Ie==="workflows"?r.jsx("div",{className:"flex-1 min-h-0 flex flex-col relative",children:r.jsx(xb,{teamId:null,defaultTeamId:Xu,projectId:W,agents:ee,users:le,projects:R,onViewRunTasks:S=>{const Y=fe.find(J=>J.id===S);Y?wi(Y):ne.requirements.get(S).then(J=>{J.requirement&&(ge(ie=>[...ie,J.requirement]),wi(J.requirement))}).catch(()=>{})}})}):Ie==="dag"?r.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",children:[r.jsx(xx,{tasks:(()=>{const S=Ys(Object.values(H).flat(),!0);if(t&&Xe){const J=new Set(Xe.taskIds??[]);return S.filter(ie=>J.has(ie.id))}if(zs.length===0)return S;const Y=new Map(S.map(J=>[J.id,J]));for(const J of zs)Y.set(J.id,J);return[...Y.values()]})(),requirements:(()=>{const S=t&&Xe?[Xe]:fn;return!An||S.some(Y=>Y.id===An.id)?S:[An,...S]})(),agents:ee,showArchived:$t,onShowArchivedChange:Ln,onTaskClick:S=>Er(S),onReqClick:S=>Tr(S),onCollapseDAG:()=>{Ve(null),He(null),es(null),Nr(null),qs([])},onDependencyChange:At,selectedTaskId:dt?.id,selectedReqId:Xe?.id,hasDetailPanel:Di,defaultExpandedNodeId:Mn??(t&&Xe?`req-${Xe.id}`:void 0),previewMode:t}),c&&r.jsx("button",{onClick:()=>vt("kanban"),className:"absolute left-3 top-1/2 -translate-y-1/2 w-11 h-11 rounded-full bg-brand-500 border border-brand-400/60 shadow-xl shadow-brand-500/30 flex items-center justify-center text-white active:bg-brand-400 backdrop-blur-sm z-10",title: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:()=>vt("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-white 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:Oo,className:"flex-1 min-h-0 overflow-auto px-4 py-5",children:r.jsx("div",{className:"flex gap-3 items-stretch",children:ff.map(S=>{const Y=Ti(S),J=Ii(S),ie=Y.length+J.length,he=De===S.id;return r.jsxs("div",{className:`w-[280px] shrink-0 rounded-xl flex flex-col transition-colors ${he?"bg-surface-elevated/60 ring-1 ring-brand-500/30":"bg-surface-secondary/50"}`,onDragOver:Me=>of(Me,S.id),onDragLeave:Me=>af(Me,S.id),onDrop:Me=>{lf(Me,S.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 ${he?"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 ${S.accent.replace("border-t-","bg-")}`}),r.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:S.label})]}),r.jsx("span",{className:"text-[11px] text-fg-tertiary font-medium tabular-nums",children:ie})]}),r.jsx("div",{className:"space-y-2 px-2 py-2",children:(()=>{const Me=[...J.map(Ce=>({kind:"req",data:Ce,time:new Date(Ce.updatedAt??Ce.createdAt).getTime()})),...Y.map(Ce=>({kind:"task",data:Ce,time:new Date(Ce.updatedAt??Ce.createdAt??0).getTime()}))];return Me.sort((Ce,se)=>se.time-Ce.time),Me.map(Ce=>{if(Ce.kind==="req"){const se=Ce.data,jt=l[se.status]??{label:se.status,cls:"bg-gray-500/15 text-fg-secondary"},Bt=se.source==="agent"&&se.status==="pending",nt=$==="all"&&se.projectId?R.find(We=>We.id===se.projectId):null,Ee=Rs(se.createdBy,ee,le)??se.createdBy.slice(0,10),lt=Xe?.id===se.id;return r.jsxs("div",{"data-work-item-id":se.id,role:"button",tabIndex:0,draggable:!0,onDragStart:We=>rf(We,se),onDragEnd:Ci,onClick:()=>Tr(se),onKeyDown:We=>We.key==="Enter"&&Tr(se),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
|
+
${lt?"!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 ${jt.cls}`,children:jt.label})]}),r.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:se.title}),se.description&&r.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:se.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:[nt&&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:nt.name,children:nt.name}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:se.priority}),r.jsxs("span",{className:"text-[10px] text-fg-muted",children:["by ",Ee]})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[se.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:se.goalConfig.completionCriteria,children:["🎯 ",se.goalConfig.currentIteration,"/",se.goalConfig.maxIterations]}),se.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:["📋 ",se.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:We=>{We.stopPropagation(),zo(se.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:We=>{We.stopPropagation(),Pn(se.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-${se.id}`)}else{const se=Ce.data,jt=se.subtasks?.length??0,Vt=i[se.status],Bt=se.status==="pending",nt=se.taskType==="scheduled"&&!!se.scheduleConfig,Ee=nt?se.scheduleConfig.every?s("work:task.everyInterval",{interval:se.scheduleConfig.every}):se.scheduleConfig.cron?s("work:task.cronLabel"):s("work:task.scheduledShort"):null,lt=$==="all"&&se.projectId?(()=>{const Lt=R.find($r=>$r.id===se.projectId)?.name;return Lt&&Lt!=="default"?Lt:null})():null,We=se.requirementId?fe.find(Lt=>Lt.id===se.requirementId)?.title:null,hn=se.createdBy?Rs(se.createdBy,ee,le)??se.createdBy:null,Wn=dt?.id===se.id,fs={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"},$i=se.status==="blocked"&&(!se.blockedBy||se.blockedBy.length===0||se.blockedBy.every(Lt=>{const $r=df.get(Lt);return $r&&$r.status==="completed"}));return r.jsxs("div",{"data-work-item-id":se.id,role:"button",tabIndex:0,"aria-label":se.title,draggable:!Bt,onDragStart:Lt=>!Bt&&sf(Lt,se),onDragEnd:Ci,onClick:()=>Er(se),onKeyDown:Lt=>Lt.key==="Enter"&&Er(se),className:`group rounded-lg p-2.5 border border-transparent transition-all ${$i?"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":nt?"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"} ${Wn?"!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 ${fs[se.priority]??"bg-gray-400"}`,title:se.priority}),nt&&r.jsx("span",{className:"text-blue-500 shrink-0",title:Ee??"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"})})}),nt&&Ee&&r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:Ee}),Vt&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${Vt.cls}`,children:Vt.label}),$i&&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:se.title}),se.description&&r.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:se.description}),(lt||We||se.blockedBy&&se.blockedBy.length>0)&&r.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[lt&&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:lt,children:lt}),We&&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:We,children:["# ",We]}),se.blockedBy&&se.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:["⏳ ",se.blockedBy.length," dep",se.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:hn&&r.jsxs("span",{className:"text-[10px] text-fg-muted",title:`by ${hn}`,children:["by ",hn]})}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[jt>0&&r.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",jt]}),se.notes&&se.notes.length>0&&r.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",se.notes.length]}),se.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 ${Gn[ee.find(Lt=>Lt.id===se.assignedAgentId)?.status??""]??"bg-gray-500"}`}),ee.find(Lt=>Lt.id===se.assignedAgentId)?.name??se.assignedAgentId.slice(0,8)]})]})]})]},se.id)}})})()}),he&&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")})})]},S.id)})})})]}),!c&&Oi&&r.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:T,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"})}),Oi&&r.jsx("div",{className:`${c||Or?"flex-1":"shrink-0"} overflow-hidden min-w-0 flex border-l border-border-default/60`,style:c||Or?void 0:{width:I},children:P==="project"&&Wt?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:zn,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(cb,{project:Wt,tasks:Object.values(H).flat().filter(S=>S.projectId===Wt.id),requirements:fe.filter(S=>S.projectId===Wt.id),agents:ee,onDeleteProject:()=>tf(Wt.id),onUpdateProject:async S=>{await ne.projects.update(Wt.id,S),Bn()},onRefresh:()=>{Bn()}})]}):P==="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:je,className:"px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium",children:s("work:task.newRequirement")}),r.jsx("button",{onClick:()=>{Qe(W??""),be(!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:zn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:s("common:close")})]})}):Or?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:r.jsx(vc,{req:Xe,agents:ee,projects:R,allTasks:Object.values(H).flat(),users:le,onClose:()=>{He(null),dt||zn()},onApprove:S=>{zo(S)},onReject:S=>{Pn(S)},onCancel:S=>{Si(S),He(null)},onStatusChange:async(S,Y)=>{try{await ne.requirements.updateStatus(S,Y),ut(`Requirement status → ${Y}`),ds({requirementId:S}),Hn(),At()}catch(J){ut(`Error: ${J}`)}},onRefresh:Hn,authUser:e,onTaskClick:S=>{Ve(S),M("item")},onCreateTask:(S,Y)=>{qe(S),Y&&Qe(Y),be(!0)},onProjectClick:Mr,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(xc,{task:dt,agents:ee,projects:R,requirements:fe,allTasks:Object.values(H).flat(),users:le,onClose:Qu,onRefresh:ji,authUser:e,scrollToComments:Bo,onScrollToCommentsDone:()=>Ks(!1),onReqClick:S=>{He(Y=>Y?.id===S.id?null:S),M("item")},onProjectClick:Mr})})]}):dt?r.jsx(xc,{task:dt,agents:ee,projects:R,requirements:fe,allTasks:Object.values(H).flat(),users:le,onClose:zn,onRefresh:ji,authUser:e,scrollToComments:Bo,onScrollToCommentsDone:()=>Ks(!1),onReqClick:S=>{He(S),Ve(null),M("item")},onProjectClick:Mr}):Xe?r.jsx(vc,{req:Xe,agents:ee,projects:R,allTasks:Object.values(H).flat(),users:le,onClose:zn,onApprove:S=>{zo(S)},onReject:S=>{Pn(S)},onCancel:S=>{Si(S),zn()},onStatusChange:async(S,Y)=>{try{await ne.requirements.updateStatus(S,Y),ut(`Requirement status → ${Y}`),ds({requirementId:S}),Hn(),At()}catch(J){ut(`Error: ${J}`)}},scrollToComments:Bo,onScrollToCommentsDone:()=>Ks(!1),onRefresh:Hn,authUser:e,onTaskClick:S=>{Ve(S),He(null),M("item"),c&&(L(!0),history.pushState({mobileDetail:Ze.WORK},"",window.location.hash))},onCreateTask:(S,Y)=>{qe(S),Y&&Qe(Y),be(!0)},onProjectClick:Mr,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:zn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:s("common:close")})]})})}),wt&&r.jsx(Pl,{orgId:e?.orgId,onCreated:ef,onClose:()=>ce(!1)}),ft&&r.jsx(Pl,{orgId:e?.orgId,onCreated:S=>{A(Y=>Y.some(J=>J.id===S.id)?Y:[...Y,S]),ft==="task"?(Qe(S.id),qe("")):$o(S.id),Ot(null),ut(s("work:task.projectCreated"))},onClose:()=>Ot(null)}),xe&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{be(!1),_e("")},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:S=>S.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("work:task.newTask")}),r.jsxs("div",{className:ba,children:[r.jsx("label",{className:st,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(S=>r.jsx("button",{type:"button",onClick:()=>ye(S),"aria-pressed":ae===S,className:`flex-1 px-3 py-1.5 text-sm rounded-md transition-colors ${ae===S?"bg-brand-600 text-white font-medium":"text-fg-secondary hover:text-fg-primary"}`,children:s(S==="standard"?"work:task.taskTypeStandard":"work:task.taskTypeScheduled")},S))}),r.jsx("label",{className:st,children:s("work:task.titleLabel")}),r.jsx("input",{autoFocus:!c,value:at,onChange:S=>Ye(S.target.value),onKeyDown:S=>{S.key==="Enter"&&ki()},className:pn}),r.jsx("label",{className:st,children:s("work:task.descriptionField")}),r.jsx("textarea",{value:Oe,onChange:S=>kt(S.target.value),rows:2,className:`${pn} resize-none`}),r.jsx("label",{className:st,children:s("work:task.priorityField")}),r.jsx(xo,{value:Et,onChange:Tt}),r.jsx("label",{className:st,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")},...R.map(S=>({value:S.id,label:S.name}))],value:it,onChange:S=>{Qe(S),qe("")},placeholder:s("work:task.noProject"),noMatchesText:s("work:task.noMatches")}),r.jsx("button",{type:"button",onClick:()=>Ot("task"),className:na,children:s("work:task.newProjectInline")})]}),r.jsx("label",{className:st,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")},...fe.filter(S=>S.status==="in_progress"&&(!it||S.projectId===it)).map(S=>({value:S.id,label:S.title}))],value:Pe,onChange:qe,placeholder:s("work:task.selectRequirement"),noMatchesText:s("work:task.noMatches")}),r.jsx("button",{type:"button",onClick:()=>{ct(!0),_e("")},className:na,children:s("work:task.newRequirementInline")})]}),Re&&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:St,onChange:S=>sn(S.target.value),placeholder:s("work:task.newReqInlinePlaceholder"),onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),vi())},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:()=>{vi()},disabled:!St.trim(),className:"px-3 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-40",children:s("common:create")})]}),r.jsx("p",{className:"text-[11px] text-fg-tertiary",children:s(it?"work:task.newReqInlineHint":"work:task.newReqInlineNeedProject")})]})]}),r.jsxs("label",{className:st,children:[s("work:task.assignToRequired"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx(Ft,{options:ee.map(S=>({value:S.id,label:`${S.name} (${S.status})`})),value:te,onChange:Ae,placeholder:s("work:task.selectAgent"),noMatchesText:s("work:task.noMatches")}),r.jsxs("label",{className:st,children:[s("work:task.reviewerRequired"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx(Ft,{options:[...le.map(S=>({value:`human:${S.id}`,label:S.name})),...ee.filter(S=>S.id!==te).map(S=>({value:`agent:${S.id}`,label:`${S.name} (${S.status})`}))],value:Ue,onChange:$e,placeholder:s("work:task.selectReviewer"),noMatchesText:s("work:task.noMatches")}),ae==="scheduled"&&r.jsx("div",{className:"col-span-2",children:r.jsx(Pc,{value:Se,onChange:re})}),r.jsx("label",{className:st,children:s("work:task.blockedBy")}),r.jsxs("div",{className:"min-w-0",children:[r.jsx(G0,{options:Object.values(H).flat().filter(S=>S.status!=="completed"&&S.status!=="cancelled").map(S=>({value:S.id,label:S.title})),selected:Je,onAdd:S=>G([...Je,S]),placeholder:s("work:task.selectDependency"),noMatchesText:s("work:task.noMatches")}),Je.length>0&&r.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:Je.map(S=>{const Y=Object.values(H).flat().find(J=>J.id===S);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):S.slice(-8),r.jsx("button",{onClick:()=>G(Je.filter(J=>J!==S)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},S)})})]})]}),ke&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:ke}),r.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[r.jsx("button",{onClick:()=>{be(!1),_e("")},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:()=>{ki()},disabled:!at.trim()||!te||!Ue||It,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-50",children:s(It?"common:creating":"common:create")})]})]})}),ns&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Dn(!1),rn(""),$n(""),wn("")},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:S=>S.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:ba,children:[r.jsxs("label",{className:st,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:R.map(S=>({value:S.id,label:S.name})),value:Sr,onChange:$o,placeholder:s("work:task.selectProject"),noMatchesText:s("work:task.noMatches")}),r.jsx("button",{type:"button",onClick:()=>Ot("req"),className:na,children:s("work:task.newProjectInline")})]}),r.jsxs("label",{className:st,children:[s("work:task.titleField"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx("input",{value:On,onChange:S=>rn(S.target.value),placeholder:s("work:task.reqTitleExample"),className:pn,autoFocus:!c,onKeyDown:S=>{S.key==="Enter"&&On.trim()&&Ni()}}),r.jsxs("label",{className:st,children:[s("work:task.descriptionField"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx("textarea",{value:ss,onChange:S=>$n(S.target.value),placeholder:s("work:task.reqDescPlaceholder"),rows:3,className:`${pn} resize-none`}),r.jsx("label",{className:st,children:s("work:task.priorityField")}),r.jsx(xo,{value:Ws,onChange:Gu})]}),ui&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:ui}),r.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[r.jsx("button",{onClick:()=>{Dn(!1),rn(""),$n(""),wn("")},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:()=>{Ni()},disabled:!On.trim()||!ss.trim()||!Sr||Po,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-white disabled:opacity-40 disabled:cursor-not-allowed",children:s(Po?"common:creating":"common:create")})]})]})}),rs&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Pn(null),os("")},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:S=>S.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:ci,onChange:S=>di(S.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})]}),hi&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:hi}),r.jsxs("div",{className:"flex justify-end gap-3",children:[r.jsx("button",{onClick:()=>{Pn(null),os("")},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:()=>{nf()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:s("work:task.reject")})]})]})}),Hs&&r.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>yn(!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:S=>S.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:[(tt.size>0||ht)&&r.jsx("button",{onClick:()=>{xt(new Set),Dt(!1)},className:"text-[11px] text-brand-500 font-medium",children:s("work:task.clearAll")}),r.jsx("button",{onClick:()=>yn(!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"})]})})]})]}),R.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(),yn(!1)},className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-lg transition-all ${$==="all"&&!W?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[s("work:task.all"),Rr>0&&r.jsx("span",{className:"text-[9px] text-fg-tertiary",children:Rr})]}),Lr.map(S=>{const Y=W===S.id,J=_r[S.id]??0;return r.jsxs("button",{type:"button",onClick:()=>{Gt(S.id),yn(!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-white":"bg-surface-overlay text-fg-tertiary"}`,children:S.name[0]?.toUpperCase()}),S.name,J>0&&r.jsx("span",{className:"text-[9px] text-fg-tertiary",children:J})]},S.id)})]})]}),e?.id&&r.jsx("div",{className:"px-4 py-3 border-t border-border-default/40",children:r.jsx("button",{type:"button",onClick:()=>Dt(S=>!S),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ht?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:s("work:task.myTasks")})}),Ar.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:Ar.map(S=>{if(S.kind==="team"){const ie=S.agentIds.every(Me=>tt.has(Me)),he=!ie&&S.agentIds.some(Me=>tt.has(Me));return r.jsxs("button",{onClick:()=>{xt(Me=>{const Ce=new Set(Me);if(ie)for(const se of S.agentIds)Ce.delete(se);else for(const se of S.agentIds)Ce.add(se);return Ce})},className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ie?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":he?"bg-brand-600/10 text-brand-400 ring-1 ring-brand-500/20":"bg-surface-elevated text-fg-secondary"}`,children:[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"})}),S.name,r.jsx("span",{className:"text-[9px] text-fg-muted",children:S.agentIds.length})]},`team-${S.id}`)}const Y=S.agent,J=tt.has(Y.id);return r.jsxs("button",{onClick:()=>Ei(Y.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${J?"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 ${J?"bg-brand-600 text-white":"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 bb({requirementId:e,createdBy:t,agents:n,users:s,authUser:o}){const{t:a}=ze(["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),ne.requirements.getComments(e).then(v=>l(v.comments)).catch(()=>{})},[e]),p.useEffect(()=>Ht.on("requirement:comment",b=>{if(b.payload?.requirementId===e&&b.payload.comment){const x=b.payload.comment;l(w=>w.some(N=>N.id===x.id)?w:[...w,x]),(x.authorType==="agent"||x.authorId?.startsWith("agt_"))&&(d(w=>{const N=w.filter(j=>j.id!==x.authorId);return N.length===0&&h.current&&(clearTimeout(h.current),h.current=null),N}),f(w=>{const N=new Map(w);return N.delete(x.authorId),N}))}}),[e]),p.useEffect(()=>{if(c.length===0)return;const v=new Set(c.map(x=>x.id));return Ht.on("agent:activity_log",x=>{const w=x.payload;if(!w)return;const N=w.agentId;if(!v.has(N))return;const j=ri(w);j&&f(E=>oi(E,N,j))})},[c]);const[m,g]=p.useState(null),y=async(v,b,x,w)=>{let N;x.length>0&&(N=(await ne.uploads.upload(x.map(_=>({dataUrl:_.dataUrl,name:_.name})),"comments")).files.map(_=>({type:"image",url:_.url,name:_.name}))),await ne.requirements.addComment(e,v,o?.name,N,o?.id,b.length>0?b:void 0,w);const j=[],E=new Set,C=D=>{if(E.has(D)||D===o?.id)return;E.add(D);const _=n.find(I=>I.id===D);_&&j.push({id:_.id,name:_.name,avatarUrl:_.avatarUrl})};for(const D of b){const _=n.find(I=>I.name.toLowerCase()===D.toLowerCase());_&&C(_.id)}t?.startsWith("agt_")&&C(t),j.length>0&&(h.current&&clearTimeout(h.current),d(j),h.current=setTimeout(()=>d([]),12e4))},k=p.useCallback(v=>{g({id:v.id,authorName:v.authorName,content:v.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(v=>r.jsx(Do,{comment:v,agents:n,onReply:k},v.id)),c.length>0&&r.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:c.map(v=>{const b=u.get(v.id)??[];return r.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>en.navigate(Ze.TEAM,{agentId:v.id,profileTab:"mind"}),children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"relative shrink-0",children:[r.jsx(Ea,{name:v.name,avatarUrl:v.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:v.name}),b.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:"→"})]}),b.length>0&&r.jsx("div",{className:"ml-8 mt-1",children:r.jsx(ai,{entries:b})})]},v.id)})})]}),r.jsx(Ac,{agents:n,humans:s,onSubmit:y,replyTo:m,onCancelReply:()=>g(null)})]})}function vc({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:y,onProjectClick:k,previewMode:v}){const{t:b}=ze(["work","common"]),x=p.useMemo(()=>li(b),[b]),w=p.useMemo(()=>Vu(b),[b]),N=hr(),[j,E]=p.useState(!1),[C,D]=p.useState(e.description),[_,I]=p.useState(!1),[O,q]=p.useState(!1),[T,B]=p.useState(!1);p.useEffect(()=>{if(!T)return;const te=Ae=>{Ae.key==="Escape"&&B(!1)};return document.addEventListener("keydown",te),()=>document.removeEventListener("keydown",te)},[T]);const[L,z]=p.useState(!1),[R,A]=p.useState(null),[$,F]=p.useState(!1),[W,X]=p.useState(null),P=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 ne.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 ne.requirements.approveTasksBulk(e.id,{runNow:!0});A({phase:"result",...te}),h?.()}catch(te){X(te instanceof Error?te.message:String(te))}finally{F(!1)}},[V,H]=p.useState(!1),Z=p.useRef(null),[ee,oe]=p.useState("none"),de=p.useRef(null),Q=p.useRef(null),le=p.useRef(80);p.useEffect(()=>{const te=Z.current;if(!te)return;const Ae=()=>{const{scrollTop:$e,scrollHeight:it,clientHeight:Qe}=te;if(!(it>Qe+50)){oe("none");return}const qe=$e<30,Je=$e+Qe>=it-30;oe(qe?"top":Je?"bottom":"middle")};Ae(),te.addEventListener("scroll",Ae,{passive:!0});const Ue=new ResizeObserver(Ae);return Ue.observe(te),()=>{te.removeEventListener("scroll",Ae),Ue.disconnect()}},[]),p.useEffect(()=>{if(j&&Q.current){const te=Q.current;te.style.height="auto",te.style.height=Math.max(te.scrollHeight,le.current)+"px",te.focus()}},[j]),p.useEffect(()=>{if(!f)return;const te=setTimeout(()=>{const Ae=Z.current;Ae&&Ae.scrollTo({top:Ae.scrollHeight,behavior:"smooth"}),m?.()},300);return()=>clearTimeout(te)},[f,m]);const ue=x[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},fe=e.source==="agent",ge=fe&&e.status==="pending",we=e.status==="pending"||e.status==="in_progress",me=e.status==="completed"||e.status==="rejected"||e.status==="cancelled"||e.status==="archived",ve=e.projectId?n.find(te=>te.id===e.projectId):null,Te=Rs(e.createdBy,t,o)??e.createdBy.slice(0,12),je=s.filter(te=>e.taskIds.includes(te.id)),Ke=ve?.teamIds?.[0]??null;p.useMemo(()=>new Map(je.map(te=>[te.id,te])),[je]);const Nt=je.length>=2;p.useEffect(()=>{D(e.description),E(!1)},[e.id,e.description]);const[wt,ce]=p.useState(!1),[xe,be]=p.useState(e.title),[at,Ye]=p.useState(!1),[Oe,kt]=p.useState((e.tags??[]).join(", ")),Et=p.useRef(null);p.useEffect(()=>{be(e.title),ce(!1)},[e.id,e.title]),p.useEffect(()=>{kt((e.tags??[]).join(", ")),Ye(!1)},[e.id,e.tags]),p.useEffect(()=>{wt&&Et.current?.focus()},[wt]);const Tt=async te=>{try{await ne.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 ${N?"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:[N&&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:[wt?r.jsx("input",{ref:Et,value:xe,onChange:te=>be(te.target.value),onBlur:()=>{const te=xe.trim();te&&te!==e.title&&Tt({title:te}),ce(!1)},onKeyDown:te=>{te.key==="Enter"&&te.target.blur(),te.key==="Escape"&&(be(e.title),ce(!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 ${me?"":"cursor-text hover:bg-surface-elevated/60"}`,onClick:me?void 0:()=>ce(!0),role:me?void 0:"button",tabIndex:me?void 0:0,onKeyDown:me?void 0:te=>te.key==="Enter"&&ce(!0),title:me?void 0:b("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:b("work:task.requirementShort")})," ",r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium align-middle ${ue.cls}`,children:ue.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:b("common:priority."+e.priority,{defaultValue:e.priority})}):r.jsx("span",{className:"text-[10px] text-fg-tertiary align-middle",children:b("common:priority."+e.priority,{defaultValue:e.priority})})]})]}),r.jsxs("div",{className:"flex items-center gap-2 shrink-0 mb-4",children:[r.jsx(Tc,{onClick:()=>H(!0),label:b("work:task.sendToChat",{defaultValue:"发送到对话"})}),r.jsx("button",{onClick:a,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0",children:"×"})]})]}),V&&r.jsx(Fu,{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:b("work:task.requirementDetailDescription")}),j?r.jsx("textarea",{ref:Q,value:C,onChange:te=>{D(te.target.value);const Ae=te.target;Ae.style.height="auto",Ae.style.height=Ae.scrollHeight+"px"},onBlur:async()=>{if(C!==e.description){I(!0);try{await ne.requirements.update(e.id,{description:C}),h?.()}catch{}finally{I(!1)}}E(!1)},onKeyDown:te=>{te.key==="Escape"&&(te.preventDefault(),D(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:b("work:task.requirementDetailDescription")}):r.jsx("div",{ref:de,className:`group relative rounded-lg -mx-2 px-2 -my-1 py-1 transition-colors ${me?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:me?void 0:te=>{te.target.closest("a, button, [data-entity-link]")||(le.current=Math.max(de.current?.offsetHeight??80,60),D(e.description),E(!0))},role:me?void 0:"button",tabIndex:me?void 0:0,onKeyDown:me?void 0:te=>te.key==="Enter"&&(D(e.description),E(!0)),children:e.description?r.jsx(rr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):r.jsx("p",{className:"text-sm text-fg-tertiary italic",children:b("work:task.requirementNoDescription")})})]}),r.jsxs("div",{className:"border-t border-border-default/60 pt-4",children:[r.jsxs("div",{className:Xd,children:[r.jsx("label",{className:st,children:b("work:task.projectLabel")}),r.jsx(Ft,{size:"sm",disabled:me,options:[{value:"",label:b("work:task.noProject")},...n.map(te=>({value:te.id,label:te.name}))],value:e.projectId??"",onChange:te=>{Tt({projectId:te||null})},placeholder:b("work:task.noProject"),noMatchesText:b("work:task.noMatches")}),r.jsx("label",{className:st,children:b("work:task.priority")}),r.jsx(xo,{value:e.priority,onChange:te=>{Tt({priority:te})}}),r.jsx("label",{className:st,children:b("work:task.tagsLabel")}),at&&!me?r.jsx("input",{autoFocus:!0,value:Oe,onChange:te=>kt(te.target.value),onBlur:()=>{const te=Oe.split(",").map(Ue=>Ue.trim()).filter(Boolean),Ae=e.tags??[];te.join("\0")!==Ae.join("\0")&&Tt({tags:te}),Ye(!1)},onKeyDown:te=>{te.key==="Enter"&&te.target.blur(),te.key==="Escape"&&(kt((e.tags??[]).join(", ")),Ye(!1))},placeholder:b("work:task.tagsPlaceholder"),className:`${pn} !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 ${me?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:me?void 0:()=>Ye(!0),role:me?void 0:"button",tabIndex:me?void 0:0,onKeyDown:me?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:b("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:[b("work:task.createdByLabel"),": ",r.jsx("span",{className:"text-fg-secondary",children:Te}),fe&&r.jsx("span",{className:"text-brand-500 ml-1",children:b("work:task.agentTag")})]}),r.jsx("span",{children:new Date(e.createdAt).toLocaleString()}),k&&ve&&r.jsxs("button",{onClick:()=>k(ve.id),className:"hover:text-fg-secondary transition-colors",children:[b("work:task.projectLabel"),": ",ve.name]}),e.approvedBy&&r.jsxs("span",{children:[b("work:task.approvedBy"),": ",r.jsx("span",{className:"text-fg-secondary",children:Rs(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:b("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:b("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?b("work:requirement.goalMaxReached"):b("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:b("work:requirement.goalIteration",{current:e.goalConfig.currentIteration,max:e.goalConfig.maxIterations})}),e.goalConfig.lastCheckedAt&&r.jsx("span",{children:b("work:requirement.goalLastChecked",{time:new Date(e.goalConfig.lastCheckedAt).toLocaleString()})}),e.goalConfig.autoResume&&r.jsx("span",{className:"text-brand-500",children:b("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:b("work:task.linkedTasks",{count:je.length})}),r.jsxs("div",{className:"flex items-center gap-2",children:[Nt&&Ke&&r.jsxs("button",{onClick:()=>z(!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"})}),b("work:task.saveAsWorkflow")]}),!me&&y&&r.jsxs("button",{onClick:()=>y(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"})}),b("work:requirement.createTask")]})]})]}),je.length>0?(()=>{const te=new Map(je.map(Pe=>[Pe.id,Pe]));if(!je.some(Pe=>Pe.blockedBy?.some(qe=>te.has(qe))))return r.jsx("div",{className:"space-y-1.5",children:je.map(Pe=>{const qe=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 ${Gn[Pe.status]??"bg-gray-500"}`}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:Pe.title}),qe&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${qe.cls}`,children:qe.label})]},Pe.id)})});const Ue=new Map,$e=new Set;for(const Pe of je)for(const qe of Pe.blockedBy??[])if(te.has(qe)){$e.add(Pe.id);const Je=Ue.get(qe)??[];Je.push(Pe.id),Ue.set(qe,Je)}const it=je.filter(Pe=>!$e.has(Pe.id)),Qe=(Pe,qe)=>{const Je=w[Pe.status],G=(Ue.get(Pe.id)??[]).map(ae=>te.get(ae)).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:qe>0?{marginLeft:qe*20}:void 0,children:[qe>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 ${Gn[Pe.status]??"bg-gray-500"}`}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:Pe.title}),Je&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Je.cls}`,children:Je.label})]}),G.map(ae=>Qe(ae,qe+1))]},Pe.id)};return r.jsx("div",{className:"space-y-1.5",children:it.map(Pe=>Qe(Pe,0))})})():r.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:b("work:requirement.noLinkedTasks")})]}),!v&&r.jsx(bb,{requirementId:e.id,createdBy:e.createdBy,agents:t,users:o,authUser:u}),!v&&r.jsx(Yu,{entityType:"requirement",entityId:e.id})]}),ee!=="none"&&ee!=="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-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:b("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"})})}),ee!=="none"&&ee!=="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-white hover:bg-brand-400 transition-colors backdrop-blur-sm",title:b("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:[P>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-white text-sm rounded-lg font-medium transition-colors disabled:opacity-60",children:b("work:requirement.bulkApprove","批量批准待批任务 ({{count}})",{count:P})}),R&&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":b("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:R.phase==="preview"?b("work:requirement.bulkApproveTitle","批量批准待批任务"):b("work:requirement.bulkApproveDone","批量批准结果")}),R.phase==="preview"&&r.jsx("p",{className:"mt-1 text-xs text-amber-600 dark:text-amber-400 leading-relaxed",children:b("work:requirement.bulkApproveWarning","批准后立即开始执行:将同时启动 {{count}} 个任务,各自占用对应 agent。",{count:R.approved.length})}),R.phase==="result"&&r.jsx("p",{className:"mt-1 text-xs text-fg-secondary",children:b("work:requirement.bulkApproveSummary","成功 {{ok}} · 跳过 {{skip}} · 失败 {{fail}}",{ok:R.approved.length,skip:R.skipped.length,fail:R.failed.length})})]}),r.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-3 space-y-3",children:[R.approved.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary mb-1",children:R.phase==="preview"?b("work:requirement.bulkApproveWillApprove","将批准"):b("work:requirement.bulkApproveApproved","已批准")}),r.jsx("ul",{className:"space-y-0.5",children:R.approved.map(te=>r.jsxs("li",{className:"text-xs text-fg-secondary truncate",children:["· ",te.title]},te.id))})]}),R.skipped.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary mb-1",children:b("work:requirement.bulkApproveSkipped","跳过(不满足批准条件)")}),r.jsx("ul",{className:"space-y-0.5",children:R.skipped.map(te=>r.jsxs("li",{className:"text-xs text-fg-tertiary truncate",children:["· ",te.title||te.id," — ",te.reason]},te.id))})]}),R.failed.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-red-500 mb-1",children:b("work:requirement.bulkApproveFailed","失败")}),r.jsx("ul",{className:"space-y-0.5",children:R.failed.map(te=>r.jsxs("li",{className:"text-xs text-red-500 truncate",children:["· ",te.title," — ",te.error]},te.id))})]}),R.approved.length===0&&R.skipped.length===0&&r.jsx("p",{className:"text-xs text-fg-tertiary",children:b("work:requirement.bulkApproveNothing","没有可批准的待批任务。")}),W&&r.jsx("p",{className:"text-xs text-red-500",children:W})]}),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:R.phase==="preview"?b("common:cancel"):b("common:close")}),R.phase==="preview"&&r.jsx("button",{onClick:()=>{K()},disabled:$||R.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:$?b("work:requirement.bulkApproving","批准中…"):b("work:requirement.bulkApproveConfirm","确认批准并开始")})]})]})})]}),ge&&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:b("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:b("work:requirement.rejectRequirement")})]}),!ge&&d&&!me&&r.jsxs("div",{className:"relative",children:[r.jsxs("button",{type:"button",onClick:()=>B(te=>!te),"aria-haspopup":"menu","aria-expanded":T,"aria-label":b("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 ${Gn[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"})})]}),T&&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=[...Sa[e.status]??[]].filter(Ae=>Ae!=="cancelled"&&!(ge&&Ae==="rejected"));return te.length===0?r.jsx("p",{className:"px-3 py-2 text-[11px] text-fg-tertiary",children:b("work:requirement.noStatusChange","暂无可用状态变更")}):te.map(Ae=>r.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{B(!1),d(e.id,Ae)},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 ${Gn[Ae]??"bg-fg-muted"}`,"aria-hidden":"true"}),r.jsx("span",{className:"flex-1",children:x[Ae]?.label??Ae}),Ae==="completed"&&r.jsx("span",{className:"text-[10px] text-fg-muted",children:b("work:requirement.terminalHint","终态")})]},Ae))})()})]})]}),me&&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:b("work:task.reopen")}),r.jsx("div",{className:"flex-1"}),we&&!ge&&r.jsx("button",{onClick:()=>q(!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:b("work:task.cancelRequirement")})]}),O&&r.jsx(gs,{title:b("work:requirement.cancelConfirmTitle","Cancel Requirement"),message:b("work:requirement.cancelConfirmMessage","Are you sure you want to cancel this requirement? This action cannot be undone."),confirmLabel:b("work:requirement.cancelConfirmLabel","Cancel Requirement"),onConfirm:()=>{q(!1),c(e.id)},onCancel:()=>q(!1)}),L&&Ke&&r.jsx(gb,{req:e,tasks:je,agents:t,teamId:Ke,onClose:()=>z(!1),onSaved:()=>z(!1)})]})}function Yu({entityType:e,entityId:t}){const{t:n}=ze(["work"]),[s,o]=p.useState([]),[a,i]=p.useState(!0),[l,c]=p.useState(!1);if(p.useEffect(()=>{i(!0),(e==="task"?ne.tasks.getHistory:ne.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{Cb as WorkPage};
|