@markus-global/cli 0.12.3 → 0.12.5-rc.1
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/background-maintenance.d.ts +25 -0
- package/dist/background-maintenance.d.ts.map +1 -1
- package/dist/background-maintenance.js +61 -0
- package/dist/background-maintenance.js.map +1 -1
- package/dist/commands/im-inbound-origin.d.ts +38 -0
- package/dist/commands/im-inbound-origin.d.ts.map +1 -0
- package/dist/commands/im-inbound-origin.js +48 -0
- package/dist/commands/im-inbound-origin.js.map +1 -0
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +211 -46
- package/dist/commands/start.js.map +1 -1
- package/dist/markus.mjs +18523 -9866
- package/dist/web-ui/assets/{AsyncState-_UC7xcxJ.js → AsyncState-fJJNUOXK.js} +1 -1
- package/dist/web-ui/assets/ChatComponents-S7d2CAAU.js +14 -0
- package/dist/web-ui/assets/{ContentRenderer-C-V5k_3K.js → ContentRenderer-DWqhC0uq.js} +6 -6
- package/dist/web-ui/assets/DeliverableShareModal-B7DwzEnt.js +1 -0
- package/dist/web-ui/assets/{Deliverables-CQnWqbTb.js → Deliverables-CueBYYpx.js} +2 -2
- package/dist/web-ui/assets/MarkdownMessage-D8BsJzvD.js +4 -0
- package/dist/web-ui/assets/{Search-CVYQIy_D.js → Search-CaYXz3u-.js} +1 -1
- package/dist/web-ui/assets/{SendToChat-IOAvuta-.js → SendToChat-_9sm7UBY.js} +1 -1
- package/dist/web-ui/assets/Settings-DTL14pY8.js +8 -0
- package/dist/web-ui/assets/{Store-BEsLd_RN.js → Store-DpGqUMS2.js} +1 -1
- package/dist/web-ui/assets/Switch-NYQTn8wl.js +1 -0
- package/dist/web-ui/assets/Team-DB-JytPl.js +93 -0
- package/dist/web-ui/assets/Work-sQq-gy3S.js +142 -0
- package/dist/web-ui/assets/{arc-DP1Vf7Sx.js → arc-JtkmqkSR.js} +1 -1
- package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-Buq8JYN8.js → architectureDiagram-3BPJPVTR-B8zM5fky.js} +1 -1
- package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-BCa2p2_X.js → blockDiagram-GPEHLZMM-BQgjaOcE.js} +1 -1
- package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-BxsgggQY.js → c4Diagram-AAUBKEIU-BnZvYRwj.js} +1 -1
- package/dist/web-ui/assets/channel-Zno2q8Ba.js +1 -0
- package/dist/web-ui/assets/{chunk-2J33WTMH-BJZZ60c9.js → chunk-2J33WTMH-KONx1qvt.js} +1 -1
- package/dist/web-ui/assets/{chunk-4BX2VUAB-C5hc4E6J.js → chunk-4BX2VUAB-BqkxAkWs.js} +1 -1
- package/dist/web-ui/assets/{chunk-55IACEB6-CbyvZ6Mk.js → chunk-55IACEB6-DxLiTj85.js} +1 -1
- package/dist/web-ui/assets/{chunk-727SXJPM-JmNt9TVA.js → chunk-727SXJPM-Dhj-9NIs.js} +1 -1
- package/dist/web-ui/assets/{chunk-AQP2D5EJ-BTk0v5ba.js → chunk-AQP2D5EJ-M1vQ4YYc.js} +1 -1
- package/dist/web-ui/assets/{chunk-FMBD7UC4-BO-dhB1U.js → chunk-FMBD7UC4-DaXv58SH.js} +1 -1
- package/dist/web-ui/assets/{chunk-ND2GUHAM-BdjCcLdb.js → chunk-ND2GUHAM-Brkz9FCu.js} +1 -1
- package/dist/web-ui/assets/{chunk-QZHKN3VN-BAzRC82n.js → chunk-QZHKN3VN-DIsEGiBf.js} +1 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-hI59DDUw.js +1 -0
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-hI59DDUw.js +1 -0
- package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-CVffmErT.js → cose-bilkent-S5V4N54A-CSjC_YL5.js} +1 -1
- package/dist/web-ui/assets/{dagre-BM42HDAG-Dd9pB2fX.js → dagre-BM42HDAG-BevSxaQN.js} +1 -1
- package/dist/web-ui/assets/{diagram-2AECGRRQ-BG_AUqzM.js → diagram-2AECGRRQ-CT3Hj8jy.js} +1 -1
- package/dist/web-ui/assets/{diagram-5GNKFQAL-D5qFMRFf.js → diagram-5GNKFQAL-CAebHy6q.js} +1 -1
- package/dist/web-ui/assets/{diagram-KO2AKTUF-B3qTxSWl.js → diagram-KO2AKTUF-BvRWS7BX.js} +1 -1
- package/dist/web-ui/assets/{diagram-LMA3HP47-BrxC1636.js → diagram-LMA3HP47-gR9HBKc4.js} +1 -1
- package/dist/web-ui/assets/{diagram-OG6HWLK6-BvXyEQ9-.js → diagram-OG6HWLK6-B5HGsfNo.js} +1 -1
- package/dist/web-ui/assets/{docx-preview-DBAZFeEb.js → docx-preview-pRjmDg6F.js} +1 -1
- package/dist/web-ui/assets/{erDiagram-TEJ5UH35-CMap9oy_.js → erDiagram-TEJ5UH35-mrPW01aQ.js} +1 -1
- package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-BZerJtvk.js → flowDiagram-I6XJVG4X-BrZ1G-Tt.js} +1 -1
- package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-CagPMHMO.js → ganttDiagram-6RSMTGT7-Dq_5mate.js} +1 -1
- package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-DZ5dDKRu.js → gitGraphDiagram-PVQCEYII-Cb3yTWUy.js} +1 -1
- package/dist/web-ui/assets/index-9SXWNIl0.css +1 -0
- package/dist/web-ui/assets/index-Bco6UnT7.js +867 -0
- package/dist/web-ui/assets/{infoDiagram-5YYISTIA-CHLdsDUZ.js → infoDiagram-5YYISTIA-CcnNlnvs.js} +1 -1
- package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-SdeinQaS.js → ishikawaDiagram-YF4QCWOH-BqHTPtO1.js} +1 -1
- package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-BtlL2fi0.js → journeyDiagram-JHISSGLW-DKBB9B-C.js} +1 -1
- package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-BKPQYXkB.js → kanban-definition-UN3LZRKU-BVO5tbNl.js} +1 -1
- package/dist/web-ui/assets/{mermaid.core-MkJR6w4B.js → mermaid.core-bMoKRCj4.js} +5 -5
- package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-CbOmHX_u.js → mindmap-definition-RKZ34NQL-Bk0lFKmi.js} +1 -1
- package/dist/web-ui/assets/{pieDiagram-4H26LBE5-CypGjJP1.js → pieDiagram-4H26LBE5-BRPnBLeL.js} +1 -1
- package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-CGtemfUz.js → quadrantDiagram-W4KKPZXB-CAqdqT5W.js} +1 -1
- package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-N7YfpCvE.js → requirementDiagram-4Y6WPE33-Vv5YNzCu.js} +1 -1
- package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-CYnSrei-.js → sankeyDiagram-5OEKKPKP-Ciq1EgmQ.js} +1 -1
- package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-CsB7dCPF.js → sequenceDiagram-3UESZ5HK-DVRqp161.js} +1 -1
- package/dist/web-ui/assets/{stateDiagram-AJRCARHV-DTDFUXFP.js → stateDiagram-AJRCARHV-zbjDSKA3.js} +1 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-C54VSYn7.js +1 -0
- package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-C_bWAN9B.js → timeline-definition-PNZ67QCA-D0hr0d1U.js} +1 -1
- package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-CX_qAuUT.js → vennDiagram-CIIHVFJN-CtuZLcPo.js} +1 -1
- package/dist/web-ui/assets/{wardley-L42UT6IY-q53jQ293.js → wardley-L42UT6IY-nP2-eCDJ.js} +1 -1
- package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-D34dKCJU.js → wardleyDiagram-YWT4CUSO-Dxc7OveP.js} +1 -1
- package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-BFAngp66.js → xychartDiagram-2RQKCTM6-Bm2LvPhZ.js} +1 -1
- package/dist/web-ui/index.html +2 -2
- package/docs/README.md +50 -16
- package/docs/api/guides/websocket.md +43 -0
- package/docs/api/reference.md +657 -0
- package/docs/architecture/a2a-communication.md +303 -0
- package/docs/architecture/agent-runtime.md +145 -28
- package/docs/architecture/architecture.md +30 -11
- package/docs/architecture/cognitive-architecture.md +189 -15
- package/docs/architecture/concurrent-processing.md +190 -31
- package/docs/architecture/context-assembly.md +264 -0
- package/docs/architecture/derived-views.md +463 -0
- package/docs/architecture/desktop-auto-update.md +185 -0
- package/docs/architecture/facts.md +406 -0
- package/docs/architecture/learning-loop.md +11 -0
- package/docs/architecture/limits.md +79 -0
- package/docs/architecture/mailbox-system.md +786 -668
- package/docs/architecture/memory-system.md +1 -1
- package/docs/architecture/messaging-gateway.md +7 -0
- package/docs/architecture/notification-delivery.md +221 -0
- package/docs/architecture/notification-sounds.md +177 -0
- package/docs/architecture/prompt-engineering.md +171 -700
- package/docs/{design/remote-access-contract.md → architecture/remote-access.md} +4 -0
- package/docs/architecture/state-machines.md +288 -5
- package/docs/architecture/tool-loop-harness.md +362 -0
- package/docs/architecture/tool-system.md +40 -16
- package/docs/design/background-callback-in-turn-delivery-2026-11-22.md +95 -0
- package/docs/design/c10-0b-pick-identity-leak-2026-11-22.md +233 -0
- package/docs/design/c10-a-identity-columns-2026-11-22.md +182 -0
- package/docs/design/c10-c-trust-boundary-2026-11-23.md +222 -0
- package/docs/design/c10-external-adapters-plan-2026-11-19.md +448 -0
- package/docs/design/c8-residual-mechanisms-2026-11-15.md +984 -0
- package/docs/design/external-signal-decision-loop-2026-11-25.md +579 -0
- package/docs/guides/development.md +1 -1
- package/docs/{architecture → guides}/mailbox-audit-checklist.md +7 -0
- package/docs/guides/remote-access.md +1 -1
- package/docs/{design/agent-stop-intent-audit.md → records/agent-stop-intent-audit-2026-11-08.md} +4 -0
- package/docs/records/c10-l5-gate-verification-2026-11-26.md +72 -0
- package/docs/records/c10-l5-live-verification-2026-11-25.md +117 -0
- package/docs/records/cut6-c4-verification-2026-11-12.md +268 -0
- package/docs/records/cut6-mailbox-address-envelope-design-2026-11-12.md +871 -0
- package/docs/records/cut7-c7a-red-green-evidence-2026-11-13.md +105 -0
- package/docs/records/cut7-c7a-workunit-implementation-2026-11-13.md +116 -0
- package/docs/records/cut7-c7b-verification-2026-11-14.md +90 -0
- package/docs/records/cut7-live-verification-2026-11-14.md +33 -0
- package/docs/records/cut7-wiring-negative-cache-2026-11-14.md +64 -0
- package/docs/records/cut7-workunit-execution-plan-2026-11-13.md +206 -0
- package/docs/records/cut8-a-entity-keys-design-2026-11-14.md +377 -0
- package/docs/records/cut8-b-turn-delta-injection-2026-11-14.md +362 -0
- package/docs/records/cut8-c-single-clock-2026-11-14.md +119 -0
- package/docs/records/cut8-c-single-clock-design-2026-11-14.md +150 -0
- package/docs/records/cut8-d-2026-11-14.md +231 -0
- package/docs/records/cut8-live-verification-2026-11-14.md +1018 -0
- package/docs/records/cut9-adjacent-identity-paths-2026-11-15.md +200 -0
- package/docs/records/cut9-identity-declaration-2026-11-15.md +163 -0
- package/docs/records/cut9-inbox-dual-run-diff-2026-11-15.md +117 -0
- package/docs/records/cut9-live-verification-2026-11-15.md +222 -0
- package/docs/records/cut9-runtime-probe-2026-11-19.md +520 -0
- package/docs/{design/deliverable-sharing.md → records/deliverable-sharing-2026-08-12.md} +10 -3
- package/docs/records/identity-backlog-disposition-2026-11-22.md +143 -0
- package/docs/records/marketplace-orphan-freeze-2026-11-22.md +239 -0
- package/docs/{architecture/notify-user-context-truth.md → records/notify-user-context-truth-2026-10-28.md} +6 -0
- package/docs/{handoff → records}/remote-access-handoff.md +1 -1
- package/package.json +1 -1
- package/templates/roles/HANDBOOK.md +1 -1
- package/templates/skills/agent-building/SKILL.md +1 -1
- package/dist/web-ui/assets/ChatComponents-Ca9tWI9W.js +0 -12
- package/dist/web-ui/assets/DeliverableShareModal-BvpyowYJ.js +0 -1
- package/dist/web-ui/assets/MarkdownMessage-DedA8Zob.js +0 -4
- package/dist/web-ui/assets/Settings-BQDqf4q5.js +0 -8
- package/dist/web-ui/assets/Switch-C6InTNUi.js +0 -1
- package/dist/web-ui/assets/Team-nfNyWj-s.js +0 -85
- package/dist/web-ui/assets/Work-BQvgkynj.js +0 -142
- package/dist/web-ui/assets/channel-BTSrOo6c.js +0 -1
- package/dist/web-ui/assets/classDiagram-4FO5ZUOK-BSYlcnF9.js +0 -1
- package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-BSYlcnF9.js +0 -1
- package/dist/web-ui/assets/index-CKPQYzzR.js +0 -867
- package/dist/web-ui/assets/index-CzHSs0Vd.css +0 -1
- package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-AVnDjlzF.js +0 -1
- package/docs/api/api.md +0 -353
- package/docs/architecture/llm-provider-timeouts.md +0 -60
- package/docs/architecture/state-ownership.md +0 -83
- /package/docs/architecture/{frontend/team-chat.md → team-chat.md} +0 -0
- /package/docs/{analysis → records}/2026-10-29-a2a-cache-hit-rate.md +0 -0
- /package/docs/{fixes → records}/2026-11-12-session-expiry-and-mention-thinking.md +0 -0
- /package/docs/{handoff → records}/approval-tri-state-handoff.md +0 -0
- /package/docs/{design → records}/overview-attention-redesign.md +0 -0
- /package/docs/{remote-access/fast-path-plan.md → records/remote-access-fast-path-plan-2026-10-17.md} +0 -0
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import{u as He,j as r,b5 as Mf,b6 as Af,a1 as Lf,b7 as _f,r as p,k as te,aq as Rf,a as pr,a3 as Df,n as en,P as tt,b as Of,c as $f,Q as Pf,R as Xi,b8 as Bf,b9 as qf,U as $t,a_ as qt,ba as zr,W as Fr,X as zf,bb as Ra,l as Gn,i as Ff,a4 as bs,d as Hf,bc as Vf,bd as Wf,aP as Kf,be as Oc,bf as Uf,A as Da,aT as Oa,aU as Zi,Z as Yf,t as Gf}from"./index-CKPQYzzR.js";import{S as $c,a as Pc,r as Bc,s as Xf}from"./SendToChat-IOAvuta-.js";import{L as Zf,P as Qf}from"./AsyncState-_UC7xcxJ.js";import{t as qc,Z as zc,_ as Qi,$ as Ji,a0 as Jf,a1 as eh,a2 as Fc,a3 as th,P as nh}from"./ChatComponents-Ca9tWI9W.js";import{MarkdownMessage as or}from"./MarkdownMessage-DedA8Zob.js";import{ContentRenderer as sh}from"./ContentRenderer-C-V5k_3K.js";import{s as zt,g as Hc,j as $a,T as Go,k as Xo,t as rh}from"./transform-BqqRT-Iy.js";import{i as Zo}from"./value-wA6veExk.js";import"./chatChips-DVIRVTpT.js";function oh(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Zt(e,t){if(e=oh(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 ah={passive:!1},ar={capture:!0,passive:!1};function Qo(e){e.stopImmediatePropagation()}function Ss(e){e.preventDefault(),e.stopImmediatePropagation()}function Vc(e){var t=e.document.documentElement,n=zt(e).on("dragstart.drag",Ss,ar);"onselectstart"in t?n.on("selectstart.drag",Ss,ar):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function Wc(e,t){var n=e.document.documentElement,s=zt(e).on("dragstart.drag",null);t&&(s.on("click.drag",Ss,ar),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 Hr=e=>()=>e;function xa(e,{sourceEvent:t,subject:n,target:s,identifier:o,active:a,x:i,y:l,dx:c,dy:d,dispatch:f}){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:f}})}xa.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function ih(e){return!e.ctrlKey&&!e.button}function lh(){return this.parentNode}function ch(e,t){return t??{x:e.x,y:e.y}}function dh(){return navigator.maxTouchPoints||"ontouchstart"in this}function Kc(){var e=ih,t=lh,n=ch,s=dh,o={},a=Hc("start","drag","end"),i=0,l,c,d,f,u=0;function h(w){w.on("mousedown.drag",m).filter(s).on("touchstart.drag",k).on("touchmove.drag",v,ah).on("touchend.drag touchcancel.drag",y).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function m(w,C){if(!(f||!e.call(this,w,C))){var j=x(this,t.call(this,w,C),w,C,"mouse");j&&(zt(w.view).on("mousemove.drag",g,ar).on("mouseup.drag",b,ar),Vc(w.view),Qo(w),d=!1,l=w.clientX,c=w.clientY,j("start",w))}}function g(w){if(Ss(w),!d){var C=w.clientX-l,j=w.clientY-c;d=C*C+j*j>u}o.mouse("drag",w)}function b(w){zt(w.view).on("mousemove.drag mouseup.drag",null),Wc(w.view,d),Ss(w),o.mouse("end",w)}function k(w,C){if(e.call(this,w,C)){var j=w.changedTouches,E=t.call(this,w,C),S=j.length,R,$;for(R=0;R<S;++R)($=x(this,E,w,C,j[R].identifier,j[R]))&&(Qo(w),$("start",w,j[R]))}}function v(w){var C=w.changedTouches,j=C.length,E,S;for(E=0;E<j;++E)(S=o[C[E].identifier])&&(Ss(w),S("drag",w,C[E]))}function y(w){var C=w.changedTouches,j=C.length,E,S;for(f&&clearTimeout(f),f=setTimeout(function(){f=null},500),E=0;E<j;++E)(S=o[C[E].identifier])&&(Qo(w),S("end",w,C[E]))}function x(w,C,j,E,S,R){var $=a.copy(),M=Zt(R||j,C),D,z,I;if((I=n.call(w,new xa("beforestart",{sourceEvent:j,target:h,identifier:S,active:i,x:M[0],y:M[1],dx:0,dy:0,dispatch:$}),E))!=null)return D=I.x-M[0]||0,z=I.y-M[1]||0,function P(L,B,_){var q=M,H;switch(L){case"start":o[S]=P,H=i++;break;case"end":delete o[S],--i;case"drag":M=Zt(_||B,C),H=i;break}$.call(L,w,new xa(L,{sourceEvent:B,subject:I,target:h,identifier:S,active:H,x:M[0]+D,y:M[1]+z,dx:M[0]-q[0],dy:M[1]-q[1],dispatch:$}),E)}}return h.filter=function(w){return arguments.length?(e=typeof w=="function"?w:Hr(!!w),h):e},h.container=function(w){return arguments.length?(t=typeof w=="function"?w:Hr(w),h):t},h.subject=function(w){return arguments.length?(n=typeof w=="function"?w:Hr(w),h):n},h.touchable=function(w){return arguments.length?(s=typeof w=="function"?w:Hr(!!w),h):s},h.on=function(){var w=a.on.apply(a,arguments);return w===a?h:w},h.clickDistance=function(w){return arguments.length?(u=(w=+w)*w,h):Math.sqrt(u)},h}var uh=1e-12;function el(e){return((e=Math.exp(e))+1/e)/2}function fh(e){return((e=Math.exp(e))-1/e)/2}function hh(e){return((e=Math.exp(2*e))-1)/(e+1)}const ao=(function e(t,n,s){function o(a,i){var l=a[0],c=a[1],d=a[2],f=i[0],u=i[1],h=i[2],m=f-l,g=u-c,b=m*m+g*g,k,v;if(b<uh)v=Math.log(h/d)/t,k=function(E){return[l+E*m,c+E*g,d*Math.exp(t*E*v)]};else{var y=Math.sqrt(b),x=(h*h-d*d+s*b)/(2*d*n*y),w=(h*h-d*d-s*b)/(2*h*n*y),C=Math.log(Math.sqrt(x*x+1)-x),j=Math.log(Math.sqrt(w*w+1)-w);v=(j-C)/t,k=function(E){var S=E*v,R=el(C),$=d/(n*y)*(R*hh(t*S+C)-fh(C));return[l+$*m,c+$*g,d*R/el(t*S+C)]}}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),Vr=e=>()=>e;function mh(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 Jo(e){e.stopImmediatePropagation()}function Qs(e){e.preventDefault(),e.stopImmediatePropagation()}function ph(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function gh(){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 tl(){return this.__zoom||$a}function xh(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function bh(){return navigator.maxTouchPoints||"ontouchstart"in this}function yh(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 Uc(){var e=ph,t=gh,n=yh,s=xh,o=bh,a=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],l=250,c=ao,d=Hc("start","zoom","end"),f,u,h,m=500,g=150,b=0,k=10;function v(I){I.property("__zoom",tl).on("wheel.zoom",S,{passive:!1}).on("mousedown.zoom",R).on("dblclick.zoom",$).filter(o).on("touchstart.zoom",M).on("touchmove.zoom",D).on("touchend.zoom touchcancel.zoom",z).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}v.transform=function(I,P,L,B){var _=I.selection?I.selection():I;_.property("__zoom",tl),I!==_?C(I,P,L,B):_.interrupt().each(function(){j(this,arguments).event(B).start().zoom(null,typeof P=="function"?P.apply(this,arguments):P).end()})},v.scaleBy=function(I,P,L,B){v.scaleTo(I,function(){var _=this.__zoom.k,q=typeof P=="function"?P.apply(this,arguments):P;return _*q},L,B)},v.scaleTo=function(I,P,L,B){v.transform(I,function(){var _=t.apply(this,arguments),q=this.__zoom,H=L==null?w(_):typeof L=="function"?L.apply(this,arguments):L,K=q.invert(H),O=typeof P=="function"?P.apply(this,arguments):P;return n(x(y(q,O),H,K),_,i)},L,B)},v.translateBy=function(I,P,L,B){v.transform(I,function(){return n(this.__zoom.translate(typeof P=="function"?P.apply(this,arguments):P,typeof L=="function"?L.apply(this,arguments):L),t.apply(this,arguments),i)},null,B)},v.translateTo=function(I,P,L,B,_){v.transform(I,function(){var q=t.apply(this,arguments),H=this.__zoom,K=B==null?w(q):typeof B=="function"?B.apply(this,arguments):B;return n($a.translate(K[0],K[1]).scale(H.k).translate(typeof P=="function"?-P.apply(this,arguments):-P,typeof L=="function"?-L.apply(this,arguments):-L),q,i)},B,_)};function y(I,P){return P=Math.max(a[0],Math.min(a[1],P)),P===I.k?I:new Go(P,I.x,I.y)}function x(I,P,L){var B=P[0]-L[0]*I.k,_=P[1]-L[1]*I.k;return B===I.x&&_===I.y?I:new Go(I.k,B,_)}function w(I){return[(+I[0][0]+ +I[1][0])/2,(+I[0][1]+ +I[1][1])/2]}function C(I,P,L,B){I.on("start.zoom",function(){j(this,arguments).event(B).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event(B).end()}).tween("zoom",function(){var _=this,q=arguments,H=j(_,q).event(B),K=t.apply(_,q),O=L==null?w(K):typeof L=="function"?L.apply(_,q):L,U=Math.max(K[1][0]-K[0][0],K[1][1]-K[0][1]),A=_.__zoom,T=typeof P=="function"?P.apply(_,q):P,V=c(A.invert(O).concat(U/A.k),T.invert(O).concat(U/T.k));return function(W){if(W===1)W=T;else{var F=V(W),Z=U/F[2];W=new Go(Z,O[0]-F[0]*Z,O[1]-F[1]*Z)}H.zoom(null,W)}})}function j(I,P,L){return!L&&I.__zooming||new E(I,P)}function E(I,P){this.that=I,this.args=P,this.active=0,this.sourceEvent=null,this.extent=t.apply(I,P),this.taps=0}E.prototype={event:function(I){return I&&(this.sourceEvent=I),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(I,P){return this.mouse&&I!=="mouse"&&(this.mouse[1]=P.invert(this.mouse[0])),this.touch0&&I!=="touch"&&(this.touch0[1]=P.invert(this.touch0[0])),this.touch1&&I!=="touch"&&(this.touch1[1]=P.invert(this.touch1[0])),this.that.__zoom=P,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(I){var P=zt(this.that).datum();d.call(I,this.that,new mh(I,{sourceEvent:this.sourceEvent,target:v,transform:this.that.__zoom,dispatch:d}),P)}};function S(I,...P){if(!e.apply(this,arguments))return;var L=j(this,P).event(I),B=this.__zoom,_=Math.max(a[0],Math.min(a[1],B.k*Math.pow(2,s.apply(this,arguments)))),q=Zt(I);if(L.wheel)(L.mouse[0][0]!==q[0]||L.mouse[0][1]!==q[1])&&(L.mouse[1]=B.invert(L.mouse[0]=q)),clearTimeout(L.wheel);else{if(B.k===_)return;L.mouse=[q,B.invert(q)],Xo(this),L.start()}Qs(I),L.wheel=setTimeout(H,g),L.zoom("mouse",n(x(y(B,_),L.mouse[0],L.mouse[1]),L.extent,i));function H(){L.wheel=null,L.end()}}function R(I,...P){if(h||!e.apply(this,arguments))return;var L=I.currentTarget,B=j(this,P,!0).event(I),_=zt(I.view).on("mousemove.zoom",O,!0).on("mouseup.zoom",U,!0),q=Zt(I,L),H=I.clientX,K=I.clientY;Vc(I.view),Jo(I),B.mouse=[q,this.__zoom.invert(q)],Xo(this),B.start();function O(A){if(Qs(A),!B.moved){var T=A.clientX-H,V=A.clientY-K;B.moved=T*T+V*V>b}B.event(A).zoom("mouse",n(x(B.that.__zoom,B.mouse[0]=Zt(A,L),B.mouse[1]),B.extent,i))}function U(A){_.on("mousemove.zoom mouseup.zoom",null),Wc(A.view,B.moved),Qs(A),B.event(A).end()}}function $(I,...P){if(e.apply(this,arguments)){var L=this.__zoom,B=Zt(I.changedTouches?I.changedTouches[0]:I,this),_=L.invert(B),q=L.k*(I.shiftKey?.5:2),H=n(x(y(L,q),B,_),t.apply(this,P),i);Qs(I),l>0?zt(this).transition().duration(l).call(C,H,B,I):zt(this).call(v.transform,H,B,I)}}function M(I,...P){if(e.apply(this,arguments)){var L=I.touches,B=L.length,_=j(this,P,I.changedTouches.length===B).event(I),q,H,K,O;for(Jo(I),H=0;H<B;++H)K=L[H],O=Zt(K,this),O=[O,this.__zoom.invert(O),K.identifier],_.touch0?!_.touch1&&_.touch0[2]!==O[2]&&(_.touch1=O,_.taps=0):(_.touch0=O,q=!0,_.taps=1+!!f);f&&(f=clearTimeout(f)),q&&(_.taps<2&&(u=O[0],f=setTimeout(function(){f=null},m)),Xo(this),_.start())}}function D(I,...P){if(this.__zooming){var L=j(this,P).event(I),B=I.changedTouches,_=B.length,q,H,K,O;for(Qs(I),q=0;q<_;++q)H=B[q],K=Zt(H,this),L.touch0&&L.touch0[2]===H.identifier?L.touch0[0]=K:L.touch1&&L.touch1[2]===H.identifier&&(L.touch1[0]=K);if(H=L.that.__zoom,L.touch1){var U=L.touch0[0],A=L.touch0[1],T=L.touch1[0],V=L.touch1[1],W=(W=T[0]-U[0])*W+(W=T[1]-U[1])*W,F=(F=V[0]-A[0])*F+(F=V[1]-A[1])*F;H=y(H,Math.sqrt(W/F)),K=[(U[0]+T[0])/2,(U[1]+T[1])/2],O=[(A[0]+V[0])/2,(A[1]+V[1])/2]}else if(L.touch0)K=L.touch0[0],O=L.touch0[1];else return;L.zoom("touch",n(x(H,K,O),L.extent,i))}}function z(I,...P){if(this.__zooming){var L=j(this,P).event(I),B=I.changedTouches,_=B.length,q,H;for(Jo(I),h&&clearTimeout(h),h=setTimeout(function(){h=null},m),q=0;q<_;++q)H=B[q],L.touch0&&L.touch0[2]===H.identifier?delete L.touch0:L.touch1&&L.touch1[2]===H.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&&(H=Zt(H,this),Math.hypot(u[0]-H[0],u[1]-H[1])<k)){var K=zt(this).on("dblclick.zoom");K&&K.apply(this,arguments)}}}return v.wheelDelta=function(I){return arguments.length?(s=typeof I=="function"?I:Vr(+I),v):s},v.filter=function(I){return arguments.length?(e=typeof I=="function"?I:Vr(!!I),v):e},v.touchable=function(I){return arguments.length?(o=typeof I=="function"?I:Vr(!!I),v):o},v.extent=function(I){return arguments.length?(t=typeof I=="function"?I:Vr([[+I[0][0],+I[0][1]],[+I[1][0],+I[1][1]]]),v):t},v.scaleExtent=function(I){return arguments.length?(a[0]=+I[0],a[1]=+I[1],v):[a[0],a[1]]},v.translateExtent=function(I){return arguments.length?(i[0][0]=+I[0][0],i[1][0]=+I[1][0],i[0][1]=+I[0][1],i[1][1]=+I[1][1],v):[[i[0][0],i[0][1]],[i[1][0],i[1][1]]]},v.constrain=function(I){return arguments.length?(n=I,v):n},v.duration=function(I){return arguments.length?(l=+I,v):l},v.interpolate=function(I){return arguments.length?(c=I,v):c},v.on=function(){var I=d.on.apply(d,arguments);return I===d?v:I},v.clickDistance=function(I){return arguments.length?(b=(I=+I)*I,v):Math.sqrt(b)},v.tapDistance=function(I){return arguments.length?(k=+I,v):k},v}const Yc=new Set(["completed","failed","rejected","cancelled","archived"]);function ir(e){return!!e&&Yc.has(e)}const Gc=new Set(["completed","rejected","cancelled","archived"]);function wh(e,t={}){const n=[];for(let s=0;s<e.length;s++){const o=e[s];if(o.toStatus!=="review")continue;const a=e[s+1],i=!a,l=`review:${o.id}`,c=t.reviewerId??o.changedById??"",d=t.reviewerName??void 0??o.changedByName??void 0??(o.changedById?t.reviewerNameOf?.(o.changedById):void 0)??c??"reviewer";n.push({id:l,reviewerId:c,reviewerName:d,status:i?"reviewing":"completed",queuedAt:o.createdAt,completedAt:a?a.createdAt:null,round:n.length+1,outcome:a?kh(a.toStatus):null,decidedByName:a?a.changedByName??null:null,note:a?a.reason??null:null})}return n}function kh(e){return e==="completed"?"approved":e==="in_progress"?"revision_requested":"closed"}function nl(e){return e.find(t=>t.status==="reviewing")??null}function vh(e){return e.some(t=>t.status==="reviewing")}function Wr(e){return e?new Date(e).getTime():Number.NaN}function jh(e,t,n="all"){const s=[];if(n!=="review")for(const o of e){const a=o.firstAt??"";Number.isNaN(Wr(a))||s.push({kind:"execution",key:`exec:${o.round}`,round:o.round,startedAt:a,endedAt:o.lastAt??null,toolCount:o.toolCount??0,logCount:o.logCount??0,status:o.status??""})}if(n!=="execution")for(const o of t)Number.isNaN(Wr(o.queuedAt))||s.push({kind:"review",key:o.id,round:o.round,startedAt:o.queuedAt,endedAt:o.completedAt,session:o});return s.sort((o,a)=>{const i=Wr(o.startedAt)-Wr(a.startedAt);return i!==0?i:o.kind!==a.kind?o.kind==="execution"?-1:1:o.round-a.round})}const sl=6e4,Nh=/^(Reviewing task from\b|Task Review$)/;function Sh(e){const t=(e.label??"").trim();return t?Nh.test(t):!1}function Xc(e,t){const n=new Date(e).getTime();if(Number.isNaN(n))return!1;const s=new Date(t.queuedAt).getTime();if(Number.isNaN(s))return!1;const o=t.completedAt?new Date(t.completedAt).getTime():Number.POSITIVE_INFINITY;return Number.isNaN(o)?!1:n>=s-sl&&n<=o+sl}function Ch(e,t){const n=new Date(t.queuedAt).getTime(),s=t.completedAt?new Date(t.completedAt).getTime():Number.POSITIVE_INFINITY;return Number.isNaN(n)||Number.isNaN(s)?[]:e.filter(o=>!Sh(o)||o.taskId&&o.taskId!==t.taskId?!1:Xc(o.startedAt,t)).sort((o,a)=>new Date(o.startedAt).getTime()-new Date(a.startedAt).getTime())}const Eh=["30m","1h","2h","4h","8h","12h","1d","1w"],Ih={"30m":"freq30m","1h":"freq1h","2h":"freq2h","4h":"freq4h","8h":"freq8h","12h":"freq12h","1d":"freq1d","1w":"freq1w"};function rl(e){return Ih[e]??"freq4h"}function Th(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function ba(){return{mode:"calendar",every:"4h",calendar:"daily",weekdays:[1,2,3,4,5],time:"09:00",cron:"",maxRuns:"",timezone:Th()}}function Zc(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 Mh(e){const[t,n]=Zc(e);return`${String(t).padStart(2,"0")}:${String(n).padStart(2,"0")}`}function Ah(e,t,n){if(e==="cron")return"";const[s,o]=Zc(n),a=e==="daily"?"*":e==="weekdays"?"1-5":t.length>0?[...t].sort((i,l)=>i-l).join(","):"*";return`${o} ${s} * * ${a}`}function Lh(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 _h(e){const t=ba();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=Lh(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 Qc(e){const t={};e.mode==="interval"?t.every=e.every||"4h":(t.cron=e.calendar==="cron"?e.cron.trim():Ah(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 Rh=[1,2,3,4,5,6,0];function Dh({options:e,value:t,onChange:n,size:s="md"}){const o=s==="sm"?"px-2.5 py-1 text-xs":"px-3 py-1.5 text-sm";return r.jsx("div",{className:"inline-flex rounded-lg border border-border-default overflow-hidden",children:e.map(a=>r.jsx("button",{type:"button",onClick:()=>n(a.value),className:`${o} transition-colors ${t===a.value?"bg-brand-600 text-on-brand":"bg-surface-elevated text-fg-secondary hover:text-fg-primary"}`,children:a.label},a.value))})}function Jc({value:e,onChange:t,compact:n=!1}){const{t:s}=He(),o=f=>t({...e,...f}),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=f=>{const h=e.weekdays.includes(f)?e.weekdays.filter(m=>m!==f):[...e.weekdays,f];o({weekdays:h})};let l;if(e.mode==="interval")l=s(`work:task.${rl(e.every)}`);else if(e.calendar==="cron")l=s("work:task.scheduleCron",{expr:e.cron.trim()||"—"});else{const f=Mh(e.time);if(e.calendar==="daily")l=s("work:task.scheduleDailyAt",{time:f});else if(e.calendar==="weekdays")l=s("work:task.scheduleWeekdaysAt",{time:f});else{const u=[...e.weekdays].sort((h,m)=>h-m).map(h=>s(`work:task.weekdayShort.${h}`)).join(" ");l=e.weekdays.length?s("work:task.scheduleWeeklyAt",{days:u,time:f}):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(Dh,{size:n?"sm":"md",value:e.mode,onChange:f=>o({mode:f}),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:f=>o({every:f.target.value}),className:a,children:Eh.map(f=>r.jsx("option",{value:f,children:s(`work:task.${rl(f)}`)},f))})]}):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:f=>o({calendar:f.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:f=>o({time:f.target.value}),className:a})]}),e.calendar==="weekly"&&r.jsx("div",{className:"flex flex-wrap gap-1 pl-[5.5rem]",children:Rh.map(f=>{const u=e.weekdays.includes(f);return r.jsx("button",{type:"button",onClick:()=>i(f),className:`w-7 h-7 rounded-full text-xs transition-colors ${u?"bg-brand-600 text-on-brand":"bg-surface-elevated text-fg-secondary border border-border-default hover:text-fg-primary"}`,children:s(`work:task.weekdayShort.${f}`)},f)})}),e.calendar==="cron"&&r.jsx("input",{value:e.cron,onChange:f=>o({cron:f.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:f=>o({maxRuns:f.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 Nt(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=Nt(e[n]))!==""&&(t+=(t&&" ")+s);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}const an={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."},lr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ed=["Enter"," ","Escape"],td={"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 Is;(function(e){e.Strict="strict",e.Loose="loose"})(Is||(Is={}));var Jn;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Jn||(Jn={}));var cr;(function(e){e.Partial="partial",e.Full="full"})(cr||(cr={}));const nd={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Tn;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Tn||(Tn={}));var Ts;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Ts||(Ts={}));var we;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(we||(we={}));const ol={[we.Left]:we.Right,[we.Right]:we.Left,[we.Top]:we.Bottom,[we.Bottom]:we.Top};function sd(e){return e===null?null:e?"valid":"invalid"}const rd=e=>"id"in e&&"source"in e&&"target"in e,Oh=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Pa=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),gr=(e,t=[0,0])=>{const{width:n,height:s}=yn(e),o=e.origin??t,a=n*o[0],i=s*o[1];return{x:e.position.x-a,y:e.position.y-i}},$h=(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):Pa(o)?o:t.nodeLookup.get(o.id));const l=i?mo(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return So(s,l)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Co(n)},xr=(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=So(n,mo(o)),s=!0)}),s?Co(n):{x:0,y:0,width:0,height:0}},Ba=(e,t,[n,s,o]=[0,0,1],a=!1,i=!1)=>{const l={...yr(t,[n,s,o]),width:t.width/o,height:t.height/o},c=[];for(const d of e.values()){const{measured:f,selectable:u=!0,hidden:h=!1}=d;if(i&&!u||h)continue;const m=f.width??d.width??d.initialWidth??null,g=f.height??d.height??d.initialHeight??null,b=dr(l,As(d)),k=(m??0)*(g??0),v=a&&b>0;(!d.internals.handleBounds||v||b>=k||d.dragging)&&c.push(d)}return c},Ph=(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 Bh(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 qh({nodes:e,width:t,height:n,panZoom:s,minZoom:o,maxZoom:a},i){if(e.size===0)return Promise.resolve(!0);const l=Bh(e,i),c=xr(l),d=qa(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 od({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},f=i.origin??s;let u=i.extent||o;if(i.extent==="parent"&&!i.expandParent)if(!l)a?.("005",an.error005());else{const m=l.measured.width,g=l.measured.height;m&&g&&(u=[[c,d],[c+m,d+g]])}else l&&Ls(i.extent)&&(u=[[i.extent[0][0]+c,i.extent[0][1]+d],[i.extent[1][0]+c,i.extent[1][1]+d]]);const h=Ls(u)?es(t,u,i.measured):t;return(i.measured.width===void 0||i.measured.height===void 0)&&a?.("015",an.error015()),{position:{x:h.x-c+(i.measured.width??0)*f[0],y:h.y-d+(i.measured.height??0)*f[1]},positionAbsolute:h}}async function zh({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:s,onBeforeDelete:o}){const a=new Set(e.map(h=>h.id)),i=[];for(const h of n){if(h.deletable===!1)continue;const m=a.has(h.id),g=!m&&h.parentId&&i.find(b=>b.id===h.parentId);(m||g)&&i.push(h)}const l=new Set(t.map(h=>h.id)),c=s.filter(h=>h.deletable!==!1),f=Ph(i,c);for(const h of c)l.has(h.id)&&!f.find(g=>g.id===h.id)&&f.push(h);if(!o)return{edges:f,nodes:i};const u=await o({nodes:i,edges:f});return typeof u=="boolean"?u?{edges:f,nodes:i}:{edges:[],nodes:[]}:u}const Ms=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),es=(e={x:0,y:0},t,n)=>({x:Ms(e.x,t[0][0],t[1][0]-(n?.width??0)),y:Ms(e.y,t[0][1],t[1][1]-(n?.height??0))});function ad(e,t,n){const{width:s,height:o}=yn(n),{x:a,y:i}=n.internals.positionAbsolute;return es(e,[[a,i],[a+s,i+o]],t)}const al=(e,t,n)=>e<t?Ms(Math.abs(e-t),1,t)/t:e>n?-Ms(Math.abs(e-n),1,t)/t:0,id=(e,t,n=15,s=40)=>{const o=al(e.x,s,t.width-s)*n,a=al(e.y,s,t.height-s)*n;return[o,a]},So=(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)}),ya=({x:e,y:t,width:n,height:s})=>({x:e,y:t,x2:e+n,y2:t+s}),Co=({x:e,y:t,x2:n,y2:s})=>({x:e,y:t,width:n-e,height:s-t}),As=(e,t=[0,0])=>{const{x:n,y:s}=Pa(e)?e.internals.positionAbsolute:gr(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}},mo=(e,t=[0,0])=>{const{x:n,y:s}=Pa(e)?e.internals.positionAbsolute:gr(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)}},ld=(e,t)=>Co(So(ya(e),ya(t))),dr=(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)},il=e=>Qt(e.width)&&Qt(e.height)&&Qt(e.x)&&Qt(e.y),Qt=e=>!isNaN(e)&&isFinite(e),Fh=(e,t)=>{},br=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),yr=({x:e,y:t},[n,s,o],a=!1,i=[1,1])=>{const l={x:(e-n)/o,y:(t-s)/o};return a?br(l,i):l},po=({x:e,y:t},[n,s,o])=>({x:e*o+n,y:t*o+s});function ps(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 Hh(e,t,n){if(typeof e=="string"||typeof e=="number"){const s=ps(e,n),o=ps(e,t);return{top:s,right:o,bottom:s,left:o,x:o*2,y:s*2}}if(typeof e=="object"){const s=ps(e.top??e.y??0,n),o=ps(e.bottom??e.y??0,n),a=ps(e.left??e.x??0,t),i=ps(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 Vh(e,t,n,s,o,a){const{x:i,y:l}=po(e,[t,n,s]),{x:c,y:d}=po({x:e.x+e.width,y:e.y+e.height},[t,n,s]),f=o-c,u=a-d;return{left:Math.floor(i),top:Math.floor(l),right:Math.floor(f),bottom:Math.floor(u)}}const qa=(e,t,n,s,o,a)=>{const i=Hh(a,t,n),l=(t-i.x)/e.width,c=(n-i.y)/e.height,d=Math.min(l,c),f=Ms(d,s,o),u=e.x+e.width/2,h=e.y+e.height/2,m=t/2-u*f,g=n/2-h*f,b=Vh(e,m,g,f,t,n),k={left:Math.min(b.left-i.left,0),top:Math.min(b.top-i.top,0),right:Math.min(b.right-i.right,0),bottom:Math.min(b.bottom-i.bottom,0)};return{x:m-k.left+k.right,y:g-k.top+k.bottom,zoom:f}},ur=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Ls(e){return e!=null&&e!=="parent"}function yn(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function cd(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function dd(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 ll(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function Wh(){let e,t;return{promise:new Promise((s,o)=>{e=s,t=o}),resolve:e,reject:t}}function Kh(e){return{...td,...e||{}}}function nr(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:s,containerBounds:o}){const{x:a,y:i}=Jt(e),l=yr({x:a-(o?.left??0),y:i-(o?.top??0)},s),{x:c,y:d}=n?br(l,t):l;return{xSnapped:c,ySnapped:d,...l}}const za=e=>({width:e.offsetWidth,height:e.offsetHeight}),ud=e=>e?.getRootNode?.()||window?.document,Uh=["INPUT","SELECT","TEXTAREA"];function fd(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:Uh.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const hd=e=>"clientX"in e,Jt=(e,t)=>{const n=hd(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)}},cl=(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,...za(i)}})};function md({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,f=Math.abs(c-e),u=Math.abs(d-t);return[c,d,f,u]}function Kr(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function dl({pos:e,x1:t,y1:n,x2:s,y2:o,c:a}){switch(e){case we.Left:return[t-Kr(t-s,a),n];case we.Right:return[t+Kr(s-t,a),n];case we.Top:return[t,n-Kr(n-o,a)];case we.Bottom:return[t,n+Kr(o-n,a)]}}function pd({sourceX:e,sourceY:t,sourcePosition:n=we.Bottom,targetX:s,targetY:o,targetPosition:a=we.Top,curvature:i=.25}){const[l,c]=dl({pos:n,x1:e,y1:t,x2:s,y2:o,c:i}),[d,f]=dl({pos:a,x1:s,y1:o,x2:e,y2:t,c:i}),[u,h,m,g]=md({sourceX:e,sourceY:t,targetX:s,targetY:o,sourceControlX:l,sourceControlY:c,targetControlX:d,targetControlY:f});return[`M${e},${t} C${l},${c} ${d},${f} ${s},${o}`,u,h,m,g]}function gd({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 Yh({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 Gh({sourceNode:e,targetNode:t,width:n,height:s,transform:o}){const a=So(mo(e),mo(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 dr(i,Co(a))>0}const Xh=({source:e,sourceHandle:t,target:n,targetHandle:s})=>`xy-edge__${e}${t||""}-${n}${s||""}`,Zh=(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)),Qh=(e,t,n={})=>{if(!e.source||!e.target)return t;const s=n.getEdgeId||Xh;let o;return rd(e)?o={...e}:o={...e,id:s(e)},Zh(o,t)?t:(o.sourceHandle===null&&delete o.sourceHandle,o.targetHandle===null&&delete o.targetHandle,t.concat(o))};function xd({sourceX:e,sourceY:t,targetX:n,targetY:s}){const[o,a,i,l]=gd({sourceX:e,sourceY:t,targetX:n,targetY:s});return[`M ${e},${t}L ${n},${s}`,o,a,i,l]}const ul={[we.Left]:{x:-1,y:0},[we.Right]:{x:1,y:0},[we.Top]:{x:0,y:-1},[we.Bottom]:{x:0,y:1}},Jh=({source:e,sourcePosition:t=we.Bottom,target:n})=>t===we.Left||t===we.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},fl=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function em({source:e,sourcePosition:t=we.Bottom,target:n,targetPosition:s=we.Top,center:o,offset:a,stepPosition:i}){const l=ul[t],c=ul[s],d={x:e.x+l.x*a,y:e.y+l.y*a},f={x:n.x+c.x*a,y:n.y+c.y*a},u=Jh({source:d,sourcePosition:t,target:f}),h=u.x!==0?"x":"y",m=u[h];let g=[],b,k;const v={x:0,y:0},y={x:0,y:0},[,,x,w]=gd({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(l[h]*c[h]===-1){h==="x"?(b=o.x??d.x+(f.x-d.x)*i,k=o.y??(d.y+f.y)/2):(b=o.x??(d.x+f.x)/2,k=o.y??d.y+(f.y-d.y)*i);const j=[{x:b,y:d.y},{x:b,y:f.y}],E=[{x:d.x,y:k},{x:f.x,y:k}];l[h]===m?g=h==="x"?j:E:g=h==="x"?E:j}else{const j=[{x:d.x,y:f.y}],E=[{x:f.x,y:d.y}];if(h==="x"?g=l.x===m?E:j:g=l.y===m?j:E,t===s){const D=Math.abs(e[h]-n[h]);if(D<=a){const z=Math.min(a-1,a-D);l[h]===m?v[h]=(d[h]>e[h]?-1:1)*z:y[h]=(f[h]>n[h]?-1:1)*z}}if(t!==s){const D=h==="x"?"y":"x",z=l[h]===c[D],I=d[D]>f[D],P=d[D]<f[D];(l[h]===1&&(!z&&I||z&&P)||l[h]!==1&&(!z&&P||z&&I))&&(g=h==="x"?j:E)}const S={x:d.x+v.x,y:d.y+v.y},R={x:f.x+y.x,y:f.y+y.y},$=Math.max(Math.abs(S.x-g[0].x),Math.abs(R.x-g[0].x)),M=Math.max(Math.abs(S.y-g[0].y),Math.abs(R.y-g[0].y));$>=M?(b=(S.x+R.x)/2,k=g[0].y):(b=g[0].x,k=(S.y+R.y)/2)}return[[e,{x:d.x+v.x,y:d.y+v.y},...g,{x:f.x+y.x,y:f.y+y.y},n],b,k,x,w]}function tm(e,t,n,s){const o=Math.min(fl(e,t)/2,fl(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,f=e.y<n.y?1:-1;return`L ${a+o*d},${i}Q ${a},${i} ${a},${i+o*f}`}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 wa({sourceX:e,sourceY:t,sourcePosition:n=we.Bottom,targetX:s,targetY:o,targetPosition:a=we.Top,borderRadius:i=5,centerX:l,centerY:c,offset:d=20,stepPosition:f=.5}){const[u,h,m,g,b]=em({source:{x:e,y:t},sourcePosition:n,target:{x:s,y:o},targetPosition:a,center:{x:l,y:c},offset:d,stepPosition:f});return[u.reduce((v,y,x)=>{let w="";return x>0&&x<u.length-1?w=tm(u[x-1],y,u[x+1],i):w=`${x===0?"M":"L"}${y.x} ${y.y}`,v+=w,v},""),h,m,g,b]}function hl(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function nm(e){const{sourceNode:t,targetNode:n}=e;if(!hl(t)||!hl(n))return null;const s=t.internals.handleBounds||ml(t.handles),o=n.internals.handleBounds||ml(n.handles),a=pl(s?.source??[],e.sourceHandle),i=pl(e.connectionMode===Is.Strict?o?.target??[]:(o?.target??[]).concat(o?.source??[]),e.targetHandle);if(!a||!i)return e.onError?.("008",an.error008(a?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const l=a?.position||we.Bottom,c=i?.position||we.Top,d=ts(t,a,l),f=ts(n,i,c);return{sourceX:d.x,sourceY:d.y,targetX:f.x,targetY:f.y,sourcePosition:l,targetPosition:c}}function ml(e){if(!e)return null;const t=[],n=[];for(const s of e)s.width=s.width??1,s.height=s.height??1,s.type==="source"?t.push(s):s.type==="target"&&n.push(s);return{source:t,target:n}}function ts(e,t,n=we.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??yn(e);if(s)return{x:o+i/2,y:a+l/2};switch(t?.position??n){case we.Top:return{x:o+i/2,y:a};case we.Right:return{x:o+i,y:a+l/2};case we.Bottom:return{x:o+i/2,y:a+l};case we.Left:return{x:o,y:a+l/2}}}function pl(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function ka(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(s=>`${s}=${e[s]}`).join("&")}`:""}function sm(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=ka(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 bd=1e3,rm=10,Fa={nodeOrigin:[0,0],nodeExtent:lr,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},om={...Fa,checkEquality:!0};function Ha(e,t){const n={...e};for(const s in t)t[s]!==void 0&&(n[s]=t[s]);return n}function am(e,t,n){const s=Ha(Fa,n);for(const o of e.values())if(o.parentId)Wa(o,e,t,s);else{const a=gr(o,s.nodeOrigin),i=Ls(o.extent)?o.extent:s.nodeExtent,l=es(a,i,yn(o));o.internals.positionAbsolute=l}}function im(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 Va(e){return e==="manual"}function va(e,t,n,s={}){const o=Ha(om,s),a={i:0},i=new Map(t),l=o?.elevateNodesOnSelect&&!Va(o.zIndexMode)?bd:0;let c=e.length>0;t.clear(),n.clear();for(const d of e){let f=i.get(d.id);if(o.checkEquality&&d===f?.internals.userNode)t.set(d.id,f);else{const u=gr(d,o.nodeOrigin),h=Ls(d.extent)?d.extent:o.nodeExtent,m=es(u,h,yn(d));f={...o.defaults,...d,measured:{width:d.measured?.width,height:d.measured?.height},internals:{positionAbsolute:m,handleBounds:im(d,f),z:yd(d,l,o.zIndexMode),userNode:d}},t.set(d.id,f)}(f.measured===void 0||f.measured.width===void 0||f.measured.height===void 0)&&!f.hidden&&(c=!1),d.parentId&&Wa(f,t,n,s,a)}return c}function lm(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 Wa(e,t,n,s,o){const{elevateNodesOnSelect:a,nodeOrigin:i,nodeExtent:l,zIndexMode:c}=Ha(Fa,s),d=e.parentId,f=t.get(d);if(!f){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}lm(e,n),o&&!f.parentId&&f.internals.rootParentIndex===void 0&&c==="auto"&&(f.internals.rootParentIndex=++o.i,f.internals.z=f.internals.z+o.i*rm),o&&f.internals.rootParentIndex!==void 0&&(o.i=f.internals.rootParentIndex);const u=a&&!Va(c)?bd:0,{x:h,y:m,z:g}=cm(e,f,i,l,u,c),{positionAbsolute:b}=e.internals,k=h!==b.x||m!==b.y;(k||g!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:k?{x:h,y:m}:b,z:g}})}function yd(e,t,n){const s=Qt(e.zIndex)?e.zIndex:0;return Va(n)?s:s+(e.selected?t:0)}function cm(e,t,n,s,o,a){const{x:i,y:l}=t.internals.positionAbsolute,c=yn(e),d=gr(e,n),f=Ls(e.extent)?es(d,e.extent,c):d;let u=es({x:i+f.x,y:l+f.y},s,c);e.extent==="parent"&&(u=ad(u,c,t));const h=yd(e,o,a),m=t.internals.z??0;return{x:u.x,y:u.y,z:m>=h?m+1:h}}function Ka(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??As(l),d=ld(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,f=yn(l),u=l.origin??s,h=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(f.width,Math.round(i.width)),b=Math.max(f.height,Math.round(i.height)),k=(g-f.width)*u[0],v=(b-f.height)*u[1];(h>0||m>0||k||v)&&(o.push({id:c,type:"position",position:{x:l.position.x-h+k,y:l.position.y-m+v}}),n.get(c)?.forEach(y=>{e.some(x=>x.id===y.id)||o.push({id:y.id,type:"position",position:{x:y.position.x+h,y:y.position.y+m}})})),(f.width<i.width||f.height<i.height||h||m)&&o.push({id:c,type:"dimensions",setAttributes:!0,dimensions:{width:g+(h?u[0]*h-k:0),height:b+(m?u[1]*m-v:0)}})}),o}function dm(e,t,n,s,o,a,i){const l=s?.querySelector(".xyflow__viewport");let c=!1;if(!l)return{changes:[],updatedInternals:c};const d=[],f=window.getComputedStyle(l),{m22:u}=new window.DOMMatrixReadOnly(f.transform),h=[];for(const m of e.values()){const g=t.get(m.id);if(!g)continue;if(g.hidden){t.set(g.id,{...g,internals:{...g.internals,handleBounds:void 0}}),c=!0;continue}const b=za(m.nodeElement),k=g.measured.width!==b.width||g.measured.height!==b.height;if(!!(b.width&&b.height&&(k||!g.internals.handleBounds||m.force))){const y=m.nodeElement.getBoundingClientRect(),x=Ls(g.extent)?g.extent:a;let{positionAbsolute:w}=g.internals;g.parentId&&g.extent==="parent"?w=ad(w,b,t.get(g.parentId)):x&&(w=es(w,x,b));const C={...g,measured:b,internals:{...g.internals,positionAbsolute:w,handleBounds:{source:cl("source",m.nodeElement,y,u,g.id),target:cl("target",m.nodeElement,y,u,g.id)}}};t.set(g.id,C),g.parentId&&Wa(C,t,n,{nodeOrigin:o,zIndexMode:i}),c=!0,k&&(d.push({id:g.id,type:"dimensions",dimensions:b}),g.expandParent&&g.parentId&&h.push({id:g.id,parentId:g.parentId,rect:As(C,o)}))}}if(h.length>0){const m=Ka(h,t,n,o);d.push(...m)}return{changes:d,updatedInternals:c}}async function um({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 gl(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 wd(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}`,f=`${a}-${l}--${o}-${i}`;gl("source",c,f,e,o,i),gl("target",c,d,e,a,l),t.set(s.id,s)}}function kd(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:kd(n,t):!1}function xl(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 fm(e,t,n,s){const o=new Map;for(const[a,i]of e)if((i.selected||i.id===s)&&(!i.parentId||!kd(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 ea({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 hm({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=br(a,t);return{x:i.x-a.x,y:i.y-a.y}}function mm({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},f=null,u=!1,h=null,m=!1,g=!1,b=null;function k({noDragClassName:y,handleSelector:x,domNode:w,isSelectable:C,nodeId:j,nodeClickDistance:E=0}){h=zt(w);function S({x:D,y:z}){const{nodeLookup:I,nodeExtent:P,snapGrid:L,snapToGrid:B,nodeOrigin:_,onNodeDrag:q,onSelectionDrag:H,onError:K,updateNodePositions:O}=t();a={x:D,y:z};let U=!1;const A=l.size>1,T=A&&P?ya(xr(l)):null,V=A&&B?hm({dragItems:l,snapGrid:L,x:D,y:z}):null;for(const[W,F]of l){if(!I.has(W))continue;let Z={x:D-F.distance.x,y:z-F.distance.y};B&&(Z=V?{x:Math.round(Z.x+V.x),y:Math.round(Z.y+V.y)}:br(Z,L));let se=null;if(A&&P&&!F.extent&&T){const{positionAbsolute:pe}=F.internals,je=pe.x-T.x+P[0][0],Se=pe.x+F.measured.width-T.x2+P[1][0],Ne=pe.y-T.y+P[0][1],Be=pe.y+F.measured.height-T.y2+P[1][1];se=[[je,Ne],[Se,Be]]}const{position:ue,positionAbsolute:ie}=od({nodeId:W,nextPosition:Z,nodeLookup:I,nodeExtent:se||P,nodeOrigin:_,onError:K});U=U||F.position.x!==ue.x||F.position.y!==ue.y,F.position=ue,F.internals.positionAbsolute=ie}if(g=g||U,!!U&&(O(l,!0),b&&(s||q||!j&&H))){const[W,F]=ea({nodeId:j,dragItems:l,nodeLookup:I});s?.(b,l,W,F),q?.(b,W,F),j||H?.(b,F)}}async function R(){if(!f)return;const{transform:D,panBy:z,autoPanSpeed:I,autoPanOnNodeDrag:P}=t();if(!P){c=!1,cancelAnimationFrame(i);return}const[L,B]=id(d,f,I);(L!==0||B!==0)&&(a.x=(a.x??0)-L/D[2],a.y=(a.y??0)-B/D[2],await z({x:L,y:B})&&S(a)),i=requestAnimationFrame(R)}function $(D){const{nodeLookup:z,multiSelectionActive:I,nodesDraggable:P,transform:L,snapGrid:B,snapToGrid:_,selectNodesOnDrag:q,onNodeDragStart:H,onSelectionDragStart:K,unselectNodesAndEdges:O}=t();u=!0,(!q||!C)&&!I&&j&&(z.get(j)?.selected||O()),C&&q&&j&&e?.(j);const U=nr(D.sourceEvent,{transform:L,snapGrid:B,snapToGrid:_,containerBounds:f});if(a=U,l=fm(z,P,U,j),l.size>0&&(n||H||!j&&K)){const[A,T]=ea({nodeId:j,dragItems:l,nodeLookup:z});n?.(D.sourceEvent,l,A,T),H?.(D.sourceEvent,A,T),j||K?.(D.sourceEvent,T)}}const M=Kc().clickDistance(E).on("start",D=>{const{domNode:z,nodeDragThreshold:I,transform:P,snapGrid:L,snapToGrid:B}=t();f=z?.getBoundingClientRect()||null,m=!1,g=!1,b=D.sourceEvent,I===0&&$(D),a=nr(D.sourceEvent,{transform:P,snapGrid:L,snapToGrid:B,containerBounds:f}),d=Jt(D.sourceEvent,f)}).on("drag",D=>{const{autoPanOnNodeDrag:z,transform:I,snapGrid:P,snapToGrid:L,nodeDragThreshold:B,nodeLookup:_}=t(),q=nr(D.sourceEvent,{transform:I,snapGrid:P,snapToGrid:L,containerBounds:f});if(b=D.sourceEvent,(D.sourceEvent.type==="touchmove"&&D.sourceEvent.touches.length>1||j&&!_.has(j))&&(m=!0),!m){if(!c&&z&&u&&(c=!0,R()),!u){const H=Jt(D.sourceEvent,f),K=H.x-d.x,O=H.y-d.y;Math.sqrt(K*K+O*O)>B&&$(D)}(a.x!==q.xSnapped||a.y!==q.ySnapped)&&l&&u&&(d=Jt(D.sourceEvent,f),S(q))}}).on("end",D=>{if(!(!u||m)&&(c=!1,u=!1,cancelAnimationFrame(i),l.size>0)){const{nodeLookup:z,updateNodePositions:I,onNodeDragStop:P,onSelectionDragStop:L}=t();if(g&&(I(l,!1),g=!1),o||P||!j&&L){const[B,_]=ea({nodeId:j,dragItems:l,nodeLookup:z,dragging:!1});o?.(D.sourceEvent,l,B,_),P?.(D.sourceEvent,B,_),j||L?.(D.sourceEvent,_)}}}).filter(D=>{const z=D.target;return!D.button&&(!y||!xl(z,`.${y}`,w))&&(!x||xl(z,x,w))});h.call(M)}function v(){h?.on(".drag",null)}return{update:k,destroy:v}}function pm(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())dr(o,As(a))>0&&s.push(a);return s}const gm=250;function xm(e,t,n,s){let o=[],a=1/0;const i=pm(e,n,t+gm);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:f,y:u}=ts(l,d,d.position,!0),h=Math.sqrt(Math.pow(f-e.x,2)+Math.pow(u-e.y,2));h>t||(h<a?(o=[{...d,x:f,y:u}],a=h):h===a&&o.push({...d,x:f,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 vd(e,t,n,s,o,a=!1){const i=s.get(e);if(!i)return null;const l=o==="strict"?i.internals.handleBounds?.[t]:[...i.internals.handleBounds?.source??[],...i.internals.handleBounds?.target??[]],c=(n?l?.find(d=>d.id===n):l?.[0])??null;return c&&a?{...c,...ts(i,c,c.position,!0)}:c}function jd(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function bm(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const Nd=()=>!0;function ym(e,{connectionMode:t,connectionRadius:n,handleId:s,nodeId:o,edgeUpdaterType:a,isTarget:i,domNode:l,nodeLookup:c,lib:d,autoPanOnConnect:f,flowId:u,panBy:h,cancelConnection:m,onConnectStart:g,onConnect:b,onConnectEnd:k,isValidConnection:v=Nd,onReconnectEnd:y,updateConnection:x,getTransform:w,getFromHandle:C,autoPanSpeed:j,dragThreshold:E=1,handleDomNode:S}){const R=ud(e.target);let $=0,M;const{x:D,y:z}=Jt(e),I=jd(a,S),P=l?.getBoundingClientRect();let L=!1;if(!P||!I)return;const B=vd(o,I,s,c,t);if(!B)return;let _=Jt(e,P),q=!1,H=null,K=!1,O=null;function U(){if(!f||!P)return;const[ue,ie]=id(_,P,j);h({x:ue,y:ie}),$=requestAnimationFrame(U)}const A={...B,nodeId:o,type:I,position:B.position},T=c.get(o);let W={inProgress:!0,isValid:null,from:ts(T,A,we.Left,!0),fromHandle:A,fromPosition:A.position,fromNode:T,to:_,toHandle:null,toPosition:ol[A.position],toNode:null,pointer:_};function F(){L=!0,x(W),g?.(e,{nodeId:o,handleId:s,handleType:I})}E===0&&F();function Z(ue){if(!L){const{x:Be,y:$e}=Jt(ue),Ie=Be-D,Ve=$e-z;if(!(Ie*Ie+Ve*Ve>E*E))return;F()}if(!C()||!A){se(ue);return}const ie=w();_=Jt(ue,P),M=xm(yr(_,ie,!1,[1,1]),n,c,A),q||(U(),q=!0);const pe=Sd(ue,{handle:M,connectionMode:t,fromNodeId:o,fromHandleId:s,fromType:i?"target":"source",isValidConnection:v,doc:R,lib:d,flowId:u,nodeLookup:c});O=pe.handleDomNode,H=pe.connection,K=bm(!!M,pe.isValid);const je=c.get(o),Se=je?ts(je,A,we.Left,!0):W.from,Ne={...W,from:Se,isValid:K,to:pe.toHandle&&K?po({x:pe.toHandle.x,y:pe.toHandle.y},ie):_,toHandle:pe.toHandle,toPosition:K&&pe.toHandle?pe.toHandle.position:ol[A.position],toNode:pe.toHandle?c.get(pe.toHandle.nodeId):null,pointer:_};x(Ne),W=Ne}function se(ue){if(!("touches"in ue&&ue.touches.length>0)){if(L){(M||O)&&H&&K&&b?.(H);const{inProgress:ie,...pe}=W,je={...pe,toPosition:W.toHandle?W.toPosition:null};k?.(ue,je),a&&y?.(ue,je)}m(),cancelAnimationFrame($),q=!1,K=!1,H=null,O=null,R.removeEventListener("mousemove",Z),R.removeEventListener("mouseup",se),R.removeEventListener("touchmove",Z),R.removeEventListener("touchend",se)}}R.addEventListener("mousemove",Z),R.addEventListener("mouseup",se),R.addEventListener("touchmove",Z),R.addEventListener("touchend",se)}function Sd(e,{handle:t,connectionMode:n,fromNodeId:s,fromHandleId:o,fromType:a,doc:i,lib:l,flowId:c,isValidConnection:d=Nd,nodeLookup:f}){const u=a==="target",h=t?i.querySelector(`.${l}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:m,y:g}=Jt(e),b=i.elementFromPoint(m,g),k=b?.classList.contains(`${l}-flow__handle`)?b:h,v={handleDomNode:k,isValid:!1,connection:null,toHandle:null};if(k){const y=jd(void 0,k),x=k.getAttribute("data-nodeid"),w=k.getAttribute("data-handleid"),C=k.classList.contains("connectable"),j=k.classList.contains("connectableend");if(!x||!y)return v;const E={source:u?x:s,sourceHandle:u?w:o,target:u?s:x,targetHandle:u?o:w};v.connection=E;const R=C&&j&&(n===Is.Strict?u&&y==="source"||!u&&y==="target":x!==s||w!==o);v.isValid=R&&d(E),v.toHandle=vd(x,y,w,f,n,!0)}return v}const ja={onPointerDown:ym,isValid:Sd};function wm({domNode:e,panZoom:t,getTransform:n,getViewScale:s}){const o=zt(e);function a({translateExtent:l,width:c,height:d,zoomStep:f=1,pannable:u=!0,zoomable:h=!0,inversePan:m=!1}){const g=x=>{if(x.sourceEvent.type!=="wheel"||!t)return;const w=n(),C=x.sourceEvent.ctrlKey&&ur()?10:1,j=-x.sourceEvent.deltaY*(x.sourceEvent.deltaMode===1?.05:x.sourceEvent.deltaMode?1:.002)*f,E=w[2]*Math.pow(2,j*C);t.scaleTo(E)};let b=[0,0];const k=x=>{(x.sourceEvent.type==="mousedown"||x.sourceEvent.type==="touchstart")&&(b=[x.sourceEvent.clientX??x.sourceEvent.touches[0].clientX,x.sourceEvent.clientY??x.sourceEvent.touches[0].clientY])},v=x=>{const w=n();if(x.sourceEvent.type!=="mousemove"&&x.sourceEvent.type!=="touchmove"||!t)return;const C=[x.sourceEvent.clientX??x.sourceEvent.touches[0].clientX,x.sourceEvent.clientY??x.sourceEvent.touches[0].clientY],j=[C[0]-b[0],C[1]-b[1]];b=C;const E=s()*Math.max(w[2],Math.log(w[2]))*(m?-1:1),S={x:w[0]-j[0]*E,y:w[1]-j[1]*E},R=[[0,0],[c,d]];t.setViewportConstrained({x:S.x,y:S.y,zoom:w[2]},R,l)},y=Uc().on("start",k).on("zoom",u?v:null).on("zoom.wheel",h?g:null);o.call(y,{})}function i(){o.on("zoom",null)}return{update:a,destroy:i,pointer:Zt}}const Eo=e=>({x:e.x,y:e.y,zoom:e.k}),ta=({x:e,y:t,zoom:n})=>$a.translate(e,t).scale(n),ys=(e,t)=>e.target.closest(`.${t}`),Cd=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),km=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,na=(e,t=0,n=km,s=()=>{})=>{const o=typeof t=="number"&&t>0;return o||s(),o?e.transition().duration(t).ease(n).on("end",s):e},Ed=e=>{const t=e.ctrlKey&&ur()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function vm({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:s,panOnScrollMode:o,panOnScrollSpeed:a,zoomOnPinch:i,onPanZoomStart:l,onPanZoom:c,onPanZoomEnd:d}){return f=>{if(ys(f,t))return f.ctrlKey&&f.preventDefault(),!1;f.preventDefault(),f.stopImmediatePropagation();const u=n.property("__zoom").k||1;if(f.ctrlKey&&i){const k=Zt(f),v=Ed(f),y=u*Math.pow(2,v);s.scaleTo(n,y,k,f);return}const h=f.deltaMode===1?20:1;let m=o===Jn.Vertical?0:f.deltaX*h,g=o===Jn.Horizontal?0:f.deltaY*h;!ur()&&f.shiftKey&&o!==Jn.Vertical&&(m=f.deltaY*h,g=0),s.translateBy(n,-(m/u)*a,-(g/u)*a,{internal:!0});const b=Eo(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(f,b),e.panScrollTimeout=setTimeout(()=>{d?.(f,b),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,l?.(f,b))}}function jm({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(s,o){const a=s.type==="wheel",i=!t&&a&&!s.ctrlKey,l=ys(s,e);if(s.ctrlKey&&a&&l&&s.preventDefault(),i||l)return null;s.preventDefault(),n.call(this,s,o)}}function Nm({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return s=>{if(s.sourceEvent?.internal)return;const o=Eo(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 Sm({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:s,onPanZoom:o}){return a=>{e.usedRightMouseButton=!!(n&&Cd(t,e.mouseButton??0)),a.sourceEvent?.sync||s([a.transform.x,a.transform.y,a.transform.k]),o&&!a.sourceEvent?.internal&&o?.(a.sourceEvent,Eo(a.transform))}}function Cm({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:s,onPanZoomEnd:o,onPaneContextMenu:a}){return i=>{if(!i.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&Cd(t,e.mouseButton??0)&&!e.usedRightMouseButton&&i.sourceEvent&&a(i.sourceEvent),e.usedRightMouseButton=!1,s(!1),o)){const l=Eo(i.transform);e.prevViewport=l,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{o?.(i.sourceEvent,l)},n?150:0)}}}function Em({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:s,panOnScroll:o,zoomOnDoubleClick:a,userSelectionActive:i,noWheelClassName:l,noPanClassName:c,lib:d,connectionInProgress:f}){return u=>{const h=e||t,m=n&&u.ctrlKey,g=u.type==="wheel";if(u.button===1&&u.type==="mousedown"&&(ys(u,`${d}-flow__node`)||ys(u,`${d}-flow__edge`)))return!0;if(!s&&!h&&!o&&!a&&!n||i||f&&!g||ys(u,l)&&g||ys(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(!h&&!o&&!m&&g||!s&&(u.type==="mousedown"||u.type==="touchstart")||Array.isArray(s)&&!s.includes(u.button)&&u.type==="mousedown")return!1;const b=Array.isArray(s)&&s.includes(u.button)||!u.button||u.button<=1;return(!u.ctrlKey||g)&&b}}function Im({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},f=e.getBoundingClientRect(),u=Uc().scaleExtent([t,n]).translateExtent(s),h=zt(e).call(u);y({x:o.x,y:o.y,zoom:Ms(o.zoom,t,n)},[[0,0],[f.width,f.height]],s);const m=h.on("wheel.zoom"),g=h.on("dblclick.zoom");u.wheelDelta(Ed);function b(M,D){return h?new Promise(z=>{u?.interpolate(D?.interpolate==="linear"?Zo:ao).transform(na(h,D?.duration,D?.ease,()=>z(!0)),M)}):Promise.resolve(!1)}function k({noWheelClassName:M,noPanClassName:D,onPaneContextMenu:z,userSelectionActive:I,panOnScroll:P,panOnDrag:L,panOnScrollMode:B,panOnScrollSpeed:_,preventScrolling:q,zoomOnPinch:H,zoomOnScroll:K,zoomOnDoubleClick:O,zoomActivationKeyPressed:U,lib:A,onTransformChange:T,connectionInProgress:V,paneClickDistance:W,selectionOnDrag:F}){I&&!d.isZoomingOrPanning&&v();const Z=P&&!U&&!I;u.clickDistance(F?1/0:!Qt(W)||W<0?0:W);const se=Z?vm({zoomPanValues:d,noWheelClassName:M,d3Selection:h,d3Zoom:u,panOnScrollMode:B,panOnScrollSpeed:_,zoomOnPinch:H,onPanZoomStart:i,onPanZoom:a,onPanZoomEnd:l}):jm({noWheelClassName:M,preventScrolling:q,d3ZoomHandler:m});if(h.on("wheel.zoom",se,{passive:!1}),!I){const ie=Nm({zoomPanValues:d,onDraggingChange:c,onPanZoomStart:i});u.on("start",ie);const pe=Sm({zoomPanValues:d,panOnDrag:L,onPaneContextMenu:!!z,onPanZoom:a,onTransformChange:T});u.on("zoom",pe);const je=Cm({zoomPanValues:d,panOnDrag:L,panOnScroll:P,onPaneContextMenu:z,onPanZoomEnd:l,onDraggingChange:c});u.on("end",je)}const ue=Em({zoomActivationKeyPressed:U,panOnDrag:L,zoomOnScroll:K,panOnScroll:P,zoomOnDoubleClick:O,zoomOnPinch:H,userSelectionActive:I,noPanClassName:D,noWheelClassName:M,lib:A,connectionInProgress:V});u.filter(ue),O?h.on("dblclick.zoom",g):h.on("dblclick.zoom",null)}function v(){u.on("zoom",null)}async function y(M,D,z){const I=ta(M),P=u?.constrain()(I,D,z);return P&&await b(P),new Promise(L=>L(P))}async function x(M,D){const z=ta(M);return await b(z,D),new Promise(I=>I(z))}function w(M){if(h){const D=ta(M),z=h.property("__zoom");(z.k!==M.zoom||z.x!==M.x||z.y!==M.y)&&u?.transform(h,D,null,{sync:!0})}}function C(){const M=h?rh(h.node()):{x:0,y:0,k:1};return{x:M.x,y:M.y,zoom:M.k}}function j(M,D){return h?new Promise(z=>{u?.interpolate(D?.interpolate==="linear"?Zo:ao).scaleTo(na(h,D?.duration,D?.ease,()=>z(!0)),M)}):Promise.resolve(!1)}function E(M,D){return h?new Promise(z=>{u?.interpolate(D?.interpolate==="linear"?Zo:ao).scaleBy(na(h,D?.duration,D?.ease,()=>z(!0)),M)}):Promise.resolve(!1)}function S(M){u?.scaleExtent(M)}function R(M){u?.translateExtent(M)}function $(M){const D=!Qt(M)||M<0?0:M;u?.clickDistance(D)}return{update:k,destroy:v,setViewport:x,setViewportConstrained:y,getViewport:C,scaleTo:j,scaleBy:E,setScaleExtent:S,setTranslateExtent:R,syncViewport:w,setClickDistance:$}}var _s;(function(e){e.Line="line",e.Handle="handle"})(_s||(_s={}));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 bl(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 Cn(e,t){return Math.max(0,t-e)}function En(e,t){return Math.max(0,e-t)}function Ur(e,t,n){return Math.max(0,t-e,e-n)}function yl(e,t){return e?!t:t}function Mm(e,t,n,s,o,a,i,l){let{affectsX:c,affectsY:d}=t;const{isHorizontal:f,isVertical:u}=t,h=f&&u,{xSnapped:m,ySnapped:g}=n,{minWidth:b,maxWidth:k,minHeight:v,maxHeight:y}=s,{x,y:w,width:C,height:j,aspectRatio:E}=e;let S=Math.floor(f?m-e.pointerX:0),R=Math.floor(u?g-e.pointerY:0);const $=C+(c?-S:S),M=j+(d?-R:R),D=-a[0]*C,z=-a[1]*j;let I=Ur($,b,k),P=Ur(M,v,y);if(i){let _=0,q=0;c&&S<0?_=Cn(x+S+D,i[0][0]):!c&&S>0&&(_=En(x+$+D,i[1][0])),d&&R<0?q=Cn(w+R+z,i[0][1]):!d&&R>0&&(q=En(w+M+z,i[1][1])),I=Math.max(I,_),P=Math.max(P,q)}if(l){let _=0,q=0;c&&S>0?_=En(x+S,l[0][0]):!c&&S<0&&(_=Cn(x+$,l[1][0])),d&&R>0?q=En(w+R,l[0][1]):!d&&R<0&&(q=Cn(w+M,l[1][1])),I=Math.max(I,_),P=Math.max(P,q)}if(o){if(f){const _=Ur($/E,v,y)*E;if(I=Math.max(I,_),i){let q=0;!c&&!d||c&&!d&&h?q=En(w+z+$/E,i[1][1])*E:q=Cn(w+z+(c?S:-S)/E,i[0][1])*E,I=Math.max(I,q)}if(l){let q=0;!c&&!d||c&&!d&&h?q=Cn(w+$/E,l[1][1])*E:q=En(w+(c?S:-S)/E,l[0][1])*E,I=Math.max(I,q)}}if(u){const _=Ur(M*E,b,k)/E;if(P=Math.max(P,_),i){let q=0;!c&&!d||d&&!c&&h?q=En(x+M*E+D,i[1][0])/E:q=Cn(x+(d?R:-R)*E+D,i[0][0])/E,P=Math.max(P,q)}if(l){let q=0;!c&&!d||d&&!c&&h?q=Cn(x+M*E,l[1][0])/E:q=En(x+(d?R:-R)*E,l[0][0])/E,P=Math.max(P,q)}}}R=R+(R<0?P:-P),S=S+(S<0?I:-I),o&&(h?$>M*E?R=(yl(c,d)?-S:S)/E:S=(yl(c,d)?-R:R)*E:f?(R=S/E,d=c):(S=R*E,c=d));const L=c?x+S:x,B=d?w+R:w;return{width:C+(c?-S:S),height:j+(d?-R:R),x:a[0]*S*(c?-1:1)+L,y:a[1]*R*(d?-1:1)+B}}const Id={width:0,height:0,x:0,y:0},Am={...Id,pointerX:0,pointerY:0,aspectRatio:1};function Lm(e){return[[0,0],[e.measured.width,e.measured.height]]}function _m(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 Rm({domNode:e,nodeId:t,getStoreItems:n,onChange:s,onEnd:o}){const a=zt(e);let i={controlDirection:bl("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:f,keepAspectRatio:u,resizeDirection:h,onResizeStart:m,onResize:g,onResizeEnd:b,shouldResize:k}){let v={...Id},y={...Am};i={boundaries:f,resizeDirection:h,keepAspectRatio:u,controlDirection:bl(d)};let x,w=null,C=[],j,E,S,R=!1;const $=Kc().on("start",M=>{const{nodeLookup:D,transform:z,snapGrid:I,snapToGrid:P,nodeOrigin:L,paneDomNode:B}=n();if(x=D.get(t),!x)return;w=B?.getBoundingClientRect()??null;const{xSnapped:_,ySnapped:q}=nr(M.sourceEvent,{transform:z,snapGrid:I,snapToGrid:P,containerBounds:w});v={width:x.measured.width??0,height:x.measured.height??0,x:x.position.x??0,y:x.position.y??0},y={...v,pointerX:_,pointerY:q,aspectRatio:v.width/v.height},j=void 0,x.parentId&&(x.extent==="parent"||x.expandParent)&&(j=D.get(x.parentId),E=j&&x.extent==="parent"?Lm(j):void 0),C=[],S=void 0;for(const[H,K]of D)if(K.parentId===t&&(C.push({id:H,position:{...K.position},extent:K.extent}),K.extent==="parent"||K.expandParent)){const O=_m(K,x,K.origin??L);S?S=[[Math.min(O[0][0],S[0][0]),Math.min(O[0][1],S[0][1])],[Math.max(O[1][0],S[1][0]),Math.max(O[1][1],S[1][1])]]:S=O}m?.(M,{...v})}).on("drag",M=>{const{transform:D,snapGrid:z,snapToGrid:I,nodeOrigin:P}=n(),L=nr(M.sourceEvent,{transform:D,snapGrid:z,snapToGrid:I,containerBounds:w}),B=[];if(!x)return;const{x:_,y:q,width:H,height:K}=v,O={},U=x.origin??P,{width:A,height:T,x:V,y:W}=Mm(y,i.controlDirection,L,i.boundaries,i.keepAspectRatio,U,E,S),F=A!==H,Z=T!==K,se=V!==_&&F,ue=W!==q&&Z;if(!se&&!ue&&!F&&!Z)return;if((se||ue||U[0]===1||U[1]===1)&&(O.x=se?V:v.x,O.y=ue?W:v.y,v.x=O.x,v.y=O.y,C.length>0)){const Se=V-_,Ne=W-q;for(const Be of C)Be.position={x:Be.position.x-Se+U[0]*(A-H),y:Be.position.y-Ne+U[1]*(T-K)},B.push(Be)}if((F||Z)&&(O.width=F&&(!i.resizeDirection||i.resizeDirection==="horizontal")?A:v.width,O.height=Z&&(!i.resizeDirection||i.resizeDirection==="vertical")?T:v.height,v.width=O.width,v.height=O.height),j&&x.expandParent){const Se=U[0]*(O.width??0);O.x&&O.x<Se&&(v.x=Se,y.x=y.x-(O.x-Se));const Ne=U[1]*(O.height??0);O.y&&O.y<Ne&&(v.y=Ne,y.y=y.y-(O.y-Ne))}const ie=Tm({width:v.width,prevWidth:H,height:v.height,prevHeight:K,affectsX:i.controlDirection.affectsX,affectsY:i.controlDirection.affectsY}),pe={...v,direction:ie};k?.(M,pe)!==!1&&(R=!0,g?.(M,pe),s(O,B))}).on("end",M=>{R&&(b?.(M,{...v}),o?.({...v}),R=!1)});a.call($)}function c(){a.on(".drag",null)}return{update:l,destroy:c}}var sa={exports:{}},ra={};var wl;function Dm(){if(wl)return ra;wl=1;var e=Mf(),t=Af();function n(d,f){return d===f&&(d!==0||1/d===1/f)||d!==d&&f!==f}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 ra.useSyncExternalStoreWithSelector=function(d,f,u,h,m){var g=a(null);if(g.current===null){var b={hasValue:!1,value:null};g.current=b}else b=g.current;g=l(function(){function v(j){if(!y){if(y=!0,x=j,j=h(j),m!==void 0&&b.hasValue){var E=b.value;if(m(E,j))return w=E}return w=j}if(E=w,s(x,j))return E;var S=h(j);return m!==void 0&&m(E,S)?(x=j,E):(x=j,w=S)}var y=!1,x,w,C=u===void 0?null:u;return[function(){return v(f())},C===null?void 0:function(){return v(C())}]},[f,u,h,m]);var k=o(d,g[0],g[1]);return i(function(){b.hasValue=!0,b.value=k},[k]),c(k),k},ra}var kl;function Om(){return kl||(kl=1,sa.exports=Dm()),sa.exports}var $m=Om();const Pm=Lf($m),Bm={},vl=e=>{let t;const n=new Set,s=(f,u)=>{const h=typeof f=="function"?f(t):f;if(!Object.is(h,t)){const m=t;t=u??(typeof h!="object"||h===null)?h:Object.assign({},t,h),n.forEach(g=>g(t,m))}},o=()=>t,c={setState:s,getState:o,getInitialState:()=>d,subscribe:f=>(n.add(f),()=>n.delete(f)),destroy:()=>{(Bm?"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},qm=e=>e?vl(e):vl,{useDebugValue:zm}=_f,{useSyncExternalStoreWithSelector:Fm}=Pm,Hm=e=>e;function Td(e,t=Hm,n){const s=Fm(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return zm(s),s}const jl=(e,t)=>{const n=qm(e),s=(o,a=t)=>Td(n,o,a);return Object.assign(s,n),s},Vm=(e,t)=>e?jl(e,t):jl;function ut(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 Io=p.createContext(null),Wm=Io.Provider,Md=an.error001();function Ue(e,t){const n=p.useContext(Io);if(n===null)throw new Error(Md);return Td(n,e,t)}function lt(){const e=p.useContext(Io);if(e===null)throw new Error(Md);return p.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const Nl={display:"none"},Km={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Ad="react-flow__node-desc",Ld="react-flow__edge-desc",Um="react-flow__aria-live",Ym=e=>e.ariaLiveMessage,Gm=e=>e.ariaLabelConfig;function Xm({rfId:e}){const t=Ue(Ym);return r.jsx("div",{id:`${Um}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Km,children:t})}function Zm({rfId:e,disableKeyboardA11y:t}){const n=Ue(Gm);return r.jsxs(r.Fragment,{children:[r.jsx("div",{id:`${Ad}-${e}`,style:Nl,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),r.jsx("div",{id:`${Ld}-${e}`,style:Nl,children:n["edge.a11yDescription.default"]}),!t&&r.jsx(Xm,{rfId:e})]})}const To=p.forwardRef(({position:e="top-left",children:t,className:n,style:s,...o},a)=>{const i=`${e}`.split("-");return r.jsx("div",{className:Nt(["react-flow__panel",n,...i]),style:s,ref:a,...o,children:t})});To.displayName="Panel";function Qm({proOptions:e,position:t="bottom-right"}){return e?.hideAttribution?null:r.jsx(To,{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 Jm=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}},Yr=e=>e.id;function ep(e,t){return ut(e.selectedNodes.map(Yr),t.selectedNodes.map(Yr))&&ut(e.selectedEdges.map(Yr),t.selectedEdges.map(Yr))}function tp({onSelectionChange:e}){const t=lt(),{selectedNodes:n,selectedEdges:s}=Ue(Jm,ep);return p.useEffect(()=>{const o={nodes:n,edges:s};e?.(o),t.getState().onSelectionChangeHandlers.forEach(a=>a(o))},[n,s,e]),null}const np=e=>!!e.onSelectionChangeHandlers;function sp({onSelectionChange:e}){const t=Ue(np);return e||t?r.jsx(tp,{onSelectionChange:e}):null}const _d=[0,0],rp={x:0,y:0,zoom:1},op=["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"],Sl=[...op,"rfId"],ap=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}),Cl={translateExtent:lr,nodeOrigin:_d,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function ip(e){const{setNodes:t,setEdges:n,setMinZoom:s,setMaxZoom:o,setTranslateExtent:a,setNodeExtent:i,reset:l,setDefaultNodesAndEdges:c}=Ue(ap,ut),d=lt();p.useEffect(()=>(c(e.defaultNodes,e.defaultEdges),()=>{f.current=Cl,l()}),[]);const f=p.useRef(Cl);return p.useEffect(()=>{for(const u of Sl){const h=e[u],m=f.current[u];h!==m&&(typeof e[u]>"u"||(u==="nodes"?t(h):u==="edges"?n(h):u==="minZoom"?s(h):u==="maxZoom"?o(h):u==="translateExtent"?a(h):u==="nodeExtent"?i(h):u==="ariaLabelConfig"?d.setState({ariaLabelConfig:Kh(h)}):u==="fitView"?d.setState({fitViewQueued:h}):u==="fitViewOptions"?d.setState({fitViewOptions:h}):d.setState({[u]:h})))}f.current=e},Sl.map(u=>e[u])),null}function El(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function lp(e){const[t,n]=p.useState(e==="system"?null:e);return p.useEffect(()=>{if(e!=="system"){n(e);return}const s=El(),o=()=>n(s?.matches?"dark":"light");return o(),s?.addEventListener("change",o),()=>{s?.removeEventListener("change",o)}},[e]),t!==null?t:El()?.matches?"dark":"light"}const Il=typeof document<"u"?document:null;function fr(e=null,t={target:Il,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
|
-
`)),f=d.reduce((u,h)=>u.concat(...h),[]);return[d,f]}return[[],[]]},[e]);return p.useEffect(()=>{const c=t?.target??Il,d=t?.actInsideInputWithModifier??!0;if(e!==null){const f=m=>{if(o.current=m.ctrlKey||m.metaKey||m.shiftKey||m.altKey,(!o.current||o.current&&!d)&&fd(m))return!1;const b=Ml(m.code,l);if(a.current.add(m[b]),Tl(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=Ml(m.code,l);Tl(i,a.current,!0)?(s(!1),a.current.clear()):a.current.delete(m[g]),m.key==="Meta"&&a.current.clear(),o.current=!1},h=()=>{a.current.clear(),s(!1)};return c?.addEventListener("keydown",f),c?.addEventListener("keyup",u),window.addEventListener("blur",h),window.addEventListener("contextmenu",h),()=>{c?.removeEventListener("keydown",f),c?.removeEventListener("keyup",u),window.removeEventListener("blur",h),window.removeEventListener("contextmenu",h)}}},[e,s]),n}function Tl(e,t,n){return e.filter(s=>n||s.length===t.size).some(s=>s.every(o=>t.has(o)))}function Ml(e,t){return t.includes(e)?"code":"key"}const cp=()=>{const e=lt();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=qa(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},f=n.snapGrid??o,u=n.snapToGrid??a;return yr(d,s,u,f)},flowToScreenPosition:t=>{const{transform:n,domNode:s}=e.getState();if(!s)return t;const{x:o,y:a}=s.getBoundingClientRect(),i=po(t,n);return{x:i.x+o,y:i.y+a}}}),[])};function Rd(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)dp(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 dp(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 Dd(e,t){return Rd(e,t)}function Od(e,t){return Rd(e,t)}function Un(e,t){return{id:e,type:"select",selected:t}}function ws(e,t=new Set,n=!1){const s=[];for(const[o,a]of e){const i=t.has(o);!(a.selected===void 0&&!i)&&a.selected!==i&&(n&&(a.selected=i),s.push(Un(a.id,i)))}return s}function Al({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 Ll(e){return{id:e.id,type:"remove"}}const _l=e=>Oh(e),up=e=>rd(e);function $d(e){return p.forwardRef(e)}const fp=typeof window<"u"?p.useLayoutEffect:p.useEffect;function Rl(e){const[t,n]=p.useState(BigInt(0)),[s]=p.useState(()=>hp(()=>n(o=>o+BigInt(1))));return fp(()=>{const o=s.get();o.length&&(e(o),s.reset())},[t]),s}function hp(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const Pd=p.createContext(null);function mp({children:e}){const t=lt(),n=p.useCallback(l=>{const{nodes:c=[],setNodes:d,hasDefaultNodes:f,onNodesChange:u,nodeLookup:h,fitViewQueued:m,onNodesChangeMiddlewareMap:g}=t.getState();let b=c;for(const v of l)b=typeof v=="function"?v(b):v;let k=Al({items:b,lookup:h});for(const v of g.values())k=v(k);f&&d(b),k.length>0?u?.(k):m&&window.requestAnimationFrame(()=>{const{fitViewQueued:v,nodes:y,setNodes:x}=t.getState();v&&x(y)})},[]),s=Rl(n),o=p.useCallback(l=>{const{edges:c=[],setEdges:d,hasDefaultEdges:f,onEdgesChange:u,edgeLookup:h}=t.getState();let m=c;for(const g of l)m=typeof g=="function"?g(m):g;f?d(m):u&&u(Al({items:m,lookup:h}))},[]),a=Rl(o),i=p.useMemo(()=>({nodeQueue:s,edgeQueue:a}),[]);return r.jsx(Pd.Provider,{value:i,children:e})}function pp(){const e=p.useContext(Pd);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const gp=e=>!!e.panZoom;function Ua(){const e=cp(),t=lt(),n=pp(),s=Ue(gp),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:h,nodeOrigin:m}=t.getState(),g=_l(u)?u:h.get(u.id),b=g.parentId?dd(g.position,g.measured,g.parentId,h,m):g.position,k={...g,position:b,width:g.measured?.width??g.width,height:g.measured?.height??g.height};return As(k)},d=(u,h,m={replace:!1})=>{i(g=>g.map(b=>{if(b.id===u){const k=typeof h=="function"?h(b):h;return m.replace&&_l(k)?k:{...b,...k}}return b}))},f=(u,h,m={replace:!1})=>{l(g=>g.map(b=>{if(b.id===u){const k=typeof h=="function"?h(b):h;return m.replace&&up(k)?k:{...b,...k}}return b}))};return{getNodes:()=>t.getState().nodes.map(u=>({...u})),getNode:u=>a(u)?.internals.userNode,getInternalNode:a,getEdges:()=>{const{edges:u=[]}=t.getState();return u.map(h=>({...h}))},getEdge:u=>t.getState().edgeLookup.get(u),setNodes:i,setEdges:l,addNodes:u=>{const h=Array.isArray(u)?u:[u];n.nodeQueue.push(m=>[...m,...h])},addEdges:u=>{const h=Array.isArray(u)?u:[u];n.edgeQueue.push(m=>[...m,...h])},toObject:()=>{const{nodes:u=[],edges:h=[],transform:m}=t.getState(),[g,b,k]=m;return{nodes:u.map(v=>({...v})),edges:h.map(v=>({...v})),viewport:{x:g,y:b,zoom:k}}},deleteElements:async({nodes:u=[],edges:h=[]})=>{const{nodes:m,edges:g,onNodesDelete:b,onEdgesDelete:k,triggerNodeChanges:v,triggerEdgeChanges:y,onDelete:x,onBeforeDelete:w}=t.getState(),{nodes:C,edges:j}=await zh({nodesToRemove:u,edgesToRemove:h,nodes:m,edges:g,onBeforeDelete:w}),E=j.length>0,S=C.length>0;if(E){const R=j.map(Ll);k?.(j),y(R)}if(S){const R=C.map(Ll);b?.(C),v(R)}return(S||E)&&x?.({nodes:C,edges:j}),{deletedNodes:C,deletedEdges:j}},getIntersectingNodes:(u,h=!0,m)=>{const g=il(u),b=g?u:c(u),k=m!==void 0;return b?(m||t.getState().nodes).filter(v=>{const y=t.getState().nodeLookup.get(v.id);if(y&&!g&&(v.id===u.id||!y.internals.positionAbsolute))return!1;const x=As(k?v:y),w=dr(x,b);return h&&w>0||w>=x.width*x.height||w>=b.width*b.height}):[]},isNodeIntersecting:(u,h,m=!0)=>{const b=il(u)?u:c(u);if(!b)return!1;const k=dr(b,h);return m&&k>0||k>=h.width*h.height||k>=b.width*b.height},updateNode:d,updateNodeData:(u,h,m={replace:!1})=>{d(u,g=>{const b=typeof h=="function"?h(g):h;return m.replace?{...g,data:b}:{...g,data:{...g.data,...b}}},m)},updateEdge:f,updateEdgeData:(u,h,m={replace:!1})=>{f(u,g=>{const b=typeof h=="function"?h(g):h;return m.replace?{...g,data:b}:{...g,data:{...g.data,...b}}},m)},getNodesBounds:u=>{const{nodeLookup:h,nodeOrigin:m}=t.getState();return $h(u,{nodeLookup:h,nodeOrigin:m})},getHandleConnections:({type:u,id:h,nodeId:m})=>Array.from(t.getState().connectionLookup.get(`${m}-${u}${h?`-${h}`:""}`)?.values()??[]),getNodeConnections:({type:u,handleId:h,nodeId:m})=>Array.from(t.getState().connectionLookup.get(`${m}${u?h?`-${u}-${h}`:`-${u}`:""}`)?.values()??[]),fitView:async u=>{const h=t.getState().fitViewResolver??Wh();return t.setState({fitViewQueued:!0,fitViewOptions:u,fitViewResolver:h}),n.nodeQueue.push(m=>[...m]),h.promise}}},[]);return p.useMemo(()=>({...o,...e,viewportInitialized:s}),[s])}const Dl=e=>e.selected,xp=typeof window<"u"?window:void 0;function bp({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=lt(),{deleteElements:s}=Ua(),o=fr(e,{actInsideInputWithModifier:!1}),a=fr(t,{target:xp});p.useEffect(()=>{if(o){const{edges:i,nodes:l}=n.getState();s({nodes:l.filter(Dl),edges:i.filter(Dl)}),n.setState({nodesSelectionActive:!1})}},[o]),p.useEffect(()=>{n.setState({multiSelectionActive:a})},[a])}function yp(e){const t=lt();p.useEffect(()=>{const n=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const s=za(e.current);(s.height===0||s.width===0)&&t.getState().onError?.("004",an.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 Mo={position:"absolute",width:"100%",height:"100%",top:0,left:0},wp=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function kp({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:s=!1,panOnScrollSpeed:o=.5,panOnScrollMode:a=Jn.Free,zoomOnDoubleClick:i=!0,panOnDrag:l=!0,defaultViewport:c,translateExtent:d,minZoom:f,maxZoom:u,zoomActivationKeyCode:h,preventScrolling:m=!0,children:g,noWheelClassName:b,noPanClassName:k,onViewportChange:v,isControlledViewport:y,paneClickDistance:x,selectionOnDrag:w}){const C=lt(),j=p.useRef(null),{userSelectionActive:E,lib:S,connectionInProgress:R}=Ue(wp,ut),$=fr(h),M=p.useRef();yp(j);const D=p.useCallback(z=>{v?.({x:z[0],y:z[1],zoom:z[2]}),y||C.setState({transform:z})},[v,y]);return p.useEffect(()=>{if(j.current){M.current=Im({domNode:j.current,minZoom:f,maxZoom:u,translateExtent:d,viewport:c,onDraggingChange:L=>C.setState(B=>B.paneDragging===L?B:{paneDragging:L}),onPanZoomStart:(L,B)=>{const{onViewportChangeStart:_,onMoveStart:q}=C.getState();q?.(L,B),_?.(B)},onPanZoom:(L,B)=>{const{onViewportChange:_,onMove:q}=C.getState();q?.(L,B),_?.(B)},onPanZoomEnd:(L,B)=>{const{onViewportChangeEnd:_,onMoveEnd:q}=C.getState();q?.(L,B),_?.(B)}});const{x:z,y:I,zoom:P}=M.current.getViewport();return C.setState({panZoom:M.current,transform:[z,I,P],domNode:j.current.closest(".react-flow")}),()=>{M.current?.destroy()}}},[]),p.useEffect(()=>{M.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:b,lib:S,onTransformChange:D,connectionInProgress:R,selectionOnDrag:w,paneClickDistance:x})},[e,t,n,s,o,a,i,l,$,m,k,E,b,S,D,R,w,x]),r.jsx("div",{className:"react-flow__renderer",ref:j,style:Mo,children:g})}const vp=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function jp(){const{userSelectionActive:e,userSelectionRect:t}=Ue(vp,ut);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 oa=(e,t)=>n=>{n.target===t.current&&e?.(n)},Np=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function Sp({isSelecting:e,selectionKeyPressed:t,selectionMode:n=cr.Full,panOnDrag:s,paneClickDistance:o,selectionOnDrag:a,onSelectionStart:i,onSelectionEnd:l,onPaneClick:c,onPaneContextMenu:d,onPaneScroll:f,onPaneMouseEnter:u,onPaneMouseMove:h,onPaneMouseLeave:m,children:g}){const b=lt(),{userSelectionActive:k,elementsSelectable:v,dragging:y,connectionInProgress:x}=Ue(Np,ut),w=v&&(e||k),C=p.useRef(null),j=p.useRef(),E=p.useRef(new Set),S=p.useRef(new Set),R=p.useRef(!1),$=_=>{if(R.current||x){R.current=!1;return}c?.(_),b.getState().resetSelectedElements(),b.setState({nodesSelectionActive:!1})},M=_=>{if(Array.isArray(s)&&s?.includes(2)){_.preventDefault();return}d?.(_)},D=f?_=>f(_):void 0,z=_=>{R.current&&(_.stopPropagation(),R.current=!1)},I=_=>{const{domNode:q}=b.getState();if(j.current=q?.getBoundingClientRect(),!j.current)return;const H=_.target===C.current;if(!H&&!!_.target.closest(".nokey")||!e||!(a&&H||t)||_.button!==0||!_.isPrimary)return;_.target?.setPointerCapture?.(_.pointerId),R.current=!1;const{x:U,y:A}=Jt(_.nativeEvent,j.current);b.setState({userSelectionRect:{width:0,height:0,startX:U,startY:A,x:U,y:A}}),H||(_.stopPropagation(),_.preventDefault())},P=_=>{const{userSelectionRect:q,transform:H,nodeLookup:K,edgeLookup:O,connectionLookup:U,triggerNodeChanges:A,triggerEdgeChanges:T,defaultEdgeOptions:V,resetSelectedElements:W}=b.getState();if(!j.current||!q)return;const{x:F,y:Z}=Jt(_.nativeEvent,j.current),{startX:se,startY:ue}=q;if(!R.current){const Ne=t?0:o;if(Math.hypot(F-se,Z-ue)<=Ne)return;W(),i?.(_)}R.current=!0;const ie={startX:se,startY:ue,x:F<se?F:se,y:Z<ue?Z:ue,width:Math.abs(F-se),height:Math.abs(Z-ue)},pe=E.current,je=S.current;E.current=new Set(Ba(K,ie,H,n===cr.Partial,!0).map(Ne=>Ne.id)),S.current=new Set;const Se=V?.selectable??!0;for(const Ne of E.current){const Be=U.get(Ne);if(Be)for(const{edgeId:$e}of Be.values()){const Ie=O.get($e);Ie&&(Ie.selectable??Se)&&S.current.add($e)}}if(!ll(pe,E.current)){const Ne=ws(K,E.current,!0);A(Ne)}if(!ll(je,S.current)){const Ne=ws(O,S.current);T(Ne)}b.setState({userSelectionRect:ie,userSelectionActive:!0,nodesSelectionActive:!1})},L=_=>{_.button===0&&(_.target?.releasePointerCapture?.(_.pointerId),!k&&_.target===C.current&&b.getState().userSelectionRect&&$?.(_),b.setState({userSelectionActive:!1,userSelectionRect:null}),R.current&&(l?.(_),b.setState({nodesSelectionActive:E.current.size>0})))},B=s===!0||Array.isArray(s)&&s.includes(0);return r.jsxs("div",{className:Nt(["react-flow__pane",{draggable:B,dragging:y,selection:e}]),onClick:w?void 0:oa($,C),onContextMenu:oa(M,C),onWheel:oa(D,C),onPointerEnter:w?void 0:u,onPointerMove:w?P:h,onPointerUp:w?L:void 0,onPointerDownCapture:w?I:void 0,onClickCapture:w?z:void 0,onPointerLeave:m,ref:C,style:Mo,children:[g,r.jsx(jp,{})]})}function Na({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",an.error012(e));return}t.setState({nodesSelectionActive:!1}),d.selected?(n||d.selected&&i)&&(a({nodes:[d],edges:[]}),requestAnimationFrame(()=>s?.current?.blur())):o([e])}function Bd({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:s,nodeId:o,isSelectable:a,nodeClickDistance:i}){const l=lt(),[c,d]=p.useState(!1),f=p.useRef();return p.useEffect(()=>{f.current=mm({getStoreItems:()=>l.getState(),onNodeMouseDown:u=>{Na({id:u,store:l,nodeRef:e})},onDragStart:()=>{d(!0)},onDragStop:()=>{d(!1)}})},[]),p.useEffect(()=>{if(!(t||!e.current||!f.current))return f.current.update({noDragClassName:n,handleSelector:s,domNode:e.current,isSelectable:a,nodeId:o,nodeClickDistance:i}),()=>{f.current?.destroy()}},[n,s,t,a,e,o,i]),c}const Cp=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function qd(){const e=lt();return p.useCallback(n=>{const{nodeExtent:s,snapToGrid:o,snapGrid:a,nodesDraggable:i,onError:l,updateNodePositions:c,nodeLookup:d,nodeOrigin:f}=e.getState(),u=new Map,h=Cp(i),m=o?a[0]:5,g=o?a[1]:5,b=n.direction.x*m*n.factor,k=n.direction.y*g*n.factor;for(const[,v]of d){if(!h(v))continue;let y={x:v.internals.positionAbsolute.x+b,y:v.internals.positionAbsolute.y+k};o&&(y=br(y,a));const{position:x,positionAbsolute:w}=od({nodeId:v.id,nextPosition:y,nodeLookup:d,nodeExtent:s,nodeOrigin:f,onError:l});v.position=x,v.internals.positionAbsolute=w,u.set(v.id,v)}c(u)},[])}const Ya=p.createContext(null),Ep=Ya.Provider;Ya.Consumer;const zd=()=>p.useContext(Ya),Ip=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,f=c?.nodeId===e&&c?.id===t&&c?.type===n;return{connectingFrom:l?.nodeId===e&&l?.id===t&&l?.type===n,connectingTo:f,clickConnecting:o?.nodeId===e&&o?.id===t&&o?.type===n,isPossibleEndHandle:a===Is.Strict?l?.type!==n:e!==l?.nodeId||t!==l?.id,connectionInProcess:!!l,clickConnectionInProcess:!!o,valid:f&&d}};function Mp({type:e="source",position:t=we.Top,isValidConnection:n,isConnectable:s=!0,isConnectableStart:o=!0,isConnectableEnd:a=!0,id:i,onConnect:l,children:c,className:d,onMouseDown:f,onTouchStart:u,...h},m){const g=i||null,b=e==="target",k=lt(),v=zd(),{connectOnClick:y,noPanClassName:x,rfId:w}=Ue(Ip,ut),{connectingFrom:C,connectingTo:j,clickConnecting:E,isPossibleEndHandle:S,connectionInProcess:R,clickConnectionInProcess:$,valid:M}=Ue(Tp(v,g,e),ut);v||k.getState().onError?.("010",an.error010());const D=P=>{const{defaultEdgeOptions:L,onConnect:B,hasDefaultEdges:_}=k.getState(),q={...L,...P};if(_){const{edges:H,setEdges:K}=k.getState();K(Qh(q,H))}B?.(q),l?.(q)},z=P=>{if(!v)return;const L=hd(P.nativeEvent);if(o&&(L&&P.button===0||!L)){const B=k.getState();ja.onPointerDown(P.nativeEvent,{handleDomNode:P.currentTarget,autoPanOnConnect:B.autoPanOnConnect,connectionMode:B.connectionMode,connectionRadius:B.connectionRadius,domNode:B.domNode,nodeLookup:B.nodeLookup,lib:B.lib,isTarget:b,handleId:g,nodeId:v,flowId:B.rfId,panBy:B.panBy,cancelConnection:B.cancelConnection,onConnectStart:B.onConnectStart,onConnectEnd:(..._)=>k.getState().onConnectEnd?.(..._),updateConnection:B.updateConnection,onConnect:D,isValidConnection:n||((..._)=>k.getState().isValidConnection?.(..._)??!0),getTransform:()=>k.getState().transform,getFromHandle:()=>k.getState().connection.fromHandle,autoPanSpeed:B.autoPanSpeed,dragThreshold:B.connectionDragThreshold})}L?f?.(P):u?.(P)},I=P=>{const{onClickConnectStart:L,onClickConnectEnd:B,connectionClickStartHandle:_,connectionMode:q,isValidConnection:H,lib:K,rfId:O,nodeLookup:U,connection:A}=k.getState();if(!v||!_&&!o)return;if(!_){L?.(P.nativeEvent,{nodeId:v,handleId:g,handleType:e}),k.setState({connectionClickStartHandle:{nodeId:v,type:e,id:g}});return}const T=ud(P.target),V=n||H,{connection:W,isValid:F}=ja.isValid(P.nativeEvent,{handle:{nodeId:v,id:g,type:e},connectionMode:q,fromNodeId:_.nodeId,fromHandleId:_.id||null,fromType:_.type,isValidConnection:V,flowId:O,doc:T,lib:K,nodeLookup:U});F&&W&&D(W);const Z=structuredClone(A);delete Z.inProgress,Z.toPosition=Z.toHandle?Z.toHandle.position:null,B?.(P,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:Nt(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",x,d,{source:!b,target:b,connectable:s,connectablestart:o,connectableend:a,clickconnecting:E,connectingfrom:C,connectingto:j,valid:M,connectionindicator:s&&(!R||S)&&(R||$?a:o)}]),onMouseDown:z,onTouchStart:z,onClick:y?I:void 0,ref:m,...h,children:c})}const _n=p.memo($d(Mp));function Ap({data:e,isConnectable:t,sourcePosition:n=we.Bottom}){return r.jsxs(r.Fragment,{children:[e?.label,r.jsx(_n,{type:"source",position:n,isConnectable:t})]})}function Lp({data:e,isConnectable:t,targetPosition:n=we.Top,sourcePosition:s=we.Bottom}){return r.jsxs(r.Fragment,{children:[r.jsx(_n,{type:"target",position:n,isConnectable:t}),e?.label,r.jsx(_n,{type:"source",position:s,isConnectable:t})]})}function _p(){return null}function Rp({data:e,isConnectable:t,targetPosition:n=we.Top}){return r.jsxs(r.Fragment,{children:[r.jsx(_n,{type:"target",position:n,isConnectable:t}),e?.label]})}const go={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},Ol={input:Ap,default:Lp,output:Rp,group:_p};function Dp(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 Op=e=>{const{width:t,height:n,x:s,y:o}=xr(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 $p({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const s=lt(),{width:o,height:a,transformString:i,userSelectionActive:l}=Ue(Op,ut),c=qd(),d=p.useRef(null);p.useEffect(()=>{n||d.current?.focus({preventScroll:!0})},[n]);const f=!l&&o!==null&&a!==null;if(Bd({nodeRef:d,disabled:!f}),!f)return null;const u=e?m=>{const g=s.getState().nodes.filter(b=>b.selected);e(m,g)}:void 0,h=m=>{Object.prototype.hasOwnProperty.call(go,m.key)&&(m.preventDefault(),c({direction:go[m.key],factor:m.shiftKey?4:1}))};return r.jsx("div",{className:Nt(["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:h,style:{width:o,height:a}})})}const $l=typeof window<"u"?window:void 0,Pp=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Fd({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:s,onPaneMouseLeave:o,onPaneContextMenu:a,onPaneScroll:i,paneClickDistance:l,deleteKeyCode:c,selectionKeyCode:d,selectionOnDrag:f,selectionMode:u,onSelectionStart:h,onSelectionEnd:m,multiSelectionKeyCode:g,panActivationKeyCode:b,zoomActivationKeyCode:k,elementsSelectable:v,zoomOnScroll:y,zoomOnPinch:x,panOnScroll:w,panOnScrollSpeed:C,panOnScrollMode:j,zoomOnDoubleClick:E,panOnDrag:S,defaultViewport:R,translateExtent:$,minZoom:M,maxZoom:D,preventScrolling:z,onSelectionContextMenu:I,noWheelClassName:P,noPanClassName:L,disableKeyboardA11y:B,onViewportChange:_,isControlledViewport:q}){const{nodesSelectionActive:H,userSelectionActive:K}=Ue(Pp,ut),O=fr(d,{target:$l}),U=fr(b,{target:$l}),A=U||S,T=U||w,V=f&&A!==!0,W=O||K||V;return bp({deleteKeyCode:c,multiSelectionKeyCode:g}),r.jsx(kp,{onPaneContextMenu:a,elementsSelectable:v,zoomOnScroll:y,zoomOnPinch:x,panOnScroll:T,panOnScrollSpeed:C,panOnScrollMode:j,zoomOnDoubleClick:E,panOnDrag:!O&&A,defaultViewport:R,translateExtent:$,minZoom:M,maxZoom:D,zoomActivationKeyCode:k,preventScrolling:z,noWheelClassName:P,noPanClassName:L,onViewportChange:_,isControlledViewport:q,paneClickDistance:l,selectionOnDrag:V,children:r.jsxs(Sp,{onSelectionStart:h,onSelectionEnd:m,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:s,onPaneMouseLeave:o,onPaneContextMenu:a,onPaneScroll:i,panOnDrag:A,isSelecting:!!W,selectionMode:u,selectionKeyPressed:O,paneClickDistance:l,selectionOnDrag:V,children:[e,H&&r.jsx($p,{onSelectionContextMenu:I,noPanClassName:L,disableKeyboardA11y:B})]})})}Fd.displayName="FlowRenderer";const Bp=p.memo(Fd),qp=e=>t=>e?Ba(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 zp(e){return Ue(p.useCallback(qp(e),[e]),ut)}const Fp=e=>e.updateNodeInternals;function Hp(){const e=Ue(Fp),[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 Vp({node:e,nodeType:t,hasDimensions:n,resizeObserver:s}){const o=lt(),a=p.useRef(null),i=p.useRef(null),l=p.useRef(e.sourcePosition),c=p.useRef(e.targetPosition),d=p.useRef(t),f=n&&!!e.internals.handleBounds;return p.useEffect(()=>{a.current&&!e.hidden&&(!f||i.current!==a.current)&&(i.current&&s?.unobserve(i.current),s?.observe(a.current),i.current=a.current)},[f,e.hidden]),p.useEffect(()=>()=>{i.current&&(s?.unobserve(i.current),i.current=null)},[]),p.useEffect(()=>{if(a.current){const u=d.current!==t,h=l.current!==e.sourcePosition,m=c.current!==e.targetPosition;(u||h||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 Wp({id:e,onClick:t,onMouseEnter:n,onMouseMove:s,onMouseLeave:o,onContextMenu:a,onDoubleClick:i,nodesDraggable:l,elementsSelectable:c,nodesConnectable:d,nodesFocusable:f,resizeObserver:u,noDragClassName:h,noPanClassName:m,disableKeyboardA11y:g,rfId:b,nodeTypes:k,nodeClickDistance:v,onError:y}){const{node:x,internals:w,isParent:C}=Ue(F=>{const Z=F.nodeLookup.get(e),se=F.parentLookup.has(e);return{node:Z,internals:Z.internals,isParent:se}},ut);let j=x.type||"default",E=k?.[j]||Ol[j];E===void 0&&(y?.("003",an.error003(j)),j="default",E=k?.default||Ol.default);const S=!!(x.draggable||l&&typeof x.draggable>"u"),R=!!(x.selectable||c&&typeof x.selectable>"u"),$=!!(x.connectable||d&&typeof x.connectable>"u"),M=!!(x.focusable||f&&typeof x.focusable>"u"),D=lt(),z=cd(x),I=Vp({node:x,nodeType:j,hasDimensions:z,resizeObserver:u}),P=Bd({nodeRef:I,disabled:x.hidden||!S,noDragClassName:h,handleSelector:x.dragHandle,nodeId:e,isSelectable:R,nodeClickDistance:v}),L=qd();if(x.hidden)return null;const B=yn(x),_=Dp(x),q=R||S||t||n||s||o,H=n?F=>n(F,{...w.userNode}):void 0,K=s?F=>s(F,{...w.userNode}):void 0,O=o?F=>o(F,{...w.userNode}):void 0,U=a?F=>a(F,{...w.userNode}):void 0,A=i?F=>i(F,{...w.userNode}):void 0,T=F=>{const{selectNodesOnDrag:Z,nodeDragThreshold:se}=D.getState();R&&(!Z||!S||se>0)&&Na({id:e,store:D,nodeRef:I}),t&&t(F,{...w.userNode})},V=F=>{if(!(fd(F.nativeEvent)||g)){if(ed.includes(F.key)&&R){const Z=F.key==="Escape";Na({id:e,store:D,unselect:Z,nodeRef:I})}else if(S&&x.selected&&Object.prototype.hasOwnProperty.call(go,F.key)){F.preventDefault();const{ariaLabelConfig:Z}=D.getState();D.setState({ariaLiveMessage:Z["node.a11yDescription.ariaLiveMessage"]({direction:F.key.replace("Arrow","").toLowerCase(),x:~~w.positionAbsolute.x,y:~~w.positionAbsolute.y})}),L({direction:go[F.key],factor:F.shiftKey?4:1})}}},W=()=>{if(g||!I.current?.matches(":focus-visible"))return;const{transform:F,width:Z,height:se,autoPanOnNodeFocus:ue,setCenter:ie}=D.getState();if(!ue)return;Ba(new Map([[e,x]]),{x:0,y:0,width:Z,height:se},F,!0).length>0||ie(x.position.x+B.width/2,x.position.y+B.height/2,{zoom:F[2]})};return r.jsx("div",{className:Nt(["react-flow__node",`react-flow__node-${j}`,{[m]:S},x.className,{selected:x.selected,selectable:R,parent:C,draggable:S,dragging:P}]),ref:I,style:{zIndex:w.z,transform:`translate(${w.positionAbsolute.x}px,${w.positionAbsolute.y}px)`,pointerEvents:q?"all":"none",visibility:z?"visible":"hidden",...x.style,..._},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:H,onMouseMove:K,onMouseLeave:O,onContextMenu:U,onClick:T,onDoubleClick:A,onKeyDown:M?V:void 0,tabIndex:M?0:void 0,onFocus:M?W:void 0,role:x.ariaRole??(M?"group":void 0),"aria-roledescription":"node","aria-describedby":g?void 0:`${Ad}-${b}`,"aria-label":x.ariaLabel,...x.domAttributes,children:r.jsx(Ep,{value:e,children:r.jsx(E,{id:e,data:x.data,type:j,positionAbsoluteX:w.positionAbsolute.x,positionAbsoluteY:w.positionAbsolute.y,selected:x.selected??!1,selectable:R,draggable:S,deletable:x.deletable??!0,isConnectable:$,sourcePosition:x.sourcePosition,targetPosition:x.targetPosition,dragging:P,dragHandle:x.dragHandle,zIndex:w.z,parentId:x.parentId,...B})})})}var Kp=p.memo(Wp);const Up=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function Hd(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:s,elementsSelectable:o,onError:a}=Ue(Up,ut),i=zp(e.onlyRenderVisibleElements),l=Hp();return r.jsx("div",{className:"react-flow__nodes",style:Mo,children:i.map(c=>r.jsx(Kp,{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))})}Hd.displayName="NodeRenderer";const Yp=p.memo(Hd);function Gp(e){return Ue(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&&Gh({sourceNode:a,targetNode:i,width:n.width,height:n.height,transform:n.transform})&&s.push(o.id)}return s},[e]),ut)}const Xp=({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"})},Zp=({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"})},Pl={[Ts.Arrow]:Xp,[Ts.ArrowClosed]:Zp};function Qp(e){const t=lt();return p.useMemo(()=>Object.prototype.hasOwnProperty.call(Pl,e)?Pl[e]:(t.getState().onError?.("009",an.error009(e)),null),[e])}const Jp=({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=Qp(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},Vd=({defaultColor:e,rfId:t})=>{const n=Ue(a=>a.edges),s=Ue(a=>a.defaultEdgeOptions),o=p.useMemo(()=>sm(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(Jp,{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};Vd.displayName="MarkerDefinitions";var eg=p.memo(Vd);function Wd({x:e,y:t,label:n,labelStyle:s,labelShowBg:o=!0,labelBgStyle:a,labelBgPadding:i=[2,4],labelBgBorderRadius:l=2,children:c,className:d,...f}){const[u,h]=p.useState({x:1,y:0,width:0,height:0}),m=Nt(["react-flow__edge-textwrapper",d]),g=p.useRef(null);return p.useEffect(()=>{if(g.current){const b=g.current.getBBox();h({x:b.x,y:b.y,width:b.width,height:b.height})}},[n]),n?r.jsxs("g",{transform:`translate(${e-u.width/2} ${t-u.height/2})`,className:m,visibility:u.width?"visible":"hidden",...f,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}Wd.displayName="EdgeText";const tg=p.memo(Wd);function Ao({path:e,labelX:t,labelY:n,label:s,labelStyle:o,labelShowBg:a,labelBgStyle:i,labelBgPadding:l,labelBgBorderRadius:c,interactionWidth:d=20,...f}){return r.jsxs(r.Fragment,{children:[r.jsx("path",{...f,d:e,fill:"none",className:Nt(["react-flow__edge-path",f.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(tg,{x:t,y:n,label:s,labelStyle:o,labelShowBg:a,labelBgStyle:i,labelBgPadding:l,labelBgBorderRadius:c}):null]})}function Bl({pos:e,x1:t,y1:n,x2:s,y2:o}){return e===we.Left||e===we.Right?[.5*(t+s),n]:[t,.5*(n+o)]}function Kd({sourceX:e,sourceY:t,sourcePosition:n=we.Bottom,targetX:s,targetY:o,targetPosition:a=we.Top}){const[i,l]=Bl({pos:n,x1:e,y1:t,x2:s,y2:o}),[c,d]=Bl({pos:a,x1:s,y1:o,x2:e,y2:t}),[f,u,h,m]=md({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}`,f,u,h,m]}function Ud(e){return p.memo(({id:t,sourceX:n,sourceY:s,targetX:o,targetY:a,sourcePosition:i,targetPosition:l,label:c,labelStyle:d,labelShowBg:f,labelBgStyle:u,labelBgPadding:h,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:k,interactionWidth:v})=>{const[y,x,w]=Kd({sourceX:n,sourceY:s,sourcePosition:i,targetX:o,targetY:a,targetPosition:l}),C=e.isInternal?void 0:t;return r.jsx(Ao,{id:C,path:y,labelX:x,labelY:w,label:c,labelStyle:d,labelShowBg:f,labelBgStyle:u,labelBgPadding:h,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:k,interactionWidth:v})})}const ng=Ud({isInternal:!1}),Yd=Ud({isInternal:!0});ng.displayName="SimpleBezierEdge";Yd.displayName="SimpleBezierEdgeInternal";function Gd(e){return p.memo(({id:t,sourceX:n,sourceY:s,targetX:o,targetY:a,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:u,style:h,sourcePosition:m=we.Bottom,targetPosition:g=we.Top,markerEnd:b,markerStart:k,pathOptions:v,interactionWidth:y})=>{const[x,w,C]=wa({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(Ao,{id:j,path:x,labelX:w,labelY:C,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:u,style:h,markerEnd:b,markerStart:k,interactionWidth:y})})}const Xd=Gd({isInternal:!1}),Zd=Gd({isInternal:!0});Xd.displayName="SmoothStepEdge";Zd.displayName="SmoothStepEdgeInternal";function Qd(e){return p.memo(({id:t,...n})=>{const s=e.isInternal?void 0:t;return r.jsx(Xd,{...n,id:s,pathOptions:p.useMemo(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}const sg=Qd({isInternal:!1}),Jd=Qd({isInternal:!0});sg.displayName="StepEdge";Jd.displayName="StepEdgeInternal";function eu(e){return p.memo(({id:t,sourceX:n,sourceY:s,targetX:o,targetY:a,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:u,style:h,markerEnd:m,markerStart:g,interactionWidth:b})=>{const[k,v,y]=xd({sourceX:n,sourceY:s,targetX:o,targetY:a}),x=e.isInternal?void 0:t;return r.jsx(Ao,{id:x,path:k,labelX:v,labelY:y,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:u,style:h,markerEnd:m,markerStart:g,interactionWidth:b})})}const rg=eu({isInternal:!1}),tu=eu({isInternal:!0});rg.displayName="StraightEdge";tu.displayName="StraightEdgeInternal";function nu(e){return p.memo(({id:t,sourceX:n,sourceY:s,targetX:o,targetY:a,sourcePosition:i=we.Bottom,targetPosition:l=we.Top,label:c,labelStyle:d,labelShowBg:f,labelBgStyle:u,labelBgPadding:h,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:k,pathOptions:v,interactionWidth:y})=>{const[x,w,C]=pd({sourceX:n,sourceY:s,sourcePosition:i,targetX:o,targetY:a,targetPosition:l,curvature:v?.curvature}),j=e.isInternal?void 0:t;return r.jsx(Ao,{id:j,path:x,labelX:w,labelY:C,label:c,labelStyle:d,labelShowBg:f,labelBgStyle:u,labelBgPadding:h,labelBgBorderRadius:m,style:g,markerEnd:b,markerStart:k,interactionWidth:y})})}const og=nu({isInternal:!1}),su=nu({isInternal:!0});og.displayName="BezierEdge";su.displayName="BezierEdgeInternal";const ql={default:su,straight:tu,step:Jd,smoothstep:Zd,simplebezier:Yd},zl={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},ag=(e,t,n)=>n===we.Left?e-t:n===we.Right?e+t:e,ig=(e,t,n)=>n===we.Top?e-t:n===we.Bottom?e+t:e,Fl="react-flow__edgeupdater";function Hl({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:Nt([Fl,`${Fl}-${l}`]),cx:ag(t,s,e),cy:ig(n,s,e),r:s,stroke:"transparent",fill:"transparent"})}function lg({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:s,sourceY:o,targetX:a,targetY:i,sourcePosition:l,targetPosition:c,onReconnect:d,onReconnectStart:f,onReconnectEnd:u,setReconnecting:h,setUpdateHover:m}){const g=lt(),b=(w,C)=>{if(w.button!==0)return;const{autoPanOnConnect:j,domNode:E,connectionMode:S,connectionRadius:R,lib:$,onConnectStart:M,cancelConnection:D,nodeLookup:z,rfId:I,panBy:P,updateConnection:L}=g.getState(),B=C.type==="target",_=(K,O)=>{h(!1),u?.(K,n,C.type,O)},q=K=>d?.(n,K),H=(K,O)=>{h(!0),f?.(w,n,C.type),M?.(K,O)};ja.onPointerDown(w.nativeEvent,{autoPanOnConnect:j,connectionMode:S,connectionRadius:R,domNode:E,handleId:C.id,nodeId:C.nodeId,nodeLookup:z,isTarget:B,edgeUpdaterType:C.type,lib:$,flowId:I,cancelConnection:D,panBy:P,isValidConnection:(...K)=>g.getState().isValidConnection?.(...K)??!0,onConnect:q,onConnectStart:H,onConnectEnd:(...K)=>g.getState().onConnectEnd?.(...K),onReconnectEnd:_,updateConnection:L,getTransform:()=>g.getState().transform,getFromHandle:()=>g.getState().connection.fromHandle,dragThreshold:g.getState().connectionDragThreshold,handleDomNode:w.currentTarget})},k=w=>b(w,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),v=w=>b(w,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),y=()=>m(!0),x=()=>m(!1);return r.jsxs(r.Fragment,{children:[(e===!0||e==="source")&&r.jsx(Hl,{position:l,centerX:s,centerY:o,radius:t,onMouseDown:k,onMouseEnter:y,onMouseOut:x,type:"source"}),(e===!0||e==="target")&&r.jsx(Hl,{position:c,centerX:a,centerY:i,radius:t,onMouseDown:v,onMouseEnter:y,onMouseOut:x,type:"target"})]})}function cg({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:s,onClick:o,onDoubleClick:a,onContextMenu:i,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,reconnectRadius:f,onReconnect:u,onReconnectStart:h,onReconnectEnd:m,rfId:g,edgeTypes:b,noPanClassName:k,onError:v,disableKeyboardA11y:y}){let x=Ue(ie=>ie.edgeLookup.get(e));const w=Ue(ie=>ie.defaultEdgeOptions);x=w?{...w,...x}:x;let C=x.type||"default",j=b?.[C]||ql[C];j===void 0&&(v?.("011",an.error011(C)),C="default",j=b?.default||ql.default);const E=!!(x.focusable||t&&typeof x.focusable>"u"),S=typeof u<"u"&&(x.reconnectable||n&&typeof x.reconnectable>"u"),R=!!(x.selectable||s&&typeof x.selectable>"u"),$=p.useRef(null),[M,D]=p.useState(!1),[z,I]=p.useState(!1),P=lt(),{zIndex:L,sourceX:B,sourceY:_,targetX:q,targetY:H,sourcePosition:K,targetPosition:O}=Ue(p.useCallback(ie=>{const pe=ie.nodeLookup.get(x.source),je=ie.nodeLookup.get(x.target);if(!pe||!je)return{zIndex:x.zIndex,...zl};const Se=nm({id:e,sourceNode:pe,targetNode:je,sourceHandle:x.sourceHandle||null,targetHandle:x.targetHandle||null,connectionMode:ie.connectionMode,onError:v});return{zIndex:Yh({selected:x.selected,zIndex:x.zIndex,sourceNode:pe,targetNode:je,elevateOnSelect:ie.elevateEdgesOnSelect,zIndexMode:ie.zIndexMode}),...Se||zl}},[x.source,x.target,x.sourceHandle,x.targetHandle,x.selected,x.zIndex]),ut),U=p.useMemo(()=>x.markerStart?`url('#${ka(x.markerStart,g)}')`:void 0,[x.markerStart,g]),A=p.useMemo(()=>x.markerEnd?`url('#${ka(x.markerEnd,g)}')`:void 0,[x.markerEnd,g]);if(x.hidden||B===null||_===null||q===null||H===null)return null;const T=ie=>{const{addSelectedEdges:pe,unselectNodesAndEdges:je,multiSelectionActive:Se}=P.getState();R&&(P.setState({nodesSelectionActive:!1}),x.selected&&Se?(je({nodes:[],edges:[x]}),$.current?.blur()):pe([e])),o&&o(ie,x)},V=a?ie=>{a(ie,{...x})}:void 0,W=i?ie=>{i(ie,{...x})}:void 0,F=l?ie=>{l(ie,{...x})}:void 0,Z=c?ie=>{c(ie,{...x})}:void 0,se=d?ie=>{d(ie,{...x})}:void 0,ue=ie=>{if(!y&&ed.includes(ie.key)&&R){const{unselectNodesAndEdges:pe,addSelectedEdges:je}=P.getState();ie.key==="Escape"?($.current?.blur(),pe({edges:[x]})):je([e])}};return r.jsx("svg",{style:{zIndex:L},children:r.jsxs("g",{className:Nt(["react-flow__edge",`react-flow__edge-${C}`,x.className,k,{selected:x.selected,animated:x.animated,inactive:!R&&!o,updating:M,selectable:R}]),onClick:T,onDoubleClick:V,onContextMenu:W,onMouseEnter:F,onMouseMove:Z,onMouseLeave:se,onKeyDown:E?ue: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?`${Ld}-${g}`:void 0,ref:$,...x.domAttributes,children:[!z&&r.jsx(j,{id:e,source:x.source,target:x.target,type:x.type,selected:x.selected,animated:x.animated,selectable:R,deletable:x.deletable??!0,label:x.label,labelStyle:x.labelStyle,labelShowBg:x.labelShowBg,labelBgStyle:x.labelBgStyle,labelBgPadding:x.labelBgPadding,labelBgBorderRadius:x.labelBgBorderRadius,sourceX:B,sourceY:_,targetX:q,targetY:H,sourcePosition:K,targetPosition:O,data:x.data,style:x.style,sourceHandleId:x.sourceHandle,targetHandleId:x.targetHandle,markerStart:U,markerEnd:A,pathOptions:"pathOptions"in x?x.pathOptions:void 0,interactionWidth:x.interactionWidth}),S&&r.jsx(lg,{edge:x,isReconnectable:S,reconnectRadius:f,onReconnect:u,onReconnectStart:h,onReconnectEnd:m,sourceX:B,sourceY:_,targetX:q,targetY:H,sourcePosition:K,targetPosition:O,setUpdateHover:D,setReconnecting:I})]})})}var dg=p.memo(cg);const ug=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function ru({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:s,noPanClassName:o,onReconnect:a,onEdgeContextMenu:i,onEdgeMouseEnter:l,onEdgeMouseMove:c,onEdgeMouseLeave:d,onEdgeClick:f,reconnectRadius:u,onEdgeDoubleClick:h,onReconnectStart:m,onReconnectEnd:g,disableKeyboardA11y:b}){const{edgesFocusable:k,edgesReconnectable:v,elementsSelectable:y,onError:x}=Ue(ug,ut),w=Gp(t);return r.jsxs("div",{className:"react-flow__edges",children:[r.jsx(eg,{defaultColor:e,rfId:n}),w.map(C=>r.jsx(dg,{id:C,edgesFocusable:k,edgesReconnectable:v,elementsSelectable:y,noPanClassName:o,onReconnect:a,onContextMenu:i,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,onClick:f,reconnectRadius:u,onDoubleClick:h,onReconnectStart:m,onReconnectEnd:g,rfId:n,onError:x,edgeTypes:s,disableKeyboardA11y:b},C))]})}ru.displayName="EdgeRenderer";const fg=p.memo(ru),hg=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function mg({children:e}){const t=Ue(hg);return r.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function pg(e){const t=Ua(),n=p.useRef(!1);p.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const gg=e=>e.panZoom?.syncViewport;function xg(e){const t=Ue(gg),n=lt();return p.useEffect(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function bg(e){return e.connection.inProgress?{...e.connection,to:yr(e.connection.to,e.transform)}:{...e.connection}}function yg(e){return bg}function wg(e){const t=yg();return Ue(t,ut)}const kg=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function vg({containerStyle:e,style:t,type:n,component:s}){const{nodesConnectable:o,width:a,height:i,isValid:l,inProgress:c}=Ue(kg,ut);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:Nt(["react-flow__connection",sd(l)]),children:r.jsx(ou,{style:t,type:n,CustomComponent:s,isValid:l})})})}const ou=({style:e,type:t=Tn.Bezier,CustomComponent:n,isValid:s})=>{const{inProgress:o,from:a,fromNode:i,fromHandle:l,fromPosition:c,to:d,toNode:f,toHandle:u,toPosition:h,pointer:m}=wg();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:h,connectionStatus:sd(s),toNode:f,toHandle:u,pointer:m});let g="";const b={sourceX:a.x,sourceY:a.y,sourcePosition:c,targetX:d.x,targetY:d.y,targetPosition:h};switch(t){case Tn.Bezier:[g]=pd(b);break;case Tn.SimpleBezier:[g]=Kd(b);break;case Tn.Step:[g]=wa({...b,borderRadius:0});break;case Tn.SmoothStep:[g]=wa(b);break;default:[g]=xd(b)}return r.jsx("path",{d:g,fill:"none",className:"react-flow__connection-path",style:e})};ou.displayName="ConnectionLine";const jg={};function Vl(e=jg){p.useRef(e),lt(),p.useEffect(()=>{},[e])}function Ng(){lt(),p.useRef(!1),p.useEffect(()=>{},[])}function au({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:s,onEdgeClick:o,onNodeDoubleClick:a,onEdgeDoubleClick:i,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:f,onSelectionContextMenu:u,onSelectionStart:h,onSelectionEnd:m,connectionLineType:g,connectionLineStyle:b,connectionLineComponent:k,connectionLineContainerStyle:v,selectionKeyCode:y,selectionOnDrag:x,selectionMode:w,multiSelectionKeyCode:C,panActivationKeyCode:j,zoomActivationKeyCode:E,deleteKeyCode:S,onlyRenderVisibleElements:R,elementsSelectable:$,defaultViewport:M,translateExtent:D,minZoom:z,maxZoom:I,preventScrolling:P,defaultMarkerColor:L,zoomOnScroll:B,zoomOnPinch:_,panOnScroll:q,panOnScrollSpeed:H,panOnScrollMode:K,zoomOnDoubleClick:O,panOnDrag:U,onPaneClick:A,onPaneMouseEnter:T,onPaneMouseMove:V,onPaneMouseLeave:W,onPaneScroll:F,onPaneContextMenu:Z,paneClickDistance:se,nodeClickDistance:ue,onEdgeContextMenu:ie,onEdgeMouseEnter:pe,onEdgeMouseMove:je,onEdgeMouseLeave:Se,reconnectRadius:Ne,onReconnect:Be,onReconnectStart:$e,onReconnectEnd:Ie,noDragClassName:Ve,noWheelClassName:ct,noPanClassName:Oe,disableKeyboardA11y:re,nodeExtent:fe,rfId:xe,viewport:J,onViewportChange:ne}){return Vl(e),Vl(t),Ng(),pg(n),xg(J),r.jsx(Bp,{onPaneClick:A,onPaneMouseEnter:T,onPaneMouseMove:V,onPaneMouseLeave:W,onPaneContextMenu:Z,onPaneScroll:F,paneClickDistance:se,deleteKeyCode:S,selectionKeyCode:y,selectionOnDrag:x,selectionMode:w,onSelectionStart:h,onSelectionEnd:m,multiSelectionKeyCode:C,panActivationKeyCode:j,zoomActivationKeyCode:E,elementsSelectable:$,zoomOnScroll:B,zoomOnPinch:_,zoomOnDoubleClick:O,panOnScroll:q,panOnScrollSpeed:H,panOnScrollMode:K,panOnDrag:U,defaultViewport:M,translateExtent:D,minZoom:z,maxZoom:I,onSelectionContextMenu:u,preventScrolling:P,noDragClassName:Ve,noWheelClassName:ct,noPanClassName:Oe,disableKeyboardA11y:re,onViewportChange:ne,isControlledViewport:!!J,children:r.jsxs(mg,{children:[r.jsx(fg,{edgeTypes:t,onEdgeClick:o,onEdgeDoubleClick:i,onReconnect:Be,onReconnectStart:$e,onReconnectEnd:Ie,onlyRenderVisibleElements:R,onEdgeContextMenu:ie,onEdgeMouseEnter:pe,onEdgeMouseMove:je,onEdgeMouseLeave:Se,reconnectRadius:Ne,defaultMarkerColor:L,noPanClassName:Oe,disableKeyboardA11y:re,rfId:xe}),r.jsx(vg,{style:b,type:g,component:k,containerStyle:v}),r.jsx("div",{className:"react-flow__edgelabel-renderer"}),r.jsx(Yp,{nodeTypes:e,onNodeClick:s,onNodeDoubleClick:a,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:f,nodeClickDistance:ue,onlyRenderVisibleElements:R,noPanClassName:Oe,noDragClassName:Ve,disableKeyboardA11y:re,nodeExtent:fe,rfId:xe}),r.jsx("div",{className:"react-flow__viewport-portal"})]})})}au.displayName="GraphView";const Sg=p.memo(au),Wl=({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,width:o,height:a,fitView:i,fitViewOptions:l,minZoom:c=.5,maxZoom:d=2,nodeOrigin:f,nodeExtent:u,zIndexMode:h="basic"}={})=>{const m=new Map,g=new Map,b=new Map,k=new Map,v=s??t??[],y=n??e??[],x=f??[0,0],w=u??lr;wd(b,k,v);const C=va(y,m,g,{nodeOrigin:x,nodeExtent:w,zIndexMode:h});let j=[0,0,1];if(i&&o&&a){const E=xr(m,{filter:M=>!!((M.width||M.initialWidth)&&(M.height||M.initialHeight))}),{x:S,y:R,zoom:$}=qa(E,o,a,c,d,l?.padding??.1);j=[S,R,$]}return{rfId:"1",width:o??0,height:a??0,transform:j,nodes:y,nodesInitialized:C,nodeLookup:m,parentLookup:g,edges:v,edgeLookup:k,connectionLookup:b,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:s!==void 0,panZoom:null,minZoom:c,maxZoom:d,translateExtent:lr,nodeExtent:w,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Is.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:{...nd},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:Fh,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:td,zIndexMode:h,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},Cg=({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,width:o,height:a,fitView:i,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:f,nodeExtent:u,zIndexMode:h})=>Vm((m,g)=>{async function b(){const{nodeLookup:k,panZoom:v,fitViewOptions:y,fitViewResolver:x,width:w,height:C,minZoom:j,maxZoom:E}=g();v&&(await qh({nodes:k,width:w,height:C,panZoom:v,minZoom:j,maxZoom:E},y),x?.resolve(!0),m({fitViewResolver:null}))}return{...Wl({nodes:e,edges:t,width:o,height:a,fitView:i,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:f,nodeExtent:u,defaultNodes:n,defaultEdges:s,zIndexMode:h}),setNodes:k=>{const{nodeLookup:v,parentLookup:y,nodeOrigin:x,elevateNodesOnSelect:w,fitViewQueued:C,zIndexMode:j}=g(),E=va(k,v,y,{nodeOrigin:x,nodeExtent:u,elevateNodesOnSelect:w,checkEquality:!0,zIndexMode:j});C&&E?(b(),m({nodes:k,nodesInitialized:E,fitViewQueued:!1,fitViewOptions:void 0})):m({nodes:k,nodesInitialized:E})},setEdges:k=>{const{connectionLookup:v,edgeLookup:y}=g();wd(v,y,k),m({edges:k})},setDefaultNodesAndEdges:(k,v)=>{if(k){const{setNodes:y}=g();y(k),m({hasDefaultNodes:!0})}if(v){const{setEdges:y}=g();y(v),m({hasDefaultEdges:!0})}},updateNodeInternals:k=>{const{triggerNodeChanges:v,nodeLookup:y,parentLookup:x,domNode:w,nodeOrigin:C,nodeExtent:j,debug:E,fitViewQueued:S,zIndexMode:R}=g(),{changes:$,updatedInternals:M}=dm(k,y,x,w,C,j,R);M&&(am(y,x,{nodeOrigin:C,nodeExtent:j,zIndexMode:R}),S?(b(),m({fitViewQueued:!1,fitViewOptions:void 0})):m({}),$?.length>0&&(E&&console.log("React Flow: trigger node changes",$),v?.($)))},updateNodePositions:(k,v=!1)=>{const y=[];let x=[];const{nodeLookup:w,triggerNodeChanges:C,connection:j,updateConnection:E,onNodesChangeMiddlewareMap:S}=g();for(const[R,$]of k){const M=w.get(R),D=!!(M?.expandParent&&M?.parentId&&$?.position),z={id:R,type:"position",position:D?{x:Math.max(0,$.position.x),y:Math.max(0,$.position.y)}:$.position,dragging:v};if(M&&j.inProgress&&j.fromNode.id===M.id){const I=ts(M,j.fromHandle,we.Left,!0);E({...j,from:I})}D&&M.parentId&&y.push({id:R,parentId:M.parentId,rect:{...$.internals.positionAbsolute,width:$.measured.width??0,height:$.measured.height??0}}),x.push(z)}if(y.length>0){const{parentLookup:R,nodeOrigin:$}=g(),M=Ka(y,w,R,$);x.push(...M)}for(const R of S.values())x=R(x);C(x)},triggerNodeChanges:k=>{const{onNodesChange:v,setNodes:y,nodes:x,hasDefaultNodes:w,debug:C}=g();if(k?.length){if(w){const j=Dd(k,x);y(j)}C&&console.log("React Flow: trigger node changes",k),v?.(k)}},triggerEdgeChanges:k=>{const{onEdgesChange:v,setEdges:y,edges:x,hasDefaultEdges:w,debug:C}=g();if(k?.length){if(w){const j=Od(k,x);y(j)}C&&console.log("React Flow: trigger edge changes",k),v?.(k)}},addSelectedNodes:k=>{const{multiSelectionActive:v,edgeLookup:y,nodeLookup:x,triggerNodeChanges:w,triggerEdgeChanges:C}=g();if(v){const j=k.map(E=>Un(E,!0));w(j);return}w(ws(x,new Set([...k]),!0)),C(ws(y))},addSelectedEdges:k=>{const{multiSelectionActive:v,edgeLookup:y,nodeLookup:x,triggerNodeChanges:w,triggerEdgeChanges:C}=g();if(v){const j=k.map(E=>Un(E,!0));C(j);return}C(ws(y,new Set([...k]))),w(ws(x,new Set,!0))},unselectNodesAndEdges:({nodes:k,edges:v}={})=>{const{edges:y,nodes:x,nodeLookup:w,triggerNodeChanges:C,triggerEdgeChanges:j}=g(),E=k||x,S=v||y,R=[];for(const M of E){if(!M.selected)continue;const D=w.get(M.id);D&&(D.selected=!1),R.push(Un(M.id,!1))}const $=[];for(const M of S)M.selected&&$.push(Un(M.id,!1));C(R),j($)},setMinZoom:k=>{const{panZoom:v,maxZoom:y}=g();v?.setScaleExtent([k,y]),m({minZoom:k})},setMaxZoom:k=>{const{panZoom:v,minZoom:y}=g();v?.setScaleExtent([y,k]),m({maxZoom:k})},setTranslateExtent:k=>{g().panZoom?.setTranslateExtent(k),m({translateExtent:k})},resetSelectedElements:()=>{const{edges:k,nodes:v,triggerNodeChanges:y,triggerEdgeChanges:x,elementsSelectable:w}=g();if(!w)return;const C=v.reduce((E,S)=>S.selected?[...E,Un(S.id,!1)]:E,[]),j=k.reduce((E,S)=>S.selected?[...E,Un(S.id,!1)]:E,[]);y(C),x(j)},setNodeExtent:k=>{const{nodes:v,nodeLookup:y,parentLookup:x,nodeOrigin:w,elevateNodesOnSelect:C,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]||(va(v,y,x,{nodeOrigin:w,nodeExtent:k,elevateNodesOnSelect:C,checkEquality:!1,zIndexMode:E}),m({nodeExtent:k}))},panBy:k=>{const{transform:v,width:y,height:x,panZoom:w,translateExtent:C}=g();return um({delta:k,panZoom:w,transform:v,translateExtent:C,width:y,height:x})},setCenter:async(k,v,y)=>{const{width:x,height:w,maxZoom:C,panZoom:j}=g();if(!j)return Promise.resolve(!1);const E=typeof y?.zoom<"u"?y.zoom:C;return await j.setViewport({x:x/2-k*E,y:w/2-v*E,zoom:E},{duration:y?.duration,ease:y?.ease,interpolate:y?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{m({connection:{...nd}})},updateConnection:k=>{m({connection:k})},reset:()=>m({...Wl()})}},Object.is);function Eg({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:s,initialWidth:o,initialHeight:a,initialMinZoom:i,initialMaxZoom:l,initialFitViewOptions:c,fitView:d,nodeOrigin:f,nodeExtent:u,zIndexMode:h,children:m}){const[g]=p.useState(()=>Cg({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,width:o,height:a,fitView:d,minZoom:i,maxZoom:l,fitViewOptions:c,nodeOrigin:f,nodeExtent:u,zIndexMode:h}));return r.jsx(Wm,{value:g,children:r.jsx(mp,{children:m})})}function Ig({children:e,nodes:t,edges:n,defaultNodes:s,defaultEdges:o,width:a,height:i,fitView:l,fitViewOptions:c,minZoom:d,maxZoom:f,nodeOrigin:u,nodeExtent:h,zIndexMode:m}){return p.useContext(Io)?r.jsx(r.Fragment,{children:e}):r.jsx(Eg,{initialNodes:t,initialEdges:n,defaultNodes:s,defaultEdges:o,initialWidth:a,initialHeight:i,fitView:l,initialFitViewOptions:c,initialMinZoom:d,initialMaxZoom:f,nodeOrigin:u,nodeExtent:h,zIndexMode:m,children:e})}const Tg={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function Mg({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,className:o,nodeTypes:a,edgeTypes:i,onNodeClick:l,onEdgeClick:c,onInit:d,onMove:f,onMoveStart:u,onMoveEnd:h,onConnect:m,onConnectStart:g,onConnectEnd:b,onClickConnectStart:k,onClickConnectEnd:v,onNodeMouseEnter:y,onNodeMouseMove:x,onNodeMouseLeave:w,onNodeContextMenu:C,onNodeDoubleClick:j,onNodeDragStart:E,onNodeDrag:S,onNodeDragStop:R,onNodesDelete:$,onEdgesDelete:M,onDelete:D,onSelectionChange:z,onSelectionDragStart:I,onSelectionDrag:P,onSelectionDragStop:L,onSelectionContextMenu:B,onSelectionStart:_,onSelectionEnd:q,onBeforeDelete:H,connectionMode:K,connectionLineType:O=Tn.Bezier,connectionLineStyle:U,connectionLineComponent:A,connectionLineContainerStyle:T,deleteKeyCode:V="Backspace",selectionKeyCode:W="Shift",selectionOnDrag:F=!1,selectionMode:Z=cr.Full,panActivationKeyCode:se="Space",multiSelectionKeyCode:ue=ur()?"Meta":"Control",zoomActivationKeyCode:ie=ur()?"Meta":"Control",snapToGrid:pe,snapGrid:je,onlyRenderVisibleElements:Se=!1,selectNodesOnDrag:Ne,nodesDraggable:Be,autoPanOnNodeFocus:$e,nodesConnectable:Ie,nodesFocusable:Ve,nodeOrigin:ct=_d,edgesFocusable:Oe,edgesReconnectable:re,elementsSelectable:fe=!0,defaultViewport:xe=rp,minZoom:J=.5,maxZoom:ne=2,translateExtent:ae=lr,preventScrolling:ke=!0,nodeExtent:ge,defaultMarkerColor:ve="#b1b1b7",zoomOnScroll:Me=!0,zoomOnPinch:nt=!0,panOnScroll:Pe=!1,panOnScrollSpeed:ee=.5,panOnScrollMode:Re=Jn.Free,zoomOnDoubleClick:We=!0,panOnDrag:ht=!0,onPaneClick:Je,onPaneMouseEnter:qe,onPaneMouseMove:Le,onPaneMouseLeave:Ke,onPaneScroll:kt,onPaneContextMenu:X,paneClickDistance:le=1,nodeClickDistance:ye=0,children:de,onReconnect:be,onReconnectStart:Ce,onReconnectEnd:Xe,onEdgeContextMenu:Ct,onEdgeDoubleClick:At,onEdgeMouseEnter:Et,onEdgeMouseMove:Ye,onEdgeMouseLeave:ot,reconnectRadius:It=10,onNodesChange:Ht,onEdgesChange:wn,noDragClassName:sn="nodrag",noWheelClassName:cn="nowheel",noPanClassName:mt="nopan",fitView:Ze,fitViewOptions:st,connectOnClick:Qe,attributionPosition:dt,proOptions:vt,defaultEdgeOptions:gt,elevateNodesOnSelect:Ot=!0,elevateEdgesOnSelect:Tt=!1,disableKeyboardA11y:Y=!1,autoPanOnConnect:me,autoPanOnNodeDrag:ze,autoPanSpeed:Fe,connectionRadius:_e,isValidConnection:St,onError:Rn,style:ss,id:kn,nodeDragThreshold:Cr,connectionDragThreshold:Er,viewport:Fs,onViewportChange:zo,width:Pt,height:Dn,colorMode:On="light",debug:Hs,onScroll:rs,ariaLabelConfig:vn,zIndexMode:$n="basic",...os},Vs){const dn=kn||"1",Pn=lp(On),jn=p.useCallback(Bn=>{Bn.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),rs?.(Bn)},[rs]);return r.jsx("div",{"data-testid":"rf__wrapper",...os,onScroll:jn,style:{...ss,...Tg},ref:Vs,className:Nt(["react-flow",o,Pn]),id:kn,role:"application",children:r.jsxs(Ig,{nodes:e,edges:t,width:Pt,height:Dn,fitView:Ze,fitViewOptions:st,minZoom:J,maxZoom:ne,nodeOrigin:ct,nodeExtent:ge,zIndexMode:$n,children:[r.jsx(Sg,{onInit:d,onNodeClick:l,onEdgeClick:c,onNodeMouseEnter:y,onNodeMouseMove:x,onNodeMouseLeave:w,onNodeContextMenu:C,onNodeDoubleClick:j,nodeTypes:a,edgeTypes:i,connectionLineType:O,connectionLineStyle:U,connectionLineComponent:A,connectionLineContainerStyle:T,selectionKeyCode:W,selectionOnDrag:F,selectionMode:Z,deleteKeyCode:V,multiSelectionKeyCode:ue,panActivationKeyCode:se,zoomActivationKeyCode:ie,onlyRenderVisibleElements:Se,defaultViewport:xe,translateExtent:ae,minZoom:J,maxZoom:ne,preventScrolling:ke,zoomOnScroll:Me,zoomOnPinch:nt,zoomOnDoubleClick:We,panOnScroll:Pe,panOnScrollSpeed:ee,panOnScrollMode:Re,panOnDrag:ht,onPaneClick:Je,onPaneMouseEnter:qe,onPaneMouseMove:Le,onPaneMouseLeave:Ke,onPaneScroll:kt,onPaneContextMenu:X,paneClickDistance:le,nodeClickDistance:ye,onSelectionContextMenu:B,onSelectionStart:_,onSelectionEnd:q,onReconnect:be,onReconnectStart:Ce,onReconnectEnd:Xe,onEdgeContextMenu:Ct,onEdgeDoubleClick:At,onEdgeMouseEnter:Et,onEdgeMouseMove:Ye,onEdgeMouseLeave:ot,reconnectRadius:It,defaultMarkerColor:ve,noDragClassName:sn,noWheelClassName:cn,noPanClassName:mt,rfId:dn,disableKeyboardA11y:Y,nodeExtent:ge,viewport:Fs,onViewportChange:zo}),r.jsx(ip,{nodes:e,edges:t,defaultNodes:n,defaultEdges:s,onConnect:m,onConnectStart:g,onConnectEnd:b,onClickConnectStart:k,onClickConnectEnd:v,nodesDraggable:Be,autoPanOnNodeFocus:$e,nodesConnectable:Ie,nodesFocusable:Ve,edgesFocusable:Oe,edgesReconnectable:re,elementsSelectable:fe,elevateNodesOnSelect:Ot,elevateEdgesOnSelect:Tt,minZoom:J,maxZoom:ne,nodeExtent:ge,onNodesChange:Ht,onEdgesChange:wn,snapToGrid:pe,snapGrid:je,connectionMode:K,translateExtent:ae,connectOnClick:Qe,defaultEdgeOptions:gt,fitView:Ze,fitViewOptions:st,onNodesDelete:$,onEdgesDelete:M,onDelete:D,onNodeDragStart:E,onNodeDrag:S,onNodeDragStop:R,onSelectionDrag:P,onSelectionDragStart:I,onSelectionDragStop:L,onMove:f,onMoveStart:u,onMoveEnd:h,noPanClassName:mt,nodeOrigin:ct,rfId:dn,autoPanOnConnect:me,autoPanOnNodeDrag:ze,autoPanSpeed:Fe,onError:Rn,connectionRadius:_e,isValidConnection:St,selectNodesOnDrag:Ne,nodeDragThreshold:Cr,connectionDragThreshold:Er,onBeforeDelete:H,debug:Hs,ariaLabelConfig:vn,zIndexMode:$n}),r.jsx(sp,{onSelectionChange:z}),de,r.jsx(Qm,{proOptions:vt,position:dt}),r.jsx(Zm,{rfId:dn,disableKeyboardA11y:Y})]})})}var Ag=$d(Mg);function Lg(){const e=lt();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 _g(e){const[t,n]=p.useState(e),s=p.useCallback(o=>n(a=>Dd(o,a)),[]);return[t,n,s]}function Rg(e){const[t,n]=p.useState(e),s=p.useCallback(o=>n(a=>Od(o,a)),[]);return[t,n,s]}function Dg({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:Nt(["react-flow__background-pattern",n,s])})}function Og({radius:e,className:t}){return r.jsx("circle",{cx:e,cy:e,r:e,className:Nt(["react-flow__background-pattern","dots",t])})}var An;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(An||(An={}));const $g={[An.Dots]:1,[An.Lines]:1,[An.Cross]:6},Pg=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function iu({id:e,variant:t=An.Dots,gap:n=20,size:s,lineWidth:o=1,offset:a=0,color:i,bgColor:l,style:c,className:d,patternClassName:f}){const u=p.useRef(null),{transform:h,patternId:m}=Ue(Pg,ut),g=s||$g[t],b=t===An.Dots,k=t===An.Cross,v=Array.isArray(n)?n:[n,n],y=[v[0]*h[2]||1,v[1]*h[2]||1],x=g*h[2],w=Array.isArray(a)?a:[a,a],C=k?[x,x]:y,j=[w[0]*h[2]||1+C[0]/2,w[1]*h[2]||1+C[1]/2],E=`${m}${e||""}`;return r.jsxs("svg",{className:Nt(["react-flow__background",d]),style:{...c,...Mo,"--xy-background-color-props":l,"--xy-background-pattern-color-props":i},ref:u,"data-testid":"rf__background",children:[r.jsx("pattern",{id:E,x:h[0]%y[0],y:h[1]%y[1],width:y[0],height:y[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${j[0]},-${j[1]})`,children:b?r.jsx(Og,{radius:x/2,className:f}):r.jsx(Dg,{dimensions:C,lineWidth:o,variant:t,className:f})}),r.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${E})`})]})}iu.displayName="Background";const Bg=p.memo(iu);function qg(){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 zg(){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 Fg(){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 Hg(){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 Vg(){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 Gr({children:e,className:t,...n}){return r.jsx("button",{type:"button",className:Nt(["react-flow__controls-button",t]),...n,children:e})}const Wg=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function lu({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:s=!0,fitViewOptions:o,onZoomIn:a,onZoomOut:i,onFitView:l,onInteractiveChange:c,className:d,children:f,position:u="bottom-left",orientation:h="vertical","aria-label":m}){const g=lt(),{isInteractive:b,minZoomReached:k,maxZoomReached:v,ariaLabelConfig:y}=Ue(Wg,ut),{zoomIn:x,zoomOut:w,fitView:C}=Ua(),j=()=>{x(),a?.()},E=()=>{w(),i?.()},S=()=>{C(o),l?.()},R=()=>{g.setState({nodesDraggable:!b,nodesConnectable:!b,elementsSelectable:!b}),c?.(!b)},$=h==="horizontal"?"horizontal":"vertical";return r.jsxs(To,{className:Nt(["react-flow__controls",$,d]),position:u,style:e,"data-testid":"rf__controls","aria-label":m??y["controls.ariaLabel"],children:[t&&r.jsxs(r.Fragment,{children:[r.jsx(Gr,{onClick:j,className:"react-flow__controls-zoomin",title:y["controls.zoomIn.ariaLabel"],"aria-label":y["controls.zoomIn.ariaLabel"],disabled:v,children:r.jsx(qg,{})}),r.jsx(Gr,{onClick:E,className:"react-flow__controls-zoomout",title:y["controls.zoomOut.ariaLabel"],"aria-label":y["controls.zoomOut.ariaLabel"],disabled:k,children:r.jsx(zg,{})})]}),n&&r.jsx(Gr,{className:"react-flow__controls-fitview",onClick:S,title:y["controls.fitView.ariaLabel"],"aria-label":y["controls.fitView.ariaLabel"],children:r.jsx(Fg,{})}),s&&r.jsx(Gr,{className:"react-flow__controls-interactive",onClick:R,title:y["controls.interactive.ariaLabel"],"aria-label":y["controls.interactive.ariaLabel"],children:b?r.jsx(Vg,{}):r.jsx(Hg,{})}),f]})}lu.displayName="Controls";const Kg=p.memo(lu);function Ug({id:e,x:t,y:n,width:s,height:o,style:a,color:i,strokeColor:l,strokeWidth:c,className:d,borderRadius:f,shapeRendering:u,selected:h,onClick:m}){const{background:g,backgroundColor:b}=a||{},k=i||g||b;return r.jsx("rect",{className:Nt(["react-flow__minimap-node",{selected:h},d]),x:t,y:n,rx:f,ry:f,width:s,height:o,style:{fill:k,stroke:l,strokeWidth:c},shapeRendering:u,onClick:m?v=>m(v,e):void 0})}const Yg=p.memo(Ug),Gg=e=>e.nodes.map(t=>t.id),aa=e=>e instanceof Function?e:()=>e;function Xg({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:s=5,nodeStrokeWidth:o,nodeComponent:a=Yg,onClick:i}){const l=Ue(Gg,ut),c=aa(t),d=aa(e),f=aa(n),u=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return r.jsx(r.Fragment,{children:l.map(h=>r.jsx(Qg,{id:h,nodeColorFunc:c,nodeStrokeColorFunc:d,nodeClassNameFunc:f,nodeBorderRadius:s,nodeStrokeWidth:o,NodeComponent:a,onClick:i,shapeRendering:u},h))})}function Zg({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:s,nodeBorderRadius:o,nodeStrokeWidth:a,shapeRendering:i,NodeComponent:l,onClick:c}){const{node:d,x:f,y:u,width:h,height:m}=Ue(g=>{const b=g.nodeLookup.get(e);if(!b)return{node:void 0,x:0,y:0,width:0,height:0};const k=b.internals.userNode,{x:v,y}=b.internals.positionAbsolute,{width:x,height:w}=yn(k);return{node:k,x:v,y,width:x,height:w}},ut);return!d||d.hidden||!cd(d)?null:r.jsx(l,{x:f,y:u,width:h,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 Qg=p.memo(Zg);var Jg=p.memo(Xg);const ex=200,tx=150,nx=e=>!e.hidden,sx=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?ld(xr(e.nodeLookup,{filter:nx}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},rx="react-flow__minimap-desc";function cu({style:e,className:t,nodeStrokeColor:n,nodeColor:s,nodeClassName:o="",nodeBorderRadius:a=5,nodeStrokeWidth:i,nodeComponent:l,bgColor:c,maskColor:d,maskStrokeColor:f,maskStrokeWidth:u,position:h="bottom-right",onClick:m,onNodeClick:g,pannable:b=!1,zoomable:k=!1,ariaLabel:v,inversePan:y,zoomStep:x=1,offsetScale:w=5}){const C=lt(),j=p.useRef(null),{boundingRect:E,viewBB:S,rfId:R,panZoom:$,translateExtent:M,flowWidth:D,flowHeight:z,ariaLabelConfig:I}=Ue(sx,ut),P=e?.width??ex,L=e?.height??tx,B=E.width/P,_=E.height/L,q=Math.max(B,_),H=q*P,K=q*L,O=w*q,U=E.x-(H-E.width)/2-O,A=E.y-(K-E.height)/2-O,T=H+O*2,V=K+O*2,W=`${rx}-${R}`,F=p.useRef(0),Z=p.useRef();F.current=q,p.useEffect(()=>{if(j.current&&$)return Z.current=wm({domNode:j.current,panZoom:$,getTransform:()=>C.getState().transform,getViewScale:()=>F.current}),()=>{Z.current?.destroy()}},[$]),p.useEffect(()=>{Z.current?.update({translateExtent:M,width:D,height:z,inversePan:y,pannable:b,zoomStep:x,zoomable:k})},[b,k,y,x,M,D,z]);const se=m?pe=>{const[je,Se]=Z.current?.pointer(pe)||[0,0];m(pe,{x:je,y:Se})}:void 0,ue=g?p.useCallback((pe,je)=>{const Se=C.getState().nodeLookup.get(je).internals.userNode;g(pe,Se)},[]):void 0,ie=v??I["minimap.ariaLabel"];return r.jsx(To,{position:h,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 f=="string"?f:void 0,"--xy-minimap-mask-stroke-width-props":typeof u=="number"?u*q: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:Nt(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:r.jsxs("svg",{width:P,height:L,viewBox:`${U} ${A} ${T} ${V}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":W,ref:j,onClick:se,children:[ie&&r.jsx("title",{id:W,children:ie}),r.jsx(Jg,{onClick:ue,nodeColor:s,nodeStrokeColor:n,nodeBorderRadius:a,nodeClassName:o,nodeStrokeWidth:i,nodeComponent:l}),r.jsx("path",{className:"react-flow__minimap-mask",d:`M${U-O},${A-O}h${T+O*2}v${V+O*2}h${-T-O*2}z
|
|
7
|
-
M${S.x},${S.y}h${S.width}v${S.height}h${-S.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}cu.displayName="MiniMap";const ox=p.memo(cu),ax=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,ix={[_s.Line]:"right",[_s.Handle]:"bottom-right"};function lx({nodeId:e,position:t,variant:n=_s.Handle,className:s,style:o=void 0,children:a,color:i,minWidth:l=10,minHeight:c=10,maxWidth:d=Number.MAX_VALUE,maxHeight:f=Number.MAX_VALUE,keepAspectRatio:u=!1,resizeDirection:h,autoScale:m=!0,shouldResize:g,onResizeStart:b,onResize:k,onResizeEnd:v}){const y=zd(),x=typeof e=="string"?e:y,w=lt(),C=p.useRef(null),j=n===_s.Handle,E=Ue(p.useCallback(ax(j&&m),[j,m]),ut),S=p.useRef(null),R=t??ix[n];p.useEffect(()=>{if(!(!C.current||!x))return S.current||(S.current=Rm({domNode:C.current,nodeId:x,getStoreItems:()=>{const{nodeLookup:M,transform:D,snapGrid:z,snapToGrid:I,nodeOrigin:P,domNode:L}=w.getState();return{nodeLookup:M,transform:D,snapGrid:z,snapToGrid:I,nodeOrigin:P,paneDomNode:L}},onChange:(M,D)=>{const{triggerNodeChanges:z,nodeLookup:I,parentLookup:P,nodeOrigin:L}=w.getState(),B=[],_={x:M.x,y:M.y},q=I.get(x);if(q&&q.expandParent&&q.parentId){const H=q.origin??L,K=M.width??q.measured.width??0,O=M.height??q.measured.height??0,U={id:q.id,parentId:q.parentId,rect:{width:K,height:O,...dd({x:M.x??q.position.x,y:M.y??q.position.y},{width:K,height:O},q.parentId,I,H)}},A=Ka([U],I,P,L);B.push(...A),_.x=M.x?Math.max(H[0]*K,M.x):void 0,_.y=M.y?Math.max(H[1]*O,M.y):void 0}if(_.x!==void 0&&_.y!==void 0){const H={id:x,type:"position",position:{..._}};B.push(H)}if(M.width!==void 0&&M.height!==void 0){const K={id:x,type:"dimensions",resizing:!0,setAttributes:h?h==="horizontal"?"width":"height":!0,dimensions:{width:M.width,height:M.height}};B.push(K)}for(const H of D){const K={...H,type:"position"};B.push(K)}z(B)},onEnd:({width:M,height:D})=>{const z={id:x,type:"dimensions",resizing:!1,dimensions:{width:M,height:D}};w.getState().triggerNodeChanges([z])}})),S.current.update({controlPosition:R,boundaries:{minWidth:l,minHeight:c,maxWidth:d,maxHeight:f},keepAspectRatio:u,resizeDirection:h,onResizeStart:b,onResize:k,onResizeEnd:v,shouldResize:g}),()=>{S.current?.destroy()}},[R,l,c,d,f,u,b,k,v,g]);const $=R.split("-");return r.jsx("div",{className:Nt(["react-flow__resize-control","nodrag",...$,n,s]),ref:C,style:{...o,scale:E,...i&&{[j?"backgroundColor":"borderColor"]:i}},children:a})}p.memo(lx);var et=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),tn=et((e,t)=>{var n=Object.defineProperty,s=(z,I,P)=>I in z?n(z,I,{enumerable:!0,configurable:!0,writable:!0,value:P}):z[I]=P,o=(z,I)=>()=>(I||z((I={exports:{}}).exports,I),I.exports),a=(z,I,P)=>s(z,typeof I!="symbol"?I+"":I,P),i=o((z,I)=>{var P="\0",L="\0",B="",_=class{constructor(A){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"),A&&(this._isDirected=Object.hasOwn(A,"directed")?A.directed:!0,this._isMultigraph=Object.hasOwn(A,"multigraph")?A.multigraph:!1,this._isCompound=Object.hasOwn(A,"compound")?A.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[L]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(A){return this._label=A,this}graph(){return this._label}setDefaultNodeLabel(A){return this._defaultNodeLabelFn=A,typeof A!="function"&&(this._defaultNodeLabelFn=()=>A),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var A=this;return this.nodes().filter(T=>Object.keys(A._in[T]).length===0)}sinks(){var A=this;return this.nodes().filter(T=>Object.keys(A._out[T]).length===0)}setNodes(A,T){var V=arguments,W=this;return A.forEach(function(F){V.length>1?W.setNode(F,T):W.setNode(F)}),this}setNode(A,T){return Object.hasOwn(this._nodes,A)?(arguments.length>1&&(this._nodes[A]=T),this):(this._nodes[A]=arguments.length>1?T:this._defaultNodeLabelFn(A),this._isCompound&&(this._parent[A]=L,this._children[A]={},this._children[L][A]=!0),this._in[A]={},this._preds[A]={},this._out[A]={},this._sucs[A]={},++this._nodeCount,this)}node(A){return this._nodes[A]}hasNode(A){return Object.hasOwn(this._nodes,A)}removeNode(A){var T=this;if(Object.hasOwn(this._nodes,A)){var V=W=>T.removeEdge(T._edgeObjs[W]);delete this._nodes[A],this._isCompound&&(this._removeFromParentsChildList(A),delete this._parent[A],this.children(A).forEach(function(W){T.setParent(W)}),delete this._children[A]),Object.keys(this._in[A]).forEach(V),delete this._in[A],delete this._preds[A],Object.keys(this._out[A]).forEach(V),delete this._out[A],delete this._sucs[A],--this._nodeCount}return this}setParent(A,T){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(T===void 0)T=L;else{T+="";for(var V=T;V!==void 0;V=this.parent(V))if(V===A)throw new Error("Setting "+T+" as parent of "+A+" would create a cycle");this.setNode(T)}return this.setNode(A),this._removeFromParentsChildList(A),this._parent[A]=T,this._children[T][A]=!0,this}_removeFromParentsChildList(A){delete this._children[this._parent[A]][A]}parent(A){if(this._isCompound){var T=this._parent[A];if(T!==L)return T}}children(A=L){if(this._isCompound){var T=this._children[A];if(T)return Object.keys(T)}else{if(A===L)return this.nodes();if(this.hasNode(A))return[]}}predecessors(A){var T=this._preds[A];if(T)return Object.keys(T)}successors(A){var T=this._sucs[A];if(T)return Object.keys(T)}neighbors(A){var T=this.predecessors(A);if(T){let W=new Set(T);for(var V of this.successors(A))W.add(V);return Array.from(W.values())}}isLeaf(A){var T;return this.isDirected()?T=this.successors(A):T=this.neighbors(A),T.length===0}filterNodes(A){var T=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});T.setGraph(this.graph());var V=this;Object.entries(this._nodes).forEach(function([Z,se]){A(Z)&&T.setNode(Z,se)}),Object.values(this._edgeObjs).forEach(function(Z){T.hasNode(Z.v)&&T.hasNode(Z.w)&&T.setEdge(Z,V.edge(Z))});var W={};function F(Z){var se=V.parent(Z);return se===void 0||T.hasNode(se)?(W[Z]=se,se):se in W?W[se]:F(se)}return this._isCompound&&T.nodes().forEach(Z=>T.setParent(Z,F(Z))),T}setDefaultEdgeLabel(A){return this._defaultEdgeLabelFn=A,typeof A!="function"&&(this._defaultEdgeLabelFn=()=>A),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(A,T){var V=this,W=arguments;return A.reduce(function(F,Z){return W.length>1?V.setEdge(F,Z,T):V.setEdge(F,Z),Z}),this}setEdge(){var A,T,V,W,F=!1,Z=arguments[0];typeof Z=="object"&&Z!==null&&"v"in Z?(A=Z.v,T=Z.w,V=Z.name,arguments.length===2&&(W=arguments[1],F=!0)):(A=Z,T=arguments[1],V=arguments[3],arguments.length>2&&(W=arguments[2],F=!0)),A=""+A,T=""+T,V!==void 0&&(V=""+V);var se=K(this._isDirected,A,T,V);if(Object.hasOwn(this._edgeLabels,se))return F&&(this._edgeLabels[se]=W),this;if(V!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(A),this.setNode(T),this._edgeLabels[se]=F?W:this._defaultEdgeLabelFn(A,T,V);var ue=O(this._isDirected,A,T,V);return A=ue.v,T=ue.w,Object.freeze(ue),this._edgeObjs[se]=ue,q(this._preds[T],A),q(this._sucs[A],T),this._in[T][se]=ue,this._out[A][se]=ue,this._edgeCount++,this}edge(A,T,V){var W=arguments.length===1?U(this._isDirected,arguments[0]):K(this._isDirected,A,T,V);return this._edgeLabels[W]}edgeAsObj(){let A=this.edge(...arguments);return typeof A!="object"?{label:A}:A}hasEdge(A,T,V){var W=arguments.length===1?U(this._isDirected,arguments[0]):K(this._isDirected,A,T,V);return Object.hasOwn(this._edgeLabels,W)}removeEdge(A,T,V){var W=arguments.length===1?U(this._isDirected,arguments[0]):K(this._isDirected,A,T,V),F=this._edgeObjs[W];return F&&(A=F.v,T=F.w,delete this._edgeLabels[W],delete this._edgeObjs[W],H(this._preds[T],A),H(this._sucs[A],T),delete this._in[T][W],delete this._out[A][W],this._edgeCount--),this}inEdges(A,T){return this.isDirected()?this.filterEdges(this._in[A],A,T):this.nodeEdges(A,T)}outEdges(A,T){return this.isDirected()?this.filterEdges(this._out[A],A,T):this.nodeEdges(A,T)}nodeEdges(A,T){if(A in this._nodes)return this.filterEdges({...this._in[A],...this._out[A]},A,T)}filterEdges(A,T,V){if(A){var W=Object.values(A);return V?W.filter(function(F){return F.v===T&&F.w===V||F.v===V&&F.w===T}):W}}};function q(A,T){A[T]?A[T]++:A[T]=1}function H(A,T){--A[T]||delete A[T]}function K(A,T,V,W){var F=""+T,Z=""+V;if(!A&&F>Z){var se=F;F=Z,Z=se}return F+B+Z+B+(W===void 0?P:W)}function O(A,T,V,W){var F=""+T,Z=""+V;if(!A&&F>Z){var se=F;F=Z,Z=se}var ue={v:F,w:Z};return W&&(ue.name=W),ue}function U(A,T){return K(A,T.v,T.w,T.name)}I.exports=_}),l=o((z,I)=>{I.exports="3.0.2"}),c=o((z,I)=>{I.exports={Graph:i(),version:l()}}),d=o((z,I)=>{var P=i();I.exports={write:L,read:q};function L(H){var K={options:{directed:H.isDirected(),multigraph:H.isMultigraph(),compound:H.isCompound()},nodes:B(H),edges:_(H)};return H.graph()!==void 0&&(K.value=structuredClone(H.graph())),K}function B(H){return H.nodes().map(function(K){var O=H.node(K),U=H.parent(K),A={v:K};return O!==void 0&&(A.value=O),U!==void 0&&(A.parent=U),A})}function _(H){return H.edges().map(function(K){var O=H.edge(K),U={v:K.v,w:K.w};return K.name!==void 0&&(U.name=K.name),O!==void 0&&(U.value=O),U})}function q(H){var K=new P(H.options).setGraph(H.value);return H.nodes.forEach(function(O){K.setNode(O.v,O.value),O.parent&&K.setParent(O.v,O.parent)}),H.edges.forEach(function(O){K.setEdge({v:O.v,w:O.w,name:O.name},O.value)}),K}}),f=o((z,I)=>{I.exports=L;var P=()=>1;function L(_,q,H,K){return B(_,String(q),H||P,K||function(O){return _.outEdges(O)})}function B(_,q,H,K){var O={},U=!0,A=0,T=_.nodes(),V=function(se){var ue=H(se);O[se.v].distance+ue<O[se.w].distance&&(O[se.w]={distance:O[se.v].distance+ue,predecessor:se.v},U=!0)},W=function(){T.forEach(function(se){K(se).forEach(function(ue){var ie=ue.v===se?ue.v:ue.w,pe=ie===ue.v?ue.w:ue.v;V({v:ie,w:pe})})})};T.forEach(function(se){var ue=se===q?0:Number.POSITIVE_INFINITY;O[se]={distance:ue}});for(var F=T.length,Z=1;Z<F&&(U=!1,A++,W(),!!U);Z++);if(A===F-1&&(U=!1,W(),U))throw new Error("The graph contains a negative weight cycle");return O}}),u=o((z,I)=>{I.exports=P;function P(L){var B={},_=[],q;function H(K){Object.hasOwn(B,K)||(B[K]=!0,q.push(K),L.successors(K).forEach(H),L.predecessors(K).forEach(H))}return L.nodes().forEach(function(K){q=[],H(K),q.length&&_.push(q)}),_}}),h=o((z,I)=>{var P=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 B=this._keyIndices[L];if(B!==void 0)return this._arr[B].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(L,B){var _=this._keyIndices;if(L=String(L),!Object.hasOwn(_,L)){var q=this._arr,H=q.length;return _[L]=H,q.push({key:L,priority:B}),this._decrease(H),!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,B){var _=this._keyIndices[L];if(B>this._arr[_].priority)throw new Error("New priority is greater than current priority. Key: "+L+" Old: "+this._arr[_].priority+" New: "+B);this._arr[_].priority=B,this._decrease(_)}_heapify(L){var B=this._arr,_=2*L,q=_+1,H=L;_<B.length&&(H=B[_].priority<B[H].priority?_:H,q<B.length&&(H=B[q].priority<B[H].priority?q:H),H!==L&&(this._swap(L,H),this._heapify(H)))}_decrease(L){for(var B=this._arr,_=B[L].priority,q;L!==0&&(q=L>>1,!(B[q].priority<_));)this._swap(L,q),L=q}_swap(L,B){var _=this._arr,q=this._keyIndices,H=_[L],K=_[B];_[L]=K,_[B]=H,q[K.key]=L,q[H.key]=B}};I.exports=P}),m=o((z,I)=>{var P=h();I.exports=B;var L=()=>1;function B(q,H,K,O){var U=function(A){return q.outEdges(A)};return _(q,String(H),K||L,O||U)}function _(q,H,K,O){var U={},A=new P,T,V,W=function(F){var Z=F.v!==T?F.v:F.w,se=U[Z],ue=K(F),ie=V.distance+ue;if(ue<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+F+" Weight: "+ue);ie<se.distance&&(se.distance=ie,se.predecessor=T,A.decrease(Z,ie))};for(q.nodes().forEach(function(F){var Z=F===H?0:Number.POSITIVE_INFINITY;U[F]={distance:Z},A.add(F,Z)});A.size()>0&&(T=A.removeMin(),V=U[T],V.distance!==Number.POSITIVE_INFINITY);)O(T).forEach(W);return U}}),g=o((z,I)=>{var P=m();I.exports=L;function L(B,_,q){return B.nodes().reduce(function(H,K){return H[K]=P(B,K,_,q),H},{})}}),b=o((z,I)=>{I.exports=P;function P(B,_,q){if(B[_].predecessor!==void 0)throw new Error("Invalid source vertex");if(B[q].predecessor===void 0&&q!==_)throw new Error("Invalid destination vertex");return{weight:B[q].distance,path:L(B,_,q)}}function L(B,_,q){for(var H=[],K=q;K!==_;)H.push(K),K=B[K].predecessor;return H.push(_),H.reverse()}}),k=o((z,I)=>{I.exports=P;function P(L){var B=0,_=[],q={},H=[];function K(O){var U=q[O]={onStack:!0,lowlink:B,index:B++};if(_.push(O),L.successors(O).forEach(function(V){Object.hasOwn(q,V)?q[V].onStack&&(U.lowlink=Math.min(U.lowlink,q[V].index)):(K(V),U.lowlink=Math.min(U.lowlink,q[V].lowlink))}),U.lowlink===U.index){var A=[],T;do T=_.pop(),q[T].onStack=!1,A.push(T);while(O!==T);H.push(A)}}return L.nodes().forEach(function(O){Object.hasOwn(q,O)||K(O)}),H}}),v=o((z,I)=>{var P=k();I.exports=L;function L(B){return P(B).filter(function(_){return _.length>1||_.length===1&&B.hasEdge(_[0],_[0])})}}),y=o((z,I)=>{I.exports=L;var P=()=>1;function L(_,q,H){return B(_,q||P,H||function(K){return _.outEdges(K)})}function B(_,q,H){var K={},O=_.nodes();return O.forEach(function(U){K[U]={},K[U][U]={distance:0},O.forEach(function(A){U!==A&&(K[U][A]={distance:Number.POSITIVE_INFINITY})}),H(U).forEach(function(A){var T=A.v===U?A.w:A.v,V=q(A);K[U][T]={distance:V,predecessor:U}})}),O.forEach(function(U){var A=K[U];O.forEach(function(T){var V=K[T];O.forEach(function(W){var F=V[U],Z=A[W],se=V[W],ue=F.distance+Z.distance;ue<se.distance&&(se.distance=ue,se.predecessor=Z.predecessor)})})}),K}}),x=o((z,I)=>{function P(B){var _={},q={},H=[];function K(O){if(Object.hasOwn(q,O))throw new L;Object.hasOwn(_,O)||(q[O]=!0,_[O]=!0,B.predecessors(O).forEach(K),delete q[O],H.push(O))}if(B.sinks().forEach(K),Object.keys(_).length!==B.nodeCount())throw new L;return H}var L=class extends Error{constructor(){super(...arguments)}};I.exports=P,P.CycleException=L}),w=o((z,I)=>{var P=x();I.exports=L;function L(B){try{P(B)}catch(_){if(_ instanceof P.CycleException)return!1;throw _}return!0}}),C=o((z,I)=>{I.exports=P;function P(B,_,q,H,K){Array.isArray(_)||(_=[_]);var O=(B.isDirected()?B.successors:B.neighbors).bind(B),U={};return _.forEach(function(A){if(!B.hasNode(A))throw new Error("Graph does not have node: "+A);K=L(B,A,q==="post",U,O,H,K)}),K}function L(B,_,q,H,K,O,U){return Object.hasOwn(H,_)||(H[_]=!0,q||(U=O(U,_)),K(_).forEach(function(A){U=L(B,A,q,H,K,O,U)}),q&&(U=O(U,_))),U}}),j=o((z,I)=>{var P=C();I.exports=L;function L(B,_,q){return P(B,_,q,function(H,K){return H.push(K),H},[])}}),E=o((z,I)=>{var P=j();I.exports=L;function L(B,_){return P(B,_,"post")}}),S=o((z,I)=>{var P=j();I.exports=L;function L(B,_){return P(B,_,"pre")}}),R=o((z,I)=>{var P=i(),L=h();I.exports=B;function B(_,q){var H=new P,K={},O=new L,U;function A(V){var W=V.v===U?V.w:V.v,F=O.priority(W);if(F!==void 0){var Z=q(V);Z<F&&(K[W]=U,O.decrease(W,Z))}}if(_.nodeCount()===0)return H;_.nodes().forEach(function(V){O.add(V,Number.POSITIVE_INFINITY),H.setNode(V)}),O.decrease(_.nodes()[0],0);for(var T=!1;O.size()>0;){if(U=O.removeMin(),Object.hasOwn(K,U))H.setEdge(U,K[U]);else{if(T)throw new Error("Input graph is not connected: "+_);T=!0}_.nodeEdges(U).forEach(A)}return H}}),$=o((z,I)=>{var P=m(),L=f();I.exports=B;function B(q,H,K,O){return _(q,H,K,O||function(U){return q.outEdges(U)})}function _(q,H,K,O){if(K===void 0)return P(q,H,K,O);for(var U=!1,A=q.nodes(),T=0;T<A.length;T++){for(var V=O(A[T]),W=0;W<V.length;W++){var F=V[W],Z=F.v===A[T]?F.v:F.w,se=Z===F.v?F.w:F.v;K({v:Z,w:se})<0&&(U=!0)}if(U)return L(q,H,K,O)}return P(q,H,K,O)}}),M=o((z,I)=>{I.exports={bellmanFord:f(),components:u(),dijkstra:m(),dijkstraAll:g(),extractPath:b(),findCycles:v(),floydWarshall:y(),isAcyclic:w(),postorder:E(),preorder:S(),prim:R(),shortestPaths:$(),reduce:C(),tarjan:k(),topsort:x()}}),D=c();t.exports={Graph:D.Graph,json:d(),alg:M(),version:D.version}}),cx=et((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}),dx=et((e,t)=>{var n=tn().Graph,s=cx();t.exports=a;var o=()=>1;function a(u,h){if(u.nodeCount()<=1)return[];let m=c(u,h||o);return i(m.graph,m.buckets,m.zeroIdx).flatMap(g=>u.outEdges(g.v,g.w))}function i(u,h,m){let g=[],b=h[h.length-1],k=h[0],v;for(;u.nodeCount();){for(;v=k.dequeue();)l(u,h,m,v);for(;v=b.dequeue();)l(u,h,m,v);if(u.nodeCount()){for(let y=h.length-2;y>0;--y)if(v=h[y].dequeue(),v){g=g.concat(l(u,h,m,v,!0));break}}}return g}function l(u,h,m,g,b){let k=b?[]:void 0;return u.inEdges(g.v).forEach(v=>{let y=u.edge(v),x=u.node(v.v);b&&k.push({v:v.v,w:v.w}),x.out-=y,d(h,m,x)}),u.outEdges(g.v).forEach(v=>{let y=u.edge(v),x=v.w,w=u.node(x);w.in-=y,d(h,m,w)}),u.removeNode(g.v),k}function c(u,h){let m=new n,g=0,b=0;u.nodes().forEach(y=>{m.setNode(y,{v:y,in:0,out:0})}),u.edges().forEach(y=>{let x=m.edge(y.v,y.w)||0,w=h(y),C=x+w;m.setEdge(y.v,y.w,C),b=Math.max(b,m.node(y.v).out+=w),g=Math.max(g,m.node(y.w).in+=w)});let k=f(b+g+3).map(()=>new s),v=g+1;return m.nodes().forEach(y=>{d(k,v,m.node(y))}),{graph:m,buckets:k,zeroIdx:v}}function d(u,h,m){m.out?m.in?u[m.out-m.in+h].enqueue(m):u[u.length-1].enqueue(m):u[0].enqueue(m)}function f(u){let h=[];for(let m=0;m<u;m++)h.push(m);return h}}),jt=et((e,t)=>{var n=tn().Graph;t.exports={addBorderNode:h,addDummyNode:s,applyWithChunking:b,asNonCompoundGraph:a,buildLayerMatrix:d,intersectRect:c,mapValues:S,maxRank:k,normalizeRanks:f,notime:x,partition:v,pick:E,predecessorWeights:l,range:j,removeEmptyRanks:u,simplify:o,successorWeights:i,time:y,uniqueId:C,zipObject:R};function s($,M,D,z){for(var I=z;$.hasNode(I);)I=C(z);return D.dummy=M,$.setNode(I,D),I}function o($){let M=new n().setGraph($.graph());return $.nodes().forEach(D=>M.setNode(D,$.node(D))),$.edges().forEach(D=>{let z=M.edge(D.v,D.w)||{weight:0,minlen:1},I=$.edge(D);M.setEdge(D.v,D.w,{weight:z.weight+I.weight,minlen:Math.max(z.minlen,I.minlen)})}),M}function a($){let M=new n({multigraph:$.isMultigraph()}).setGraph($.graph());return $.nodes().forEach(D=>{$.children(D).length||M.setNode(D,$.node(D))}),$.edges().forEach(D=>{M.setEdge(D,$.edge(D))}),M}function i($){let M=$.nodes().map(D=>{let z={};return $.outEdges(D).forEach(I=>{z[I.w]=(z[I.w]||0)+$.edge(I).weight}),z});return R($.nodes(),M)}function l($){let M=$.nodes().map(D=>{let z={};return $.inEdges(D).forEach(I=>{z[I.v]=(z[I.v]||0)+$.edge(I).weight}),z});return R($.nodes(),M)}function c($,M){let D=$.x,z=$.y,I=M.x-D,P=M.y-z,L=$.width/2,B=$.height/2;if(!I&&!P)throw new Error("Not possible to find intersection inside of the rectangle");let _,q;return Math.abs(P)*L>Math.abs(I)*B?(P<0&&(B=-B),_=B*I/P,q=B):(I<0&&(L=-L),_=L,q=L*P/I),{x:D+_,y:z+q}}function d($){let M=j(k($)+1).map(()=>[]);return $.nodes().forEach(D=>{let z=$.node(D),I=z.rank;I!==void 0&&(M[I][z.order]=D)}),M}function f($){let M=$.nodes().map(z=>{let I=$.node(z).rank;return I===void 0?Number.MAX_VALUE:I}),D=b(Math.min,M);$.nodes().forEach(z=>{let I=$.node(z);Object.hasOwn(I,"rank")&&(I.rank-=D)})}function u($){let M=$.nodes().map(L=>$.node(L).rank).filter(L=>L!==void 0),D=b(Math.min,M),z=[];$.nodes().forEach(L=>{let B=$.node(L).rank-D;z[B]||(z[B]=[]),z[B].push(L)});let I=0,P=$.graph().nodeRankFactor;Array.from(z).forEach((L,B)=>{L===void 0&&B%P!==0?--I:L!==void 0&&I&&L.forEach(_=>$.node(_).rank+=I)})}function h($,M,D,z){let I={width:0,height:0};return arguments.length>=4&&(I.rank=D,I.order=z),s($,"border",I,M)}function m($,M=g){let D=[];for(let z=0;z<$.length;z+=M){let I=$.slice(z,z+M);D.push(I)}return D}var g=65535;function b($,M){if(M.length>g){let D=m(M);return $.apply(null,D.map(z=>$.apply(null,z)))}else return $.apply(null,M)}function k($){let M=$.nodes().map(D=>{let z=$.node(D).rank;return z===void 0?Number.MIN_VALUE:z});return b(Math.max,M)}function v($,M){let D={lhs:[],rhs:[]};return $.forEach(z=>{M(z)?D.lhs.push(z):D.rhs.push(z)}),D}function y($,M){let D=Date.now();try{return M()}finally{console.log($+" time: "+(Date.now()-D)+"ms")}}function x($,M){return M()}var w=0;function C($){var M=++w;return $+(""+M)}function j($,M,D=1){M==null&&(M=$,$=0);let z=P=>P<M;D<0&&(z=P=>M<P);let I=[];for(let P=$;z(P);P+=D)I.push(P);return I}function E($,M){let D={};for(let z of M)$[z]!==void 0&&(D[z]=$[z]);return D}function S($,M){let D=M;return typeof M=="string"&&(D=z=>z[M]),Object.entries($).reduce((z,[I,P])=>(z[I]=D(P,I),z),{})}function R($,M){return $.reduce((D,z,I)=>(D[z]=M[I],D),{})}}),ux=et((e,t)=>{var n=dx(),s=jt().uniqueId;t.exports={run:o,undo:i};function o(l){(l.graph().acyclicer==="greedy"?n(l,c(l)):a(l)).forEach(d=>{let f=l.edge(d);l.removeEdge(d),f.forwardName=d.name,f.reversed=!0,l.setEdge(d.w,d.v,f,s("rev"))});function c(d){return f=>d.edge(f).weight}}function a(l){let c=[],d={},f={};function u(h){Object.hasOwn(f,h)||(f[h]=!0,d[h]=!0,l.outEdges(h).forEach(m=>{Object.hasOwn(d,m.w)?c.push(m):u(m.w)}),delete d[h])}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 f=d.forwardName;delete d.reversed,delete d.forwardName,l.setEdge(c.w,c.v,d,f)}})}}),fx=et((e,t)=>{var n=jt();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,f=l.w,u=i.node(f).rank,h=l.name,m=i.edge(l),g=m.labelRank;if(u===d+1)return;i.removeEdge(l);let b,k,v;for(v=0,++d;d<u;++v,++d)m.points=[],k={width:0,height:0,edgeLabel:m,edgeObj:l,rank:d},b=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,b,{weight:m.weight},h),v===0&&i.graph().dummyChains.push(b),c=b;i.setEdge(c,f,{weight:m.weight},h)}function a(i){i.graph().dummyChains.forEach(l=>{let c=i.node(l),d=c.edgeLabel,f;for(i.setEdge(c.edgeObj,d);c.dummy;)f=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=f,c=i.node(l)})}}),xo=et((e,t)=>{var{applyWithChunking:n}=jt();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 f=a.outEdges(c).map(h=>h==null?Number.POSITIVE_INFINITY:l(h.w)-a.edge(h).minlen);var u=n(Math.min,f);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}}),du=et((e,t)=>{var n=tn().Graph,s=xo().slack;t.exports=o;function o(c){var d=new n({directed:!1}),f=c.nodes()[0],u=c.nodeCount();d.setNode(f,{});for(var h,m;a(d,c)<u;)h=i(d,c),m=d.hasNode(h.v)?s(c,h):-s(c,h),l(d,c,m);return d}function a(c,d){function f(u){d.nodeEdges(u).forEach(h=>{var m=h.v,g=u===m?h.w:m;!c.hasNode(g)&&!s(d,h)&&(c.setNode(g,{}),c.setEdge(u,g,{}),f(g))})}return c.nodes().forEach(f),c.nodeCount()}function i(c,d){return d.edges().reduce((f,u)=>{let h=Number.POSITIVE_INFINITY;return c.hasNode(u.v)!==c.hasNode(u.w)&&(h=s(d,u)),h<f[0]?[h,u]:f},[Number.POSITIVE_INFINITY,null])[1]}function l(c,d,f){c.nodes().forEach(u=>d.node(u).rank+=f)}}),hx=et((e,t)=>{var n=du(),s=xo().slack,o=xo().longestPath,a=tn().alg.preorder,i=tn().alg.postorder,l=jt().simplify;t.exports=c,c.initLowLimValues=h,c.initCutValues=d,c.calcCutValue=u,c.leaveEdge=g,c.enterEdge=b,c.exchangeEdges=k;function c(w){w=l(w),o(w);var C=n(w);h(C),d(C,w);for(var j,E;j=g(C);)E=b(C,w,j),k(C,w,j,E)}function d(w,C){var j=i(w,w.nodes());j=j.slice(0,j.length-1),j.forEach(E=>f(w,C,E))}function f(w,C,j){var E=w.node(j),S=E.parent;w.edge(j,S).cutvalue=u(w,C,j)}function u(w,C,j){var E=w.node(j),S=E.parent,R=!0,$=C.edge(j,S),M=0;return $||(R=!1,$=C.edge(S,j)),M=$.weight,C.nodeEdges(j).forEach(D=>{var z=D.v===j,I=z?D.w:D.v;if(I!==S){var P=z===R,L=C.edge(D).weight;if(M+=P?L:-L,y(w,j,I)){var B=w.edge(j,I).cutvalue;M+=P?-B:B}}}),M}function h(w,C){arguments.length<2&&(C=w.nodes()[0]),m(w,{},1,C)}function m(w,C,j,E,S){var R=j,$=w.node(E);return C[E]=!0,w.neighbors(E).forEach(M=>{Object.hasOwn(C,M)||(j=m(w,C,j,M,E))}),$.low=R,$.lim=j++,S?$.parent=S:delete $.parent,j}function g(w){return w.edges().find(C=>w.edge(C).cutvalue<0)}function b(w,C,j){var E=j.v,S=j.w;C.hasEdge(E,S)||(E=j.w,S=j.v);var R=w.node(E),$=w.node(S),M=R,D=!1;R.lim>$.lim&&(M=$,D=!0);var z=C.edges().filter(I=>D===x(w,w.node(I.v),M)&&D!==x(w,w.node(I.w),M));return z.reduce((I,P)=>s(C,P)<s(C,I)?P:I)}function k(w,C,j,E){var S=j.v,R=j.w;w.removeEdge(S,R),w.setEdge(E.v,E.w,{}),h(w),d(w,C),v(w,C)}function v(w,C){var j=w.nodes().find(S=>!C.node(S).parent),E=a(w,j);E=E.slice(1),E.forEach(S=>{var R=w.node(S).parent,$=C.edge(S,R),M=!1;$||($=C.edge(R,S),M=!0),C.node(S).rank=C.node(R).rank+(M?$.minlen:-$.minlen)})}function y(w,C,j){return w.hasEdge(C,j)}function x(w,C,j){return j.low<=C.lim&&C.lim<=j.lim}}),mx=et((e,t)=>{var n=xo(),s=n.longestPath,o=du(),a=hx();t.exports=i;function i(f){var u=f.graph().ranker;if(u instanceof Function)return u(f);switch(f.graph().ranker){case"network-simplex":d(f);break;case"tight-tree":c(f);break;case"longest-path":l(f);break;case"none":break;default:d(f)}}var l=s;function c(f){s(f),o(f)}function d(f){a(f)}}),px=et((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,f=s(a,i,d.v,d.w),u=f.path,h=f.lca,m=0,g=u[m],b=!0;for(;l!==d.w;){if(c=a.node(l),b){for(;(g=u[m])!==h&&a.node(g).maxRank<c.rank;)m++;g===h&&(b=!1)}if(!b){for(;m<u.length-1&&a.node(g=u[m+1]).minRank<=c.rank;)m++;g=u[m]}a.setParent(l,g),l=a.successors(l)[0]}})}function s(a,i,l,c){let d=[],f=[],u=Math.min(i[l].low,i[c].low),h=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||h>i[m].lim));for(g=m,m=c;(m=a.parent(m))!==g;)f.push(m);return{path:d.concat(f.reverse()),lca:g}}function o(a){let i={},l=0;function c(d){let f=l;a.children(d).forEach(c),i[d]={low:f,lim:l++}}return a.children().forEach(c),i}}),gx=et((e,t)=>{var n=jt();t.exports={run:s,cleanup:l};function s(c){let d=n.addDummyNode(c,"root",{},"_root"),f=a(c),u=Object.values(f),h=n.applyWithChunking(Math.max,u)-1,m=2*h+1;c.graph().nestingRoot=d,c.edges().forEach(b=>c.edge(b).minlen*=m);let g=i(c)+1;c.children().forEach(b=>o(c,d,m,g,h,f,b)),c.graph().nodeRankFactor=m}function o(c,d,f,u,h,m,g){let b=c.children(g);if(!b.length){g!==d&&c.setEdge(d,g,{weight:0,minlen:f});return}let k=n.addBorderNode(c,"_bt"),v=n.addBorderNode(c,"_bb"),y=c.node(g);c.setParent(k,g),y.borderTop=k,c.setParent(v,g),y.borderBottom=v,b.forEach(x=>{o(c,d,f,u,h,m,x);let w=c.node(x),C=w.borderTop?w.borderTop:x,j=w.borderBottom?w.borderBottom:x,E=w.borderTop?u:2*u,S=C!==j?1:h-m[g]+1;c.setEdge(k,C,{weight:E,minlen:S,nestingEdge:!0}),c.setEdge(j,v,{weight:E,minlen:S,nestingEdge:!0})}),c.parent(g)||c.setEdge(d,k,{weight:0,minlen:h+m[g]})}function a(c){var d={};function f(u,h){var m=c.children(u);m&&m.length&&m.forEach(g=>f(g,h+1)),d[u]=h}return c.children().forEach(u=>f(u,1)),d}function i(c){return c.edges().reduce((d,f)=>d+c.edge(f).weight,0)}function l(c){var d=c.graph();c.removeNode(d.nestingRoot),delete d.nestingRoot,c.edges().forEach(f=>{var u=c.edge(f);u.nestingEdge&&c.removeEdge(f)})}}),xx=et((e,t)=>{var n=jt();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 f=d.minRank,u=d.maxRank+1;f<u;++f)o(a,"borderLeft","_bl",l,d,f),o(a,"borderRight","_br",l,d,f)}}a.children().forEach(i)}function o(a,i,l,c,d,f){let u={width:0,height:0,rank:f,borderType:i},h=d[i][f-1],m=n.addDummyNode(a,"border",u,l);d[i][f]=m,a.setParent(m,c),h&&a.setEdge(h,m,{weight:1})}}),bx=et((e,t)=>{t.exports={adjust:n,undo:s};function n(f){let u=f.graph().rankdir.toLowerCase();(u==="lr"||u==="rl")&&o(f)}function s(f){let u=f.graph().rankdir.toLowerCase();(u==="bt"||u==="rl")&&i(f),(u==="lr"||u==="rl")&&(c(f),o(f))}function o(f){f.nodes().forEach(u=>a(f.node(u))),f.edges().forEach(u=>a(f.edge(u)))}function a(f){let u=f.width;f.width=f.height,f.height=u}function i(f){f.nodes().forEach(u=>l(f.node(u))),f.edges().forEach(u=>{let h=f.edge(u);h.points.forEach(l),Object.hasOwn(h,"y")&&l(h)})}function l(f){f.y=-f.y}function c(f){f.nodes().forEach(u=>d(f.node(u))),f.edges().forEach(u=>{let h=f.edge(u);h.points.forEach(d),Object.hasOwn(h,"x")&&d(h)})}function d(f){let u=f.x;f.x=f.y,f.y=u}}),yx=et((e,t)=>{var n=jt();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 f(u){if(a[u])return;a[u]=!0;let h=o.node(u);d[h.rank].push(u),o.successors(u).forEach(f)}return i.sort((u,h)=>o.node(u).rank-o.node(h).rank).forEach(f),d}}),wx=et((e,t)=>{var n=jt().zipObject;t.exports=s;function s(a,i){let l=0;for(let c=1;c<i.length;++c)l+=o(a,i[c-1],i[c]);return l}function o(a,i,l){let c=n(l,l.map((g,b)=>b)),d=i.flatMap(g=>a.outEdges(g).map(b=>({pos:c[b.w],weight:a.edge(b).weight})).sort((b,k)=>b.pos-k.pos)),f=1;for(;f<l.length;)f<<=1;let u=2*f-1;f-=1;let h=new Array(u).fill(0),m=0;return d.forEach(g=>{let b=g.pos+f;h[b]+=g.weight;let k=0;for(;b>0;)b%2&&(k+=h[b+1]),b=b-1>>1,h[b]+=g.weight;m+=g.weight*k}),m}}),kx=et((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 f=s.edge(d),u=s.node(d.v);return{sum:c.sum+f.weight*u.order,weight:c.weight+f.weight}},{sum:0,weight:0});return{v:a,barycenter:l.sum/l.weight,weight:l.weight}}else return{v:a}})}}),vx=et((e,t)=>{var n=jt();t.exports=s;function s(i,l){let c={};i.forEach((f,u)=>{let h=c[f.v]={indegree:0,in:[],out:[],vs:[f.v],i:u};f.barycenter!==void 0&&(h.barycenter=f.barycenter,h.weight=f.weight)}),l.edges().forEach(f=>{let u=c[f.v],h=c[f.w];u!==void 0&&h!==void 0&&(h.indegree++,u.out.push(c[f.w]))});let d=Object.values(c).filter(f=>!f.indegree);return o(d)}function o(i){let l=[];function c(f){return u=>{u.merged||(u.barycenter===void 0||f.barycenter===void 0||u.barycenter>=f.barycenter)&&a(f,u)}}function d(f){return u=>{u.in.push(f),--u.indegree===0&&i.push(u)}}for(;i.length;){let f=i.pop();l.push(f),f.in.reverse().forEach(c(f)),f.out.forEach(d(f))}return l.filter(f=>!f.merged).map(f=>n.pick(f,["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}}),jx=et((e,t)=>{var n=jt();t.exports=s;function s(i,l){let c=n.partition(i,k=>Object.hasOwn(k,"barycenter")),d=c.lhs,f=c.rhs.sort((k,v)=>v.i-k.i),u=[],h=0,m=0,g=0;d.sort(a(!!l)),g=o(u,f,g),d.forEach(k=>{g+=k.vs.length,u.push(k.vs),h+=k.barycenter*k.weight,m+=k.weight,g=o(u,f,g)});let b={vs:u.flat(!0)};return m&&(b.barycenter=h/m,b.weight=m),b}function o(i,l,c){let d;for(;l.length&&(d=l[l.length-1]).i<=c;)l.pop(),i.push(d.vs),c++;return c}function a(i){return(l,c)=>l.barycenter<c.barycenter?-1:l.barycenter>c.barycenter?1:i?c.i-l.i:l.i-c.i}}),Nx=et((e,t)=>{var n=kx(),s=vx(),o=jx();t.exports=a;function a(c,d,f,u){let h=c.children(d),m=c.node(d),g=m?m.borderLeft:void 0,b=m?m.borderRight:void 0,k={};g&&(h=h.filter(w=>w!==g&&w!==b));let v=n(c,h);v.forEach(w=>{if(c.children(w.v).length){let C=a(c,w.v,f,u);k[w.v]=C,Object.hasOwn(C,"barycenter")&&l(w,C)}});let y=s(v,f);i(y,k);let x=o(y,u);if(g&&(x.vs=[g,x.vs,b].flat(!0),c.predecessors(g).length)){let w=c.node(c.predecessors(g)[0]),C=c.node(c.predecessors(b)[0]);Object.hasOwn(x,"barycenter")||(x.barycenter=0,x.weight=0),x.barycenter=(x.barycenter*x.weight+w.order+C.order)/(x.weight+2),x.weight+=2}return x}function i(c,d){c.forEach(f=>{f.vs=f.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)}}),Sx=et((e,t)=>{var n=tn().Graph,s=jt();t.exports=o;function o(i,l,c,d){d||(d=i.nodes());let f=a(i),u=new n({compound:!0}).setGraph({root:f}).setDefaultNodeLabel(h=>i.node(h));return d.forEach(h=>{let m=i.node(h),g=i.parent(h);(m.rank===l||m.minRank<=l&&l<=m.maxRank)&&(u.setNode(h),u.setParent(h,g||f),i[c](h).forEach(b=>{let k=b.v===h?b.w:b.v,v=u.edge(k,h),y=v!==void 0?v.weight:0;u.setEdge(k,h,{weight:i.edge(b).weight+y})}),Object.hasOwn(m,"minRank")&&u.setNode(h,{borderLeft:m.borderLeft[l],borderRight:m.borderRight[l]}))}),u}function a(i){for(var l;i.hasNode(l=s.uniqueId("_root")););return l}}),Cx=et((e,t)=>{t.exports=n;function n(s,o,a){let i={},l;a.forEach(c=>{let d=s.parent(c),f,u;for(;d;){if(f=s.parent(d),f?(u=i[f],i[f]=d):(u=l,l=d),u&&u!==d){o.setEdge(u,d);return}d=f}})}}),Ex=et((e,t)=>{var n=yx(),s=wx(),o=Nx(),a=Sx(),i=Cx(),l=tn().Graph,c=jt();t.exports=d;function d(m,g={}){if(typeof g.customOrder=="function"){g.customOrder(m,d);return}let b=c.maxRank(m),k=f(m,c.range(1,b+1),"inEdges"),v=f(m,c.range(b-1,-1,-1),"outEdges"),y=n(m);if(h(m,y),g.disableOptimalOrderHeuristic)return;let x=Number.POSITIVE_INFINITY,w,C=g.constraints||[];for(let j=0,E=0;E<4;++j,++E){u(j%2?k:v,j%4>=2,C),y=c.buildLayerMatrix(m);let S=s(m,y);S<x?(E=0,w=Object.assign({},y),x=S):S===x&&(w=structuredClone(y))}h(m,w)}function f(m,g,b){let k=new Map,v=(y,x)=>{k.has(y)||k.set(y,[]),k.get(y).push(x)};for(let y of m.nodes()){let x=m.node(y);if(typeof x.rank=="number"&&v(x.rank,y),typeof x.minRank=="number"&&typeof x.maxRank=="number")for(let w=x.minRank;w<=x.maxRank;w++)w!==x.rank&&v(w,y)}return g.map(function(y){return a(m,y,b,k.get(y)||[])})}function u(m,g,b){let k=new l;m.forEach(function(v){b.forEach(w=>k.setEdge(w.left,w.right));let y=v.graph().root,x=o(v,y,k,g);x.vs.forEach((w,C)=>v.node(w).order=C),i(v,k,x.vs)})}function h(m,g){Object.values(g).forEach(b=>b.forEach((k,v)=>m.node(k).order=v))}}),Ix=et((e,t)=>{var n=tn().Graph,s=jt();t.exports={positionX:b,findType1Conflicts:o,findType2Conflicts:a,addConflict:l,hasConflict:c,verticalAlignment:d,horizontalCompaction:f,alignCoordinates:m,findSmallestWidthAlignment:h,balance:g};function o(y,x){let w={};function C(j,E){let S=0,R=0,$=j.length,M=E[E.length-1];return E.forEach((D,z)=>{let I=i(y,D),P=I?y.node(I).order:$;(I||D===M)&&(E.slice(R,z+1).forEach(L=>{y.predecessors(L).forEach(B=>{let _=y.node(B),q=_.order;(q<S||P<q)&&!(_.dummy&&y.node(L).dummy)&&l(w,B,L)})}),R=z+1,S=P)}),E}return x.length&&x.reduce(C),w}function a(y,x){let w={};function C(E,S,R,$,M){let D;s.range(S,R).forEach(z=>{D=E[z],y.node(D).dummy&&y.predecessors(D).forEach(I=>{let P=y.node(I);P.dummy&&(P.order<$||P.order>M)&&l(w,I,D)})})}function j(E,S){let R=-1,$,M=0;return S.forEach((D,z)=>{if(y.node(D).dummy==="border"){let I=y.predecessors(D);I.length&&($=y.node(I[0]).order,C(S,M,z,R,$),M=z,R=$)}C(S,M,S.length,$,E.length)}),S}return x.length&&x.reduce(j),w}function i(y,x){if(y.node(x).dummy)return y.predecessors(x).find(w=>y.node(w).dummy)}function l(y,x,w){if(x>w){let j=x;x=w,w=j}let C=y[x];C||(y[x]=C={}),C[w]=!0}function c(y,x,w){if(x>w){let C=x;x=w,w=C}return!!y[x]&&Object.hasOwn(y[x],w)}function d(y,x,w,C){let j={},E={},S={};return x.forEach(R=>{R.forEach(($,M)=>{j[$]=$,E[$]=$,S[$]=M})}),x.forEach(R=>{let $=-1;R.forEach(M=>{let D=C(M);if(D.length){D=D.sort((I,P)=>S[I]-S[P]);let z=(D.length-1)/2;for(let I=Math.floor(z),P=Math.ceil(z);I<=P;++I){let L=D[I];E[M]===M&&$<S[L]&&!c(w,M,L)&&(E[L]=M,E[M]=j[M]=j[L],$=S[L])}}})}),{root:j,align:E}}function f(y,x,w,C,j){let E={},S=u(y,x,w,j),R=j?"borderLeft":"borderRight";function $(z,I){let P=S.nodes().slice(),L={},B=P.pop();for(;B;){if(L[B])z(B);else{L[B]=!0,P.push(B);for(let _ of I(B))P.push(_)}B=P.pop()}}function M(z){E[z]=S.inEdges(z).reduce((I,P)=>Math.max(I,E[P.v]+S.edge(P)),0)}function D(z){let I=S.outEdges(z).reduce((L,B)=>Math.min(L,E[B.w]-S.edge(B)),Number.POSITIVE_INFINITY),P=y.node(z);I!==Number.POSITIVE_INFINITY&&P.borderType!==R&&(E[z]=Math.max(E[z],I))}return $(M,S.predecessors.bind(S)),$(D,S.successors.bind(S)),Object.keys(C).forEach(z=>E[z]=E[w[z]]),E}function u(y,x,w,C){let j=new n,E=y.graph(),S=k(E.nodesep,E.edgesep,C);return x.forEach(R=>{let $;R.forEach(M=>{let D=w[M];if(j.setNode(D),$){var z=w[$],I=j.edge(z,D);j.setEdge(z,D,Math.max(S(y,M,$),I||0))}$=M})}),j}function h(y,x){return Object.values(x).reduce((w,C)=>{let j=Number.NEGATIVE_INFINITY,E=Number.POSITIVE_INFINITY;Object.entries(C).forEach(([R,$])=>{let M=v(y,R)/2;j=Math.max($+M,j),E=Math.min($-M,E)});let S=j-E;return S<w[0]&&(w=[S,C]),w},[Number.POSITIVE_INFINITY,null])[1]}function m(y,x){let w=Object.values(x),C=s.applyWithChunking(Math.min,w),j=s.applyWithChunking(Math.max,w);["u","d"].forEach(E=>{["l","r"].forEach(S=>{let R=E+S,$=y[R];if($===x)return;let M=Object.values($),D=C-s.applyWithChunking(Math.min,M);S!=="l"&&(D=j-s.applyWithChunking(Math.max,M)),D&&(y[R]=s.mapValues($,z=>z+D))})})}function g(y,x){return s.mapValues(y.ul,(w,C)=>{if(x)return y[x.toLowerCase()][C];{let j=Object.values(y).map(E=>E[C]).sort((E,S)=>E-S);return(j[1]+j[2])/2}})}function b(y){let x=s.buildLayerMatrix(y),w=Object.assign(o(y,x),a(y,x)),C={},j;["u","d"].forEach(S=>{j=S==="u"?x:Object.values(x).reverse(),["l","r"].forEach(R=>{R==="r"&&(j=j.map(z=>Object.values(z).reverse()));let $=(S==="u"?y.predecessors:y.successors).bind(y),M=d(y,j,w,$),D=f(y,j,M.root,M.align,R==="r");R==="r"&&(D=s.mapValues(D,z=>-z)),C[S+R]=D})});let E=h(y,C);return m(C,E),g(C,y.graph().align)}function k(y,x,w){return(C,j,E)=>{let S=C.node(j),R=C.node(E),$=0,M;if($+=S.width/2,Object.hasOwn(S,"labelpos"))switch(S.labelpos.toLowerCase()){case"l":M=-S.width/2;break;case"r":M=S.width/2;break}if(M&&($+=w?M:-M),M=0,$+=(S.dummy?x:y)/2,$+=(R.dummy?x:y)/2,$+=R.width/2,Object.hasOwn(R,"labelpos"))switch(R.labelpos.toLowerCase()){case"l":M=R.width/2;break;case"r":M=-R.width/2;break}return M&&($+=w?M:-M),M=0,$}}function v(y,x){return y.node(x).width}}),Tx=et((e,t)=>{var n=jt(),s=Ix().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,f=0;l.forEach(u=>{let h=u.reduce((m,g)=>{let b=i.node(g).height;return m>b?m:b},0);u.forEach(m=>{let g=i.node(m);d==="top"?g.y=f+g.height/2:d==="bottom"?g.y=f+h-g.height/2:g.y=f+h/2}),f+=h+c})}}),Mx=et((e,t)=>{var n=ux(),s=fx(),o=mx(),a=jt().normalizeRanks,i=px(),l=jt().removeEmptyRanks,c=gx(),d=xx(),f=bx(),u=Ex(),h=Tx(),m=jt(),g=tn().Graph;t.exports=b;function b(T,V={}){let W=V.debugTiming?m.time:m.notime;return W("layout",()=>{let F=W(" buildLayoutGraph",()=>$(T));return W(" runLayout",()=>k(F,W,V)),W(" updateInputGraph",()=>v(T,F)),F})}function k(T,V,W){V(" makeSpaceForEdgeLabels",()=>M(T)),V(" removeSelfEdges",()=>H(T)),V(" acyclic",()=>n.run(T)),V(" nestingGraph.run",()=>c.run(T)),V(" rank",()=>o(m.asNonCompoundGraph(T))),V(" injectEdgeLabelProxies",()=>D(T)),V(" removeEmptyRanks",()=>l(T)),V(" nestingGraph.cleanup",()=>c.cleanup(T)),V(" normalizeRanks",()=>a(T)),V(" assignRankMinMax",()=>z(T)),V(" removeEdgeLabelProxies",()=>I(T)),V(" normalize.run",()=>s.run(T)),V(" parentDummyChains",()=>i(T)),V(" addBorderSegments",()=>d(T)),V(" order",()=>u(T,W)),V(" insertSelfEdges",()=>K(T)),V(" adjustCoordinateSystem",()=>f.adjust(T)),V(" position",()=>h(T)),V(" positionSelfEdges",()=>O(T)),V(" removeBorderNodes",()=>q(T)),V(" normalize.undo",()=>s.undo(T)),V(" fixupEdgeLabelCoords",()=>B(T)),V(" undoCoordinateSystem",()=>f.undo(T)),V(" translateGraph",()=>P(T)),V(" assignNodeIntersects",()=>L(T)),V(" reversePoints",()=>_(T)),V(" acyclic.undo",()=>n.undo(T))}function v(T,V){T.nodes().forEach(W=>{let F=T.node(W),Z=V.node(W);F&&(F.x=Z.x,F.y=Z.y,F.order=Z.order,F.rank=Z.rank,V.children(W).length&&(F.width=Z.width,F.height=Z.height))}),T.edges().forEach(W=>{let F=T.edge(W),Z=V.edge(W);F.points=Z.points,Object.hasOwn(Z,"x")&&(F.x=Z.x,F.y=Z.y)}),T.graph().width=V.graph().width,T.graph().height=V.graph().height}var y=["nodesep","edgesep","ranksep","marginx","marginy"],x={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},w=["acyclicer","ranker","rankdir","align","rankalign"],C=["width","height","rank"],j={width:0,height:0},E=["minlen","weight","width","height","labeloffset"],S={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},R=["labelpos"];function $(T){let V=new g({multigraph:!0,compound:!0}),W=A(T.graph());return V.setGraph(Object.assign({},x,U(W,y),m.pick(W,w))),T.nodes().forEach(F=>{let Z=A(T.node(F)),se=U(Z,C);Object.keys(j).forEach(ue=>{se[ue]===void 0&&(se[ue]=j[ue])}),V.setNode(F,se),V.setParent(F,T.parent(F))}),T.edges().forEach(F=>{let Z=A(T.edge(F));V.setEdge(F,Object.assign({},S,U(Z,E),m.pick(Z,R)))}),V}function M(T){let V=T.graph();V.ranksep/=2,T.edges().forEach(W=>{let F=T.edge(W);F.minlen*=2,F.labelpos.toLowerCase()!=="c"&&(V.rankdir==="TB"||V.rankdir==="BT"?F.width+=F.labeloffset:F.height+=F.labeloffset)})}function D(T){T.edges().forEach(V=>{let W=T.edge(V);if(W.width&&W.height){let F=T.node(V.v),Z={rank:(T.node(V.w).rank-F.rank)/2+F.rank,e:V};m.addDummyNode(T,"edge-proxy",Z,"_ep")}})}function z(T){let V=0;T.nodes().forEach(W=>{let F=T.node(W);F.borderTop&&(F.minRank=T.node(F.borderTop).rank,F.maxRank=T.node(F.borderBottom).rank,V=Math.max(V,F.maxRank))}),T.graph().maxRank=V}function I(T){T.nodes().forEach(V=>{let W=T.node(V);W.dummy==="edge-proxy"&&(T.edge(W.e).labelRank=W.rank,T.removeNode(V))})}function P(T){let V=Number.POSITIVE_INFINITY,W=0,F=Number.POSITIVE_INFINITY,Z=0,se=T.graph(),ue=se.marginx||0,ie=se.marginy||0;function pe(je){let Se=je.x,Ne=je.y,Be=je.width,$e=je.height;V=Math.min(V,Se-Be/2),W=Math.max(W,Se+Be/2),F=Math.min(F,Ne-$e/2),Z=Math.max(Z,Ne+$e/2)}T.nodes().forEach(je=>pe(T.node(je))),T.edges().forEach(je=>{let Se=T.edge(je);Object.hasOwn(Se,"x")&&pe(Se)}),V-=ue,F-=ie,T.nodes().forEach(je=>{let Se=T.node(je);Se.x-=V,Se.y-=F}),T.edges().forEach(je=>{let Se=T.edge(je);Se.points.forEach(Ne=>{Ne.x-=V,Ne.y-=F}),Object.hasOwn(Se,"x")&&(Se.x-=V),Object.hasOwn(Se,"y")&&(Se.y-=F)}),se.width=W-V+ue,se.height=Z-F+ie}function L(T){T.edges().forEach(V=>{let W=T.edge(V),F=T.node(V.v),Z=T.node(V.w),se,ue;W.points?(se=W.points[0],ue=W.points[W.points.length-1]):(W.points=[],se=Z,ue=F),W.points.unshift(m.intersectRect(F,se)),W.points.push(m.intersectRect(Z,ue))})}function B(T){T.edges().forEach(V=>{let W=T.edge(V);if(Object.hasOwn(W,"x"))switch((W.labelpos==="l"||W.labelpos==="r")&&(W.width-=W.labeloffset),W.labelpos){case"l":W.x-=W.width/2+W.labeloffset;break;case"r":W.x+=W.width/2+W.labeloffset;break}})}function _(T){T.edges().forEach(V=>{let W=T.edge(V);W.reversed&&W.points.reverse()})}function q(T){T.nodes().forEach(V=>{if(T.children(V).length){let W=T.node(V),F=T.node(W.borderTop),Z=T.node(W.borderBottom),se=T.node(W.borderLeft[W.borderLeft.length-1]),ue=T.node(W.borderRight[W.borderRight.length-1]);W.width=Math.abs(ue.x-se.x),W.height=Math.abs(Z.y-F.y),W.x=se.x+W.width/2,W.y=F.y+W.height/2}}),T.nodes().forEach(V=>{T.node(V).dummy==="border"&&T.removeNode(V)})}function H(T){T.edges().forEach(V=>{if(V.v===V.w){var W=T.node(V.v);W.selfEdges||(W.selfEdges=[]),W.selfEdges.push({e:V,label:T.edge(V)}),T.removeEdge(V)}})}function K(T){var V=m.buildLayerMatrix(T);V.forEach(W=>{var F=0;W.forEach((Z,se)=>{var ue=T.node(Z);ue.order=se+F,(ue.selfEdges||[]).forEach(ie=>{m.addDummyNode(T,"selfedge",{width:ie.label.width,height:ie.label.height,rank:ue.rank,order:se+ ++F,e:ie.e,label:ie.label},"_se")}),delete ue.selfEdges})})}function O(T){T.nodes().forEach(V=>{var W=T.node(V);if(W.dummy==="selfedge"){var F=T.node(W.e.v),Z=F.x+F.width/2,se=F.y,ue=W.x-Z,ie=F.height/2;T.setEdge(W.e,W.label),T.removeNode(V),W.label.points=[{x:Z+2*ue/3,y:se-ie},{x:Z+5*ue/6,y:se-ie},{x:Z+ue,y:se},{x:Z+5*ue/6,y:se+ie},{x:Z+2*ue/3,y:se+ie}],W.label.x=W.x,W.label.y=W.y}})}function U(T,V){return m.mapValues(m.pick(T,V),Number)}function A(T){var V={};return T&&Object.entries(T).forEach(([W,F])=>{typeof W=="string"&&(W=W.toLowerCase()),V[W]=F}),V}}),Ax=et((e,t)=>{var n=jt(),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 f="layer"+d;l.setNode(f,{rank:"same"}),c.reduce((u,h)=>(l.setEdge(u,h,{style:"invis"}),h))}),l}}),Lx=et((e,t)=>{t.exports="2.0.4"}),_x=et((e,t)=>{t.exports={graphlib:tn(),layout:Mx(),debug:Ax(),util:{time:jt().time,notime:jt().notime},version:Lx()}});const Kl=_x();const Ul={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"}},Rx={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function Dx({data:e}){const{t}=He(["work","common"]),{task:n,agentName:s,selected:o,direction:a="TB",isExpandedRoot:i,onCollapse:l}=e,c=Ul[n.status]??Ul.pending,d=n.taskType==="scheduled"&&!!n.scheduleConfig,f=d?n.scheduleConfig.every?t("work:task.everyInterval",{interval:n.scheduleConfig.every}):n.scheduleConfig.cron?t("work:task.cronLabel"):"":"",u=a==="LR"?we.Left:we.Top,h=a==="LR"?we.Right:we.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(_n,{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 ${Rx[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"})}),f]})]}),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(_n,{type:"source",position:h,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 Yl={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"}},Gl={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done",archived:"done"};function Ox({data:e}){const{t}=He(["work","common"]),{req:n,selected:s,direction:o="TB",isExpandedRoot:a,onCollapse:i}=e,l=Yl[n.status]??Yl.pending,c=o==="LR"?we.Left:we.Top,d=o==="LR"?we.Right:we.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(_n,{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(_n,{type:"source",position:d,className:"!bg-border-default !w-2 !h-2"}),a&&i&&r.jsx("button",{onClick:f=>{f.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 $x={task:Dx,requirement:Ox};function Px({nodeIds:e,rfRef:t}){const n=Lg();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 Bx=()=>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,qx=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 zx(){return p.useSyncExternalStore(qx,Bx,()=>!1)}const io=200,lo=80;function Xl(e,t,n="TB"){const s=a=>{const i=new Kl.graphlib.Graph;i.setDefaultEdgeLabel(()=>({})),i.setGraph({rankdir:a,nodesep:40,ranksep:60});for(const l of e)i.setNode(l.id,{width:io,height:lo});for(const l of t)i.setEdge(l.source,l.target);return Kl.layout(i),e.map(l=>{const c=i.node(l.id);return{...l,position:{x:(c?.x??0)-io/2,y:(c?.y??0)-lo/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 h of o)a=Math.min(a,h.position.x),i=Math.max(i,h.position.x+io),l=Math.min(l,h.position.y),c=Math.max(c,h.position.y+lo);const d=i-a,f=c-l,u=n==="TB"?"LR":"TB";if(d>f*3)return{nodes:s(u),direction:u}}return{nodes:o,direction:n}}function Fx(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 f of n.get(d)??[])o.has(f)||c.push(f)}}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 Zl(e,t){if(e.length===0)return{nodes:[],direction:"TB"};const n=Fx(e,t);if(n.length===1)return Xl(e,t);let s="TB";const o=n.map(h=>{const{nodes:m,direction:g}=Xl(h.nodes,h.edges);s=g;let b=1/0,k=-1/0,v=1/0,y=-1/0;for(const x of m)b=Math.min(b,x.position.x),k=Math.max(k,x.position.x+io),v=Math.min(v,x.position.y),y=Math.max(y,x.position.y+lo);for(const x of m)x.position.x-=b,x.position.y-=v;return{nodes:m,w:k-b,h:y-v}});o.sort((h,m)=>m.h-h.h);const a=60,i=o.reduce((h,m)=>h+(m.w+a)*(m.h+a),0),l=Math.sqrt(i)*1.1,c=[];let d=0,f=0,u=0;for(const h of o){d>0&&d+h.w>l&&(d=0,f+=u+a,u=0);for(const m of h.nodes)c.push({...m,position:{x:m.position.x+d,y:m.position.y+f}});d+=h.w+a,u=Math.max(u,h.h)}return{nodes:c,direction:s}}function Hx(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 ks=[{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(Yc),color:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"}}];new Set(ks.map(e=>e.id));const Xr=new Set(ks.filter(e=>e.id!=="done").map(e=>e.id)),ia=e=>e.status==="archived";function Vx(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 Wx({tasks:e,requirements:t=[],agents:n,showArchived:s,onShowArchivedChange:o,onTaskClick:a,onReqClick:i,onCollapseDAG:l,onDependencyChange:c,selectedTaskId:d,selectedReqId:f,hasDetailPanel:u,defaultExpandedNodeId:h,previewMode:m}){const{t:g}=He(["work","common"]),b=zx(),[k,v]=p.useState(null),[y,x]=p.useState(null),[w,C]=p.useState(()=>new Set(Xr)),[j,E]=p.useState(h??null),[S,R]=p.useState(s??!1),$=s??S,M=p.useCallback(J=>{const ne=typeof J=="function"?J($):J;R(ne),o?.(ne)},[$,o]);p.useEffect(()=>{s!==void 0&&R(s)},[s]),p.useEffect(()=>{h&&E(h)},[h]);const D=p.useMemo(()=>e.filter(J=>ia(J)).length,[e]),z=p.useMemo(()=>{const J=new Set;for(const ne of ks)if(w.has(ne.id))for(const ae of ne.statuses)J.add(ae);return J},[w]),I=p.useMemo(()=>{const J=new Set;for(const ne of e)for(const ae of ks)if(ae.statuses.has(ne.status)){J.add(ae.id);break}for(const ne of t){const ae=Gl[ne.status];ae&&J.add(ae)}return ks.filter(ne=>J.has(ne.id))},[e,t]),P=p.useCallback(J=>{C(ne=>{const ae=new Set(ne);return ae.has(J)?ae.delete(J):ae.add(J),ae})},[]),L=p.useCallback((J,ne="success")=>{v({msg:J,type:ne}),setTimeout(()=>v(null),2500)},[]),B=p.useMemo(()=>{const J=new Map;for(const ne of n)J.set(ne.id,ne.name);return J},[n]),_=p.useMemo(()=>{const J=new Map;for(const ne of e)J.set(ne.id,ne);return J},[e]),q=p.useMemo(()=>{const J=new Map;for(const ne of t)J.set(ne.id,ne);return J},[t]),H=p.useRef(!1),K=p.useCallback(()=>{H.current=!1,E(null),l?.()},[l]),O=b?"#94a3b8":"#6b7280",U=p.useCallback((J,ne,ae)=>({id:`${J}->${ne}`,source:J,target:ne,animated:ae==="blocked",markerEnd:{type:Ts.ArrowClosed,width:14,height:14,color:ae==="blocked"?"#ef4444":O},style:{stroke:ae==="blocked"?"#ef4444":O,strokeWidth:1.5,cursor:"pointer"}}),[O]),{initialNodes:A,initialEdges:T,topLevelIds:V}=p.useMemo(()=>{const J=(de,be)=>{const Ce=new Set,Xe=de.map(Ye=>(Ce.add(Ye.id),{id:Ye.id,type:"task",data:{task:Ye,agentName:Ye.assignedAgentId?B.get(Ye.assignedAgentId):void 0,selected:Ye.id===d},position:{x:0,y:0}}));for(const Ye of be){const ot=`req-${Ye.id}`;Ce.add(ot),Xe.push({id:ot,type:"requirement",data:{req:Ye,selected:Ye.id===f},position:{x:0,y:0}})}const Ct=[];for(const Ye of de)if(Ye.blockedBy)for(const ot of Ye.blockedBy)Ce.has(ot)&&Ct.push(U(ot,Ye.id,Ye.status));const At=new Set,Et=(Ye,ot)=>{const It=`${Ye}->${ot}`;At.has(It)||(At.add(It),Ct.push({id:It,source:Ye,target:ot,markerEnd:{type:Ts.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const Ye of be){const ot=`req-${Ye.id}`;for(const It of Ye.taskIds)Ce.has(It)&&Et(ot,It)}for(const Ye of de)if(Ye.requirementId){const ot=`req-${Ye.requirementId}`;Ce.has(ot)&&Et(ot,Ye.id)}return{nodes:Xe,edges:Ct}},ne=e.filter(de=>z.has(de.status)&&($||!ia(de))),ae=new Set;for(const de of ks)w.has(de.id)&&ae.add(de.id);const ke=t.filter(de=>{const be=Gl[de.status];return be&&ae.has(be)}),ge=new Set(ke.filter(de=>!Gc.has(de.status)).map(de=>de.id)),ve=new Set;for(const de of t)if(ge.has(de.id))for(const be of de.taskIds)ve.add(be);const Me=e.filter(de=>ve.has(de.id)&&($||!ia(de))),nt=[...new Map([...ne,...Me].map(de=>[de.id,de])).values()],{nodes:Pe,edges:ee}=J(nt,ke),Re=new Set;for(const de of ee)Re.add(de.target);const We=new Set(Pe.filter(de=>!Re.has(de.id)).map(de=>de.id)),ht=(()=>{if(!j)return null;const{nodes:de,edges:be}=J(e,t);return de.some(Ce=>Ce.id===j)?{allNodes:de,allEdges:be}:null})();if(!j||!ht){const de=Pe,{nodes:be,direction:Ce}=Zl(de,ee);return{initialNodes:be.map(Ct=>({...Ct,data:{...Ct.data,direction:Ce}})),initialEdges:ee,topLevelIds:We}}const{allNodes:Je,allEdges:qe}=ht,Le=Vx(j,_,q,e),Ke=Je.filter(de=>Le.has(de.id)).map(de=>de.id===j?{...de,data:{...de.data,isExpandedRoot:!0,onCollapse:K}}:de),kt=qe.filter(de=>Le.has(de.source)&&Le.has(de.target)),{nodes:X,direction:le}=Zl(Ke,kt);return{initialNodes:X.map(de=>({...de,data:{...de.data,direction:le}})),initialEdges:kt,topLevelIds:We}},[e,t,B,_,q,U,z,w,$,d,f,j,K]),[W,F,Z]=_g(A),[se,ue,ie]=Rg(T),pe=p.useRef(null),je=p.useRef({groupFilter:w,showArchived:$});p.useEffect(()=>{const J=je.current;(J.groupFilter!==w||J.showArchived!==$)&&(H.current=!1,E(null),je.current={groupFilter:w,showArchived:$})},[w,$]),p.useEffect(()=>{F(A),ue(T),H.current||requestAnimationFrame(()=>{pe.current?.fitView({padding:.2,duration:300})})},[A,T,F,ue]),p.useEffect(()=>{const J=setTimeout(()=>{pe.current?.fitView({padding:.2,duration:300})},50);return()=>clearTimeout(J)},[u]);const Se=p.useCallback(J=>{J&&(H.current=!0)},[]),Ne=p.useCallback((J,ne)=>{if(!j&&V.has(ne.id)&&(H.current=!1,E(ne.id)),ne.id.startsWith("req-")){const ae=q.get(ne.id.slice(4));ae&&i&&i(ae)}else{const ae=_.get(ne.id);ae&&a&&a(ae)}},[_,q,a,i,V,j]),Be=p.useCallback(async J=>{const{source:ne,target:ae}=J;if(!ne||!ae||ne===ae)return;const ke=_.get(ae);if(!ke)return;if(ke.blockedBy?.includes(ne)){L(g("work:dag.toast.dependencyExists"),"error");return}if(Hx(_,ne,ae)){L(g("work:dag.toast.cycleError"),"error");return}const ge=[...ke.blockedBy??[],ne];try{await te.tasks.update(ae,{blockedBy:ge}),L(g("work:dag.toast.dependencyAdded")),c?.()}catch(ve){L(g("work:dag.toast.failed",{message:ve instanceof Error?ve.message:String(ve)}),"error")}},[_,L,c,g]),$e=p.useCallback((J,ne)=>{x(ne)},[]),Ie=p.useCallback(async()=>{if(!y)return;const J=_.get(y.target);if(!J){x(null);return}const ne=(J.blockedBy??[]).filter(ae=>ae!==y.source);try{await te.tasks.update(y.target,{blockedBy:ne}),L(g("work:dag.toast.dependencyRemoved")),c?.()}catch(ae){L(g("work:dag.toast.failed",{message:ae instanceof Error?ae.message:String(ae)}),"error")}x(null)},[y,_,L,c,g]),Ve=p.useRef(null),[ct,Oe]=p.useState(null);if(p.useEffect(()=>{let J=document;const ne=()=>{const ge=Ve.current;if(!ge){Oe(null);return}let ve=ge.parentElement;for(;ve;){const qe=getComputedStyle(ve).overflowY;if((qe==="auto"||qe==="scroll")&&ve.clientHeight>0)break;ve=ve.parentElement}if(!document.documentElement.classList.contains("mobile-doc-scroll")&&!(ve!==null)){Oe(null);return}const Pe=ve?ve.clientHeight:window.innerHeight,ee=ve?ve.getBoundingClientRect().top:0,Re=ve?ve.scrollTop:window.scrollY,ht=ge.getBoundingClientRect().top-ee+Re,Je=Math.min(Pe,window.innerHeight)-ht-8;Oe(Math.max(320,Math.round(Je))),ve&&J!==ve&&(ae.disconnect(),ae.observe(ve),J=ve)},ae=new ResizeObserver(ne);ne(),ae.observe(document.documentElement),window.addEventListener("resize",ne);const ke=new MutationObserver(ne);return ke.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>{window.removeEventListener("resize",ne),ae.disconnect(),ke.disconnect()}},[]),p.useEffect(()=>{if(ct===null)return;const J=requestAnimationFrame(()=>{pe.current?.fitView({padding:.2})});return()=>cancelAnimationFrame(J)},[ct]),e.length===0)return r.jsx("div",{className:"doc-scroll-viewport flex-1 flex items-center justify-center",children:r.jsxs("div",{className:"flex flex-col items-center gap-3 max-w-sm text-center",children:[r.jsx("svg",{className:"w-10 h-10 text-fg-muted",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),r.jsx("p",{className:"text-sm font-medium text-fg-secondary",children:g("work:task.dagEmptyTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:g("work:task.dagEmptyDesc")})]})});const re=w.size===Xr.size&&[...Xr].every(J=>w.has(J))&&!$,fe=y?_.get(y.source):null,xe=y?_.get(y.target):null;return r.jsxs("div",{ref:Ve,className:"doc-scroll-viewport flex-1 min-h-0 relative",style:{height:ct??"100%"},children:[r.jsxs(Ag,{nodes:W,edges:se,onNodesChange:Z,onEdgesChange:ie,onNodeClick:Ne,onConnect:Be,onEdgeClick:$e,onMoveEnd:Se,onInit:J=>{pe.current=J},nodeTypes:$x,fitView:!0,minZoom:.08,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[m&&r.jsx(Px,{nodeIds:W.map(J=>J.id),rfRef:pe}),r.jsx(Bg,{color:b?"#cbd5e1":"#374151",gap:20,size:1}),r.jsx(Kg,{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(ox,{nodeColor:J=>{const ne=J.data?.task,ae=ne?.status;return ne?.taskType==="scheduled"?"#8b8fa3":ae==="completed"||ae==="accepted"?"#10b981":ae==="in_progress"?"#f59e0b":ae==="blocked"||ae==="failed"?"#ef4444":b?"#94a3b8":"#6b7280"},maskColor:b?"rgba(255,255,255,0.7)":"rgba(0,0,0,0.7)",className:"!bg-surface-secondary !border-border-default"})]}),r.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 px-3 py-1.5 bg-surface-secondary/90 border border-border-default rounded-lg backdrop-blur-sm z-10 flex flex-col items-center gap-1",children:[r.jsxs("div",{className:"flex items-center gap-1 flex-wrap justify-center",children:[I.map(J=>{const ne=w.has(J.id);return r.jsx("button",{onClick:()=>P(J.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${ne?`${J.color.bg} ${J.color.border} ${J.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:g(`work:dag.filter.${J.id}`)},J.id)}),D>0&&r.jsx("button",{onClick:()=>M(J=>!J),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:D})}),!re&&r.jsx("button",{onClick:()=>{C(new Set(Xr)),M(!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:K,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}),y&&r.jsx("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-50 backdrop-blur-[2px]",onClick:()=>x(null),children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:J=>J.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:xe?.title??y.target.slice(-8),source:fe?.title??y.source.slice(-8)})}),r.jsxs("div",{className:"flex justify-end gap-2",children:[r.jsx("button",{onClick:()=>x(null),className:"px-3 py-1.5 text-xs text-fg-secondary hover:text-fg-primary bg-surface-elevated rounded-lg border border-border-default hover:border-gray-600 transition-colors",children:g("common:cancel")}),r.jsx("button",{onClick:Ie,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 Sa="grid grid-cols-[auto_1fr] gap-x-3 gap-y-3.5 items-start",uu="grid grid-cols-[auto_1fr] sm:grid-cols-[auto_1fr_auto_1fr] gap-x-5 gap-y-3 items-start",it="pt-2 text-sm text-fg-secondary whitespace-nowrap",gn="w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",la="shrink-0 whitespace-nowrap text-[11px] font-medium text-brand-500 hover:text-brand-400";function Kx(e){return/^(https?:\/\/|git@|ssh:\/\/|git:\/\/)/i.test(e)}function Ql({orgId:e,onCreated:t,onClose:n}){const{t:s}=He(["work","common"]);Rf(!0);const[o,a]=p.useState(""),[i,l]=p.useState(""),[c,d]=p.useState(""),[f,u]=p.useState("main"),[h,m]=p.useState(!1),[g,b]=p.useState(""),[k,v]=p.useState(!1),y=pr();p.useEffect(()=>{const C=j=>{j.key==="Escape"&&n()};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[n]);const x=p.useCallback(async C=>{if(C?.preventDefault(),v(!0),!(!o.trim()||h)){m(!0),b("");try{const j=c.trim(),E=j?[{...Kx(j)?{url:j}:{localPath:j},defaultBranch:f.trim()||"main",role:"primary"}]:[],S=await te.projects.create({name:o.trim(),description:i.trim()||void 0,repositories:E.length>0?E:void 0,orgId:e??"default"});t(S.project)}catch(j){b(j instanceof Error?j.message:s("project.failedToCreate"))}m(!1)}},[o,i,c,f,e,h,t,s]),w=k&&!o.trim();return Df.createPortal(r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-3",onClick:n,children:r.jsxs("form",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 shadow-2xl max-h-[90dvh] overflow-y-auto space-y-4 ${y?"w-full":"w-[26rem]"}`,onClick:C=>C.stopPropagation(),onSubmit:x,children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("project.newProject")}),r.jsxs("div",{className:Sa,children:[r.jsx("label",{className:it,children:s("project.projectName")}),r.jsxs("div",{children:[r.jsx("input",{value:o,onChange:C=>{a(C.target.value),b("")},onBlur:()=>v(!0),placeholder:s("project.projectNamePlaceholder"),className:`${gn} ${w?"!border-red-500":""}`,autoFocus:!y}),w&&r.jsx("p",{className:"text-[11px] text-red-400 mt-1",children:s("project.projectNameRequired")})]}),r.jsx("label",{className:it,children:s("project.description")}),r.jsx("textarea",{value:i,onChange:C=>l(C.target.value),placeholder:s("project.descriptionPlaceholder"),className:`${gn} resize-none`,rows:2}),r.jsx("label",{className:it,children:s("project.repositoryUrl")}),r.jsx("input",{value:c,onChange:C=>d(C.target.value),placeholder:s("project.repositoryPlaceholder"),className:`${gn} placeholder:text-[11px]`}),c.trim()&&r.jsxs(r.Fragment,{children:[r.jsx("label",{className:it,children:s("project.branch")}),r.jsx("input",{value:f,onChange:C=>u(C.target.value),placeholder:s("project.branchPlaceholder"),className:gn})]})]}),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()||h,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-on-brand",children:s(h?"common:creating":"project.createProject")})]})]})}),document.body)}function Ux({projects:e,selectedProjectId:t,allSelected:n,taskCounts:s,totalTaskCount:o,onSelectAll:a,onSelectProject:i,onEditProject:l,onCreateProject:c,onCollapse:d,width:f,onResizeStart:u,hidden:h,focused:m,onActivate:g}){const{t:b}=He(["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:h?{display:"none"}:f!=null?{width:f}:void 0,children:[r.jsxs("div",{"data-electron-drag":!0,className:"px-3 h-14 flex items-center shrink-0 gap-2",children:[d&&r.jsx("button",{type:"button","data-no-drag":!0,onClick:d,className:"w-8 h-8 flex items-center justify-center rounded-lg transition-colors shrink-0 bg-brand-500/15 text-brand-500 hover:bg-brand-500/25",title:b("common:shortcuts.toggleLeft"),children:r.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),r.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),r.jsx("h2",{className:"text-sm font-semibold text-fg-primary truncate",children:b("work:task.projects",{defaultValue:"Projects"})}),r.jsx("button",{type:"button","data-no-drag":!0,onClick:c,className:"ml-auto w-7 h-7 flex items-center justify-center rounded-md text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated transition-colors",title:b("work:project.newProject"),children:r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),r.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),r.jsx("div",{className:"flex-1 overflow-y-auto px-2 pb-3 space-y-0.5",children:e.length===0?r.jsxs("div",{className:"px-2 py-8 text-center space-y-3",children:[r.jsx("div",{className:"w-10 h-10 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:r.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),r.jsx("p",{className:"text-[11px] text-fg-tertiary leading-relaxed px-1",children:b("work:task.emptyNoProjectsHint")}),r.jsx("button",{type:"button",onClick:c,className:"inline-flex items-center gap-1 px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-on-brand rounded-lg font-medium transition-colors",children:b("work:project.newProject")})]}):r.jsxs(r.Fragment,{children:[a&&r.jsxs("button",{type:"button","data-project-id":"__all__",onClick:a,className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-left transition-colors ${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-on-brand":"bg-surface-overlay text-fg-secondary"}`,children:r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),r.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),r.jsx("rect",{x:"14",y:"14",width:"7",height:"7"}),r.jsx("rect",{x:"3",y:"14",width:"7",height:"7"})]})}),r.jsx("span",{className:"min-w-0 flex-1",children:r.jsx("span",{className:"block text-[12px] font-medium truncate",children:b("work:task.all")})}),(o??0)>0&&r.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:o})]}),[...e].sort((v,y)=>{const x=v.status==="archived"?1:0,w=y.status==="archived"?1:0;return x-w}).map(v=>{const y=!k&&v.id===t,x=s[v.id]??0,w=v.status==="paused",C=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 ${y?m?"bg-brand-500/20 ring-1 ring-brand-500/40 text-brand-500":"bg-brand-500/15 text-brand-600":"text-fg-secondary hover:bg-surface-elevated hover:text-fg-primary"}`,children:[r.jsx("span",{className:`w-7 h-7 rounded-md flex items-center justify-center text-[11px] font-bold shrink-0 ${y?"bg-brand-600 text-on-brand":"bg-surface-overlay text-fg-secondary"}`,children: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}),C&&r.jsx("span",{className:"block text-[10px] text-fg-tertiary italic",children:b("work:project.statusArchived")}),w&&r.jsx("span",{className:"block text-[10px] text-amber-500/80",children:b("work:project.statusPaused")})]}),l&&r.jsx("button",{type:"button","data-no-drag":!0,title:b("work:project.editProject"),"aria-label":b("work:project.editProject"),onClick:j=>{j.stopPropagation(),l(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)})]})})]}),!h&&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 Yx({project:e,onUpdateProject:t}){const{t:n}=He(["work","common"]),s=e.knowledgeBasePaths??[],[o,a]=p.useState(""),[i,l]=p.useState(!1),[c,d]=p.useState(!0),[f,u]=p.useState([]),[h,m]=p.useState(null),[g,b]=p.useState(null),k=p.useCallback(async()=>{if(e.id){d(!0);try{const{results:S}=await te.deliverables.search({projectId:e.id,source:"knowledge",limit:200});u(S)}catch(S){m({type:"error",text:`${n("work:project.kbLoadFailed")}: ${String(S)}`})}finally{d(!1)}}},[e.id,n]);p.useEffect(()=>{k()},[k]);const v=async()=>{const S=o.trim();if(!(!S||i))try{const R=[...new Set([...s,S])];await t({knowledgeBasePaths:R}),a(""),await C()}catch(R){m({type:"error",text:`${n("work:project.kbPathsSaveFailed")}: ${String(R)}`})}},y=async()=>{const S=g;if(!S||i)return;b(null);const R=s.filter($=>$!==S);await t({knowledgeBasePaths:R}),await C(R)},x=typeof window<"u"&&!!window.markusDesktop?.selectDirectory,w=async()=>{try{const S=await window.markusDesktop?.selectDirectory?.(n("work:project.kbBrowseTitle"));S&&a(S)}catch(S){m({type:"error",text:`${n("work:project.kbBrowseFailed")}: ${String(S)}`})}},C=async S=>{if(!i){l(!0),m(null);try{const R=await te.projects.syncKnowledge(e.id,S);m({type:R.errors.length>0?"error":"success",text:n("work:project.kbSyncResult",{scanned:R.scanned,registered:R.registered,updated:R.updated,outdated:R.outdated,errors:R.errors.length})}),await k()}catch(R){m({type:"error",text:`${n("work:project.kbSyncFailed")}: ${String(R)}`})}finally{l(!1)}}},j=async()=>{await C(s.length?s:void 0)},E=S=>{en.navigate(tt.DELIVERABLES,{projectId:e.id,source:"knowledge",...S?{openDeliverable:S}:{}})};return r.jsxs("div",{className:"bg-surface-elevated rounded-xl p-4",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2 mb-3",children:[r.jsx("h4",{className:"text-xs font-semibold text-fg-secondary",children:n("work:project.kbHeading")}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("button",{type:"button",onClick:()=>E(),className:"text-[10px] px-2 py-1 rounded-md text-fg-tertiary hover:text-brand-500 hover:bg-surface-overlay transition-colors",children:n("work:project.kbOpenInDeliverables")}),r.jsx("button",{type:"button",onClick:j,disabled:i||s.length===0,className:"text-[10px] px-2 py-1 rounded-md bg-brand-600 text-on-brand hover:bg-brand-500 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:n(i?"work:project.kbSyncing":"work:project.kbSync")})]})]}),g&&r.jsxs("div",{className:"mb-3 px-3 py-2 bg-surface-overlay border border-border-default rounded-lg",children:[r.jsx("p",{className:"text-xs text-fg-secondary mb-2",children:n("work:project.kbRemoveConfirm",{path:g})}),r.jsxs("div",{className:"flex gap-2 justify-end",children:[r.jsx("button",{type:"button",onClick:()=>b(null),className:"px-2.5 py-1 text-xs rounded-md bg-surface-secondary text-fg-secondary hover:text-fg-primary border border-border-default transition-colors",children:n("common:cancel")}),r.jsx("button",{type:"button",onClick:()=>{y()},disabled:i,className:"px-2.5 py-1 text-xs rounded-md bg-red-600 text-white hover:bg-red-500 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:n(i?"work:project.kbSyncing":"common:confirm")})]})]}),r.jsxs("div",{className:"space-y-1.5 mb-3",children:[s.length===0&&r.jsx("p",{className:"text-[11px] text-fg-tertiary",children:n("work:project.kbNoPaths")}),s.map((S,R)=>r.jsxs("div",{className:"flex items-center gap-2 group",children:[r.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary shrink-0",children:r.jsx("path",{d:"M3 7v10a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-6l-2-2H5a2 2 0 0 0-2 2z"})}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 min-w-0 truncate font-mono",title:S,children:S}),r.jsx("button",{type:"button",onClick:()=>b(S),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"})]})})]},`${S}-${R}`)),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{value:o,onChange:S=>a(S.target.value),onKeyDown:S=>{S.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")})]})]}),h&&r.jsx("div",{className:`mb-2 px-2.5 py-1.5 text-[11px] rounded-md ${h.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:h.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"),f.length>0&&r.jsxs("span",{className:"ml-1 text-fg-muted",children:["(",f.length,")"]})]}),c?r.jsx(Zf,{variant:"text",label:n("work:project.kbLoadingDocs"),className:"px-0"}):f.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:f.map(S=>r.jsxs("button",{type:"button",onClick:()=>E(S.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:S.reference??S.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:S.format??"file"}),r.jsx("span",{className:"text-xs text-fg-secondary truncate flex-1 min-w-0 group-hover:text-brand-500",children:S.title}),r.jsx("span",{className:"text-[10px] text-fg-muted shrink-0",children:"→"})]},S.id))})]})]})}const Gx=new Set(["rejected","cancelled","archived"]);function Xx(e){return Gx.has(e)}function Zx(e,t){let s=t.showClosed||t.includeClosed===!0?e:e.filter(o=>!Xx(o.status));return t.statusFilter&&(s=s.filter(o=>o.status===t.statusFilter)),t.viewMode==="project"&&t.selectedProjectId&&(s=s.filter(o=>o.projectId===t.selectedProjectId)),t.projectFilter&&t.projectFilter.size>0&&(s=s.filter(o=>o.projectId&&t.projectFilter.has(o.projectId))),t.agentFilter&&t.agentFilter.size>0&&(s=s.filter(o=>o.assignedAgentId&&t.agentFilter.has(o.assignedAgentId))),t.myTasksOnly&&t.currentUserId&&(s=s.filter(o=>o.createdBy===t.currentUserId)),s}function Ga(e,t){if(!e||e.length===0)return[];const n=new Map(t.map(a=>[a.id,a])),s=[],o=new Set;for(const a of e){if(o.has(a))continue;o.add(a);const i=n.get(a);i&&s.push({id:i.id,name:i.name,avatarUrl:i.avatarUrl})}return s}const Xa=Symbol.for("yaml.alias"),Ca=Symbol.for("yaml.document"),Ln=Symbol.for("yaml.map"),fu=Symbol.for("yaml.pair"),ln=Symbol.for("yaml.scalar"),$s=Symbol.for("yaml.seq"),Yt=Symbol.for("yaml.node.type"),Ps=e=>!!e&&typeof e=="object"&&e[Yt]===Xa,wr=e=>!!e&&typeof e=="object"&&e[Yt]===Ca,kr=e=>!!e&&typeof e=="object"&&e[Yt]===Ln,wt=e=>!!e&&typeof e=="object"&&e[Yt]===fu,rt=e=>!!e&&typeof e=="object"&&e[Yt]===ln,vr=e=>!!e&&typeof e=="object"&&e[Yt]===$s;function bt(e){if(e&&typeof e=="object")switch(e[Yt]){case Ln:case $s:return!0}return!1}function yt(e){if(e&&typeof e=="object")switch(e[Yt]){case Xa:case Ln:case ln:case $s:return!0}return!1}const hu=e=>(rt(e)||bt(e))&&!!e.anchor,Yn=Symbol("break visit"),Qx=Symbol("skip children"),sr=Symbol("remove node");function Bs(e,t){const n=Jx(t);wr(e)?vs(null,e.contents,n,Object.freeze([e]))===sr&&(e.contents=null):vs(null,e,n,Object.freeze([]))}Bs.BREAK=Yn;Bs.SKIP=Qx;Bs.REMOVE=sr;function vs(e,t,n,s){const o=e0(e,t,n,s);if(yt(o)||wt(o))return t0(e,s,o),vs(e,o,n,s);if(typeof o!="symbol"){if(bt(t)){s=Object.freeze(s.concat(t));for(let a=0;a<t.items.length;++a){const i=vs(a,t.items[a],n,s);if(typeof i=="number")a=i-1;else{if(i===Yn)return Yn;i===sr&&(t.items.splice(a,1),a-=1)}}}else if(wt(t)){s=Object.freeze(s.concat(t));const a=vs("key",t.key,n,s);if(a===Yn)return Yn;a===sr&&(t.key=null);const i=vs("value",t.value,n,s);if(i===Yn)return Yn;i===sr&&(t.value=null)}}return o}function Jx(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 e0(e,t,n,s){if(typeof n=="function")return n(e,t,s);if(kr(t))return n.Map?.(e,t,s);if(vr(t))return n.Seq?.(e,t,s);if(wt(t))return n.Pair?.(e,t,s);if(rt(t))return n.Scalar?.(e,t,s);if(Ps(t))return n.Alias?.(e,t,s)}function t0(e,t,n){const s=t[t.length-1];if(bt(s))s.items[e]=n;else if(wt(s))e==="key"?s.key=n:s.value=n;else if(wr(s))s.contents=n;else{const o=Ps(s)?"alias":"scalar";throw new Error(`Cannot replace node with ${o} parent`)}}const n0={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"},s0=e=>e.replace(/[!,[\]{}]/g,t=>n0[t]);class Rt{constructor(t,n){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},Rt.defaultYaml,t),this.tags=Object.assign({},Rt.defaultTags,n)}clone(){const t=new Rt(this.yaml,this.tags);return t.docStart=this.docStart,t}atDocument(){const t=new Rt(this.yaml,this.tags);switch(this.yaml.version){case"1.1":this.atNextDocument=!0;break;case"1.2":this.atNextDocument=!1,this.yaml={explicit:Rt.defaultYaml.explicit,version:"1.2"},this.tags=Object.assign({},Rt.defaultTags);break}return t}add(t,n){this.atNextDocument&&(this.yaml={explicit:Rt.defaultYaml.explicit,version:"1.1"},this.tags=Object.assign({},Rt.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+s0(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&&yt(t.contents)){const a={};Bs(t.contents,(i,l)=>{yt(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
|
-
`)}}Rt.defaultYaml={explicit:!1,version:"1.2"};Rt.defaultTags={"!!":"tag:yaml.org,2002:"};function mu(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 pu(e){const t=new Set;return Bs(e,{Value(n,s){s.anchor&&t.add(s.anchor)}}),t}function gu(e,t){for(let n=1;;++n){const s=`${e}${n}`;if(!t.has(s))return s}}function r0(e,t){const n=[],s=new Map;let o=null;return{onAnchor:a=>{n.push(a),o??(o=pu(e));const i=gu(t,o);return o.add(i),i},setAnchors:()=>{for(const a of n){const i=s.get(a);if(typeof i=="object"&&i.anchor&&(rt(i.node)||bt(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 js(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=js(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=js(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=js(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=js(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||!hu(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 Za{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(!wr(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"?js(a,{"":l},"",l):l}}class Qa extends Za{constructor(t){super(Xa),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=[],Bs(t,{Node:(a,i)=>{(Ps(i)||hu(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=co(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(mu(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 co(e,t,n){if(Ps(t)){const s=t.resolve(e),o=n&&s&&n.get(s);return o?o.count*o.aliasCount:0}else if(bt(t)){let s=0;for(const o of t.items){const a=co(e,o,n);a>s&&(s=a)}return s}else if(wt(t)){const s=co(e,t.key,n),o=co(e,t.value,n);return Math.max(s,o)}return 1}const xu=e=>!e||typeof e!="function"&&typeof e!="object";class De extends Za{constructor(t){super(ln),this.value=t}toJSON(t,n){return n?.keep?this.value:Ut(this.value,t,n)}toString(){return String(this.value)}}De.BLOCK_FOLDED="BLOCK_FOLDED";De.BLOCK_LITERAL="BLOCK_LITERAL";De.PLAIN="PLAIN";De.QUOTE_DOUBLE="QUOTE_DOUBLE";De.QUOTE_SINGLE="QUOTE_SINGLE";const o0="tag:yaml.org,2002:";function a0(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 hr(e,t,n){if(wr(e)&&(e=e.contents),yt(e))return e;if(wt(e)){const u=n.schema[Ln].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 Qa(c.anchor);c={anchor:null,node:null},l.set(e,c)}t?.startsWith("!!")&&(t=o0+t.slice(2));let d=a0(e,t,i.tags);if(!d){if(e&&typeof e.toJSON=="function"&&(e=e.toJSON()),!e||typeof e!="object"){const u=new De(e);return c&&(c.node=u),u}d=e instanceof Map?i[Ln]:Symbol.iterator in Object(e)?i[$s]:i[Ln]}a&&(a(d),delete n.onTagObj);const f=d?.createNode?d.createNode(n.schema,e,n):typeof d?.nodeClass?.from=="function"?d.nodeClass.from(n.schema,e,n):new De(e);return t?f.tag=t:d.default||(f.tag=d.tag),c&&(c.node=f),f}function bo(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 hr(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 er=e=>e==null||typeof e=="object"&&!!e[Symbol.iterator]().next().done;class bu extends Za{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=>yt(s)||wt(s)?s.clone(t):s),this.range&&(n.range=this.range.slice()),n}addIn(t,n){if(er(t))this.add(n);else{const[s,...o]=t,a=this.get(s,!0);if(bt(a))a.addIn(o,n);else if(a===void 0&&this.schema)this.set(s,bo(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(bt(o))return o.deleteIn(s);throw new Error(`Expected YAML collection at ${n}. Remaining path: ${s}`)}getIn(t,n){const[s,...o]=t,a=this.get(s,!0);return o.length===0?!n&&rt(a)?a.value:a:bt(a)?a.getIn(o,n):void 0}hasAllNullValues(t){return this.items.every(n=>{if(!wt(n))return!1;const s=n.value;return s==null||t&&rt(s)&&s.value==null&&!s.commentBefore&&!s.comment&&!s.tag})}hasIn(t){const[n,...s]=t;if(s.length===0)return this.has(n);const o=this.get(n,!0);return bt(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(bt(a))a.setIn(o,n);else if(a===void 0&&this.schema)this.set(s,bo(this.schema,o,n));else throw new Error(`Expected YAML collection at ${s}. Remaining path: ${o}`)}}}const i0=e=>e.replace(/^(?!$)(?: $)?/gm,"#");function xn(e,t){return/^\n+$/.test(e)?e.substring(1):t?e.replace(/^(?! *$)/gm,t):e}const Xn=(e,t,n)=>e.endsWith(`
|
|
9
|
-
`)?xn(n,t):n.includes(`
|
|
10
|
-
`)?`
|
|
11
|
-
`+xn(n,t):(e.endsWith(" ")?"":" ")+n,yu="flow",Ea="block",uo="quoted";function Lo(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=[],f={};let u=o-t.length;typeof s=="number"&&(s>o-Math.max(2,a)?d.push(0):u=o-s);let h,m,g=!1,b=-1,k=-1,v=-1;n===Ea&&(b=Jl(e,b,t.length),b!==-1&&(u=b+c));for(let x;x=e[b+=1];){if(n===uo&&x==="\\"){switch(k=b,e[b+1]){case"x":b+=3;break;case"u":b+=5;break;case"U":b+=9;break;default:b+=1}v=b}if(x===`
|
|
12
|
-
`)n===Ea&&(b=Jl(e,b,t.length)),u=b+t.length+c,h=void 0;else{if(x===" "&&m&&m!==" "&&m!==`
|
|
13
|
-
`&&m!==" "){const w=e[b+1];w&&w!==" "&&w!==`
|
|
14
|
-
`&&w!==" "&&(h=b)}if(b>=u)if(h)d.push(h),u=h+c,h=void 0;else if(n===uo){for(;m===" "||m===" ";)m=x,x=e[b+=1],g=!0;const w=b>v+1?b-2:k-1;if(f[w])return e;d.push(w),f[w]=!0,u=w+c,h=void 0}else g=!0}m=x}if(g&&l&&l(),d.length===0)return e;i&&i();let y=e.slice(0,d[0]);for(let x=0;x<d.length;++x){const w=d[x],C=d[x+1]||e.length;w===0?y=`
|
|
15
|
-
${t}${e.slice(0,C)}`:(n===uo&&f[w]&&(y+=`${e[w]}\\`),y+=`
|
|
16
|
-
${t}${e.slice(w+1,C)}`)}return y}function Jl(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 _o=(e,t)=>({indentAtStart:t?e.indent.length:e.indentAtStart,lineWidth:e.options.lineWidth,minContentWidth:e.options.minContentWidth}),Ro=e=>/^(%|---|\.\.\.)/m.test(e);function l0(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 rr(e,t){const n=JSON.stringify(e);if(t.options.doubleQuotedAsJSON)return n;const{implicitKey:s}=t,o=t.options.doubleQuotedMinMultiLineLength,a=t.indent||(Ro(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 f=n.substr(c+2,4);switch(f){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:f.substr(0,2)==="00"?i+="\\x"+f.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:Lo(i,a,uo,_o(t,!1))}function Ia(e,t){if(t.options.singleQuote===!1||t.implicitKey&&e.includes(`
|
|
22
|
-
`)||/[ \t]\n|\n[ \t]/.test(e))return rr(e,t);const n=t.indent||(Ro(e)?" ":""),s="'"+e.replace(/'/g,"''").replace(/\n+/g,`$&
|
|
23
|
-
${n}`)+"'";return t.implicitKey?s:Lo(s,n,yu,_o(t,!1))}function Ns(e,t){const{singleQuote:n}=t.options;let s;if(n===!1)s=rr;else{const o=e.includes('"'),a=e.includes("'");o&&!a?s=Ia:a&&!o?s=rr:s=n?Ia:rr}return s(e,t)}let Ta;try{Ta=new RegExp(`(^|(?<!
|
|
24
|
-
))
|
|
25
|
-
+(?!
|
|
26
|
-
|$)`,"g")}catch{Ta=/\n+(?!\n|$)/g}function fo({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 Ns(n,s);const d=s.indent||(s.forceBlockIndent||Ro(n)?" ":""),f=i==="literal"?!0:i==="folded"||t===De.BLOCK_FOLDED?!1:t===De.BLOCK_LITERAL?!0:!l0(n,c,d.length);if(!n)return f?`|
|
|
27
|
-
`:`>
|
|
28
|
-
`;let u,h;for(h=n.length;h>0;--h){const C=n[h-1];if(C!==`
|
|
29
|
-
`&&C!==" "&&C!==" ")break}let m=n.substring(h);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(Ta,`$&${d}`));let b=!1,k,v=-1;for(k=0;k<n.length;++k){const C=n[k];if(C===" ")b=!0;else if(C===`
|
|
32
|
-
`)v=k;else break}let y=n.substring(0,v<k?v+1:k);y&&(n=n.substring(y.length),y=y.replace(/\n+/g,`$&${d}`));let w=(b?d?"2":"1":"")+u;if(e&&(w+=" "+l(e.replace(/ ?[\r\n]+/g," ")),o&&o()),!f){const C=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=_o(s,!0);i!=="folded"&&t!==De.BLOCK_FOLDED&&(E.onOverflow=()=>{j=!0});const S=Lo(`${y}${C}${m}`,d,Ea,E);if(!j)return`>${w}
|
|
34
|
-
${d}${S}`}return n=n.replace(/\n+/g,`$&${d}`),`|${w}
|
|
35
|
-
${d}${y}${n}${m}`}function c0(e,t,n,s){const{type:o,value:a}=e,{actualString:i,implicitKey:l,indent:c,indentStep:d,inFlow:f}=t;if(l&&a.includes(`
|
|
36
|
-
`)||f&&/[[\]{},]/.test(a))return Ns(a,t);if(/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(a))return l||f||!a.includes(`
|
|
37
|
-
`)?Ns(a,t):fo(e,t,n,s);if(!l&&!f&&o!==De.PLAIN&&a.includes(`
|
|
38
|
-
`))return fo(e,t,n,s);if(Ro(a)){if(c==="")return t.forceBlockIndent=!0,fo(e,t,n,s);if(l&&c===d)return Ns(a,t)}const u=a.replace(/\n+/g,`$&
|
|
39
|
-
${c}`);if(i){const h=b=>b.default&&b.tag!=="tag:yaml.org,2002:str"&&b.test?.test(u),{compat:m,tags:g}=t.doc.schema;if(g.some(h)||m?.some(h))return Ns(a,t)}return l?u:Lo(u,c,yu,_o(t,!1))}function Ja(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!==De.QUOTE_DOUBLE&&/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(i.value)&&(l=De.QUOTE_DOUBLE);const c=f=>{switch(f){case De.BLOCK_FOLDED:case De.BLOCK_LITERAL:return o||a?Ns(i.value,t):fo(i,t,n,s);case De.QUOTE_DOUBLE:return rr(i.value,t);case De.QUOTE_SINGLE:return Ia(i.value,t);case De.PLAIN:return c0(i,t,n,s);default:return null}};let d=c(l);if(d===null){const{defaultKeyType:f,defaultStringType:u}=t.options,h=o&&f||u;if(d=c(h),d===null)throw new Error(`Unsupported default string type ${h}`)}return d}function wu(e,t){const n=Object.assign({blockQuote:!0,commentString:i0,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 d0(e,t){if(t.tag){const o=e.filter(a=>a.tag===t.tag);if(o.length>0)return o.find(a=>a.format===t.format)??o[0]}let n,s;if(rt(t)){s=t.value;let o=e.filter(a=>a.identify?.(s));if(o.length>1){const a=o.filter(i=>i.test);a.length>0&&(o=a)}n=o.find(a=>a.format===t.format)??o.find(a=>!a.format)}else s=t,n=e.find(o=>o.nodeClass&&s instanceof o.nodeClass);if(!n){const o=s?.constructor?.name??(s===null?"null":typeof s);throw new Error(`Tag not resolved for ${o} value`)}return n}function u0(e,t,{anchors:n,doc:s}){if(!s.directives)return"";const o=[],a=(rt(e)||bt(e))&&e.anchor;a&&mu(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 Rs(e,t,n,s){if(wt(e))return e.toString(t,n,s);if(Ps(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=yt(e)?e:t.doc.createNode(e,{onTagObj:c=>o=c});o??(o=d0(t.doc.schema.tags,a));const i=u0(a,o,t);i.length>0&&(t.indentAtStart=(t.indentAtStart??0)+i.length+1);const l=typeof o.stringify=="function"?o.stringify(a,t,n,s):rt(a)?Ja(a,t,n,s):a.toString(t,n,s);return i?rt(a)||l[0]==="{"||l[0]==="["?`${i} ${l}`:`${i}
|
|
40
|
-
${t.indent}${l}`:l}function f0({key:e,value:t},n,s,o){const{allNullValues:a,doc:i,indent:l,indentStep:c,options:{commentString:d,indentSeq:f,simpleKeys:u}}=n;let h=yt(e)&&e.comment||null;if(u){if(h)throw new Error("With simple keys, key nodes cannot have comments");if(bt(e)||!yt(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||h&&t==null&&!n.inFlow||bt(e)||(rt(e)?e.type===De.BLOCK_FOLDED||e.type===De.BLOCK_LITERAL:typeof e=="object"));n=Object.assign({},n,{allNullValues:!1,implicitKey:!m&&(u||!a),indent:l+c});let g=!1,b=!1,k=Rs(e,n,()=>g=!0,()=>b=!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}`,h&&!g?k+=Xn(k,n.indent,d(h)):b&&o&&o(),k;g&&(h=null),m?(h&&(k+=Xn(k,n.indent,d(h))),k=`? ${k}
|
|
41
|
-
${l}:`):(k=`${k}:`,h&&(k+=Xn(k,n.indent,d(h))));let v,y,x;yt(t)?(v=!!t.spaceBefore,y=t.commentBefore,x=t.comment):(v=!1,y=null,x=null,t&&typeof t=="object"&&(t=i.createNode(t))),n.implicitKey=!1,!m&&!h&&rt(t)&&(n.indentAtStart=k.length+1),b=!1,!f&&c.length>=2&&!n.inFlow&&!m&&vr(t)&&!t.flow&&!t.tag&&!t.anchor&&(n.indent=n.indent.substring(2));let w=!1;const C=Rs(t,n,()=>w=!0,()=>b=!0);let j=" ";if(h||v||y){if(j=v?`
|
|
42
|
-
`:"",y){const E=d(y);j+=`
|
|
43
|
-
${xn(E,n.indent)}`}C===""&&!n.inFlow?j===`
|
|
44
|
-
`&&x&&(j=`
|
|
45
|
-
|
|
46
|
-
`):j+=`
|
|
47
|
-
${n.indent}`}else if(!m&&bt(t)){const E=C[0],S=C.indexOf(`
|
|
48
|
-
`),R=S!==-1,$=n.inFlow??t.flow??t.items.length===0;if(R||!$){let M=!1;if(R&&(E==="&"||E==="!")){let D=C.indexOf(" ");E==="&"&&D!==-1&&D<S&&C[D+1]==="!"&&(D=C.indexOf(" ",D+1)),(D===-1||S<D)&&(M=!0)}M||(j=`
|
|
49
|
-
${n.indent}`)}}else(C===""||C[0]===`
|
|
50
|
-
`)&&(j="");return k+=j+C,n.inFlow?w&&s&&s():x&&!w?k+=Xn(k,n.indent,d(x)):b&&o&&o(),k}function ku(e,t){(e==="debug"||e==="warn")&&console.warn(t)}const Zr="<<",bn={identify:e=>e===Zr||typeof e=="symbol"&&e.description===Zr,default:"key",tag:"tag:yaml.org,2002:merge",test:/^<<$/,resolve:()=>Object.assign(new De(Symbol(Zr)),{addToJSMap:vu}),stringify:()=>Zr},h0=(e,t)=>(bn.identify(t)||rt(t)&&(!t.type||t.type===De.PLAIN)&&bn.identify(t.value))&&e?.doc.schema.tags.some(n=>n.tag===bn.tag&&n.default);function vu(e,t,n){const s=ju(e,n);if(vr(s))for(const o of s.items)ca(e,t,o);else if(Array.isArray(s))for(const o of s)ca(e,t,o);else ca(e,t,s)}function ca(e,t,n){const s=ju(e,n);if(!kr(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 ju(e,t){return e&&Ps(t)?t.resolve(e.doc,e):t}function Nu(e,t,{key:n,value:s}){if(yt(n)&&n.addToJSMap)n.addToJSMap(e,t,s);else if(h0(e,n))vu(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=m0(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 m0(e,t,n){if(t===null)return"";if(typeof t!="object")return String(t);if(yt(e)&&n?.doc){const s=wu(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)+'..."'),ku(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 ei(e,t,n){const s=hr(e,void 0,n),o=hr(t,void 0,n);return new Dt(s,o)}class Dt{constructor(t,n=null){Object.defineProperty(this,Yt,{value:fu}),this.key=t,this.value=n}clone(t){let{key:n,value:s}=this;return yt(n)&&(n=n.clone(t)),yt(s)&&(s=s.clone(t)),new Dt(n,s)}toJSON(t,n){const s=n?.mapAsMap?new Map:{};return Nu(n,s,this)}toString(t,n,s){return t?.doc?f0(this,t,n,s):JSON.stringify(this)}}function Su(e,t,n){return(t.inFlow??e.flow?g0:p0)(e,t,n)}function p0({comment:e,items:t},n,{blockItemPrefix:s,flowChars:o,itemIndent:a,onChompKeep:i,onComment:l}){const{indent:c,options:{commentString:d}}=n,f=Object.assign({},n,{indent:a,type:null});let u=!1;const h=[];for(let g=0;g<t.length;++g){const b=t[g];let k=null;if(yt(b))!u&&b.spaceBefore&&h.push(""),yo(n,h,b.commentBefore,u),b.comment&&(k=b.comment);else if(wt(b)){const y=yt(b.key)?b.key:null;y&&(!u&&y.spaceBefore&&h.push(""),yo(n,h,y.commentBefore,u))}u=!1;let v=Rs(b,f,()=>k=null,()=>u=!0);k&&(v+=Xn(v,a,d(k))),u&&k&&(u=!1),h.push(s+v)}let m;if(h.length===0)m=o.start+o.end;else{m=h[0];for(let g=1;g<h.length;++g){const b=h[g];m+=b?`
|
|
51
|
-
${c}${b}`:`
|
|
52
|
-
`}}return e?(m+=`
|
|
53
|
-
`+xn(d(e),c),l&&l()):u&&i&&i(),m}function g0({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,f=0;const u=[];for(let g=0;g<e.length;++g){const b=e[g];let k=null;if(yt(b))b.spaceBefore&&u.push(""),yo(t,u,b.commentBefore,!1),b.comment&&(k=b.comment);else if(wt(b)){const y=yt(b.key)?b.key:null;y&&(y.spaceBefore&&u.push(""),yo(t,u,y.commentBefore,!1),y.comment&&(d=!0));const x=yt(b.value)?b.value:null;x?(x.comment&&(k=x.comment),x.commentBefore&&(d=!0)):b.value==null&&y?.comment&&(k=y.comment)}k&&(d=!0);let v=Rs(b,c,()=>k=null);d||(d=u.length>f||v.includes(`
|
|
54
|
-
`)),g<e.length-1?v+=",":t.options.trailingComma&&(t.options.lineWidth>0&&(d||(d=u.reduce((y,x)=>y+x.length+2,2)+(v.length+2)>t.options.lineWidth)),d&&(v+=",")),k&&(v+=Xn(v,s,l(k))),u.push(v),f=u.length}const{start:h,end:m}=n;if(u.length===0)return h+m;if(!d){const g=u.reduce((b,k)=>b+k.length+2,2);d=t.options.lineWidth>0&&g>t.options.lineWidth}if(d){let g=h;for(const b of u)g+=b?`
|
|
55
|
-
${a}${o}${b}`:`
|
|
56
|
-
`;return`${g}
|
|
57
|
-
${o}${m}`}else return`${h}${i}${u.join(" ")}${i}${m}`}function yo({indent:e,options:{commentString:t}},n,s,o){if(s&&o&&(s=s.replace(/^\n+/,"")),s){const a=xn(t(s),e);n.push(a.trimStart())}}function Zn(e,t){const n=rt(t)?t.value:t;for(const s of e)if(wt(s)&&(s.key===t||s.key===n||rt(s.key)&&s.key.value===n))return s}class Kt extends bu{static get tagName(){return"tag:yaml.org,2002:map"}constructor(t){super(Ln,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(ei(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;wt(t)?s=t:!t||typeof t!="object"||!("key"in t)?s=new Dt(t,t?.value):s=new Dt(t.key,t.value);const o=Zn(this.items,s.key),a=this.schema?.sortMapEntries;if(o){if(!n)throw new Error(`Key ${s.key} already set`);rt(o.value)&&xu(s.value)?o.value.value=s.value:o.value=s.value}else if(a){const i=this.items.findIndex(l=>a(s,l)<0);i===-1?this.items.push(s):this.items.splice(i,0,s)}else this.items.push(s)}delete(t){const n=Zn(this.items,t);return n?this.items.splice(this.items.indexOf(n),1).length>0:!1}get(t,n){const o=Zn(this.items,t)?.value;return(!n&&rt(o)?o.value:o)??void 0}has(t){return!!Zn(this.items,t)}set(t,n){this.add(new Dt(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)Nu(n,o,a);return o}toString(t,n,s){if(!t)return JSON.stringify(this);for(const o of this.items)if(!wt(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})),Su(this,t,{blockItemPrefix:"",flowChars:{start:"{",end:"}"},itemIndent:t.indent||"",onChompKeep:s,onComment:n})}}const qs={collection:"map",default:!0,nodeClass:Kt,tag:"tag:yaml.org,2002:map",resolve(e,t){return kr(e)||t("Expected a mapping for this tag"),e},createNode:(e,t,n)=>Kt.from(e,t,n)};class ns extends bu{static get tagName(){return"tag:yaml.org,2002:seq"}constructor(t){super($s,t),this.items=[]}add(t){this.items.push(t)}delete(t){const n=Qr(t);return typeof n!="number"?!1:this.items.splice(n,1).length>0}get(t,n){const s=Qr(t);if(typeof s!="number")return;const o=this.items[s];return!n&&rt(o)?o.value:o}has(t){const n=Qr(t);return typeof n=="number"&&n<this.items.length}set(t,n){const s=Qr(t);if(typeof s!="number")throw new Error(`Expected a valid index, not ${t}.`);const o=this.items[s];rt(o)&&xu(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?Su(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(hr(l,void 0,s))}}return a}}function Qr(e){let t=rt(e)?e.value:e;return t&&typeof t=="string"&&(t=Number(t)),typeof t=="number"&&Number.isInteger(t)&&t>=0?t:null}const zs={collection:"seq",default:!0,nodeClass:ns,tag:"tag:yaml.org,2002:seq",resolve(e,t){return vr(e)||t("Expected a sequence for this tag"),e},createNode:(e,t,n)=>ns.from(e,t,n)},Do={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),Ja(e,t,n,s)}},Oo={identify:e=>e==null,createNode:()=>new De(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^(?:~|[Nn]ull|NULL)?$/,resolve:()=>new De(null),stringify:({source:e},t)=>typeof e=="string"&&Oo.test.test(e)?e:t.options.nullStr},ti={identify:e=>typeof e=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,resolve:e=>new De(e[0]==="t"||e[0]==="T"),stringify({source:e,value:t},n){if(e&&ti.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 Cu={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},Eu={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)}},Iu={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 De(parseFloat(e)),n=e.indexOf(".");return n!==-1&&e[e.length-1]==="0"&&(t.minFractionDigits=e.length-n-1),t},stringify:nn},$o=e=>typeof e=="bigint"||Number.isInteger(e),ni=(e,t,n,{intAsBigInt:s})=>s?BigInt(e):parseInt(e.substring(t),n);function Tu(e,t,n){const{value:s}=e;return $o(s)&&s>=0?n+s.toString(t):nn(e)}const Mu={identify:e=>$o(e)&&e>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^0o[0-7]+$/,resolve:(e,t,n)=>ni(e,2,8,n),stringify:e=>Tu(e,8,"0o")},Au={identify:$o,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9]+$/,resolve:(e,t,n)=>ni(e,0,10,n),stringify:nn},Lu={identify:e=>$o(e)&&e>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^0x[0-9a-fA-F]+$/,resolve:(e,t,n)=>ni(e,2,16,n),stringify:e=>Tu(e,16,"0x")},x0=[qs,zs,Do,Oo,ti,Mu,Au,Lu,Cu,Eu,Iu];function ec(e){return typeof e=="bigint"||Number.isInteger(e)}const Jr=({value:e})=>JSON.stringify(e),b0=[{identify:e=>typeof e=="string",default:!0,tag:"tag:yaml.org,2002:str",resolve:e=>e,stringify:Jr},{identify:e=>e==null,createNode:()=>new De(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^null$/,resolve:()=>null,stringify:Jr},{identify:e=>typeof e=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^true$|^false$/,resolve:e=>e==="true",stringify:Jr},{identify:ec,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})=>ec(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:Jr}],y0={default:!0,tag:"",test:/^/,resolve(e,t){return t(`Unresolved plain scalar ${JSON.stringify(e)}`),e}},w0=[qs,zs].concat(b0,y0),si={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=De.BLOCK_LITERAL),t!==De.QUOTE_DOUBLE){const c=Math.max(s.options.lineWidth-s.indent.length,s.options.minContentWidth),d=Math.ceil(l.length/c),f=new Array(d);for(let u=0,h=0;u<d;++u,h+=c)f[u]=l.substr(h,c);l=f.join(t===De.BLOCK_LITERAL?`
|
|
58
|
-
`:" ")}return Ja({comment:e,type:t,value:l},s,o,a)}};function _u(e,t){if(vr(e))for(let n=0;n<e.items.length;++n){let s=e.items[n];if(!wt(s)){if(kr(s)){s.items.length>1&&t("Each pair must have its own sequence indicator");const o=s.items[0]||new Dt(new De(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]=wt(s)?s:new Dt(s)}}else t("Expected a sequence for this tag");return e}function Ru(e,t,n){const{replacer:s}=n,o=new ns(e);o.tag="tag:yaml.org,2002:pairs";let a=0;if(t&&Symbol.iterator in Object(t))for(let i of t){typeof s=="function"&&(i=s.call(t,String(a++),i));let l,c;if(Array.isArray(i))if(i.length===2)l=i[0],c=i[1];else throw new TypeError(`Expected [key, value] tuple: ${i}`);else if(i&&i instanceof Object){const d=Object.keys(i);if(d.length===1)l=d[0],c=i[l];else throw new TypeError(`Expected tuple with one key, not ${d.length} keys`)}else l=i;o.items.push(ei(l,c,n))}return o}const ri={collection:"seq",default:!1,tag:"tag:yaml.org,2002:pairs",resolve:_u,createNode:Ru};class Cs extends ns{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=Cs.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(wt(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=Ru(t,n,s),a=new this;return a.items=o.items,a}}Cs.tag="tag:yaml.org,2002:omap";const oi={collection:"seq",identify:e=>e instanceof Map,nodeClass:Cs,default:!1,tag:"tag:yaml.org,2002:omap",resolve(e,t){const n=_u(e,t),s=[];for(const{key:o}of n.items)rt(o)&&(s.includes(o.value)?t(`Ordered maps must not include duplicate keys: ${o.value}`):s.push(o.value));return Object.assign(new Cs,n)},createNode:(e,t,n)=>Cs.from(e,t,n)};function Du({value:e,source:t},n){return t&&(e?Ou:$u).test.test(t)?t:e?n.options.trueStr:n.options.falseStr}const Ou={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 De(!0),stringify:Du},$u={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 De(!1),stringify:Du},k0={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},v0={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)}},j0={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 De(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},jr=e=>typeof e=="bigint"||Number.isInteger(e);function Po(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 ai(e,t,n){const{value:s}=e;if(jr(s)){const o=s.toString(t);return s<0?"-"+n+o.substr(1):n+o}return nn(e)}const N0={identify:jr,default:!0,tag:"tag:yaml.org,2002:int",format:"BIN",test:/^[-+]?0b[0-1_]+$/,resolve:(e,t,n)=>Po(e,2,2,n),stringify:e=>ai(e,2,"0b")},S0={identify:jr,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^[-+]?0[0-7_]+$/,resolve:(e,t,n)=>Po(e,1,8,n),stringify:e=>ai(e,8,"0")},C0={identify:jr,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9][0-9_]*$/,resolve:(e,t,n)=>Po(e,0,10,n),stringify:nn},E0={identify:jr,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^[-+]?0x[0-9a-fA-F_]+$/,resolve:(e,t,n)=>Po(e,2,16,n),stringify:e=>ai(e,16,"0x")};class Es extends Kt{constructor(t){super(t),this.tag=Es.tag}add(t){let n;wt(t)?n=t:t&&typeof t=="object"&&"key"in t&&"value"in t&&t.value===null?n=new Dt(t.key,null):n=new Dt(t,null),Zn(this.items,n.key)||this.items.push(n)}get(t,n){const s=Zn(this.items,t);return!n&&wt(s)?rt(s.key)?s.key.value:s.key:s}set(t,n){if(typeof n!="boolean")throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof n}`);const s=Zn(this.items,t);s&&!n?this.items.splice(this.items.indexOf(s),1):!s&&n&&this.items.push(new Dt(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(ei(i,null,s));return a}}Es.tag="tag:yaml.org,2002:set";const ii={collection:"map",identify:e=>e instanceof Set,nodeClass:Es,default:!1,tag:"tag:yaml.org,2002:set",createNode:(e,t,n)=>Es.from(e,t,n),resolve(e,t){if(kr(e)){if(e.hasAllNullValues(!0))return Object.assign(new Es,e);t("Set items must all have null values")}else t("Expected a mapping for this tag");return e}};function li(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 Pu(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 Bu={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})=>li(e,n),stringify:Pu},qu={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=>li(e,!1),stringify:Pu},Bo={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(Bo.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 f=t[8];if(f&&f!=="Z"){let u=li(f,!1);Math.abs(u)<30&&(u*=60),d-=6e4*u}return new Date(d)},stringify:({value:e})=>e?.toISOString().replace(/(T00:00:00)?\.000Z$/,"")??""},tc=[qs,zs,Do,Oo,Ou,$u,N0,S0,C0,E0,k0,v0,j0,si,bn,oi,ri,ii,Bu,qu,Bo],nc=new Map([["core",x0],["failsafe",[qs,zs,Do]],["json",w0],["yaml11",tc],["yaml-1.1",tc]]),sc={binary:si,bool:ti,float:Iu,floatExp:Eu,floatNaN:Cu,floatTime:qu,int:Au,intHex:Lu,intOct:Mu,intTime:Bu,map:qs,merge:bn,null:Oo,omap:oi,pairs:ri,seq:zs,set:ii,timestamp:Bo},I0={"tag:yaml.org,2002:binary":si,"tag:yaml.org,2002:merge":bn,"tag:yaml.org,2002:omap":oi,"tag:yaml.org,2002:pairs":ri,"tag:yaml.org,2002:set":ii,"tag:yaml.org,2002:timestamp":Bo};function da(e,t,n){const s=nc.get(t);if(s&&!e)return n&&!s.includes(bn)?s.concat(bn):s.slice();let o=s;if(!o)if(Array.isArray(e))o=[];else{const a=Array.from(nc.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(bn)),o.reduce((a,i)=>{const l=typeof i=="string"?sc[i]:i;if(!l){const c=JSON.stringify(i),d=Object.keys(sc).map(f=>JSON.stringify(f)).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 ci{constructor({compat:t,customTags:n,merge:s,resolveKnownTags:o,schema:a,sortMapEntries:i,toStringDefaults:l}){this.compat=Array.isArray(t)?da(t,"compat"):t?da(null,t):null,this.name=typeof a=="string"&&a||"core",this.knownTags=o?I0:{},this.tags=da(n,this.name,s),this.toStringOptions=l??null,Object.defineProperty(this,Ln,{value:qs}),Object.defineProperty(this,ln,{value:Do}),Object.defineProperty(this,$s,{value:zs}),this.sortMapEntries=typeof i=="function"?i:i===!0?T0:null}clone(){const t=Object.create(ci.prototype,Object.getOwnPropertyDescriptors(this));return t.tags=this.tags.slice(),t}}function M0(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=wu(e,t),{commentString:a}=o.options;if(e.commentBefore){n.length!==1&&n.unshift("");const c=a(e.commentBefore);n.unshift(xn(c,""))}let i=!1,l=null;if(e.contents){if(yt(e.contents)){if(e.contents.spaceBefore&&s&&n.push(""),e.contents.commentBefore){const f=a(e.contents.commentBefore);n.push(xn(f,""))}o.forceBlockIndent=!!e.comment,l=e.contents.comment}const c=l?void 0:()=>i=!0;let d=Rs(e.contents,o,()=>l=null,c);l&&(d+=Xn(d,"",a(l))),(d[0]==="|"||d[0]===">")&&n[n.length-1]==="---"?n[n.length-1]=`--- ${d}`:n.push(d)}else n.push(Rs(e.contents,o));if(e.directives?.docEnd)if(e.comment){const c=a(e.comment);c.includes(`
|
|
61
|
-
`)?(n.push("..."),n.push(xn(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(xn(a(c),"")))}return n.join(`
|
|
62
|
-
`)+`
|
|
63
|
-
`}class Nr{constructor(t,n,s){this.commentBefore=null,this.comment=null,this.errors=[],this.warnings=[],Object.defineProperty(this,Yt,{value:Ca});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 Rt({version:i}),this.setSchema(i,s),this.contents=t===void 0?null:this.createNode(t,o,s)}clone(){const t=Object.create(Nr.prototype,{[Yt]:{value:Ca}});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=yt(this.contents)?this.contents.clone(t.schema):this.contents,this.range&&(t.range=this.range.slice()),t}add(t){gs(this.contents)&&this.contents.add(t)}addIn(t,n){gs(this.contents)&&this.contents.addIn(t,n)}createAlias(t,n){if(!t.anchor){const s=pu(this);t.anchor=!n||s.has(n)?gu(n||"a",s):n}return new Qa(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=y=>typeof y=="number"||y instanceof String||y 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:f}=s??{},{onAnchor:u,setAnchors:h,sourceObjects:m}=r0(this,i||"a"),g={aliasDuplicateObjects:a??!0,keepUndefined:c??!1,onAnchor:u,onTagObj:d,replacer:o,schema:this.schema,sourceObjects:m},b=hr(t,f,g);return l&&bt(b)&&(b.flow=!0),h(),b}createPair(t,n,s={}){const o=this.createNode(t,null,s),a=this.createNode(n,null,s);return new Dt(o,a)}delete(t){return gs(this.contents)?this.contents.delete(t):!1}deleteIn(t){return er(t)?this.contents==null?!1:(this.contents=null,!0):gs(this.contents)?this.contents.deleteIn(t):!1}get(t,n){return bt(this.contents)?this.contents.get(t,n):void 0}getIn(t,n){return er(t)?!n&&rt(this.contents)?this.contents.value:this.contents:bt(this.contents)?this.contents.getIn(t,n):void 0}has(t){return bt(this.contents)?this.contents.has(t):!1}hasIn(t){return er(t)?this.contents!==void 0:bt(this.contents)?this.contents.hasIn(t):!1}set(t,n){this.contents==null?this.contents=bo(this.schema,[t],n):gs(this.contents)&&this.contents.set(t,n)}setIn(t,n){er(t)?this.contents=n:this.contents==null?this.contents=bo(this.schema,Array.from(t),n):gs(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 Rt({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 Rt({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 ci(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:f}of l.anchors.values())a(f,d);return typeof i=="function"?js(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 M0(this,t)}}function gs(e){if(bt(e))return!0;throw new Error("Expected a YAML collection as document contents")}class zu extends Error{constructor(t,n,s,o){super(),this.name=t,this.code=s,this.message=o,this.pos=n}}class tr extends zu{constructor(t,n,s){super("YAMLParseError",t,n,s)}}class A0 extends zu{constructor(t,n,s){super("YAMLWarning",t,n,s)}}const rc=(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 Ds(e,{flow:t,indicator:n,next:s,offset:o,onError:a,parentIndent:i,startOnNewline:l}){let c=!1,d=l,f=l,u="",h="",m=!1,g=!1,b=null,k=null,v=null,y=null,x=null,w=null,C=null;for(const S of e)switch(g&&(S.type!=="space"&&S.type!=="newline"&&S.type!=="comma"&&a(S.offset,"MISSING_CHAR","Tags and anchors must be separated from the next token by white space"),g=!1),b&&(d&&S.type!=="comment"&&S.type!=="newline"&&a(b,"TAB_AS_INDENT","Tabs are not allowed as indentation"),b=null),S.type){case"space":!t&&(n!=="doc-start"||s?.type!=="flow-collection")&&S.source.includes(" ")&&(b=S),f=!0;break;case"comment":{f||a(S,"MISSING_CHAR","Comments must be separated from other tokens by white space characters");const R=S.source.substring(1)||" ";u?u+=h+R:u=R,h="",d=!1;break}case"newline":d?u?u+=S.source:(!w||n!=="seq-item-ind")&&(c=!0):h+=S.source,d=!0,m=!0,(k||v)&&(y=S),f=!0;break;case"anchor":k&&a(S,"MULTIPLE_ANCHORS","A node can have at most one anchor"),S.source.endsWith(":")&&a(S.offset+S.source.length-1,"BAD_ALIAS","Anchor ending in : is ambiguous",!0),k=S,C??(C=S.offset),d=!1,f=!1,g=!0;break;case"tag":{v&&a(S,"MULTIPLE_TAGS","A node can have at most one tag"),v=S,C??(C=S.offset),d=!1,f=!1,g=!0;break}case n:(k||v)&&a(S,"BAD_PROP_ORDER",`Anchors and tags must be after the ${S.source} indicator`),w&&a(S,"UNEXPECTED_TOKEN",`Unexpected ${S.source} in ${t??"collection"}`),w=S,d=n==="seq-item-ind"||n==="explicit-key-ind",f=!1;break;case"comma":if(t){x&&a(S,"UNEXPECTED_TOKEN",`Unexpected , in ${t}`),x=S,d=!1,f=!1;break}default:a(S,"UNEXPECTED_TOKEN",`Unexpected ${S.type} token`),d=!1,f=!1}const j=e[e.length-1],E=j?j.offset+j.source.length:o;return g&&s&&s.type!=="space"&&s.type!=="newline"&&s.type!=="comma"&&(s.type!=="scalar"||s.source!=="")&&a(s.offset,"MISSING_CHAR","Tags and anchors must be separated from the next token by white space"),b&&(d&&b.indent<=i||s?.type==="block-map"||s?.type==="block-seq")&&a(b,"TAB_AS_INDENT","Tabs are not allowed as indentation"),{comma:x,found:w,spaceBefore:c,comment:u,hasNewline:m,anchor:k,tag:v,newlineAfterProp:y,end:E,start:C??E}}function mr(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(mr(t.key)||mr(t.value))return!0}return!1;default:return!0}}function Ma(e,t,n){if(t?.type==="flow-collection"){const s=t.end[0];s.indent===e&&(s.source==="]"||s.source==="}")&&mr(t)&&n(s,"BAD_INDENT","Flow end indicator should be more indented than parent",!0)}}function Fu(e,t,n){const{uniqueKeys:s}=e.options;if(s===!1)return!1;const o=typeof s=="function"?s:(a,i)=>a===i||rt(a)&&rt(i)&&a.value===i.value;return t.some(a=>o(a.key,n))}const oc="All mapping items must start at the same column";function L0({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 f of s.items){const{start:u,key:h,sep:m,value:g}=f,b=Ds(u,{indicator:"explicit-key-ind",next:h??m?.[0],offset:c,onError:o,parentIndent:s.indent,startOnNewline:!0}),k=!b.found;if(k){if(h&&(h.type==="block-seq"?o(c,"BLOCK_AS_IMPLICIT_KEY","A block sequence may not be used as an implicit map key"):"indent"in h&&h.indent!==s.indent&&o(c,"BAD_INDENT",oc)),!b.anchor&&!b.tag&&!m){d=b.end,b.comment&&(l.comment?l.comment+=`
|
|
70
|
-
`+b.comment:l.comment=b.comment);continue}(b.newlineAfterProp||mr(h))&&o(h??u[u.length-1],"MULTILINE_IMPLICIT_KEY","Implicit keys need to be on a single line")}else b.found?.indent!==s.indent&&o(c,"BAD_INDENT",oc);n.atKey=!0;const v=b.end,y=h?e(n,h,b,o):t(n,v,u,null,b,o);n.schema.compat&&Ma(s.indent,h,o),n.atKey=!1,Fu(n,l.items,y)&&o(v,"DUPLICATE_KEY","Map keys must be unique");const x=Ds(m??[],{indicator:"map-value-ind",next:g,offset:y.range[2],onError:o,parentIndent:s.indent,startOnNewline:!h||h.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&&b.start<x.found.offset-1024&&o(y.range,"KEY_OVER_1024_CHARS","The : indicator must be at most 1024 chars after the start of an implicit block mapping key"));const w=g?e(n,g,x,o):t(n,c,m,null,x,o);n.schema.compat&&Ma(s.indent,g,o),c=w.range[2];const C=new Dt(y,w);n.options.keepSourceTokens&&(C.srcToken=f),l.items.push(C)}else{k&&o(y.range,"MISSING_CHAR","Implicit map keys need to be followed by map values"),x.comment&&(y.comment?y.comment+=`
|
|
71
|
-
`+x.comment:y.comment=x.comment);const w=new Dt(y);n.options.keepSourceTokens&&(w.srcToken=f),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 _0({composeNode:e,composeEmptyNode:t},n,s,o,a){const i=a?.nodeClass??ns,l=new i(n.schema);n.atRoot&&(n.atRoot=!1),n.atKey&&(n.atKey=!1);let c=s.offset,d=null;for(const{start:f,value:u}of s.items){const h=Ds(f,{indicator:"seq-item-ind",next:u,offset:c,onError:o,parentIndent:s.indent,startOnNewline:!0});if(!h.found)if(h.anchor||h.tag||u)u?.type==="block-seq"?o(h.end,"BAD_INDENT","All sequence items must start at the same column"):o(c,"MISSING_CHAR","Sequence item without - indicator");else{d=h.end,h.comment&&(l.comment=h.comment);continue}const m=u?e(n,u,h,o):t(n,h.end,f,null,h,o);n.schema.compat&&Ma(s.indent,u,o),c=m.range[2],l.items.push(m)}return l.range=[s.offset,c,d??c],l}function Sr(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 f=c.substring(1)||" ";o?o+=i+f:o=f,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 ua="Block collections are not allowed within flow collections",fa=e=>e&&(e.type==="block-map"||e.type==="block-seq");function R0({composeNode:e,composeEmptyNode:t},n,s,o,a){const i=s.start.source==="{",l=i?"flow map":"flow sequence",c=a?.nodeClass??(i?Kt:ns),d=new c(n.schema);d.flow=!0;const f=n.atRoot;f&&(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:y,key:x,sep:w,value:C}=v,j=Ds(y,{flow:l,indicator:"explicit-key-ind",next:x??w?.[0],offset:u,onError:o,parentIndent:s.indent,startOnNewline:!1});if(!j.found){if(!j.anchor&&!j.tag&&!w&&!C){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&&mr(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 S of y)switch(S.type){case"comma":case"space":break;case"comment":E=S.source.substring(1);break e;default:break e}if(E){let S=d.items[d.items.length-1];wt(S)&&(S=S.value??S.key),S.comment?S.comment+=`
|
|
73
|
-
`+E:S.comment=E,j.comment=j.comment.substring(E.length+1)}}if(!i&&!w&&!j.found){const E=C?e(n,C,j,o):t(n,j.end,w,null,j,o);d.items.push(E),u=E.range[2],fa(C)&&o(E.range,"BLOCK_IN_FLOW",ua)}else{n.atKey=!0;const E=j.end,S=x?e(n,x,j,o):t(n,E,y,null,j,o);fa(x)&&o(S.range,"BLOCK_IN_FLOW",ua),n.atKey=!1;const R=Ds(w??[],{flow:l,indicator:"map-value-ind",next:C,offset:S.range[2],onError:o,parentIndent:s.indent,startOnNewline:!1});if(R.found){if(!i&&!j.found&&n.options.strict){if(w)for(const D of w){if(D===R.found)break;if(D.type==="newline"){o(D,"MULTILINE_IMPLICIT_KEY","Implicit keys of flow sequence pairs need to be on a single line");break}}j.start<R.found.offset-1024&&o(R.found,"KEY_OVER_1024_CHARS","The : indicator must be at most 1024 chars after the start of an implicit flow sequence key")}}else C&&("source"in C&&C.source?.[0]===":"?o(C,"MISSING_CHAR",`Missing space after : in ${l}`):o(R.start,"MISSING_CHAR",`Missing , or : between ${l} items`));const $=C?e(n,C,R,o):R.found?t(n,R.end,w,null,R,o):null;$?fa(C)&&o($.range,"BLOCK_IN_FLOW",ua):R.comment&&(S.comment?S.comment+=`
|
|
74
|
-
`+R.comment:S.comment=R.comment);const M=new Dt(S,$);if(n.options.keepSourceTokens&&(M.srcToken=v),i){const D=d;Fu(n,D.items,S)&&o(E,"DUPLICATE_KEY","Map keys must be unique"),D.items.push(M)}else{const D=new Kt(n.schema);D.flow=!0,D.items.push(M);const z=($??S).range;D.range=[S.range[0],z[1],z[2]],d.items.push(D)}u=$?$.range[2]:R.end}}const h=i?"}":"]",[m,...g]=s.end;let b=u;if(m?.source===h)b=m.offset+m.source.length;else{const k=l[0].toUpperCase()+l.substring(1),v=f?`${k} must end with a ${h}`:`${k} in block collection must be sufficiently indented and end with a ${h}`;o(u,f?"MISSING_CHAR":"BAD_INDENT",v),m&&m.source.length!==1&&g.unshift(m)}if(g.length>0){const k=Sr(g,b,n.options.strict,o);k.comment&&(d.comment?d.comment+=`
|
|
75
|
-
`+k.comment:d.comment=k.comment),d.range=[s.offset,b,k.offset]}else d.range=[s.offset,b,b];return d}function ha(e,t,n,s,o,a){const i=n.type==="block-map"?L0(e,t,n,s,a):n.type==="block-seq"?_0(e,t,n,s,a):R0(e,t,n,s,a),l=i.constructor;return o==="!"||o===l.tagName?(i.tag=l.tagName,i):(o&&(i.tag=o),i)}function D0(e,t,n,s,o){const a=s.tag,i=a?t.directives.tagName(a.source,h=>o(a,"TAG_RESOLVE_FAILED",h)):null;if(n.type==="block-seq"){const{anchor:h,newlineAfterProp:m}=s,g=h&&a?h.offset>a.offset?h:a:h??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===ns.tagName&&l==="seq")return ha(e,t,n,o,i);let c=t.schema.tags.find(h=>h.tag===i&&h.collection===l);if(!c){const h=t.schema.knownTags[i];if(h?.collection===l)t.schema.tags.push(Object.assign({},h,{default:!1})),c=h;else return h?o(a,"BAD_COLLECTION_TYPE",`${h.tag} used for ${l} collection, but expects ${h.collection??"scalar"}`,!0):o(a,"TAG_RESOLVE_FAILED",`Unresolved tag: ${i}`,!0),ha(e,t,n,o,i)}const d=ha(e,t,n,o,i,c),f=c.resolve?.(d,h=>o(a,"TAG_RESOLVE_FAILED",h),t.options)??d,u=yt(f)?f:new De(f);return u.range=d.range,u.tag=i,c?.format&&(u.format=c.format),u}function O0(e,t,n){const s=t.offset,o=$0(t,e.options.strict,n);if(!o)return{value:"",type:null,comment:"",range:[s,s,s]};const a=o.mode===">"?De.BLOCK_FOLDED:De.BLOCK_LITERAL,i=t.source?P0(t.source):[];let l=i.length;for(let b=i.length-1;b>=0;--b){const k=i[b][1];if(k===""||k==="\r")l=b;else break}if(l===0){const b=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:b,type:a,comment:o.comment,range:[s,k,k]}}let c=t.indent+o.indent,d=t.offset+o.length,f=0;for(let b=0;b<l;++b){const[k,v]=i[b];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),f=b,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 b=i.length-1;b>=l;--b)i[b][0].length>c&&(l=b+1);let u="",h="",m=!1;for(let b=0;b<f;++b)u+=i[b][0].slice(c)+`
|
|
77
|
-
`;for(let b=f;b<l;++b){let[k,v]=i[b];d+=k.length+v.length+1;const y=v[v.length-1]==="\r";if(y&&(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-(y?2:1),"BAD_INDENT",w),k=""}a===De.BLOCK_LITERAL?(u+=h+k.slice(c)+v,h=`
|
|
78
|
-
`):k.length>c||v[0]===" "?(h===" "?h=`
|
|
79
|
-
`:!m&&h===`
|
|
80
|
-
`&&(h=`
|
|
81
|
-
|
|
82
|
-
`),u+=h+k.slice(c)+v,h=`
|
|
83
|
-
`,m=!0):v===""?h===`
|
|
84
|
-
`?u+=`
|
|
85
|
-
`:h=`
|
|
86
|
-
`:(u+=h+v,h=" ",m=!1)}switch(o.chomp){case"-":break;case"+":for(let b=l;b<i.length;++b)u+=`
|
|
87
|
-
`+i[b][0].slice(c);u[u.length-1]!==`
|
|
88
|
-
`&&(u+=`
|
|
89
|
-
`);break;default:u+=`
|
|
90
|
-
`}const g=s+o.length+t.source.length;return{value:u,type:a,comment:o.comment,range:[s,g,g]}}function $0({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 h=1;h<o.length;++h){const m=o[h];if(!l&&(m==="-"||m==="+"))l=m;else{const g=Number(m);!i&&g?i=g:c===-1&&(c=e+h)}}c!==-1&&s(c,"UNEXPECTED_TOKEN",`Block scalar header includes extra characters: ${o}`);let d=!1,f="",u=o.length;for(let h=1;h<t.length;++h){const m=t[h];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,f=m.source.substring(1);break;case"error":s(m,"UNEXPECTED_TOKEN",m.message),u+=m.source.length;break;default:{const g=`Unexpected token in block scalar header: ${m.type}`;s(m,"UNEXPECTED_TOKEN",g);const b=m.source;b&&typeof b=="string"&&(u+=b.length)}}}return{mode:a,indent:i,chomp:l,comment:f,length:u}}function P0(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 B0(e,t,n){const{offset:s,type:o,source:a,end:i}=e;let l,c;const d=(h,m,g)=>n(s+h,m,g);switch(o){case"scalar":l=De.PLAIN,c=q0(a,d);break;case"single-quoted-scalar":l=De.QUOTE_SINGLE,c=z0(a,d);break;case"double-quoted-scalar":l=De.QUOTE_DOUBLE,c=F0(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 f=s+a.length,u=Sr(i,f,t,n);return{value:c,type:l,comment:u.comment,range:[s,f,u.offset]}}function q0(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}`),Hu(e)}function z0(e,t){return(e[e.length-1]!=="'"||e.length===1)&&t(e.length,"MISSING_CHAR","Missing closing 'quote"),Hu(e.slice(1,-1)).replace(/''/g,"'")}function Hu(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 F0(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}=H0(e,s);n+=a,s=i}else if(o==="\\"){let a=e[++s];const i=V0[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+=W0(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 H0(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 V0={0:"\0",a:"\x07",b:"\b",e:"\x1B",f:"\f",n:`
|
|
105
|
-
`,r:"\r",t:" ",v:"\v",N:"
",_:" ",L:"\u2028",P:"\u2029"," ":" ",'"':'"',"/":"/","\\":"\\"," ":" "};function W0(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 Vu(e,t,n,s){const{value:o,type:a,comment:i,range:l}=t.type==="block-scalar"?O0(e,t,s):B0(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[ln]:c?d=K0(e.schema,o,c,n,s):t.type==="scalar"?d=U0(e,o,t,s):d=e.schema[ln];let f;try{const u=d.resolve(o,h=>s(n??t,"TAG_RESOLVE_FAILED",h),e.options);f=rt(u)?u:new De(u)}catch(u){const h=u instanceof Error?u.message:String(u);s(n??t,"TAG_RESOLVE_FAILED",h),f=new De(o)}return f.range=l,f.source=o,a&&(f.type=a),c&&(f.tag=c),d.format&&(f.format=d.format),i&&(f.comment=i),f}function K0(e,t,n,s,o){if(n==="!")return e[ln];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[ln])}function U0({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[ln];if(n.compat){const l=n.compat.find(c=>c.default&&c.test?.test(s))??n[ln];if(i.tag!==l.tag){const c=t.tagString(i.tag),d=t.tagString(l.tag),f=`Value may be parsed as either ${c} or ${d}`;a(o,"TAG_RESOLVE_FAILED",f,!0)}}return i}function Y0(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 G0={composeNode:Wu,composeEmptyNode:di};function Wu(e,t,n,s){const o=e.atKey,{spaceBefore:a,comment:i,anchor:l,tag:c}=n;let d,f=!0;switch(t.type){case"alias":d=X0(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=Vu(e,t,c,s),l&&(d.anchor=l.source.substring(1));break;case"block-map":case"block-seq":case"flow-collection":try{d=D0(G0,e,t,n,s),l&&(d.anchor=l.source.substring(1))}catch(u){const h=u instanceof Error?u.message:String(u);s(t,"RESOURCE_EXHAUSTION",h)}break;default:{const u=t.type==="error"?t.message:`Unsupported token (type: ${t.type})`;s(t,"UNEXPECTED_TOKEN",u),f=!1}}return d??(d=di(e,t.offset,void 0,null,n,s)),l&&d.anchor===""&&s(l,"BAD_ALIAS","Anchor cannot be an empty string"),o&&e.options.stringKeys&&(!rt(d)||typeof d.value!="string"||d.tag&&d.tag!=="tag:yaml.org,2002:str")&&s(c??t,"NON_STRING_KEY","With stringKeys, all keys must be strings"),a&&(d.spaceBefore=!0),i&&(t.type==="scalar"&&t.source===""?d.comment=i:d.commentBefore=i),e.options.keepSourceTokens&&f&&(d.srcToken=t),d}function di(e,t,n,s,{spaceBefore:o,comment:a,anchor:i,tag:l,end:c},d){const f={type:"scalar",offset:Y0(t,n,s),indent:-1,source:""},u=Vu(e,f,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 X0({options:e},{offset:t,source:n,end:s},o){const a=new Qa(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=Sr(s,i,e.strict,o);return a.range=[t,i,l.offset],l.comment&&(a.comment=l.comment),a}function Z0(e,t,{offset:n,start:s,value:o,end:a},i){const l=Object.assign({_directives:t},e),c=new Nr(void 0,l),d={atKey:!1,atRoot:!0,directives:c.directives,options:c.options,schema:c.schema},f=Ds(s,{indicator:"doc-start",next:o??a?.[0],offset:n,onError:i,parentIndent:0,startOnNewline:!0});f.found&&(c.directives.docStart=!0,o&&(o.type==="block-map"||o.type==="block-seq")&&!f.hasNewline&&i(f.end,"MISSING_CHAR","Block collection cannot start on same line with directives-end marker")),c.contents=o?Wu(d,o,f,i):di(d,f.end,s,null,f,i);const u=c.contents.range[2],h=Sr(a,u,!1,i);return h.comment&&(c.comment=h.comment),c.range=[n,u,h.offset],c}function Js(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 ac(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 Q0{constructor(t={}){this.doc=null,this.atDirectives=!1,this.prelude=[],this.errors=[],this.warnings=[],this.onError=(n,s,o,a)=>{const i=Js(n);a?this.warnings.push(new A0(i,s,o)):this.errors.push(new tr(i,s,o))},this.directives=new Rt({version:t.version||"1.2"}),this.options=t}decorate(t,n){const{comment:s,afterEmptyLine:o}=ac(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(bt(a)&&!a.flow&&a.items.length>0){let i=a.items[0];wt(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:ac(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=Js(t);a[0]+=n,this.onError(a,"BAD_DIRECTIVE",s,o)}),this.prelude.push(t.source),this.atDirectives=!0;break;case"document":{const n=Z0(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 tr(Js(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 tr(Js(t),"UNEXPECTED_TOKEN",s));break}this.doc.directives.docEnd=!0;const n=Sr(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 tr(Js(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 Nr(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 Ku="\uFEFF",Uu="",Yu="",Aa="";function J0(e){switch(e){case Ku:return"byte-order-mark";case Uu:return"doc-mode";case Yu:return"flow-error-end";case Aa: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 ic=new Set("0123456789ABCDEFabcdef"),eb=new Set("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()"),eo=new Set(",[]{}"),tb=new Set(` ,[]{}
|
|
116
|
-
\r `),ma=e=>!e||tb.has(e);class nb{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]===Ku&&(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 Uu,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(ma),"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 Yu,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(ma),"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 Aa,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&&eo.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&&eo.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&&eo.has(o))break;n=s}return!o&&!this.atEnd?this.setNext("plain-scalar"):(yield Aa,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(ma),t+=yield*this.pushSpaces(!0);continue e;case"-":case"?":case":":{const n=this.flowLevel>0,s=this.charAt(1);if(Xt(s)||n&&eo.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(eb.has(n))n=this.buffer[++t];else if(n==="%"&&ic.has(this.buffer[t+1])&&ic.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 sb{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 In(e,t){for(let n=0;n<e.length;++n)if(e[n].type===t)return!0;return!1}function lc(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 Gu(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 to(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 xs(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 wo(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 cc(e){if(e.start.type==="flow-seq-start")for(const t of e.items)t.sep&&!t.value&&!In(t.start,"explicit-key-ind")&&!In(t.sep,"map-value-ind")&&(t.key&&(t.value=t.key),delete t.key,Gu(t.value)?t.value.end?wo(t.value.end,t.sep):t.value.end=t.sep:wo(t.start,t.sep),delete t.sep)}class rb{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 nb,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=J0(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"&&cc(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&&lc(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":{lc(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=to(this.peek(2)),s=xs(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)){wo(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(In(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(Gu(n.key)&&!In(n.sep,"newline")){const i=xs(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(In(n.start,"newline"))Object.assign(n,{key:null,sep:[this.sourceToken]});else{const i=xs(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]}):In(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&&!In(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)){wo(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||In(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=to(s),a=xs(o);cc(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=to(t),s=xs(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=to(t),s=xs(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 ob(e){const t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new sb||null,prettyErrors:t}}function ab(e,t={}){const{lineCounter:n,prettyErrors:s}=ob(t),o=new rb(n?.addNewLine),a=new Q0(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 tr(l.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}return s&&n&&(i.errors.forEach(rc(e,n)),i.warnings.forEach(rc(e,n))),i}function dc(e,t,n){let s;typeof t=="function"?s=t:n===void 0&&t&&typeof t=="object"&&(n=t);const o=ab(e,n);if(!o)return null;if(o.warnings.forEach(a=>ku(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 uc(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 wr(e)&&!s?e.toString(n):new Nr(e,s,n).toString(n)}function ib({expanded:e,onToggle:t,summary:n,actions:s,children:o,className:a="",summaryClassName:i="",panelClassName:l="",testId:c,disabled:d=!1,panelLabel:f}){const u=p.useId(),h=`${u}-toggle`,m=`${u}-panel`,[g,b]=p.useState(e);p.useEffect(()=>{e&&b(!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:h,"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":h,"aria-label":f,"data-testid":c?`${c}-panel`:void 0,className:l,children:g?o:null})})})]})}function lb({step:e,index:t,total:n,dependsOnNames:s,roleOptions:o,onClose:a,onSave:i}){const{t:l}=He(["work","common"]),[c,d]=p.useState(null),[f,u]=p.useState(e.name),[h,m]=p.useState(e.prompt),[g,b]=p.useState(!1),[k,v]=p.useState(null),y=p.useRef(null);p.useEffect(()=>{u(e.name)},[e.name]),p.useEffect(()=>{m(e.prompt)},[e.prompt]),p.useEffect(()=>{const j=E=>{if(E.key==="Escape"){if(c){E.stopPropagation(),d(null),u(e.name),m(e.prompt);return}a()}};return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[c,a,e.name,e.prompt]);const x=async j=>{b(!0),v(null);try{await i(j)}catch(E){v(E instanceof Error?E.message:String(E))}finally{b(!1)}},w=async()=>{d(null);const j=f.trim();if(!j||j===e.name){u(e.name);return}await x({name:j})},C=async()=>{d(null),h!==e.prompt&&await x({prompt:h})};return r.jsxs("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[r.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:a,"aria-hidden":"true"}),r.jsxs("div",{ref:y,role:"dialog","aria-modal":"true","aria-labelledby":"workflow-step-title",className:"relative flex max-h-[88vh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-border-default bg-surface-secondary shadow-2xl","data-testid":"workflow-step-modal",children:[r.jsxs("header",{className:"flex items-start justify-between gap-3 border-b border-border-default/50 px-5 py-3",children:[r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"text-[10px] font-medium uppercase tracking-wider text-fg-muted",children:l("work:task.workflowStepOf","步骤 {{index}} / {{total}}",{index:t+1,total:n})}),c==="name"?r.jsx("input",{autoFocus:!0,value:f,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:h,onChange:j=>m(j.target.value),onBlur:()=>{C()},"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 cb={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:"已取消"}},fc={tone:"neutral",key:"runStatusUnknown",label:"未知"};function Xu(e){return e?cb[e]??{...fc,label:e}:fc}const Mn={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"}},Zu=new Set(["completed","archived"]),Qu=new Set(["failed","rejected"]),Ju=new Set(["in_progress","review"]);function ui(e){return e==="running"||e==="paused"}function fi(e){const t=new Map;for(const n of e)t.set(n.id,n);return t}function db(e,t){return t.get(e)?.name??e}function hi(e,t){return(e.depends_on??[]).map(n=>db(n,t))}function ub(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 f=(n[d]??0)+1;f>(n[c.id]??0)&&(n[c.id]=f,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 ef(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 tf(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++,Zu.has(d.status)?s++:Qu.has(d.status)?(o++,i.push(c)):Ju.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 no(e){return e?Zu.has(e.status)?"done":Qu.has(e.status)?"failed":Ju.has(e.status)?"active":"pending":"unknown"}const nf="markus_workflows_expanded";function fb(e){try{const t=e(nf);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 hb(e,t){try{t(nf,JSON.stringify([...e]))}catch{}}function mb(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 hc({status:e,className:t=""}){const{t:n}=He(["work"]),s=Xu(e),o=Mn[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 pb({items:e}){const{t}=He(["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(gb,{})}),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 gb({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 xb(){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 bb({steps:e,roleAgentName:t,onOpenStep:n}){const{t:s}=He(["work"]),o=fi(e),{layers:a}=ub(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 f=c.length>1;return r.jsxs("li",{children:[f?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:f?"ml-1 space-y-0.5 border-l border-brand-500/30 pl-2":"space-y-0.5",children:c.map(u=>{const h=o.get(u);if(!h)return null;const m=hi(h,o),g=t?.(h.role),b=(i.get(u)??0)+1;return l+=1,r.jsx("li",{children:r.jsxs("button",{type:"button",onClick:()=>n(h,i.get(u)??0),"data-testid":`workflow-step-${u}`,className:"group flex w-full items-center gap-2 rounded-lg px-1.5 py-1.5 text-left transition-colors hover:bg-surface-elevated/60 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60",children:[r.jsx("span",{className:"w-4 shrink-0 text-right text-[10px] tabular-nums text-fg-muted",children:b}),r.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-primary",children:h.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:h.role,children:g??h.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 yb({workflow:e,detail:t,detailState:n,onRetryDetail:s,expanded:o,onToggle:a,runs:i,runTasks:l,onRun:c,onOpenRun:d,onSaveStep:f,roleAgentName:u,onSendToAgent:h,onEdit:m,onDuplicate:g,onDelete:b}){const{t:k}=He(["work","common"]),[v,y]=p.useState(null),x=i[0],w=i.some(S=>ui(S.status)),C=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(hc,{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-on-brand 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(pb,{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:h},{key:"delete",label:k("work:task.workflowDelete","删除工作流"),onSelect:b,danger:!0}]})]});return r.jsxs("div",{className:"min-w-0 rounded-xl border border-border-default/50 bg-surface-secondary p-4","data-testid":`workflow-card-${e.name}`,children:[r.jsx(ib,{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:[C.length>0?r.jsx(bb,{steps:C,roleAgentName:u,onOpenStep:(S,R)=>y({step:S,index:R})}):null,t.params&&t.params.length>0?r.jsxs("div",{children:[r.jsx("p",{className:"mb-1.5 text-[10px] font-medium uppercase tracking-wider text-fg-tertiary",children:k("work:task.workflowParamsCount","参数 ({{count}})",{count:t.params.length})}),r.jsx("div",{className:"flex flex-wrap gap-2",children:t.params.map(S=>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:S.label||S.name}),r.jsx("span",{className:"text-fg-muted",children:S.type||"string"}),S.required?r.jsx("span",{className:"text-red-500",children:"*"}):null]},S.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(S=>{const R=ef(C,l[S.id]??[]),$=tf(C,R);return r.jsx("li",{children:r.jsxs("button",{type:"button",onClick:()=>d(S),"aria-label":k("work:task.workflowRunDetails","运行详情"),"data-testid":`workflow-run-open-${S.id}`,className:"group flex w-full flex-wrap items-center gap-x-2 gap-y-1 rounded-lg px-1.5 py-1.5 text-left text-xs transition-colors hover:bg-surface-elevated/60 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60",children:[r.jsxs("span",{className:"shrink-0 font-medium tabular-nums text-fg-secondary",children:["#",S.runNumber]}),r.jsx(hc,{status:S.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:S.taskIds.length})}),r.jsx("span",{className:"text-[11px] text-fg-muted",children:qc(S.startedAt,k)}),S.triggeredBy==="schedule"?r.jsx("span",{className:"shrink-0 text-[10px] text-purple-500",children:k("work:task.workflowScheduled","定时")}):null,r.jsx("svg",{className:"ml-auto h-3.5 w-3.5 shrink-0 text-fg-muted opacity-0 transition-opacity group-hover:opacity-100",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})})]})},S.id)})})]})]}):r.jsx(xb,{})}),v?r.jsx(lb,{step:v.step,index:v.index,total:C.length,dependsOnNames:hi(v.step,fi(C)),roleOptions:[...new Set([...C.map(S=>S.role),...Object.keys(x?.roleMapping??{})])],onClose:()=>y(null),onSave:S=>f?.(v.step.id,S)??Promise.resolve()}):null]})}const mc={done:Mn.success.bar,failed:Mn.danger.bar,active:Mn.info.bar,pending:"bg-fg-muted/50",unknown:"bg-border-default"},pa={done:{key:"runStatusCompleted",label:"已完成"},failed:{key:"runStatusFailed",label:"失败"},active:{key:"runStatusRunning",label:"进行中"},pending:{key:"workflowStepPending",label:"待处理"},unknown:{key:"workflowStepNoTask",label:"未创建任务"}};function wb({workflow:e,run:t,detail:n,tasks:s,tasksLoading:o,onClose:a,onPauseResume:i,onCancel:l,onViewTasks:c,pausing:d,roleAgentName:f,onOpenTask:u}){const{t:h}=He(["work","common"]),m=p.useRef(null);p.useEffect(()=>{m.current?.focus();const j=E=>{E.key==="Escape"&&a()};return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[a]);const g=t.templateSnapshot?.steps??n?.steps??[],b=fi(g),k=ef(g,s??[]),v=tf(g,k),y=Xu(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),C=j=>w&&j==="unknown"?{key:"workflowStepUnmatched",label:"未匹配(历史运行)"}:pa[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 ${Mn[y.tone].chip}`,children:[r.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${Mn[y.tone].dot}`,"aria-hidden":"true"}),h(`work:task.${y.key}`,y.label)]}),r.jsx("span",{children:qc(t.startedAt,h)}),t.triggeredBy==="schedule"?r.jsx("span",{className:"text-purple-500",children:h("work:task.workflowScheduled","定时")}):null]})]}),r.jsx("button",{ref:m,type:"button",onClick:a,"aria-label":h("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:h("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:h("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?Mn.danger.bar:Mn.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:h("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:h("work:task.workflowLoading","加载中…")}):r.jsx("ol",{className:"space-y-1",children:g.map((j,E)=>{const S=k[j.id],R=no(S),$=C(R),M=hi(j,b),D=f?.(j.role),z=r.jsxs(r.Fragment,{children:[r.jsx("span",{className:`mt-1.5 h-2 w-2 shrink-0 rounded-full ${mc[R]}`,"aria-hidden":"true"}),r.jsxs("span",{className:"min-w-0 flex-1",children:[r.jsxs("span",{className:"flex flex-wrap items-center gap-x-2 gap-y-0.5",children:[r.jsxs("span",{className:"text-xs font-medium text-fg-primary",children:[E+1,". ",j.name]}),r.jsx("span",{className:"text-[10px] text-fg-muted",children:h(`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:D??j.role}),M.length>0?r.jsx("span",{children:h("work:task.workflowDependsOn","依赖 {{steps}}",{steps:M.join("、")})}):null,S?r.jsx("span",{className:"max-w-[16rem] truncate",children:S.title}):null]})]}),S&&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:S&&u?r.jsx("button",{type:"button",onClick:()=>u(S.id),"data-testid":`workflow-run-step-${j.id}`,title:h("work:task.workflowOpenTask","查看对应任务"),className:"group flex w-full items-start gap-2 rounded-lg px-1 py-1 text-left transition-colors hover:bg-surface-elevated/60 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60",children:z}):r.jsx("div",{className:"flex items-start gap-2 rounded-lg px-1 py-1",children:z})},j.id)})}),x.length>0?r.jsxs("div",{className:"mt-3 rounded-lg border border-border-default/50 bg-surface px-2.5 py-2",children:[r.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary",children:h("work:task.workflowUnmatchedTitle","该运行的任务(未能对应到步骤)")}),r.jsx("p",{className:"mt-0.5 text-[10px] leading-relaxed text-fg-muted",children:h("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 ${mc[no(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:h(`work:task.${pa[no(j)].key}`,pa[no(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:h("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:h("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:f?.(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:[ui(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"?h("work:task.workflowPause","暂停"):h("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:h("work:task.workflowCancelRun","取消运行")})]}):null,r.jsx("button",{type:"button",onClick:c,className:"rounded-lg bg-brand-600 px-3 py-1.5 text-xs font-medium text-on-brand transition-colors hover:bg-brand-500",children:h("work:task.workflowViewTasks","查看任务")})]})]})]})}function kb({mode:e,workflow:t,yaml:n,yamlLoading:s,busy:o,error:a,onClose:i,onSubmit:l}){const{t:c}=He(["work","common"]),[d,f]=p.useState(`${t.name}-copy`),[u,h]=p.useState(n??""),m=p.useRef(null);p.useEffect(()=>{h(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","删除工作流"),b=e==="duplicate"&&!/^[a-z0-9][a-z0-9-]*$/.test(d.trim());return r.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[r.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:i,"aria-hidden":"true"}),r.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"workflow-manage-title",className:"relative flex max-h-[85vh] w-full max-w-lg flex-col rounded-xl border border-border-default bg-surface-secondary p-5 shadow-2xl","data-testid":`workflow-manage-${e}`,children:[r.jsx("h2",{id:"workflow-manage-title",className:"text-sm font-semibold text-fg-primary",children:g}),r.jsx("p",{className:"mt-1 text-[11px] text-fg-tertiary",children:e==="delete"?c("work:task.workflowDeleteConfirmDesc","将删除「{{name}}」。已产生的运行记录与任务会保留,此操作不可撤销。",{name:t.displayName||t.name}):e==="duplicate"?c("work:task.workflowDuplicateDesc","基于当前模板创建一份副本,之后可以独立编辑。"):c("work:task.workflowEditDesc","直接编辑模板 YAML。保存时服务端会做校验。")}),e==="delete"?null:r.jsxs("div",{className:"mt-3 flex-1 space-y-3 overflow-y-auto",children:[e==="duplicate"?r.jsxs("div",{children:[r.jsx("label",{className:"mb-1 block text-[11px] font-medium text-fg-secondary",htmlFor:"workflow-new-name",children:c("work:task.workflowNewName","新工作流名称")}),r.jsx("input",{id:"workflow-new-name",ref:m,value:d,onChange:k=>f(k.target.value),placeholder:c("work:task.workflowNewNamePlaceholder","例如 feature-development-v2"),className:"input-field w-full font-mono text-xs"}),b?r.jsx("p",{className:"mt-1 text-[10px] text-red-500",children:c("work:task.workflowNameInvalid","只能使用小写字母、数字和连字符")}):null]}):null,r.jsxs("div",{children:[r.jsx("label",{className:"mb-1 block text-[11px] font-medium text-fg-secondary",htmlFor:"workflow-yaml",children:c("work:task.workflowYaml","YAML")}),s?r.jsxs("div",{className:"space-y-1.5","aria-busy":"true",children:[r.jsx("div",{className:"h-3 w-full animate-pulse rounded bg-surface-elevated"}),r.jsx("div",{className:"h-3 w-5/6 animate-pulse rounded bg-surface-elevated"}),r.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-surface-elevated"})]}):r.jsx("textarea",{id:"workflow-yaml",value:u,onChange:k=>h(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"&&b,onClick:()=>l({name:e==="duplicate"?d.trim():void 0,yaml:u}),className:`px-4 py-1.5 text-xs font-medium text-white transition-colors disabled:opacity-60 ${e==="delete"?"rounded-lg bg-red-600 hover:bg-red-500":"btn-primary"}`,children:o?c("work:task.workflowSaving","保存中…"):e==="delete"?c("work:task.workflowDelete","删除工作流"):e==="duplicate"?c("work:task.workflowDuplicateBtn","创建副本"):c("work:task.workflowSave","保存")})]})]})]})}const pc={pending:new Set(["in_progress","blocked","rejected","cancelled","completed"]),in_progress:new Set(["review","blocked","failed","cancelled"]),blocked:new Set(["in_progress","cancelled","failed"]),review:new Set(["completed","in_progress","cancelled"]),completed:new Set(["archived","in_progress"]),failed:new Set(["in_progress","archived"]),rejected:new Set(["archived"]),cancelled:new Set(["archived","in_progress"]),archived:new Set([])},La={pending:new Set(["in_progress","blocked","rejected","cancelled"]),in_progress:new Set(["completed","blocked","rejected","cancelled"]),blocked:new Set(["in_progress","rejected","cancelled"]),review:new Set(["completed","in_progress","cancelled"]),completed:new Set(["archived","in_progress"]),failed:new Set(["in_progress","archived","pending"]),rejected:new Set(["in_progress","archived","pending"]),cancelled:new Set(["in_progress","archived","pending"]),archived:new Set([])},gc="markus_work_l1_collapsed",xc="markus_workflows_team",bc="__all__",yc=["backlog","kanban","dag","workflows"];function ko(e){const t=e.agentId,n=e.activityId;return!t||!n?null:Oa({seq:e.seq,type:e.type,content:e.content??"",metadata:e.metadata,createdAt:e.createdAt??new Date().toISOString()},n,t)}function mi(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 pi({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(th,{entries:e,isActive:!0,onExpand:()=>n("full"),embedded:!0}):r.jsx(Fc,{entries:e,isActive:!0,onCollapse:()=>n("compact"),embedded:!0})})}function gi(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),[f,u]=p.useState(""),h=p.useRef(null),m=p.useRef(null),g=p.useRef(null),b=p.useRef(null),k=gi(m,c);p.useEffect(()=>{const w=C=>{h.current&&!h.current.contains(C.target)&&b.current&&!b.current.contains(C.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",y=e.find(w=>w.value===t)?.label??"",x=f?e.filter(w=>w.label.toLowerCase().includes(f.toLowerCase())):e;return r.jsxs("div",{ref:h,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:f,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:y||s,autoFocus:!0}):r.jsx("span",{className:y?"text-fg-primary":"text-fg-tertiary",children:y||s}),r.jsx("svg",{className:"w-4 h-4 ml-auto text-fg-tertiary shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),c&&k&&r.jsx("div",{ref:b,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style: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 vb=[{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 vo({value:e,onChange:t}){const{t:n}=He("work");return r.jsx("div",{className:"flex flex-wrap gap-2",children:vb.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 sf({kind:e,entity:t,agents:n,users:s,projects:o,onClose:a}){const i=t.title?.trim()||t.id,l=Xf(i),c=t.projectId?o.find(u=>u.id===t.projectId)?.name??t.projectId:"",d=`${e==="requirement"?"📋":"✅"} ${l}`,f=[`@[${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($c,{chipKind:e,chipLabel:d,chipContent:f,agents:n,users:s,defaultTarget:Bc(t.createdBy,n,s),onClose:a})}function jb({options:e,selected:t,onAdd:n,placeholder:s,noMatchesText:o,className:a}){const[i,l]=p.useState(!1),[c,d]=p.useState(""),f=p.useRef(null),u=p.useRef(null),h=p.useRef(null),m=p.useRef(null),g=gi(u,i);p.useEffect(()=>{const v=y=>{f.current&&!f.current.contains(y.target)&&m.current&&!m.current.contains(y.target)&&l(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]);const b=e.filter(v=>!t.includes(v.value)),k=c?b.filter(v=>v.label.toLowerCase().includes(c.toLowerCase())):b;return r.jsxs("div",{ref:f,className:a??"",children:[r.jsxs("div",{ref:u,onClick:()=>{l(!i),d(""),setTimeout(()=>h.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:h,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 Nb({options:e,onSelect:t,placeholder:n,noMatchesText:s,className:o,itemSuffix:a}){const[i,l]=p.useState(!1),[c,d]=p.useState(""),f=p.useRef(null),u=p.useRef(null),h=p.useRef(null),m=p.useRef(null),g=gi(u,i);p.useEffect(()=>{const k=v=>{f.current&&!f.current.contains(v.target)&&m.current&&!m.current.contains(v.target)&&l(!1)};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[]);const b=c?e.filter(k=>k.label.toLowerCase().includes(c.toLowerCase())):e;return r.jsxs("div",{ref:f,className:o??"",children:[r.jsxs("div",{ref:u,onClick:()=>{l(!i),d(""),setTimeout(()=>h.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:h,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:b.length===0?r.jsx("div",{className:"px-3 py-2 text-xs text-fg-tertiary",children:s??"No matches"}):b.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 Os(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 Sb({value:e,onSave:t,className:n,placeholder:s}){const{t:o}=He(["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 f=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:()=>{f()},onKeyDown:u=>{u.key==="Enter"&&f(),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 Cb({value:e,onSave:t,className:n,placeholder:s}){const{t:o}=He(["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 f=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:()=>{f()},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 Eb=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function rf(e){const t=e.match(Eb);return t?{timestamp:t[1].trim(),author:t[2]?.trim()??"System",content:t[3].trim()}:{timestamp:"",author:"",content:e}}function Ib(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),f=s.getTime()-d.getTime();return f<6e4?t("work:relative.justNow"):f<36e5?t("work:relative.minutesAgo",{count:Math.floor(f/6e4)}):f<864e5?t("work:relative.hoursAgo",{count:Math.floor(f/36e5)}):f<6048e5?t("work:relative.daysAgo",{count:Math.floor(f/864e5)}):`${o}-${String(a+1).padStart(2,"0")}-${String(i).padStart(2,"0")}`}const wc=[{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 wc[Math.abs(t)%wc.length]}function Mb({note:e,compact:t}){const{t:n}=He(["work","common"]),s=rf(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=Ib(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(or,{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(or,{content:s.content,className:"text-xs text-fg-secondary"})})]})})]})}const Ab=new Set(["rejected","cancelled","archived"]),jo=[{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"}],kc={pending:Gn.neutral.chip,blocked:Gn.blocked.chip,failed:Gn.danger.chip,rejected:Gn.danger.chip},vc=Object.fromEntries(["pending","in_progress","blocked","review","revision","completed","failed","rejected","cancelled","archived"].map(e=>[e,Gn[Gf(e)].chip])),jc={low:"bg-gray-500/15 text-fg-tertiary",medium:"bg-surface-overlay text-fg-secondary",high:"bg-surface-overlay text-fg-secondary font-semibold",urgent:Gn.danger.chip},Nc=Object.fromEntries(["pending","in_progress","completed","rejected","cancelled","archived"].map(e=>[e,Gn[Uf(e)].chip]));function of(e){return Object.keys(vc).reduce((t,n)=>(t[n]={label:e(`work:status.task.${n}`),cls:vc[n]},t),{})}function af(e){return Object.keys(kc).reduce((t,n)=>(t[n]={label:e(`work:status.sub.${n}`),cls:kc[n]},t),{})}function Lb(e){return Object.keys(jc).reduce((t,n)=>(t[n]={label:e(`work:priority.${n}`),cls:jc[n]},t),{})}function xi(e){return Object.keys(Nc).reduce((t,n)=>(t[n]={label:e(`work:status.requirement.${n}`),cls:Nc[n]},t),{})}const Sc=["low","medium","high","urgent"],Cc=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],Ec=["pending","in_progress","blocked","completed","rejected","cancelled"],Qn={idle:"bg-green-400",working:"bg-blue-400",error:"bg-red-400",paused:"bg-amber-400",offline:"bg-gray-600",pending:"bg-amber-400",in_progress:"bg-brand-400",blocked:"bg-amber-400",review:"bg-brand-400",completed:"bg-green-400",failed:"bg-red-400",rejected:"bg-red-400",cancelled:"bg-gray-600",archived:"bg-surface-overlay"},Ic={idle:"text-green-500",working:"text-blue-500",error:"text-red-500",paused:"text-amber-500",offline:"text-fg-muted"};function _b({agent:e,anchorRect:t,onClose:n}){const{t:s}=He(["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(tt.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 qo({comment:e,agents:t,onReply:n}){const{t:s}=He(["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),[f,u]=p.useState(!1),[h,m]=p.useState([]),[g,b]=p.useState(!1),k=p.useCallback((C,j)=>{const E=t.find(S=>S.name.toLowerCase()===C.toLowerCase());if(E){const S=j.target.getBoundingClientRect();d({agent:E,top:S.bottom,left:S.left})}},[t]),v=p.useMemo(()=>t.map(C=>C.name),[t]),y=p.useCallback(C=>{const j=t.find(E=>E.name.toLowerCase()===e.authorName.toLowerCase());if(j){const E=C.currentTarget.getBoundingClientRect();d({agent:j,top:E.bottom,left:E.left})}},[t,e.authorName]),x=p.useCallback(async()=>{if(f){u(!1);return}const C=e.activityId;if(C&&(u(!0),!(h.length>0))){b(!0);try{const{logs:j}=await te.agents.getActivityLogs(e.authorId,C),E=j.map(S=>Oa(S,C,e.authorId)).filter(S=>S!==null).map(S=>({...S,ts:new Date(S.createdAt).getTime()}));m(E)}catch{}b(!1)}},[f,h.length,e]),w=p.useMemo(()=>Jf(h.map(eh).filter(C=>C!==null)),[h]);return r.jsxs("div",{className:"flex gap-2.5 group py-1",id:`comment-${e.id}`,children:[r.jsx("div",{onClick:y,className:`flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center text-[10px] mt-0.5 cursor-pointer transition-all hover:ring-1 hover:ring-brand-500/40 ${o?"bg-indigo-500/20 text-indigo-400":"bg-blue-500/20 text-blue-400"}`,children:e.authorName.slice(0,2).toUpperCase()}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-baseline gap-1.5 mb-0.5",children:[r.jsx("span",{className:`text-[11px] font-medium cursor-pointer hover:underline ${o?"text-indigo-400":"text-blue-400"}`,onClick:y,children:e.authorName}),r.jsxs("span",{className:"text-fg-tertiary text-[10px]",children:[l," ",i]}),n&&r.jsx("button",{onClick:()=>n(e),className:"text-fg-tertiary hover:text-fg-secondary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:s("work:task.reply")}),e.activityId&&o&&r.jsx("button",{onClick:x,className:"text-fg-tertiary hover:text-brand-400 text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:s(f?"work:task.hideLog":"work:task.viewLog")})]}),e.replyTo&&e.replyToAuthor&&r.jsxs("button",{onClick:()=>{const C=document.getElementById(`comment-${e.replyTo}`);C&&(C.scrollIntoView({behavior:"smooth",block:"center"}),C.classList.add("bg-brand-500/10"),setTimeout(()=>C.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(or,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:k,knownNames:v}),e.attachments?.map((C,j)=>C.type==="image"?r.jsx("img",{src:C.url,alt:C.name,className:"mt-1 max-w-[200px] rounded"},j):null),f&&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(Fc,{entries:h,isActive:!1,onCollapse:()=>u(!1),embedded:!0})})]}),c&&r.jsx(_b,{agent:c.agent,anchorRect:{top:c.top,left:c.left},onClose:()=>d(null)})]})}function Rb({task:e,agents:t,users:n,authUser:s}){const{t:o}=He(["work","common"]),[a,i]=p.useState([]),[l,c]=p.useState([]),d=p.useRef(null),[f,u]=p.useState(new Map);p.useEffect(()=>{c([]),u(new Map),d.current&&(clearTimeout(d.current),d.current=null),te.tasks.getComments(e.id).then(v=>i(v.comments)).catch(()=>{})},[e.id]),p.useEffect(()=>$t.on("task:comment",y=>{if(y.payload?.taskId===e.id&&y.payload.comment){const x=y.payload.comment;i(w=>w.some(C=>C.id===x.id)?w:[...w,x]),(x.authorType==="agent"||x.authorId?.startsWith("agt_"))&&(c(w=>{const C=w.filter(j=>j.id!==x.authorId);return C.length===0&&d.current&&(clearTimeout(d.current),d.current=null),C}),u(w=>{const C=new Map(w);return C.delete(x.authorId),C}))}}),[e.id]),p.useEffect(()=>{if(l.length===0)return;const v=new Set(l.map(x=>x.id));return $t.on("agent:activity_log",x=>{const w=x.payload;if(!w)return;const C=w.agentId;if(!v.has(C))return;const j=ko(w);j&&u(E=>mi(E,C,j))})},[l]);const h=p.useMemo(()=>{const v=[];for(const y of e.notes??[]){const x=rf(y);let w;if(x.timestamp){const C=x.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);w=C?new Date(+C[1],+C[2]-1,+C[3],+C[4],+C[5],+(C[6]??0)):new Date(0)}else w=new Date(0);v.push({type:"note",note:y,ts:w})}for(const y of a)v.push({type:"comment",comment:y,ts:new Date(y.createdAt)});return v.sort((y,x)=>y.ts.getTime()-x.ts.getTime()),v},[e.notes,a]),[m,g]=p.useState(null),b=async(v,y,x,w)=>{let C;x.length>0&&(C=(await te.uploads.upload(x.map(R=>({dataUrl:R.dataUrl,name:R.name})),"comments")).files.map(R=>({type:"image",url:R.url,name:R.name})));const j=await te.tasks.addComment(e.id,v,s?.name,C,s?.id,y.length>0?y:void 0,w),E=Ga(j.notifiedAgentIds,t);E.length>0&&(d.current&&clearTimeout(d.current),c(E),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:[h.length===0&&r.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:o("work:task.noActivityYet")}),h.map((v,y)=>v.type==="note"?r.jsx(Mb,{note:v.note,compact:!0},`n-${y}`):r.jsx(qo,{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 y=f.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(tt.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(Da,{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}),y.length===0&&r.jsxs("span",{className:"flex items-center gap-0.5",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o("work:task.agentProcessing")}),r.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),y.length>0&&r.jsx("div",{className:"ml-8 mt-1",children:r.jsx(pi,{entries:y})})]},v.id)})})]}),r.jsx(zc,{agents:t,humans:n,onSubmit:b,replyTo:m,onCancelReply:()=>g(null),placeholder:o("work:task.commentPlaceholder")})]})}function ga({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(qo,{comment:i.comment,agents:n},i.key):r.jsx(nh,{entries:i.entries,isStreaming:s},i.key))})}function Db({task:e,isRunning:t,authUser:n,agents:s,reviewSessions:o=[]}){const a=e.id,{t:i}=He(["work","common"]),[l,c]=p.useState([]),[d,f]=p.useState(new Map),[u,h]=p.useState(new Set),[m,g]=p.useState([]),[b,k]=p.useState(""),[v,y]=p.useState(t),[x,w]=p.useState(!0),[C,j]=p.useState(new Set),[E,S]=p.useState(""),[R,$]=p.useState(!1),[M,D]=p.useState([]),z=p.useRef(null),[I,P]=p.useState(new Map),[L,B]=p.useState([]),[_,q]=p.useState([]),[H,K]=p.useState(!1),O=p.useRef(null),U=p.useRef(null),[A,T]=p.useState(new Map),[V,W]=p.useState(new Set),[F,Z]=p.useState(new Set),se=p.useCallback(async re=>{W(fe=>new Set(fe).add(re.id));try{const{activities:fe}=await te.agents.getActivities(re.reviewerId,{limit:200}),xe=Ch(fe,{taskId:a,queuedAt:re.queuedAt,completedAt:re.completedAt}),J=[];for(const ne of xe){const{logs:ae}=await te.agents.getActivityLogs(re.reviewerId,ne.id);for(const ke of ae){const ge=Oa(ke,ne.id,re.reviewerId);ge&&J.push(ge)}}T(ne=>new Map(ne).set(re.id,J))}catch{T(fe=>new Map(fe).set(re.id,[]))}finally{W(fe=>{const xe=new Set(fe);return xe.delete(re.id),xe})}},[a]),ue=re=>{Z(fe=>{const xe=new Set(fe);return xe.has(re.id)?(xe.delete(re.id),xe):(xe.add(re.id),xe)}),!A.has(re.id)&&!V.has(re.id)&&se(re)},ie=p.useMemo(()=>jh(l,o,"all").map(re=>{if(re.kind==="review")return{kind:"review",session:re.session};const fe=l.findIndex(xe=>xe.round===re.round);return{kind:"execution",rs:l[fe],rsIdx:fe}}),[l,o]);p.useEffect(()=>{const re=o.filter(xe=>xe.status==="reviewing"&&F.has(xe.id));return re.length===0?void 0:$t.on("agent:activity_log",xe=>{const J=xe.payload;if(!J)return;const ne=J.agentId;if(!ne)return;const ae=ko(J);if(ae)for(const ke of re)ke.reviewerId===ne&&Xc(ae.createdAt,{queuedAt:ke.queuedAt,completedAt:ke.completedAt})&&T(ge=>{const ve=ge.get(ke.id)??[];if(ve.some(nt=>nt.sourceId===ae.sourceId&&nt.seq===ae.seq))return ge;const Me=new Map(ge);return Me.set(ke.id,[...ve,ae]),Me})})},[o,F,a]),p.useEffect(()=>{y(t)},[t]),p.useEffect(()=>{D([]),P(new Map),z.current&&(clearTimeout(z.current),z.current=null)},[a]),p.useEffect(()=>{w(!0),Promise.all([te.tasks.getLogsSummary(a).catch(()=>({rounds:[]})),te.tasks.getComments(a).catch(()=>({comments:[]}))]).then(([re,fe])=>{const xe=re.rounds;if(c(xe),g(fe.comments),xe.length===0){w(!1);return}const J=xe[xe.length-1].round;j(new Set([J])),te.tasks.getLogs(a,J).catch(()=>({logs:[]})).then(ne=>{f(new Map([[J,ne.logs]])),w(!1)})})},[a]),p.useEffect(()=>{const re=e.assignedAgentId;re&&(K(!0),te.agents.getActivities(re,{taskId:a,limit:20}).then(fe=>q(fe.activities)).catch(()=>q([])).finally(()=>K(!1)))},[a,e.assignedAgentId]);const pe=p.useCallback(re=>{d.has(re)||u.has(re)||(h(fe=>new Set(fe).add(re)),te.tasks.getLogs(a,re).catch(()=>({logs:[]})).then(fe=>{f(xe=>new Map(xe).set(re,fe.logs)),h(xe=>{const J=new Set(xe);return J.delete(re),J})}))},[a,d,u]),je=p.useCallback(re=>{j(fe=>{const xe=new Set(fe);return xe.has(re)?xe.delete(re):(xe.add(re),d.has(re)||pe(re)),xe})},[d,pe]);p.useEffect(()=>{const re=$t.on("task:log",J=>{const ne=J.payload;if(ne.taskId!==a)return;const ae={id:ne.id,taskId:ne.taskId,agentId:ne.agentId,seq:ne.seq,type:ne.logType,content:ne.content,metadata:ne.metadata,executionRound:ne.executionRound,createdAt:ne.createdAt},ke=ae.executionRound??1;c(ge=>ge.find(Me=>Me.round===ke)?ge:[...ge,{round:ke,logCount:0,toolCount:0,firstAt:ae.createdAt,lastAt:ae.createdAt,status:"running"}]),j(ge=>ge.has(ke)?ge:new Set(ge).add(ke)),f(ge=>{const ve=ge.get(ke)??[];return ae.id&&ve.some(Me=>Me.id===ae.id)?ge:new Map(ge).set(ke,[...ve,ae])}),ae.type==="text"&&k(""),ae.type==="status"&&(ae.content==="started"||ae.content==="resumed"?y(!0):["completed","failed","cancelled","execution_finished"].includes(ae.content)&&(y(!1),c(ge=>ge.map(ve=>ve.round===ke?{...ve,status:ae.content}:ve)))),ae.type==="error"&&y(!1)}),fe=$t.on("task:log:delta",J=>{const ne=J.payload;ne.taskId===a&&k(ae=>ae+ne.text)}),xe=$t.on("task:comment",J=>{const ne=J.payload;if(ne.taskId!==a)return;const ae=ne.comment;g(ke=>ke.some(ge=>ge.id===ae.id)?ke:[...ke,ae]),(ae.authorType==="agent"||ae.authorId?.startsWith("agt_"))&&(D(ke=>{const ge=ke.filter(ve=>ve.id!==ae.authorId);return ge.length===0&&z.current&&(clearTimeout(z.current),z.current=null),ge}),P(ke=>{const ge=new Map(ke);return ge.delete(ae.authorId),ge}))});return()=>{re(),fe(),xe()}},[a]),p.useEffect(()=>{if(M.length===0)return;const re=new Set(M.map(xe=>xe.id));return $t.on("agent:activity_log",xe=>{const J=xe.payload;if(!J)return;const ne=J.agentId;if(!re.has(ne))return;const ae=ko(J);ae&&P(ke=>mi(ke,ne,ae))})},[M]);const Se=p.useMemo(()=>{const re=[];for(const[,fe]of d)re.push(...fe);return re.sort((fe,xe)=>fe.seq-xe.seq),re},[d]),Ne=p.useMemo(()=>Se.map(re=>Zi(re)),[Se]),Be=l.length>1||o.length>0,$e=re=>{const fe=re.target.files;if(fe){for(const xe of Array.from(fe)){if(!xe.type.startsWith("image/"))continue;const J=new FileReader;J.onload=()=>{B(ne=>[...ne,{type:"image",url:J.result,name:xe.name}])},J.readAsDataURL(xe)}re.target.value=""}},Ie=async()=>{if(!(!E.trim()&&L.length===0)){$(!0);try{let re;L.length>0&&(re=(await te.uploads.upload(L.map(ne=>({dataUrl:ne.url,name:ne.name})),"comments")).files.map(ne=>({type:"image",url:ne.url,name:ne.name})));const fe=await te.tasks.addComment(a,E,n?.name,re,n?.id);fe.comment&&g(J=>J.some(ne=>ne.id===fe.comment.id)?J:[...J,fe.comment]),S(""),B([]);const xe=Ga(fe.notifiedAgentIds,s);xe.length>0&&(z.current&&clearTimeout(z.current),D(xe),z.current=setTimeout(()=>D([]),12e4))}catch{}$(!1)}},Ve=r.jsxs("div",{className:"border-t border-border-default px-4 py-3 sticky bottom-0 bg-surface-primary z-10",children:[L.length>0&&r.jsx("div",{className:"flex gap-2 mb-2 flex-wrap",children:L.map((re,fe)=>r.jsxs("div",{className:"relative group",children:[r.jsx("img",{src:re.url,alt:re.name,className:"w-16 h-16 object-cover rounded-lg border border-border-default"}),r.jsx("button",{onClick:()=>B(xe=>xe.filter((J,ne)=>ne!==fe)),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:"×"})]},fe))}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"text",value:E,onChange:re=>S(re.target.value),onKeyDown:re=>{re.key==="Enter"&&!re.shiftKey&&(re.preventDefault(),Ie())},placeholder:i("work:task.commentInstructionPlaceholder"),className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-blue-500 outline-none text-fg-primary placeholder-gray-600"}),r.jsx("input",{type:"file",ref:O,accept:"image/*",multiple:!0,onChange:$e,className:"hidden"}),r.jsx("button",{onClick:()=>O.current?.click(),className:"px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-fg-secondary hover:text-fg-primary text-sm",title:i("work:task.attachImage"),children:"📎"}),r.jsx("button",{onClick:()=>{Ie()},disabled:R||!E.trim()&&L.length===0,className:"px-3 py-1.5 bg-blue-600 hover:bg-blue-500 rounded-lg text-white text-xs disabled:opacity-50",children:i("common:send")})]})]});if(x)return r.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-fg-tertiary",children:i("work:task.loadingLogs")});if(l.length===0&&!b){const re=e.assignedAgentId?s.find(Me=>Me.id===e.assignedAgentId):void 0,fe=_.length>0,xe=re&&re.currentTaskId&&re.currentTaskId!==e.id,J=e.status==="pending",ne=e.status==="in_progress",ae=!e.assignedAgentId;let ke="📋",ge=i("work:task.emptyLogs.default"),ve=i("work:task.emptyLogs.defaultHint");return ae?(ke="👤",ge=i("work:task.emptyLogs.noAgent"),ve=i("work:task.emptyLogs.noAgentHint")):J?(ke="⏳",ge=i("work:task.emptyLogs.pending"),ve=i("work:task.emptyLogs.pendingHint")):ne&&xe?(ke="🔄",ge=i("work:task.emptyLogs.agentBusy",{agent:re?.name??e.assignedAgentId}),ve=i("work:task.emptyLogs.agentBusyHint")):ne&&(ke="⏳",ge=i("work:task.emptyLogs.starting"),ve=i("work:task.emptyLogs.startingHint")),r.jsxs("div",{className:"flex flex-col min-h-full",children:[r.jsx("div",{className:"flex-1 overflow-y-auto",children:H?r.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-fg-tertiary",children:i("work:task.loadingLogs")}):fe?r.jsxs("div",{className:"px-4 py-4",children:[r.jsxs("div",{className:"text-xs text-fg-secondary mb-3 flex items-center gap-1.5",children:[r.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-blue-500"}),i("work:task.relatedSessions",{agent:re?.name??i("work:task.agent"),count:_.length})]}),r.jsx("div",{className:"space-y-1.5",children:_.map(Me=>{const nt=!Me.endedAt,Pe=Me.type==="task"?"🔧":Me.type==="chat"||Me.type==="respond_in_session"?"💬":Me.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(tt.TEAM,{agentId:e.assignedAgentId}),children:[r.jsx("span",{className:"text-sm shrink-0",children:Pe}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"text-xs text-fg-primary truncate",children:Me.label}),r.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[new Date(Me.startedAt).toLocaleString(),Me.endedAt?` — ${Me.totalTools} tools, ${Me.totalTokens.toLocaleString()} tokens`:""]})]}),nt&&r.jsxs("span",{className:"shrink-0 flex items-center gap-1 text-[10px] text-green-500 font-medium",children:[r.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 animate-pulse"}),i("work:task.sessionLive")]}),!nt&&r.jsx("span",{className:`shrink-0 text-[10px] ${Me.success?"text-fg-tertiary":"text-red-400"}`,children:Me.success?"✓":"✗"}),r.jsx("span",{className:"shrink-0 text-fg-tertiary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity",children:"→"})]},Me.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:ke}),r.jsxs("div",{className:"text-xs",children:[ge,r.jsx("br",{}),r.jsx("span",{className:"text-fg-muted",children:ve})]})]})})}),Ve]})}if(!Be)return r.jsxs("div",{className:"flex flex-col min-h-full",children:[r.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[r.jsx(ga,{entries:Ne,comments:m,agents:s,isExecuting:v}),v&&b&&r.jsx(Qi,{content:b}),v&&!b&&Ne.length>0&&r.jsx(Ji,{})]}),Ve]});const ct=(re,fe)=>{const xe=re.firstAt?new Date(re.firstAt).getTime():0,J=fe?.firstAt?new Date(fe.firstAt).getTime():1/0;return m.filter(ne=>{const ae=new Date(ne.createdAt).getTime();return ae>=xe&&ae<J})},Oe=l.length>0?m.filter(re=>new Date(re.createdAt).getTime()<new Date(l[0].firstAt).getTime()):[];return r.jsxs("div",{className:"flex flex-col min-h-full",children:[r.jsx("div",{ref:U}),r.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[Oe.length>0&&r.jsx("div",{className:"space-y-0.5",children:Oe.map(re=>r.jsx(qo,{comment:re,agents:s},re.id))}),ie.map(re=>{if(re.kind==="review"){const Pe=re.session,ee=F.has(Pe.id),Re=Pe.status==="reviewing",We=A.get(Pe.id),ht=V.has(Pe.id),Je=Re?"🔄":Pe.outcome==="approved"?"✅":Pe.outcome==="revision_requested"?"↩️":"⏹";return r.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[r.jsxs("button",{onClick:()=>ue(Pe),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:Je}),r.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:i("work:task.reviewRoundLabel",{round:Pe.round})}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:Pe.reviewerName}),Re&&r.jsx("span",{className:"text-[10px] text-purple-400",children:i("work:task.reviewLive")})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:new Date(Pe.queuedAt).toLocaleString()}),r.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${ee?"rotate-180":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:r.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})]})]}),ee&&r.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[Pe.note&&r.jsx("p",{className:"whitespace-pre-wrap break-words text-[11px] leading-relaxed text-fg-secondary",children:Pe.note}),ht&&r.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:i("work:task.reviewLoading")}),We&&We.length>0&&r.jsx(ga,{entries:We,comments:[],agents:s,isExecuting:!1}),We&&We.length===0&&r.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:i("work:task.reviewNoTurns")})]})]},Pe.id)}const fe=re.rs,xe=re.rsIdx,J=C.has(fe.round),ne=fe.round===l[l.length-1].round,ae=d.get(fe.round),ke=u.has(fe.round),ge=ct(fe,l[xe+1]),ve=fe.status==="completed"||fe.status==="execution_finished"?"✅":fe.status==="failed"?"❌":fe.status==="cancelled"?"⏹":"🔄",Me=fe.lastAt&&fe.firstAt?Math.max(0,new Date(fe.lastAt).getTime()-new Date(fe.firstAt).getTime()):0,nt=Me>=6e4?`${Math.floor(Me/6e4)}m ${Math.floor(Me%6e4/1e3)}s`:Me>=1e3?`${Math.floor(Me/1e3)}s`:"";return r.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[r.jsxs("button",{onClick:()=>je(fe.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:i("work:task.roundHeader",{n:fe.round})}),ge.length>0&&r.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",ge.length]}),ne&&v&&r.jsxs("svg",{className:"w-3 h-3 animate-spin text-brand-500",viewBox:"0 0 24 24",fill:"none",children:[r.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),r.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("work:task.toolCount",{count:fe.toolCount})}),nt&&r.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:nt}),r.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${J?"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"})})]})]}),J&&r.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[ke&&r.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:i("work:task.loadingRound",{n:fe.round})}),ae&&r.jsx(ga,{entries:ae.map(Pe=>Zi(Pe)),comments:ge,agents:s,isExecuting:ne&&v}),ne&&v&&b&&r.jsx(Qi,{content:b}),ne&&v&&!b&&!ke&&r.jsx(Ji,{})]})]},fe.round)}),M.length>0&&r.jsx("div",{className:"flex flex-col gap-1.5 mt-2",children:M.map(re=>{const fe=I.get(re.id)??[];return r.jsxs("div",{className:"px-3 py-2 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>en.navigate(tt.TEAM,{agentId:re.id,profileTab:"mind"}),children:[r.jsxs("div",{className:"flex items-center gap-2.5",children:[r.jsxs("div",{className:"relative shrink-0",children:[r.jsx(Da,{name:re.name,avatarUrl:re.avatarUrl,size:24,bgClass:"bg-brand-500/15 text-brand-600"}),r.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500 animate-pulse ring-2 ring-surface-primary"})]}),r.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[r.jsx("span",{className:"text-xs font-medium text-fg-secondary truncate",children:re.name}),fe.length===0&&r.jsxs("span",{className:"flex items-center gap-0.5",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:i("work:task.agentProcessing")})]}),r.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),fe.length>0&&r.jsx("div",{className:"ml-9 mt-1",children:r.jsx(pi,{entries:fe})})]},re.id)})})]}),Ve]})}const Tc=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 so(e){return e==null?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Ob({filePath:e,onClose:t,onOpenExternal:n}){const{t:s}=He(["work","common"]),[o,a]=p.useState([e]),i=o[o.length-1],[l,c]=p.useState(null),[d,f]=p.useState(null),[u,h]=p.useState(!0),[m,g]=p.useState(!1);p.useEffect(()=>{h(!0),f(null),c(null),te.files.preview(i).then(S=>c(S)).catch(S=>f(String(S))).finally(()=>h(!1))},[i]);const b=S=>a(R=>[...R,S]),k=()=>a(S=>S.length>1?S.slice(0,-1):S),v=o.length>1,y=S=>{te.files.reveal(S).catch(()=>{})},x=()=>{navigator.clipboard?.writeText(i).then(()=>{g(!0),setTimeout(()=>g(!1),1500)}).catch(()=>{})},w=S=>{S.isDirectory||Tc.has(S.ext)?b(S.path):y(S.path)},C=i.split("/").pop()??i,j=l?.type==="directory",E=(S,R)=>{if(R)return"📁";const $=[".md",".markdown"],M=[".png",".jpg",".jpeg",".gif",".webp",".svg"];return $.includes(S)?"📝":M.includes(S)?"🖼":[".json",".yaml",".yml",".toml",".xml"].includes(S)?"⚙":[".js",".ts",".jsx",".tsx",".py",".sh"].includes(S)?"💻":"📄"};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:S=>S.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:C}),j&&l.entries&&r.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:["(",l.entries.length,")"]})]}),r.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-3",children:[r.jsx("button",{onClick:x,className:"text-fg-tertiary hover:text-fg-primary px-2 py-1.5 rounded hover:bg-surface-elevated/60 transition-colors text-xs",title:s("common:copyPath",{defaultValue:"复制路径"}),children:m?`${s("common:copied",{defaultValue:"已复制"})} ✓`:s("common:copyPath",{defaultValue:"复制路径"})}),r.jsx("button",{onClick:()=>n?n():y(i),className:"text-fg-tertiary hover:text-fg-primary p-1.5 rounded hover:bg-surface-elevated/60 transition-colors",title:s(n?"work:task.openInDeliverables":"work:task.openInFinder"),children:r.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"}),r.jsx("polyline",{points:"15 3 21 3 21 9"}),r.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}),r.jsx("button",{onClick:t,className:"text-fg-tertiary hover:text-fg-secondary text-lg shrink-0",children:"×"})]})]}),r.jsx("div",{className:"px-4 py-1 border-b border-border-default/60",children:r.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:i})}),r.jsxs("div",{className:"flex-1 overflow-auto min-h-0",children:[u&&r.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:s("work:task.filePreviewLoading")}),d&&r.jsx("div",{className:"text-sm text-red-500 text-center py-8",children:d}),l?.type==="directory"&&l.entries&&r.jsxs("div",{className:"divide-y divide-border-default/50",children:[l.entries.length===0&&r.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:s("work:task.emptyDirectory")}),l.entries.map(S=>r.jsxs("button",{onClick:()=>w(S),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(S.ext,S.isDirectory)}),r.jsx("span",{className:"flex-1 min-w-0 truncate text-sm text-fg-primary group-hover:text-brand-400 transition-colors",children:S.name}),!S.isDirectory&&S.size!=null&&r.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:so(S.size)}),S.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"})}),!S.isDirectory&&!Tc.has(S.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"})]})]},S.path))]}),l&&l.type!=="directory"&&r.jsx("div",{className:"p-5",children:l.type==="office"&&l.streamUrl?r.jsx(Yf,{data:{format:(l.extension||"").replace(/^\./,"")||"pdf",streamUrl:l.streamUrl||(l.path?te.files.streamUrl(l.path):te.files.streamUrl(i)),name:l.name,size:l.size},reference:l.path||i,onFallback:()=>y(i)}):l.type==="image"&&l.content?r.jsx("div",{className:"flex justify-center",children:r.jsx("img",{src:`data:${l.mimeType};base64,${l.content}`,alt:l.name,className:"max-w-full max-h-[60vh] rounded-lg"})}):l.type==="audio"?r.jsxs("div",{className:"flex flex-col gap-3",children:[r.jsx("audio",{controls:!0,preload:"metadata",src:l.streamUrl||(l.path?te.files.streamUrl(l.path):te.files.streamUrl(i)),className:"w-full"}),r.jsxs("span",{className:"text-xs text-fg-tertiary",children:[l.name,l.size!=null?` · ${so(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?te.files.streamUrl(l.path):te.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?` · ${so(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?` · ${so(l.size)}`:""]}),r.jsx("button",{onClick:()=>y(i),className:"px-3 py-2 text-xs rounded-lg bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors",children:s("work:task.openInFinder")})]}):r.jsx(sh,{content:l.content,format:l.type==="text"?"text":l.type,className:"text-sm text-fg-secondary leading-relaxed",copyVariant:"preview"})})]})]})})}function Mc({task:e,agents:t,projects:n,requirements:s,allTasks:o,users:a,onClose:i,onRefresh:l,authUser:c,scrollToComments:d,onScrollToCommentsDone:f,onReqClick:u,onProjectClick:h}){const{t:m}=He(["work","common"]),g=p.useMemo(()=>of(m),[m]),[b,k]=p.useState([]),[v,y]=p.useState(""),[x,w]=p.useState(!1),[C,j]=p.useState(!1),[E,S]=p.useState(null),[R,$]=p.useState(null),[M,D]=p.useState(!1),[z,I]=p.useState(!1),[P,L]=p.useState(!1),[B,_]=p.useState(null),[q,H]=p.useState(!1),[K,O]=p.useState(!1),[U,A]=p.useState("details"),T=p.useRef(null),[V,W]=p.useState("none"),[F,Z]=p.useState(1),[se,ue]=p.useState([]),ie=p.useCallback(async()=>{try{const{results:Y}=await te.deliverables.search({taskId:e.id,limit:200});ue(Y.filter(me=>me.status!=="outdated"))}catch{}},[e.id]),pe=p.useCallback(Y=>{A(Y),Y==="deliverables"&&ie(),requestAnimationFrame(()=>{T.current?.scrollTo({top:0,behavior:"instant"})})},[ie]),je=p.useMemo(()=>[{id:"details"},{id:"activity"},{id:"deliverables"},{id:"history"}],[]),Se=Hf(je,U,pe),[Ne,Be]=p.useState([]);p.useEffect(()=>{let Y=!0;return te.tasks.getHistory(e.id).then(me=>{Y&&Be(wh(me.history,{reviewerId:e.reviewerId,reviewerName:t.find(ze=>ze.id===e.reviewerId)?.name}))}).catch(()=>{Y&&Be([])}),()=>{Y=!1}},[e.id,e.status,e.reviewerId,t]),p.useEffect(()=>{const Y=T.current;if(!Y)return;const me=()=>{const{scrollTop:Fe,scrollHeight:_e,clientHeight:St}=Y;if(!(_e>St+50)){W("none");return}const ss=Fe<30,kn=Fe+St>=_e-30;W(ss?"top":kn?"bottom":"middle")};me(),Y.addEventListener("scroll",me,{passive:!0});const ze=new ResizeObserver(me);return ze.observe(Y),()=>{Y.removeEventListener("scroll",me),ze.disconnect()}},[U]),p.useEffect(()=>{if(!d)return;A("details");const Y=setTimeout(()=>{const me=T.current;me&&me.scrollTo({top:me.scrollHeight,behavior:"smooth"}),f?.()},300);return()=>clearTimeout(Y)},[d,f]);const[$e,Ie]=p.useState(null),[Ve,ct]=p.useState(!1),[Oe,re]=p.useState(null),[fe,xe]=p.useState(!1),[J,ne]=p.useState(e.description),ae=p.useRef(null),ke=p.useRef(null),ge=p.useRef(80);p.useEffect(()=>{if(fe&&ke.current){const Y=ke.current;Y.style.height="auto",Y.style.height=Math.max(Y.scrollHeight,ge.current)+"px",Y.focus()}},[fe]);const[ve,Me]=p.useState(!1),[nt,Pe]=p.useState("");p.useEffect(()=>{ie()},[ie,e.updatedAt]),p.useEffect(()=>{const Y=["created","updated","removed"].map(me=>$t.on(`deliverable:${me}`,ze=>{const Fe=ze.payload;!Fe||Fe.taskId!==e.id||ie()}));return()=>{Y.forEach(me=>me())}},[e.id,ie]);const[ee,Re]=p.useState(!1),We=pr(),ht=20,Je=p.useCallback(async()=>{try{const Y=await te.tasks.listSubtasks(e.id);k(Y.subtasks)}catch{}},[e.id]);p.useEffect(()=>{Je()},[Je,e.updatedAt]);const qe=async Y=>{if(!q){H(!0);try{await Y(),l(),await Je()}catch(me){Ie(String(me).replace("Error: ",""))}finally{H(!1)}}},Le=Y=>qe(()=>te.tasks.update(e.id,{priority:Y})),Ke=Y=>qe(()=>te.tasks.assign(e.id,Y||null)),kt=Y=>qe(()=>te.tasks.update(e.id,{projectId:Y||null})),X=async()=>{if(!q){H(!0);try{await te.tasks.pause(e.id),l()}finally{H(!1)}}},le=Y=>{if(Y instanceof Oc){if(Y.code==="TASK_BLOCKED"){const me=Y.data?.dependencyTitles??[];return me.length?m("work:task.errorBlockedDeps",{deps:me.join("、")}):m("work:task.errorBlocked")}if(Y.code==="TASK_NOT_BLOCKED")return m("work:task.errorNotBlocked");if(Y.code==="TASK_NOT_RETRYABLE")return m("work:task.errorNotRetryable")}return String(Y).replace("Error: API error: 400","Server error").replace("Error: ","")},ye=async()=>{if(!q){H(!0),Ie(null),pe("activity");try{await te.tasks.resume(e.id),l()}catch(Y){Ie(le(Y))}finally{H(!1)}}},de=async()=>{v.trim()&&(await te.tasks.createSubtask(e.id,v.trim()),y(""),w(!1),Je(),l())},be=async Y=>{Y.status==="completed"||Y.status==="cancelled"?await te.tasks.cancelSubtask(e.id,Y.id):await te.tasks.completeSubtask(e.id,Y.id),Je(),l()},Ce=async Y=>{await te.tasks.deleteSubtask(e.id,Y.id),S(null),Je(),l()},Xe=async()=>{if(!q){H(!0),Ie(null);try{await te.tasks.updateStatus(e.id,"in_progress"),l()}catch(Y){Ie(le(Y))}finally{H(!1)}}},Ct=async()=>{if(!q){H(!0),Ie(null),pe("activity");try{await te.tasks.retry(e.id),l()}catch(Y){Ie(le(Y))}finally{H(!1)}}},At=async()=>{if(!q){H(!0),Ie(null),pe("activity");try{await te.tasks.runNow(e.id),l()}catch(Y){Ie(le(Y)),l()}finally{H(!1)}}},Et=p.useRef(l);Et.current=l,p.useEffect(()=>$t.on("task:update",me=>{me.payload.taskId===e.id&&(Je(),ie(),Et.current())}),[e.id,Je,ie]);const Ye=b.filter(Y=>Y.status==="completed").length,ot=b.filter(Y=>Y.status==="cancelled").length,It=Ye+ot,Ht=e.status==="in_progress",wn=e.status==="blocked",sn=wn&&Ra(e,Y=>o.find(me=>me.id===Y)),cn=e.status==="completed",mt=e.status==="failed",Ze=e.status==="rejected",st=e.status==="cancelled",Qe=e.status==="archived",dt=ir(e.status),vt=e.taskType==="scheduled"&&!!e.scheduleConfig,gt=vt&&!!e.scheduleConfig?.paused,Ot=(()=>{const Y=n.find(me=>me.id===e.projectId);return Y&&Y.name!=="default"?Y:void 0})(),Tt=s.find(Y=>Y.id===e.requirementId);return t.find(Y=>Y.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 ${We?"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:[We&&r.jsx("button",{onClick:()=>history.back(),className:"text-fg-secondary hover:text-fg-primary transition-colors p-1 -ml-1 shrink-0",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"15 18 9 12 15 6"})})}),r.jsxs("h3",{className:"flex-1 min-w-0 text-base font-semibold leading-snug text-fg-primary",children:[e.title," ",(()=>{if(e.status==="blocked"){const me=Vf(e.status,m,Wf(e));return r.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle ${me.tone?.chip??"bg-gray-500/15 text-fg-tertiary"}`,children:me.label})}const Y=g[e.status];return Y?r.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle ${Y.cls}`,children:Y.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:Kf(e.status,m)})})(),sn&&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(Pc,{onClick:()=>O(!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:"×"})]})]}),K&&r.jsx(sf,{kind:"task",entity:e,agents:t,users:a,projects:n,onClose:()=>O(!1)}),r.jsxs("div",{className:"flex gap-1 px-6 pt-2 pb-0 shrink-0",children:[r.jsx("button",{onClick:()=>pe("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${U==="details"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:m("work:task.detailsTab")}),r.jsxs("button",{onClick:()=>pe("activity"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${U==="activity"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:[m("work:task.activityTab"),(Ht||vh(Ne))&&r.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),r.jsx("button",{onClick:()=>pe("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${U==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:(()=>{const Y=se.filter(me=>typeof me.reference=="string"&&me.reference.length>0).length;return Y>0?m("work:task.deliverablesCount",{count:Y}):m("work:task.deliverables")})()}),r.jsx("button",{onClick:()=>pe("history"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${U==="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:T,"data-swipe-owner":!0,className:"h-full overflow-y-auto overflow-x-hidden",onTouchStart:Se.onTouchStart,onTouchEnd:Se.onTouchEnd,children:[r.jsxs("div",{className:U==="activity"?"min-w-0 min-h-full":"hidden",children:[$e&&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")})," ",$e]}),r.jsx(Db,{task:e,isRunning:e.status==="in_progress",authUser:c,agents:t,reviewSessions:Ne})]}),r.jsxs("div",{className:U==="details"?"":"hidden",children:[r.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:fe?r.jsx("textarea",{ref:ke,value:J,onChange:Y=>{ne(Y.target.value);const me=Y.target;me.style.height="auto",me.style.height=me.scrollHeight+"px"},onBlur:()=>{J!==e.description&&qe(()=>te.tasks.update(e.id,{description:J})),xe(!1)},onKeyDown:Y=>{Y.key==="Escape"&&(Y.preventDefault(),ne(e.description),xe(!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:ae,className:"group relative cursor-pointer rounded-lg -mx-2 px-2 -my-1 py-1 hover:bg-surface-elevated/50 transition-colors",onClick:Y=>{Y.target.closest("a, button, [data-entity-link]")||(ge.current=Math.max(ae.current?.offsetHeight??80,60),ne(e.description),xe(!0))},role:"button",tabIndex:0,onKeyDown:Y=>Y.key==="Enter"&&(ne(e.description),xe(!0)),children:e.description?r.jsxs("div",{children:[r.jsx("div",{className:We&&!ee?"line-clamp-3":"",children:r.jsx(or,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),We&&e.description.length>150&&r.jsx("button",{onClick:Y=>{Y.stopPropagation(),Re(!ee)},className:"text-[11px] text-brand-500 mt-1 font-medium",children:m(ee?"work:task.collapse":"common:showMore")})]}):r.jsx("p",{className:"text-sm text-fg-tertiary italic",children:m("work:task.noDescription")})})}),(Ot||Tt)&&r.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[Ot&&r.jsxs("span",{className:`flex items-center gap-1 text-[11px] px-2 py-0.5 bg-brand-500/10 text-brand-500 rounded-full ${h?"cursor-pointer hover:bg-brand-500/20 transition-colors":""}`,onClick:h?()=>h(Ot.id):void 0,role:h?"button":void 0,tabIndex:h?0:void 0,onKeyDown:h?Y=>Y.key==="Enter"&&h(Ot.id):void 0,children:[r.jsx("span",{className:"text-[9px] text-brand-500/60",children:m("work:task.projectLabel")}),Ot.name]}),Tt&&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(Tt):void 0,role:u?"button":void 0,tabIndex:u?0:void 0,onKeyDown:u?Y=>Y.key==="Enter"&&u(Tt):void 0,children:[r.jsx("span",{className:"text-[9px] text-brand-500/60",children:m("work:task.requirementLabel")}),Tt.title.length>40?Tt.title.slice(0,40)+"…":Tt.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(Y=>{const me=o.find(Fe=>Fe.id===Y),ze=me&&(me.status==="completed"||me.status==="cancelled");return r.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${ze?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[r.jsx("span",{className:"text-[9px]",children:ze?"✓":"⏳"}),r.jsx("span",{className:`font-mono ${ze?"line-through opacity-60":""}`,children:me?me.title.slice(0,30):Y.slice(-8)}),!dt&&r.jsx("button",{onClick:async()=>{const Fe=(e.blockedBy??[]).filter(_e=>_e!==Y);await te.tasks.update(e.id,{blockedBy:Fe}),l()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:m("work:task.removeDependency"),children:"×"})]},Y)})}):r.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:m("work:task.noDependencies")}),sn&&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")})]}),!dt&&r.jsx(Nb,{options:o.filter(Y=>Y.id!==e.id&&!(e.blockedBy??[]).includes(Y.id)).map(Y=>({value:Y.id,label:Y.title,status:Y.status})),placeholder:m("work:task.addDependency"),noMatchesText:m("work:task.noMatches"),itemSuffix:Y=>Y.status==="completed"||Y.status==="archived"?r.jsx("span",{className:"text-[9px] text-green-600 shrink-0",children:"✓"}):Y.status==="cancelled"?r.jsx("span",{className:"text-[9px] text-fg-tertiary shrink-0",children:"✕"}):null,onSelect:async Y=>{if(!Y)return;const me=[...e.blockedBy??[],Y];await te.tasks.update(e.id,{blockedBy:me}),l()}})]}),r.jsx("div",{className:"px-6 py-4 border-b border-border-default/60",children:r.jsxs("div",{className:uu,children:[r.jsx("label",{className:it,children:m("work:task.projectLabel")}),r.jsx(Ft,{size:"sm",disabled:q,options:[{value:"",label:m("work:task.noProject")},...n.map(Y=>({value:Y.id,label:Y.name}))],value:e.projectId??"",onChange:Y=>{kt(Y)},placeholder:m("work:task.noProject"),noMatchesText:m("work:task.noMatches")}),r.jsx("label",{className:it,children:m("work:task.requirementLabel")}),r.jsx(Ft,{size:"sm",disabled:q,options:[{value:"",label:m("work:task.noRequirement")},...s.filter(Y=>!e.projectId||Y.projectId===e.projectId).map(Y=>({value:Y.id,label:Y.title}))],value:e.requirementId??"",onChange:Y=>qe(()=>te.tasks.update(e.id,{requirementId:Y||null})),placeholder:m("work:task.noRequirement"),noMatchesText:m("work:task.noMatches")}),r.jsx("label",{className:it,children:m("work:task.assignee")}),r.jsx(Ft,{size:"sm",disabled:q,options:[{value:"",label:m("work:task.unassigned")},...t.map(Y=>({value:Y.id,label:`${Y.name} (${Y.status})`}))],value:e.assignedAgentId??"",onChange:Y=>{Ke(Y)},placeholder:m("work:task.unassigned"),noMatchesText:m("work:task.noMatches")}),r.jsx("label",{className:it,children:m("work:task.reviewer")}),r.jsx(Ft,{size:"sm",disabled:q,options:[...a.map(Y=>({value:`human:${Y.id}`,label:Y.name})),...t.map(Y=>({value:`agent:${Y.id}`,label:`${Y.name} (${Y.status})`}))],value:`${e.reviewerType??"agent"}:${e.reviewerId??""}`,onChange:Y=>{if(!Y)return;const me=Y.startsWith("human:"),ze=Y.replace(/^(human|agent):/,"");(ze!==e.reviewerId||(me?"human":"agent")!==(e.reviewerType??"agent"))&&qe(()=>te.tasks.update(e.id,{reviewerId:ze,reviewerType:me?"human":"agent"}))},placeholder:m("work:task.selectReviewer"),noMatchesText:m("work:task.noMatches")}),r.jsx("label",{className:it,children:m("work:task.priority")}),r.jsx(vo,{value:e.priority,onChange:Y=>{Le(Y)}})]})}),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:Os(e.createdBy,t,a)??e.createdBy})}),e.updatedBy&&r.jsx("span",{children:m("work:task.updatedBy",{name:Os(e.updatedBy,t,a)??e.updatedBy})}),e.createdAt&&r.jsx("span",{children:new Date(e.createdAt).toLocaleDateString()}),e.startedAt&&r.jsx("span",{children:m("work:task.started",{date:new Date(e.startedAt).toLocaleDateString()})}),e.updatedAt&&r.jsx("span",{children:m("work:task.updatedMeta",{date:new Date(e.updatedAt).toLocaleDateString()})}),e.projectId&&r.jsxs("span",{className:"font-mono text-blue-600/70",children:["task/",e.id]}),(e.executionRound??1)>1&&r.jsx("span",{className:"text-amber-600",children:m("work:task.executionRound",{n:e.executionRound})})]}),r.jsxs("div",{className:"px-6 py-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsxs("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:[m("work:task.subtasks")," ",b.length>0&&r.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal normal-case",children:[m("work:task.subtasksProgress",{done:Ye,total:b.length-ot}),ot>0?` · ${ot} cancelled`:""]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[It>0&&r.jsx("button",{onClick:()=>j(Y=>!Y),className:`text-[10px] px-2 py-0.5 rounded-full border transition-colors ${C?"bg-brand-500/15 text-brand-500 border-brand-500/30":"text-fg-tertiary border-border-default hover:text-fg-secondary"}`,children:C?m("work:task.hideCompleted"):m("work:task.showCompleted",{count:It})}),r.jsx("button",{onClick:()=>w(!0),className:"text-xs text-brand-500 hover:text-brand-500 transition-colors",children:m("work:task.addSubtask")})]})]}),(()=>{const Y=C?b:b.filter(me=>me.status!=="completed"&&me.status!=="cancelled");return Y.length>0?r.jsx("div",{className:"space-y-1.5 mb-3",children:Y.map(me=>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 ${me.status==="cancelled"?"opacity-50":""}`,children:[r.jsxs("button",{onClick:()=>{be(me)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${me.status==="completed"?"bg-green-600 border-green-600 text-white":me.status==="cancelled"?"bg-gray-500 border-gray-500 text-white":"border-gray-600 hover:border-brand-500"}`,children:[me.status==="completed"&&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"})}),me.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 ${me.status==="completed"?"line-through text-fg-tertiary":me.status==="cancelled"?"line-through text-fg-muted":"text-fg-secondary"}`,children:me.title}),r.jsx("button",{onClick:()=>S(me),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},me.id))}):null})(),b.length===0&&!x&&r.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:m("work:task.noSubtasksYet")}),x&&r.jsxs("div",{className:"flex gap-2 mt-2",children:[r.jsx("input",{autoFocus:!0,value:v,onChange:Y=>y(Y.target.value),onKeyDown:Y=>{Y.key==="Enter"&&de(),Y.key==="Escape"&&(w(!1),y(""))},placeholder:m("work:task.subtaskTitlePlaceholder"),className:"flex-1 px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none"}),r.jsx("button",{onClick:()=>{de()},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-on-brand text-xs rounded-lg",children:m("work:task.add")}),r.jsx("button",{onClick:()=>{w(!1),y("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:m("common:cancel")})]}),(()=>{const Y=se.filter(Fe=>typeof Fe.reference=="string"&&Fe.reference.length>0);if(Y.length===0)return null;const me={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},ze=Y.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:Y.length})}),Y.length>3&&r.jsx("button",{onClick:()=>pe("deliverables"),className:"text-[10px] text-brand-500 hover:text-brand-500",children:m("work:task.viewAll")})]}),r.jsx("div",{className:"space-y-1.5",children:ze.map(Fe=>{const _e=/^https?:\/\//i.test(Fe.reference),St=_e?Fe.summary||Fe.reference:Fe.reference.split("/").pop()??Fe.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 ${me[Fe.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Fe.type}),r.jsxs("div",{className:"flex-1 min-w-0",children:[_e?r.jsxs("a",{href:Fe.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:Fe.reference,children:[St," ",r.jsxs("svg",{className:"w-3 h-3 inline -mt-0.5 ml-0.5 opacity-60",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M9 6.5v3a.5.5 0 0 1-.5.5h-6a.5.5 0 0 1-.5-.5v-6A.5.5 0 0 1 2.5 3H6"}),r.jsx("path",{d:"M7 2h3v3"}),r.jsx("path",{d:"M5 7 10 2"})]})]}):r.jsx("button",{onClick:()=>re(Fe.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Fe.reference,children:St}),Fe.summary&&!_e&&r.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Fe.summary}),r.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Fe.reference})]})]},Fe.id)})})]})})(),r.jsx(Rb,{task:e,agents:t,users:a,authUser:c})]})]}),r.jsx("div",{className:U==="history"?"":"hidden",children:r.jsx(df,{entityType:"task",entityId:e.id})}),r.jsx("div",{className:U==="deliverables"?"px-6 py-4":"hidden",children:(()=>{const Y=se.filter(_e=>typeof _e.reference=="string"&&_e.reference.length>0);if(Y.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 me={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},ze=Math.ceil(Y.length/ht),Fe=Y.slice((F-1)*ht,F*ht);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:Y.length})}),ze>1&&r.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[r.jsx("button",{disabled:F<=1,onClick:()=>Z(_e=>_e-1),className:"px-1.5 py-0.5 rounded bg-surface-elevated hover:bg-surface-overlay disabled:opacity-30",children:"‹"}),r.jsxs("span",{children:[F,"/",ze]}),r.jsx("button",{disabled:F>=ze,onClick:()=>Z(_e=>_e+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:Fe.map(_e=>{const St=/^https?:\/\//i.test(_e.reference),Rn=St?_e.summary||_e.reference:_e.reference.split("/").pop()??_e.reference;return r.jsxs("div",{className:"flex items-start gap-2.5 bg-surface-elevated/60 rounded-lg px-3 py-2 group hover:bg-surface-elevated/80 transition-colors",children:[r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium shrink-0 mt-0.5 ${me[_e.type]??"bg-gray-500/15 text-fg-secondary"}`,children:_e.type}),r.jsxs("div",{className:"flex-1 min-w-0",children:[St?r.jsxs("a",{href:_e.reference,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:_e.reference,children:[Rn," ",r.jsxs("svg",{className:"w-3 h-3 inline -mt-0.5 ml-0.5 opacity-60",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M9 6.5v3a.5.5 0 0 1-.5.5h-6a.5.5 0 0 1-.5-.5v-6A.5.5 0 0 1 2.5 3H6"}),r.jsx("path",{d:"M7 2h3v3"}),r.jsx("path",{d:"M5 7 10 2"})]})]}):r.jsx("button",{onClick:()=>re(_e.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:_e.reference,children:Rn}),_e.summary&&!St&&r.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:_e.summary}),r.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:_e.reference})]})]},_e.id)})})]})})()})]}),V!=="none"&&V!=="top"&&r.jsx("button",{onClick:()=>T.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-36 right-4 md:bottom-28 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-on-brand hover:bg-brand-400 transition-colors backdrop-blur-sm",title:m("work:task.scrollToTop"),children:r.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:r.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),V!=="none"&&V!=="bottom"&&r.jsx("button",{onClick:()=>{const Y=T.current;Y&&Y.scrollTo({top:Y.scrollHeight,behavior:"smooth"})},className:"absolute bottom-22 right-4 md:bottom-18 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-on-brand hover:bg-brand-400 transition-colors backdrop-blur-sm",title:m("work:task.scrollToBottom"),children:r.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:r.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),vt&&e.scheduleConfig&&r.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${gt?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"} ${!Ht&&!P&&!e.scheduleConfig.runAt?"cursor-pointer hover:border-brand-500/40 transition-colors":""}`,onClick:()=>{Ht||P||e.scheduleConfig?.runAt||(_(_h(e.scheduleConfig)),L(!0))},children:[r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.jsx("span",{className:gt?"text-amber-600":"text-brand-500",children:gt?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")}),!gt&&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 Y=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(Y<=0)return m("work:task.scheduleDueNow");const me=Math.floor(Y/6e4);if(me<60)return m("work:task.scheduleInMinutes",{count:me});const ze=Math.floor(me/60);return ze<24?m("work:task.scheduleInHoursMinutes",{h:ze,m:me%60}):m("work:task.scheduleInDaysHours",{d:Math.floor(ze/24),h:ze%24})})()})})]}),!Ht&&!P&&!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"})]})]}),P&&B?r.jsxs("div",{className:"mt-2 pt-2 border-t border-border-default/50 space-y-2",onClick:Y=>Y.stopPropagation(),children:[r.jsx(Jc,{value:B,onChange:_,compact:!0}),r.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[r.jsx("button",{onClick:async()=>{await qe(()=>te.tasks.updateSchedule(e.id,Qc(B))),L(!1)},disabled:q,className:"px-3 py-1 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-on-brand disabled:opacity-50",children:m("common:save")}),r.jsx("button",{onClick:()=>L(!1),className:"px-3 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:m("common:cancel")})]})]}):r.jsxs("div",{className:"flex items-center gap-2 mt-1 text-fg-tertiary",children:[r.jsx("span",{children:m("work:task.scheduleRuns",{current:e.scheduleConfig.currentRuns??0,max:e.scheduleConfig.maxRuns&&e.scheduleConfig.maxRuns>0?m("work:task.scheduleRunsMax",{max:e.scheduleConfig.maxRuns}):""})}),e.scheduleConfig.lastRunAt&&r.jsxs(r.Fragment,{children:[r.jsx("span",{children:"·"}),r.jsx("span",{children:m("work:task.scheduleLast",{when:(()=>{const Y=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),me=Math.floor(Y/6e4);if(me<1)return m("work:task.noteTimeJustNow");if(me<60)return m("work:task.noteTimeMinutes",{count:me});const ze=Math.floor(me/60);return ze<24?m("work:task.noteTimeHours",{count:ze}):m("work:task.noteTimeDays",{count:Math.floor(ze/24)})})()})})]})]})]}),e.status==="review"&&nl(Ne)&&r.jsxs("div",{className:"mx-6 mt-3 flex items-start gap-2.5 rounded-lg border border-purple-500/30 bg-purple-500/8 px-3 py-2",children:[r.jsx("span",{className:"mt-1 w-1.5 h-1.5 shrink-0 rounded-full bg-purple-400 animate-pulse"}),r.jsx("div",{className:"min-w-0 flex-1 text-xs text-fg-primary",children:m("work:task.reviewInProgressBy",{agent:nl(Ne).reviewerName})}),r.jsx("button",{onClick:()=>pe("activity"),className:"shrink-0 rounded-md border border-purple-500/30 px-2 py-1 text-[11px] font-medium text-purple-400 hover:bg-purple-500/10 transition-colors",children:m("work:task.reviewViewSession")})]}),r.jsx("div",{className:"px-6 py-4 border-t border-border-default flex items-center justify-between gap-2",children:r.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.status==="pending"&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{if(vt){ct(!0);return}qe(()=>te.tasks.approve(e.id))},disabled:q,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:Y}=await te.tasks.getDependentCount(e.id);$({dependentCount:Y})},disabled:q,className:"px-3 py-1.5 text-xs text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50",children:m("work:task.cancelTask")}):r.jsx("button",{onClick:()=>D(!0),disabled:q,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:()=>{qe(()=>te.tasks.accept(e.id,c?.id))},disabled:q,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")}),ve?r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("input",{type:"text",value:nt,onChange:Y=>Pe(Y.target.value),onKeyDown:Y=>{Y.key==="Enter"&&nt.trim()&&(qe(()=>te.tasks.revision(e.id,nt.trim(),c?.id)),Me(!1),Pe(""))},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:()=>{qe(()=>te.tasks.revision(e.id,nt.trim()||m("work:task.revisionsNeededDefault"),c?.id)),Me(!1),Pe("")},disabled:q,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:()=>{Me(!1),Pe("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):r.jsx("button",{onClick:()=>Me(!0),disabled:q,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")})]}),Ht&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>{X()},disabled:q,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:()=>{Ct()},disabled:q,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")]})]}),wn&&r.jsx("button",{onClick:()=>{ye()},disabled:q,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:q?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")]})}),mt&&!vt&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>{Ct()},disabled:q,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:()=>{Xe()},disabled:q,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")]})]}),vt&&(cn||mt||st)&&!Qe&&r.jsx("button",{onClick:()=>{At()},disabled:q,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-on-brand disabled:opacity-50 flex items-center gap-1.5",children:q?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")]})}),vt&&!Ht&&!Qe&&!Ze&&(gt?r.jsx("button",{onClick:()=>{qe(()=>te.tasks.resumeSchedule(e.id))},disabled:q,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:()=>{qe(()=>te.tasks.pauseSchedule(e.id))},disabled:q,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")})),(cn||mt||Ze||st)&&r.jsx("button",{onClick:()=>I(!0),disabled:q,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")}),cn&&!vt&&r.jsx("button",{onClick:()=>{Xe()},disabled:q,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")}),!dt&&e.status!=="pending"&&r.jsx("button",{onClick:async()=>{const{count:Y}=await te.tasks.getDependentCount(e.id);$({dependentCount:Y})},disabled:q,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(bs,{title:m("work:task.deleteSubtaskTitle",{title:E.title}),message:m("work:task.deleteSubtaskMessage"),confirmLabel:m("common:delete"),onConfirm:()=>{Ce(E)},onCancel:()=>S(null)}),M&&r.jsx(bs,{title:m("work:task.rejectConfirmTitle"),message:m("work:task.rejectConfirmMessage"),confirmLabel:m("work:task.reject"),onConfirm:()=>{D(!1),qe(()=>te.tasks.reject(e.id))},onCancel:()=>D(!1)}),z&&r.jsx(bs,{title:m("work:task.archiveConfirmTitle"),message:m(vt?"work:task.archiveScheduledConfirmMessage":"work:task.archiveConfirmMessage"),confirmLabel:m("work:task.archive"),onConfirm:()=>{I(!1),qe(()=>te.tasks.archive(e.id))},onCancel:()=>I(!1)}),R&&R.dependentCount>0?r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>$(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:Y=>Y.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:[vt&&r.jsx(r.Fragment,{children:r.jsx("span",{className:"block mb-1 text-amber-600",children:m("work:task.cancelScheduledConfirmMessage")})}),m("work:task.cancelTaskDependent",{count:R.dependentCount})]}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsxs("button",{onClick:()=>{$(null),qe(()=>te.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),qe(()=>te.tasks.cancel(e.id,!0))},className:"w-full px-4 py-2.5 text-sm bg-red-500/10 border border-red-500/30 rounded-lg hover:bg-red-500/20 text-red-500 text-left",children:[r.jsx("span",{className:"font-medium",children:m("work:task.cancelWithDependents")}),r.jsx("span",{className:"block text-xs text-red-500/70 mt-0.5",children:m("work:task.cancelWithDependentsHint",{count:R.dependentCount})})]}),r.jsx("button",{onClick:()=>$(null),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:m("work:task.keepTaskRunning")})]})]})}):R&&r.jsx(bs,{title:m("work:task.cancelTaskModalTitle"),message:m(vt?"work:task.cancelScheduledConfirmMessage":"work:task.cancelConfirmMessage"),confirmLabel:m("work:task.cancelTask"),onConfirm:()=>{$(null),qe(()=>te.tasks.cancel(e.id))},onCancel:()=>$(null)}),Oe&&r.jsx(Ob,{filePath:Oe,onClose:()=>re(null),onOpenExternal:()=>{re(null),te.deliverables.search({taskId:e.id,limit:100}).then(({results:Y})=>{const me=Y.find(ze=>ze.reference===Oe);me?en.navigate(tt.DELIVERABLES,{openDeliverable:me.id}):en.navigate(tt.DELIVERABLES)}).catch(()=>en.navigate(tt.DELIVERABLES))}}),Ve&&e.scheduleConfig&&r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>ct(!1),children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[380px] shadow-2xl",onClick:Y=>Y.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:q,onClick:()=>{ct(!1),qe(()=>te.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:q,onClick:()=>{ct(!1),qe(()=>te.tasks.approve(e.id,!1))},className:"w-full px-4 py-2.5 text-sm bg-brand-600 hover:bg-brand-500 text-on-brand rounded-lg font-medium transition-colors disabled:opacity-50",children:m("work:task.scheduleApproveWait")}),r.jsx("button",{onClick:()=>ct(!1),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:m("common:cancel")})]})]})})]})}function $b({project:e,tasks:t,requirements:n,agents:s,onDeleteProject:o,onUpdateProject:a,onRefresh:i}){const l=p.useMemo(()=>t.filter(M=>M.projectId===e.id),[t,e.id]),c=p.useMemo(()=>n.filter(M=>M.projectId===e.id),[n,e.id]),d=p.useMemo(()=>{const M={total:l.length,completed:0,inProgress:0,inReview:0,blocked:0,pending:0,failed:0,reqs:c.length,reqsDone:0};for(const D of l)D.status==="completed"||D.status==="accepted"?M.completed++:D.status==="in_progress"?M.inProgress++:D.status==="review"||D.status==="revision"?M.inReview++:D.status==="blocked"?M.blocked++:D.status==="failed"?M.failed++:M.pending++;for(const D of c)D.status==="completed"&&M.reqsDone++;return M},[l,c]),f=p.useMemo(()=>new Set(l.map(M=>M.assignedAgentId).filter(Boolean)),[l]),u=p.useMemo(()=>s.filter(M=>f.has(M.id)),[s,f]),[h,m]=p.useState(!1),[g,b]=p.useState(""),[k,v]=p.useState("main"),[y,x]=p.useState(!1),[w,C]=p.useState(!1),{t:j}=He(["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")}],S=async M=>{if(M!==e.status){x(!0);try{await a({status:M}),i()}finally{x(!1)}}},R=async()=>{const M=g.trim();if(!M)return;const D=[...e.repositories??[],{url:"",localPath:M,defaultBranch:k||"main"}];await a({repositories:D}),b(""),v("main"),m(!1),i()},$=async M=>{const D=(e.repositories??[]).filter((z,I)=>I!==M);await a({repositories:D}),i()};return r.jsxs("div",{className:"p-5 space-y-5 max-w-3xl",children:[r.jsxs("div",{className:"space-y-3",children:[r.jsx(Cb,{value:e.description??"",onSave:async M=>{await a({description:M}),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(M=>r.jsxs("button",{disabled:y,onClick:()=>S(M.value),className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium transition-all ${e.status===M.value?M.value==="active"?"bg-green-500/15 text-green-600 ring-1 ring-green-500/30":M.value==="paused"?"bg-amber-500/15 text-amber-600 ring-1 ring-amber-500/30":"bg-gray-500/15 text-fg-tertiary ring-1 ring-gray-500/30":"bg-surface-elevated text-fg-tertiary hover:text-fg-secondary hover:bg-surface-overlay"} ${y?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[r.jsx("div",{children:M.label}),r.jsx("div",{className:"text-[10px] opacity-70 mt-0.5",children:M.desc})]},M.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(pn,{label:j("work:project.statTotal"),value:d.total,color:"text-fg-primary"}),r.jsx(pn,{label:j("work:project.statCompleted"),value:d.completed,color:"text-green-600"}),r.jsx(pn,{label:j("work:project.statInProgress"),value:d.inProgress,color:"text-brand-500"}),r.jsx(pn,{label:j("work:project.statInReview"),value:d.inReview,color:"text-brand-500"}),r.jsx(pn,{label:j("work:project.statBlocked"),value:d.blocked,color:"text-amber-600"}),r.jsx(pn,{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(pn,{label:j("work:project.statTotal"),value:d.reqs,color:"text-fg-primary"}),r.jsx(pn,{label:j("work:project.statCompleted"),value:d.reqsDone,color:"text-green-600"}),r.jsx(pn,{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(M=>{const D=l.filter(I=>I.assignedAgentId===M.id),z=D.filter(I=>!ir(I.status));return r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-surface-elevated/60 rounded-lg",children:[r.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${M.status==="working"?"bg-blue-500":M.status==="idle"?"bg-green-500":"bg-gray-500"}`}),r.jsx("span",{className:"text-xs text-fg-secondary",children:M.name}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:j("work:project.agentTaskCounts",{active:z.length,total:D.length})})]},M.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(!h),className:"text-[10px] text-brand-500 hover:text-brand-500",children:j(h?"common:cancel":"work:project.addRepo")})]}),(e.repositories??[]).length===0&&!h&&r.jsx("p",{className:"text-xs text-fg-tertiary",children:j("work:project.noReposLinked")}),(e.repositories??[]).map((M,D)=>r.jsxs("div",{className:"flex items-center gap-2 py-1.5 group",children:[r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary shrink-0",children:[r.jsx("path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"}),r.jsx("path",{d:"M9 18c-4.51 2-5-2-7-2"})]}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 min-w-0 truncate",children:M.url||M.localPath}),r.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:M.defaultBranch}),r.jsx("button",{onClick:()=>$(D),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:j("work:project.removeRepo"),children:r.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},D)),h&&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:M=>b(M.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:M=>v(M.target.value),placeholder:j("work:project.repoBranchPlaceholder"),className:"flex-1 px-2.5 py-1.5 text-xs bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder:text-fg-tertiary"}),r.jsx("button",{onClick:R,disabled:!g.trim(),className:"px-3 py-1.5 text-xs bg-brand-600 text-on-brand rounded-md hover:bg-brand-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:j("work:task.add")})]})]})]}),r.jsx(Yx,{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:()=>C(!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(bs,{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:()=>{C(!1),o()},onCancel:()=>C(!1)})]})}function pn({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 ho={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed",archived:"closed"},lf={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},Pb={urgent:0,high:1,medium:2,low:3},No={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},Ac={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"},Bb={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 cf(e){for(const t of jo)if(t.statuses.includes(e))return t.id;return"closed"}function Lc(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 ro({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=f=>{l.current&&!l.current.contains(f.target)&&i.current&&!i.current.contains(f.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 f=d.value===e,u=f||!s||s.has(d.value);return r.jsxs("button",{disabled:!u,onClick:()=>{!f&&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 ${f?"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 ${f?"text-fg-primary":u?"text-fg-secondary":"text-fg-muted"}`,children:d.label}),f&&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 qb({onQuickCreateReq:e,onQuickCreateTask:t}){const{t:n}=He(["work","common"]),[s,o]=p.useState("req"),[a,i]=p.useState(!1),[l,c]=p.useState(""),d=p.useRef(null),f=p.useRef(null);p.useEffect(()=>{a&&(d.current?.focus({preventScroll:!0}),f.current?.scrollIntoView({block:"nearest",inline:"start"}))},[a]);const u=()=>{const h=l.trim();c(""),i(!1),h&&(s==="req"?e(h):t(h))};return r.jsxs("div",{ref:f,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:h=>h.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:h=>h.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:h=>c(h.target.value),onKeyDown:h=>{h.key==="Enter"?u():h.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 _c({row:e,idx:t,dragIdx:n,agentMap:s,projMap:o,onTaskClick:a,onReqClick:i,onRowDragStart:l,onRowDragEnd:c,handleStatusChange:d,handlePriorityChange:f,selected:u,isMobile:h,isAbnormalBlocked:m}){const{t:g}=He(["work","common"]),b=p.useMemo(()=>of(g),[g]),k=p.useMemo(()=>xi(g),[g]),v=p.useMemo(()=>Lb(g),[g]),y=e.data.status,x=e.data.priority,w=e.kind==="task"?s.get(e.data.assignedAgentId??""):void 0,C=(()=>{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 h?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 ${Ac[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(ro,{value:y,options:e.kind==="task"?Cc.map(E=>({value:E,label:b[E]?.label??E,cls:b[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})):Ec.map(E=>({value:E,label:k[E]?.label??E,cls:k[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?pc[y]:La[y],onSelect:E=>{d(e,E)}})}),r.jsx("div",{onClick:E=>E.stopPropagation(),children:r.jsx(ro,{value:x,options:Sc.map(E=>({value:E,label:v[E]?.label??E,cls:v[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:E=>{f(e,E)}})}),w&&r.jsxs("span",{className:"flex items-center gap-1 text-[10px]",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Qn[w.status]??"bg-gray-500"}`}),r.jsx("span",{className:`${Ic[w.status]??"text-fg-secondary"}`,children:w.name})]}),C?.name&&r.jsx("span",{className:"text-[10px] text-brand-400/70 truncate max-w-[80px]",children:C.name}),r.jsx("span",{className:"text-[9px] text-fg-muted ml-auto",children:Lc(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 ${Ac[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(ro,{value:y,options:e.kind==="task"?Cc.map(E=>({value:E,label:b[E]?.label??E,cls:b[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})):Ec.map(E=>({value:E,label:k[E]?.label??E,cls:k[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?pc[y]:La[y],onSelect:E=>{d(e,E)}})}),r.jsx("div",{className:"w-[100px] shrink-0",onClick:E=>E.stopPropagation(),children:r.jsx(ro,{value:x,options:Sc.map(E=>({value:E,label:v[E]?.label??E,cls:v[E]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:E=>{f(e,E)}})}),r.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:w?r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Qn[w.status]??"bg-gray-500"}`}),r.jsx("span",{className:`font-medium ${Ic[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:C?.name?r.jsx("span",{className:"text-brand-400/70",children:C.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:Lc(e.data.updatedAt??"",g)})]})}function zb({tasks:e,requirements:t,agents:n,projects:s,onTaskClick:o,onReqClick:a,onRefresh:i,selectedTaskId:l,selectedReqId:c,onQuickCreateReq:d,onQuickCreateTask:f,onLoadMore:u,hasMore:h,loadingMore:m}){const{t:g}=He(["work","common"]),b=pr(),[k,v]=p.useState("status"),[y,x]=p.useState(null),[w,C]=p.useState(null),j=p.useMemo(()=>{const O=new Map;for(const U of e)O.set(U.id,U);return O},[e]),E=p.useCallback(O=>O.status!=="blocked"?!1:Ra(O,U=>j.get(U)),[j]),S=p.useMemo(()=>{const O=[];for(const U of e){const A=cf(U.status);O.push({kind:"task",data:U,group:A,groupOrder:No[A]??5})}for(const U of t){const A=ho[U.status]??"todo";O.push({kind:"req",data:U,group:A,groupOrder:No[A]??5})}if(k==="status")O.sort((U,A)=>{if(U.groupOrder!==A.groupOrder)return U.groupOrder-A.groupOrder;const T=new Date(U.data.updatedAt??0).getTime();return new Date(A.data.updatedAt??0).getTime()-T});else{const U=A=>Pb[A.data.priority]??2;O.sort((A,T)=>{const V=U(A),W=U(T);return V!==W?V-W:new Date(T.data.updatedAt??0).getTime()-new Date(A.data.updatedAt??0).getTime()})}return O},[e,t,k]),R=async(O,U)=>{try{O.kind==="task"?await te.tasks.updateStatus(O.data.id,U):await te.requirements.updateStatus(O.data.id,U),i()}catch{}},$=async(O,U)=>{try{O.kind==="task"?await te.tasks.update(O.data.id,{priority:U}):await te.requirements.update(O.data.id,{priority:U}),i()}catch{}},M=(O,U)=>{x(U),O.dataTransfer.effectAllowed="move",O.dataTransfer.setData("text/plain",String(U)),O.currentTarget.style.opacity="0.4"},D=O=>{O.currentTarget.style.opacity="1",x(null),C(null)},z=(O,U)=>{O.preventDefault(),O.dataTransfer.dropEffect="move",w!==U&&C(U)},I=async(O,U)=>{if(O.preventDefault(),C(null),y==null)return;const A=S[y];if(!A||A.group===U)return;const T=jo.find(V=>V.id===U);if(T){try{if(A.kind==="task"){if(A.data.status==="pending")return;await te.tasks.updateStatus(A.data.id,T.dropStatus)}else{const V=lf[U];V&&await te.requirements.updateStatus(A.data.id,V)}i()}catch{}x(null)}},P=p.useMemo(()=>new Map(n.map(O=>[O.id,O])),[n]),L=p.useMemo(()=>new Map(s.map(O=>[O.id,O])),[s]),B=["todo","in_progress","review","done"],_=p.useMemo(()=>{const O={};for(const U of S)O[U.group]=(O[U.group]??0)+1;return O},[S]),{rowsByGroup:q,rowIndexMap:H}=p.useMemo(()=>{const O=new Map,U=new Map;for(let A=0;A<S.length;A++){const T=S[A];U.set(T,A);const V=O.get(T.group)??[];V.push(T),O.set(T.group,V)}return{rowsByGroup:O,rowIndexMap:U}},[S]),K=p.useMemo(()=>{if(k!=="status")return null;const O=new Set(S.map(T=>T.group)),U=[],A=new Set;O.has("failed")&&(U.push("failed"),A.add("failed"));for(const T of B)U.push(T),A.add(T);for(const T of S)A.has(T.group)||(U.push(T.group),A.add(T.group));return U},[S,k]);return r.jsx("div",{className:`flex-1 min-h-0 overflow-auto bg-surface-primary ${b?"overflow-x-hidden w-full":""}`,onScroll:O=>{if(!u||!h)return;const U=O.currentTarget;U.scrollTop+U.clientHeight>=U.scrollHeight-240&&u()},children:r.jsxs("div",{className:b?"w-full":"w-fit min-w-full",children:[!b&&r.jsxs("div",{className:"flex items-center gap-2 px-6 py-2 border-b border-border-default text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider sticky top-0 z-20 bg-surface-primary",children:[r.jsx("div",{className:"w-12 shrink-0 text-fg-muted normal-case font-normal",children:S.length}),r.jsx("div",{className:"flex-1 min-w-[200px]",children:g("work:task.backlogTitle")}),r.jsxs("button",{onClick:()=>v("status"),className:`w-[130px] shrink-0 text-left flex items-center gap-1 transition-colors ${k==="status"?"text-brand-500":"hover:text-fg-secondary"}`,children:[g("work:filters.status")," ",k==="status"&&r.jsx("span",{className:"text-[8px]",children:"▼"})]}),r.jsxs("button",{onClick:()=>v("priority"),className:`w-[100px] shrink-0 text-left flex items-center gap-1 transition-colors ${k==="priority"?"text-brand-500":"hover:text-fg-secondary"}`,children:[g("work:filters.priority")," ",k==="priority"&&r.jsx("span",{className:"text-[8px]",children:"▼"})]}),r.jsx("div",{className:"w-[120px] shrink-0",children:g("work:filters.assignee")}),r.jsx("div",{className:"w-[120px] shrink-0",children:g("work:task.projectLabel")}),r.jsx("div",{className:"w-[90px] shrink-0 text-right",children:g("work:task.backlogUpdated")})]}),r.jsxs("div",{children:[k==="status"&&K?K.map(O=>{const U=q.get(O)??[];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 ${Bb[O]??""} ${w===O?"ring-1 ring-brand-500/40":""}`,onDragOver:A=>z(A,O),onDragLeave:()=>C(null),onDrop:A=>{I(A,O)},children:[r.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:g(`work:boardColumn.${O}`)}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:_[O]??0})]}),U.map(A=>r.jsx(_c,{row:A,idx:H.get(A)??0,dragIdx:y,agentMap:P,projMap:L,onTaskClick:o,onReqClick:a,onRowDragStart:M,onRowDragEnd:D,handleStatusChange:R,handlePriorityChange:$,selected:A.kind==="task"?A.data.id===l:A.data.id===c,isMobile:b,isAbnormalBlocked:A.kind==="task"?E(A.data):!1},`${A.kind}-${A.data.id}`)),O==="todo"&&r.jsx(qb,{onQuickCreateReq:d,onQuickCreateTask:f})]},O)}):S.map((O,U)=>r.jsx(_c,{row:O,idx:U,dragIdx:y,agentMap:P,projMap:L,onTaskClick:o,onReqClick:a,onRowDragStart:M,onRowDragEnd:D,handleStatusChange:R,handlePriorityChange:$,selected:O.kind==="task"?O.data.id===l:O.data.id===c,isMobile:b,isAbnormalBlocked:O.kind==="task"?E(O.data):!1},`${O.kind}-${O.data.id}`)),m&&r.jsxs("div",{className:"flex items-center justify-center gap-2 py-3 text-[11px] text-fg-tertiary",children:[r.jsx("span",{className:"w-3 h-3 border-2 border-fg-muted/40 border-t-brand-500 rounded-full animate-spin"}),g("work:task.loadingMore","正在加载更多…")]}),!m&&h&&S.length>0&&r.jsx("div",{className:"py-3 text-center text-[11px] text-fg-muted",children:g("work:task.scrollForMore","滚动到底部继续加载")}),S.length===0&&r.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-3 max-w-sm mx-auto text-center",children:[r.jsx("svg",{className:"w-10 h-10 text-fg-muted",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})}),r.jsx("p",{className:"text-sm font-medium text-fg-secondary",children:g("work:task.backlogEmptyTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:g("work:task.backlogEmptyDesc")})]})]})]})})}function _a(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,60)||"workflow"}function Fb(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=_a(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 f=_a(d).replace(/[^a-z0-9-]/g,"")||"worker";i.has(f)&&(f=`${f}-${c.slice(-4)}`),i.add(f),a.set(c,f)}}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 oo(e){return/[:#\[\]{}&*!|>'"%@`\n]/.test(e)||e.startsWith(" ")||e.endsWith(" ")?JSON.stringify(e):e}function Hb(e,t,n){const s=[];s.push(`name: ${oo(e)}`),s.push(`description: ${oo(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: ${oo(o.name)}`),s.push(" type: agent_task"),s.push(` role: ${oo(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 Vb({req:e,tasks:t,agents:n,teamId:s,onClose:o,onSaved:a}){const{t:i}=He(["work"]),l=p.useMemo(()=>{const R={};for(const $ of n)R[$.id]=$.name;return R},[n]),c=p.useMemo(()=>Fb(t,l),[t,l]),[d,f]=p.useState(()=>_a(e.title)),[u,h]=p.useState(e.description||e.title),[m,g]=p.useState(c),[b,k]=p.useState(!1),[v,y]=p.useState(null),x=(R,$,M)=>{g(D=>D.map((z,I)=>I===R?{...z,[$]:M}:z))},w=R=>{const $=m[R]?.id;g(M=>M.filter((D,z)=>z!==R).map(D=>({...D,depends_on:D.depends_on.filter(z=>z!==$)})))},[C,j]=p.useState(!1),E=async()=>{if(d.trim()){k(!0),y(null);try{const R=Hb(d.trim(),u,m);await te.workflows.create(s,d.trim(),R),j(!0),setTimeout(()=>a(),800)}catch(R){y(String(R))}k(!1)}},S=p.useMemo(()=>[...new Set(m.map(R=>R.role))],[m]);return r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",onClick:o,children:r.jsxs("div",{className:"bg-surface-primary border border-border-default rounded-2xl shadow-2xl w-full max-w-[640px] mx-4 max-h-[85vh] flex flex-col",onClick:R=>R.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-6 py-4 border-b border-border-default",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-base font-semibold text-fg-primary",children:i("work:task.saveAsWorkflow","Save as Workflow")}),r.jsx("p",{className:"text-xs text-fg-tertiary mt-0.5",children:i("work:task.saveAsWorkflowDesc","Turn this task structure into a reusable workflow template")})]}),r.jsx("button",{onClick:o,className:"text-fg-tertiary hover:text-fg-secondary p-1 rounded-lg hover:bg-surface-elevated transition-colors",children:r.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),r.jsxs("div",{className:"flex-1 overflow-auto px-4 sm:px-6 py-4 space-y-4",children:[r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:i("work:task.workflowName","Name")}),r.jsx("input",{value:d,onChange:R=>f(R.target.value),className:"w-full text-sm bg-surface-secondary border border-border-default/50 rounded-lg px-3 py-2 text-fg-primary focus:outline-none focus:ring-1 focus:ring-brand-500",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:S.map(R=>r.jsx("span",{className:"px-2 py-0.5 text-[10px] font-medium bg-brand-500/10 text-brand-500 rounded-full",children:R},R))})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:i("work:task.description","Description")}),r.jsx("input",{value:u,onChange:R=>h(R.target.value),className:"w-full text-sm bg-surface-secondary border border-border-default/50 rounded-lg px-3 py-2 text-fg-primary focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 block",children:[i("work:task.workflowSteps","Steps")," (",m.length,")"]}),r.jsx("div",{className:"space-y-2",children:m.map((R,$)=>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:R.name,onChange:M=>x($,"name",M.target.value),className:"flex-1 text-sm font-medium bg-transparent border-b border-transparent hover:border-border-default focus:border-brand-500 text-fg-primary focus:outline-none px-0 py-0.5 transition-colors"}),r.jsx("input",{value:R.role,onChange:M=>x($,"role",M.target.value),className:"w-28 text-[10px] bg-surface-elevated border border-border-default/40 rounded-md px-2 py-1 text-fg-secondary focus:outline-none focus:ring-1 focus:ring-brand-500",title:i("work:task.role","Role")})]}),R.depends_on.length>0&&r.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[r.jsxs("span",{children:[i("work:task.dependsOn","Depends on"),":"]}),R.depends_on.map(M=>{const D=m.find(z=>z.id===M);return r.jsx("span",{className:"px-1.5 py-0.5 bg-surface-elevated rounded text-fg-secondary",children:D?.name??M},M)})]}),r.jsx("div",{className:"text-xs text-fg-tertiary line-clamp-2 leading-relaxed",children:R.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"})})})]})},R.id))})]}),v&&r.jsx("p",{className:"text-xs text-red-500",children:v}),C&&r.jsx("p",{className:"text-xs text-green-500 font-medium",children:i("work:task.workflowSavedSuccess","Workflow saved successfully")})]}),r.jsxs("div",{className:"flex items-center justify-end gap-2 px-6 py-4 border-t border-border-default",children:[r.jsx("button",{onClick:o,className:"px-4 py-2 text-sm text-fg-secondary hover:text-fg-primary hover:bg-surface-elevated rounded-lg transition-colors",children:i("work:task.cancel","Cancel")}),r.jsx("button",{onClick:E,disabled:b||C||!d.trim()||m.length===0,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-50 disabled:cursor-not-allowed text-on-brand text-sm rounded-lg font-medium transition-colors",children:b?i("work:task.saving","Saving..."):C?i("work:task.workflowSavedSuccess","Saved!"):i("work:task.saveWorkflow","Save Workflow")})]})]})})}function Rc({teamId:e,agents:t,compact:n}){const{t:s}=He(["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(tt.TEAM,{agentId:o.id,prefillMessage:s("work:task.workflowCreatePrompt","Please create a workflow template for our team. Review the team composition, then design a multi-step process that matches our regular work. Use the workflow_create tool to save it. If the user specifies a project, bind the workflow to that project by including a project_id parameter. Otherwise, leave project as an optional runtime parameter so users can choose when starting a run.")})};return r.jsxs("div",{className:`min-w-0 ${n?"max-w-4xl space-y-3":"max-w-lg w-full text-center space-y-5"}`,children:[!n&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-brand-500/10",children:r.jsx("svg",{className:"w-8 h-8 text-brand-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3.75 6A2.25 2.25 0 016 3.75h2.25A2.25 2.25 0 0110.5 6v2.25a2.25 2.25 0 01-2.25 2.25H6a2.25 2.25 0 01-2.25-2.25V6zM3.75 15.75A2.25 2.25 0 016 13.5h2.25a2.25 2.25 0 012.25 2.25V18a2.25 2.25 0 01-2.25 2.25H6A2.25 2.25 0 013.75 18v-2.25zM13.5 6a2.25 2.25 0 012.25-2.25H18A2.25 2.25 0 0120.25 6v2.25A2.25 2.25 0 0118 10.5h-2.25a2.25 2.25 0 01-2.25-2.25V6zM13.5 15.75a2.25 2.25 0 012.25-2.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-2.25A2.25 2.25 0 0113.5 18v-2.25z"})})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-1.5",children:s("work:task.workflowEmptyTitle","No workflow templates yet")}),r.jsx("p",{className:"text-sm text-fg-secondary leading-relaxed",children:s("work:task.workflowEmptyDesc","Workflows automate repeatable multi-step processes. Define a sequence of tasks as a DAG — the system handles dependencies, role assignment, and scheduling automatically.")})]})]}),r.jsxs("details",{className:n?"group":"",open:!n,children:[r.jsxs("summary",{className:`text-xs font-medium text-fg-secondary uppercase tracking-wider cursor-pointer select-none list-none flex items-center gap-1.5 ${n?"py-1":"sr-only"}`,children:[r.jsx("svg",{className:"w-3 h-3 transition-transform group-open:rotate-90",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),s("work:task.workflowHowItWorks","How it works")]}),r.jsxs("div",{className:`bg-surface-secondary border border-border-default/40 rounded-xl p-4 text-left space-y-3 ${n?"mt-2":""}`,children:[!n&&r.jsx("p",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:s("work:task.workflowHowItWorks","How it works")}),r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"shrink-0 w-6 h-6 rounded-full bg-brand-500/15 flex items-center justify-center text-[11px] font-bold text-brand-500",children:"1"}),r.jsxs("div",{className:"text-xs text-fg-secondary leading-relaxed",children:[r.jsx("span",{className:"font-medium text-fg-primary",children:s("work:task.workflowStep1Title","Requirement")})," — ",s("work:task.workflowStep1Desc","A workflow run creates a Requirement to group all its tasks under one trackable goal.")]})]}),r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"shrink-0 w-6 h-6 rounded-full bg-brand-500/15 flex items-center justify-center text-[11px] font-bold text-brand-500",children:"2"}),r.jsxs("div",{className:"text-xs text-fg-secondary leading-relaxed",children:[r.jsx("span",{className:"font-medium text-fg-primary",children:s("work:task.workflowStep2Title","Task DAG")})," — ",s("work:task.workflowStep2Desc","Each step becomes a Task assigned to the right team member. Dependencies are tracked — downstream tasks wait for upstream ones to finish.")]})]}),r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"shrink-0 w-6 h-6 rounded-full bg-brand-500/15 flex items-center justify-center text-[11px] font-bold text-brand-500",children:"3"}),r.jsxs("div",{className:"text-xs text-fg-secondary leading-relaxed",children:[r.jsx("span",{className:"font-medium text-fg-primary",children:s("work:task.workflowStep3Title","Auto-execution")})," — ",s("work:task.workflowStep3Desc","Agents pick up tasks, pass deliverables downstream, and the workflow completes automatically. Optionally, schedule it to run on a recurring basis.")]})]})]})]}),o&&r.jsx("div",{className:n?"":"text-center",children:r.jsxs("button",{onClick:a,className:"inline-flex items-center gap-2 px-4 py-2 bg-brand-600 hover:bg-brand-500 text-on-brand text-sm rounded-lg font-medium transition-colors",children:[r.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),s("work:task.workflowAskManager","Ask {{name}} to create a workflow",{name:o.name})]})})]})}function Wb({teamId:e,defaultTeamId:t,projectId:n,agents:s,users:o,projects:a,onViewRunTasks:i}){const{t:l}=He(["work"]),[c,d]=p.useState([]),[f,u]=p.useState({}),[h,m]=p.useState(!1),[g,b]=p.useState(null),[k,v]=p.useState({}),[y,x]=p.useState(!1),[w,C]=p.useState(null),[j,E]=p.useState([]),[S,R]=p.useState(()=>{try{const X=localStorage.getItem(xc);if(X)return X===bc?null:X}catch{}return t??null}),[$,M]=p.useState(()=>fb(X=>{try{return localStorage.getItem(X)}catch{return null}})),[D,z]=p.useState({}),[I,P]=p.useState({}),[L,B]=p.useState({}),[_,q]=p.useState({}),[H,K]=p.useState(null),[O,U]=p.useState(null),[A,T]=p.useState(null),[V,W]=p.useState(null),[F,Z]=p.useState(null),[se,ue]=p.useState(null),[ie,pe]=p.useState([]),[je,Se]=p.useState({}),[Ne,Be]=p.useState(null),[$e,Ie]=p.useState({}),Ve=e??S,ct=X=>{if(X!==S){R(X),d([]),u({});try{localStorage.setItem(xc,X??bc)}catch{}}};p.useEffect(()=>{e||te.teams.list().then(({teams:X})=>{E(X.map(le=>({id:le.id,name:le.name})))}).catch(()=>{})},[e]),p.useMemo(()=>{const X={};for(const le of s)X[le.id]=le.name;return X},[s]);const Oe=p.useCallback(async()=>{const X=Ve?[Ve]:j.map(le=>le.id);if(X.length!==0){m(!0);try{const le=[],ye={},de={};await Promise.all(X.map(async be=>{try{const{workflows:Ce}=await te.workflows.list(be);for(const Xe of Ce)de[Xe.name]=be;le.push(...Ce),await Promise.all(Ce.map(async Xe=>{try{const{runs:Ct}=await te.workflows.listRuns(be,Xe.name,5);ye[Xe.name]=Ct}catch{}}))}catch{}})),d(le),u(ye),Ie(de)}catch{}m(!1)}},[Ve,j]);p.useEffect(()=>{Oe()},[Oe]);const re=X=>Ve??$e[X],fe=p.useCallback(X=>{M(X),hb(X,(le,ye)=>{try{localStorage.setItem(le,ye)}catch{}})},[]),xe=X=>{const le=new Set($);le.has(X)?le.delete(X):le.add(X),fe(le)},J=X=>P(le=>({...le,[X]:"idle"}));p.useEffect(()=>{for(const X of $){if(D[X]||I[X]==="loading"||I[X]==="error")continue;const le=re(X);le&&(P(ye=>({...ye,[X]:"loading"})),te.workflows.get(le,X).then(({template:ye,yaml:de})=>{z(be=>({...be,[X]:{...ye,yaml:de}})),P(be=>({...be,[X]:"ready"}))}).catch(()=>P(ye=>({...ye,[X]:"error"}))))}},[$,D,I,Ve,$e]);const ne=p.useRef(new Set),ae=p.useCallback(async X=>{if(!(!X.requirementId||ne.current.has(X.id))){ne.current.add(X.id),q(le=>({...le,[X.id]:!0}));try{const{tasks:le}=await te.tasks.list({requirementId:X.requirementId,pageSize:200}),ye=new Set(X.taskIds),de=ye.size>0?le.filter(be=>ye.has(be.id)):le;B(be=>({...be,[X.id]:de.map(Ce=>({id:Ce.id,title:Ce.title,status:Ce.status,workflowStepId:Ce.workflowStepId,workflowRunId:Ce.workflowRunId}))}))}catch{B(le=>({...le,[X.id]:[]}))}finally{ne.current.delete(X.id),q(le=>({...le,[X.id]:!1}))}}},[]);p.useEffect(()=>{for(const X of c){const le=(f[X.name]??[])[0];le&&L[le.id]===void 0&&!_[le.id]&&ae(le)}},[c,f,L,_,ae]);const ke=p.useMemo(()=>{const X=[];for(const le of Object.values(f))for(const ye of le)ui(ye.status)&&X.push(ye.id);return X.sort().join(",")},[f]);p.useEffect(()=>{if(!ke)return;const X=window.setInterval(()=>{document.hidden||Oe()},4e3);return()=>window.clearInterval(X)},[ke,Oe]);const ge=async(X,le)=>{const ye=D[le.name]?.yaml;if(T({mode:X,workflow:le,yaml:ye,yamlLoading:X!=="delete"&&!ye,error:null}),X==="delete"||ye)return;const de=re(le.name);if(!de){T(be=>be&&{...be,yamlLoading:!1,error:l("work:task.workflowNoTeam","无法确定此工作流所属的团队")});return}try{const{template:be,yaml:Ce}=await te.workflows.get(de,le.name);z(Xe=>({...Xe,[le.name]:{...be,yaml:Ce}})),P(Xe=>({...Xe,[le.name]:"ready"})),T(Xe=>Xe&&Xe.workflow.name===le.name?{...Xe,yaml:Ce,yamlLoading:!1}:Xe)}catch(be){T(Ce=>Ce&&{...Ce,yamlLoading:!1,error:be instanceof Error?be.message:String(be)})}},ve=async({name:X,yaml:le})=>{if(!A)return;const ye=re(A.workflow.name);if(!ye){T(de=>de&&{...de,error:l("work:task.workflowNoTeam","无法确定此工作流所属的团队")});return}T(de=>de&&{...de,busy:!0,error:null});try{if(A.mode==="edit")await te.workflows.update(ye,A.workflow.name,le??"");else if(A.mode==="duplicate"){const be=X??"",Ce=mb(le??"",be,dc,uc);await te.workflows.create(ye,be,Ce)}else await te.workflows.remove(ye,A.workflow.name);const de=A.workflow.name;T(null),z(be=>{const Ce={...be};return delete Ce[de],Ce}),P(be=>({...be,[de]:"idle"})),qt(),await Oe()}catch(de){T(be=>be&&{...be,busy:!1,error:de instanceof Error?de.message:String(de)})}},Me=X=>{const le={};for(const Ce of X.params??[])Ce.default&&(le[Ce.name]=Ce.default);v(le),C(null),pe([]),Se({});const ye=localStorage.getItem(`markus_wf_project_${X.name}`)??localStorage.getItem("markus_wf_project_last"),de=ye&&a.some(Ce=>Ce.id===ye)?ye:null;Be(n??de??a[0]?.id??null),b(X);const be=re(X.name);be&&te.workflows.roles(be,X.name).then(({roles:Ce})=>pe(Ce)).catch(()=>{})},nt=async()=>{const X=Ne??a[0]?.id,le=g?re(g.name):void 0;if(!g||!le||!X){C(X?l("work:task.workflowNoTeam","Cannot determine team for this workflow"):l("work:task.workflowNoProject","Please select a project"));return}x(!0),C(null);try{let ye;if(ie.length>0){ye={};for(const de of ie)ye[de.role]=je[de.role]??de.recommended??""}await te.workflows.startRun(le,g.name,X,k,ye),localStorage.setItem(`markus_wf_project_${g.name}`,X),localStorage.setItem("markus_wf_project_last",X),b(null),Oe()}catch(ye){C(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(h&&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 Pe=async X=>{W(X),Z(null);try{await te.workflows.cancelRun(X),Oe()}catch{}W(null)},ee=async X=>{ue(X.id);try{X.status==="running"?await te.workflows.pauseRun(X.id):X.status==="paused"&&await te.workflows.resumeRun(X.id),Oe()}catch{}ue(null)},Re=X=>{X.requirementId&&i&&i(X.requirementId)},We=g&&(g.params??[]).some(X=>X.required&&!k[X.name]?.trim()),ht=X=>{en.navigate(tt.WORK,{openTask:X})},Je=async(X,le,ye)=>{const de=re(X);if(!de)throw new Error(l("work:task.workflowNoTeam","无法确定此工作流所属的团队"));let be=D[X]?.yaml;if(!be&&(be=(await te.workflows.get(de,X)).yaml,!be))throw new Error(l("work:task.workflowNoYaml","模板缺少原始 YAML,无法编辑"));const Ce=dc(be),Xe=Ce?.steps?.find(Et=>Et?.id===le);if(!Ce||!Xe)throw new Error(`找不到步骤 ${le}`);ye.name!==void 0&&(Xe.name=ye.name),ye.role!==void 0&&(Xe.role=ye.role),ye.prompt!==void 0&&(Xe.prompt=ye.prompt),await te.workflows.update(de,X,uc(Ce)),qt();const{template:Ct,yaml:At}=await te.workflows.get(de,X);z(Et=>({...Et,[X]:{...Ct,yaml:At}})),P(Et=>({...Et,[X]:"ready"}))},qe=X=>U(X),Le=X=>X.displayName||X.name,Ke=X=>`@[${X.displayName||X.name}](workflow:${X.name})`,kt=X=>{const le=re(X.name),ye=le?s.find(de=>de.teamId===le&&de.agentRole==="manager"):void 0;return Bc(ye?.id,s,o)};return r.jsxs("div",{className:"flex-1 min-h-0 overflow-auto px-4 py-5","data-testid":"workflows-panel",children:[!e&&j.length>0&&r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-4",children:[r.jsx("button",{onClick:()=>ct(null),className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${S===null?"bg-brand-600 text-on-brand":"bg-surface-secondary border border-border-default/50 text-fg-secondary hover:text-fg-primary hover:border-border-default"}`,children:l("work:task.all","All")}),j.map(X=>r.jsx("button",{onClick:()=>ct(X.id),className:`px-3 py-1.5 text-xs rounded-lg font-medium transition-colors ${S===X.id?"bg-brand-600 text-on-brand":"bg-surface-secondary border border-border-default/50 text-fg-secondary hover:text-fg-primary hover:border-border-default"}`,children:X.name},X.id))]}),c.length===0&&!h?r.jsx("div",{className:"flex-1 flex items-center justify-center px-4",children:r.jsx(Rc,{teamId:Ve,agents:s})}):r.jsxs("div",{className:"grid grid-cols-1 gap-4 max-w-4xl min-w-0","data-testid":"workflows-list",children:[c.map(X=>{const le=f[X.name]??[],ye=le[0],de=be=>{const Ce=ye?.roleMapping?.[be];return Ce?s.find(Xe=>Xe.id===Ce)?.name:void 0};return r.jsx(yb,{workflow:X,detail:D[X.name],detailState:I[X.name]??"idle",onRetryDetail:()=>J(X.name),expanded:$.has(X.name),onToggle:()=>xe(X.name),runs:le,runTasks:L,onRun:()=>Me(X),onOpenRun:be=>{K(be),ae(be)},onSaveStep:(be,Ce)=>Je(X.name,be,Ce),roleAgentName:de,onSendToAgent:()=>qe(X),onEdit:()=>{ge("edit",X)},onDuplicate:()=>{ge("duplicate",X)},onDelete:()=>{ge("delete",X)}},X.name)}),r.jsx(Rc,{teamId:Ve,agents:s,compact:!0})]}),H&&r.jsx(wb,{workflow:c.find(X=>X.name===H.workflowName)??{name:H.workflowName,displayName:H.workflowName,description:"",version:"",roles:[],hasSchedule:!1,stepCount:0},run:H,detail:D[H.workflowName],tasks:L[H.id],tasksLoading:_[H.id],onClose:()=>K(null),onPauseResume:()=>{ee(H)},onCancel:()=>Z(H.id),onViewTasks:()=>{Re(H),K(null)},pausing:se===H.id,onOpenTask:X=>{K(null),ht(X)},roleAgentName:X=>{const le=H.roleMapping?.[X];return le?s.find(ye=>ye.id===le)?.name:void 0}}),A&&r.jsx(kb,{mode:A.mode,workflow:A.workflow,yaml:A.yaml,yamlLoading:A.yamlLoading,busy:A.busy,error:A.error,onClose:()=>T(null),onSubmit:ve}),O&&r.jsx($c,{chipKind:"workflow",chipLabel:Le(O),chipContent:Ke(O),agents:s,users:o,defaultTarget:kt(O),onClose:()=>U(null)}),g&&r.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50",onClick:()=>b(null),children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-full max-w-md shadow-2xl",onClick:X=>X.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(X=>r.jsxs("div",{children:[r.jsxs("label",{className:"block text-xs text-fg-secondary mb-1",children:[X.label||X.name,X.required&&r.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),X.type==="enum"&&X.options?r.jsx(Ft,{options:[{value:"",label:"—"},...X.options.map(le=>({value:le,label:le}))],value:k[X.name]??"",onChange:le=>v(ye=>({...ye,[X.name]:le})),placeholder:"—",className:"w-full"}):r.jsx("textarea",{value:k[X.name]??"",onChange:le=>{v(be=>({...be,[X.name]:le.target.value}));const ye=le.target;ye.style.height="auto";const de=parseFloat(getComputedStyle(ye).lineHeight)||18;ye.style.height=Math.min(ye.scrollHeight,de*7)+"px"},placeholder:X.default??"",rows:1,className:"input-field text-xs w-full resize-none overflow-y-auto",style:{maxHeight:`${7*1.5}em`}})]},X.name))}),ie.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:ie.map(X=>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:X.role}),r.jsx(Ft,{options:X.candidates.map(le=>({value:le.agentId,label:le.agentName+(le.agentId===X.recommended?" ★":"")})),value:je[X.role]??X.recommended??"",onChange:le=>Se(ye=>({...ye,[X.role]:le})),className:"flex-1"})]},X.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(X=>({value:X.id,label:X.name}))],value:Ne??"",onChange:X=>{const le=X||null;Be(le),C(null),le&&localStorage.setItem("markus_wf_project_last",le)},placeholder:l("work:task.workflowSelectProject","— Select a project —"),className:"w-full"})]}),w&&r.jsx("p",{className:"text-xs text-red-400 mb-3",children:w}),r.jsxs("div",{className:"flex justify-end gap-2",children:[r.jsx("button",{onClick:()=>b(null),className:"btn-secondary text-xs px-4 py-1.5",children:l("work:task.workflowCancel","Cancel")}),r.jsx("button",{onClick:nt,disabled:y||!!We,className:"btn-primary text-xs px-4 py-1.5",children:y?l("work:task.workflowStarting","Starting..."):l("work:task.workflowStartRun","Start Run")})]})]})}),F&&(()=>{const X=Object.values(f).flat().find(be=>be.id===F),le=X?L[X.id]:void 0,ye=X?.taskIds.length??0,de=le?le.filter(be=>!ir(be.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:be=>be.stopPropagation(),children:[r.jsx("h3",{className:"text-sm font-semibold text-fg-primary mb-2",children:l("work:task.workflowConfirmCancelTitle","Cancel Workflow Run")}),r.jsx("p",{className:"text-xs text-fg-secondary mb-2",children:l("work:task.workflowConfirmCancelDesc","This will cancel all running and pending tasks in this workflow run. This action cannot be undone.")}),de!==null?r.jsx("p",{className:"text-xs font-medium text-fg-primary mb-5",children:l("work:task.workflowCancelScope","将取消 {{count}} 个未完成任务(该运行共 {{total}} 个)",{count:de,total: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:()=>Pe(F),disabled:V===F,className:"px-4 py-1.5 bg-red-600 hover:bg-red-500 text-white text-xs rounded-lg font-medium transition-colors",children:V===F?l("work:task.workflowCancelling","Cancelling..."):l("work:task.workflowConfirmCancelBtn","Confirm Cancel")})]})]})})})()]})}function sy({authUser:e,previewMode:t,previewData:n}={}){const{t:s}=He(["work","common"]),o=Of(tt.WORK),a=p.useMemo(()=>jo.map(N=>({...N,label:s(`work:boardColumn.${N.id}`)})),[s]),i=p.useMemo(()=>af(s),[s]),l=p.useMemo(()=>xi(s),[s]),c=pr(),d=$f(),f=d?.leftCollapsed??!1,u=p.useRef(null),[h,m]=p.useState(0);p.useEffect(()=>{const N=u.current;if(!N)return;const G=new ResizeObserver(([Q])=>m(Q.contentRect.width));return G.observe(N),m(N.clientWidth),()=>G.disconnect()},[]);const[g,b]=p.useState(()=>{if(t)return!1;try{return localStorage.getItem(gc)==="1"}catch{return!1}}),k=p.useCallback(N=>{b(N);try{localStorage.setItem(gc,N?"1":"0")}catch{}},[]),v=p.useRef(f);p.useEffect(()=>{t||c||v.current!==f&&(v.current=f,b(f))},[f,t,c]);const y=Pf({side:"left",defaultWidth:240,minWidth:180,maxWidth:360,storageKey:"markus_work_l1"}),x=6,w=!c&&!g?y.width+x:0,C=Math.max(0,(h||window.innerWidth)-w-x-8),j=Math.max(320,Math.round(C/2)),[E,S]=p.useState("auto"),R=Math.max(320,C-280),$=E==="auto"?Math.min(j,R):E,M=Math.max(320,Math.min($,R)),D=p.useRef(M);D.current=M;const z=p.useRef(R);z.current=R;const I=p.useCallback(N=>{N.preventDefault();const G=N.clientX,Q=D.current,ce=Te=>{const Ee=Math.max(320,Math.min(z.current,Q+(G-Te.clientX)));S(Ee)},he=()=>{document.removeEventListener("mousemove",ce),document.removeEventListener("mouseup",he),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",ce),document.addEventListener("mouseup",he),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]),[P,L]=p.useState(!1),B=p.useRef(P);B.current=P,p.useEffect(()=>(Xi(tt.WORK,c&&P?1:0),()=>Xi(tt.WORK,0)),[c,P]);const[_,q]=p.useState(n?.projects??[]),[H,K]=p.useState("all"),[O,U]=p.useState(null),[A,T]=p.useState("closed"),[V,W]=p.useState("projects"),[F,Z]=p.useState(n?.board??{}),[se,ue]=p.useState({}),[ie,pe]=p.useState(n?.agents??[]),[je,Se]=p.useState([]),[Ne,Be]=p.useState(n?.users??[]),[$e,Ie]=p.useState(n?.allRequirements??[]),[Ve,ct]=p.useState(!n),[Oe,re]=p.useState(""),fe=p.useCallback(()=>{Fo(O??""),dn(!0)},[O]),xe=async N=>{if(!O){jn(N),fe();return}try{const{requirement:G}=await te.requirements.create({title:N,description:N,priority:"medium",projectId:O});pt(s("work:task.quickAddReqDone",{title:N})),Bt(),G&&Sn(G)}catch(G){pt(s("work:task.errorGeneric",{message:String(G)}))}},J=N=>{Me(N),Ke(O??""),ge(!0),pt(s("work:task.quickAddTaskHint"))},[ne,ae]=p.useState(!1),[ke,ge]=p.useState(!1),[ve,Me]=p.useState(""),[nt,Pe]=p.useState(""),[ee,Re]=p.useState("medium"),[We,ht]=p.useState(""),[Je,qe]=p.useState(""),[Le,Ke]=p.useState(""),[kt,X]=p.useState(""),[le,ye]=p.useState([]),[de,be]=p.useState("standard"),[Ce,Xe]=p.useState(()=>ba()),[Ct,At]=p.useState(""),[Et,Ye]=p.useState(!1),[ot,It]=p.useState(null),[Ht,wn]=p.useState(!1),[sn,cn]=p.useState(""),[mt,Ze]=p.useState(null),[st,Qe]=p.useState(()=>n?.initialSelectedReqId&&n.allRequirements?n.allRequirements.find(N=>N.id===n.initialSelectedReqId)??null:null);p.useEffect(()=>{n?.initialSelectedReqId&&st&&T("item")},[]);const[dt,vt]=p.useState(new Set),[gt,Ot]=p.useState(!1),[Tt,Y]=p.useState(new Set),me=p.useRef(new Set),[ze,Fe]=p.useState(null),[_e,St]=p.useState(n?.initialBoardType??"backlog"),[Rn,ss]=p.useState(null),[kn,Cr]=p.useState(null),[Er,Fs]=p.useState([]);p.useEffect(()=>Bf(tt.WORK,()=>_r.current),[]),p.useEffect(()=>qf((N,G)=>{N===tt.WORK&&yc.includes(G)&&St(G)}),[]);const zo=p.useRef(null),[Pt,Dn]=p.useState(!1),[On,Hs]=p.useState(null),[rs,vn]=p.useState(!1),$n=p.useRef(null),os=p.useRef(null),[Vs,dn]=p.useState(!1),[Pn,jn]=p.useState(""),[Bn,Ws]=p.useState(""),[bi,uf]=p.useState("medium"),[Ir,Fo]=p.useState(""),[as,qn]=p.useState(null),[yi,wi]=p.useState(""),[ki,Nn]=p.useState(""),[Ho,vi]=p.useState(!1),[ji,is]=p.useState(""),pt=p.useCallback(N=>{re(N),setTimeout(()=>re(""),3e3)},[]);p.useEffect(()=>{const N=G=>{G.key==="Escape"&&(ot?It(null):Ht?(wn(!1),cn("")):as?(qn(null),is("")):ke?(ge(!1),At("")):Vs?(dn(!1),jn(""),Ws(""),Nn("")):rs?vn(!1):A!=="closed"&&(T("closed"),Ze(null),Qe(null),c&&B.current&&L(!1)))};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[ot,Ht,as,ke,Vs,rs,A,c]);const Vt=_.find(N=>N.id===O)??null,ff=Vt?.teamIds?.[0]??null,hf=p.useMemo(()=>_.filter(N=>N.status!=="archived"),[_]),Ni=p.useCallback(()=>{O&&(Ze(null),Qe(null),T("project"),S("auto"),c&&L(!0))},[O,c]),Tr=p.useCallback(()=>{if(A==="project"){T("closed"),c&&L(!1);return}Ni()},[A,Ni,c]);p.useEffect(()=>{me.current=Tt},[Tt]);const zn=p.useCallback(async()=>{try{const{projects:N}=await te.projects.list();q(N)}catch{}},[]),Lt=p.useCallback(async()=>{const N={};H==="project"&&O&&(N.projectId=O);try{const{board:G,counts:Q}=await te.tasks.board(N);Z(G),ue(Q??{})}catch{}},[H,O]),Mr=p.useMemo(()=>Object.keys(se).filter(N=>(F[N]?.length??0)<(se[N]??0)),[F,se]),[Vo,Si]=p.useState(!1),Ci=p.useCallback(async()=>{if(Vo)return;const N=Mr;if(N.length!==0){Si(!0);try{const Q={};H==="project"&&O&&(Q.projectId=O);const ce=await Promise.all(N.map(async he=>{const Te=F[he]?.length??0,Ee=Math.floor(Te/100)+1;try{const oe=await te.tasks.list({...Q,status:he,page:Ee,pageSize:100});return{status:he,tasks:oe.tasks??[]}}catch{return{status:he,tasks:[]}}}));Z(he=>{const Te={...he};for(const{status:Ee,tasks:oe}of ce){if(!oe.length)continue;const xt=new Set((Te[Ee]??[]).map(Mt=>Mt.id)),Wt=oe.filter(Mt=>!xt.has(Mt.id));Wt.length&&(Te[Ee]=[...Te[Ee]??[],...Wt])}return Te})}finally{Si(!1)}}},[Vo,Mr,F,H,O]),Ks=p.useCallback(async()=>{try{const{agents:N}=await te.agents.list();pe(N)}catch{}},[]),Ei=p.useCallback(async()=>{try{const{teams:N}=await te.teams.list();Se(N.map(G=>({id:G.id,name:G.name})))}catch{}},[]),Ii=p.useCallback(async()=>{try{const{users:N}=await te.users.list(e?.orgId);Be(N)}catch{}},[e?.orgId]),Bt=p.useCallback(async()=>{try{const{requirements:N}=await te.requirements.list({});Ie(N)}catch{}},[]),Ti=p.useCallback(async()=>{await Promise.all([zn(),Lt(),Ks(),Ii(),Bt(),Ei()]),ct(!1)},[zn,Lt,Ks,Ii,Bt,Ei]);p.useEffect(()=>{t||Ti()},[t,Ti]),p.useEffect(()=>{!t||!n||(q(n.projects??[]),Z(n.board??{}),pe(n.agents??[]),Be(n.users??[]),Ie(n.allRequirements??[]))},[t,n]);const Ar=p.useCallback(N=>{W("items"),Ze(G=>G?.id===N.id&&A==="item"?(T("closed"),c&&B.current&&L(!1),null):(T("item"),S("auto"),c&&(L(!0),history.pushState({mobileDetail:tt.WORK},"",window.location.hash)),N)),Qe(null)},[c,A]),Lr=p.useCallback(N=>{W("items"),Qe(G=>G?.id===N.id&&A==="item"?(T("closed"),c&&B.current&&L(!1),null):(T("item"),S("auto"),c&&(L(!0),history.pushState({mobileDetail:tt.WORK},"",window.location.hash)),N)),Ze(null)},[c,A]),Fn=p.useCallback(()=>{Ze(null),Qe(null),T("closed"),c&&B.current&&L(!1)},[c]),un=p.useRef(mt);un.current=mt;const fn=p.useRef(st);fn.current=st;const Hn=p.useRef(A);Hn.current=A;const ls=p.useRef(V);ls.current=V;const cs=p.useRef(g);cs.current=g;const _r=p.useRef(_e);_r.current=_e;const mf=p.useCallback(()=>{Ze(null),fn.current||(T("closed"),c&&B.current&&L(!1))},[c]);p.useEffect(()=>{if(!c)return;const N=()=>{B.current&&(L(!1),Ze(null),Qe(null),T("closed"))};return window.addEventListener("popstate",N),()=>window.removeEventListener("popstate",N)},[c]),p.useEffect(()=>{if(t||!o)return;Lt(),Ks(),Bt();const N=un.current?12e4:45e3,G=setInterval(()=>{Lt(),Ks(),Bt()},N);let Q=null;const ce=()=>{Q||(Q=setTimeout(()=>{Q=null,Lt()},800))};let he=null;const Te=()=>{he||(he=setTimeout(()=>{he=null,Bt()},800))},Ee=$t.on("task:update",at=>{qt("/taskboard"),ce();const Ae=at?.payload;Ae?.taskId&&(Ze(ft=>{if(!ft||ft.id!==Ae.taskId)return ft;const Ge={};return typeof Ae.status=="string"&&(Ge.status=Ae.status),Array.isArray(Ae.deliverables)&&(Ge.deliverables=Ae.deliverables),Array.isArray(Ae.notes)&&(Ge.notes=Ae.notes),Ae.result!==void 0&&(Ge.result=Ae.result),{...ft,...Ge}}),un.current?.id===Ae.taskId&&(qt("/tasks/"+Ae.taskId),te.tasks.get(Ae.taskId).then(ft=>{ft.task&&Ze(Ge=>Ge?.id===ft.task.id?ft.task:Ge)}).catch(()=>{})))}),oe=$t.on("task:create",()=>{ce()}),Wt=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(at=>$t.on(at,Ae=>{qt("/requirements"),Te();const ft=Ae?.payload,Ge=ft?.id??ft?.requirementId;Ge&&fn.current?.id===Ge&&(qt("/requirements/"+Ge),te.requirements.get(Ge).then(mn=>{mn.requirement&&Qe(Kn=>Kn?.id===mn.requirement.id?mn.requirement:Kn)}).catch(()=>{}))})),Mt=()=>{qt("/taskboard"),qt("/tasks"),qt("/requirements"),Lt(),Bt(),un.current&&te.tasks.get(un.current.id).then(at=>{at.task&&Ze(Ae=>Ae?.id===at.task.id?at.task:Ae)}).catch(()=>{}),fn.current&&te.requirements.get(fn.current.id).then(at=>{at.requirement&&Qe(Ae=>Ae?.id===at.requirement.id?at.requirement:Ae)}).catch(()=>{})};return window.addEventListener("markus:data-changed",Mt),()=>{clearInterval(G),Ee(),oe(),Wt.forEach(at=>at()),window.removeEventListener("markus:data-changed",Mt),Q&&clearTimeout(Q),he&&clearTimeout(he)}},[t,o,Lt,Ks,Bt]);const Mi=p.useRef(F);Mi.current=F;const Ai=p.useRef($e);Ai.current=$e,p.useEffect(()=>{const N=un.current;if(!N)return;const Q=Object.values(F).flat().find(ce=>ce.id===N.id);Q&&Q.updatedAt!==N.updatedAt&&Ze(Q)},[F]),p.useEffect(()=>{const N=fn.current;if(!N)return;const G=$e.find(Q=>Q.id===N.id);G&&G.updatedAt!==N.updatedAt&&Qe(G)},[$e]);const rn=p.useCallback(N=>{if(!N){Y(new Set),U(null),K("all"),history.replaceState(null,"",zr(tt.WORK)),te.tasks.board({}).then(G=>Z(G.board)).catch(()=>{});return}U(N),K("project"),Y(new Set),history.replaceState(null,"",zr(tt.WORK,N)),te.tasks.board({projectId:N}).then(G=>Z(G.board)).catch(()=>{})},[]),[Wo,Us]=p.useState(!1),Ys=p.useCallback((N,G)=>{Ze(N),Qe(null),T("item"),W("items"),S("auto"),G?.scrollToComments&&Us(!0),c&&L(!0)},[c]),Sn=p.useCallback((N,G)=>{Qe(N),Ze(null),T("item"),W("items"),S("auto"),G?.scrollToComments&&Us(!0),c&&L(!0)},[c]),Li=p.useCallback(N=>{rn(N.projectId),Hs(null),vt(new Set),Y(new Set),Ot(!1),Dn(!0),Cr(N),Fs([]),te.tasks.list({requirementId:N.id,pageSize:200}).then(({tasks:G})=>{G?.length&&Fs(G)}).catch(()=>{}),Sn(N),ss(`req-${N.id}`),St("dag")},[rn,Sn]),ds=p.useRef(null);p.useEffect(()=>{const N=ds.current||localStorage.getItem("markus_nav_openTask");if(!N)return;const Q=Object.values(F).flat().find(ce=>ce.id===N);Q?(ds.current=null,rn(Q.projectId),Ys(Q),localStorage.removeItem("markus_nav_openTask")):ds.current||(ds.current=N,localStorage.removeItem("markus_nav_openTask"),te.tasks.get(N).then(ce=>{ce.task&&(ds.current=null,rn(ce.task.projectId),Ys(ce.task))}).catch(()=>{ds.current=null,pt(s("work:task.notFound",{id:N}))}))},[F,Ys,rn,o,pt,s]);const us=p.useRef(null);p.useEffect(()=>{const N=us.current||localStorage.getItem("markus_nav_openRequirement");if(!N)return;const G=$e.find(Q=>Q.id===N);G?(us.current=null,rn(G.projectId),Sn(G),localStorage.removeItem("markus_nav_openRequirement")):us.current||(us.current=N,localStorage.removeItem("markus_nav_openRequirement"),te.requirements.get(N).then(Q=>{Q.requirement&&(us.current=null,rn(Q.requirement.projectId),Sn(Q.requirement))}).catch(()=>{us.current=null}))},[$e,Sn,rn,o]);const Gt=p.useCallback((N,G)=>{Y(new Set),U(N),K("project"),W(g?"items":"projects"),G?.keepItemDetail||(Ze(null),Qe(null),T(Q=>Q==="closed"?Q:"project")),history.replaceState(null,"",zr(tt.WORK,N))},[g]),on=p.useCallback(N=>{Y(new Set),U(null),K("all"),W(g?"items":"projects"),N?.keepItemDetail||(Ze(null),Qe(null),T(G=>G==="closed"?G:G==="project"?"closed":"empty")),history.replaceState(null,"",zr(tt.WORK))},[g]),Vn=p.useRef(!1);p.useEffect(()=>{if(Vn.current)return;const N=window.location.hash.slice(1).split("/");if(Fr(N[0])===tt.WORK&&N[1]){Vn.current=!0,Gt(N[1],{keepItemDetail:!0});return}const G=localStorage.getItem("markus_nav_projectId");if(G){Vn.current=!0,localStorage.removeItem("markus_nav_projectId"),Gt(G,{keepItemDetail:!0});return}Vn.current=!0,on({keepItemDetail:!0})},[]),p.useEffect(()=>{if(!Ve){if(!O){Vn.current=!0,H!=="all"&&K("all");return}if(_.some(N=>N.id===O)){Vn.current=!0;return}Vn.current=!0,on({keepItemDetail:!0})}},[Ve,_,O,on,H]);const pf=p.useRef(Fr(window.location.hash.slice(1).split("/")[0]));p.useEffect(()=>{if(t)return;const N=()=>{const Q=window.location.hash.slice(1).split("/"),ce=Fr(Q[0]);pf.current=ce,ce===tt.WORK&&(Q[1]?Gt(Q[1],{keepItemDetail:!0}):on({keepItemDetail:!0}))},G=async Q=>{const ce=Q.detail;if(Fr(ce.page)===tt.WORK){if(ce.params?.openTask){const he=ce.params.openTask,Te=ce.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let Ee=Object.values(Mi.current).flat().find(oe=>oe.id===he);if(!Ee)try{Ee=(await te.tasks.get(he)).task}catch{}Ee?(rn(Ee.projectId),Ys(Ee,{scrollToComments:Te})):pt(s("work:task.notFound",{id:he}))}if(ce.params?.openRequirement){const he=ce.params.openRequirement,Te=ce.params.scrollToComments==="true";let Ee=Ai.current.find(oe=>oe.id===he);if(!Ee)try{Ee=(await te.requirements.get(he)).requirement}catch{}Ee&&(rn(Ee.projectId),Sn(Ee,{scrollToComments:Te}))}if(ce.params?.projectId&&Gt(ce.params.projectId),ce.params?.statusFilter){const he=ce.params.statusFilter;localStorage.removeItem("markus_nav_statusFilter"),Ab.has(he)&&Dn(!0),Hs(he)}}};return window.addEventListener("markus:navigate",G),window.addEventListener("hashchange",N),()=>{window.removeEventListener("markus:navigate",G),window.removeEventListener("hashchange",N)}},[t]);const gf=N=>{ae(!1),pt(s("work:task.projectCreated")),q(G=>G.some(Q=>Q.id===N.id)?G:[...G,N]),Gt(N.id),zn()},xf=async N=>{try{await te.projects.delete(N),O===N&&on(),pt(s("work:task.projectDeleted")),zn(),Lt()}catch(G){pt(s("work:task.errorGeneric",{message:String(G)}))}},_i=async()=>{if(!ve||!We||!Je||Et)return;At("");const N=Je.startsWith("human:"),G=Je.replace(/^(human|agent):/,"");if(We===G&&!N){pt(s("work:task.assignedReviewerDifferent"));return}const Q=Le||void 0,ce=kt||void 0;Ye(!0);try{const{task:he}=await te.tasks.create(ve,nt,We,G,ee,Q,le.length>0?le:void 0,ce,de!=="standard"?de:void 0,de==="scheduled"?Qc(Ce):void 0,N?"human":"agent");Me(""),Pe(""),ye([]),X(""),be("standard"),Xe(ba()),ge(!1),Lt(),he&&Ys(he)}catch(he){const Ee=`work:task.errorCode_${(he instanceof Oc?he.code:void 0)||"unknown"}`,oe=s(Ee,{defaultValue:""});At(oe||s("work:task.errorCreatingTask",{message:he instanceof Error?he.message:String(he)}))}finally{Ye(!1)}},Ri=async()=>{if(!(!sn.trim()||!Le))try{const{requirement:N}=await te.requirements.create({title:sn.trim(),description:sn.trim(),priority:"medium",projectId:Le});cn(""),wn(!1),pt(s("work:task.requirementCreated")),Bt(),N&&X(N.id)}catch(N){At(N instanceof Error?N.message:String(N))}},fs=N=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:N}))},Di=()=>{qt("/taskboard"),Lt(),mt&&(fs({taskId:mt.id}),qt("/tasks/"+mt.id),te.tasks.get(mt.id).then(N=>{N.task&&Ze(G=>G?.id===N.task.id?N.task:G)}).catch(()=>{}))},Wn=()=>{qt("/requirements"),Bt(),st&&(qt("/requirements/"+st.id),te.requirements.get(st.id).then(N=>{N.requirement&&Qe(G=>G?.id===N.requirement.id?N.requirement:G)}).catch(()=>{}))},Oi=async()=>{if(!Ho){if(!Pn.trim()){Nn(s("work:task.pleaseReqTitle"));return}if(!Bn.trim()){Nn(s("work:task.pleaseReqDesc"));return}if(!Ir){Nn(s("work:task.pleaseReqProject"));return}Nn(""),vi(!0);try{const{requirement:N}=await te.requirements.create({title:Pn.trim(),description:Bn.trim(),priority:bi,projectId:Ir});pt(s("work:task.requirementCreated")),jn(""),Ws(""),dn(!1),Bt(),N&&Sn(N)}catch(N){Nn(N instanceof Error?N.message:String(N))}finally{vi(!1)}}},Ko=async N=>{try{await te.requirements.approve(N),pt(s("work:task.requirementApproved")),fs({requirementId:N}),Wn(),Lt()}catch(G){pt(s("work:task.errorGeneric",{message:String(G)}))}},bf=async()=>{if(as){is("");try{await te.requirements.reject(as,yi),pt(s("work:task.requirementRejected")),fs({requirementId:as}),qn(null),wi(""),is(""),Wn()}catch(N){is(N instanceof Error?N.message:String(N))}}},$i=async N=>{try{await te.requirements.cancel(N),pt(s("work:task.requirementCancelled")),fs({requirementId:N}),Wn()}catch(G){pt(s("work:task.errorGeneric",{message:String(G)}))}},yf=(N,G)=>{$n.current=G,os.current=null,N.dataTransfer.effectAllowed="move",N.dataTransfer.setData("text/plain",`task:${G.id}`),N.currentTarget.style.opacity="0.4"},wf=(N,G)=>{os.current=G,$n.current=null,N.dataTransfer.effectAllowed="move",N.dataTransfer.setData("text/plain",`req:${G.id}`),N.currentTarget.style.opacity="0.4"},Pi=N=>{N.currentTarget.style.opacity="1",$n.current=null,os.current=null,Fe(null)},kf=(N,G)=>{N.preventDefault(),N.dataTransfer.dropEffect="move",ze!==G&&Fe(G)},vf=(N,G)=>{const Q=N.currentTarget.getBoundingClientRect(),{clientX:ce,clientY:he}=N;(ce<Q.left||ce>Q.right||he<Q.top||he>Q.bottom)&&ze===G&&Fe(null)},jf=async(N,G)=>{N.preventDefault(),Fe(null);const Q=$n.current,ce=os.current;if(Q){const he=a.find(Ee=>Ee.id===G);if(!he)return;const Te=he.dropStatus;if(Q.status===Te||Q.status==="pending")return;try{await te.tasks.updateStatus(Q.id,Te),Lt()}catch{}}else if(ce){const he=lf[G];if(!he||ce.status===he)return;try{await te.requirements.updateStatus(ce.id,he),Bt()}catch{}}},Bi=N=>{vt(G=>{const Q=new Set(G);return Q.has(N)?Q.delete(N):Q.add(N),Q})},Rr=N=>{Gt(N)},Nf=new Set(["rejected","cancelled","archived"]),Uo=N=>Nf.has(N.status),Gs=(N,G=!1)=>Zx(N,{showClosed:Pt,includeClosed:G,statusFilter:On,viewMode:H,selectedProjectId:O,projectFilter:Tt,agentFilter:dt,myTasksOnly:gt,currentUserId:e?.id}),Sf=p.useMemo(()=>{const N=new Map;for(const G of Object.values(F))for(const Q of G)N.set(Q.id,Q);return N},[F]),Cf=p.useMemo(()=>new Set(ie.map(N=>N.id)),[ie]),qi=N=>N.statuses.flatMap(G=>Gs(F[G]??[])),hn=p.useMemo(()=>{let N=$e;return Pt||(N=N.filter(G=>!Uo(G))),H==="project"&&O&&(N=N.filter(G=>G.projectId===O)),Tt.size>0&&(N=N.filter(G=>G.projectId&&Tt.has(G.projectId))),dt.size>0&&(N=N.filter(G=>dt.has(G.createdBy))),gt&&e?.id&&(N=N.filter(G=>G.createdBy===e.id)),N},[$e,Pt,H,O,Tt,dt,gt,e?.id,Cf]),zi=p.useCallback(N=>hn.filter(G=>ho[G.status]===N.id),[hn]),Ef=a.filter(N=>{if(N.id==="failed"||N.id==="closed"){const G=qi(N),Q=zi(N);return G.length+Q.length>0}return!0}),Xs=((se.archived??0)+(se.rejected??0)+(se.cancelled??0)||Object.values(F).flat().filter(N=>Uo(N)).length)+$e.filter(N=>Uo(N)).length,Fi=p.useMemo(()=>{const N=Object.values(F).flat(),G=new Set;for(const Q of N)Q.assignedAgentId&&!ir(Q.status)&&(!O||Q.projectId===O)&&G.add(Q.assignedAgentId);return[...ie].sort((Q,ce)=>{const he=G.has(Q.id)?0:1,Te=G.has(ce.id)?0:1;return he-Te})},[ie,F,O]),Dr=p.useMemo(()=>{const N=new Map,G=[];for(const ce of Fi)if(ce.teamId){const he=N.get(ce.teamId)??[];he.push(ce.id),N.set(ce.teamId,he)}else G.push(ce);const Q=[];for(const ce of G)Q.push({kind:"agent",agent:ce});for(const ce of je){const he=N.get(ce.id);he&&he.length>0&&Q.push({kind:"team",id:ce.id,name:ce.name,agentIds:he})}return Q},[Fi,je]);p.useMemo(()=>{const N=Object.values(F).flat(),G=new Set;for(const ce of N)ce.projectId&&!ir(ce.status)&&G.add(ce.projectId);return[...Pt?_:_.filter(ce=>ce.status!=="archived")].sort((ce,he)=>{const Te=ce.status==="archived"?1:0,Ee=he.status==="archived"?1:0;if(Te!==Ee)return Te-Ee;const oe=G.has(ce.id)?0:1,xt=G.has(he.id)?0:1;return oe!==xt?oe-xt:ce.name.localeCompare(he.name)})},[_,F,Pt]);const Or=p.useMemo(()=>[..._].sort((N,G)=>{const Q=N.status==="archived"?1:0,ce=G.status==="archived"?1:0;return Q!==ce?Q-ce:N.name.localeCompare(G.name)}),[_]),$r=p.useMemo(()=>{const N={};for(const G of Object.values(F))for(const Q of G){const ce=Q.projectId??"__none__";N[ce]=(N[ce]??0)+1}return N},[F]),Pr=Object.values($r).reduce((N,G)=>N+G,0),If=O?$r[O]??0:Pr,Hi=p.useMemo(()=>{const N=Gs(Object.values(F).flat()),G=[];if(_e==="kanban"){for(const ce of jo){const he=ce.statuses.flatMap(oe=>N.filter(xt=>xt.status===oe)),Ee=[...hn.filter(oe=>ho[oe.status]===ce.id).map(oe=>({kind:"req",data:oe,time:new Date(oe.updatedAt??oe.createdAt).getTime()})),...he.map(oe=>({kind:"task",data:oe,time:new Date(oe.updatedAt??oe.createdAt??0).getTime()}))];Ee.sort((oe,xt)=>xt.time-oe.time);for(const oe of Ee)oe.kind==="req"?G.push({kind:"req",data:oe.data}):G.push({kind:"task",data:oe.data})}return G}const Q=[];for(const ce of N){const he=cf(ce.status);Q.push({kind:"task",data:ce,groupOrder:No[he]??5,time:new Date(ce.updatedAt??ce.createdAt??0).getTime()})}for(const ce of hn){const he=ho[ce.status]??"todo";Q.push({kind:"req",data:ce,groupOrder:No[he]??5,time:new Date(ce.updatedAt??ce.createdAt).getTime()})}return Q.sort((ce,he)=>ce.groupOrder!==he.groupOrder?ce.groupOrder-he.groupOrder:he.time-ce.time),Q.map(ce=>ce.kind==="req"?{kind:"req",data:ce.data}:{kind:"task",data:ce.data})},[F,hn,_e,Pt,On,O,Tt,dt,gt,e?.id,H]),Br=p.useRef(Hi);Br.current=Hi;const Vi=p.useRef(Or);Vi.current=Or;const Yo=p.useRef(O);Yo.current=O;const hs=p.useCallback(N=>{N.kind==="req"?(Qe(N.data),Ze(null)):(Ze(N.data),Qe(null)),T("item"),S("auto"),W("items")},[]),Wi=p.useCallback(()=>{if(Hn.current==="item"||Hn.current==="empty"){T("closed"),Ze(null),Qe(null);return}if(un.current||fn.current){T("item"),S("auto"),W("items");return}const N=Br.current;if(N.length>0){hs(N[0]);return}Ze(null),Qe(null),T("empty"),S("auto")},[hs]);p.useEffect(()=>{if(!c)if(g){if(W("items"),Hn.current==="project")if(un.current||fn.current)T("item");else{const N=Br.current;N.length>0?hs(N[0]):T("closed")}}else ls.current==="items"&&Hn.current==="closed"||!g&&Hn.current==="closed"&&W("projects")},[g,c,hs]);const Zs=d?.keyboardPane??"content",Ki=p.useRef(Zs);if(p.useEffect(()=>{if(t||c||!o)return;const N=Ki.current;Ki.current=Zs,Zs==="l1"&&(W("projects"),N!=="l1"&&cs.current&&(k(!1),d?.setLeftCollapsed(!1)))},[Zs,t,c,o,k,d]),p.useEffect(()=>{if(t||c||!o)return;const N=navigator.platform.toUpperCase().includes("MAC"),G=Q=>{if(d?.keyboardPane==="l0")return;const ce=N?Q.metaKey&&!Q.ctrlKey:Q.ctrlKey&&!Q.metaKey;if(Q.ctrlKey&&!Q.metaKey&&Q.key==="Tab"){Q.preventDefault();const Ae=yc,ft=Ae.indexOf(_r.current),Ge=Q.shiftKey?Ae[(ft-1+Ae.length)%Ae.length]:Ae[(ft+1)%Ae.length];St(Ge);return}if(ce&&!Q.altKey&&!Q.shiftKey){const Ae=Q.key.toLowerCase();if(Ae==="j"){Q.preventDefault(),Tr();return}if(Ae==="l"){Q.preventDefault(),Wi();return}}if(ce||Q.altKey||Q.ctrlKey||Q.metaKey||Ff(Q.target))return;const he=Q.key.length===1?Q.key.toLowerCase():Q.key;if(he==="h"||he==="ArrowLeft"){if(cs.current){Q.preventDefault(),k(!1),d?.setLeftCollapsed(!1),W("projects"),d?.setKeyboardPane("l1");return}if(ls.current==="items"){Q.preventDefault(),W("projects"),d?.setKeyboardPane("l1");return}Q.preventDefault(),d?.setL0FocusPageId(tt.WORK),d?.setLeftCollapsed(!1),d?.setKeyboardPane("l0");return}if((he==="l"||he==="ArrowRight"||he==="Tab"&&!Q.shiftKey)&&!cs.current&&ls.current==="projects"){Q.preventDefault(),W("items"),d?.setKeyboardPane("content");return}if((he==="l"||he==="ArrowRight")&&(cs.current||ls.current==="items")){Q.preventDefault();return}const Te=he==="j"||he==="ArrowDown"?1:he==="k"||he==="ArrowUp"?-1:0;if(!Te)return;if((cs.current?"items":ls.current)==="projects"){Q.preventDefault(),d?.setKeyboardPane("l1");const Ae=Vi.current,ft=Ae.length+1;if(Ae.length===0)return;const Ge=Yo.current==null?0:Ae.findIndex(ms=>ms.id===Yo.current)+1,mn=Ge<0?0:Ge,Kn=Math.max(0,Math.min(ft-1,mn+Te));if(Kn===0)on(),requestAnimationFrame(()=>{document.querySelector('[data-project-id="__all__"]')?.scrollIntoView({block:"nearest"})});else{const ms=Ae[Kn-1];Gt(ms.id),Hn.current!=="closed"&&(T("project"),Ze(null),Qe(null)),requestAnimationFrame(()=>{document.querySelector(`[data-project-id="${ms.id}"]`)?.scrollIntoView({block:"nearest"})})}return}const oe=_r.current;if(oe!=="backlog"&&oe!=="kanban")return;Q.preventDefault(),d?.setKeyboardPane("content");const xt=Br.current;if(xt.length===0){T(Ae=>Ae==="closed"?"empty":Ae);return}const Wt=un.current?.id??fn.current?.id??null;let Mt=Wt?xt.findIndex(Ae=>Ae.data.id===Wt):-1;Mt<0&&(Mt=Te>0?-1:0);const at=Math.max(0,Math.min(xt.length-1,Mt+Te));hs(xt[at]),requestAnimationFrame(()=>{document.querySelector(`[data-work-item-id="${xt[at].data.id}"]`)?.scrollIntoView({block:"nearest"})})};return document.addEventListener("keydown",G,!0),()=>document.removeEventListener("keydown",G,!0)},[t,c,o,Tr,Wi,Gt,on,hs,k,d]),Ve)return r.jsx(Qf,{label:s("work:task.loadingPage")});const Ui=A!=="closed"||!!(mt||st),qr=!c&&!!(mt&&st)&&A==="item",Yi=c?P:Ui;return r.jsxs("div",{ref:u,className:"flex-1 overflow-hidden flex bg-surface-primary",children:[!c&&r.jsx(Ux,{projects:Or,selectedProjectId:O,allSelected:H==="all"&&!O,taskCounts:$r,totalTaskCount:Pr,onSelectAll:()=>{on(),W("projects")},onSelectProject:N=>{Gt(N),W("projects")},onEditProject:N=>{Gt(N),Ze(null),Qe(null),T("project"),W("projects")},onCreateProject:()=>ae(!0),onCollapse:()=>{const N=!g;k(N),d?.setLeftCollapsed(N)},width:y.width,onResizeStart:y.onResizeStart,hidden:g,focused:Zs==="l1"&&V==="projects"&&!g,onActivate:()=>W("projects")}),r.jsxs("div",{"data-keyboard-pane":"content",onPointerDown:()=>W("items"),className:`${c?"flex-1 min-w-0":qr?"w-0 shrink-0 overflow-hidden":"flex-1 min-w-0"} overflow-hidden flex flex-col bg-surface-primary`,style:c&&P?{display:"none"}:void 0,children:[Oe&&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:Oe}),c?r.jsxs("div",{className:"shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[r.jsx(zf,{}),Vt?r.jsxs("div",{className:"flex items-center gap-1 min-w-0 flex-1",children:[r.jsx("span",{className:"text-sm font-semibold text-fg-primary truncate",children:Vt.name}),r.jsx("button",{onClick:Tr,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${A==="project"?"bg-surface-overlay text-fg-primary":"text-fg-tertiary"}`,children:r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3"}),r.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):r.jsx("h2",{className:"text-sm font-semibold text-fg-primary min-w-0 flex-1 truncate",children:s("work:task.projectsCount",{count:_.length})}),r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx("button",{onClick:()=>ae(!0),className:"px-2 py-1 text-[11px] bg-brand-600 text-on-brand rounded-md",children:s("work:task.shortProject")}),r.jsx("button",{onClick:fe,className:"px-2 py-1 text-[11px] bg-brand-600 text-on-brand rounded-md",children:s("work:task.shortReq")}),r.jsx("button",{onClick:()=>{Ke(O??""),ge(!0)},className:"px-2 py-1 text-[11px] border border-amber-500/60 text-amber-600 rounded-md",children:s("work:task.shortTask")})]})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 px-3 py-1.5 min-h-9",children:[r.jsx("div",{className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag","workflows"].map(N=>r.jsx("button",{onClick:()=>St(N),className:`px-2 py-0.5 text-[10px] font-medium whitespace-nowrap transition-colors ${_e===N?"bg-brand-600/25 text-brand-500":"text-fg-tertiary"}`,children:N==="backlog"?s("work:task.backlog"):N==="kanban"?s("work:task.kanban"):N==="dag"?s("work:task.dag"):s("work:task.workflows","Workflows")},N))}),Xs>0&&r.jsx("button",{onClick:()=>Dn(N=>!N),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Pt?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:Pt?s("work:task.hideArchived"):s("work:task.archivedCount",{count:Xs})}),r.jsx("div",{className:"flex-1"}),On&&r.jsxs("button",{onClick:()=>Hs(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.${On==="in_progress"?"inProgress":On}`),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"})]})]}),(hf.length>1||ie.length>0||e?.id)&&r.jsxs("button",{onClick:()=>vn(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${dt.size>0||gt?"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:dt.size+(gt?1:0)>0?s("work:task.filterWithCount",{count:dt.size+(gt?1:0)}):s("work:task.filter")})]})]})]}):r.jsxs("div",{"data-electron-drag":!0,className:"flex items-center gap-3 px-6 h-14 shrink-0",children:[r.jsx("button",{"data-no-drag":!0,type:"button",onClick:()=>{const N=!g;k(N),d?.setLeftCollapsed(N),W("projects")},className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors shrink-0 ${g?"bg-brand-500/15 text-brand-500 hover:bg-brand-500/25":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,title:s(g?"work:task.expand":"work:task.collapse"),children:r.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),r.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),Vt?r.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1 shrink-0 min-w-0",children:[r.jsx(Sb,{value:Vt.name,onSave:async N=>{await te.projects.update(Vt.id,{name:N}),zn()},className:"text-sm font-semibold text-fg-primary"}),r.jsx("button",{onClick:Tr,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${A==="project"?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:`${s("work:project.settingsTitle")} (⌘J)`,children:r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3"}),r.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):r.jsx("h2",{className:"text-sm font-semibold text-fg-primary shrink-0",children:s("work:task.projectsCount",{count:_.length})}),Xs>0&&r.jsx("button",{onClick:()=>Dn(N=>!N),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${Pt?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:Pt?s("work:task.hideArchivedWithCount",{count:Xs}):s("work:task.archivedCount",{count:Xs})}),r.jsx("div",{"data-no-drag":!0,className:"flex items-center border border-border-default/60 rounded-md overflow-hidden shrink-0",children:["backlog","kanban","dag","workflows"].map(N=>r.jsx("button",{onClick:()=>St(N),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${_e===N?"bg-brand-600/25 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:N==="backlog"?s("work:task.backlog"):N==="kanban"?s("work:task.kanban"):N==="dag"?s("work:task.dag"):s("work:task.workflows","Workflows")},N))}),r.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1.5 shrink-0",children:[r.jsx("button",{onClick:()=>ae(!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:fe,className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-on-brand text-xs rounded-lg font-medium transition-colors",children:s("work:task.newRequirement")}),r.jsx("button",{onClick:()=>{Ke(O??""),ge(!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&&_e!=="workflows"&&(Dr.length>0||e?.id)&&(If>0||hn.length>0||dt.size>0||gt)&&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:()=>{vt(new Set),Ot(!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 ${dt.size>0||gt?"visible opacity-100":"invisible opacity-0"}`,children:s("work:task.clear")}),e?.id&&r.jsx("button",{type:"button",onClick:()=>Ot(N=>!N),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${gt?"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")}),Dr.map(N=>{if(N.kind==="team"){const ce=N.agentIds.every(Te=>dt.has(Te)),he=!ce&&N.agentIds.some(Te=>dt.has(Te));return r.jsxs("button",{onClick:()=>{vt(Te=>{const Ee=new Set(Te);if(ce)for(const oe of N.agentIds)Ee.delete(oe);else for(const oe of N.agentIds)Ee.add(oe);return Ee})},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${ce?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":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"})}),N.name,r.jsx("span",{className:"text-[9px] text-fg-muted",children:N.agentIds.length})]},`team-${N.id}`)}const G=N.agent,Q=dt.has(G.id);return r.jsxs("button",{onClick:()=>Bi(G.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Q?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[r.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${Q?"bg-brand-600 text-on-brand":"bg-surface-overlay text-fg-secondary"}`,children:G.name[0]?.toUpperCase()}),G.name]},G.id)})]}),_.length===0?r.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:r.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[r.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:r.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:r.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),r.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:s("work:task.emptyNoProjectsTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:s("work:task.emptyNoProjectsHint")}),r.jsx("button",{onClick:()=>ae(!0),className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-on-brand rounded-lg font-medium transition-colors",children:s("work:project.newProject")})]})}):Gs(Object.values(F).flat()).length===0&&hn.length===0?r.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:r.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[r.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:r.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:[r.jsx("path",{d:"M9 11l3 3L22 4"}),r.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})}),dt.size>0||gt?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:()=>{vt(new Set),Ot(!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:fe,className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs bg-brand-600 hover:bg-brand-500 text-on-brand rounded-lg font-medium transition-colors",children:s("work:task.createRequirementCta")}),r.jsx("button",{onClick:()=>{Ke(O??""),ge(!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")})]}),H==="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:()=>on(),className:"inline text-brand-500 hover:text-brand-500 hover:underline",children:s("work:allProjects")})]})]})]})}):_e==="backlog"?r.jsx("div",{className:"flex-1 min-h-0 flex flex-col",children:r.jsx(zb,{tasks:Gs(Object.values(F).flat()),requirements:hn,agents:ie,projects:_,onTaskClick:N=>Ar(N),onReqClick:N=>Lr(N),onRefresh:()=>{Lt(),Bt()},selectedTaskId:mt?.id,selectedReqId:st?.id,onQuickCreateReq:xe,onQuickCreateTask:J,onLoadMore:()=>{Ci()},hasMore:Mr.length>0,loadingMore:Vo})}):_e==="workflows"?r.jsx("div",{className:"flex-1 min-h-0 flex flex-col relative",children:r.jsx(Wb,{teamId:null,defaultTeamId:ff,projectId:O,agents:ie,users:Ne,projects:_,onViewRunTasks:N=>{const G=$e.find(Q=>Q.id===N);G?Li(G):te.requirements.get(N).then(Q=>{Q.requirement&&(Ie(ce=>[...ce,Q.requirement]),Li(Q.requirement))}).catch(()=>{})}})}):_e==="dag"?r.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",children:[r.jsx(Wx,{tasks:(()=>{const N=Gs(Object.values(F).flat(),!0);if(t&&st){const Q=new Set(st.taskIds??[]);return N.filter(ce=>Q.has(ce.id))}if(Er.length===0)return N;const G=new Map(N.map(Q=>[Q.id,Q]));for(const Q of Er)G.set(Q.id,Q);return[...G.values()]})(),requirements:(()=>{const N=t&&st?[st]:hn;return!kn||N.some(G=>G.id===kn.id)?N:[kn,...N]})(),agents:ie,showArchived:Pt,onShowArchivedChange:Dn,onTaskClick:N=>Ar(N),onReqClick:N=>Lr(N),onCollapseDAG:()=>{Ze(null),Qe(null),ss(null),Cr(null),Fs([])},onDependencyChange:Lt,selectedTaskId:mt?.id,selectedReqId:st?.id,hasDetailPanel:Ui,defaultExpandedNodeId:Rn??(t&&st?`req-${st.id}`:void 0),previewMode:t}),c&&r.jsx("button",{onClick:()=>St("kanban"),className:"absolute left-3 top-1/2 -translate-y-1/2 w-11 h-11 rounded-full bg-brand-500 border border-brand-400/60 shadow-xl shadow-brand-500/30 flex items-center justify-center text-on-brand active:bg-brand-400 backdrop-blur-sm z-10",title:s("work:task.backToKanban"),children:r.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 20 20",fill:"currentColor",children:r.jsx("path",{fillRule:"evenodd",d:"M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z",clipRule:"evenodd"})})}),c&&r.jsx("button",{onClick:()=>St("workflows"),className:"absolute right-3 top-1/2 -translate-y-1/2 w-11 h-11 rounded-full bg-brand-500 border border-brand-400/60 shadow-xl shadow-brand-500/30 flex items-center justify-center text-on-brand active:bg-brand-400 backdrop-blur-sm z-10",title:s("work:task.toWorkflows","Workflows"),children:r.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polyline",{points:"9 18 15 12 9 6"})})})]}):r.jsx("div",{ref:zo,className:"flex-1 min-h-0 overflow-auto px-4 py-5",onScroll:N=>{if(Mr.length===0)return;const G=N.currentTarget;G.scrollTop+G.clientHeight>=G.scrollHeight-240&&Ci()},children:r.jsx("div",{className:"flex gap-3 items-stretch",children:Ef.map(N=>{const G=qi(N),Q=zi(N),ce=G.length+Q.length,he=ze===N.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:Te=>kf(Te,N.id),onDragLeave:Te=>vf(Te,N.id),onDrop:Te=>{jf(Te,N.id)},children:[r.jsxs("div",{className:`flex justify-between items-center px-3 py-2.5 shrink-0 border-b border-border-default/30 sticky top-0 z-10 rounded-t-xl ${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 ${N.accent.replace("border-t-","bg-")}`}),r.jsx("span",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:N.label})]}),r.jsx("span",{className:"text-[11px] text-fg-tertiary font-medium tabular-nums",children:ce})]}),r.jsx("div",{className:"space-y-2 px-2 py-2",children:(()=>{const Te=[...Q.map(Ee=>({kind:"req",data:Ee,time:new Date(Ee.updatedAt??Ee.createdAt).getTime()})),...G.map(Ee=>({kind:"task",data:Ee,time:new Date(Ee.updatedAt??Ee.createdAt??0).getTime()}))];return Te.sort((Ee,oe)=>oe.time-Ee.time),Te.map(Ee=>{if(Ee.kind==="req"){const oe=Ee.data,xt=l[oe.status]??{label:oe.status,cls:"bg-gray-500/15 text-fg-secondary"},Mt=oe.source==="agent"&&oe.status==="pending",at=H==="all"&&oe.projectId?_.find(Ge=>Ge.id===oe.projectId):null,Ae=Os(oe.createdBy,ie,Ne)??oe.createdBy.slice(0,10),ft=st?.id===oe.id;return r.jsxs("div",{"data-work-item-id":oe.id,role:"button",tabIndex:0,draggable:!0,onDragStart:Ge=>wf(Ge,oe),onDragEnd:Pi,onClick:()=>Lr(oe),onKeyDown:Ge=>Ge.key==="Enter"&&Lr(oe),className:`group rounded-lg p-2.5 border border-transparent transition-all cursor-grab active:cursor-grabbing
|
|
141
|
-
${Mt?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15":"bg-surface-elevated/80 hover:bg-surface-elevated border-border-default/50 hover:border-brand-400/40"}
|
|
142
|
-
${ft?"!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 ${xt.cls}`,children:xt.label})]}),r.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:oe.title}),oe.description&&r.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:oe.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:[at&&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:at.name,children:at.name}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:oe.priority}),r.jsxs("span",{className:"text-[10px] text-fg-muted",children:["by ",Ae]})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[oe.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:oe.goalConfig.completionCriteria,children:["🎯 ",oe.goalConfig.currentIteration,"/",oe.goalConfig.maxIterations]}),oe.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:["📋 ",oe.taskIds.length]})]})]}),Mt&&r.jsxs("div",{className:"flex items-center gap-2 mt-2 pt-2 border-t border-amber-500/15",children:[r.jsx("button",{onClick:Ge=>{Ge.stopPropagation(),Ko(oe.id)},className:"flex-1 py-1 bg-green-600 hover:bg-green-500 text-white text-[10px] rounded-md font-medium transition-colors",children:s("work:task.approve")}),r.jsx("button",{onClick:Ge=>{Ge.stopPropagation(),qn(oe.id)},className:"flex-1 py-1 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-[10px] rounded-md font-medium transition-colors",children:s("work:task.reject")})]})]},`req-${oe.id}`)}else{const oe=Ee.data,xt=oe.subtasks?.length??0,Wt=i[oe.status],Mt=oe.status==="pending",at=oe.taskType==="scheduled"&&!!oe.scheduleConfig,Ae=at?oe.scheduleConfig.every?s("work:task.everyInterval",{interval:oe.scheduleConfig.every}):oe.scheduleConfig.cron?s("work:task.cronLabel"):s("work:task.scheduledShort"):null,ft=H==="all"&&oe.projectId?(()=>{const _t=_.find(Tf=>Tf.id===oe.projectId)?.name;return _t&&_t!=="default"?_t:null})():null,Ge=oe.requirementId?$e.find(_t=>_t.id===oe.requirementId)?.title:null,mn=oe.createdBy?Os(oe.createdBy,ie,Ne)??oe.createdBy:null,Kn=mt?.id===oe.id,ms={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"},Gi=oe.status==="blocked"&&Ra(oe,_t=>Sf.get(_t));return r.jsxs("div",{"data-work-item-id":oe.id,role:"button",tabIndex:0,"aria-label":oe.title,draggable:!Mt,onDragStart:_t=>!Mt&&yf(_t,oe),onDragEnd:Pi,onClick:()=>Ar(oe),onKeyDown:_t=>_t.key==="Enter"&&Ar(oe),className:`group rounded-lg p-2.5 border border-transparent transition-all ${Gi?"bg-red-500/[0.06] border-red-500/30 ring-1 ring-red-500/15 cursor-pointer":Mt?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":at?"bg-blue-500/[0.04] border-blue-500/20 hover:border-blue-400/40 cursor-pointer":"bg-surface-elevated/80 hover:bg-surface-elevated border-border-default/50 hover:border-brand-400/40 cursor-grab active:cursor-grabbing"} ${Kn?"!bg-brand-500/25 !border-brand-500/50 ring-1 ring-brand-500/40":""}`,children:[r.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${ms[oe.priority]??"bg-gray-400"}`,title:oe.priority}),at&&r.jsx("span",{className:"text-blue-500 shrink-0",title:Ae??"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"})})}),at&&Ae&&r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:Ae}),Wt&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${Wt.cls}`,children:Wt.label}),Gi&&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:oe.title}),oe.description&&r.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:oe.description}),(ft||Ge||oe.blockedBy&&oe.blockedBy.length>0)&&r.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[ft&&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:ft,children:ft}),Ge&&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:Ge,children:["# ",Ge]}),oe.blockedBy&&oe.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:["⏳ ",oe.blockedBy.length," dep",oe.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:mn&&r.jsxs("span",{className:"text-[10px] text-fg-muted",title:`by ${mn}`,children:["by ",mn]})}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[xt>0&&r.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",xt]}),oe.notes&&oe.notes.length>0&&r.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",oe.notes.length]}),oe.assignedAgentId&&r.jsxs("span",{className:"text-[10px] text-brand-500 bg-brand-500/8 px-1.5 py-0.5 rounded-md flex items-center gap-1",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Qn[ie.find(_t=>_t.id===oe.assignedAgentId)?.status??""]??"bg-gray-500"}`}),ie.find(_t=>_t.id===oe.assignedAgentId)?.name??oe.assignedAgentId.slice(0,8)]})]})]})]},oe.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")})})]},N.id)})})})]}),!c&&Yi&&r.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:I,children:r.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})}),Yi&&r.jsx("div",{className:`${c||qr?"flex-1":"shrink-0"} overflow-hidden min-w-0 flex border-l border-border-default/60`,style:c||qr?void 0:{width:M},children:A==="project"&&Vt?r.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[r.jsxs("div",{className:"px-4 py-3 flex items-center gap-2 border-b border-border-default/60 sticky top-0 bg-surface-primary z-10",children:[r.jsx("h3",{className:"text-sm font-semibold text-fg-primary truncate flex-1",children:s("work:project.settingsTitle")}),r.jsx("button",{type:"button",onClick:Fn,className:"w-7 h-7 flex items-center justify-center rounded-md text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated","aria-label":s("common:close"),children:r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),r.jsx($b,{project:Vt,tasks:Object.values(F).flat().filter(N=>N.projectId===Vt.id),requirements:$e.filter(N=>N.projectId===Vt.id),agents:ie,onDeleteProject:()=>xf(Vt.id),onUpdateProject:async N=>{await te.projects.update(Vt.id,N),zn()},onRefresh:()=>{zn()}})]}):A==="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:fe,className:"px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-on-brand rounded-lg font-medium",children:s("work:task.newRequirement")}),r.jsx("button",{onClick:()=>{Ke(O??""),ge(!0)},className:"px-3 py-1.5 text-[11px] border border-amber-500/60 text-amber-600 rounded-lg font-medium",children:s("work:task.newTaskBtn")})]}),r.jsx("button",{type:"button",onClick:Fn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:s("common:close")})]})}):qr?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:r.jsx(Dc,{req:st,agents:ie,projects:_,allTasks:Object.values(F).flat(),users:Ne,onClose:()=>{Qe(null),mt||Fn()},onApprove:N=>{Ko(N)},onReject:N=>{qn(N)},onCancel:N=>{$i(N),Qe(null)},onStatusChange:async(N,G)=>{try{await te.requirements.updateStatus(N,G),pt(`Requirement status → ${G}`),fs({requirementId:N}),Wn(),Lt()}catch(Q){pt(`Error: ${Q}`)}},onRefresh:Wn,authUser:e,onTaskClick:N=>{Ze(N),T("item")},onCreateTask:(N,G)=>{X(N),G&&Ke(G),ge(!0)},onProjectClick:Rr,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(Mc,{task:mt,agents:ie,projects:_,requirements:$e,allTasks:Object.values(F).flat(),users:Ne,onClose:mf,onRefresh:Di,authUser:e,scrollToComments:Wo,onScrollToCommentsDone:()=>Us(!1),onReqClick:N=>{Qe(G=>G?.id===N.id?null:N),T("item")},onProjectClick:Rr})})]}):mt?r.jsx(Mc,{task:mt,agents:ie,projects:_,requirements:$e,allTasks:Object.values(F).flat(),users:Ne,onClose:Fn,onRefresh:Di,authUser:e,scrollToComments:Wo,onScrollToCommentsDone:()=>Us(!1),onReqClick:N=>{Qe(N),Ze(null),T("item")},onProjectClick:Rr}):st?r.jsx(Dc,{req:st,agents:ie,projects:_,allTasks:Object.values(F).flat(),users:Ne,onClose:Fn,onApprove:N=>{Ko(N)},onReject:N=>{qn(N)},onCancel:N=>{$i(N),Fn()},onStatusChange:async(N,G)=>{try{await te.requirements.updateStatus(N,G),pt(`Requirement status → ${G}`),fs({requirementId:N}),Wn(),Lt()}catch(Q){pt(`Error: ${Q}`)}},scrollToComments:Wo,onScrollToCommentsDone:()=>Us(!1),onRefresh:Wn,authUser:e,onTaskClick:N=>{Ze(N),Qe(null),T("item"),c&&(L(!0),history.pushState({mobileDetail:tt.WORK},"",window.location.hash))},onCreateTask:(N,G)=>{X(N),G&&Ke(G),ge(!0)},onProjectClick:Rr,previewMode:t}):r.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:r.jsxs("div",{className:"max-w-xs w-full text-center space-y-3",children:[r.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:s("work:task.emptyDetailTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:s("work:task.emptyDetailHint")}),r.jsx("button",{type:"button",onClick:Fn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:s("common:close")})]})})}),ne&&r.jsx(Ql,{orgId:e?.orgId,onCreated:gf,onClose:()=>ae(!1)}),ot&&r.jsx(Ql,{orgId:e?.orgId,onCreated:N=>{q(G=>G.some(Q=>Q.id===N.id)?G:[...G,N]),ot==="task"?(Ke(N.id),X("")):Fo(N.id),It(null),pt(s("work:task.projectCreated"))},onClose:()=>It(null)}),ke&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{ge(!1),At("")},children:r.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${c?"w-full":"w-[28rem]"}`,onClick:N=>N.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("work:task.newTask")}),r.jsxs("div",{className:Sa,children:[r.jsx("label",{className:it,children:s("work:task.taskType")}),r.jsx("div",{className:"inline-flex w-full p-0.5 bg-surface-elevated border border-border-default rounded-lg",children:["standard","scheduled"].map(N=>r.jsx("button",{type:"button",onClick:()=>be(N),"aria-pressed":de===N,className:`flex-1 px-3 py-1.5 text-sm rounded-md transition-colors ${de===N?"bg-brand-600 text-on-brand font-medium":"text-fg-secondary hover:text-fg-primary"}`,children:s(N==="standard"?"work:task.taskTypeStandard":"work:task.taskTypeScheduled")},N))}),r.jsx("label",{className:it,children:s("work:task.titleLabel")}),r.jsx("input",{autoFocus:!c,value:ve,onChange:N=>Me(N.target.value),onKeyDown:N=>{N.key==="Enter"&&_i()},className:gn}),r.jsx("label",{className:it,children:s("work:task.descriptionField")}),r.jsx("textarea",{value:nt,onChange:N=>Pe(N.target.value),rows:2,className:`${gn} resize-none`}),r.jsx("label",{className:it,children:s("work:task.priorityField")}),r.jsx(vo,{value:ee,onChange:Re}),r.jsx("label",{className:it,children:s("work:task.projectLabel")}),r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx(Ft,{className:"flex-1",options:[{value:"",label:s("work:task.noProject")},..._.map(N=>({value:N.id,label:N.name}))],value:Le,onChange:N=>{Ke(N),X("")},placeholder:s("work:task.noProject"),noMatchesText:s("work:task.noMatches")}),r.jsx("button",{type:"button",onClick:()=>It("task"),className:la,children:s("work:task.newProjectInline")})]}),r.jsx("label",{className:it,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")},...$e.filter(N=>N.status==="in_progress"&&(!Le||N.projectId===Le)).map(N=>({value:N.id,label:N.title}))],value:kt,onChange:X,placeholder:s("work:task.selectRequirement"),noMatchesText:s("work:task.noMatches")}),r.jsx("button",{type:"button",onClick:()=>{wn(!0),At("")},className:la,children:s("work:task.newRequirementInline")})]}),Ht&&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:sn,onChange:N=>cn(N.target.value),placeholder:s("work:task.newReqInlinePlaceholder"),onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),Ri())},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:()=>{Ri()},disabled:!sn.trim(),className:"px-3 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-on-brand disabled:opacity-40",children:s("common:create")})]}),r.jsx("p",{className:"text-[11px] text-fg-tertiary",children:s(Le?"work:task.newReqInlineHint":"work:task.newReqInlineNeedProject")})]})]}),r.jsxs("label",{className:it,children:[s("work:task.assignToRequired"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx(Ft,{options:ie.map(N=>({value:N.id,label:`${N.name} (${N.status})`})),value:We,onChange:ht,placeholder:s("work:task.selectAgent"),noMatchesText:s("work:task.noMatches")}),r.jsxs("label",{className:it,children:[s("work:task.reviewerRequired"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx(Ft,{options:[...Ne.map(N=>({value:`human:${N.id}`,label:N.name})),...ie.filter(N=>N.id!==We).map(N=>({value:`agent:${N.id}`,label:`${N.name} (${N.status})`}))],value:Je,onChange:qe,placeholder:s("work:task.selectReviewer"),noMatchesText:s("work:task.noMatches")}),de==="scheduled"&&r.jsx("div",{className:"col-span-2",children:r.jsx(Jc,{value:Ce,onChange:Xe})}),r.jsx("label",{className:it,children:s("work:task.blockedBy")}),r.jsxs("div",{className:"min-w-0",children:[r.jsx(jb,{options:Object.values(F).flat().filter(N=>N.status!=="completed"&&N.status!=="cancelled").map(N=>({value:N.id,label:N.title})),selected:le,onAdd:N=>ye([...le,N]),placeholder:s("work:task.selectDependency"),noMatchesText:s("work:task.noMatches")}),le.length>0&&r.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:le.map(N=>{const G=Object.values(F).flat().find(Q=>Q.id===N);return r.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] px-2 py-1 bg-amber-500/10 text-amber-600 rounded-full",children:[G?G.title.slice(0,30):N.slice(-8),r.jsx("button",{onClick:()=>ye(le.filter(Q=>Q!==N)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},N)})})]})]}),Ct&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Ct}),r.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[r.jsx("button",{onClick:()=>{ge(!1),At("")},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:()=>{_i()},disabled:!ve.trim()||!We||!Je||Et,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-on-brand disabled:opacity-50",children:s(Et?"common:creating":"common:create")})]})]})}),Vs&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{dn(!1),jn(""),Ws(""),Nn("")},children:r.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 max-h-[90dvh] overflow-y-auto ${c?"w-full":"w-[28rem]"}`,onClick:N=>N.stopPropagation(),children:[r.jsxs("div",{children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("work:task.newRequirementModalTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:s("work:task.newRequirementModalHint")})]}),r.jsxs("div",{className:Sa,children:[r.jsxs("label",{className:it,children:[s("work:task.projectLabel"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx(Ft,{className:"flex-1",options:_.map(N=>({value:N.id,label:N.name})),value:Ir,onChange:Fo,placeholder:s("work:task.selectProject"),noMatchesText:s("work:task.noMatches")}),r.jsx("button",{type:"button",onClick:()=>It("req"),className:la,children:s("work:task.newProjectInline")})]}),r.jsxs("label",{className:it,children:[s("work:task.titleField"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx("input",{value:Pn,onChange:N=>jn(N.target.value),placeholder:s("work:task.reqTitleExample"),className:gn,autoFocus:!c,onKeyDown:N=>{N.key==="Enter"&&Pn.trim()&&Oi()}}),r.jsxs("label",{className:it,children:[s("work:task.descriptionField"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx("textarea",{value:Bn,onChange:N=>Ws(N.target.value),placeholder:s("work:task.reqDescPlaceholder"),rows:3,className:`${gn} resize-none`}),r.jsx("label",{className:it,children:s("work:task.priorityField")}),r.jsx(vo,{value:bi,onChange:uf})]}),ki&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:ki}),r.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[r.jsx("button",{onClick:()=>{dn(!1),jn(""),Ws(""),Nn("")},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:()=>{Oi()},disabled:!Pn.trim()||!Bn.trim()||!Ir||Ho,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-on-brand disabled:opacity-40 disabled:cursor-not-allowed",children:s(Ho?"common:creating":"common:create")})]})]})}),as&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{qn(null),is("")},children:r.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 space-y-4 ${c?"w-full":"w-96"}`,onClick:N=>N.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("work:task.rejectRequirementTitle")}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-fg-secondary mb-1.5",children:s("work:task.rejectReasonLabel")}),r.jsx("textarea",{value:yi,onChange:N=>wi(N.target.value),placeholder:s("work:task.rejectReasonPlaceholder"),rows:3,className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm text-fg-primary focus:border-red-500 outline-none resize-none",autoFocus:!c})]}),ji&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:ji}),r.jsxs("div",{className:"flex justify-end gap-3",children:[r.jsx("button",{onClick:()=>{qn(null),is("")},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:()=>{bf()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:s("work:task.reject")})]})]})}),rs&&r.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>vn(!1),children:[r.jsx("div",{className:"absolute inset-0 bg-black/50"}),r.jsxs("div",{className:"relative bg-surface-secondary rounded-t-2xl border-t border-border-default max-h-[70vh] overflow-y-auto pb-16",onClick:N=>N.stopPropagation(),children:[r.jsxs("div",{className:"sticky top-0 bg-surface-secondary z-10 px-4 pt-3 pb-2 flex items-center justify-between border-b border-border-default/60",children:[r.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:s("work:task.filtersSheetTitle")}),r.jsxs("div",{className:"flex items-center gap-2",children:[(dt.size>0||gt)&&r.jsx("button",{onClick:()=>{vt(new Set),Ot(!1)},className:"text-[11px] text-brand-500 font-medium",children:s("work:task.clearAll")}),r.jsx("button",{onClick:()=>vn(!1),className:"w-7 h-7 flex items-center justify-center rounded-full bg-surface-elevated text-fg-tertiary",children:r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),_.length>0&&r.jsxs("div",{className:"px-4 py-3",children:[r.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:s("work:task.projectsFilterGroup")}),r.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[r.jsxs("button",{type:"button",onClick:()=>{on(),vn(!1)},className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-lg transition-all ${H==="all"&&!O?"bg-brand-500/15 text-brand-600 ring-1 ring-brand-500/30":"bg-surface-elevated text-fg-secondary"}`,children:[s("work:task.all"),Pr>0&&r.jsx("span",{className:"text-[9px] text-fg-tertiary",children:Pr})]}),Or.map(N=>{const G=O===N.id,Q=$r[N.id]??0;return r.jsxs("button",{type:"button",onClick:()=>{Gt(N.id),vn(!1)},className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-lg transition-all ${G?"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 ${G?"bg-brand-600 text-on-brand":"bg-surface-overlay text-fg-tertiary"}`,children:N.name[0]?.toUpperCase()}),N.name,Q>0&&r.jsx("span",{className:"text-[9px] text-fg-tertiary",children:Q})]},N.id)})]})]}),e?.id&&r.jsx("div",{className:"px-4 py-3 border-t border-border-default/40",children:r.jsx("button",{type:"button",onClick:()=>Ot(N=>!N),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${gt?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:s("work:task.myTasks")})}),Dr.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:Dr.map(N=>{if(N.kind==="team"){const ce=N.agentIds.every(Te=>dt.has(Te)),he=!ce&&N.agentIds.some(Te=>dt.has(Te));return r.jsxs("button",{onClick:()=>{vt(Te=>{const Ee=new Set(Te);if(ce)for(const oe of N.agentIds)Ee.delete(oe);else for(const oe of N.agentIds)Ee.add(oe);return Ee})},className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ce?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":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"})}),N.name,r.jsx("span",{className:"text-[9px] text-fg-muted",children:N.agentIds.length})]},`team-${N.id}`)}const G=N.agent,Q=dt.has(G.id);return r.jsxs("button",{onClick:()=>Bi(G.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Q?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"bg-surface-elevated text-fg-secondary"}`,children:[r.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${Q?"bg-brand-600 text-on-brand":"bg-surface-overlay text-fg-tertiary"}`,children:G.name[0]?.toUpperCase()}),G.name]},G.id)})})]}),r.jsx("div",{className:"h-[env(safe-area-inset-bottom,0px)]"})]})]})]})}function Kb({requirementId:e,createdBy:t,agents:n,users:s,authUser:o}){const{t:a}=He(["work","common"]),[i,l]=p.useState([]),[c,d]=p.useState([]),f=p.useRef(null),[u,h]=p.useState(new Map);p.useEffect(()=>{d([]),h(new Map),f.current&&(clearTimeout(f.current),f.current=null),te.requirements.getComments(e).then(v=>l(v.comments)).catch(()=>{})},[e]),p.useEffect(()=>$t.on("requirement:comment",y=>{if(y.payload?.requirementId===e&&y.payload.comment){const x=y.payload.comment;l(w=>w.some(C=>C.id===x.id)?w:[...w,x]),(x.authorType==="agent"||x.authorId?.startsWith("agt_"))&&(d(w=>{const C=w.filter(j=>j.id!==x.authorId);return C.length===0&&f.current&&(clearTimeout(f.current),f.current=null),C}),h(w=>{const C=new Map(w);return C.delete(x.authorId),C}))}}),[e]),p.useEffect(()=>{if(c.length===0)return;const v=new Set(c.map(x=>x.id));return $t.on("agent:activity_log",x=>{const w=x.payload;if(!w)return;const C=w.agentId;if(!v.has(C))return;const j=ko(w);j&&h(E=>mi(E,C,j))})},[c]);const[m,g]=p.useState(null),b=async(v,y,x,w)=>{let C;x.length>0&&(C=(await te.uploads.upload(x.map(R=>({dataUrl:R.dataUrl,name:R.name})),"comments")).files.map(R=>({type:"image",url:R.url,name:R.name})));const j=await te.requirements.addComment(e,v,o?.name,C,o?.id,y.length>0?y:void 0,w),E=Ga(j.notifiedAgentIds,n);E.length>0&&(f.current&&clearTimeout(f.current),d(E),f.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(qo,{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 y=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(tt.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(Da,{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}),y.length===0&&r.jsxs("span",{className:"flex items-center gap-0.5",children:[r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce"}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.15s"}}),r.jsx("span",{className:"w-1 h-1 rounded-full bg-blue-400 animate-bounce",style:{animationDelay:"0.3s"}})]}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:a("work:task.agentProcessing")}),r.jsx("span",{className:"ml-auto text-[10px] text-fg-tertiary",children:"→"})]}),y.length>0&&r.jsx("div",{className:"ml-8 mt-1",children:r.jsx(pi,{entries:y})})]},v.id)})})]}),r.jsx(zc,{agents:n,humans:s,onSubmit:b,replyTo:m,onCancelReply:()=>g(null)})]})}function Dc({req:e,agents:t,projects:n,allTasks:s,users:o,onClose:a,onApprove:i,onReject:l,onCancel:c,onStatusChange:d,onRefresh:f,authUser:u,scrollToComments:h,onScrollToCommentsDone:m,onTaskClick:g,onCreateTask:b,onProjectClick:k,previewMode:v}){const{t:y}=He(["work","common"]),x=p.useMemo(()=>xi(y),[y]),w=p.useMemo(()=>af(y),[y]),C=pr(),[j,E]=p.useState(!1),[S,R]=p.useState(e.description),[$,M]=p.useState(!1),[D,z]=p.useState(!1),[I,P]=p.useState(!1);p.useEffect(()=>{if(!I)return;const ee=Re=>{Re.key==="Escape"&&P(!1)};return document.addEventListener("keydown",ee),()=>document.removeEventListener("keydown",ee)},[I]);const[L,B]=p.useState(!1),[_,q]=p.useState(null),[H,K]=p.useState(!1),[O,U]=p.useState(null),A=p.useMemo(()=>s.filter(ee=>ee.requirementId===e.id&&ee.status==="pending").length,[s,e.id]),T=async()=>{U(null),K(!0);try{const ee=await te.requirements.approveTasksBulk(e.id,{dryRun:!0});q({phase:"preview",...ee})}catch(ee){U(ee instanceof Error?ee.message:String(ee))}finally{K(!1)}},V=async()=>{U(null),K(!0);try{const ee=await te.requirements.approveTasksBulk(e.id,{runNow:!0});q({phase:"result",...ee}),f?.()}catch(ee){U(ee instanceof Error?ee.message:String(ee))}finally{K(!1)}},[W,F]=p.useState(!1),Z=p.useRef(null),[se,ue]=p.useState("none"),ie=p.useRef(null),pe=p.useRef(null),je=p.useRef(80);p.useEffect(()=>{const ee=Z.current;if(!ee)return;const Re=()=>{const{scrollTop:ht,scrollHeight:Je,clientHeight:qe}=ee;if(!(Je>qe+50)){ue("none");return}const Ke=ht<30,kt=ht+qe>=Je-30;ue(Ke?"top":kt?"bottom":"middle")};Re(),ee.addEventListener("scroll",Re,{passive:!0});const We=new ResizeObserver(Re);return We.observe(ee),()=>{ee.removeEventListener("scroll",Re),We.disconnect()}},[]),p.useEffect(()=>{if(j&&pe.current){const ee=pe.current;ee.style.height="auto",ee.style.height=Math.max(ee.scrollHeight,je.current)+"px",ee.focus()}},[j]),p.useEffect(()=>{if(!h)return;const ee=setTimeout(()=>{const Re=Z.current;Re&&Re.scrollTo({top:Re.scrollHeight,behavior:"smooth"}),m?.()},300);return()=>clearTimeout(ee)},[h,m]);const Se=x[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},Ne=e.source==="agent",Be=Ne&&e.status==="pending",$e=e.status==="pending"||e.status==="in_progress",Ie=Gc.has(e.status),Ve=e.projectId?n.find(ee=>ee.id===e.projectId):null,ct=Os(e.createdBy,t,o)??e.createdBy.slice(0,12),Oe=s.filter(ee=>e.taskIds.includes(ee.id)),re=Ve?.teamIds?.[0]??null;p.useMemo(()=>new Map(Oe.map(ee=>[ee.id,ee])),[Oe]);const fe=Oe.length>=2;p.useEffect(()=>{R(e.description),E(!1)},[e.id,e.description]);const[xe,J]=p.useState(!1),[ne,ae]=p.useState(e.title),[ke,ge]=p.useState(!1),[ve,Me]=p.useState((e.tags??[]).join(", ")),nt=p.useRef(null);p.useEffect(()=>{ae(e.title),J(!1)},[e.id,e.title]),p.useEffect(()=>{Me((e.tags??[]).join(", ")),ge(!1)},[e.id,e.tags]),p.useEffect(()=>{xe&&nt.current?.focus()},[xe]);const Pe=async ee=>{try{await te.requirements.update(e.id,ee),f?.()}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 ${C?"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:[C&&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:[xe?r.jsx("input",{ref:nt,value:ne,onChange:ee=>ae(ee.target.value),onBlur:()=>{const ee=ne.trim();ee&&ee!==e.title&&Pe({title:ee}),J(!1)},onKeyDown:ee=>{ee.key==="Enter"&&ee.target.blur(),ee.key==="Escape"&&(ae(e.title),J(!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 ${Ie?"":"cursor-text hover:bg-surface-elevated/60"}`,onClick:Ie?void 0:()=>J(!0),role:Ie?void 0:"button",tabIndex:Ie?void 0:0,onKeyDown:Ie?void 0:ee=>ee.key==="Enter"&&J(!0),title:Ie?void 0:y("work:task.clickToEdit",{defaultValue:"点击编辑"}),children:e.title})," ",r.jsx("span",{className:"text-[10px] font-bold text-brand-500 bg-brand-500/15 px-2 py-0.5 rounded align-middle",children:y("work:task.requirementShort")})," ",r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium align-middle ${Se.cls}`,children:Se.label})," ",e.priority==="high"||e.priority==="urgent"?r.jsx("span",{className:`text-[10px] font-medium align-middle ${e.priority==="urgent"?"text-red-500":"text-amber-600"}`,children:y("common:priority."+e.priority,{defaultValue:e.priority})}):r.jsx("span",{className:"text-[10px] text-fg-tertiary align-middle",children:y("common:priority."+e.priority,{defaultValue:e.priority})})]})]}),r.jsxs("div",{className:"flex items-center gap-2 shrink-0 mb-4",children:[r.jsx(Pc,{onClick:()=>F(!0),label:y("work:task.sendToChat",{defaultValue:"发送到对话"})}),r.jsx("button",{onClick:a,className:"text-fg-tertiary hover:text-fg-secondary text-xl leading-none shrink-0",children:"×"})]})]}),W&&r.jsx(sf,{kind:"requirement",entity:e,agents:t,users:o,projects:n,onClose:()=>F(!1)}),r.jsxs("div",{className:"flex-1 min-h-0 relative",children:[r.jsxs("div",{ref:Z,className:"h-full overflow-y-auto p-5 space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-1 block",children:y("work:task.requirementDetailDescription")}),j?r.jsx("textarea",{ref:pe,value:S,onChange:ee=>{R(ee.target.value);const Re=ee.target;Re.style.height="auto",Re.style.height=Re.scrollHeight+"px"},onBlur:async()=>{if(S!==e.description){M(!0);try{await te.requirements.update(e.id,{description:S}),f?.()}catch{}finally{M(!1)}}E(!1)},onKeyDown:ee=>{ee.key==="Escape"&&(ee.preventDefault(),R(e.description),E(!1))},className:"w-full bg-transparent border border-brand-500/30 rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none -mx-2 px-2 -my-1 py-1",placeholder:y("work:task.requirementDetailDescription")}):r.jsx("div",{ref:ie,className:`group relative rounded-lg -mx-2 px-2 -my-1 py-1 transition-colors ${Ie?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:Ie?void 0:ee=>{ee.target.closest("a, button, [data-entity-link]")||(je.current=Math.max(ie.current?.offsetHeight??80,60),R(e.description),E(!0))},role:Ie?void 0:"button",tabIndex:Ie?void 0:0,onKeyDown:Ie?void 0:ee=>ee.key==="Enter"&&(R(e.description),E(!0)),children:e.description?r.jsx(or,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"}):r.jsx("p",{className:"text-sm text-fg-tertiary italic",children:y("work:task.requirementNoDescription")})})]}),r.jsxs("div",{className:"border-t border-border-default/60 pt-4",children:[r.jsxs("div",{className:uu,children:[r.jsx("label",{className:it,children:y("work:task.projectLabel")}),r.jsx(Ft,{size:"sm",disabled:Ie,options:[{value:"",label:y("work:task.noProject")},...n.map(ee=>({value:ee.id,label:ee.name}))],value:e.projectId??"",onChange:ee=>{Pe({projectId:ee||null})},placeholder:y("work:task.noProject"),noMatchesText:y("work:task.noMatches")}),r.jsx("label",{className:it,children:y("work:task.priority")}),r.jsx(vo,{value:e.priority,onChange:ee=>{Pe({priority:ee})}}),r.jsx("label",{className:it,children:y("work:task.tagsLabel")}),ke&&!Ie?r.jsx("input",{autoFocus:!0,value:ve,onChange:ee=>Me(ee.target.value),onBlur:()=>{const ee=ve.split(",").map(We=>We.trim()).filter(Boolean),Re=e.tags??[];ee.join("\0")!==Re.join("\0")&&Pe({tags:ee}),ge(!1)},onKeyDown:ee=>{ee.key==="Enter"&&ee.target.blur(),ee.key==="Escape"&&(Me((e.tags??[]).join(", ")),ge(!1))},placeholder:y("work:task.tagsPlaceholder"),className:`${gn} !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 ${Ie?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:Ie?void 0:()=>ge(!0),role:Ie?void 0:"button",tabIndex:Ie?void 0:0,onKeyDown:Ie?void 0:ee=>ee.key==="Enter"&&ge(!0),children:e.tags&&e.tags.length>0?e.tags.map(ee=>r.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",ee]},ee)):r.jsx("span",{className:"text-xs text-fg-tertiary italic",children:y("work:task.noTags")})})]}),r.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-x-4 gap-y-1 text-[11px] text-fg-tertiary",children:[r.jsxs("span",{children:[y("work:task.createdByLabel"),": ",r.jsx("span",{className:"text-fg-secondary",children:ct}),Ne&&r.jsx("span",{className:"text-brand-500 ml-1",children:y("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:[y("work:task.projectLabel"),": ",Ve.name]}),e.approvedBy&&r.jsxs("span",{children:[y("work:task.approvedBy"),": ",r.jsx("span",{className:"text-fg-secondary",children:Os(e.approvedBy,t,o)??e.approvedBy.slice(0,12)}),e.approvedAt&&r.jsx("span",{className:"ml-1",children:new Date(e.approvedAt).toLocaleDateString()})]})]})]}),e.rejectedReason&&r.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[r.jsx("span",{className:"text-[10px] font-semibold text-red-500 uppercase tracking-wider block mb-1",children:y("work:task.rejectionReason")}),r.jsx("p",{className:"text-sm text-red-500/80",children:e.rejectedReason})]}),e.goalConfig?.loopEnabled&&r.jsxs("div",{className:"bg-brand-500/8 border border-brand-500/20 rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx("span",{className:"text-[10px] font-semibold text-brand-500 uppercase tracking-wider",children:y("work:requirement.goal")}),r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium ${e.goalConfig.currentIteration>=e.goalConfig.maxIterations?"bg-amber-500/15 text-amber-600":"bg-green-500/15 text-green-600"}`,children:e.goalConfig.currentIteration>=e.goalConfig.maxIterations?y("work:requirement.goalMaxReached"):y("work:requirement.goalActive")})]}),r.jsx("p",{className:"text-xs text-fg-secondary mb-2",children:e.goalConfig.completionCriteria}),r.jsxs("div",{className:"flex items-center gap-4 text-[10px] text-fg-tertiary",children:[r.jsx("span",{children:y("work:requirement.goalIteration",{current:e.goalConfig.currentIteration,max:e.goalConfig.maxIterations})}),e.goalConfig.lastCheckedAt&&r.jsx("span",{children:y("work:requirement.goalLastChecked",{time:new Date(e.goalConfig.lastCheckedAt).toLocaleString()})}),e.goalConfig.autoResume&&r.jsx("span",{className:"text-brand-500",children:y("work:requirement.goalAutoResume")})]})]}),Array.isArray(e.tags)&&e.tags.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(ee=>r.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",ee]},ee))}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("label",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:y("work:task.linkedTasks",{count:Oe.length})}),r.jsxs("div",{className:"flex items-center gap-2",children:[fe&&re&&r.jsxs("button",{onClick:()=>B(!0),className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium flex items-center gap-1",children:[r.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),y("work:task.saveAsWorkflow")]}),!Ie&&b&&r.jsxs("button",{onClick:()=>b(e.id,e.projectId),className:"text-[11px] text-amber-500 hover:text-amber-400 font-medium flex items-center gap-1",children:[r.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),y("work:requirement.createTask")]})]})]}),Oe.length>0?(()=>{const ee=new Map(Oe.map(Le=>[Le.id,Le]));if(!Oe.some(Le=>Le.blockedBy?.some(Ke=>ee.has(Ke))))return r.jsx("div",{className:"space-y-1.5",children:Oe.map(Le=>{const Ke=w[Le.status];return r.jsxs("div",{onClick:()=>g?.(Le),className:`flex items-center gap-2 bg-surface-elevated/60 rounded-lg px-3 py-2 ${g?"cursor-pointer hover:bg-surface-elevated transition-colors":""}`,children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Qn[Le.status]??"bg-gray-500"}`}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:Le.title}),Ke&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${Ke.cls}`,children:Ke.label})]},Le.id)})});const We=new Map,ht=new Set;for(const Le of Oe)for(const Ke of Le.blockedBy??[])if(ee.has(Ke)){ht.add(Le.id);const kt=We.get(Ke)??[];kt.push(Le.id),We.set(Ke,kt)}const Je=Oe.filter(Le=>!ht.has(Le.id)),qe=(Le,Ke)=>{const kt=w[Le.status],X=(We.get(Le.id)??[]).map(le=>ee.get(le)).filter(Boolean);return r.jsxs("div",{children:[r.jsxs("div",{onClick:()=>g?.(Le),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:Ke>0?{marginLeft:Ke*20}:void 0,children:[Ke>0&&r.jsx("span",{className:"text-fg-muted text-[10px] shrink-0",children:"↳"}),r.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${Qn[Le.status]??"bg-gray-500"}`}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:Le.title}),kt&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${kt.cls}`,children:kt.label})]}),X.map(le=>qe(le,Ke+1))]},Le.id)};return r.jsx("div",{className:"space-y-1.5",children:Je.map(Le=>qe(Le,0))})})():r.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:y("work:requirement.noLinkedTasks")})]}),!v&&r.jsx(Kb,{requirementId:e.id,createdBy:e.createdBy,agents:t,users:o,authUser:u}),!v&&r.jsx(df,{entityType:"requirement",entityId:e.id})]}),se!=="none"&&se!=="top"&&r.jsx("button",{onClick:()=>Z.current?.scrollTo({top:0,behavior:"smooth"}),className:"absolute bottom-20 right-4 md:bottom-14 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-on-brand hover:bg-brand-400 transition-colors backdrop-blur-sm",title:y("work:task.scrollToTop"),children:r.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:r.jsx("path",{fillRule:"evenodd",d:"M14.77 12.79a.75.75 0 01-1.06-.02L10 8.832l-3.71 3.938a.75.75 0 11-1.08-1.04l4.25-4.5a.75.75 0 011.08 0l4.25 4.5a.75.75 0 01-.02 1.06z",clipRule:"evenodd"})})}),se!=="none"&&se!=="bottom"&&r.jsx("button",{onClick:()=>{const ee=Z.current;ee&&ee.scrollTo({top:ee.scrollHeight,behavior:"smooth"})},className:"absolute bottom-6 right-4 md:bottom-4 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-on-brand hover:bg-brand-400 transition-colors backdrop-blur-sm",title:y("work:task.scrollToBottom"),children:r.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:r.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),r.jsxs("div",{className:"flex items-center gap-2 p-5 pt-3 border-t border-border-default",children:[A>0&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{T()},disabled:H,className:"px-3 py-2 bg-brand-600 hover:bg-brand-500 text-on-brand text-sm rounded-lg font-medium transition-colors disabled:opacity-60",children:y("work:requirement.bulkApprove","批量批准待批任务 ({{count}})",{count:A})}),_&&r.jsx("div",{className:"fixed inset-0 z-[10050] flex items-center justify-center bg-black/60 p-4",onClick:()=>{H||q(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:ee=>ee.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":y("work:requirement.bulkApproveTitle","批量批准待批任务"),children:[r.jsxs("div",{className:"px-5 pt-4 pb-3 border-b border-border-default shrink-0",children:[r.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:_.phase==="preview"?y("work:requirement.bulkApproveTitle","批量批准待批任务"):y("work:requirement.bulkApproveDone","批量批准结果")}),_.phase==="preview"&&r.jsx("p",{className:"mt-1 text-xs text-amber-600 dark:text-amber-400 leading-relaxed",children:y("work:requirement.bulkApproveWarning","批准后立即开始执行:将同时启动 {{count}} 个任务,各自占用对应 agent。",{count:_.approved.length})}),_.phase==="result"&&r.jsx("p",{className:"mt-1 text-xs text-fg-secondary",children:y("work:requirement.bulkApproveSummary","成功 {{ok}} · 跳过 {{skip}} · 失败 {{fail}}",{ok:_.approved.length,skip:_.skipped.length,fail:_.failed.length})})]}),r.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-3 space-y-3",children:[_.approved.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary mb-1",children:_.phase==="preview"?y("work:requirement.bulkApproveWillApprove","将批准"):y("work:requirement.bulkApproveApproved","已批准")}),r.jsx("ul",{className:"space-y-0.5",children:_.approved.map(ee=>r.jsxs("li",{className:"text-xs text-fg-secondary truncate",children:["· ",ee.title]},ee.id))})]}),_.skipped.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary mb-1",children:y("work:requirement.bulkApproveSkipped","跳过(不满足批准条件)")}),r.jsx("ul",{className:"space-y-0.5",children:_.skipped.map(ee=>r.jsxs("li",{className:"text-xs text-fg-tertiary truncate",children:["· ",ee.title||ee.id," — ",ee.reason]},ee.id))})]}),_.failed.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-red-500 mb-1",children:y("work:requirement.bulkApproveFailed","失败")}),r.jsx("ul",{className:"space-y-0.5",children:_.failed.map(ee=>r.jsxs("li",{className:"text-xs text-red-500 truncate",children:["· ",ee.title," — ",ee.error]},ee.id))})]}),_.approved.length===0&&_.skipped.length===0&&r.jsx("p",{className:"text-xs text-fg-tertiary",children:y("work:requirement.bulkApproveNothing","没有可批准的待批任务。")}),O&&r.jsx("p",{className:"text-xs text-red-500",children:O})]}),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:()=>q(null),disabled:H,className:"px-3 py-1.5 text-xs rounded-lg border border-border-default text-fg-secondary hover:bg-surface-elevated transition-colors disabled:opacity-60",children:_.phase==="preview"?y("common:cancel"):y("common:close")}),_.phase==="preview"&&r.jsx("button",{onClick:()=>{V()},disabled:H||_.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:H?y("work:requirement.bulkApproving","批准中…"):y("work:requirement.bulkApproveConfirm","确认批准并开始")})]})]})})]}),Be&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>i(e.id),className:"px-4 py-2 bg-green-600 hover:bg-green-500 text-white text-sm rounded-lg font-medium transition-colors",children:y("work:requirement.approveRequirement")}),r.jsx("button",{onClick:()=>l(e.id),className:"px-4 py-2 border border-red-500/30 hover:bg-red-500/10 text-red-500 text-sm rounded-lg font-medium transition-colors",children:y("work:requirement.rejectRequirement")})]}),!Be&&d&&!Ie&&r.jsxs("div",{className:"relative",children:[r.jsxs("button",{type:"button",onClick:()=>P(ee=>!ee),"aria-haspopup":"menu","aria-expanded":I,"aria-label":y("work:requirement.changeStatus","切换状态"),"data-testid":"requirement-status-menu",className:"inline-flex items-center gap-1.5 px-2.5 py-1.5 text-xs rounded-lg bg-surface-elevated border border-border-default text-fg-secondary hover:border-gray-500 hover:text-fg-primary transition-colors",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Qn[e.status]??"bg-fg-muted"}`,"aria-hidden":"true"}),x[e.status]?.label??e.status,r.jsx("svg",{className:"w-3 h-3 text-fg-tertiary",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,"aria-hidden":"true",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M18 15l-6-6-6 6"})})]}),I&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fixed inset-0 z-20",onClick:()=>P(!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 ee=[...La[e.status]??[]].filter(Re=>Re!=="cancelled"&&!(Be&&Re==="rejected"));return ee.length===0?r.jsx("p",{className:"px-3 py-2 text-[11px] text-fg-tertiary",children:y("work:requirement.noStatusChange","暂无可用状态变更")}):ee.map(Re=>r.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{P(!1),d(e.id,Re)},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-secondary transition-colors hover:bg-surface-elevated hover:text-fg-primary focus:bg-surface-elevated focus:outline-none",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Qn[Re]??"bg-fg-muted"}`,"aria-hidden":"true"}),r.jsx("span",{className:"flex-1",children:x[Re]?.label??Re}),Re==="completed"&&r.jsx("span",{className:"text-[10px] text-fg-muted",children:y("work:requirement.terminalHint","终态")})]},Re))})()})]})]}),Ie&&d&&r.jsx("button",{onClick:()=>d(e.id,"in_progress"),className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",children:y("work:task.reopen")}),r.jsx("div",{className:"flex-1"}),$e&&!Be&&r.jsx("button",{onClick:()=>z(!0),className:"px-3 py-1.5 text-xs text-red-500/70 hover:text-red-500 hover:bg-red-500/10 border border-transparent hover:border-red-500/20 rounded-lg transition-colors",children:y("work:task.cancelRequirement")})]}),D&&r.jsx(bs,{title:y("work:requirement.cancelConfirmTitle","Cancel Requirement"),message:y("work:requirement.cancelConfirmMessage","Are you sure you want to cancel this requirement? This action cannot be undone."),confirmLabel:y("work:requirement.cancelConfirmLabel","Cancel Requirement"),onConfirm:()=>{z(!1),c(e.id)},onCancel:()=>z(!1)}),L&&re&&r.jsx(Vb,{req:e,tasks:Oe,agents:t,teamId:re,onClose:()=>B(!1),onSaved:()=>B(!1)})]})}function df({entityType:e,entityId:t}){const{t:n}=He(["work"]),[s,o]=p.useState([]),[a,i]=p.useState(!0),[l,c]=p.useState(!1);if(p.useEffect(()=>{i(!0),(e==="task"?te.tasks.getHistory:te.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),f=s.length>5&&!l,u=h=>{const m=h.changedByName||h.changedById||(h.changedByType==="human"?"User":h.changedByType==="agent"?"Agent":"System"),g=h.changedByType==="human"?"bg-blue-500/20 text-blue-500":h.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")}),f&&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(h=>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:h.changedByType==="human"?"#3b82f6":h.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(h),r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary line-through",children:h.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:h.toStatus})]}),h.reason&&r.jsx("p",{className:"text-[10px] text-fg-secondary mt-0.5 leading-snug",children:h.reason}),r.jsx("p",{className:"text-[9px] text-fg-tertiary mt-0.5",children:new Date(h.createdAt).toLocaleString()})]})]},h.id))})]})]})}export{sy as WorkPage,Wb as WorkflowsPanel};
|