@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.
Files changed (159) hide show
  1. package/dist/background-maintenance.d.ts +25 -0
  2. package/dist/background-maintenance.d.ts.map +1 -1
  3. package/dist/background-maintenance.js +61 -0
  4. package/dist/background-maintenance.js.map +1 -1
  5. package/dist/commands/im-inbound-origin.d.ts +38 -0
  6. package/dist/commands/im-inbound-origin.d.ts.map +1 -0
  7. package/dist/commands/im-inbound-origin.js +48 -0
  8. package/dist/commands/im-inbound-origin.js.map +1 -0
  9. package/dist/commands/start.d.ts.map +1 -1
  10. package/dist/commands/start.js +211 -46
  11. package/dist/commands/start.js.map +1 -1
  12. package/dist/markus.mjs +18523 -9866
  13. package/dist/web-ui/assets/{AsyncState-_UC7xcxJ.js → AsyncState-fJJNUOXK.js} +1 -1
  14. package/dist/web-ui/assets/ChatComponents-S7d2CAAU.js +14 -0
  15. package/dist/web-ui/assets/{ContentRenderer-C-V5k_3K.js → ContentRenderer-DWqhC0uq.js} +6 -6
  16. package/dist/web-ui/assets/DeliverableShareModal-B7DwzEnt.js +1 -0
  17. package/dist/web-ui/assets/{Deliverables-CQnWqbTb.js → Deliverables-CueBYYpx.js} +2 -2
  18. package/dist/web-ui/assets/MarkdownMessage-D8BsJzvD.js +4 -0
  19. package/dist/web-ui/assets/{Search-CVYQIy_D.js → Search-CaYXz3u-.js} +1 -1
  20. package/dist/web-ui/assets/{SendToChat-IOAvuta-.js → SendToChat-_9sm7UBY.js} +1 -1
  21. package/dist/web-ui/assets/Settings-DTL14pY8.js +8 -0
  22. package/dist/web-ui/assets/{Store-BEsLd_RN.js → Store-DpGqUMS2.js} +1 -1
  23. package/dist/web-ui/assets/Switch-NYQTn8wl.js +1 -0
  24. package/dist/web-ui/assets/Team-DB-JytPl.js +93 -0
  25. package/dist/web-ui/assets/Work-sQq-gy3S.js +142 -0
  26. package/dist/web-ui/assets/{arc-DP1Vf7Sx.js → arc-JtkmqkSR.js} +1 -1
  27. package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-Buq8JYN8.js → architectureDiagram-3BPJPVTR-B8zM5fky.js} +1 -1
  28. package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-BCa2p2_X.js → blockDiagram-GPEHLZMM-BQgjaOcE.js} +1 -1
  29. package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-BxsgggQY.js → c4Diagram-AAUBKEIU-BnZvYRwj.js} +1 -1
  30. package/dist/web-ui/assets/channel-Zno2q8Ba.js +1 -0
  31. package/dist/web-ui/assets/{chunk-2J33WTMH-BJZZ60c9.js → chunk-2J33WTMH-KONx1qvt.js} +1 -1
  32. package/dist/web-ui/assets/{chunk-4BX2VUAB-C5hc4E6J.js → chunk-4BX2VUAB-BqkxAkWs.js} +1 -1
  33. package/dist/web-ui/assets/{chunk-55IACEB6-CbyvZ6Mk.js → chunk-55IACEB6-DxLiTj85.js} +1 -1
  34. package/dist/web-ui/assets/{chunk-727SXJPM-JmNt9TVA.js → chunk-727SXJPM-Dhj-9NIs.js} +1 -1
  35. package/dist/web-ui/assets/{chunk-AQP2D5EJ-BTk0v5ba.js → chunk-AQP2D5EJ-M1vQ4YYc.js} +1 -1
  36. package/dist/web-ui/assets/{chunk-FMBD7UC4-BO-dhB1U.js → chunk-FMBD7UC4-DaXv58SH.js} +1 -1
  37. package/dist/web-ui/assets/{chunk-ND2GUHAM-BdjCcLdb.js → chunk-ND2GUHAM-Brkz9FCu.js} +1 -1
  38. package/dist/web-ui/assets/{chunk-QZHKN3VN-BAzRC82n.js → chunk-QZHKN3VN-DIsEGiBf.js} +1 -1
  39. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-hI59DDUw.js +1 -0
  40. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-hI59DDUw.js +1 -0
  41. package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-CVffmErT.js → cose-bilkent-S5V4N54A-CSjC_YL5.js} +1 -1
  42. package/dist/web-ui/assets/{dagre-BM42HDAG-Dd9pB2fX.js → dagre-BM42HDAG-BevSxaQN.js} +1 -1
  43. package/dist/web-ui/assets/{diagram-2AECGRRQ-BG_AUqzM.js → diagram-2AECGRRQ-CT3Hj8jy.js} +1 -1
  44. package/dist/web-ui/assets/{diagram-5GNKFQAL-D5qFMRFf.js → diagram-5GNKFQAL-CAebHy6q.js} +1 -1
  45. package/dist/web-ui/assets/{diagram-KO2AKTUF-B3qTxSWl.js → diagram-KO2AKTUF-BvRWS7BX.js} +1 -1
  46. package/dist/web-ui/assets/{diagram-LMA3HP47-BrxC1636.js → diagram-LMA3HP47-gR9HBKc4.js} +1 -1
  47. package/dist/web-ui/assets/{diagram-OG6HWLK6-BvXyEQ9-.js → diagram-OG6HWLK6-B5HGsfNo.js} +1 -1
  48. package/dist/web-ui/assets/{docx-preview-DBAZFeEb.js → docx-preview-pRjmDg6F.js} +1 -1
  49. package/dist/web-ui/assets/{erDiagram-TEJ5UH35-CMap9oy_.js → erDiagram-TEJ5UH35-mrPW01aQ.js} +1 -1
  50. package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-BZerJtvk.js → flowDiagram-I6XJVG4X-BrZ1G-Tt.js} +1 -1
  51. package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-CagPMHMO.js → ganttDiagram-6RSMTGT7-Dq_5mate.js} +1 -1
  52. package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-DZ5dDKRu.js → gitGraphDiagram-PVQCEYII-Cb3yTWUy.js} +1 -1
  53. package/dist/web-ui/assets/index-9SXWNIl0.css +1 -0
  54. package/dist/web-ui/assets/index-Bco6UnT7.js +867 -0
  55. package/dist/web-ui/assets/{infoDiagram-5YYISTIA-CHLdsDUZ.js → infoDiagram-5YYISTIA-CcnNlnvs.js} +1 -1
  56. package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-SdeinQaS.js → ishikawaDiagram-YF4QCWOH-BqHTPtO1.js} +1 -1
  57. package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-BtlL2fi0.js → journeyDiagram-JHISSGLW-DKBB9B-C.js} +1 -1
  58. package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-BKPQYXkB.js → kanban-definition-UN3LZRKU-BVO5tbNl.js} +1 -1
  59. package/dist/web-ui/assets/{mermaid.core-MkJR6w4B.js → mermaid.core-bMoKRCj4.js} +5 -5
  60. package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-CbOmHX_u.js → mindmap-definition-RKZ34NQL-Bk0lFKmi.js} +1 -1
  61. package/dist/web-ui/assets/{pieDiagram-4H26LBE5-CypGjJP1.js → pieDiagram-4H26LBE5-BRPnBLeL.js} +1 -1
  62. package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-CGtemfUz.js → quadrantDiagram-W4KKPZXB-CAqdqT5W.js} +1 -1
  63. package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-N7YfpCvE.js → requirementDiagram-4Y6WPE33-Vv5YNzCu.js} +1 -1
  64. package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-CYnSrei-.js → sankeyDiagram-5OEKKPKP-Ciq1EgmQ.js} +1 -1
  65. package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-CsB7dCPF.js → sequenceDiagram-3UESZ5HK-DVRqp161.js} +1 -1
  66. package/dist/web-ui/assets/{stateDiagram-AJRCARHV-DTDFUXFP.js → stateDiagram-AJRCARHV-zbjDSKA3.js} +1 -1
  67. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-C54VSYn7.js +1 -0
  68. package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-C_bWAN9B.js → timeline-definition-PNZ67QCA-D0hr0d1U.js} +1 -1
  69. package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-CX_qAuUT.js → vennDiagram-CIIHVFJN-CtuZLcPo.js} +1 -1
  70. package/dist/web-ui/assets/{wardley-L42UT6IY-q53jQ293.js → wardley-L42UT6IY-nP2-eCDJ.js} +1 -1
  71. package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-D34dKCJU.js → wardleyDiagram-YWT4CUSO-Dxc7OveP.js} +1 -1
  72. package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-BFAngp66.js → xychartDiagram-2RQKCTM6-Bm2LvPhZ.js} +1 -1
  73. package/dist/web-ui/index.html +2 -2
  74. package/docs/README.md +50 -16
  75. package/docs/api/guides/websocket.md +43 -0
  76. package/docs/api/reference.md +657 -0
  77. package/docs/architecture/a2a-communication.md +303 -0
  78. package/docs/architecture/agent-runtime.md +145 -28
  79. package/docs/architecture/architecture.md +30 -11
  80. package/docs/architecture/cognitive-architecture.md +189 -15
  81. package/docs/architecture/concurrent-processing.md +190 -31
  82. package/docs/architecture/context-assembly.md +264 -0
  83. package/docs/architecture/derived-views.md +463 -0
  84. package/docs/architecture/desktop-auto-update.md +185 -0
  85. package/docs/architecture/facts.md +406 -0
  86. package/docs/architecture/learning-loop.md +11 -0
  87. package/docs/architecture/limits.md +79 -0
  88. package/docs/architecture/mailbox-system.md +786 -668
  89. package/docs/architecture/memory-system.md +1 -1
  90. package/docs/architecture/messaging-gateway.md +7 -0
  91. package/docs/architecture/notification-delivery.md +221 -0
  92. package/docs/architecture/notification-sounds.md +177 -0
  93. package/docs/architecture/prompt-engineering.md +171 -700
  94. package/docs/{design/remote-access-contract.md → architecture/remote-access.md} +4 -0
  95. package/docs/architecture/state-machines.md +288 -5
  96. package/docs/architecture/tool-loop-harness.md +362 -0
  97. package/docs/architecture/tool-system.md +40 -16
  98. package/docs/design/background-callback-in-turn-delivery-2026-11-22.md +95 -0
  99. package/docs/design/c10-0b-pick-identity-leak-2026-11-22.md +233 -0
  100. package/docs/design/c10-a-identity-columns-2026-11-22.md +182 -0
  101. package/docs/design/c10-c-trust-boundary-2026-11-23.md +222 -0
  102. package/docs/design/c10-external-adapters-plan-2026-11-19.md +448 -0
  103. package/docs/design/c8-residual-mechanisms-2026-11-15.md +984 -0
  104. package/docs/design/external-signal-decision-loop-2026-11-25.md +579 -0
  105. package/docs/guides/development.md +1 -1
  106. package/docs/{architecture → guides}/mailbox-audit-checklist.md +7 -0
  107. package/docs/guides/remote-access.md +1 -1
  108. package/docs/{design/agent-stop-intent-audit.md → records/agent-stop-intent-audit-2026-11-08.md} +4 -0
  109. package/docs/records/c10-l5-gate-verification-2026-11-26.md +72 -0
  110. package/docs/records/c10-l5-live-verification-2026-11-25.md +117 -0
  111. package/docs/records/cut6-c4-verification-2026-11-12.md +268 -0
  112. package/docs/records/cut6-mailbox-address-envelope-design-2026-11-12.md +871 -0
  113. package/docs/records/cut7-c7a-red-green-evidence-2026-11-13.md +105 -0
  114. package/docs/records/cut7-c7a-workunit-implementation-2026-11-13.md +116 -0
  115. package/docs/records/cut7-c7b-verification-2026-11-14.md +90 -0
  116. package/docs/records/cut7-live-verification-2026-11-14.md +33 -0
  117. package/docs/records/cut7-wiring-negative-cache-2026-11-14.md +64 -0
  118. package/docs/records/cut7-workunit-execution-plan-2026-11-13.md +206 -0
  119. package/docs/records/cut8-a-entity-keys-design-2026-11-14.md +377 -0
  120. package/docs/records/cut8-b-turn-delta-injection-2026-11-14.md +362 -0
  121. package/docs/records/cut8-c-single-clock-2026-11-14.md +119 -0
  122. package/docs/records/cut8-c-single-clock-design-2026-11-14.md +150 -0
  123. package/docs/records/cut8-d-2026-11-14.md +231 -0
  124. package/docs/records/cut8-live-verification-2026-11-14.md +1018 -0
  125. package/docs/records/cut9-adjacent-identity-paths-2026-11-15.md +200 -0
  126. package/docs/records/cut9-identity-declaration-2026-11-15.md +163 -0
  127. package/docs/records/cut9-inbox-dual-run-diff-2026-11-15.md +117 -0
  128. package/docs/records/cut9-live-verification-2026-11-15.md +222 -0
  129. package/docs/records/cut9-runtime-probe-2026-11-19.md +520 -0
  130. package/docs/{design/deliverable-sharing.md → records/deliverable-sharing-2026-08-12.md} +10 -3
  131. package/docs/records/identity-backlog-disposition-2026-11-22.md +143 -0
  132. package/docs/records/marketplace-orphan-freeze-2026-11-22.md +239 -0
  133. package/docs/{architecture/notify-user-context-truth.md → records/notify-user-context-truth-2026-10-28.md} +6 -0
  134. package/docs/{handoff → records}/remote-access-handoff.md +1 -1
  135. package/package.json +1 -1
  136. package/templates/roles/HANDBOOK.md +1 -1
  137. package/templates/skills/agent-building/SKILL.md +1 -1
  138. package/dist/web-ui/assets/ChatComponents-Ca9tWI9W.js +0 -12
  139. package/dist/web-ui/assets/DeliverableShareModal-BvpyowYJ.js +0 -1
  140. package/dist/web-ui/assets/MarkdownMessage-DedA8Zob.js +0 -4
  141. package/dist/web-ui/assets/Settings-BQDqf4q5.js +0 -8
  142. package/dist/web-ui/assets/Switch-C6InTNUi.js +0 -1
  143. package/dist/web-ui/assets/Team-nfNyWj-s.js +0 -85
  144. package/dist/web-ui/assets/Work-BQvgkynj.js +0 -142
  145. package/dist/web-ui/assets/channel-BTSrOo6c.js +0 -1
  146. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-BSYlcnF9.js +0 -1
  147. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-BSYlcnF9.js +0 -1
  148. package/dist/web-ui/assets/index-CKPQYzzR.js +0 -867
  149. package/dist/web-ui/assets/index-CzHSs0Vd.css +0 -1
  150. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-AVnDjlzF.js +0 -1
  151. package/docs/api/api.md +0 -353
  152. package/docs/architecture/llm-provider-timeouts.md +0 -60
  153. package/docs/architecture/state-ownership.md +0 -83
  154. /package/docs/architecture/{frontend/team-chat.md → team-chat.md} +0 -0
  155. /package/docs/{analysis → records}/2026-10-29-a2a-cache-hit-rate.md +0 -0
  156. /package/docs/{fixes → records}/2026-11-12-session-expiry-and-mention-thinking.md +0 -0
  157. /package/docs/{handoff → records}/approval-tri-state-handoff.md +0 -0
  158. /package/docs/{design → records}/overview-attention-redesign.md +0 -0
  159. /package/docs/{remote-access/fast-path-plan.md → records/remote-access-fast-path-plan-2026-10-17.md} +0 -0
@@ -0,0 +1,142 @@
1
+ import{u as ze,j as r,bl as zf,bm as Ff,a3 as Hf,bn as Vf,r as p,k as ee,aD as Wf,a as wr,a1 as Kf,l as kn,n as Gt,P as st,$ as ol,b as Uf,c as Yf,Q as Gf,R as al,bo as Xf,bp as Zf,U as Bt,bc as Ft,bq as Fr,W as Hr,X as Qf,br as qa,bs as cr,bt as za,i as Jf,a7 as js,d as eh,b1 as th,bu as Uc,bv as nh,A as Fa,b6 as Ha,b5 as il,Z as sh,t as rh}from"./index-Bco6UnT7.js";import{t as Yc,a1 as Gc,a2 as oh,a3 as ll,a4 as cl,a5 as ah,a6 as ih,a7 as Xc,a8 as lh,P as ch}from"./ChatComponents-S7d2CAAU.js";import{S as Zc,a as Qc,r as Jc,s as dh}from"./SendToChat-_9sm7UBY.js";import{L as uh,P as fh}from"./AsyncState-fJJNUOXK.js";import{MarkdownMessage as dr}from"./MarkdownMessage-D8BsJzvD.js";import{ContentRenderer as hh}from"./ContentRenderer-DWqhC0uq.js";import{s as Ht,g as ed,j as Va,T as ta,k as na,t as mh}from"./transform-BqqRT-Iy.js";import{i as sa}from"./value-wA6veExk.js";import"./chatChips-DVIRVTpT.js";function ph(e){let t;for(;t=e.sourceEvent;)e=t;return e}function tn(e,t){if(e=ph(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 gh={passive:!1},ur={capture:!0,passive:!1};function ra(e){e.stopImmediatePropagation()}function Ts(e){e.preventDefault(),e.stopImmediatePropagation()}function td(e){var t=e.document.documentElement,n=Ht(e).on("dragstart.drag",Ts,ur);"onselectstart"in t?n.on("selectstart.drag",Ts,ur):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function nd(e,t){var n=e.document.documentElement,s=Ht(e).on("dragstart.drag",null);t&&(s.on("click.drag",Ts,ur),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 Vr=e=>()=>e;function Na(e,{sourceEvent:t,subject:n,target:s,identifier:o,active:a,x:i,y:l,dx:c,dy:d,dispatch:h}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:s,enumerable:!0,configurable:!0},identifier:{value:o,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:i,enumerable:!0,configurable:!0},y:{value:l,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:d,enumerable:!0,configurable:!0},_:{value:h}})}Na.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function xh(e){return!e.ctrlKey&&!e.button}function bh(){return this.parentNode}function yh(e,t){return t??{x:e.x,y:e.y}}function wh(){return navigator.maxTouchPoints||"ontouchstart"in this}function sd(){var e=xh,t=bh,n=yh,s=wh,o={},a=ed("start","drag","end"),i=0,l,c,d,h,u=0;function m(k){k.on("mousedown.drag",f).filter(s).on("touchstart.drag",w).on("touchmove.drag",v,gh).on("touchend.drag touchcancel.drag",y).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(k,C){if(!(h||!e.call(this,k,C))){var j=b(this,t.call(this,k,C),k,C,"mouse");j&&(Ht(k.view).on("mousemove.drag",g,ur).on("mouseup.drag",x,ur),td(k.view),ra(k),d=!1,l=k.clientX,c=k.clientY,j("start",k))}}function g(k){if(Ts(k),!d){var C=k.clientX-l,j=k.clientY-c;d=C*C+j*j>u}o.mouse("drag",k)}function x(k){Ht(k.view).on("mousemove.drag mouseup.drag",null),nd(k.view,d),Ts(k),o.mouse("end",k)}function w(k,C){if(e.call(this,k,C)){var j=k.changedTouches,A=t.call(this,k,C),S=j.length,T,P;for(T=0;T<S;++T)(P=b(this,A,k,C,j[T].identifier,j[T]))&&(ra(k),P("start",k,j[T]))}}function v(k){var C=k.changedTouches,j=C.length,A,S;for(A=0;A<j;++A)(S=o[C[A].identifier])&&(Ts(k),S("drag",k,C[A]))}function y(k){var C=k.changedTouches,j=C.length,A,S;for(h&&clearTimeout(h),h=setTimeout(function(){h=null},500),A=0;A<j;++A)(S=o[C[A].identifier])&&(ra(k),S("end",k,C[A]))}function b(k,C,j,A,S,T){var P=a.copy(),M=tn(T||j,C),D,z,E;if((E=n.call(k,new Na("beforestart",{sourceEvent:j,target:m,identifier:S,active:i,x:M[0],y:M[1],dx:0,dy:0,dispatch:P}),A))!=null)return D=E.x-M[0]||0,z=E.y-M[1]||0,function B(L,$,R){var q=M,H;switch(L){case"start":o[S]=B,H=i++;break;case"end":delete o[S],--i;case"drag":M=tn(R||$,C),H=i;break}P.call(L,k,new Na(L,{sourceEvent:$,subject:E,target:m,identifier:S,active:H,x:M[0]+D,y:M[1]+z,dx:M[0]-q[0],dy:M[1]-q[1],dispatch:P}),A)}}return m.filter=function(k){return arguments.length?(e=typeof k=="function"?k:Vr(!!k),m):e},m.container=function(k){return arguments.length?(t=typeof k=="function"?k:Vr(k),m):t},m.subject=function(k){return arguments.length?(n=typeof k=="function"?k:Vr(k),m):n},m.touchable=function(k){return arguments.length?(s=typeof k=="function"?k:Vr(!!k),m):s},m.on=function(){var k=a.on.apply(a,arguments);return k===a?m:k},m.clickDistance=function(k){return arguments.length?(u=(k=+k)*k,m):Math.sqrt(u)},m}var kh=1e-12;function dl(e){return((e=Math.exp(e))+1/e)/2}function vh(e){return((e=Math.exp(e))-1/e)/2}function jh(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],h=i[0],u=i[1],m=i[2],f=h-l,g=u-c,x=f*f+g*g,w,v;if(x<kh)v=Math.log(m/d)/t,w=function(A){return[l+A*f,c+A*g,d*Math.exp(t*A*v)]};else{var y=Math.sqrt(x),b=(m*m-d*d+s*x)/(2*d*n*y),k=(m*m-d*d-s*x)/(2*m*n*y),C=Math.log(Math.sqrt(b*b+1)-b),j=Math.log(Math.sqrt(k*k+1)-k);v=(j-C)/t,w=function(A){var S=A*v,T=dl(C),P=d/(n*y)*(T*jh(t*S+C)-vh(C));return[l+P*f,c+P*g,d*T/dl(t*S+C)]}}return w.duration=v*1e3*t/Math.SQRT2,w}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),Wr=e=>()=>e;function Nh(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 oa(e){e.stopImmediatePropagation()}function nr(e){e.preventDefault(),e.stopImmediatePropagation()}function Sh(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Ch(){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 ul(){return this.__zoom||Va}function Eh(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Ih(){return navigator.maxTouchPoints||"ontouchstart"in this}function Th(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 rd(){var e=Sh,t=Ch,n=Th,s=Eh,o=Ih,a=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],l=250,c=ao,d=ed("start","zoom","end"),h,u,m,f=500,g=150,x=0,w=10;function v(E){E.property("__zoom",ul).on("wheel.zoom",S,{passive:!1}).on("mousedown.zoom",T).on("dblclick.zoom",P).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(E,B,L,$){var R=E.selection?E.selection():E;R.property("__zoom",ul),E!==R?C(E,B,L,$):R.interrupt().each(function(){j(this,arguments).event($).start().zoom(null,typeof B=="function"?B.apply(this,arguments):B).end()})},v.scaleBy=function(E,B,L,$){v.scaleTo(E,function(){var R=this.__zoom.k,q=typeof B=="function"?B.apply(this,arguments):B;return R*q},L,$)},v.scaleTo=function(E,B,L,$){v.transform(E,function(){var R=t.apply(this,arguments),q=this.__zoom,H=L==null?k(R):typeof L=="function"?L.apply(this,arguments):L,K=q.invert(H),O=typeof B=="function"?B.apply(this,arguments):B;return n(b(y(q,O),H,K),R,i)},L,$)},v.translateBy=function(E,B,L,$){v.transform(E,function(){return n(this.__zoom.translate(typeof B=="function"?B.apply(this,arguments):B,typeof L=="function"?L.apply(this,arguments):L),t.apply(this,arguments),i)},null,$)},v.translateTo=function(E,B,L,$,R){v.transform(E,function(){var q=t.apply(this,arguments),H=this.__zoom,K=$==null?k(q):typeof $=="function"?$.apply(this,arguments):$;return n(Va.translate(K[0],K[1]).scale(H.k).translate(typeof B=="function"?-B.apply(this,arguments):-B,typeof L=="function"?-L.apply(this,arguments):-L),q,i)},$,R)};function y(E,B){return B=Math.max(a[0],Math.min(a[1],B)),B===E.k?E:new ta(B,E.x,E.y)}function b(E,B,L){var $=B[0]-L[0]*E.k,R=B[1]-L[1]*E.k;return $===E.x&&R===E.y?E:new ta(E.k,$,R)}function k(E){return[(+E[0][0]+ +E[1][0])/2,(+E[0][1]+ +E[1][1])/2]}function C(E,B,L,$){E.on("start.zoom",function(){j(this,arguments).event($).start()}).on("interrupt.zoom end.zoom",function(){j(this,arguments).event($).end()}).tween("zoom",function(){var R=this,q=arguments,H=j(R,q).event($),K=t.apply(R,q),O=L==null?k(K):typeof L=="function"?L.apply(R,q):L,Y=Math.max(K[1][0]-K[0][0],K[1][1]-K[0][1]),_=R.__zoom,I=typeof B=="function"?B.apply(R,q):B,V=c(_.invert(O).concat(Y/_.k),I.invert(O).concat(Y/I.k));return function(W){if(W===1)W=I;else{var F=V(W),Z=Y/F[2];W=new ta(Z,O[0]-F[0]*Z,O[1]-F[1]*Z)}H.zoom(null,W)}})}function j(E,B,L){return!L&&E.__zooming||new A(E,B)}function A(E,B){this.that=E,this.args=B,this.active=0,this.sourceEvent=null,this.extent=t.apply(E,B),this.taps=0}A.prototype={event:function(E){return E&&(this.sourceEvent=E),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(E,B){return this.mouse&&E!=="mouse"&&(this.mouse[1]=B.invert(this.mouse[0])),this.touch0&&E!=="touch"&&(this.touch0[1]=B.invert(this.touch0[0])),this.touch1&&E!=="touch"&&(this.touch1[1]=B.invert(this.touch1[0])),this.that.__zoom=B,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(E){var B=Ht(this.that).datum();d.call(E,this.that,new Nh(E,{sourceEvent:this.sourceEvent,target:v,transform:this.that.__zoom,dispatch:d}),B)}};function S(E,...B){if(!e.apply(this,arguments))return;var L=j(this,B).event(E),$=this.__zoom,R=Math.max(a[0],Math.min(a[1],$.k*Math.pow(2,s.apply(this,arguments)))),q=tn(E);if(L.wheel)(L.mouse[0][0]!==q[0]||L.mouse[0][1]!==q[1])&&(L.mouse[1]=$.invert(L.mouse[0]=q)),clearTimeout(L.wheel);else{if($.k===R)return;L.mouse=[q,$.invert(q)],na(this),L.start()}nr(E),L.wheel=setTimeout(H,g),L.zoom("mouse",n(b(y($,R),L.mouse[0],L.mouse[1]),L.extent,i));function H(){L.wheel=null,L.end()}}function T(E,...B){if(m||!e.apply(this,arguments))return;var L=E.currentTarget,$=j(this,B,!0).event(E),R=Ht(E.view).on("mousemove.zoom",O,!0).on("mouseup.zoom",Y,!0),q=tn(E,L),H=E.clientX,K=E.clientY;td(E.view),oa(E),$.mouse=[q,this.__zoom.invert(q)],na(this),$.start();function O(_){if(nr(_),!$.moved){var I=_.clientX-H,V=_.clientY-K;$.moved=I*I+V*V>x}$.event(_).zoom("mouse",n(b($.that.__zoom,$.mouse[0]=tn(_,L),$.mouse[1]),$.extent,i))}function Y(_){R.on("mousemove.zoom mouseup.zoom",null),nd(_.view,$.moved),nr(_),$.event(_).end()}}function P(E,...B){if(e.apply(this,arguments)){var L=this.__zoom,$=tn(E.changedTouches?E.changedTouches[0]:E,this),R=L.invert($),q=L.k*(E.shiftKey?.5:2),H=n(b(y(L,q),$,R),t.apply(this,B),i);nr(E),l>0?Ht(this).transition().duration(l).call(C,H,$,E):Ht(this).call(v.transform,H,$,E)}}function M(E,...B){if(e.apply(this,arguments)){var L=E.touches,$=L.length,R=j(this,B,E.changedTouches.length===$).event(E),q,H,K,O;for(oa(E),H=0;H<$;++H)K=L[H],O=tn(K,this),O=[O,this.__zoom.invert(O),K.identifier],R.touch0?!R.touch1&&R.touch0[2]!==O[2]&&(R.touch1=O,R.taps=0):(R.touch0=O,q=!0,R.taps=1+!!h);h&&(h=clearTimeout(h)),q&&(R.taps<2&&(u=O[0],h=setTimeout(function(){h=null},f)),na(this),R.start())}}function D(E,...B){if(this.__zooming){var L=j(this,B).event(E),$=E.changedTouches,R=$.length,q,H,K,O;for(nr(E),q=0;q<R;++q)H=$[q],K=tn(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 Y=L.touch0[0],_=L.touch0[1],I=L.touch1[0],V=L.touch1[1],W=(W=I[0]-Y[0])*W+(W=I[1]-Y[1])*W,F=(F=V[0]-_[0])*F+(F=V[1]-_[1])*F;H=y(H,Math.sqrt(W/F)),K=[(Y[0]+I[0])/2,(Y[1]+I[1])/2],O=[(_[0]+V[0])/2,(_[1]+V[1])/2]}else if(L.touch0)K=L.touch0[0],O=L.touch0[1];else return;L.zoom("touch",n(b(H,K,O),L.extent,i))}}function z(E,...B){if(this.__zooming){var L=j(this,B).event(E),$=E.changedTouches,R=$.length,q,H;for(oa(E),m&&clearTimeout(m),m=setTimeout(function(){m=null},f),q=0;q<R;++q)H=$[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=tn(H,this),Math.hypot(u[0]-H[0],u[1]-H[1])<w)){var K=Ht(this).on("dblclick.zoom");K&&K.apply(this,arguments)}}}return v.wheelDelta=function(E){return arguments.length?(s=typeof E=="function"?E:Wr(+E),v):s},v.filter=function(E){return arguments.length?(e=typeof E=="function"?E:Wr(!!E),v):e},v.touchable=function(E){return arguments.length?(o=typeof E=="function"?E:Wr(!!E),v):o},v.extent=function(E){return arguments.length?(t=typeof E=="function"?E:Wr([[+E[0][0],+E[0][1]],[+E[1][0],+E[1][1]]]),v):t},v.scaleExtent=function(E){return arguments.length?(a[0]=+E[0],a[1]=+E[1],v):[a[0],a[1]]},v.translateExtent=function(E){return arguments.length?(i[0][0]=+E[0][0],i[1][0]=+E[1][0],i[0][1]=+E[0][1],i[1][1]=+E[1][1],v):[[i[0][0],i[0][1]],[i[1][0],i[1][1]]]},v.constrain=function(E){return arguments.length?(n=E,v):n},v.duration=function(E){return arguments.length?(l=+E,v):l},v.interpolate=function(E){return arguments.length?(c=E,v):c},v.on=function(){var E=d.on.apply(d,arguments);return E===d?v:E},v.clickDistance=function(E){return arguments.length?(x=(E=+E)*E,v):Math.sqrt(x)},v.tapDistance=function(E){return arguments.length?(w=+E,v):w},v}const od=new Set(["completed","failed","rejected","cancelled","archived"]);function fr(e){return!!e&&od.has(e)}const ad=new Set(["completed","rejected","cancelled","archived"]);function Mh(e,t={}){const n=[];for(let s=0;s<e.length;s++){const o=e[s];if(o.toStatus!=="review")continue;const a=e[s+1],i=!a,l=`review:${o.id}`,c=t.reviewerId??o.changedById??"",d=t.reviewerName??void 0??(c?t.reviewerNameOf?.(c):void 0)??null;n.push({id:l,reviewerId:c,reviewerName:d,reviewerType:t.reviewerType??null,status:i?"reviewing":"completed",queuedAt:o.createdAt,completedAt:a?a.createdAt:null,round:n.length+1,outcome:a?Ah(a.toStatus):null,decidedByName:a?a.changedByName??null:null,note:a?a.reason??null:null})}return n}function Ah(e){return e==="completed"?"approved":e==="in_progress"?"revision_requested":"closed"}function fl(e){return e.find(t=>t.status==="reviewing")??null}function _h(e){return e.some(t=>t.status==="reviewing")}function Kr(e){return e?new Date(e).getTime():Number.NaN}function Lh(e,t,n="all"){const s=[];if(n!=="review")for(const o of e){const a=o.firstAt??"";Number.isNaN(Kr(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(Kr(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=Kr(o.startedAt)-Kr(a.startedAt);return i!==0?i:o.kind!==a.kind?o.kind==="execution"?-1:1:o.round-a.round})}const hl=6e4,Rh=/^(Reviewing task from\b|Task Review$)/;function Dh(e){const t=(e.label??"").trim();return t?Rh.test(t):!1}function id(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-hl&&n<=o+hl}function Oh(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=>!Dh(o)||o.taskId&&o.taskId!==t.taskId?!1:id(o.startedAt,t)).sort((o,a)=>new Date(o.startedAt).getTime()-new Date(a.startedAt).getTime())}const $h=["30m","1h","2h","4h","8h","12h","1d","1w"],Ph={"30m":"freq30m","1h":"freq1h","2h":"freq2h","4h":"freq4h","8h":"freq8h","12h":"freq12h","1d":"freq1d","1w":"freq1w"};function ml(e){return Ph[e]??"freq4h"}function Bh(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function Sa(){return{mode:"calendar",every:"4h",calendar:"daily",weekdays:[1,2,3,4,5],time:"09:00",cron:"",maxRuns:"",timezone:Bh()}}function ld(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 qh(e){const[t,n]=ld(e);return`${String(t).padStart(2,"0")}:${String(n).padStart(2,"0")}`}function zh(e,t,n){if(e==="cron")return"";const[s,o]=ld(n),a=e==="daily"?"*":e==="weekdays"?"1-5":t.length>0?[...t].sort((i,l)=>i-l).join(","):"*";return`${o} ${s} * * ${a}`}function Fh(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 Hh(e){const t=Sa();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=Fh(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 cd(e){const t={};e.mode==="interval"?t.every=e.every||"4h":(t.cron=e.calendar==="cron"?e.cron.trim():zh(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 Vh=[1,2,3,4,5,6,0];function Wh({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 dd({value:e,onChange:t,compact:n=!1}){const{t:s}=ze(),o=h=>t({...e,...h}),a=`px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg outline-none focus:border-brand-500 ${n?"text-xs":"text-sm"}`,i=h=>{const m=e.weekdays.includes(h)?e.weekdays.filter(f=>f!==h):[...e.weekdays,h];o({weekdays:m})};let l;if(e.mode==="interval")l=s(`work:task.${ml(e.every)}`);else if(e.calendar==="cron")l=s("work:task.scheduleCron",{expr:e.cron.trim()||"—"});else{const h=qh(e.time);if(e.calendar==="daily")l=s("work:task.scheduleDailyAt",{time:h});else if(e.calendar==="weekdays")l=s("work:task.scheduleWeekdaysAt",{time:h});else{const u=[...e.weekdays].sort((m,f)=>m-f).map(m=>s(`work:task.weekdayShort.${m}`)).join(" ");l=e.weekdays.length?s("work:task.scheduleWeeklyAt",{days:u,time:h}):s("work:task.scheduleNoDays")}}const c=e.calendar==="daily"||e.calendar==="weekdays"||e.calendar==="weekly",d="text-fg-tertiary shrink-0 text-xs w-20";return r.jsxs("div",{className:"rounded-lg border border-border-default/70 bg-surface-elevated/40 p-3 space-y-2.5",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[r.jsx("span",{className:d,children:s("work:task.scheduleRepeatMode")}),r.jsx(Wh,{size:n?"sm":"md",value:e.mode,onChange:h=>o({mode:h}),options:[{value:"interval",label:s("work:task.scheduleByInterval")},{value:"calendar",label:s("work:task.scheduleByCalendar")}]})]}),e.mode==="interval"?r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx("span",{className:d,children:s("work:task.scheduleEveryLabel")}),r.jsx("select",{value:e.every,onChange:h=>o({every:h.target.value}),className:a,children:$h.map(h=>r.jsx("option",{value:h,children:s(`work:task.${ml(h)}`)},h))})]}):r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx("span",{className:d,children:s("work:task.scheduleRepeatLabel")}),r.jsxs("select",{value:e.calendar,onChange:h=>o({calendar:h.target.value}),className:a,children:[r.jsx("option",{value:"daily",children:s("work:task.scheduleCalendarDaily")}),r.jsx("option",{value:"weekdays",children:s("work:task.scheduleCalendarWeekdays")}),r.jsx("option",{value:"weekly",children:s("work:task.scheduleCalendarWeekly")}),r.jsx("option",{value:"cron",children:s("work:task.scheduleCalendarCron")})]}),c&&r.jsx("input",{type:"time",value:e.time,onChange:h=>o({time:h.target.value}),className:a})]}),e.calendar==="weekly"&&r.jsx("div",{className:"flex flex-wrap gap-1 pl-[5.5rem]",children:Vh.map(h=>{const u=e.weekdays.includes(h);return r.jsx("button",{type:"button",onClick:()=>i(h),className:`w-7 h-7 rounded-full text-xs transition-colors ${u?"bg-brand-600 text-on-brand":"bg-surface-elevated text-fg-secondary border border-border-default hover:text-fg-primary"}`,children:s(`work:task.weekdayShort.${h}`)},h)})}),e.calendar==="cron"&&r.jsx("input",{value:e.cron,onChange:h=>o({cron:h.target.value}),placeholder:"0 9 * * 1-5",className:`${a} w-full font-mono`})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:d,children:s("work:task.scheduleMaxRuns")}),r.jsx("input",{value:e.maxRuns,onChange:h=>o({maxRuns:h.target.value.replace(/\D/g,"")}),placeholder:s("work:task.scheduleMaxRunsPlaceholder"),className:`${a} w-20`})]}),r.jsxs("div",{className:"text-[11px] text-fg-secondary pt-1 border-t border-border-default/50",children:[s("work:task.schedulePreview",{desc:l}),r.jsxs("span",{className:"text-fg-tertiary",children:[" · ",s("work:task.scheduleTimezoneNote",{tz:e.timezone})]})]})]})}function jt(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=jt(e[n]))!==""&&(t+=(t&&" ")+s);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}const un={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."},hr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ud=["Enter"," ","Escape"],fd={"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 _s;(function(e){e.Strict="strict",e.Loose="loose"})(_s||(_s={}));var ts;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(ts||(ts={}));var mr;(function(e){e.Partial="partial",e.Full="full"})(mr||(mr={}));const hd={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Ln;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Ln||(Ln={}));var Ls;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Ls||(Ls={}));var ve;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(ve||(ve={}));const pl={[ve.Left]:ve.Right,[ve.Right]:ve.Left,[ve.Top]:ve.Bottom,[ve.Bottom]:ve.Top};function md(e){return e===null?null:e?"valid":"invalid"}const pd=e=>"id"in e&&"source"in e&&"target"in e,Kh=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Wa=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),kr=(e,t=[0,0])=>{const{width:n,height:s}=Sn(e),o=e.origin??t,a=n*o[0],i=s*o[1];return{x:e.position.x-a,y:e.position.y-i}},Uh=(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):Wa(o)?o:t.nodeLookup.get(o.id));const l=i?po(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return To(s,l)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Mo(n)},vr=(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=To(n,po(o)),s=!0)}),s?Mo(n):{x:0,y:0,width:0,height:0}},Ka=(e,t,[n,s,o]=[0,0,1],a=!1,i=!1)=>{const l={...Nr(t,[n,s,o]),width:t.width/o,height:t.height/o},c=[];for(const d of e.values()){const{measured:h,selectable:u=!0,hidden:m=!1}=d;if(i&&!u||m)continue;const f=h.width??d.width??d.initialWidth??null,g=h.height??d.height??d.initialHeight??null,x=pr(l,Ds(d)),w=(f??0)*(g??0),v=a&&x>0;(!d.internals.handleBounds||v||x>=w||d.dragging)&&c.push(d)}return c},Yh=(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 Gh(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 Xh({nodes:e,width:t,height:n,panZoom:s,minZoom:o,maxZoom:a},i){if(e.size===0)return Promise.resolve(!0);const l=Gh(e,i),c=vr(l),d=Ua(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 gd({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:s=[0,0],nodeExtent:o,onError:a}){const i=n.get(e),l=i.parentId?n.get(i.parentId):void 0,{x:c,y:d}=l?l.internals.positionAbsolute:{x:0,y:0},h=i.origin??s;let u=i.extent||o;if(i.extent==="parent"&&!i.expandParent)if(!l)a?.("005",un.error005());else{const f=l.measured.width,g=l.measured.height;f&&g&&(u=[[c,d],[c+f,d+g]])}else l&&Os(i.extent)&&(u=[[i.extent[0][0]+c,i.extent[0][1]+d],[i.extent[1][0]+c,i.extent[1][1]+d]]);const m=Os(u)?ns(t,u,i.measured):t;return(i.measured.width===void 0||i.measured.height===void 0)&&a?.("015",un.error015()),{position:{x:m.x-c+(i.measured.width??0)*h[0],y:m.y-d+(i.measured.height??0)*h[1]},positionAbsolute:m}}async function Zh({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:s,onBeforeDelete:o}){const a=new Set(e.map(m=>m.id)),i=[];for(const m of n){if(m.deletable===!1)continue;const f=a.has(m.id),g=!f&&m.parentId&&i.find(x=>x.id===m.parentId);(f||g)&&i.push(m)}const l=new Set(t.map(m=>m.id)),c=s.filter(m=>m.deletable!==!1),h=Yh(i,c);for(const m of c)l.has(m.id)&&!h.find(g=>g.id===m.id)&&h.push(m);if(!o)return{edges:h,nodes:i};const u=await o({nodes:i,edges:h});return typeof u=="boolean"?u?{edges:h,nodes:i}:{edges:[],nodes:[]}:u}const Rs=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),ns=(e={x:0,y:0},t,n)=>({x:Rs(e.x,t[0][0],t[1][0]-(n?.width??0)),y:Rs(e.y,t[0][1],t[1][1]-(n?.height??0))});function xd(e,t,n){const{width:s,height:o}=Sn(n),{x:a,y:i}=n.internals.positionAbsolute;return ns(e,[[a,i],[a+s,i+o]],t)}const gl=(e,t,n)=>e<t?Rs(Math.abs(e-t),1,t)/t:e>n?-Rs(Math.abs(e-n),1,t)/t:0,bd=(e,t,n=15,s=40)=>{const o=gl(e.x,s,t.width-s)*n,a=gl(e.y,s,t.height-s)*n;return[o,a]},To=(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)}),Ca=({x:e,y:t,width:n,height:s})=>({x:e,y:t,x2:e+n,y2:t+s}),Mo=({x:e,y:t,x2:n,y2:s})=>({x:e,y:t,width:n-e,height:s-t}),Ds=(e,t=[0,0])=>{const{x:n,y:s}=Wa(e)?e.internals.positionAbsolute:kr(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}},po=(e,t=[0,0])=>{const{x:n,y:s}=Wa(e)?e.internals.positionAbsolute:kr(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)}},yd=(e,t)=>Mo(To(Ca(e),Ca(t))),pr=(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)},xl=e=>nn(e.width)&&nn(e.height)&&nn(e.x)&&nn(e.y),nn=e=>!isNaN(e)&&isFinite(e),Qh=(e,t)=>{},jr=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),Nr=({x:e,y:t},[n,s,o],a=!1,i=[1,1])=>{const l={x:(e-n)/o,y:(t-s)/o};return a?jr(l,i):l},go=({x:e,y:t},[n,s,o])=>({x:e*o+n,y:t*o+s});function ws(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 Jh(e,t,n){if(typeof e=="string"||typeof e=="number"){const s=ws(e,n),o=ws(e,t);return{top:s,right:o,bottom:s,left:o,x:o*2,y:s*2}}if(typeof e=="object"){const s=ws(e.top??e.y??0,n),o=ws(e.bottom??e.y??0,n),a=ws(e.left??e.x??0,t),i=ws(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 em(e,t,n,s,o,a){const{x:i,y:l}=go(e,[t,n,s]),{x:c,y:d}=go({x:e.x+e.width,y:e.y+e.height},[t,n,s]),h=o-c,u=a-d;return{left:Math.floor(i),top:Math.floor(l),right:Math.floor(h),bottom:Math.floor(u)}}const Ua=(e,t,n,s,o,a)=>{const i=Jh(a,t,n),l=(t-i.x)/e.width,c=(n-i.y)/e.height,d=Math.min(l,c),h=Rs(d,s,o),u=e.x+e.width/2,m=e.y+e.height/2,f=t/2-u*h,g=n/2-m*h,x=em(e,f,g,h,t,n),w={left:Math.min(x.left-i.left,0),top:Math.min(x.top-i.top,0),right:Math.min(x.right-i.right,0),bottom:Math.min(x.bottom-i.bottom,0)};return{x:f-w.left+w.right,y:g-w.top+w.bottom,zoom:h}},gr=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Os(e){return e!=null&&e!=="parent"}function Sn(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function wd(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function kd(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 bl(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function tm(){let e,t;return{promise:new Promise((s,o)=>{e=s,t=o}),resolve:e,reject:t}}function nm(e){return{...fd,...e||{}}}function ar(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:s,containerBounds:o}){const{x:a,y:i}=sn(e),l=Nr({x:a-(o?.left??0),y:i-(o?.top??0)},s),{x:c,y:d}=n?jr(l,t):l;return{xSnapped:c,ySnapped:d,...l}}const Ya=e=>({width:e.offsetWidth,height:e.offsetHeight}),vd=e=>e?.getRootNode?.()||window?.document,sm=["INPUT","SELECT","TEXTAREA"];function jd(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:sm.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const Nd=e=>"clientX"in e,sn=(e,t)=>{const n=Nd(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)}},yl=(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,...Ya(i)}})};function Sd({sourceX:e,sourceY:t,targetX:n,targetY:s,sourceControlX:o,sourceControlY:a,targetControlX:i,targetControlY:l}){const c=e*.125+o*.375+i*.375+n*.125,d=t*.125+a*.375+l*.375+s*.125,h=Math.abs(c-e),u=Math.abs(d-t);return[c,d,h,u]}function Ur(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function wl({pos:e,x1:t,y1:n,x2:s,y2:o,c:a}){switch(e){case ve.Left:return[t-Ur(t-s,a),n];case ve.Right:return[t+Ur(s-t,a),n];case ve.Top:return[t,n-Ur(n-o,a)];case ve.Bottom:return[t,n+Ur(o-n,a)]}}function Cd({sourceX:e,sourceY:t,sourcePosition:n=ve.Bottom,targetX:s,targetY:o,targetPosition:a=ve.Top,curvature:i=.25}){const[l,c]=wl({pos:n,x1:e,y1:t,x2:s,y2:o,c:i}),[d,h]=wl({pos:a,x1:s,y1:o,x2:e,y2:t,c:i}),[u,m,f,g]=Sd({sourceX:e,sourceY:t,targetX:s,targetY:o,sourceControlX:l,sourceControlY:c,targetControlX:d,targetControlY:h});return[`M${e},${t} C${l},${c} ${d},${h} ${s},${o}`,u,m,f,g]}function Ed({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 rm({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 om({sourceNode:e,targetNode:t,width:n,height:s,transform:o}){const a=To(po(e),po(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 pr(i,Mo(a))>0}const am=({source:e,sourceHandle:t,target:n,targetHandle:s})=>`xy-edge__${e}${t||""}-${n}${s||""}`,im=(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)),lm=(e,t,n={})=>{if(!e.source||!e.target)return t;const s=n.getEdgeId||am;let o;return pd(e)?o={...e}:o={...e,id:s(e)},im(o,t)?t:(o.sourceHandle===null&&delete o.sourceHandle,o.targetHandle===null&&delete o.targetHandle,t.concat(o))};function Id({sourceX:e,sourceY:t,targetX:n,targetY:s}){const[o,a,i,l]=Ed({sourceX:e,sourceY:t,targetX:n,targetY:s});return[`M ${e},${t}L ${n},${s}`,o,a,i,l]}const kl={[ve.Left]:{x:-1,y:0},[ve.Right]:{x:1,y:0},[ve.Top]:{x:0,y:-1},[ve.Bottom]:{x:0,y:1}},cm=({source:e,sourcePosition:t=ve.Bottom,target:n})=>t===ve.Left||t===ve.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},vl=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function dm({source:e,sourcePosition:t=ve.Bottom,target:n,targetPosition:s=ve.Top,center:o,offset:a,stepPosition:i}){const l=kl[t],c=kl[s],d={x:e.x+l.x*a,y:e.y+l.y*a},h={x:n.x+c.x*a,y:n.y+c.y*a},u=cm({source:d,sourcePosition:t,target:h}),m=u.x!==0?"x":"y",f=u[m];let g=[],x,w;const v={x:0,y:0},y={x:0,y:0},[,,b,k]=Ed({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(l[m]*c[m]===-1){m==="x"?(x=o.x??d.x+(h.x-d.x)*i,w=o.y??(d.y+h.y)/2):(x=o.x??(d.x+h.x)/2,w=o.y??d.y+(h.y-d.y)*i);const j=[{x,y:d.y},{x,y:h.y}],A=[{x:d.x,y:w},{x:h.x,y:w}];l[m]===f?g=m==="x"?j:A:g=m==="x"?A:j}else{const j=[{x:d.x,y:h.y}],A=[{x:h.x,y:d.y}];if(m==="x"?g=l.x===f?A:j:g=l.y===f?j:A,t===s){const D=Math.abs(e[m]-n[m]);if(D<=a){const z=Math.min(a-1,a-D);l[m]===f?v[m]=(d[m]>e[m]?-1:1)*z:y[m]=(h[m]>n[m]?-1:1)*z}}if(t!==s){const D=m==="x"?"y":"x",z=l[m]===c[D],E=d[D]>h[D],B=d[D]<h[D];(l[m]===1&&(!z&&E||z&&B)||l[m]!==1&&(!z&&B||z&&E))&&(g=m==="x"?j:A)}const S={x:d.x+v.x,y:d.y+v.y},T={x:h.x+y.x,y:h.y+y.y},P=Math.max(Math.abs(S.x-g[0].x),Math.abs(T.x-g[0].x)),M=Math.max(Math.abs(S.y-g[0].y),Math.abs(T.y-g[0].y));P>=M?(x=(S.x+T.x)/2,w=g[0].y):(x=g[0].x,w=(S.y+T.y)/2)}return[[e,{x:d.x+v.x,y:d.y+v.y},...g,{x:h.x+y.x,y:h.y+y.y},n],x,w,b,k]}function um(e,t,n,s){const o=Math.min(vl(e,t)/2,vl(t,n)/2,s),{x:a,y:i}=t;if(e.x===a&&a===n.x||e.y===i&&i===n.y)return`L${a} ${i}`;if(e.y===i){const d=e.x<n.x?-1:1,h=e.y<n.y?1:-1;return`L ${a+o*d},${i}Q ${a},${i} ${a},${i+o*h}`}const l=e.x<n.x?1:-1,c=e.y<n.y?-1:1;return`L ${a},${i+o*c}Q ${a},${i} ${a+o*l},${i}`}function Ea({sourceX:e,sourceY:t,sourcePosition:n=ve.Bottom,targetX:s,targetY:o,targetPosition:a=ve.Top,borderRadius:i=5,centerX:l,centerY:c,offset:d=20,stepPosition:h=.5}){const[u,m,f,g,x]=dm({source:{x:e,y:t},sourcePosition:n,target:{x:s,y:o},targetPosition:a,center:{x:l,y:c},offset:d,stepPosition:h});return[u.reduce((v,y,b)=>{let k="";return b>0&&b<u.length-1?k=um(u[b-1],y,u[b+1],i):k=`${b===0?"M":"L"}${y.x} ${y.y}`,v+=k,v},""),m,f,g,x]}function jl(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function fm(e){const{sourceNode:t,targetNode:n}=e;if(!jl(t)||!jl(n))return null;const s=t.internals.handleBounds||Nl(t.handles),o=n.internals.handleBounds||Nl(n.handles),a=Sl(s?.source??[],e.sourceHandle),i=Sl(e.connectionMode===_s.Strict?o?.target??[]:(o?.target??[]).concat(o?.source??[]),e.targetHandle);if(!a||!i)return e.onError?.("008",un.error008(a?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const l=a?.position||ve.Bottom,c=i?.position||ve.Top,d=ss(t,a,l),h=ss(n,i,c);return{sourceX:d.x,sourceY:d.y,targetX:h.x,targetY:h.y,sourcePosition:l,targetPosition:c}}function Nl(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 ss(e,t,n=ve.Left,s=!1){const o=(t?.x??0)+e.internals.positionAbsolute.x,a=(t?.y??0)+e.internals.positionAbsolute.y,{width:i,height:l}=t??Sn(e);if(s)return{x:o+i/2,y:a+l/2};switch(t?.position??n){case ve.Top:return{x:o+i/2,y:a};case ve.Right:return{x:o+i,y:a+l/2};case ve.Bottom:return{x:o+i/2,y:a+l};case ve.Left:return{x:o,y:a+l/2}}}function Sl(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function Ia(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(s=>`${s}=${e[s]}`).join("&")}`:""}function hm(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=Ia(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 Td=1e3,mm=10,Ga={nodeOrigin:[0,0],nodeExtent:hr,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},pm={...Ga,checkEquality:!0};function Xa(e,t){const n={...e};for(const s in t)t[s]!==void 0&&(n[s]=t[s]);return n}function gm(e,t,n){const s=Xa(Ga,n);for(const o of e.values())if(o.parentId)Qa(o,e,t,s);else{const a=kr(o,s.nodeOrigin),i=Os(o.extent)?o.extent:s.nodeExtent,l=ns(a,i,Sn(o));o.internals.positionAbsolute=l}}function xm(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;const n=[],s=[];for(const o of e.handles){const a={id:o.id,width:o.width??1,height:o.height??1,nodeId:e.id,x:o.x,y:o.y,position:o.position,type:o.type};o.type==="source"?n.push(a):o.type==="target"&&s.push(a)}return{source:n,target:s}}function Za(e){return e==="manual"}function Ta(e,t,n,s={}){const o=Xa(pm,s),a={i:0},i=new Map(t),l=o?.elevateNodesOnSelect&&!Za(o.zIndexMode)?Td:0;let c=e.length>0;t.clear(),n.clear();for(const d of e){let h=i.get(d.id);if(o.checkEquality&&d===h?.internals.userNode)t.set(d.id,h);else{const u=kr(d,o.nodeOrigin),m=Os(d.extent)?d.extent:o.nodeExtent,f=ns(u,m,Sn(d));h={...o.defaults,...d,measured:{width:d.measured?.width,height:d.measured?.height},internals:{positionAbsolute:f,handleBounds:xm(d,h),z:Md(d,l,o.zIndexMode),userNode:d}},t.set(d.id,h)}(h.measured===void 0||h.measured.width===void 0||h.measured.height===void 0)&&!h.hidden&&(c=!1),d.parentId&&Qa(h,t,n,s,a)}return c}function bm(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 Qa(e,t,n,s,o){const{elevateNodesOnSelect:a,nodeOrigin:i,nodeExtent:l,zIndexMode:c}=Xa(Ga,s),d=e.parentId,h=t.get(d);if(!h){console.warn(`Parent node ${d} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}bm(e,n),o&&!h.parentId&&h.internals.rootParentIndex===void 0&&c==="auto"&&(h.internals.rootParentIndex=++o.i,h.internals.z=h.internals.z+o.i*mm),o&&h.internals.rootParentIndex!==void 0&&(o.i=h.internals.rootParentIndex);const u=a&&!Za(c)?Td:0,{x:m,y:f,z:g}=ym(e,h,i,l,u,c),{positionAbsolute:x}=e.internals,w=m!==x.x||f!==x.y;(w||g!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:w?{x:m,y:f}:x,z:g}})}function Md(e,t,n){const s=nn(e.zIndex)?e.zIndex:0;return Za(n)?s:s+(e.selected?t:0)}function ym(e,t,n,s,o,a){const{x:i,y:l}=t.internals.positionAbsolute,c=Sn(e),d=kr(e,n),h=Os(e.extent)?ns(d,e.extent,c):d;let u=ns({x:i+h.x,y:l+h.y},s,c);e.extent==="parent"&&(u=xd(u,c,t));const m=Md(e,o,a),f=t.internals.z??0;return{x:u.x,y:u.y,z:f>=m?f+1:m}}function Ja(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??Ds(l),d=yd(c,i.rect);a.set(i.parentId,{expandedRect:d,parent:l})}return a.size>0&&a.forEach(({expandedRect:i,parent:l},c)=>{const d=l.internals.positionAbsolute,h=Sn(l),u=l.origin??s,m=i.x<d.x?Math.round(Math.abs(d.x-i.x)):0,f=i.y<d.y?Math.round(Math.abs(d.y-i.y)):0,g=Math.max(h.width,Math.round(i.width)),x=Math.max(h.height,Math.round(i.height)),w=(g-h.width)*u[0],v=(x-h.height)*u[1];(m>0||f>0||w||v)&&(o.push({id:c,type:"position",position:{x:l.position.x-m+w,y:l.position.y-f+v}}),n.get(c)?.forEach(y=>{e.some(b=>b.id===y.id)||o.push({id:y.id,type:"position",position:{x:y.position.x+m,y:y.position.y+f}})})),(h.width<i.width||h.height<i.height||m||f)&&o.push({id:c,type:"dimensions",setAttributes:!0,dimensions:{width:g+(m?u[0]*m-w:0),height:x+(f?u[1]*f-v:0)}})}),o}function wm(e,t,n,s,o,a,i){const l=s?.querySelector(".xyflow__viewport");let c=!1;if(!l)return{changes:[],updatedInternals:c};const d=[],h=window.getComputedStyle(l),{m22:u}=new window.DOMMatrixReadOnly(h.transform),m=[];for(const f of e.values()){const g=t.get(f.id);if(!g)continue;if(g.hidden){t.set(g.id,{...g,internals:{...g.internals,handleBounds:void 0}}),c=!0;continue}const x=Ya(f.nodeElement),w=g.measured.width!==x.width||g.measured.height!==x.height;if(!!(x.width&&x.height&&(w||!g.internals.handleBounds||f.force))){const y=f.nodeElement.getBoundingClientRect(),b=Os(g.extent)?g.extent:a;let{positionAbsolute:k}=g.internals;g.parentId&&g.extent==="parent"?k=xd(k,x,t.get(g.parentId)):b&&(k=ns(k,b,x));const C={...g,measured:x,internals:{...g.internals,positionAbsolute:k,handleBounds:{source:yl("source",f.nodeElement,y,u,g.id),target:yl("target",f.nodeElement,y,u,g.id)}}};t.set(g.id,C),g.parentId&&Qa(C,t,n,{nodeOrigin:o,zIndexMode:i}),c=!0,w&&(d.push({id:g.id,type:"dimensions",dimensions:x}),g.expandParent&&g.parentId&&m.push({id:g.id,parentId:g.parentId,rect:Ds(C,o)}))}}if(m.length>0){const f=Ja(m,t,n,o);d.push(...f)}return{changes:d,updatedInternals:c}}async function km({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 Cl(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 Ad(e,t,n){e.clear(),t.clear();for(const s of n){const{source:o,target:a,sourceHandle:i=null,targetHandle:l=null}=s,c={edgeId:s.id,source:o,target:a,sourceHandle:i,targetHandle:l},d=`${o}-${i}--${a}-${l}`,h=`${a}-${l}--${o}-${i}`;Cl("source",c,h,e,o,i),Cl("target",c,d,e,a,l),t.set(s.id,s)}}function _d(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:_d(n,t):!1}function El(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 vm(e,t,n,s){const o=new Map;for(const[a,i]of e)if((i.selected||i.id===s)&&(!i.parentId||!_d(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 aa({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 jm({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=jr(a,t);return{x:i.x-a.x,y:i.y-a.y}}function Nm({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:s,onDragStop:o}){let a={x:null,y:null},i=0,l=new Map,c=!1,d={x:0,y:0},h=null,u=!1,m=null,f=!1,g=!1,x=null;function w({noDragClassName:y,handleSelector:b,domNode:k,isSelectable:C,nodeId:j,nodeClickDistance:A=0}){m=Ht(k);function S({x:D,y:z}){const{nodeLookup:E,nodeExtent:B,snapGrid:L,snapToGrid:$,nodeOrigin:R,onNodeDrag:q,onSelectionDrag:H,onError:K,updateNodePositions:O}=t();a={x:D,y:z};let Y=!1;const _=l.size>1,I=_&&B?Ca(vr(l)):null,V=_&&$?jm({dragItems:l,snapGrid:L,x:D,y:z}):null;for(const[W,F]of l){if(!E.has(W))continue;let Z={x:D-F.distance.x,y:z-F.distance.y};$&&(Z=V?{x:Math.round(Z.x+V.x),y:Math.round(Z.y+V.y)}:jr(Z,L));let te=null;if(_&&B&&!F.extent&&I){const{positionAbsolute:be}=F.internals,Ne=be.x-I.x+B[0][0],Ie=be.x+F.measured.width-I.x2+B[1][0],Ce=be.y-I.y+B[0][1],Fe=be.y+F.measured.height-I.y2+B[1][1];te=[[Ne,Ce],[Ie,Fe]]}const{position:ce,positionAbsolute:oe}=gd({nodeId:W,nextPosition:Z,nodeLookup:E,nodeExtent:te||B,nodeOrigin:R,onError:K});Y=Y||F.position.x!==ce.x||F.position.y!==ce.y,F.position=ce,F.internals.positionAbsolute=oe}if(g=g||Y,!!Y&&(O(l,!0),x&&(s||q||!j&&H))){const[W,F]=aa({nodeId:j,dragItems:l,nodeLookup:E});s?.(x,l,W,F),q?.(x,W,F),j||H?.(x,F)}}async function T(){if(!h)return;const{transform:D,panBy:z,autoPanSpeed:E,autoPanOnNodeDrag:B}=t();if(!B){c=!1,cancelAnimationFrame(i);return}const[L,$]=bd(d,h,E);(L!==0||$!==0)&&(a.x=(a.x??0)-L/D[2],a.y=(a.y??0)-$/D[2],await z({x:L,y:$})&&S(a)),i=requestAnimationFrame(T)}function P(D){const{nodeLookup:z,multiSelectionActive:E,nodesDraggable:B,transform:L,snapGrid:$,snapToGrid:R,selectNodesOnDrag:q,onNodeDragStart:H,onSelectionDragStart:K,unselectNodesAndEdges:O}=t();u=!0,(!q||!C)&&!E&&j&&(z.get(j)?.selected||O()),C&&q&&j&&e?.(j);const Y=ar(D.sourceEvent,{transform:L,snapGrid:$,snapToGrid:R,containerBounds:h});if(a=Y,l=vm(z,B,Y,j),l.size>0&&(n||H||!j&&K)){const[_,I]=aa({nodeId:j,dragItems:l,nodeLookup:z});n?.(D.sourceEvent,l,_,I),H?.(D.sourceEvent,_,I),j||K?.(D.sourceEvent,I)}}const M=sd().clickDistance(A).on("start",D=>{const{domNode:z,nodeDragThreshold:E,transform:B,snapGrid:L,snapToGrid:$}=t();h=z?.getBoundingClientRect()||null,f=!1,g=!1,x=D.sourceEvent,E===0&&P(D),a=ar(D.sourceEvent,{transform:B,snapGrid:L,snapToGrid:$,containerBounds:h}),d=sn(D.sourceEvent,h)}).on("drag",D=>{const{autoPanOnNodeDrag:z,transform:E,snapGrid:B,snapToGrid:L,nodeDragThreshold:$,nodeLookup:R}=t(),q=ar(D.sourceEvent,{transform:E,snapGrid:B,snapToGrid:L,containerBounds:h});if(x=D.sourceEvent,(D.sourceEvent.type==="touchmove"&&D.sourceEvent.touches.length>1||j&&!R.has(j))&&(f=!0),!f){if(!c&&z&&u&&(c=!0,T()),!u){const H=sn(D.sourceEvent,h),K=H.x-d.x,O=H.y-d.y;Math.sqrt(K*K+O*O)>$&&P(D)}(a.x!==q.xSnapped||a.y!==q.ySnapped)&&l&&u&&(d=sn(D.sourceEvent,h),S(q))}}).on("end",D=>{if(!(!u||f)&&(c=!1,u=!1,cancelAnimationFrame(i),l.size>0)){const{nodeLookup:z,updateNodePositions:E,onNodeDragStop:B,onSelectionDragStop:L}=t();if(g&&(E(l,!1),g=!1),o||B||!j&&L){const[$,R]=aa({nodeId:j,dragItems:l,nodeLookup:z,dragging:!1});o?.(D.sourceEvent,l,$,R),B?.(D.sourceEvent,$,R),j||L?.(D.sourceEvent,R)}}}).filter(D=>{const z=D.target;return!D.button&&(!y||!El(z,`.${y}`,k))&&(!b||El(z,b,k))});m.call(M)}function v(){m?.on(".drag",null)}return{update:w,destroy:v}}function Sm(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())pr(o,Ds(a))>0&&s.push(a);return s}const Cm=250;function Em(e,t,n,s){let o=[],a=1/0;const i=Sm(e,n,t+Cm);for(const l of i){const c=[...l.internals.handleBounds?.source??[],...l.internals.handleBounds?.target??[]];for(const d of c){if(s.nodeId===d.nodeId&&s.type===d.type&&s.id===d.id)continue;const{x:h,y:u}=ss(l,d,d.position,!0),m=Math.sqrt(Math.pow(h-e.x,2)+Math.pow(u-e.y,2));m>t||(m<a?(o=[{...d,x:h,y:u}],a=m):m===a&&o.push({...d,x:h,y:u}))}}if(!o.length)return null;if(o.length>1){const l=s.type==="source"?"target":"source";return o.find(c=>c.type===l)??o[0]}return o[0]}function Ld(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,...ss(i,c,c.position,!0)}:c}function Rd(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function Im(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const Dd=()=>!0;function Tm(e,{connectionMode:t,connectionRadius:n,handleId:s,nodeId:o,edgeUpdaterType:a,isTarget:i,domNode:l,nodeLookup:c,lib:d,autoPanOnConnect:h,flowId:u,panBy:m,cancelConnection:f,onConnectStart:g,onConnect:x,onConnectEnd:w,isValidConnection:v=Dd,onReconnectEnd:y,updateConnection:b,getTransform:k,getFromHandle:C,autoPanSpeed:j,dragThreshold:A=1,handleDomNode:S}){const T=vd(e.target);let P=0,M;const{x:D,y:z}=sn(e),E=Rd(a,S),B=l?.getBoundingClientRect();let L=!1;if(!B||!E)return;const $=Ld(o,E,s,c,t);if(!$)return;let R=sn(e,B),q=!1,H=null,K=!1,O=null;function Y(){if(!h||!B)return;const[ce,oe]=bd(R,B,j);m({x:ce,y:oe}),P=requestAnimationFrame(Y)}const _={...$,nodeId:o,type:E,position:$.position},I=c.get(o);let W={inProgress:!0,isValid:null,from:ss(I,_,ve.Left,!0),fromHandle:_,fromPosition:_.position,fromNode:I,to:R,toHandle:null,toPosition:pl[_.position],toNode:null,pointer:R};function F(){L=!0,b(W),g?.(e,{nodeId:o,handleId:s,handleType:E})}A===0&&F();function Z(ce){if(!L){const{x:Fe,y:Be}=sn(ce),Re=Fe-D,$e=Be-z;if(!(Re*Re+$e*$e>A*A))return;F()}if(!C()||!_){te(ce);return}const oe=k();R=sn(ce,B),M=Em(Nr(R,oe,!1,[1,1]),n,c,_),q||(Y(),q=!0);const be=Od(ce,{handle:M,connectionMode:t,fromNodeId:o,fromHandleId:s,fromType:i?"target":"source",isValidConnection:v,doc:T,lib:d,flowId:u,nodeLookup:c});O=be.handleDomNode,H=be.connection,K=Im(!!M,be.isValid);const Ne=c.get(o),Ie=Ne?ss(Ne,_,ve.Left,!0):W.from,Ce={...W,from:Ie,isValid:K,to:be.toHandle&&K?go({x:be.toHandle.x,y:be.toHandle.y},oe):R,toHandle:be.toHandle,toPosition:K&&be.toHandle?be.toHandle.position:pl[_.position],toNode:be.toHandle?c.get(be.toHandle.nodeId):null,pointer:R};b(Ce),W=Ce}function te(ce){if(!("touches"in ce&&ce.touches.length>0)){if(L){(M||O)&&H&&K&&x?.(H);const{inProgress:oe,...be}=W,Ne={...be,toPosition:W.toHandle?W.toPosition:null};w?.(ce,Ne),a&&y?.(ce,Ne)}f(),cancelAnimationFrame(P),q=!1,K=!1,H=null,O=null,T.removeEventListener("mousemove",Z),T.removeEventListener("mouseup",te),T.removeEventListener("touchmove",Z),T.removeEventListener("touchend",te)}}T.addEventListener("mousemove",Z),T.addEventListener("mouseup",te),T.addEventListener("touchmove",Z),T.addEventListener("touchend",te)}function Od(e,{handle:t,connectionMode:n,fromNodeId:s,fromHandleId:o,fromType:a,doc:i,lib:l,flowId:c,isValidConnection:d=Dd,nodeLookup:h}){const u=a==="target",m=t?i.querySelector(`.${l}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:f,y:g}=sn(e),x=i.elementFromPoint(f,g),w=x?.classList.contains(`${l}-flow__handle`)?x:m,v={handleDomNode:w,isValid:!1,connection:null,toHandle:null};if(w){const y=Rd(void 0,w),b=w.getAttribute("data-nodeid"),k=w.getAttribute("data-handleid"),C=w.classList.contains("connectable"),j=w.classList.contains("connectableend");if(!b||!y)return v;const A={source:u?b:s,sourceHandle:u?k:o,target:u?s:b,targetHandle:u?o:k};v.connection=A;const T=C&&j&&(n===_s.Strict?u&&y==="source"||!u&&y==="target":b!==s||k!==o);v.isValid=T&&d(A),v.toHandle=Ld(b,y,k,h,n,!0)}return v}const Ma={onPointerDown:Tm,isValid:Od};function Mm({domNode:e,panZoom:t,getTransform:n,getViewScale:s}){const o=Ht(e);function a({translateExtent:l,width:c,height:d,zoomStep:h=1,pannable:u=!0,zoomable:m=!0,inversePan:f=!1}){const g=b=>{if(b.sourceEvent.type!=="wheel"||!t)return;const k=n(),C=b.sourceEvent.ctrlKey&&gr()?10:1,j=-b.sourceEvent.deltaY*(b.sourceEvent.deltaMode===1?.05:b.sourceEvent.deltaMode?1:.002)*h,A=k[2]*Math.pow(2,j*C);t.scaleTo(A)};let x=[0,0];const w=b=>{(b.sourceEvent.type==="mousedown"||b.sourceEvent.type==="touchstart")&&(x=[b.sourceEvent.clientX??b.sourceEvent.touches[0].clientX,b.sourceEvent.clientY??b.sourceEvent.touches[0].clientY])},v=b=>{const k=n();if(b.sourceEvent.type!=="mousemove"&&b.sourceEvent.type!=="touchmove"||!t)return;const C=[b.sourceEvent.clientX??b.sourceEvent.touches[0].clientX,b.sourceEvent.clientY??b.sourceEvent.touches[0].clientY],j=[C[0]-x[0],C[1]-x[1]];x=C;const A=s()*Math.max(k[2],Math.log(k[2]))*(f?-1:1),S={x:k[0]-j[0]*A,y:k[1]-j[1]*A},T=[[0,0],[c,d]];t.setViewportConstrained({x:S.x,y:S.y,zoom:k[2]},T,l)},y=rd().on("start",w).on("zoom",u?v:null).on("zoom.wheel",m?g:null);o.call(y,{})}function i(){o.on("zoom",null)}return{update:a,destroy:i,pointer:tn}}const Ao=e=>({x:e.x,y:e.y,zoom:e.k}),ia=({x:e,y:t,zoom:n})=>Va.translate(e,t).scale(n),Ns=(e,t)=>e.target.closest(`.${t}`),$d=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Am=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,la=(e,t=0,n=Am,s=()=>{})=>{const o=typeof t=="number"&&t>0;return o||s(),o?e.transition().duration(t).ease(n).on("end",s):e},Pd=e=>{const t=e.ctrlKey&&gr()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function _m({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:s,panOnScrollMode:o,panOnScrollSpeed:a,zoomOnPinch:i,onPanZoomStart:l,onPanZoom:c,onPanZoomEnd:d}){return h=>{if(Ns(h,t))return h.ctrlKey&&h.preventDefault(),!1;h.preventDefault(),h.stopImmediatePropagation();const u=n.property("__zoom").k||1;if(h.ctrlKey&&i){const w=tn(h),v=Pd(h),y=u*Math.pow(2,v);s.scaleTo(n,y,w,h);return}const m=h.deltaMode===1?20:1;let f=o===ts.Vertical?0:h.deltaX*m,g=o===ts.Horizontal?0:h.deltaY*m;!gr()&&h.shiftKey&&o!==ts.Vertical&&(f=h.deltaY*m,g=0),s.translateBy(n,-(f/u)*a,-(g/u)*a,{internal:!0});const x=Ao(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(h,x),e.panScrollTimeout=setTimeout(()=>{d?.(h,x),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,l?.(h,x))}}function Lm({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(s,o){const a=s.type==="wheel",i=!t&&a&&!s.ctrlKey,l=Ns(s,e);if(s.ctrlKey&&a&&l&&s.preventDefault(),i||l)return null;s.preventDefault(),n.call(this,s,o)}}function Rm({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return s=>{if(s.sourceEvent?.internal)return;const o=Ao(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 Dm({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:s,onPanZoom:o}){return a=>{e.usedRightMouseButton=!!(n&&$d(t,e.mouseButton??0)),a.sourceEvent?.sync||s([a.transform.x,a.transform.y,a.transform.k]),o&&!a.sourceEvent?.internal&&o?.(a.sourceEvent,Ao(a.transform))}}function Om({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:s,onPanZoomEnd:o,onPaneContextMenu:a}){return i=>{if(!i.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&$d(t,e.mouseButton??0)&&!e.usedRightMouseButton&&i.sourceEvent&&a(i.sourceEvent),e.usedRightMouseButton=!1,s(!1),o)){const l=Ao(i.transform);e.prevViewport=l,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{o?.(i.sourceEvent,l)},n?150:0)}}}function $m({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:s,panOnScroll:o,zoomOnDoubleClick:a,userSelectionActive:i,noWheelClassName:l,noPanClassName:c,lib:d,connectionInProgress:h}){return u=>{const m=e||t,f=n&&u.ctrlKey,g=u.type==="wheel";if(u.button===1&&u.type==="mousedown"&&(Ns(u,`${d}-flow__node`)||Ns(u,`${d}-flow__edge`)))return!0;if(!s&&!m&&!o&&!a&&!n||i||h&&!g||Ns(u,l)&&g||Ns(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(!m&&!o&&!f&&g||!s&&(u.type==="mousedown"||u.type==="touchstart")||Array.isArray(s)&&!s.includes(u.button)&&u.type==="mousedown")return!1;const x=Array.isArray(s)&&s.includes(u.button)||!u.button||u.button<=1;return(!u.ctrlKey||g)&&x}}function Pm({domNode:e,minZoom:t,maxZoom:n,translateExtent:s,viewport:o,onPanZoom:a,onPanZoomStart:i,onPanZoomEnd:l,onDraggingChange:c}){const d={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},h=e.getBoundingClientRect(),u=rd().scaleExtent([t,n]).translateExtent(s),m=Ht(e).call(u);y({x:o.x,y:o.y,zoom:Rs(o.zoom,t,n)},[[0,0],[h.width,h.height]],s);const f=m.on("wheel.zoom"),g=m.on("dblclick.zoom");u.wheelDelta(Pd);function x(M,D){return m?new Promise(z=>{u?.interpolate(D?.interpolate==="linear"?sa:ao).transform(la(m,D?.duration,D?.ease,()=>z(!0)),M)}):Promise.resolve(!1)}function w({noWheelClassName:M,noPanClassName:D,onPaneContextMenu:z,userSelectionActive:E,panOnScroll:B,panOnDrag:L,panOnScrollMode:$,panOnScrollSpeed:R,preventScrolling:q,zoomOnPinch:H,zoomOnScroll:K,zoomOnDoubleClick:O,zoomActivationKeyPressed:Y,lib:_,onTransformChange:I,connectionInProgress:V,paneClickDistance:W,selectionOnDrag:F}){E&&!d.isZoomingOrPanning&&v();const Z=B&&!Y&&!E;u.clickDistance(F?1/0:!nn(W)||W<0?0:W);const te=Z?_m({zoomPanValues:d,noWheelClassName:M,d3Selection:m,d3Zoom:u,panOnScrollMode:$,panOnScrollSpeed:R,zoomOnPinch:H,onPanZoomStart:i,onPanZoom:a,onPanZoomEnd:l}):Lm({noWheelClassName:M,preventScrolling:q,d3ZoomHandler:f});if(m.on("wheel.zoom",te,{passive:!1}),!E){const oe=Rm({zoomPanValues:d,onDraggingChange:c,onPanZoomStart:i});u.on("start",oe);const be=Dm({zoomPanValues:d,panOnDrag:L,onPaneContextMenu:!!z,onPanZoom:a,onTransformChange:I});u.on("zoom",be);const Ne=Om({zoomPanValues:d,panOnDrag:L,panOnScroll:B,onPaneContextMenu:z,onPanZoomEnd:l,onDraggingChange:c});u.on("end",Ne)}const ce=$m({zoomActivationKeyPressed:Y,panOnDrag:L,zoomOnScroll:K,panOnScroll:B,zoomOnDoubleClick:O,zoomOnPinch:H,userSelectionActive:E,noPanClassName:D,noWheelClassName:M,lib:_,connectionInProgress:V});u.filter(ce),O?m.on("dblclick.zoom",g):m.on("dblclick.zoom",null)}function v(){u.on("zoom",null)}async function y(M,D,z){const E=ia(M),B=u?.constrain()(E,D,z);return B&&await x(B),new Promise(L=>L(B))}async function b(M,D){const z=ia(M);return await x(z,D),new Promise(E=>E(z))}function k(M){if(m){const D=ia(M),z=m.property("__zoom");(z.k!==M.zoom||z.x!==M.x||z.y!==M.y)&&u?.transform(m,D,null,{sync:!0})}}function C(){const M=m?mh(m.node()):{x:0,y:0,k:1};return{x:M.x,y:M.y,zoom:M.k}}function j(M,D){return m?new Promise(z=>{u?.interpolate(D?.interpolate==="linear"?sa:ao).scaleTo(la(m,D?.duration,D?.ease,()=>z(!0)),M)}):Promise.resolve(!1)}function A(M,D){return m?new Promise(z=>{u?.interpolate(D?.interpolate==="linear"?sa:ao).scaleBy(la(m,D?.duration,D?.ease,()=>z(!0)),M)}):Promise.resolve(!1)}function S(M){u?.scaleExtent(M)}function T(M){u?.translateExtent(M)}function P(M){const D=!nn(M)||M<0?0:M;u?.clickDistance(D)}return{update:w,destroy:v,setViewport:b,setViewportConstrained:y,getViewport:C,scaleTo:j,scaleBy:A,setScaleExtent:S,setTranslateExtent:T,syncViewport:k,setClickDistance:P}}var $s;(function(e){e.Line="line",e.Handle="handle"})($s||($s={}));function Bm({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 Il(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 Mn(e,t){return Math.max(0,t-e)}function An(e,t){return Math.max(0,e-t)}function Yr(e,t,n){return Math.max(0,t-e,e-n)}function Tl(e,t){return e?!t:t}function qm(e,t,n,s,o,a,i,l){let{affectsX:c,affectsY:d}=t;const{isHorizontal:h,isVertical:u}=t,m=h&&u,{xSnapped:f,ySnapped:g}=n,{minWidth:x,maxWidth:w,minHeight:v,maxHeight:y}=s,{x:b,y:k,width:C,height:j,aspectRatio:A}=e;let S=Math.floor(h?f-e.pointerX:0),T=Math.floor(u?g-e.pointerY:0);const P=C+(c?-S:S),M=j+(d?-T:T),D=-a[0]*C,z=-a[1]*j;let E=Yr(P,x,w),B=Yr(M,v,y);if(i){let R=0,q=0;c&&S<0?R=Mn(b+S+D,i[0][0]):!c&&S>0&&(R=An(b+P+D,i[1][0])),d&&T<0?q=Mn(k+T+z,i[0][1]):!d&&T>0&&(q=An(k+M+z,i[1][1])),E=Math.max(E,R),B=Math.max(B,q)}if(l){let R=0,q=0;c&&S>0?R=An(b+S,l[0][0]):!c&&S<0&&(R=Mn(b+P,l[1][0])),d&&T>0?q=An(k+T,l[0][1]):!d&&T<0&&(q=Mn(k+M,l[1][1])),E=Math.max(E,R),B=Math.max(B,q)}if(o){if(h){const R=Yr(P/A,v,y)*A;if(E=Math.max(E,R),i){let q=0;!c&&!d||c&&!d&&m?q=An(k+z+P/A,i[1][1])*A:q=Mn(k+z+(c?S:-S)/A,i[0][1])*A,E=Math.max(E,q)}if(l){let q=0;!c&&!d||c&&!d&&m?q=Mn(k+P/A,l[1][1])*A:q=An(k+(c?S:-S)/A,l[0][1])*A,E=Math.max(E,q)}}if(u){const R=Yr(M*A,x,w)/A;if(B=Math.max(B,R),i){let q=0;!c&&!d||d&&!c&&m?q=An(b+M*A+D,i[1][0])/A:q=Mn(b+(d?T:-T)*A+D,i[0][0])/A,B=Math.max(B,q)}if(l){let q=0;!c&&!d||d&&!c&&m?q=Mn(b+M*A,l[1][0])/A:q=An(b+(d?T:-T)*A,l[0][0])/A,B=Math.max(B,q)}}}T=T+(T<0?B:-B),S=S+(S<0?E:-E),o&&(m?P>M*A?T=(Tl(c,d)?-S:S)/A:S=(Tl(c,d)?-T:T)*A:h?(T=S/A,d=c):(S=T*A,c=d));const L=c?b+S:b,$=d?k+T:k;return{width:C+(c?-S:S),height:j+(d?-T:T),x:a[0]*S*(c?-1:1)+L,y:a[1]*T*(d?-1:1)+$}}const Bd={width:0,height:0,x:0,y:0},zm={...Bd,pointerX:0,pointerY:0,aspectRatio:1};function Fm(e){return[[0,0],[e.measured.width,e.measured.height]]}function Hm(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 Vm({domNode:e,nodeId:t,getStoreItems:n,onChange:s,onEnd:o}){const a=Ht(e);let i={controlDirection:Il("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function l({controlPosition:d,boundaries:h,keepAspectRatio:u,resizeDirection:m,onResizeStart:f,onResize:g,onResizeEnd:x,shouldResize:w}){let v={...Bd},y={...zm};i={boundaries:h,resizeDirection:m,keepAspectRatio:u,controlDirection:Il(d)};let b,k=null,C=[],j,A,S,T=!1;const P=sd().on("start",M=>{const{nodeLookup:D,transform:z,snapGrid:E,snapToGrid:B,nodeOrigin:L,paneDomNode:$}=n();if(b=D.get(t),!b)return;k=$?.getBoundingClientRect()??null;const{xSnapped:R,ySnapped:q}=ar(M.sourceEvent,{transform:z,snapGrid:E,snapToGrid:B,containerBounds:k});v={width:b.measured.width??0,height:b.measured.height??0,x:b.position.x??0,y:b.position.y??0},y={...v,pointerX:R,pointerY:q,aspectRatio:v.width/v.height},j=void 0,b.parentId&&(b.extent==="parent"||b.expandParent)&&(j=D.get(b.parentId),A=j&&b.extent==="parent"?Fm(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=Hm(K,b,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}f?.(M,{...v})}).on("drag",M=>{const{transform:D,snapGrid:z,snapToGrid:E,nodeOrigin:B}=n(),L=ar(M.sourceEvent,{transform:D,snapGrid:z,snapToGrid:E,containerBounds:k}),$=[];if(!b)return;const{x:R,y:q,width:H,height:K}=v,O={},Y=b.origin??B,{width:_,height:I,x:V,y:W}=qm(y,i.controlDirection,L,i.boundaries,i.keepAspectRatio,Y,A,S),F=_!==H,Z=I!==K,te=V!==R&&F,ce=W!==q&&Z;if(!te&&!ce&&!F&&!Z)return;if((te||ce||Y[0]===1||Y[1]===1)&&(O.x=te?V:v.x,O.y=ce?W:v.y,v.x=O.x,v.y=O.y,C.length>0)){const Ie=V-R,Ce=W-q;for(const Fe of C)Fe.position={x:Fe.position.x-Ie+Y[0]*(_-H),y:Fe.position.y-Ce+Y[1]*(I-K)},$.push(Fe)}if((F||Z)&&(O.width=F&&(!i.resizeDirection||i.resizeDirection==="horizontal")?_:v.width,O.height=Z&&(!i.resizeDirection||i.resizeDirection==="vertical")?I:v.height,v.width=O.width,v.height=O.height),j&&b.expandParent){const Ie=Y[0]*(O.width??0);O.x&&O.x<Ie&&(v.x=Ie,y.x=y.x-(O.x-Ie));const Ce=Y[1]*(O.height??0);O.y&&O.y<Ce&&(v.y=Ce,y.y=y.y-(O.y-Ce))}const oe=Bm({width:v.width,prevWidth:H,height:v.height,prevHeight:K,affectsX:i.controlDirection.affectsX,affectsY:i.controlDirection.affectsY}),be={...v,direction:oe};w?.(M,be)!==!1&&(T=!0,g?.(M,be),s(O,$))}).on("end",M=>{T&&(x?.(M,{...v}),o?.({...v}),T=!1)});a.call(P)}function c(){a.on(".drag",null)}return{update:l,destroy:c}}var ca={exports:{}},da={};var Ml;function Wm(){if(Ml)return da;Ml=1;var e=zf(),t=Ff();function n(d,h){return d===h&&(d!==0||1/d===1/h)||d!==d&&h!==h}var s=typeof Object.is=="function"?Object.is:n,o=t.useSyncExternalStore,a=e.useRef,i=e.useEffect,l=e.useMemo,c=e.useDebugValue;return da.useSyncExternalStoreWithSelector=function(d,h,u,m,f){var g=a(null);if(g.current===null){var x={hasValue:!1,value:null};g.current=x}else x=g.current;g=l(function(){function v(j){if(!y){if(y=!0,b=j,j=m(j),f!==void 0&&x.hasValue){var A=x.value;if(f(A,j))return k=A}return k=j}if(A=k,s(b,j))return A;var S=m(j);return f!==void 0&&f(A,S)?(b=j,A):(b=j,k=S)}var y=!1,b,k,C=u===void 0?null:u;return[function(){return v(h())},C===null?void 0:function(){return v(C())}]},[h,u,m,f]);var w=o(d,g[0],g[1]);return i(function(){x.hasValue=!0,x.value=w},[w]),c(w),w},da}var Al;function Km(){return Al||(Al=1,ca.exports=Wm()),ca.exports}var Um=Km();const Ym=Hf(Um),Gm={},_l=e=>{let t;const n=new Set,s=(h,u)=>{const m=typeof h=="function"?h(t):h;if(!Object.is(m,t)){const f=t;t=u??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(g=>g(t,f))}},o=()=>t,c={setState:s,getState:o,getInitialState:()=>d,subscribe:h=>(n.add(h),()=>n.delete(h)),destroy:()=>{(Gm?"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},Xm=e=>e?_l(e):_l,{useDebugValue:Zm}=Vf,{useSyncExternalStoreWithSelector:Qm}=Ym,Jm=e=>e;function qd(e,t=Jm,n){const s=Qm(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return Zm(s),s}const Ll=(e,t)=>{const n=Xm(e),s=(o,a=t)=>qd(n,o,a);return Object.assign(s,n),s},ep=(e,t)=>e?Ll(e,t):Ll;function ct(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 _o=p.createContext(null),tp=_o.Provider,zd=un.error001();function Ke(e,t){const n=p.useContext(_o);if(n===null)throw new Error(zd);return qd(n,e,t)}function it(){const e=p.useContext(_o);if(e===null)throw new Error(zd);return p.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const Rl={display:"none"},np={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Fd="react-flow__node-desc",Hd="react-flow__edge-desc",sp="react-flow__aria-live",rp=e=>e.ariaLiveMessage,op=e=>e.ariaLabelConfig;function ap({rfId:e}){const t=Ke(rp);return r.jsx("div",{id:`${sp}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:np,children:t})}function ip({rfId:e,disableKeyboardA11y:t}){const n=Ke(op);return r.jsxs(r.Fragment,{children:[r.jsx("div",{id:`${Fd}-${e}`,style:Rl,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),r.jsx("div",{id:`${Hd}-${e}`,style:Rl,children:n["edge.a11yDescription.default"]}),!t&&r.jsx(ap,{rfId:e})]})}const Lo=p.forwardRef(({position:e="top-left",children:t,className:n,style:s,...o},a)=>{const i=`${e}`.split("-");return r.jsx("div",{className:jt(["react-flow__panel",n,...i]),style:s,ref:a,...o,children:t})});Lo.displayName="Panel";function lp({proOptions:e,position:t="bottom-right"}){return e?.hideAttribution?null:r.jsx(Lo,{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 cp=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}},Gr=e=>e.id;function dp(e,t){return ct(e.selectedNodes.map(Gr),t.selectedNodes.map(Gr))&&ct(e.selectedEdges.map(Gr),t.selectedEdges.map(Gr))}function up({onSelectionChange:e}){const t=it(),{selectedNodes:n,selectedEdges:s}=Ke(cp,dp);return p.useEffect(()=>{const o={nodes:n,edges:s};e?.(o),t.getState().onSelectionChangeHandlers.forEach(a=>a(o))},[n,s,e]),null}const fp=e=>!!e.onSelectionChangeHandlers;function hp({onSelectionChange:e}){const t=Ke(fp);return e||t?r.jsx(up,{onSelectionChange:e}):null}const Vd=[0,0],mp={x:0,y:0,zoom:1},pp=["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"],Dl=[...pp,"rfId"],gp=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}),Ol={translateExtent:hr,nodeOrigin:Vd,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function xp(e){const{setNodes:t,setEdges:n,setMinZoom:s,setMaxZoom:o,setTranslateExtent:a,setNodeExtent:i,reset:l,setDefaultNodesAndEdges:c}=Ke(gp,ct),d=it();p.useEffect(()=>(c(e.defaultNodes,e.defaultEdges),()=>{h.current=Ol,l()}),[]);const h=p.useRef(Ol);return p.useEffect(()=>{for(const u of Dl){const m=e[u],f=h.current[u];m!==f&&(typeof e[u]>"u"||(u==="nodes"?t(m):u==="edges"?n(m):u==="minZoom"?s(m):u==="maxZoom"?o(m):u==="translateExtent"?a(m):u==="nodeExtent"?i(m):u==="ariaLabelConfig"?d.setState({ariaLabelConfig:nm(m)}):u==="fitView"?d.setState({fitViewQueued:m}):u==="fitViewOptions"?d.setState({fitViewOptions:m}):d.setState({[u]:m})))}h.current=e},Dl.map(u=>e[u])),null}function $l(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function bp(e){const[t,n]=p.useState(e==="system"?null:e);return p.useEffect(()=>{if(e!=="system"){n(e);return}const s=$l(),o=()=>n(s?.matches?"dark":"light");return o(),s?.addEventListener("change",o),()=>{s?.removeEventListener("change",o)}},[e]),t!==null?t:$l()?.matches?"dark":"light"}const Pl=typeof document<"u"?document:null;function xr(e=null,t={target:Pl,actInsideInputWithModifier:!0}){const[n,s]=p.useState(!1),o=p.useRef(!1),a=p.useRef(new Set([])),[i,l]=p.useMemo(()=>{if(e!==null){const d=(Array.isArray(e)?e:[e]).filter(u=>typeof u=="string").map(u=>u.replace("+",`
2
+ `).replace(`
3
+
4
+ `,`
5
+ +`).split(`
6
+ `)),h=d.reduce((u,m)=>u.concat(...m),[]);return[d,h]}return[[],[]]},[e]);return p.useEffect(()=>{const c=t?.target??Pl,d=t?.actInsideInputWithModifier??!0;if(e!==null){const h=f=>{if(o.current=f.ctrlKey||f.metaKey||f.shiftKey||f.altKey,(!o.current||o.current&&!d)&&jd(f))return!1;const x=ql(f.code,l);if(a.current.add(f[x]),Bl(i,a.current,!1)){const w=f.composedPath?.()?.[0]||f.target,v=w?.nodeName==="BUTTON"||w?.nodeName==="A";t.preventDefault!==!1&&(o.current||!v)&&f.preventDefault(),s(!0)}},u=f=>{const g=ql(f.code,l);Bl(i,a.current,!0)?(s(!1),a.current.clear()):a.current.delete(f[g]),f.key==="Meta"&&a.current.clear(),o.current=!1},m=()=>{a.current.clear(),s(!1)};return c?.addEventListener("keydown",h),c?.addEventListener("keyup",u),window.addEventListener("blur",m),window.addEventListener("contextmenu",m),()=>{c?.removeEventListener("keydown",h),c?.removeEventListener("keyup",u),window.removeEventListener("blur",m),window.removeEventListener("contextmenu",m)}}},[e,s]),n}function Bl(e,t,n){return e.filter(s=>n||s.length===t.size).some(s=>s.every(o=>t.has(o)))}function ql(e,t){return t.includes(e)?"code":"key"}const yp=()=>{const e=it();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=Ua(t,s,o,a,i,n?.padding??.1);return l?(await l.setViewport(c,{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(t,n={})=>{const{transform:s,snapGrid:o,snapToGrid:a,domNode:i}=e.getState();if(!i)return t;const{x:l,y:c}=i.getBoundingClientRect(),d={x:t.x-l,y:t.y-c},h=n.snapGrid??o,u=n.snapToGrid??a;return Nr(d,s,u,h)},flowToScreenPosition:t=>{const{transform:n,domNode:s}=e.getState();if(!s)return t;const{x:o,y:a}=s.getBoundingClientRect(),i=go(t,n);return{x:i.x+o,y:i.y+a}}}),[])};function Wd(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)wp(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 wp(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 Kd(e,t){return Wd(e,t)}function Ud(e,t){return Wd(e,t)}function Xn(e,t){return{id:e,type:"select",selected:t}}function Ss(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(Xn(a.id,i)))}return s}function zl({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 Fl(e){return{id:e.id,type:"remove"}}const Hl=e=>Kh(e),kp=e=>pd(e);function Yd(e){return p.forwardRef(e)}const vp=typeof window<"u"?p.useLayoutEffect:p.useEffect;function Vl(e){const[t,n]=p.useState(BigInt(0)),[s]=p.useState(()=>jp(()=>n(o=>o+BigInt(1))));return vp(()=>{const o=s.get();o.length&&(e(o),s.reset())},[t]),s}function jp(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const Gd=p.createContext(null);function Np({children:e}){const t=it(),n=p.useCallback(l=>{const{nodes:c=[],setNodes:d,hasDefaultNodes:h,onNodesChange:u,nodeLookup:m,fitViewQueued:f,onNodesChangeMiddlewareMap:g}=t.getState();let x=c;for(const v of l)x=typeof v=="function"?v(x):v;let w=zl({items:x,lookup:m});for(const v of g.values())w=v(w);h&&d(x),w.length>0?u?.(w):f&&window.requestAnimationFrame(()=>{const{fitViewQueued:v,nodes:y,setNodes:b}=t.getState();v&&b(y)})},[]),s=Vl(n),o=p.useCallback(l=>{const{edges:c=[],setEdges:d,hasDefaultEdges:h,onEdgesChange:u,edgeLookup:m}=t.getState();let f=c;for(const g of l)f=typeof g=="function"?g(f):g;h?d(f):u&&u(zl({items:f,lookup:m}))},[]),a=Vl(o),i=p.useMemo(()=>({nodeQueue:s,edgeQueue:a}),[]);return r.jsx(Gd.Provider,{value:i,children:e})}function Sp(){const e=p.useContext(Gd);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const Cp=e=>!!e.panZoom;function ei(){const e=yp(),t=it(),n=Sp(),s=Ke(Cp),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:m,nodeOrigin:f}=t.getState(),g=Hl(u)?u:m.get(u.id),x=g.parentId?kd(g.position,g.measured,g.parentId,m,f):g.position,w={...g,position:x,width:g.measured?.width??g.width,height:g.measured?.height??g.height};return Ds(w)},d=(u,m,f={replace:!1})=>{i(g=>g.map(x=>{if(x.id===u){const w=typeof m=="function"?m(x):m;return f.replace&&Hl(w)?w:{...x,...w}}return x}))},h=(u,m,f={replace:!1})=>{l(g=>g.map(x=>{if(x.id===u){const w=typeof m=="function"?m(x):m;return f.replace&&kp(w)?w:{...x,...w}}return x}))};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(m=>({...m}))},getEdge:u=>t.getState().edgeLookup.get(u),setNodes:i,setEdges:l,addNodes:u=>{const m=Array.isArray(u)?u:[u];n.nodeQueue.push(f=>[...f,...m])},addEdges:u=>{const m=Array.isArray(u)?u:[u];n.edgeQueue.push(f=>[...f,...m])},toObject:()=>{const{nodes:u=[],edges:m=[],transform:f}=t.getState(),[g,x,w]=f;return{nodes:u.map(v=>({...v})),edges:m.map(v=>({...v})),viewport:{x:g,y:x,zoom:w}}},deleteElements:async({nodes:u=[],edges:m=[]})=>{const{nodes:f,edges:g,onNodesDelete:x,onEdgesDelete:w,triggerNodeChanges:v,triggerEdgeChanges:y,onDelete:b,onBeforeDelete:k}=t.getState(),{nodes:C,edges:j}=await Zh({nodesToRemove:u,edgesToRemove:m,nodes:f,edges:g,onBeforeDelete:k}),A=j.length>0,S=C.length>0;if(A){const T=j.map(Fl);w?.(j),y(T)}if(S){const T=C.map(Fl);x?.(C),v(T)}return(S||A)&&b?.({nodes:C,edges:j}),{deletedNodes:C,deletedEdges:j}},getIntersectingNodes:(u,m=!0,f)=>{const g=xl(u),x=g?u:c(u),w=f!==void 0;return x?(f||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 b=Ds(w?v:y),k=pr(b,x);return m&&k>0||k>=b.width*b.height||k>=x.width*x.height}):[]},isNodeIntersecting:(u,m,f=!0)=>{const x=xl(u)?u:c(u);if(!x)return!1;const w=pr(x,m);return f&&w>0||w>=m.width*m.height||w>=x.width*x.height},updateNode:d,updateNodeData:(u,m,f={replace:!1})=>{d(u,g=>{const x=typeof m=="function"?m(g):m;return f.replace?{...g,data:x}:{...g,data:{...g.data,...x}}},f)},updateEdge:h,updateEdgeData:(u,m,f={replace:!1})=>{h(u,g=>{const x=typeof m=="function"?m(g):m;return f.replace?{...g,data:x}:{...g,data:{...g.data,...x}}},f)},getNodesBounds:u=>{const{nodeLookup:m,nodeOrigin:f}=t.getState();return Uh(u,{nodeLookup:m,nodeOrigin:f})},getHandleConnections:({type:u,id:m,nodeId:f})=>Array.from(t.getState().connectionLookup.get(`${f}-${u}${m?`-${m}`:""}`)?.values()??[]),getNodeConnections:({type:u,handleId:m,nodeId:f})=>Array.from(t.getState().connectionLookup.get(`${f}${u?m?`-${u}-${m}`:`-${u}`:""}`)?.values()??[]),fitView:async u=>{const m=t.getState().fitViewResolver??tm();return t.setState({fitViewQueued:!0,fitViewOptions:u,fitViewResolver:m}),n.nodeQueue.push(f=>[...f]),m.promise}}},[]);return p.useMemo(()=>({...o,...e,viewportInitialized:s}),[s])}const Wl=e=>e.selected,Ep=typeof window<"u"?window:void 0;function Ip({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=it(),{deleteElements:s}=ei(),o=xr(e,{actInsideInputWithModifier:!1}),a=xr(t,{target:Ep});p.useEffect(()=>{if(o){const{edges:i,nodes:l}=n.getState();s({nodes:l.filter(Wl),edges:i.filter(Wl)}),n.setState({nodesSelectionActive:!1})}},[o]),p.useEffect(()=>{n.setState({multiSelectionActive:a})},[a])}function Tp(e){const t=it();p.useEffect(()=>{const n=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const s=Ya(e.current);(s.height===0||s.width===0)&&t.getState().onError?.("004",un.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 Ro={position:"absolute",width:"100%",height:"100%",top:0,left:0},Mp=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function Ap({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:s=!1,panOnScrollSpeed:o=.5,panOnScrollMode:a=ts.Free,zoomOnDoubleClick:i=!0,panOnDrag:l=!0,defaultViewport:c,translateExtent:d,minZoom:h,maxZoom:u,zoomActivationKeyCode:m,preventScrolling:f=!0,children:g,noWheelClassName:x,noPanClassName:w,onViewportChange:v,isControlledViewport:y,paneClickDistance:b,selectionOnDrag:k}){const C=it(),j=p.useRef(null),{userSelectionActive:A,lib:S,connectionInProgress:T}=Ke(Mp,ct),P=xr(m),M=p.useRef();Tp(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=Pm({domNode:j.current,minZoom:h,maxZoom:u,translateExtent:d,viewport:c,onDraggingChange:L=>C.setState($=>$.paneDragging===L?$:{paneDragging:L}),onPanZoomStart:(L,$)=>{const{onViewportChangeStart:R,onMoveStart:q}=C.getState();q?.(L,$),R?.($)},onPanZoom:(L,$)=>{const{onViewportChange:R,onMove:q}=C.getState();q?.(L,$),R?.($)},onPanZoomEnd:(L,$)=>{const{onViewportChangeEnd:R,onMoveEnd:q}=C.getState();q?.(L,$),R?.($)}});const{x:z,y:E,zoom:B}=M.current.getViewport();return C.setState({panZoom:M.current,transform:[z,E,B],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:P,preventScrolling:f,noPanClassName:w,userSelectionActive:A,noWheelClassName:x,lib:S,onTransformChange:D,connectionInProgress:T,selectionOnDrag:k,paneClickDistance:b})},[e,t,n,s,o,a,i,l,P,f,w,A,x,S,D,T,k,b]),r.jsx("div",{className:"react-flow__renderer",ref:j,style:Ro,children:g})}const _p=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function Lp(){const{userSelectionActive:e,userSelectionRect:t}=Ke(_p,ct);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 ua=(e,t)=>n=>{n.target===t.current&&e?.(n)},Rp=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function Dp({isSelecting:e,selectionKeyPressed:t,selectionMode:n=mr.Full,panOnDrag:s,paneClickDistance:o,selectionOnDrag:a,onSelectionStart:i,onSelectionEnd:l,onPaneClick:c,onPaneContextMenu:d,onPaneScroll:h,onPaneMouseEnter:u,onPaneMouseMove:m,onPaneMouseLeave:f,children:g}){const x=it(),{userSelectionActive:w,elementsSelectable:v,dragging:y,connectionInProgress:b}=Ke(Rp,ct),k=v&&(e||w),C=p.useRef(null),j=p.useRef(),A=p.useRef(new Set),S=p.useRef(new Set),T=p.useRef(!1),P=R=>{if(T.current||b){T.current=!1;return}c?.(R),x.getState().resetSelectedElements(),x.setState({nodesSelectionActive:!1})},M=R=>{if(Array.isArray(s)&&s?.includes(2)){R.preventDefault();return}d?.(R)},D=h?R=>h(R):void 0,z=R=>{T.current&&(R.stopPropagation(),T.current=!1)},E=R=>{const{domNode:q}=x.getState();if(j.current=q?.getBoundingClientRect(),!j.current)return;const H=R.target===C.current;if(!H&&!!R.target.closest(".nokey")||!e||!(a&&H||t)||R.button!==0||!R.isPrimary)return;R.target?.setPointerCapture?.(R.pointerId),T.current=!1;const{x:Y,y:_}=sn(R.nativeEvent,j.current);x.setState({userSelectionRect:{width:0,height:0,startX:Y,startY:_,x:Y,y:_}}),H||(R.stopPropagation(),R.preventDefault())},B=R=>{const{userSelectionRect:q,transform:H,nodeLookup:K,edgeLookup:O,connectionLookup:Y,triggerNodeChanges:_,triggerEdgeChanges:I,defaultEdgeOptions:V,resetSelectedElements:W}=x.getState();if(!j.current||!q)return;const{x:F,y:Z}=sn(R.nativeEvent,j.current),{startX:te,startY:ce}=q;if(!T.current){const Ce=t?0:o;if(Math.hypot(F-te,Z-ce)<=Ce)return;W(),i?.(R)}T.current=!0;const oe={startX:te,startY:ce,x:F<te?F:te,y:Z<ce?Z:ce,width:Math.abs(F-te),height:Math.abs(Z-ce)},be=A.current,Ne=S.current;A.current=new Set(Ka(K,oe,H,n===mr.Partial,!0).map(Ce=>Ce.id)),S.current=new Set;const Ie=V?.selectable??!0;for(const Ce of A.current){const Fe=Y.get(Ce);if(Fe)for(const{edgeId:Be}of Fe.values()){const Re=O.get(Be);Re&&(Re.selectable??Ie)&&S.current.add(Be)}}if(!bl(be,A.current)){const Ce=Ss(K,A.current,!0);_(Ce)}if(!bl(Ne,S.current)){const Ce=Ss(O,S.current);I(Ce)}x.setState({userSelectionRect:oe,userSelectionActive:!0,nodesSelectionActive:!1})},L=R=>{R.button===0&&(R.target?.releasePointerCapture?.(R.pointerId),!w&&R.target===C.current&&x.getState().userSelectionRect&&P?.(R),x.setState({userSelectionActive:!1,userSelectionRect:null}),T.current&&(l?.(R),x.setState({nodesSelectionActive:A.current.size>0})))},$=s===!0||Array.isArray(s)&&s.includes(0);return r.jsxs("div",{className:jt(["react-flow__pane",{draggable:$,dragging:y,selection:e}]),onClick:k?void 0:ua(P,C),onContextMenu:ua(M,C),onWheel:ua(D,C),onPointerEnter:k?void 0:u,onPointerMove:k?B:m,onPointerUp:k?L:void 0,onPointerDownCapture:k?E:void 0,onClickCapture:k?z:void 0,onPointerLeave:f,ref:C,style:Ro,children:[g,r.jsx(Lp,{})]})}function Aa({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",un.error012(e));return}t.setState({nodesSelectionActive:!1}),d.selected?(n||d.selected&&i)&&(a({nodes:[d],edges:[]}),requestAnimationFrame(()=>s?.current?.blur())):o([e])}function Xd({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:s,nodeId:o,isSelectable:a,nodeClickDistance:i}){const l=it(),[c,d]=p.useState(!1),h=p.useRef();return p.useEffect(()=>{h.current=Nm({getStoreItems:()=>l.getState(),onNodeMouseDown:u=>{Aa({id:u,store:l,nodeRef:e})},onDragStart:()=>{d(!0)},onDragStop:()=>{d(!1)}})},[]),p.useEffect(()=>{if(!(t||!e.current||!h.current))return h.current.update({noDragClassName:n,handleSelector:s,domNode:e.current,isSelectable:a,nodeId:o,nodeClickDistance:i}),()=>{h.current?.destroy()}},[n,s,t,a,e,o,i]),c}const Op=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function Zd(){const e=it();return p.useCallback(n=>{const{nodeExtent:s,snapToGrid:o,snapGrid:a,nodesDraggable:i,onError:l,updateNodePositions:c,nodeLookup:d,nodeOrigin:h}=e.getState(),u=new Map,m=Op(i),f=o?a[0]:5,g=o?a[1]:5,x=n.direction.x*f*n.factor,w=n.direction.y*g*n.factor;for(const[,v]of d){if(!m(v))continue;let y={x:v.internals.positionAbsolute.x+x,y:v.internals.positionAbsolute.y+w};o&&(y=jr(y,a));const{position:b,positionAbsolute:k}=gd({nodeId:v.id,nextPosition:y,nodeLookup:d,nodeExtent:s,nodeOrigin:h,onError:l});v.position=b,v.internals.positionAbsolute=k,u.set(v.id,v)}c(u)},[])}const ti=p.createContext(null),$p=ti.Provider;ti.Consumer;const Qd=()=>p.useContext(ti),Pp=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),Bp=(e,t,n)=>s=>{const{connectionClickStartHandle:o,connectionMode:a,connection:i}=s,{fromHandle:l,toHandle:c,isValid:d}=i,h=c?.nodeId===e&&c?.id===t&&c?.type===n;return{connectingFrom:l?.nodeId===e&&l?.id===t&&l?.type===n,connectingTo:h,clickConnecting:o?.nodeId===e&&o?.id===t&&o?.type===n,isPossibleEndHandle:a===_s.Strict?l?.type!==n:e!==l?.nodeId||t!==l?.id,connectionInProcess:!!l,clickConnectionInProcess:!!o,valid:h&&d}};function qp({type:e="source",position:t=ve.Top,isValidConnection:n,isConnectable:s=!0,isConnectableStart:o=!0,isConnectableEnd:a=!0,id:i,onConnect:l,children:c,className:d,onMouseDown:h,onTouchStart:u,...m},f){const g=i||null,x=e==="target",w=it(),v=Qd(),{connectOnClick:y,noPanClassName:b,rfId:k}=Ke(Pp,ct),{connectingFrom:C,connectingTo:j,clickConnecting:A,isPossibleEndHandle:S,connectionInProcess:T,clickConnectionInProcess:P,valid:M}=Ke(Bp(v,g,e),ct);v||w.getState().onError?.("010",un.error010());const D=B=>{const{defaultEdgeOptions:L,onConnect:$,hasDefaultEdges:R}=w.getState(),q={...L,...B};if(R){const{edges:H,setEdges:K}=w.getState();K(lm(q,H))}$?.(q),l?.(q)},z=B=>{if(!v)return;const L=Nd(B.nativeEvent);if(o&&(L&&B.button===0||!L)){const $=w.getState();Ma.onPointerDown(B.nativeEvent,{handleDomNode:B.currentTarget,autoPanOnConnect:$.autoPanOnConnect,connectionMode:$.connectionMode,connectionRadius:$.connectionRadius,domNode:$.domNode,nodeLookup:$.nodeLookup,lib:$.lib,isTarget:x,handleId:g,nodeId:v,flowId:$.rfId,panBy:$.panBy,cancelConnection:$.cancelConnection,onConnectStart:$.onConnectStart,onConnectEnd:(...R)=>w.getState().onConnectEnd?.(...R),updateConnection:$.updateConnection,onConnect:D,isValidConnection:n||((...R)=>w.getState().isValidConnection?.(...R)??!0),getTransform:()=>w.getState().transform,getFromHandle:()=>w.getState().connection.fromHandle,autoPanSpeed:$.autoPanSpeed,dragThreshold:$.connectionDragThreshold})}L?h?.(B):u?.(B)},E=B=>{const{onClickConnectStart:L,onClickConnectEnd:$,connectionClickStartHandle:R,connectionMode:q,isValidConnection:H,lib:K,rfId:O,nodeLookup:Y,connection:_}=w.getState();if(!v||!R&&!o)return;if(!R){L?.(B.nativeEvent,{nodeId:v,handleId:g,handleType:e}),w.setState({connectionClickStartHandle:{nodeId:v,type:e,id:g}});return}const I=vd(B.target),V=n||H,{connection:W,isValid:F}=Ma.isValid(B.nativeEvent,{handle:{nodeId:v,id:g,type:e},connectionMode:q,fromNodeId:R.nodeId,fromHandleId:R.id||null,fromType:R.type,isValidConnection:V,flowId:O,doc:I,lib:K,nodeLookup:Y});F&&W&&D(W);const Z=structuredClone(_);delete Z.inProgress,Z.toPosition=Z.toHandle?Z.toHandle.position:null,$?.(B,Z),w.setState({connectionClickStartHandle:null})};return r.jsx("div",{"data-handleid":g,"data-nodeid":v,"data-handlepos":t,"data-id":`${k}-${v}-${g}-${e}`,className:jt(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",b,d,{source:!x,target:x,connectable:s,connectablestart:o,connectableend:a,clickconnecting:A,connectingfrom:C,connectingto:j,valid:M,connectionindicator:s&&(!T||S)&&(T||P?a:o)}]),onMouseDown:z,onTouchStart:z,onClick:y?E:void 0,ref:f,...m,children:c})}const rs=p.memo(Yd(qp));function zp({data:e,isConnectable:t,sourcePosition:n=ve.Bottom}){return r.jsxs(r.Fragment,{children:[e?.label,r.jsx(rs,{type:"source",position:n,isConnectable:t})]})}function Fp({data:e,isConnectable:t,targetPosition:n=ve.Top,sourcePosition:s=ve.Bottom}){return r.jsxs(r.Fragment,{children:[r.jsx(rs,{type:"target",position:n,isConnectable:t}),e?.label,r.jsx(rs,{type:"source",position:s,isConnectable:t})]})}function Hp(){return null}function Vp({data:e,isConnectable:t,targetPosition:n=ve.Top}){return r.jsxs(r.Fragment,{children:[r.jsx(rs,{type:"target",position:n,isConnectable:t}),e?.label]})}const xo={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},Kl={input:zp,default:Fp,output:Vp,group:Hp};function Wp(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 Kp=e=>{const{width:t,height:n,x:s,y:o}=vr(e.nodeLookup,{filter:a=>!!a.selected});return{width:nn(t)?t:null,height:nn(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 Up({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const s=it(),{width:o,height:a,transformString:i,userSelectionActive:l}=Ke(Kp,ct),c=Zd(),d=p.useRef(null);p.useEffect(()=>{n||d.current?.focus({preventScroll:!0})},[n]);const h=!l&&o!==null&&a!==null;if(Xd({nodeRef:d,disabled:!h}),!h)return null;const u=e?f=>{const g=s.getState().nodes.filter(x=>x.selected);e(f,g)}:void 0,m=f=>{Object.prototype.hasOwnProperty.call(xo,f.key)&&(f.preventDefault(),c({direction:xo[f.key],factor:f.shiftKey?4:1}))};return r.jsx("div",{className:jt(["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:m,style:{width:o,height:a}})})}const Ul=typeof window<"u"?window:void 0,Yp=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Jd({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:s,onPaneMouseLeave:o,onPaneContextMenu:a,onPaneScroll:i,paneClickDistance:l,deleteKeyCode:c,selectionKeyCode:d,selectionOnDrag:h,selectionMode:u,onSelectionStart:m,onSelectionEnd:f,multiSelectionKeyCode:g,panActivationKeyCode:x,zoomActivationKeyCode:w,elementsSelectable:v,zoomOnScroll:y,zoomOnPinch:b,panOnScroll:k,panOnScrollSpeed:C,panOnScrollMode:j,zoomOnDoubleClick:A,panOnDrag:S,defaultViewport:T,translateExtent:P,minZoom:M,maxZoom:D,preventScrolling:z,onSelectionContextMenu:E,noWheelClassName:B,noPanClassName:L,disableKeyboardA11y:$,onViewportChange:R,isControlledViewport:q}){const{nodesSelectionActive:H,userSelectionActive:K}=Ke(Yp,ct),O=xr(d,{target:Ul}),Y=xr(x,{target:Ul}),_=Y||S,I=Y||k,V=h&&_!==!0,W=O||K||V;return Ip({deleteKeyCode:c,multiSelectionKeyCode:g}),r.jsx(Ap,{onPaneContextMenu:a,elementsSelectable:v,zoomOnScroll:y,zoomOnPinch:b,panOnScroll:I,panOnScrollSpeed:C,panOnScrollMode:j,zoomOnDoubleClick:A,panOnDrag:!O&&_,defaultViewport:T,translateExtent:P,minZoom:M,maxZoom:D,zoomActivationKeyCode:w,preventScrolling:z,noWheelClassName:B,noPanClassName:L,onViewportChange:R,isControlledViewport:q,paneClickDistance:l,selectionOnDrag:V,children:r.jsxs(Dp,{onSelectionStart:m,onSelectionEnd:f,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:s,onPaneMouseLeave:o,onPaneContextMenu:a,onPaneScroll:i,panOnDrag:_,isSelecting:!!W,selectionMode:u,selectionKeyPressed:O,paneClickDistance:l,selectionOnDrag:V,children:[e,H&&r.jsx(Up,{onSelectionContextMenu:E,noPanClassName:L,disableKeyboardA11y:$})]})})}Jd.displayName="FlowRenderer";const Gp=p.memo(Jd),Xp=e=>t=>e?Ka(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 Ke(p.useCallback(Xp(e),[e]),ct)}const Qp=e=>e.updateNodeInternals;function Jp(){const e=Ke(Qp),[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 eg({node:e,nodeType:t,hasDimensions:n,resizeObserver:s}){const o=it(),a=p.useRef(null),i=p.useRef(null),l=p.useRef(e.sourcePosition),c=p.useRef(e.targetPosition),d=p.useRef(t),h=n&&!!e.internals.handleBounds;return p.useEffect(()=>{a.current&&!e.hidden&&(!h||i.current!==a.current)&&(i.current&&s?.unobserve(i.current),s?.observe(a.current),i.current=a.current)},[h,e.hidden]),p.useEffect(()=>()=>{i.current&&(s?.unobserve(i.current),i.current=null)},[]),p.useEffect(()=>{if(a.current){const u=d.current!==t,m=l.current!==e.sourcePosition,f=c.current!==e.targetPosition;(u||m||f)&&(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 tg({id:e,onClick:t,onMouseEnter:n,onMouseMove:s,onMouseLeave:o,onContextMenu:a,onDoubleClick:i,nodesDraggable:l,elementsSelectable:c,nodesConnectable:d,nodesFocusable:h,resizeObserver:u,noDragClassName:m,noPanClassName:f,disableKeyboardA11y:g,rfId:x,nodeTypes:w,nodeClickDistance:v,onError:y}){const{node:b,internals:k,isParent:C}=Ke(F=>{const Z=F.nodeLookup.get(e),te=F.parentLookup.has(e);return{node:Z,internals:Z.internals,isParent:te}},ct);let j=b.type||"default",A=w?.[j]||Kl[j];A===void 0&&(y?.("003",un.error003(j)),j="default",A=w?.default||Kl.default);const S=!!(b.draggable||l&&typeof b.draggable>"u"),T=!!(b.selectable||c&&typeof b.selectable>"u"),P=!!(b.connectable||d&&typeof b.connectable>"u"),M=!!(b.focusable||h&&typeof b.focusable>"u"),D=it(),z=wd(b),E=eg({node:b,nodeType:j,hasDimensions:z,resizeObserver:u}),B=Xd({nodeRef:E,disabled:b.hidden||!S,noDragClassName:m,handleSelector:b.dragHandle,nodeId:e,isSelectable:T,nodeClickDistance:v}),L=Zd();if(b.hidden)return null;const $=Sn(b),R=Wp(b),q=T||S||t||n||s||o,H=n?F=>n(F,{...k.userNode}):void 0,K=s?F=>s(F,{...k.userNode}):void 0,O=o?F=>o(F,{...k.userNode}):void 0,Y=a?F=>a(F,{...k.userNode}):void 0,_=i?F=>i(F,{...k.userNode}):void 0,I=F=>{const{selectNodesOnDrag:Z,nodeDragThreshold:te}=D.getState();T&&(!Z||!S||te>0)&&Aa({id:e,store:D,nodeRef:E}),t&&t(F,{...k.userNode})},V=F=>{if(!(jd(F.nativeEvent)||g)){if(ud.includes(F.key)&&T){const Z=F.key==="Escape";Aa({id:e,store:D,unselect:Z,nodeRef:E})}else if(S&&b.selected&&Object.prototype.hasOwnProperty.call(xo,F.key)){F.preventDefault();const{ariaLabelConfig:Z}=D.getState();D.setState({ariaLiveMessage:Z["node.a11yDescription.ariaLiveMessage"]({direction:F.key.replace("Arrow","").toLowerCase(),x:~~k.positionAbsolute.x,y:~~k.positionAbsolute.y})}),L({direction:xo[F.key],factor:F.shiftKey?4:1})}}},W=()=>{if(g||!E.current?.matches(":focus-visible"))return;const{transform:F,width:Z,height:te,autoPanOnNodeFocus:ce,setCenter:oe}=D.getState();if(!ce)return;Ka(new Map([[e,b]]),{x:0,y:0,width:Z,height:te},F,!0).length>0||oe(b.position.x+$.width/2,b.position.y+$.height/2,{zoom:F[2]})};return r.jsx("div",{className:jt(["react-flow__node",`react-flow__node-${j}`,{[f]:S},b.className,{selected:b.selected,selectable:T,parent:C,draggable:S,dragging:B}]),ref:E,style:{zIndex:k.z,transform:`translate(${k.positionAbsolute.x}px,${k.positionAbsolute.y}px)`,pointerEvents:q?"all":"none",visibility:z?"visible":"hidden",...b.style,...R},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:H,onMouseMove:K,onMouseLeave:O,onContextMenu:Y,onClick:I,onDoubleClick:_,onKeyDown:M?V:void 0,tabIndex:M?0:void 0,onFocus:M?W:void 0,role:b.ariaRole??(M?"group":void 0),"aria-roledescription":"node","aria-describedby":g?void 0:`${Fd}-${x}`,"aria-label":b.ariaLabel,...b.domAttributes,children:r.jsx($p,{value:e,children:r.jsx(A,{id:e,data:b.data,type:j,positionAbsoluteX:k.positionAbsolute.x,positionAbsoluteY:k.positionAbsolute.y,selected:b.selected??!1,selectable:T,draggable:S,deletable:b.deletable??!0,isConnectable:P,sourcePosition:b.sourcePosition,targetPosition:b.targetPosition,dragging:B,dragHandle:b.dragHandle,zIndex:k.z,parentId:b.parentId,...$})})})}var ng=p.memo(tg);const sg=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function eu(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:s,elementsSelectable:o,onError:a}=Ke(sg,ct),i=Zp(e.onlyRenderVisibleElements),l=Jp();return r.jsx("div",{className:"react-flow__nodes",style:Ro,children:i.map(c=>r.jsx(ng,{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))})}eu.displayName="NodeRenderer";const rg=p.memo(eu);function og(e){return Ke(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&&om({sourceNode:a,targetNode:i,width:n.width,height:n.height,transform:n.transform})&&s.push(o.id)}return s},[e]),ct)}const ag=({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"})},ig=({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"})},Yl={[Ls.Arrow]:ag,[Ls.ArrowClosed]:ig};function lg(e){const t=it();return p.useMemo(()=>Object.prototype.hasOwnProperty.call(Yl,e)?Yl[e]:(t.getState().onError?.("009",un.error009(e)),null),[e])}const cg=({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=lg(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},tu=({defaultColor:e,rfId:t})=>{const n=Ke(a=>a.edges),s=Ke(a=>a.defaultEdgeOptions),o=p.useMemo(()=>hm(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(cg,{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};tu.displayName="MarkerDefinitions";var dg=p.memo(tu);function nu({x:e,y:t,label:n,labelStyle:s,labelShowBg:o=!0,labelBgStyle:a,labelBgPadding:i=[2,4],labelBgBorderRadius:l=2,children:c,className:d,...h}){const[u,m]=p.useState({x:1,y:0,width:0,height:0}),f=jt(["react-flow__edge-textwrapper",d]),g=p.useRef(null);return p.useEffect(()=>{if(g.current){const x=g.current.getBBox();m({x:x.x,y:x.y,width:x.width,height:x.height})}},[n]),n?r.jsxs("g",{transform:`translate(${e-u.width/2} ${t-u.height/2})`,className:f,visibility:u.width?"visible":"hidden",...h,children:[o&&r.jsx("rect",{width:u.width+2*i[0],x:-i[0],y:-i[1],height:u.height+2*i[1],className:"react-flow__edge-textbg",style:a,rx:l,ry:l}),r.jsx("text",{className:"react-flow__edge-text",y:u.height/2,dy:"0.3em",ref:g,style:s,children:n}),c]}):null}nu.displayName="EdgeText";const ug=p.memo(nu);function Do({path:e,labelX:t,labelY:n,label:s,labelStyle:o,labelShowBg:a,labelBgStyle:i,labelBgPadding:l,labelBgBorderRadius:c,interactionWidth:d=20,...h}){return r.jsxs(r.Fragment,{children:[r.jsx("path",{...h,d:e,fill:"none",className:jt(["react-flow__edge-path",h.className])}),d?r.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:d,className:"react-flow__edge-interaction"}):null,s&&nn(t)&&nn(n)?r.jsx(ug,{x:t,y:n,label:s,labelStyle:o,labelShowBg:a,labelBgStyle:i,labelBgPadding:l,labelBgBorderRadius:c}):null]})}function Gl({pos:e,x1:t,y1:n,x2:s,y2:o}){return e===ve.Left||e===ve.Right?[.5*(t+s),n]:[t,.5*(n+o)]}function su({sourceX:e,sourceY:t,sourcePosition:n=ve.Bottom,targetX:s,targetY:o,targetPosition:a=ve.Top}){const[i,l]=Gl({pos:n,x1:e,y1:t,x2:s,y2:o}),[c,d]=Gl({pos:a,x1:s,y1:o,x2:e,y2:t}),[h,u,m,f]=Sd({sourceX:e,sourceY:t,targetX:s,targetY:o,sourceControlX:i,sourceControlY:l,targetControlX:c,targetControlY:d});return[`M${e},${t} C${i},${l} ${c},${d} ${s},${o}`,h,u,m,f]}function ru(e){return p.memo(({id:t,sourceX:n,sourceY:s,targetX:o,targetY:a,sourcePosition:i,targetPosition:l,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:u,labelBgPadding:m,labelBgBorderRadius:f,style:g,markerEnd:x,markerStart:w,interactionWidth:v})=>{const[y,b,k]=su({sourceX:n,sourceY:s,sourcePosition:i,targetX:o,targetY:a,targetPosition:l}),C=e.isInternal?void 0:t;return r.jsx(Do,{id:C,path:y,labelX:b,labelY:k,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:u,labelBgPadding:m,labelBgBorderRadius:f,style:g,markerEnd:x,markerStart:w,interactionWidth:v})})}const fg=ru({isInternal:!1}),ou=ru({isInternal:!0});fg.displayName="SimpleBezierEdge";ou.displayName="SimpleBezierEdgeInternal";function au(e){return p.memo(({id:t,sourceX:n,sourceY:s,targetX:o,targetY:a,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:u,style:m,sourcePosition:f=ve.Bottom,targetPosition:g=ve.Top,markerEnd:x,markerStart:w,pathOptions:v,interactionWidth:y})=>{const[b,k,C]=Ea({sourceX:n,sourceY:s,sourcePosition:f,targetX:o,targetY:a,targetPosition:g,borderRadius:v?.borderRadius,offset:v?.offset,stepPosition:v?.stepPosition}),j=e.isInternal?void 0:t;return r.jsx(Do,{id:j,path:b,labelX:k,labelY:C,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:u,style:m,markerEnd:x,markerStart:w,interactionWidth:y})})}const iu=au({isInternal:!1}),lu=au({isInternal:!0});iu.displayName="SmoothStepEdge";lu.displayName="SmoothStepEdgeInternal";function cu(e){return p.memo(({id:t,...n})=>{const s=e.isInternal?void 0:t;return r.jsx(iu,{...n,id:s,pathOptions:p.useMemo(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}const hg=cu({isInternal:!1}),du=cu({isInternal:!0});hg.displayName="StepEdge";du.displayName="StepEdgeInternal";function uu(e){return p.memo(({id:t,sourceX:n,sourceY:s,targetX:o,targetY:a,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:u,style:m,markerEnd:f,markerStart:g,interactionWidth:x})=>{const[w,v,y]=Id({sourceX:n,sourceY:s,targetX:o,targetY:a}),b=e.isInternal?void 0:t;return r.jsx(Do,{id:b,path:w,labelX:v,labelY:y,label:i,labelStyle:l,labelShowBg:c,labelBgStyle:d,labelBgPadding:h,labelBgBorderRadius:u,style:m,markerEnd:f,markerStart:g,interactionWidth:x})})}const mg=uu({isInternal:!1}),fu=uu({isInternal:!0});mg.displayName="StraightEdge";fu.displayName="StraightEdgeInternal";function hu(e){return p.memo(({id:t,sourceX:n,sourceY:s,targetX:o,targetY:a,sourcePosition:i=ve.Bottom,targetPosition:l=ve.Top,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:u,labelBgPadding:m,labelBgBorderRadius:f,style:g,markerEnd:x,markerStart:w,pathOptions:v,interactionWidth:y})=>{const[b,k,C]=Cd({sourceX:n,sourceY:s,sourcePosition:i,targetX:o,targetY:a,targetPosition:l,curvature:v?.curvature}),j=e.isInternal?void 0:t;return r.jsx(Do,{id:j,path:b,labelX:k,labelY:C,label:c,labelStyle:d,labelShowBg:h,labelBgStyle:u,labelBgPadding:m,labelBgBorderRadius:f,style:g,markerEnd:x,markerStart:w,interactionWidth:y})})}const pg=hu({isInternal:!1}),mu=hu({isInternal:!0});pg.displayName="BezierEdge";mu.displayName="BezierEdgeInternal";const Xl={default:mu,straight:fu,step:du,smoothstep:lu,simplebezier:ou},Zl={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},gg=(e,t,n)=>n===ve.Left?e-t:n===ve.Right?e+t:e,xg=(e,t,n)=>n===ve.Top?e-t:n===ve.Bottom?e+t:e,Ql="react-flow__edgeupdater";function Jl({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:jt([Ql,`${Ql}-${l}`]),cx:gg(t,s,e),cy:xg(n,s,e),r:s,stroke:"transparent",fill:"transparent"})}function bg({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:s,sourceY:o,targetX:a,targetY:i,sourcePosition:l,targetPosition:c,onReconnect:d,onReconnectStart:h,onReconnectEnd:u,setReconnecting:m,setUpdateHover:f}){const g=it(),x=(k,C)=>{if(k.button!==0)return;const{autoPanOnConnect:j,domNode:A,connectionMode:S,connectionRadius:T,lib:P,onConnectStart:M,cancelConnection:D,nodeLookup:z,rfId:E,panBy:B,updateConnection:L}=g.getState(),$=C.type==="target",R=(K,O)=>{m(!1),u?.(K,n,C.type,O)},q=K=>d?.(n,K),H=(K,O)=>{m(!0),h?.(k,n,C.type),M?.(K,O)};Ma.onPointerDown(k.nativeEvent,{autoPanOnConnect:j,connectionMode:S,connectionRadius:T,domNode:A,handleId:C.id,nodeId:C.nodeId,nodeLookup:z,isTarget:$,edgeUpdaterType:C.type,lib:P,flowId:E,cancelConnection:D,panBy:B,isValidConnection:(...K)=>g.getState().isValidConnection?.(...K)??!0,onConnect:q,onConnectStart:H,onConnectEnd:(...K)=>g.getState().onConnectEnd?.(...K),onReconnectEnd:R,updateConnection:L,getTransform:()=>g.getState().transform,getFromHandle:()=>g.getState().connection.fromHandle,dragThreshold:g.getState().connectionDragThreshold,handleDomNode:k.currentTarget})},w=k=>x(k,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),v=k=>x(k,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),y=()=>f(!0),b=()=>f(!1);return r.jsxs(r.Fragment,{children:[(e===!0||e==="source")&&r.jsx(Jl,{position:l,centerX:s,centerY:o,radius:t,onMouseDown:w,onMouseEnter:y,onMouseOut:b,type:"source"}),(e===!0||e==="target")&&r.jsx(Jl,{position:c,centerX:a,centerY:i,radius:t,onMouseDown:v,onMouseEnter:y,onMouseOut:b,type:"target"})]})}function yg({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:s,onClick:o,onDoubleClick:a,onContextMenu:i,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,reconnectRadius:h,onReconnect:u,onReconnectStart:m,onReconnectEnd:f,rfId:g,edgeTypes:x,noPanClassName:w,onError:v,disableKeyboardA11y:y}){let b=Ke(oe=>oe.edgeLookup.get(e));const k=Ke(oe=>oe.defaultEdgeOptions);b=k?{...k,...b}:b;let C=b.type||"default",j=x?.[C]||Xl[C];j===void 0&&(v?.("011",un.error011(C)),C="default",j=x?.default||Xl.default);const A=!!(b.focusable||t&&typeof b.focusable>"u"),S=typeof u<"u"&&(b.reconnectable||n&&typeof b.reconnectable>"u"),T=!!(b.selectable||s&&typeof b.selectable>"u"),P=p.useRef(null),[M,D]=p.useState(!1),[z,E]=p.useState(!1),B=it(),{zIndex:L,sourceX:$,sourceY:R,targetX:q,targetY:H,sourcePosition:K,targetPosition:O}=Ke(p.useCallback(oe=>{const be=oe.nodeLookup.get(b.source),Ne=oe.nodeLookup.get(b.target);if(!be||!Ne)return{zIndex:b.zIndex,...Zl};const Ie=fm({id:e,sourceNode:be,targetNode:Ne,sourceHandle:b.sourceHandle||null,targetHandle:b.targetHandle||null,connectionMode:oe.connectionMode,onError:v});return{zIndex:rm({selected:b.selected,zIndex:b.zIndex,sourceNode:be,targetNode:Ne,elevateOnSelect:oe.elevateEdgesOnSelect,zIndexMode:oe.zIndexMode}),...Ie||Zl}},[b.source,b.target,b.sourceHandle,b.targetHandle,b.selected,b.zIndex]),ct),Y=p.useMemo(()=>b.markerStart?`url('#${Ia(b.markerStart,g)}')`:void 0,[b.markerStart,g]),_=p.useMemo(()=>b.markerEnd?`url('#${Ia(b.markerEnd,g)}')`:void 0,[b.markerEnd,g]);if(b.hidden||$===null||R===null||q===null||H===null)return null;const I=oe=>{const{addSelectedEdges:be,unselectNodesAndEdges:Ne,multiSelectionActive:Ie}=B.getState();T&&(B.setState({nodesSelectionActive:!1}),b.selected&&Ie?(Ne({nodes:[],edges:[b]}),P.current?.blur()):be([e])),o&&o(oe,b)},V=a?oe=>{a(oe,{...b})}:void 0,W=i?oe=>{i(oe,{...b})}:void 0,F=l?oe=>{l(oe,{...b})}:void 0,Z=c?oe=>{c(oe,{...b})}:void 0,te=d?oe=>{d(oe,{...b})}:void 0,ce=oe=>{if(!y&&ud.includes(oe.key)&&T){const{unselectNodesAndEdges:be,addSelectedEdges:Ne}=B.getState();oe.key==="Escape"?(P.current?.blur(),be({edges:[b]})):Ne([e])}};return r.jsx("svg",{style:{zIndex:L},children:r.jsxs("g",{className:jt(["react-flow__edge",`react-flow__edge-${C}`,b.className,w,{selected:b.selected,animated:b.animated,inactive:!T&&!o,updating:M,selectable:T}]),onClick:I,onDoubleClick:V,onContextMenu:W,onMouseEnter:F,onMouseMove:Z,onMouseLeave:te,onKeyDown:A?ce:void 0,tabIndex:A?0:void 0,role:b.ariaRole??(A?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":b.ariaLabel===null?void 0:b.ariaLabel||`Edge from ${b.source} to ${b.target}`,"aria-describedby":A?`${Hd}-${g}`:void 0,ref:P,...b.domAttributes,children:[!z&&r.jsx(j,{id:e,source:b.source,target:b.target,type:b.type,selected:b.selected,animated:b.animated,selectable:T,deletable:b.deletable??!0,label:b.label,labelStyle:b.labelStyle,labelShowBg:b.labelShowBg,labelBgStyle:b.labelBgStyle,labelBgPadding:b.labelBgPadding,labelBgBorderRadius:b.labelBgBorderRadius,sourceX:$,sourceY:R,targetX:q,targetY:H,sourcePosition:K,targetPosition:O,data:b.data,style:b.style,sourceHandleId:b.sourceHandle,targetHandleId:b.targetHandle,markerStart:Y,markerEnd:_,pathOptions:"pathOptions"in b?b.pathOptions:void 0,interactionWidth:b.interactionWidth}),S&&r.jsx(bg,{edge:b,isReconnectable:S,reconnectRadius:h,onReconnect:u,onReconnectStart:m,onReconnectEnd:f,sourceX:$,sourceY:R,targetX:q,targetY:H,sourcePosition:K,targetPosition:O,setUpdateHover:D,setReconnecting:E})]})})}var wg=p.memo(yg);const kg=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function pu({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:s,noPanClassName:o,onReconnect:a,onEdgeContextMenu:i,onEdgeMouseEnter:l,onEdgeMouseMove:c,onEdgeMouseLeave:d,onEdgeClick:h,reconnectRadius:u,onEdgeDoubleClick:m,onReconnectStart:f,onReconnectEnd:g,disableKeyboardA11y:x}){const{edgesFocusable:w,edgesReconnectable:v,elementsSelectable:y,onError:b}=Ke(kg,ct),k=og(t);return r.jsxs("div",{className:"react-flow__edges",children:[r.jsx(dg,{defaultColor:e,rfId:n}),k.map(C=>r.jsx(wg,{id:C,edgesFocusable:w,edgesReconnectable:v,elementsSelectable:y,noPanClassName:o,onReconnect:a,onContextMenu:i,onMouseEnter:l,onMouseMove:c,onMouseLeave:d,onClick:h,reconnectRadius:u,onDoubleClick:m,onReconnectStart:f,onReconnectEnd:g,rfId:n,onError:b,edgeTypes:s,disableKeyboardA11y:x},C))]})}pu.displayName="EdgeRenderer";const vg=p.memo(pu),jg=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Ng({children:e}){const t=Ke(jg);return r.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function Sg(e){const t=ei(),n=p.useRef(!1);p.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Cg=e=>e.panZoom?.syncViewport;function Eg(e){const t=Ke(Cg),n=it();return p.useEffect(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function Ig(e){return e.connection.inProgress?{...e.connection,to:Nr(e.connection.to,e.transform)}:{...e.connection}}function Tg(e){return Ig}function Mg(e){const t=Tg();return Ke(t,ct)}const Ag=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function _g({containerStyle:e,style:t,type:n,component:s}){const{nodesConnectable:o,width:a,height:i,isValid:l,inProgress:c}=Ke(Ag,ct);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:jt(["react-flow__connection",md(l)]),children:r.jsx(gu,{style:t,type:n,CustomComponent:s,isValid:l})})})}const gu=({style:e,type:t=Ln.Bezier,CustomComponent:n,isValid:s})=>{const{inProgress:o,from:a,fromNode:i,fromHandle:l,fromPosition:c,to:d,toNode:h,toHandle:u,toPosition:m,pointer:f}=Mg();if(!o)return;if(n)return r.jsx(n,{connectionLineType:t,connectionLineStyle:e,fromNode:i,fromHandle:l,fromX:a.x,fromY:a.y,toX:d.x,toY:d.y,fromPosition:c,toPosition:m,connectionStatus:md(s),toNode:h,toHandle:u,pointer:f});let g="";const x={sourceX:a.x,sourceY:a.y,sourcePosition:c,targetX:d.x,targetY:d.y,targetPosition:m};switch(t){case Ln.Bezier:[g]=Cd(x);break;case Ln.SimpleBezier:[g]=su(x);break;case Ln.Step:[g]=Ea({...x,borderRadius:0});break;case Ln.SmoothStep:[g]=Ea(x);break;default:[g]=Id(x)}return r.jsx("path",{d:g,fill:"none",className:"react-flow__connection-path",style:e})};gu.displayName="ConnectionLine";const Lg={};function ec(e=Lg){p.useRef(e),it(),p.useEffect(()=>{},[e])}function Rg(){it(),p.useRef(!1),p.useEffect(()=>{},[])}function xu({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:s,onEdgeClick:o,onNodeDoubleClick:a,onEdgeDoubleClick:i,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:h,onSelectionContextMenu:u,onSelectionStart:m,onSelectionEnd:f,connectionLineType:g,connectionLineStyle:x,connectionLineComponent:w,connectionLineContainerStyle:v,selectionKeyCode:y,selectionOnDrag:b,selectionMode:k,multiSelectionKeyCode:C,panActivationKeyCode:j,zoomActivationKeyCode:A,deleteKeyCode:S,onlyRenderVisibleElements:T,elementsSelectable:P,defaultViewport:M,translateExtent:D,minZoom:z,maxZoom:E,preventScrolling:B,defaultMarkerColor:L,zoomOnScroll:$,zoomOnPinch:R,panOnScroll:q,panOnScrollSpeed:H,panOnScrollMode:K,zoomOnDoubleClick:O,panOnDrag:Y,onPaneClick:_,onPaneMouseEnter:I,onPaneMouseMove:V,onPaneMouseLeave:W,onPaneScroll:F,onPaneContextMenu:Z,paneClickDistance:te,nodeClickDistance:ce,onEdgeContextMenu:oe,onEdgeMouseEnter:be,onEdgeMouseMove:Ne,onEdgeMouseLeave:Ie,reconnectRadius:Ce,onReconnect:Fe,onReconnectStart:Be,onReconnectEnd:Re,noDragClassName:$e,noWheelClassName:Et,noPanClassName:qe,disableKeyboardA11y:Ge,nodeExtent:ft,rfId:mt,viewport:re,onViewportChange:ue}){return ec(e),ec(t),Rg(),Sg(n),Eg(re),r.jsx(Gp,{onPaneClick:_,onPaneMouseEnter:I,onPaneMouseMove:V,onPaneMouseLeave:W,onPaneContextMenu:Z,onPaneScroll:F,paneClickDistance:te,deleteKeyCode:S,selectionKeyCode:y,selectionOnDrag:b,selectionMode:k,onSelectionStart:m,onSelectionEnd:f,multiSelectionKeyCode:C,panActivationKeyCode:j,zoomActivationKeyCode:A,elementsSelectable:P,zoomOnScroll:$,zoomOnPinch:R,zoomOnDoubleClick:O,panOnScroll:q,panOnScrollSpeed:H,panOnScrollMode:K,panOnDrag:Y,defaultViewport:M,translateExtent:D,minZoom:z,maxZoom:E,onSelectionContextMenu:u,preventScrolling:B,noDragClassName:$e,noWheelClassName:Et,noPanClassName:qe,disableKeyboardA11y:Ge,onViewportChange:ue,isControlledViewport:!!re,children:r.jsxs(Ng,{children:[r.jsx(vg,{edgeTypes:t,onEdgeClick:o,onEdgeDoubleClick:i,onReconnect:Fe,onReconnectStart:Be,onReconnectEnd:Re,onlyRenderVisibleElements:T,onEdgeContextMenu:oe,onEdgeMouseEnter:be,onEdgeMouseMove:Ne,onEdgeMouseLeave:Ie,reconnectRadius:Ce,defaultMarkerColor:L,noPanClassName:qe,disableKeyboardA11y:Ge,rfId:mt}),r.jsx(_g,{style:x,type:g,component:w,containerStyle:v}),r.jsx("div",{className:"react-flow__edgelabel-renderer"}),r.jsx(rg,{nodeTypes:e,onNodeClick:s,onNodeDoubleClick:a,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:d,onNodeContextMenu:h,nodeClickDistance:ce,onlyRenderVisibleElements:T,noPanClassName:qe,noDragClassName:$e,disableKeyboardA11y:Ge,nodeExtent:ft,rfId:mt}),r.jsx("div",{className:"react-flow__viewport-portal"})]})})}xu.displayName="GraphView";const Dg=p.memo(xu),tc=({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,width:o,height:a,fitView:i,fitViewOptions:l,minZoom:c=.5,maxZoom:d=2,nodeOrigin:h,nodeExtent:u,zIndexMode:m="basic"}={})=>{const f=new Map,g=new Map,x=new Map,w=new Map,v=s??t??[],y=n??e??[],b=h??[0,0],k=u??hr;Ad(x,w,v);const C=Ta(y,f,g,{nodeOrigin:b,nodeExtent:k,zIndexMode:m});let j=[0,0,1];if(i&&o&&a){const A=vr(f,{filter:M=>!!((M.width||M.initialWidth)&&(M.height||M.initialHeight))}),{x:S,y:T,zoom:P}=Ua(A,o,a,c,d,l?.padding??.1);j=[S,T,P]}return{rfId:"1",width:o??0,height:a??0,transform:j,nodes:y,nodesInitialized:C,nodeLookup:f,parentLookup:g,edges:v,edgeLookup:w,connectionLookup:x,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:s!==void 0,panZoom:null,minZoom:c,maxZoom:d,translateExtent:hr,nodeExtent:k,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:_s.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:b,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:{...hd},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:Qh,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:fd,zIndexMode:m,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},Og=({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,width:o,height:a,fitView:i,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:h,nodeExtent:u,zIndexMode:m})=>ep((f,g)=>{async function x(){const{nodeLookup:w,panZoom:v,fitViewOptions:y,fitViewResolver:b,width:k,height:C,minZoom:j,maxZoom:A}=g();v&&(await Xh({nodes:w,width:k,height:C,panZoom:v,minZoom:j,maxZoom:A},y),b?.resolve(!0),f({fitViewResolver:null}))}return{...tc({nodes:e,edges:t,width:o,height:a,fitView:i,fitViewOptions:l,minZoom:c,maxZoom:d,nodeOrigin:h,nodeExtent:u,defaultNodes:n,defaultEdges:s,zIndexMode:m}),setNodes:w=>{const{nodeLookup:v,parentLookup:y,nodeOrigin:b,elevateNodesOnSelect:k,fitViewQueued:C,zIndexMode:j}=g(),A=Ta(w,v,y,{nodeOrigin:b,nodeExtent:u,elevateNodesOnSelect:k,checkEquality:!0,zIndexMode:j});C&&A?(x(),f({nodes:w,nodesInitialized:A,fitViewQueued:!1,fitViewOptions:void 0})):f({nodes:w,nodesInitialized:A})},setEdges:w=>{const{connectionLookup:v,edgeLookup:y}=g();Ad(v,y,w),f({edges:w})},setDefaultNodesAndEdges:(w,v)=>{if(w){const{setNodes:y}=g();y(w),f({hasDefaultNodes:!0})}if(v){const{setEdges:y}=g();y(v),f({hasDefaultEdges:!0})}},updateNodeInternals:w=>{const{triggerNodeChanges:v,nodeLookup:y,parentLookup:b,domNode:k,nodeOrigin:C,nodeExtent:j,debug:A,fitViewQueued:S,zIndexMode:T}=g(),{changes:P,updatedInternals:M}=wm(w,y,b,k,C,j,T);M&&(gm(y,b,{nodeOrigin:C,nodeExtent:j,zIndexMode:T}),S?(x(),f({fitViewQueued:!1,fitViewOptions:void 0})):f({}),P?.length>0&&(A&&console.log("React Flow: trigger node changes",P),v?.(P)))},updateNodePositions:(w,v=!1)=>{const y=[];let b=[];const{nodeLookup:k,triggerNodeChanges:C,connection:j,updateConnection:A,onNodesChangeMiddlewareMap:S}=g();for(const[T,P]of w){const M=k.get(T),D=!!(M?.expandParent&&M?.parentId&&P?.position),z={id:T,type:"position",position:D?{x:Math.max(0,P.position.x),y:Math.max(0,P.position.y)}:P.position,dragging:v};if(M&&j.inProgress&&j.fromNode.id===M.id){const E=ss(M,j.fromHandle,ve.Left,!0);A({...j,from:E})}D&&M.parentId&&y.push({id:T,parentId:M.parentId,rect:{...P.internals.positionAbsolute,width:P.measured.width??0,height:P.measured.height??0}}),b.push(z)}if(y.length>0){const{parentLookup:T,nodeOrigin:P}=g(),M=Ja(y,k,T,P);b.push(...M)}for(const T of S.values())b=T(b);C(b)},triggerNodeChanges:w=>{const{onNodesChange:v,setNodes:y,nodes:b,hasDefaultNodes:k,debug:C}=g();if(w?.length){if(k){const j=Kd(w,b);y(j)}C&&console.log("React Flow: trigger node changes",w),v?.(w)}},triggerEdgeChanges:w=>{const{onEdgesChange:v,setEdges:y,edges:b,hasDefaultEdges:k,debug:C}=g();if(w?.length){if(k){const j=Ud(w,b);y(j)}C&&console.log("React Flow: trigger edge changes",w),v?.(w)}},addSelectedNodes:w=>{const{multiSelectionActive:v,edgeLookup:y,nodeLookup:b,triggerNodeChanges:k,triggerEdgeChanges:C}=g();if(v){const j=w.map(A=>Xn(A,!0));k(j);return}k(Ss(b,new Set([...w]),!0)),C(Ss(y))},addSelectedEdges:w=>{const{multiSelectionActive:v,edgeLookup:y,nodeLookup:b,triggerNodeChanges:k,triggerEdgeChanges:C}=g();if(v){const j=w.map(A=>Xn(A,!0));C(j);return}C(Ss(y,new Set([...w]))),k(Ss(b,new Set,!0))},unselectNodesAndEdges:({nodes:w,edges:v}={})=>{const{edges:y,nodes:b,nodeLookup:k,triggerNodeChanges:C,triggerEdgeChanges:j}=g(),A=w||b,S=v||y,T=[];for(const M of A){if(!M.selected)continue;const D=k.get(M.id);D&&(D.selected=!1),T.push(Xn(M.id,!1))}const P=[];for(const M of S)M.selected&&P.push(Xn(M.id,!1));C(T),j(P)},setMinZoom:w=>{const{panZoom:v,maxZoom:y}=g();v?.setScaleExtent([w,y]),f({minZoom:w})},setMaxZoom:w=>{const{panZoom:v,minZoom:y}=g();v?.setScaleExtent([y,w]),f({maxZoom:w})},setTranslateExtent:w=>{g().panZoom?.setTranslateExtent(w),f({translateExtent:w})},resetSelectedElements:()=>{const{edges:w,nodes:v,triggerNodeChanges:y,triggerEdgeChanges:b,elementsSelectable:k}=g();if(!k)return;const C=v.reduce((A,S)=>S.selected?[...A,Xn(S.id,!1)]:A,[]),j=w.reduce((A,S)=>S.selected?[...A,Xn(S.id,!1)]:A,[]);y(C),b(j)},setNodeExtent:w=>{const{nodes:v,nodeLookup:y,parentLookup:b,nodeOrigin:k,elevateNodesOnSelect:C,nodeExtent:j,zIndexMode:A}=g();w[0][0]===j[0][0]&&w[0][1]===j[0][1]&&w[1][0]===j[1][0]&&w[1][1]===j[1][1]||(Ta(v,y,b,{nodeOrigin:k,nodeExtent:w,elevateNodesOnSelect:C,checkEquality:!1,zIndexMode:A}),f({nodeExtent:w}))},panBy:w=>{const{transform:v,width:y,height:b,panZoom:k,translateExtent:C}=g();return km({delta:w,panZoom:k,transform:v,translateExtent:C,width:y,height:b})},setCenter:async(w,v,y)=>{const{width:b,height:k,maxZoom:C,panZoom:j}=g();if(!j)return Promise.resolve(!1);const A=typeof y?.zoom<"u"?y.zoom:C;return await j.setViewport({x:b/2-w*A,y:k/2-v*A,zoom:A},{duration:y?.duration,ease:y?.ease,interpolate:y?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{f({connection:{...hd}})},updateConnection:w=>{f({connection:w})},reset:()=>f({...tc()})}},Object.is);function $g({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:s,initialWidth:o,initialHeight:a,initialMinZoom:i,initialMaxZoom:l,initialFitViewOptions:c,fitView:d,nodeOrigin:h,nodeExtent:u,zIndexMode:m,children:f}){const[g]=p.useState(()=>Og({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,width:o,height:a,fitView:d,minZoom:i,maxZoom:l,fitViewOptions:c,nodeOrigin:h,nodeExtent:u,zIndexMode:m}));return r.jsx(tp,{value:g,children:r.jsx(Np,{children:f})})}function Pg({children:e,nodes:t,edges:n,defaultNodes:s,defaultEdges:o,width:a,height:i,fitView:l,fitViewOptions:c,minZoom:d,maxZoom:h,nodeOrigin:u,nodeExtent:m,zIndexMode:f}){return p.useContext(_o)?r.jsx(r.Fragment,{children:e}):r.jsx($g,{initialNodes:t,initialEdges:n,defaultNodes:s,defaultEdges:o,initialWidth:a,initialHeight:i,fitView:l,initialFitViewOptions:c,initialMinZoom:d,initialMaxZoom:h,nodeOrigin:u,nodeExtent:m,zIndexMode:f,children:e})}const Bg={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function qg({nodes:e,edges:t,defaultNodes:n,defaultEdges:s,className:o,nodeTypes:a,edgeTypes:i,onNodeClick:l,onEdgeClick:c,onInit:d,onMove:h,onMoveStart:u,onMoveEnd:m,onConnect:f,onConnectStart:g,onConnectEnd:x,onClickConnectStart:w,onClickConnectEnd:v,onNodeMouseEnter:y,onNodeMouseMove:b,onNodeMouseLeave:k,onNodeContextMenu:C,onNodeDoubleClick:j,onNodeDragStart:A,onNodeDrag:S,onNodeDragStop:T,onNodesDelete:P,onEdgesDelete:M,onDelete:D,onSelectionChange:z,onSelectionDragStart:E,onSelectionDrag:B,onSelectionDragStop:L,onSelectionContextMenu:$,onSelectionStart:R,onSelectionEnd:q,onBeforeDelete:H,connectionMode:K,connectionLineType:O=Ln.Bezier,connectionLineStyle:Y,connectionLineComponent:_,connectionLineContainerStyle:I,deleteKeyCode:V="Backspace",selectionKeyCode:W="Shift",selectionOnDrag:F=!1,selectionMode:Z=mr.Full,panActivationKeyCode:te="Space",multiSelectionKeyCode:ce=gr()?"Meta":"Control",zoomActivationKeyCode:oe=gr()?"Meta":"Control",snapToGrid:be,snapGrid:Ne,onlyRenderVisibleElements:Ie=!1,selectNodesOnDrag:Ce,nodesDraggable:Fe,autoPanOnNodeFocus:Be,nodesConnectable:Re,nodesFocusable:$e,nodeOrigin:Et=Vd,edgesFocusable:qe,edgesReconnectable:Ge,elementsSelectable:ft=!0,defaultViewport:mt=mp,minZoom:re=.5,maxZoom:ue=2,translateExtent:me=hr,preventScrolling:Ee=!0,nodeExtent:pe,defaultMarkerColor:Te="#b1b1b7",zoomOnScroll:se=!0,zoomOnPinch:le=!0,panOnScroll:fe=!1,panOnScrollSpeed:Q=.5,panOnScrollMode:ge=ts.Free,zoomOnDoubleClick:Se=!0,panOnDrag:tt=!0,onPaneClick:Qe,onPaneMouseEnter:Je,onPaneMouseMove:ye,onPaneMouseLeave:He,onPaneScroll:wt,onPaneContextMenu:X,paneClickDistance:ie=1,nodeClickDistance:xe=0,children:je,onReconnect:we,onReconnectStart:Le,onReconnectEnd:ke,onEdgeContextMenu:pt,onEdgeDoubleClick:lt,onEdgeMouseEnter:It,onEdgeMouseMove:Ot,onEdgeMouseLeave:Wt,reconnectRadius:_t=10,onNodesChange:We,onEdgesChange:nt,noDragClassName:Tt="nodrag",noWheelClassName:Cn="nowheel",noPanClassName:kt="nopan",fitView:Ye,fitViewOptions:et,connectOnClick:Xe,attributionPosition:dt,proOptions:Kt,defaultEdgeOptions:Nt,elevateNodesOnSelect:St=!0,elevateEdgesOnSelect:Lt=!1,disableKeyboardA11y:$t=!1,autoPanOnConnect:Qt,autoPanOnNodeDrag:U,autoPanSpeed:de,connectionRadius:De,isValidConnection:Oe,onError:Ve,style:Pt,id:an,nodeDragThreshold:as,connectionDragThreshold:is,viewport:Us,onViewportChange:Wo,width:qt,height:Pn,colorMode:Bn="light",debug:Ys,onScroll:ls,ariaLabelConfig:En,zIndexMode:qn="basic",...cs},Gs){const hn=an||"1",zn=bp(Bn),In=p.useCallback(Fn=>{Fn.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),ls?.(Fn)},[ls]);return r.jsx("div",{"data-testid":"rf__wrapper",...cs,onScroll:In,style:{...Pt,...Bg},ref:Gs,className:jt(["react-flow",o,zn]),id:an,role:"application",children:r.jsxs(Pg,{nodes:e,edges:t,width:qt,height:Pn,fitView:Ye,fitViewOptions:et,minZoom:re,maxZoom:ue,nodeOrigin:Et,nodeExtent:pe,zIndexMode:qn,children:[r.jsx(Dg,{onInit:d,onNodeClick:l,onEdgeClick:c,onNodeMouseEnter:y,onNodeMouseMove:b,onNodeMouseLeave:k,onNodeContextMenu:C,onNodeDoubleClick:j,nodeTypes:a,edgeTypes:i,connectionLineType:O,connectionLineStyle:Y,connectionLineComponent:_,connectionLineContainerStyle:I,selectionKeyCode:W,selectionOnDrag:F,selectionMode:Z,deleteKeyCode:V,multiSelectionKeyCode:ce,panActivationKeyCode:te,zoomActivationKeyCode:oe,onlyRenderVisibleElements:Ie,defaultViewport:mt,translateExtent:me,minZoom:re,maxZoom:ue,preventScrolling:Ee,zoomOnScroll:se,zoomOnPinch:le,zoomOnDoubleClick:Se,panOnScroll:fe,panOnScrollSpeed:Q,panOnScrollMode:ge,panOnDrag:tt,onPaneClick:Qe,onPaneMouseEnter:Je,onPaneMouseMove:ye,onPaneMouseLeave:He,onPaneScroll:wt,onPaneContextMenu:X,paneClickDistance:ie,nodeClickDistance:xe,onSelectionContextMenu:$,onSelectionStart:R,onSelectionEnd:q,onReconnect:we,onReconnectStart:Le,onReconnectEnd:ke,onEdgeContextMenu:pt,onEdgeDoubleClick:lt,onEdgeMouseEnter:It,onEdgeMouseMove:Ot,onEdgeMouseLeave:Wt,reconnectRadius:_t,defaultMarkerColor:Te,noDragClassName:Tt,noWheelClassName:Cn,noPanClassName:kt,rfId:hn,disableKeyboardA11y:$t,nodeExtent:pe,viewport:Us,onViewportChange:Wo}),r.jsx(xp,{nodes:e,edges:t,defaultNodes:n,defaultEdges:s,onConnect:f,onConnectStart:g,onConnectEnd:x,onClickConnectStart:w,onClickConnectEnd:v,nodesDraggable:Fe,autoPanOnNodeFocus:Be,nodesConnectable:Re,nodesFocusable:$e,edgesFocusable:qe,edgesReconnectable:Ge,elementsSelectable:ft,elevateNodesOnSelect:St,elevateEdgesOnSelect:Lt,minZoom:re,maxZoom:ue,nodeExtent:pe,onNodesChange:We,onEdgesChange:nt,snapToGrid:be,snapGrid:Ne,connectionMode:K,translateExtent:me,connectOnClick:Xe,defaultEdgeOptions:Nt,fitView:Ye,fitViewOptions:et,onNodesDelete:P,onEdgesDelete:M,onDelete:D,onNodeDragStart:A,onNodeDrag:S,onNodeDragStop:T,onSelectionDrag:B,onSelectionDragStart:E,onSelectionDragStop:L,onMove:h,onMoveStart:u,onMoveEnd:m,noPanClassName:kt,nodeOrigin:Et,rfId:hn,autoPanOnConnect:Qt,autoPanOnNodeDrag:U,autoPanSpeed:de,onError:Ve,connectionRadius:De,isValidConnection:Oe,selectNodesOnDrag:Ce,nodeDragThreshold:as,connectionDragThreshold:is,onBeforeDelete:H,debug:Ys,ariaLabelConfig:En,zIndexMode:qn}),r.jsx(hp,{onSelectionChange:z}),je,r.jsx(lp,{proOptions:Kt,position:dt}),r.jsx(ip,{rfId:hn,disableKeyboardA11y:$t})]})})}var zg=Yd(qg);function Fg(){const e=it();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 Hg(e){const[t,n]=p.useState(e),s=p.useCallback(o=>n(a=>Kd(o,a)),[]);return[t,n,s]}function Vg(e){const[t,n]=p.useState(e),s=p.useCallback(o=>n(a=>Ud(o,a)),[]);return[t,n,s]}function Wg({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:jt(["react-flow__background-pattern",n,s])})}function Kg({radius:e,className:t}){return r.jsx("circle",{cx:e,cy:e,r:e,className:jt(["react-flow__background-pattern","dots",t])})}var On;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(On||(On={}));const Ug={[On.Dots]:1,[On.Lines]:1,[On.Cross]:6},Yg=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function bu({id:e,variant:t=On.Dots,gap:n=20,size:s,lineWidth:o=1,offset:a=0,color:i,bgColor:l,style:c,className:d,patternClassName:h}){const u=p.useRef(null),{transform:m,patternId:f}=Ke(Yg,ct),g=s||Ug[t],x=t===On.Dots,w=t===On.Cross,v=Array.isArray(n)?n:[n,n],y=[v[0]*m[2]||1,v[1]*m[2]||1],b=g*m[2],k=Array.isArray(a)?a:[a,a],C=w?[b,b]:y,j=[k[0]*m[2]||1+C[0]/2,k[1]*m[2]||1+C[1]/2],A=`${f}${e||""}`;return r.jsxs("svg",{className:jt(["react-flow__background",d]),style:{...c,...Ro,"--xy-background-color-props":l,"--xy-background-pattern-color-props":i},ref:u,"data-testid":"rf__background",children:[r.jsx("pattern",{id:A,x:m[0]%y[0],y:m[1]%y[1],width:y[0],height:y[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${j[0]},-${j[1]})`,children:x?r.jsx(Kg,{radius:b/2,className:h}):r.jsx(Wg,{dimensions:C,lineWidth:o,variant:t,className:h})}),r.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${A})`})]})}bu.displayName="Background";const Gg=p.memo(bu);function Xg(){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 Qg(){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 Jg(){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 ex(){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 Xr({children:e,className:t,...n}){return r.jsx("button",{type:"button",className:jt(["react-flow__controls-button",t]),...n,children:e})}const tx=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function yu({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:s=!0,fitViewOptions:o,onZoomIn:a,onZoomOut:i,onFitView:l,onInteractiveChange:c,className:d,children:h,position:u="bottom-left",orientation:m="vertical","aria-label":f}){const g=it(),{isInteractive:x,minZoomReached:w,maxZoomReached:v,ariaLabelConfig:y}=Ke(tx,ct),{zoomIn:b,zoomOut:k,fitView:C}=ei(),j=()=>{b(),a?.()},A=()=>{k(),i?.()},S=()=>{C(o),l?.()},T=()=>{g.setState({nodesDraggable:!x,nodesConnectable:!x,elementsSelectable:!x}),c?.(!x)},P=m==="horizontal"?"horizontal":"vertical";return r.jsxs(Lo,{className:jt(["react-flow__controls",P,d]),position:u,style:e,"data-testid":"rf__controls","aria-label":f??y["controls.ariaLabel"],children:[t&&r.jsxs(r.Fragment,{children:[r.jsx(Xr,{onClick:j,className:"react-flow__controls-zoomin",title:y["controls.zoomIn.ariaLabel"],"aria-label":y["controls.zoomIn.ariaLabel"],disabled:v,children:r.jsx(Xg,{})}),r.jsx(Xr,{onClick:A,className:"react-flow__controls-zoomout",title:y["controls.zoomOut.ariaLabel"],"aria-label":y["controls.zoomOut.ariaLabel"],disabled:w,children:r.jsx(Zg,{})})]}),n&&r.jsx(Xr,{className:"react-flow__controls-fitview",onClick:S,title:y["controls.fitView.ariaLabel"],"aria-label":y["controls.fitView.ariaLabel"],children:r.jsx(Qg,{})}),s&&r.jsx(Xr,{className:"react-flow__controls-interactive",onClick:T,title:y["controls.interactive.ariaLabel"],"aria-label":y["controls.interactive.ariaLabel"],children:x?r.jsx(ex,{}):r.jsx(Jg,{})}),h]})}yu.displayName="Controls";const nx=p.memo(yu);function sx({id:e,x:t,y:n,width:s,height:o,style:a,color:i,strokeColor:l,strokeWidth:c,className:d,borderRadius:h,shapeRendering:u,selected:m,onClick:f}){const{background:g,backgroundColor:x}=a||{},w=i||g||x;return r.jsx("rect",{className:jt(["react-flow__minimap-node",{selected:m},d]),x:t,y:n,rx:h,ry:h,width:s,height:o,style:{fill:w,stroke:l,strokeWidth:c},shapeRendering:u,onClick:f?v=>f(v,e):void 0})}const rx=p.memo(sx),ox=e=>e.nodes.map(t=>t.id),fa=e=>e instanceof Function?e:()=>e;function ax({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:s=5,nodeStrokeWidth:o,nodeComponent:a=rx,onClick:i}){const l=Ke(ox,ct),c=fa(t),d=fa(e),h=fa(n),u=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return r.jsx(r.Fragment,{children:l.map(m=>r.jsx(lx,{id:m,nodeColorFunc:c,nodeStrokeColorFunc:d,nodeClassNameFunc:h,nodeBorderRadius:s,nodeStrokeWidth:o,NodeComponent:a,onClick:i,shapeRendering:u},m))})}function ix({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:s,nodeBorderRadius:o,nodeStrokeWidth:a,shapeRendering:i,NodeComponent:l,onClick:c}){const{node:d,x:h,y:u,width:m,height:f}=Ke(g=>{const x=g.nodeLookup.get(e);if(!x)return{node:void 0,x:0,y:0,width:0,height:0};const w=x.internals.userNode,{x:v,y}=x.internals.positionAbsolute,{width:b,height:k}=Sn(w);return{node:w,x:v,y,width:b,height:k}},ct);return!d||d.hidden||!wd(d)?null:r.jsx(l,{x:h,y:u,width:m,height:f,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 lx=p.memo(ix);var cx=p.memo(ax);const dx=200,ux=150,fx=e=>!e.hidden,hx=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?yd(vr(e.nodeLookup,{filter:fx}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},mx="react-flow__minimap-desc";function wu({style:e,className:t,nodeStrokeColor:n,nodeColor:s,nodeClassName:o="",nodeBorderRadius:a=5,nodeStrokeWidth:i,nodeComponent:l,bgColor:c,maskColor:d,maskStrokeColor:h,maskStrokeWidth:u,position:m="bottom-right",onClick:f,onNodeClick:g,pannable:x=!1,zoomable:w=!1,ariaLabel:v,inversePan:y,zoomStep:b=1,offsetScale:k=5}){const C=it(),j=p.useRef(null),{boundingRect:A,viewBB:S,rfId:T,panZoom:P,translateExtent:M,flowWidth:D,flowHeight:z,ariaLabelConfig:E}=Ke(hx,ct),B=e?.width??dx,L=e?.height??ux,$=A.width/B,R=A.height/L,q=Math.max($,R),H=q*B,K=q*L,O=k*q,Y=A.x-(H-A.width)/2-O,_=A.y-(K-A.height)/2-O,I=H+O*2,V=K+O*2,W=`${mx}-${T}`,F=p.useRef(0),Z=p.useRef();F.current=q,p.useEffect(()=>{if(j.current&&P)return Z.current=Mm({domNode:j.current,panZoom:P,getTransform:()=>C.getState().transform,getViewScale:()=>F.current}),()=>{Z.current?.destroy()}},[P]),p.useEffect(()=>{Z.current?.update({translateExtent:M,width:D,height:z,inversePan:y,pannable:x,zoomStep:b,zoomable:w})},[x,w,y,b,M,D,z]);const te=f?be=>{const[Ne,Ie]=Z.current?.pointer(be)||[0,0];f(be,{x:Ne,y:Ie})}:void 0,ce=g?p.useCallback((be,Ne)=>{const Ie=C.getState().nodeLookup.get(Ne).internals.userNode;g(be,Ie)},[]):void 0,oe=v??E["minimap.ariaLabel"];return r.jsx(Lo,{position:m,style:{...e,"--xy-minimap-background-color-props":typeof c=="string"?c:void 0,"--xy-minimap-mask-background-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-stroke-color-props":typeof h=="string"?h:void 0,"--xy-minimap-mask-stroke-width-props":typeof u=="number"?u*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:jt(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:r.jsxs("svg",{width:B,height:L,viewBox:`${Y} ${_} ${I} ${V}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":W,ref:j,onClick:te,children:[oe&&r.jsx("title",{id:W,children:oe}),r.jsx(cx,{onClick:ce,nodeColor:s,nodeStrokeColor:n,nodeBorderRadius:a,nodeClassName:o,nodeStrokeWidth:i,nodeComponent:l}),r.jsx("path",{className:"react-flow__minimap-mask",d:`M${Y-O},${_-O}h${I+O*2}v${V+O*2}h${-I-O*2}z
7
+ M${S.x},${S.y}h${S.width}v${S.height}h${-S.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}wu.displayName="MiniMap";const px=p.memo(wu),gx=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,xx={[$s.Line]:"right",[$s.Handle]:"bottom-right"};function bx({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:h=Number.MAX_VALUE,keepAspectRatio:u=!1,resizeDirection:m,autoScale:f=!0,shouldResize:g,onResizeStart:x,onResize:w,onResizeEnd:v}){const y=Qd(),b=typeof e=="string"?e:y,k=it(),C=p.useRef(null),j=n===$s.Handle,A=Ke(p.useCallback(gx(j&&f),[j,f]),ct),S=p.useRef(null),T=t??xx[n];p.useEffect(()=>{if(!(!C.current||!b))return S.current||(S.current=Vm({domNode:C.current,nodeId:b,getStoreItems:()=>{const{nodeLookup:M,transform:D,snapGrid:z,snapToGrid:E,nodeOrigin:B,domNode:L}=k.getState();return{nodeLookup:M,transform:D,snapGrid:z,snapToGrid:E,nodeOrigin:B,paneDomNode:L}},onChange:(M,D)=>{const{triggerNodeChanges:z,nodeLookup:E,parentLookup:B,nodeOrigin:L}=k.getState(),$=[],R={x:M.x,y:M.y},q=E.get(b);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,Y={id:q.id,parentId:q.parentId,rect:{width:K,height:O,...kd({x:M.x??q.position.x,y:M.y??q.position.y},{width:K,height:O},q.parentId,E,H)}},_=Ja([Y],E,B,L);$.push(..._),R.x=M.x?Math.max(H[0]*K,M.x):void 0,R.y=M.y?Math.max(H[1]*O,M.y):void 0}if(R.x!==void 0&&R.y!==void 0){const H={id:b,type:"position",position:{...R}};$.push(H)}if(M.width!==void 0&&M.height!==void 0){const K={id:b,type:"dimensions",resizing:!0,setAttributes:m?m==="horizontal"?"width":"height":!0,dimensions:{width:M.width,height:M.height}};$.push(K)}for(const H of D){const K={...H,type:"position"};$.push(K)}z($)},onEnd:({width:M,height:D})=>{const z={id:b,type:"dimensions",resizing:!1,dimensions:{width:M,height:D}};k.getState().triggerNodeChanges([z])}})),S.current.update({controlPosition:T,boundaries:{minWidth:l,minHeight:c,maxWidth:d,maxHeight:h},keepAspectRatio:u,resizeDirection:m,onResizeStart:x,onResize:w,onResizeEnd:v,shouldResize:g}),()=>{S.current?.destroy()}},[T,l,c,d,h,u,x,w,v,g]);const P=T.split("-");return r.jsx("div",{className:jt(["react-flow__resize-control","nodrag",...P,n,s]),ref:C,style:{...o,scale:A,...i&&{[j?"backgroundColor":"borderColor"]:i}},children:a})}p.memo(bx);var Ze=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),rn=Ze((e,t)=>{var n=Object.defineProperty,s=(z,E,B)=>E in z?n(z,E,{enumerable:!0,configurable:!0,writable:!0,value:B}):z[E]=B,o=(z,E)=>()=>(E||z((E={exports:{}}).exports,E),E.exports),a=(z,E,B)=>s(z,typeof E!="symbol"?E+"":E,B),i=o((z,E)=>{var B="\0",L="\0",$="",R=class{constructor(_){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"),_&&(this._isDirected=Object.hasOwn(_,"directed")?_.directed:!0,this._isMultigraph=Object.hasOwn(_,"multigraph")?_.multigraph:!1,this._isCompound=Object.hasOwn(_,"compound")?_.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[L]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(_){return this._label=_,this}graph(){return this._label}setDefaultNodeLabel(_){return this._defaultNodeLabelFn=_,typeof _!="function"&&(this._defaultNodeLabelFn=()=>_),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var _=this;return this.nodes().filter(I=>Object.keys(_._in[I]).length===0)}sinks(){var _=this;return this.nodes().filter(I=>Object.keys(_._out[I]).length===0)}setNodes(_,I){var V=arguments,W=this;return _.forEach(function(F){V.length>1?W.setNode(F,I):W.setNode(F)}),this}setNode(_,I){return Object.hasOwn(this._nodes,_)?(arguments.length>1&&(this._nodes[_]=I),this):(this._nodes[_]=arguments.length>1?I:this._defaultNodeLabelFn(_),this._isCompound&&(this._parent[_]=L,this._children[_]={},this._children[L][_]=!0),this._in[_]={},this._preds[_]={},this._out[_]={},this._sucs[_]={},++this._nodeCount,this)}node(_){return this._nodes[_]}hasNode(_){return Object.hasOwn(this._nodes,_)}removeNode(_){var I=this;if(Object.hasOwn(this._nodes,_)){var V=W=>I.removeEdge(I._edgeObjs[W]);delete this._nodes[_],this._isCompound&&(this._removeFromParentsChildList(_),delete this._parent[_],this.children(_).forEach(function(W){I.setParent(W)}),delete this._children[_]),Object.keys(this._in[_]).forEach(V),delete this._in[_],delete this._preds[_],Object.keys(this._out[_]).forEach(V),delete this._out[_],delete this._sucs[_],--this._nodeCount}return this}setParent(_,I){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(I===void 0)I=L;else{I+="";for(var V=I;V!==void 0;V=this.parent(V))if(V===_)throw new Error("Setting "+I+" as parent of "+_+" would create a cycle");this.setNode(I)}return this.setNode(_),this._removeFromParentsChildList(_),this._parent[_]=I,this._children[I][_]=!0,this}_removeFromParentsChildList(_){delete this._children[this._parent[_]][_]}parent(_){if(this._isCompound){var I=this._parent[_];if(I!==L)return I}}children(_=L){if(this._isCompound){var I=this._children[_];if(I)return Object.keys(I)}else{if(_===L)return this.nodes();if(this.hasNode(_))return[]}}predecessors(_){var I=this._preds[_];if(I)return Object.keys(I)}successors(_){var I=this._sucs[_];if(I)return Object.keys(I)}neighbors(_){var I=this.predecessors(_);if(I){let W=new Set(I);for(var V of this.successors(_))W.add(V);return Array.from(W.values())}}isLeaf(_){var I;return this.isDirected()?I=this.successors(_):I=this.neighbors(_),I.length===0}filterNodes(_){var I=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});I.setGraph(this.graph());var V=this;Object.entries(this._nodes).forEach(function([Z,te]){_(Z)&&I.setNode(Z,te)}),Object.values(this._edgeObjs).forEach(function(Z){I.hasNode(Z.v)&&I.hasNode(Z.w)&&I.setEdge(Z,V.edge(Z))});var W={};function F(Z){var te=V.parent(Z);return te===void 0||I.hasNode(te)?(W[Z]=te,te):te in W?W[te]:F(te)}return this._isCompound&&I.nodes().forEach(Z=>I.setParent(Z,F(Z))),I}setDefaultEdgeLabel(_){return this._defaultEdgeLabelFn=_,typeof _!="function"&&(this._defaultEdgeLabelFn=()=>_),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(_,I){var V=this,W=arguments;return _.reduce(function(F,Z){return W.length>1?V.setEdge(F,Z,I):V.setEdge(F,Z),Z}),this}setEdge(){var _,I,V,W,F=!1,Z=arguments[0];typeof Z=="object"&&Z!==null&&"v"in Z?(_=Z.v,I=Z.w,V=Z.name,arguments.length===2&&(W=arguments[1],F=!0)):(_=Z,I=arguments[1],V=arguments[3],arguments.length>2&&(W=arguments[2],F=!0)),_=""+_,I=""+I,V!==void 0&&(V=""+V);var te=K(this._isDirected,_,I,V);if(Object.hasOwn(this._edgeLabels,te))return F&&(this._edgeLabels[te]=W),this;if(V!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(_),this.setNode(I),this._edgeLabels[te]=F?W:this._defaultEdgeLabelFn(_,I,V);var ce=O(this._isDirected,_,I,V);return _=ce.v,I=ce.w,Object.freeze(ce),this._edgeObjs[te]=ce,q(this._preds[I],_),q(this._sucs[_],I),this._in[I][te]=ce,this._out[_][te]=ce,this._edgeCount++,this}edge(_,I,V){var W=arguments.length===1?Y(this._isDirected,arguments[0]):K(this._isDirected,_,I,V);return this._edgeLabels[W]}edgeAsObj(){let _=this.edge(...arguments);return typeof _!="object"?{label:_}:_}hasEdge(_,I,V){var W=arguments.length===1?Y(this._isDirected,arguments[0]):K(this._isDirected,_,I,V);return Object.hasOwn(this._edgeLabels,W)}removeEdge(_,I,V){var W=arguments.length===1?Y(this._isDirected,arguments[0]):K(this._isDirected,_,I,V),F=this._edgeObjs[W];return F&&(_=F.v,I=F.w,delete this._edgeLabels[W],delete this._edgeObjs[W],H(this._preds[I],_),H(this._sucs[_],I),delete this._in[I][W],delete this._out[_][W],this._edgeCount--),this}inEdges(_,I){return this.isDirected()?this.filterEdges(this._in[_],_,I):this.nodeEdges(_,I)}outEdges(_,I){return this.isDirected()?this.filterEdges(this._out[_],_,I):this.nodeEdges(_,I)}nodeEdges(_,I){if(_ in this._nodes)return this.filterEdges({...this._in[_],...this._out[_]},_,I)}filterEdges(_,I,V){if(_){var W=Object.values(_);return V?W.filter(function(F){return F.v===I&&F.w===V||F.v===V&&F.w===I}):W}}};function q(_,I){_[I]?_[I]++:_[I]=1}function H(_,I){--_[I]||delete _[I]}function K(_,I,V,W){var F=""+I,Z=""+V;if(!_&&F>Z){var te=F;F=Z,Z=te}return F+$+Z+$+(W===void 0?B:W)}function O(_,I,V,W){var F=""+I,Z=""+V;if(!_&&F>Z){var te=F;F=Z,Z=te}var ce={v:F,w:Z};return W&&(ce.name=W),ce}function Y(_,I){return K(_,I.v,I.w,I.name)}E.exports=R}),l=o((z,E)=>{E.exports="3.0.2"}),c=o((z,E)=>{E.exports={Graph:i(),version:l()}}),d=o((z,E)=>{var B=i();E.exports={write:L,read:q};function L(H){var K={options:{directed:H.isDirected(),multigraph:H.isMultigraph(),compound:H.isCompound()},nodes:$(H),edges:R(H)};return H.graph()!==void 0&&(K.value=structuredClone(H.graph())),K}function $(H){return H.nodes().map(function(K){var O=H.node(K),Y=H.parent(K),_={v:K};return O!==void 0&&(_.value=O),Y!==void 0&&(_.parent=Y),_})}function R(H){return H.edges().map(function(K){var O=H.edge(K),Y={v:K.v,w:K.w};return K.name!==void 0&&(Y.name=K.name),O!==void 0&&(Y.value=O),Y})}function q(H){var K=new B(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}}),h=o((z,E)=>{E.exports=L;var B=()=>1;function L(R,q,H,K){return $(R,String(q),H||B,K||function(O){return R.outEdges(O)})}function $(R,q,H,K){var O={},Y=!0,_=0,I=R.nodes(),V=function(te){var ce=H(te);O[te.v].distance+ce<O[te.w].distance&&(O[te.w]={distance:O[te.v].distance+ce,predecessor:te.v},Y=!0)},W=function(){I.forEach(function(te){K(te).forEach(function(ce){var oe=ce.v===te?ce.v:ce.w,be=oe===ce.v?ce.w:ce.v;V({v:oe,w:be})})})};I.forEach(function(te){var ce=te===q?0:Number.POSITIVE_INFINITY;O[te]={distance:ce}});for(var F=I.length,Z=1;Z<F&&(Y=!1,_++,W(),!!Y);Z++);if(_===F-1&&(Y=!1,W(),Y))throw new Error("The graph contains a negative weight cycle");return O}}),u=o((z,E)=>{E.exports=B;function B(L){var $={},R=[],q;function H(K){Object.hasOwn($,K)||($[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&&R.push(q)}),R}}),m=o((z,E)=>{var B=class{constructor(){a(this,"_arr",[]),a(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(L){return L.key})}has(L){return Object.hasOwn(this._keyIndices,L)}priority(L){var $=this._keyIndices[L];if($!==void 0)return this._arr[$].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(L,$){var R=this._keyIndices;if(L=String(L),!Object.hasOwn(R,L)){var q=this._arr,H=q.length;return R[L]=H,q.push({key:L,priority:$}),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,$){var R=this._keyIndices[L];if($>this._arr[R].priority)throw new Error("New priority is greater than current priority. Key: "+L+" Old: "+this._arr[R].priority+" New: "+$);this._arr[R].priority=$,this._decrease(R)}_heapify(L){var $=this._arr,R=2*L,q=R+1,H=L;R<$.length&&(H=$[R].priority<$[H].priority?R:H,q<$.length&&(H=$[q].priority<$[H].priority?q:H),H!==L&&(this._swap(L,H),this._heapify(H)))}_decrease(L){for(var $=this._arr,R=$[L].priority,q;L!==0&&(q=L>>1,!($[q].priority<R));)this._swap(L,q),L=q}_swap(L,$){var R=this._arr,q=this._keyIndices,H=R[L],K=R[$];R[L]=K,R[$]=H,q[K.key]=L,q[H.key]=$}};E.exports=B}),f=o((z,E)=>{var B=m();E.exports=$;var L=()=>1;function $(q,H,K,O){var Y=function(_){return q.outEdges(_)};return R(q,String(H),K||L,O||Y)}function R(q,H,K,O){var Y={},_=new B,I,V,W=function(F){var Z=F.v!==I?F.v:F.w,te=Y[Z],ce=K(F),oe=V.distance+ce;if(ce<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+F+" Weight: "+ce);oe<te.distance&&(te.distance=oe,te.predecessor=I,_.decrease(Z,oe))};for(q.nodes().forEach(function(F){var Z=F===H?0:Number.POSITIVE_INFINITY;Y[F]={distance:Z},_.add(F,Z)});_.size()>0&&(I=_.removeMin(),V=Y[I],V.distance!==Number.POSITIVE_INFINITY);)O(I).forEach(W);return Y}}),g=o((z,E)=>{var B=f();E.exports=L;function L($,R,q){return $.nodes().reduce(function(H,K){return H[K]=B($,K,R,q),H},{})}}),x=o((z,E)=>{E.exports=B;function B($,R,q){if($[R].predecessor!==void 0)throw new Error("Invalid source vertex");if($[q].predecessor===void 0&&q!==R)throw new Error("Invalid destination vertex");return{weight:$[q].distance,path:L($,R,q)}}function L($,R,q){for(var H=[],K=q;K!==R;)H.push(K),K=$[K].predecessor;return H.push(R),H.reverse()}}),w=o((z,E)=>{E.exports=B;function B(L){var $=0,R=[],q={},H=[];function K(O){var Y=q[O]={onStack:!0,lowlink:$,index:$++};if(R.push(O),L.successors(O).forEach(function(V){Object.hasOwn(q,V)?q[V].onStack&&(Y.lowlink=Math.min(Y.lowlink,q[V].index)):(K(V),Y.lowlink=Math.min(Y.lowlink,q[V].lowlink))}),Y.lowlink===Y.index){var _=[],I;do I=R.pop(),q[I].onStack=!1,_.push(I);while(O!==I);H.push(_)}}return L.nodes().forEach(function(O){Object.hasOwn(q,O)||K(O)}),H}}),v=o((z,E)=>{var B=w();E.exports=L;function L($){return B($).filter(function(R){return R.length>1||R.length===1&&$.hasEdge(R[0],R[0])})}}),y=o((z,E)=>{E.exports=L;var B=()=>1;function L(R,q,H){return $(R,q||B,H||function(K){return R.outEdges(K)})}function $(R,q,H){var K={},O=R.nodes();return O.forEach(function(Y){K[Y]={},K[Y][Y]={distance:0},O.forEach(function(_){Y!==_&&(K[Y][_]={distance:Number.POSITIVE_INFINITY})}),H(Y).forEach(function(_){var I=_.v===Y?_.w:_.v,V=q(_);K[Y][I]={distance:V,predecessor:Y}})}),O.forEach(function(Y){var _=K[Y];O.forEach(function(I){var V=K[I];O.forEach(function(W){var F=V[Y],Z=_[W],te=V[W],ce=F.distance+Z.distance;ce<te.distance&&(te.distance=ce,te.predecessor=Z.predecessor)})})}),K}}),b=o((z,E)=>{function B($){var R={},q={},H=[];function K(O){if(Object.hasOwn(q,O))throw new L;Object.hasOwn(R,O)||(q[O]=!0,R[O]=!0,$.predecessors(O).forEach(K),delete q[O],H.push(O))}if($.sinks().forEach(K),Object.keys(R).length!==$.nodeCount())throw new L;return H}var L=class extends Error{constructor(){super(...arguments)}};E.exports=B,B.CycleException=L}),k=o((z,E)=>{var B=b();E.exports=L;function L($){try{B($)}catch(R){if(R instanceof B.CycleException)return!1;throw R}return!0}}),C=o((z,E)=>{E.exports=B;function B($,R,q,H,K){Array.isArray(R)||(R=[R]);var O=($.isDirected()?$.successors:$.neighbors).bind($),Y={};return R.forEach(function(_){if(!$.hasNode(_))throw new Error("Graph does not have node: "+_);K=L($,_,q==="post",Y,O,H,K)}),K}function L($,R,q,H,K,O,Y){return Object.hasOwn(H,R)||(H[R]=!0,q||(Y=O(Y,R)),K(R).forEach(function(_){Y=L($,_,q,H,K,O,Y)}),q&&(Y=O(Y,R))),Y}}),j=o((z,E)=>{var B=C();E.exports=L;function L($,R,q){return B($,R,q,function(H,K){return H.push(K),H},[])}}),A=o((z,E)=>{var B=j();E.exports=L;function L($,R){return B($,R,"post")}}),S=o((z,E)=>{var B=j();E.exports=L;function L($,R){return B($,R,"pre")}}),T=o((z,E)=>{var B=i(),L=m();E.exports=$;function $(R,q){var H=new B,K={},O=new L,Y;function _(V){var W=V.v===Y?V.w:V.v,F=O.priority(W);if(F!==void 0){var Z=q(V);Z<F&&(K[W]=Y,O.decrease(W,Z))}}if(R.nodeCount()===0)return H;R.nodes().forEach(function(V){O.add(V,Number.POSITIVE_INFINITY),H.setNode(V)}),O.decrease(R.nodes()[0],0);for(var I=!1;O.size()>0;){if(Y=O.removeMin(),Object.hasOwn(K,Y))H.setEdge(Y,K[Y]);else{if(I)throw new Error("Input graph is not connected: "+R);I=!0}R.nodeEdges(Y).forEach(_)}return H}}),P=o((z,E)=>{var B=f(),L=h();E.exports=$;function $(q,H,K,O){return R(q,H,K,O||function(Y){return q.outEdges(Y)})}function R(q,H,K,O){if(K===void 0)return B(q,H,K,O);for(var Y=!1,_=q.nodes(),I=0;I<_.length;I++){for(var V=O(_[I]),W=0;W<V.length;W++){var F=V[W],Z=F.v===_[I]?F.v:F.w,te=Z===F.v?F.w:F.v;K({v:Z,w:te})<0&&(Y=!0)}if(Y)return L(q,H,K,O)}return B(q,H,K,O)}}),M=o((z,E)=>{E.exports={bellmanFord:h(),components:u(),dijkstra:f(),dijkstraAll:g(),extractPath:x(),findCycles:v(),floydWarshall:y(),isAcyclic:k(),postorder:A(),preorder:S(),prim:T(),shortestPaths:P(),reduce:C(),tarjan:w(),topsort:b()}}),D=c();t.exports={Graph:D.Graph,json:d(),alg:M(),version:D.version}}),yx=Ze((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}),wx=Ze((e,t)=>{var n=rn().Graph,s=yx();t.exports=a;var o=()=>1;function a(u,m){if(u.nodeCount()<=1)return[];let f=c(u,m||o);return i(f.graph,f.buckets,f.zeroIdx).flatMap(g=>u.outEdges(g.v,g.w))}function i(u,m,f){let g=[],x=m[m.length-1],w=m[0],v;for(;u.nodeCount();){for(;v=w.dequeue();)l(u,m,f,v);for(;v=x.dequeue();)l(u,m,f,v);if(u.nodeCount()){for(let y=m.length-2;y>0;--y)if(v=m[y].dequeue(),v){g=g.concat(l(u,m,f,v,!0));break}}}return g}function l(u,m,f,g,x){let w=x?[]:void 0;return u.inEdges(g.v).forEach(v=>{let y=u.edge(v),b=u.node(v.v);x&&w.push({v:v.v,w:v.w}),b.out-=y,d(m,f,b)}),u.outEdges(g.v).forEach(v=>{let y=u.edge(v),b=v.w,k=u.node(b);k.in-=y,d(m,f,k)}),u.removeNode(g.v),w}function c(u,m){let f=new n,g=0,x=0;u.nodes().forEach(y=>{f.setNode(y,{v:y,in:0,out:0})}),u.edges().forEach(y=>{let b=f.edge(y.v,y.w)||0,k=m(y),C=b+k;f.setEdge(y.v,y.w,C),x=Math.max(x,f.node(y.v).out+=k),g=Math.max(g,f.node(y.w).in+=k)});let w=h(x+g+3).map(()=>new s),v=g+1;return f.nodes().forEach(y=>{d(w,v,f.node(y))}),{graph:f,buckets:w,zeroIdx:v}}function d(u,m,f){f.out?f.in?u[f.out-f.in+m].enqueue(f):u[u.length-1].enqueue(f):u[0].enqueue(f)}function h(u){let m=[];for(let f=0;f<u;f++)m.push(f);return m}}),vt=Ze((e,t)=>{var n=rn().Graph;t.exports={addBorderNode:m,addDummyNode:s,applyWithChunking:x,asNonCompoundGraph:a,buildLayerMatrix:d,intersectRect:c,mapValues:S,maxRank:w,normalizeRanks:h,notime:b,partition:v,pick:A,predecessorWeights:l,range:j,removeEmptyRanks:u,simplify:o,successorWeights:i,time:y,uniqueId:C,zipObject:T};function s(P,M,D,z){for(var E=z;P.hasNode(E);)E=C(z);return D.dummy=M,P.setNode(E,D),E}function o(P){let M=new n().setGraph(P.graph());return P.nodes().forEach(D=>M.setNode(D,P.node(D))),P.edges().forEach(D=>{let z=M.edge(D.v,D.w)||{weight:0,minlen:1},E=P.edge(D);M.setEdge(D.v,D.w,{weight:z.weight+E.weight,minlen:Math.max(z.minlen,E.minlen)})}),M}function a(P){let M=new n({multigraph:P.isMultigraph()}).setGraph(P.graph());return P.nodes().forEach(D=>{P.children(D).length||M.setNode(D,P.node(D))}),P.edges().forEach(D=>{M.setEdge(D,P.edge(D))}),M}function i(P){let M=P.nodes().map(D=>{let z={};return P.outEdges(D).forEach(E=>{z[E.w]=(z[E.w]||0)+P.edge(E).weight}),z});return T(P.nodes(),M)}function l(P){let M=P.nodes().map(D=>{let z={};return P.inEdges(D).forEach(E=>{z[E.v]=(z[E.v]||0)+P.edge(E).weight}),z});return T(P.nodes(),M)}function c(P,M){let D=P.x,z=P.y,E=M.x-D,B=M.y-z,L=P.width/2,$=P.height/2;if(!E&&!B)throw new Error("Not possible to find intersection inside of the rectangle");let R,q;return Math.abs(B)*L>Math.abs(E)*$?(B<0&&($=-$),R=$*E/B,q=$):(E<0&&(L=-L),R=L,q=L*B/E),{x:D+R,y:z+q}}function d(P){let M=j(w(P)+1).map(()=>[]);return P.nodes().forEach(D=>{let z=P.node(D),E=z.rank;E!==void 0&&(M[E][z.order]=D)}),M}function h(P){let M=P.nodes().map(z=>{let E=P.node(z).rank;return E===void 0?Number.MAX_VALUE:E}),D=x(Math.min,M);P.nodes().forEach(z=>{let E=P.node(z);Object.hasOwn(E,"rank")&&(E.rank-=D)})}function u(P){let M=P.nodes().map(L=>P.node(L).rank).filter(L=>L!==void 0),D=x(Math.min,M),z=[];P.nodes().forEach(L=>{let $=P.node(L).rank-D;z[$]||(z[$]=[]),z[$].push(L)});let E=0,B=P.graph().nodeRankFactor;Array.from(z).forEach((L,$)=>{L===void 0&&$%B!==0?--E:L!==void 0&&E&&L.forEach(R=>P.node(R).rank+=E)})}function m(P,M,D,z){let E={width:0,height:0};return arguments.length>=4&&(E.rank=D,E.order=z),s(P,"border",E,M)}function f(P,M=g){let D=[];for(let z=0;z<P.length;z+=M){let E=P.slice(z,z+M);D.push(E)}return D}var g=65535;function x(P,M){if(M.length>g){let D=f(M);return P.apply(null,D.map(z=>P.apply(null,z)))}else return P.apply(null,M)}function w(P){let M=P.nodes().map(D=>{let z=P.node(D).rank;return z===void 0?Number.MIN_VALUE:z});return x(Math.max,M)}function v(P,M){let D={lhs:[],rhs:[]};return P.forEach(z=>{M(z)?D.lhs.push(z):D.rhs.push(z)}),D}function y(P,M){let D=Date.now();try{return M()}finally{console.log(P+" time: "+(Date.now()-D)+"ms")}}function b(P,M){return M()}var k=0;function C(P){var M=++k;return P+(""+M)}function j(P,M,D=1){M==null&&(M=P,P=0);let z=B=>B<M;D<0&&(z=B=>M<B);let E=[];for(let B=P;z(B);B+=D)E.push(B);return E}function A(P,M){let D={};for(let z of M)P[z]!==void 0&&(D[z]=P[z]);return D}function S(P,M){let D=M;return typeof M=="string"&&(D=z=>z[M]),Object.entries(P).reduce((z,[E,B])=>(z[E]=D(B,E),z),{})}function T(P,M){return P.reduce((D,z,E)=>(D[z]=M[E],D),{})}}),kx=Ze((e,t)=>{var n=wx(),s=vt().uniqueId;t.exports={run:o,undo:i};function o(l){(l.graph().acyclicer==="greedy"?n(l,c(l)):a(l)).forEach(d=>{let h=l.edge(d);l.removeEdge(d),h.forwardName=d.name,h.reversed=!0,l.setEdge(d.w,d.v,h,s("rev"))});function c(d){return h=>d.edge(h).weight}}function a(l){let c=[],d={},h={};function u(m){Object.hasOwn(h,m)||(h[m]=!0,d[m]=!0,l.outEdges(m).forEach(f=>{Object.hasOwn(d,f.w)?c.push(f):u(f.w)}),delete d[m])}return l.nodes().forEach(u),c}function i(l){l.edges().forEach(c=>{let d=l.edge(c);if(d.reversed){l.removeEdge(c);let h=d.forwardName;delete d.reversed,delete d.forwardName,l.setEdge(c.w,c.v,d,h)}})}}),vx=Ze((e,t)=>{var n=vt();t.exports={run:s,undo:a};function s(i){i.graph().dummyChains=[],i.edges().forEach(l=>o(i,l))}function o(i,l){let c=l.v,d=i.node(c).rank,h=l.w,u=i.node(h).rank,m=l.name,f=i.edge(l),g=f.labelRank;if(u===d+1)return;i.removeEdge(l);let x,w,v;for(v=0,++d;d<u;++v,++d)f.points=[],w={width:0,height:0,edgeLabel:f,edgeObj:l,rank:d},x=n.addDummyNode(i,"edge",w,"_d"),d===g&&(w.width=f.width,w.height=f.height,w.dummy="edge-label",w.labelpos=f.labelpos),i.setEdge(c,x,{weight:f.weight},m),v===0&&i.graph().dummyChains.push(x),c=x;i.setEdge(c,h,{weight:f.weight},m)}function a(i){i.graph().dummyChains.forEach(l=>{let c=i.node(l),d=c.edgeLabel,h;for(i.setEdge(c.edgeObj,d);c.dummy;)h=i.successors(l)[0],i.removeNode(l),d.points.push({x:c.x,y:c.y}),c.dummy==="edge-label"&&(d.x=c.x,d.y=c.y,d.width=c.width,d.height=c.height),l=h,c=i.node(l)})}}),bo=Ze((e,t)=>{var{applyWithChunking:n}=vt();t.exports={longestPath:s,slack:o};function s(a){var i={};function l(c){var d=a.node(c);if(Object.hasOwn(i,c))return d.rank;i[c]=!0;let h=a.outEdges(c).map(m=>m==null?Number.POSITIVE_INFINITY:l(m.w)-a.edge(m).minlen);var u=n(Math.min,h);return u===Number.POSITIVE_INFINITY&&(u=0),d.rank=u}a.sources().forEach(l)}function o(a,i){return a.node(i.w).rank-a.node(i.v).rank-a.edge(i).minlen}}),ku=Ze((e,t)=>{var n=rn().Graph,s=bo().slack;t.exports=o;function o(c){var d=new n({directed:!1}),h=c.nodes()[0],u=c.nodeCount();d.setNode(h,{});for(var m,f;a(d,c)<u;)m=i(d,c),f=d.hasNode(m.v)?s(c,m):-s(c,m),l(d,c,f);return d}function a(c,d){function h(u){d.nodeEdges(u).forEach(m=>{var f=m.v,g=u===f?m.w:f;!c.hasNode(g)&&!s(d,m)&&(c.setNode(g,{}),c.setEdge(u,g,{}),h(g))})}return c.nodes().forEach(h),c.nodeCount()}function i(c,d){return d.edges().reduce((h,u)=>{let m=Number.POSITIVE_INFINITY;return c.hasNode(u.v)!==c.hasNode(u.w)&&(m=s(d,u)),m<h[0]?[m,u]:h},[Number.POSITIVE_INFINITY,null])[1]}function l(c,d,h){c.nodes().forEach(u=>d.node(u).rank+=h)}}),jx=Ze((e,t)=>{var n=ku(),s=bo().slack,o=bo().longestPath,a=rn().alg.preorder,i=rn().alg.postorder,l=vt().simplify;t.exports=c,c.initLowLimValues=m,c.initCutValues=d,c.calcCutValue=u,c.leaveEdge=g,c.enterEdge=x,c.exchangeEdges=w;function c(k){k=l(k),o(k);var C=n(k);m(C),d(C,k);for(var j,A;j=g(C);)A=x(C,k,j),w(C,k,j,A)}function d(k,C){var j=i(k,k.nodes());j=j.slice(0,j.length-1),j.forEach(A=>h(k,C,A))}function h(k,C,j){var A=k.node(j),S=A.parent;k.edge(j,S).cutvalue=u(k,C,j)}function u(k,C,j){var A=k.node(j),S=A.parent,T=!0,P=C.edge(j,S),M=0;return P||(T=!1,P=C.edge(S,j)),M=P.weight,C.nodeEdges(j).forEach(D=>{var z=D.v===j,E=z?D.w:D.v;if(E!==S){var B=z===T,L=C.edge(D).weight;if(M+=B?L:-L,y(k,j,E)){var $=k.edge(j,E).cutvalue;M+=B?-$:$}}}),M}function m(k,C){arguments.length<2&&(C=k.nodes()[0]),f(k,{},1,C)}function f(k,C,j,A,S){var T=j,P=k.node(A);return C[A]=!0,k.neighbors(A).forEach(M=>{Object.hasOwn(C,M)||(j=f(k,C,j,M,A))}),P.low=T,P.lim=j++,S?P.parent=S:delete P.parent,j}function g(k){return k.edges().find(C=>k.edge(C).cutvalue<0)}function x(k,C,j){var A=j.v,S=j.w;C.hasEdge(A,S)||(A=j.w,S=j.v);var T=k.node(A),P=k.node(S),M=T,D=!1;T.lim>P.lim&&(M=P,D=!0);var z=C.edges().filter(E=>D===b(k,k.node(E.v),M)&&D!==b(k,k.node(E.w),M));return z.reduce((E,B)=>s(C,B)<s(C,E)?B:E)}function w(k,C,j,A){var S=j.v,T=j.w;k.removeEdge(S,T),k.setEdge(A.v,A.w,{}),m(k),d(k,C),v(k,C)}function v(k,C){var j=k.nodes().find(S=>!C.node(S).parent),A=a(k,j);A=A.slice(1),A.forEach(S=>{var T=k.node(S).parent,P=C.edge(S,T),M=!1;P||(P=C.edge(T,S),M=!0),C.node(S).rank=C.node(T).rank+(M?P.minlen:-P.minlen)})}function y(k,C,j){return k.hasEdge(C,j)}function b(k,C,j){return j.low<=C.lim&&C.lim<=j.lim}}),Nx=Ze((e,t)=>{var n=bo(),s=n.longestPath,o=ku(),a=jx();t.exports=i;function i(h){var u=h.graph().ranker;if(u instanceof Function)return u(h);switch(h.graph().ranker){case"network-simplex":d(h);break;case"tight-tree":c(h);break;case"longest-path":l(h);break;case"none":break;default:d(h)}}var l=s;function c(h){s(h),o(h)}function d(h){a(h)}}),Sx=Ze((e,t)=>{t.exports=n;function n(a){let i=o(a);a.graph().dummyChains.forEach(l=>{let c=a.node(l),d=c.edgeObj,h=s(a,i,d.v,d.w),u=h.path,m=h.lca,f=0,g=u[f],x=!0;for(;l!==d.w;){if(c=a.node(l),x){for(;(g=u[f])!==m&&a.node(g).maxRank<c.rank;)f++;g===m&&(x=!1)}if(!x){for(;f<u.length-1&&a.node(g=u[f+1]).minRank<=c.rank;)f++;g=u[f]}a.setParent(l,g),l=a.successors(l)[0]}})}function s(a,i,l,c){let d=[],h=[],u=Math.min(i[l].low,i[c].low),m=Math.max(i[l].lim,i[c].lim),f,g;f=l;do f=a.parent(f),d.push(f);while(f&&(i[f].low>u||m>i[f].lim));for(g=f,f=c;(f=a.parent(f))!==g;)h.push(f);return{path:d.concat(h.reverse()),lca:g}}function o(a){let i={},l=0;function c(d){let h=l;a.children(d).forEach(c),i[d]={low:h,lim:l++}}return a.children().forEach(c),i}}),Cx=Ze((e,t)=>{var n=vt();t.exports={run:s,cleanup:l};function s(c){let d=n.addDummyNode(c,"root",{},"_root"),h=a(c),u=Object.values(h),m=n.applyWithChunking(Math.max,u)-1,f=2*m+1;c.graph().nestingRoot=d,c.edges().forEach(x=>c.edge(x).minlen*=f);let g=i(c)+1;c.children().forEach(x=>o(c,d,f,g,m,h,x)),c.graph().nodeRankFactor=f}function o(c,d,h,u,m,f,g){let x=c.children(g);if(!x.length){g!==d&&c.setEdge(d,g,{weight:0,minlen:h});return}let w=n.addBorderNode(c,"_bt"),v=n.addBorderNode(c,"_bb"),y=c.node(g);c.setParent(w,g),y.borderTop=w,c.setParent(v,g),y.borderBottom=v,x.forEach(b=>{o(c,d,h,u,m,f,b);let k=c.node(b),C=k.borderTop?k.borderTop:b,j=k.borderBottom?k.borderBottom:b,A=k.borderTop?u:2*u,S=C!==j?1:m-f[g]+1;c.setEdge(w,C,{weight:A,minlen:S,nestingEdge:!0}),c.setEdge(j,v,{weight:A,minlen:S,nestingEdge:!0})}),c.parent(g)||c.setEdge(d,w,{weight:0,minlen:m+f[g]})}function a(c){var d={};function h(u,m){var f=c.children(u);f&&f.length&&f.forEach(g=>h(g,m+1)),d[u]=m}return c.children().forEach(u=>h(u,1)),d}function i(c){return c.edges().reduce((d,h)=>d+c.edge(h).weight,0)}function l(c){var d=c.graph();c.removeNode(d.nestingRoot),delete d.nestingRoot,c.edges().forEach(h=>{var u=c.edge(h);u.nestingEdge&&c.removeEdge(h)})}}),Ex=Ze((e,t)=>{var n=vt();t.exports=s;function s(a){function i(l){let c=a.children(l),d=a.node(l);if(c.length&&c.forEach(i),Object.hasOwn(d,"minRank")){d.borderLeft=[],d.borderRight=[];for(let h=d.minRank,u=d.maxRank+1;h<u;++h)o(a,"borderLeft","_bl",l,d,h),o(a,"borderRight","_br",l,d,h)}}a.children().forEach(i)}function o(a,i,l,c,d,h){let u={width:0,height:0,rank:h,borderType:i},m=d[i][h-1],f=n.addDummyNode(a,"border",u,l);d[i][h]=f,a.setParent(f,c),m&&a.setEdge(m,f,{weight:1})}}),Ix=Ze((e,t)=>{t.exports={adjust:n,undo:s};function n(h){let u=h.graph().rankdir.toLowerCase();(u==="lr"||u==="rl")&&o(h)}function s(h){let u=h.graph().rankdir.toLowerCase();(u==="bt"||u==="rl")&&i(h),(u==="lr"||u==="rl")&&(c(h),o(h))}function o(h){h.nodes().forEach(u=>a(h.node(u))),h.edges().forEach(u=>a(h.edge(u)))}function a(h){let u=h.width;h.width=h.height,h.height=u}function i(h){h.nodes().forEach(u=>l(h.node(u))),h.edges().forEach(u=>{let m=h.edge(u);m.points.forEach(l),Object.hasOwn(m,"y")&&l(m)})}function l(h){h.y=-h.y}function c(h){h.nodes().forEach(u=>d(h.node(u))),h.edges().forEach(u=>{let m=h.edge(u);m.points.forEach(d),Object.hasOwn(m,"x")&&d(m)})}function d(h){let u=h.x;h.x=h.y,h.y=u}}),Tx=Ze((e,t)=>{var n=vt();t.exports=s;function s(o){let a={},i=o.nodes().filter(u=>!o.children(u).length),l=i.map(u=>o.node(u).rank),c=n.applyWithChunking(Math.max,l),d=n.range(c+1).map(()=>[]);function h(u){if(a[u])return;a[u]=!0;let m=o.node(u);d[m.rank].push(u),o.successors(u).forEach(h)}return i.sort((u,m)=>o.node(u).rank-o.node(m).rank).forEach(h),d}}),Mx=Ze((e,t)=>{var n=vt().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,x)=>x)),d=i.flatMap(g=>a.outEdges(g).map(x=>({pos:c[x.w],weight:a.edge(x).weight})).sort((x,w)=>x.pos-w.pos)),h=1;for(;h<l.length;)h<<=1;let u=2*h-1;h-=1;let m=new Array(u).fill(0),f=0;return d.forEach(g=>{let x=g.pos+h;m[x]+=g.weight;let w=0;for(;x>0;)x%2&&(w+=m[x+1]),x=x-1>>1,m[x]+=g.weight;f+=g.weight*w}),f}}),Ax=Ze((e,t)=>{t.exports=n;function n(s,o=[]){return o.map(a=>{let i=s.inEdges(a);if(i.length){let l=i.reduce((c,d)=>{let h=s.edge(d),u=s.node(d.v);return{sum:c.sum+h.weight*u.order,weight:c.weight+h.weight}},{sum:0,weight:0});return{v:a,barycenter:l.sum/l.weight,weight:l.weight}}else return{v:a}})}}),_x=Ze((e,t)=>{var n=vt();t.exports=s;function s(i,l){let c={};i.forEach((h,u)=>{let m=c[h.v]={indegree:0,in:[],out:[],vs:[h.v],i:u};h.barycenter!==void 0&&(m.barycenter=h.barycenter,m.weight=h.weight)}),l.edges().forEach(h=>{let u=c[h.v],m=c[h.w];u!==void 0&&m!==void 0&&(m.indegree++,u.out.push(c[h.w]))});let d=Object.values(c).filter(h=>!h.indegree);return o(d)}function o(i){let l=[];function c(h){return u=>{u.merged||(u.barycenter===void 0||h.barycenter===void 0||u.barycenter>=h.barycenter)&&a(h,u)}}function d(h){return u=>{u.in.push(h),--u.indegree===0&&i.push(u)}}for(;i.length;){let h=i.pop();l.push(h),h.in.reverse().forEach(c(h)),h.out.forEach(d(h))}return l.filter(h=>!h.merged).map(h=>n.pick(h,["vs","i","barycenter","weight"]))}function a(i,l){let c=0,d=0;i.weight&&(c+=i.barycenter*i.weight,d+=i.weight),l.weight&&(c+=l.barycenter*l.weight,d+=l.weight),i.vs=l.vs.concat(i.vs),i.barycenter=c/d,i.weight=d,i.i=Math.min(l.i,i.i),l.merged=!0}}),Lx=Ze((e,t)=>{var n=vt();t.exports=s;function s(i,l){let c=n.partition(i,w=>Object.hasOwn(w,"barycenter")),d=c.lhs,h=c.rhs.sort((w,v)=>v.i-w.i),u=[],m=0,f=0,g=0;d.sort(a(!!l)),g=o(u,h,g),d.forEach(w=>{g+=w.vs.length,u.push(w.vs),m+=w.barycenter*w.weight,f+=w.weight,g=o(u,h,g)});let x={vs:u.flat(!0)};return f&&(x.barycenter=m/f,x.weight=f),x}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}}),Rx=Ze((e,t)=>{var n=Ax(),s=_x(),o=Lx();t.exports=a;function a(c,d,h,u){let m=c.children(d),f=c.node(d),g=f?f.borderLeft:void 0,x=f?f.borderRight:void 0,w={};g&&(m=m.filter(k=>k!==g&&k!==x));let v=n(c,m);v.forEach(k=>{if(c.children(k.v).length){let C=a(c,k.v,h,u);w[k.v]=C,Object.hasOwn(C,"barycenter")&&l(k,C)}});let y=s(v,h);i(y,w);let b=o(y,u);if(g&&(b.vs=[g,b.vs,x].flat(!0),c.predecessors(g).length)){let k=c.node(c.predecessors(g)[0]),C=c.node(c.predecessors(x)[0]);Object.hasOwn(b,"barycenter")||(b.barycenter=0,b.weight=0),b.barycenter=(b.barycenter*b.weight+k.order+C.order)/(b.weight+2),b.weight+=2}return b}function i(c,d){c.forEach(h=>{h.vs=h.vs.flatMap(u=>d[u]?d[u].vs:u)})}function l(c,d){c.barycenter!==void 0?(c.barycenter=(c.barycenter*c.weight+d.barycenter*d.weight)/(c.weight+d.weight),c.weight+=d.weight):(c.barycenter=d.barycenter,c.weight=d.weight)}}),Dx=Ze((e,t)=>{var n=rn().Graph,s=vt();t.exports=o;function o(i,l,c,d){d||(d=i.nodes());let h=a(i),u=new n({compound:!0}).setGraph({root:h}).setDefaultNodeLabel(m=>i.node(m));return d.forEach(m=>{let f=i.node(m),g=i.parent(m);(f.rank===l||f.minRank<=l&&l<=f.maxRank)&&(u.setNode(m),u.setParent(m,g||h),i[c](m).forEach(x=>{let w=x.v===m?x.w:x.v,v=u.edge(w,m),y=v!==void 0?v.weight:0;u.setEdge(w,m,{weight:i.edge(x).weight+y})}),Object.hasOwn(f,"minRank")&&u.setNode(m,{borderLeft:f.borderLeft[l],borderRight:f.borderRight[l]}))}),u}function a(i){for(var l;i.hasNode(l=s.uniqueId("_root")););return l}}),Ox=Ze((e,t)=>{t.exports=n;function n(s,o,a){let i={},l;a.forEach(c=>{let d=s.parent(c),h,u;for(;d;){if(h=s.parent(d),h?(u=i[h],i[h]=d):(u=l,l=d),u&&u!==d){o.setEdge(u,d);return}d=h}})}}),$x=Ze((e,t)=>{var n=Tx(),s=Mx(),o=Rx(),a=Dx(),i=Ox(),l=rn().Graph,c=vt();t.exports=d;function d(f,g={}){if(typeof g.customOrder=="function"){g.customOrder(f,d);return}let x=c.maxRank(f),w=h(f,c.range(1,x+1),"inEdges"),v=h(f,c.range(x-1,-1,-1),"outEdges"),y=n(f);if(m(f,y),g.disableOptimalOrderHeuristic)return;let b=Number.POSITIVE_INFINITY,k,C=g.constraints||[];for(let j=0,A=0;A<4;++j,++A){u(j%2?w:v,j%4>=2,C),y=c.buildLayerMatrix(f);let S=s(f,y);S<b?(A=0,k=Object.assign({},y),b=S):S===b&&(k=structuredClone(y))}m(f,k)}function h(f,g,x){let w=new Map,v=(y,b)=>{w.has(y)||w.set(y,[]),w.get(y).push(b)};for(let y of f.nodes()){let b=f.node(y);if(typeof b.rank=="number"&&v(b.rank,y),typeof b.minRank=="number"&&typeof b.maxRank=="number")for(let k=b.minRank;k<=b.maxRank;k++)k!==b.rank&&v(k,y)}return g.map(function(y){return a(f,y,x,w.get(y)||[])})}function u(f,g,x){let w=new l;f.forEach(function(v){x.forEach(k=>w.setEdge(k.left,k.right));let y=v.graph().root,b=o(v,y,w,g);b.vs.forEach((k,C)=>v.node(k).order=C),i(v,w,b.vs)})}function m(f,g){Object.values(g).forEach(x=>x.forEach((w,v)=>f.node(w).order=v))}}),Px=Ze((e,t)=>{var n=rn().Graph,s=vt();t.exports={positionX:x,findType1Conflicts:o,findType2Conflicts:a,addConflict:l,hasConflict:c,verticalAlignment:d,horizontalCompaction:h,alignCoordinates:f,findSmallestWidthAlignment:m,balance:g};function o(y,b){let k={};function C(j,A){let S=0,T=0,P=j.length,M=A[A.length-1];return A.forEach((D,z)=>{let E=i(y,D),B=E?y.node(E).order:P;(E||D===M)&&(A.slice(T,z+1).forEach(L=>{y.predecessors(L).forEach($=>{let R=y.node($),q=R.order;(q<S||B<q)&&!(R.dummy&&y.node(L).dummy)&&l(k,$,L)})}),T=z+1,S=B)}),A}return b.length&&b.reduce(C),k}function a(y,b){let k={};function C(A,S,T,P,M){let D;s.range(S,T).forEach(z=>{D=A[z],y.node(D).dummy&&y.predecessors(D).forEach(E=>{let B=y.node(E);B.dummy&&(B.order<P||B.order>M)&&l(k,E,D)})})}function j(A,S){let T=-1,P,M=0;return S.forEach((D,z)=>{if(y.node(D).dummy==="border"){let E=y.predecessors(D);E.length&&(P=y.node(E[0]).order,C(S,M,z,T,P),M=z,T=P)}C(S,M,S.length,P,A.length)}),S}return b.length&&b.reduce(j),k}function i(y,b){if(y.node(b).dummy)return y.predecessors(b).find(k=>y.node(k).dummy)}function l(y,b,k){if(b>k){let j=b;b=k,k=j}let C=y[b];C||(y[b]=C={}),C[k]=!0}function c(y,b,k){if(b>k){let C=b;b=k,k=C}return!!y[b]&&Object.hasOwn(y[b],k)}function d(y,b,k,C){let j={},A={},S={};return b.forEach(T=>{T.forEach((P,M)=>{j[P]=P,A[P]=P,S[P]=M})}),b.forEach(T=>{let P=-1;T.forEach(M=>{let D=C(M);if(D.length){D=D.sort((E,B)=>S[E]-S[B]);let z=(D.length-1)/2;for(let E=Math.floor(z),B=Math.ceil(z);E<=B;++E){let L=D[E];A[M]===M&&P<S[L]&&!c(k,M,L)&&(A[L]=M,A[M]=j[M]=j[L],P=S[L])}}})}),{root:j,align:A}}function h(y,b,k,C,j){let A={},S=u(y,b,k,j),T=j?"borderLeft":"borderRight";function P(z,E){let B=S.nodes().slice(),L={},$=B.pop();for(;$;){if(L[$])z($);else{L[$]=!0,B.push($);for(let R of E($))B.push(R)}$=B.pop()}}function M(z){A[z]=S.inEdges(z).reduce((E,B)=>Math.max(E,A[B.v]+S.edge(B)),0)}function D(z){let E=S.outEdges(z).reduce((L,$)=>Math.min(L,A[$.w]-S.edge($)),Number.POSITIVE_INFINITY),B=y.node(z);E!==Number.POSITIVE_INFINITY&&B.borderType!==T&&(A[z]=Math.max(A[z],E))}return P(M,S.predecessors.bind(S)),P(D,S.successors.bind(S)),Object.keys(C).forEach(z=>A[z]=A[k[z]]),A}function u(y,b,k,C){let j=new n,A=y.graph(),S=w(A.nodesep,A.edgesep,C);return b.forEach(T=>{let P;T.forEach(M=>{let D=k[M];if(j.setNode(D),P){var z=k[P],E=j.edge(z,D);j.setEdge(z,D,Math.max(S(y,M,P),E||0))}P=M})}),j}function m(y,b){return Object.values(b).reduce((k,C)=>{let j=Number.NEGATIVE_INFINITY,A=Number.POSITIVE_INFINITY;Object.entries(C).forEach(([T,P])=>{let M=v(y,T)/2;j=Math.max(P+M,j),A=Math.min(P-M,A)});let S=j-A;return S<k[0]&&(k=[S,C]),k},[Number.POSITIVE_INFINITY,null])[1]}function f(y,b){let k=Object.values(b),C=s.applyWithChunking(Math.min,k),j=s.applyWithChunking(Math.max,k);["u","d"].forEach(A=>{["l","r"].forEach(S=>{let T=A+S,P=y[T];if(P===b)return;let M=Object.values(P),D=C-s.applyWithChunking(Math.min,M);S!=="l"&&(D=j-s.applyWithChunking(Math.max,M)),D&&(y[T]=s.mapValues(P,z=>z+D))})})}function g(y,b){return s.mapValues(y.ul,(k,C)=>{if(b)return y[b.toLowerCase()][C];{let j=Object.values(y).map(A=>A[C]).sort((A,S)=>A-S);return(j[1]+j[2])/2}})}function x(y){let b=s.buildLayerMatrix(y),k=Object.assign(o(y,b),a(y,b)),C={},j;["u","d"].forEach(S=>{j=S==="u"?b:Object.values(b).reverse(),["l","r"].forEach(T=>{T==="r"&&(j=j.map(z=>Object.values(z).reverse()));let P=(S==="u"?y.predecessors:y.successors).bind(y),M=d(y,j,k,P),D=h(y,j,M.root,M.align,T==="r");T==="r"&&(D=s.mapValues(D,z=>-z)),C[S+T]=D})});let A=m(y,C);return f(C,A),g(C,y.graph().align)}function w(y,b,k){return(C,j,A)=>{let S=C.node(j),T=C.node(A),P=0,M;if(P+=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&&(P+=k?M:-M),M=0,P+=(S.dummy?b:y)/2,P+=(T.dummy?b:y)/2,P+=T.width/2,Object.hasOwn(T,"labelpos"))switch(T.labelpos.toLowerCase()){case"l":M=T.width/2;break;case"r":M=-T.width/2;break}return M&&(P+=k?M:-M),M=0,P}}function v(y,b){return y.node(b).width}}),Bx=Ze((e,t)=>{var n=vt(),s=Px().positionX;t.exports=o;function o(i){i=n.asNonCompoundGraph(i),a(i),Object.entries(s(i)).forEach(([l,c])=>i.node(l).x=c)}function a(i){let l=n.buildLayerMatrix(i),c=i.graph().ranksep,d=i.graph().rankalign,h=0;l.forEach(u=>{let m=u.reduce((f,g)=>{let x=i.node(g).height;return f>x?f:x},0);u.forEach(f=>{let g=i.node(f);d==="top"?g.y=h+g.height/2:d==="bottom"?g.y=h+m-g.height/2:g.y=h+m/2}),h+=m+c})}}),qx=Ze((e,t)=>{var n=kx(),s=vx(),o=Nx(),a=vt().normalizeRanks,i=Sx(),l=vt().removeEmptyRanks,c=Cx(),d=Ex(),h=Ix(),u=$x(),m=Bx(),f=vt(),g=rn().Graph;t.exports=x;function x(I,V={}){let W=V.debugTiming?f.time:f.notime;return W("layout",()=>{let F=W(" buildLayoutGraph",()=>P(I));return W(" runLayout",()=>w(F,W,V)),W(" updateInputGraph",()=>v(I,F)),F})}function w(I,V,W){V(" makeSpaceForEdgeLabels",()=>M(I)),V(" removeSelfEdges",()=>H(I)),V(" acyclic",()=>n.run(I)),V(" nestingGraph.run",()=>c.run(I)),V(" rank",()=>o(f.asNonCompoundGraph(I))),V(" injectEdgeLabelProxies",()=>D(I)),V(" removeEmptyRanks",()=>l(I)),V(" nestingGraph.cleanup",()=>c.cleanup(I)),V(" normalizeRanks",()=>a(I)),V(" assignRankMinMax",()=>z(I)),V(" removeEdgeLabelProxies",()=>E(I)),V(" normalize.run",()=>s.run(I)),V(" parentDummyChains",()=>i(I)),V(" addBorderSegments",()=>d(I)),V(" order",()=>u(I,W)),V(" insertSelfEdges",()=>K(I)),V(" adjustCoordinateSystem",()=>h.adjust(I)),V(" position",()=>m(I)),V(" positionSelfEdges",()=>O(I)),V(" removeBorderNodes",()=>q(I)),V(" normalize.undo",()=>s.undo(I)),V(" fixupEdgeLabelCoords",()=>$(I)),V(" undoCoordinateSystem",()=>h.undo(I)),V(" translateGraph",()=>B(I)),V(" assignNodeIntersects",()=>L(I)),V(" reversePoints",()=>R(I)),V(" acyclic.undo",()=>n.undo(I))}function v(I,V){I.nodes().forEach(W=>{let F=I.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))}),I.edges().forEach(W=>{let F=I.edge(W),Z=V.edge(W);F.points=Z.points,Object.hasOwn(Z,"x")&&(F.x=Z.x,F.y=Z.y)}),I.graph().width=V.graph().width,I.graph().height=V.graph().height}var y=["nodesep","edgesep","ranksep","marginx","marginy"],b={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb",rankalign:"center"},k=["acyclicer","ranker","rankdir","align","rankalign"],C=["width","height","rank"],j={width:0,height:0},A=["minlen","weight","width","height","labeloffset"],S={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},T=["labelpos"];function P(I){let V=new g({multigraph:!0,compound:!0}),W=_(I.graph());return V.setGraph(Object.assign({},b,Y(W,y),f.pick(W,k))),I.nodes().forEach(F=>{let Z=_(I.node(F)),te=Y(Z,C);Object.keys(j).forEach(ce=>{te[ce]===void 0&&(te[ce]=j[ce])}),V.setNode(F,te),V.setParent(F,I.parent(F))}),I.edges().forEach(F=>{let Z=_(I.edge(F));V.setEdge(F,Object.assign({},S,Y(Z,A),f.pick(Z,T)))}),V}function M(I){let V=I.graph();V.ranksep/=2,I.edges().forEach(W=>{let F=I.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(I){I.edges().forEach(V=>{let W=I.edge(V);if(W.width&&W.height){let F=I.node(V.v),Z={rank:(I.node(V.w).rank-F.rank)/2+F.rank,e:V};f.addDummyNode(I,"edge-proxy",Z,"_ep")}})}function z(I){let V=0;I.nodes().forEach(W=>{let F=I.node(W);F.borderTop&&(F.minRank=I.node(F.borderTop).rank,F.maxRank=I.node(F.borderBottom).rank,V=Math.max(V,F.maxRank))}),I.graph().maxRank=V}function E(I){I.nodes().forEach(V=>{let W=I.node(V);W.dummy==="edge-proxy"&&(I.edge(W.e).labelRank=W.rank,I.removeNode(V))})}function B(I){let V=Number.POSITIVE_INFINITY,W=0,F=Number.POSITIVE_INFINITY,Z=0,te=I.graph(),ce=te.marginx||0,oe=te.marginy||0;function be(Ne){let Ie=Ne.x,Ce=Ne.y,Fe=Ne.width,Be=Ne.height;V=Math.min(V,Ie-Fe/2),W=Math.max(W,Ie+Fe/2),F=Math.min(F,Ce-Be/2),Z=Math.max(Z,Ce+Be/2)}I.nodes().forEach(Ne=>be(I.node(Ne))),I.edges().forEach(Ne=>{let Ie=I.edge(Ne);Object.hasOwn(Ie,"x")&&be(Ie)}),V-=ce,F-=oe,I.nodes().forEach(Ne=>{let Ie=I.node(Ne);Ie.x-=V,Ie.y-=F}),I.edges().forEach(Ne=>{let Ie=I.edge(Ne);Ie.points.forEach(Ce=>{Ce.x-=V,Ce.y-=F}),Object.hasOwn(Ie,"x")&&(Ie.x-=V),Object.hasOwn(Ie,"y")&&(Ie.y-=F)}),te.width=W-V+ce,te.height=Z-F+oe}function L(I){I.edges().forEach(V=>{let W=I.edge(V),F=I.node(V.v),Z=I.node(V.w),te,ce;W.points?(te=W.points[0],ce=W.points[W.points.length-1]):(W.points=[],te=Z,ce=F),W.points.unshift(f.intersectRect(F,te)),W.points.push(f.intersectRect(Z,ce))})}function $(I){I.edges().forEach(V=>{let W=I.edge(V);if(Object.hasOwn(W,"x"))switch((W.labelpos==="l"||W.labelpos==="r")&&(W.width-=W.labeloffset),W.labelpos){case"l":W.x-=W.width/2+W.labeloffset;break;case"r":W.x+=W.width/2+W.labeloffset;break}})}function R(I){I.edges().forEach(V=>{let W=I.edge(V);W.reversed&&W.points.reverse()})}function q(I){I.nodes().forEach(V=>{if(I.children(V).length){let W=I.node(V),F=I.node(W.borderTop),Z=I.node(W.borderBottom),te=I.node(W.borderLeft[W.borderLeft.length-1]),ce=I.node(W.borderRight[W.borderRight.length-1]);W.width=Math.abs(ce.x-te.x),W.height=Math.abs(Z.y-F.y),W.x=te.x+W.width/2,W.y=F.y+W.height/2}}),I.nodes().forEach(V=>{I.node(V).dummy==="border"&&I.removeNode(V)})}function H(I){I.edges().forEach(V=>{if(V.v===V.w){var W=I.node(V.v);W.selfEdges||(W.selfEdges=[]),W.selfEdges.push({e:V,label:I.edge(V)}),I.removeEdge(V)}})}function K(I){var V=f.buildLayerMatrix(I);V.forEach(W=>{var F=0;W.forEach((Z,te)=>{var ce=I.node(Z);ce.order=te+F,(ce.selfEdges||[]).forEach(oe=>{f.addDummyNode(I,"selfedge",{width:oe.label.width,height:oe.label.height,rank:ce.rank,order:te+ ++F,e:oe.e,label:oe.label},"_se")}),delete ce.selfEdges})})}function O(I){I.nodes().forEach(V=>{var W=I.node(V);if(W.dummy==="selfedge"){var F=I.node(W.e.v),Z=F.x+F.width/2,te=F.y,ce=W.x-Z,oe=F.height/2;I.setEdge(W.e,W.label),I.removeNode(V),W.label.points=[{x:Z+2*ce/3,y:te-oe},{x:Z+5*ce/6,y:te-oe},{x:Z+ce,y:te},{x:Z+5*ce/6,y:te+oe},{x:Z+2*ce/3,y:te+oe}],W.label.x=W.x,W.label.y=W.y}})}function Y(I,V){return f.mapValues(f.pick(I,V),Number)}function _(I){var V={};return I&&Object.entries(I).forEach(([W,F])=>{typeof W=="string"&&(W=W.toLowerCase()),V[W]=F}),V}}),zx=Ze((e,t)=>{var n=vt(),s=rn().Graph;t.exports={debugOrdering:o};function o(a){let i=n.buildLayerMatrix(a),l=new s({compound:!0,multigraph:!0}).setGraph({});return a.nodes().forEach(c=>{l.setNode(c,{label:c}),l.setParent(c,"layer"+a.node(c).rank)}),a.edges().forEach(c=>l.setEdge(c.v,c.w,{},c.name)),i.forEach((c,d)=>{let h="layer"+d;l.setNode(h,{rank:"same"}),c.reduce((u,m)=>(l.setEdge(u,m,{style:"invis"}),m))}),l}}),Fx=Ze((e,t)=>{t.exports="2.0.4"}),Hx=Ze((e,t)=>{t.exports={graphlib:rn(),layout:qx(),debug:zx(),util:{time:vt().time,notime:vt().notime},version:Fx()}});const nc=Hx();const Ps="req-",sc=e=>`${Ps}${e}`,yo=e=>e.startsWith(Ps),wo=e=>e.status==="archived";function Vx(e){const{nodeId:t,focusedNodeId:n,selectedEntityId:s,requirementIdOfTask:o,profile:a}=e,i=yo(t),l=i?t.slice(Ps.length):t;return a==="mobile"?n!==null?i?{type:"selectRequirement",requirementId:l}:{type:"selectTask",taskId:l}:i?{type:"focusRequirement",requirementNodeId:t,select:null}:o?{type:"focusRequirement",requirementNodeId:sc(o),select:null}:{type:"selectTask",taskId:l}:n!==null&&s===l?{type:"exitFocus"}:n!==null?i?{type:"selectRequirement",requirementId:l}:{type:"selectTask",taskId:l}:i?{type:"focusRequirement",requirementNodeId:t,select:{kind:"requirement",requirementId:l}}:o?{type:"focusRequirement",requirementNodeId:sc(o),select:{kind:"task",taskId:l}}:{type:"selectTask",taskId:l}}function ha(e,t){return e==="focus"?new Set(t):new Set(t.filter(n=>n!=="done"))}function ni(e,t,n){const s=new Set(n);return e.filter(o=>s.has(o.id)||o.requirementId===t)}function Wx(e,t,n){const s=new Set;for(const o of t)if(n.has(o.id))for(const a of ni(e,o.id,o.taskIds))s.add(a.id);return s}function Kx(e,t){return(t?ni(e,t.requirementId,t.requirementTaskIds):e).filter(wo).length}function Ux(e){const t=new Set([e.focusedNodeId]);if(!yo(e.focusedNodeId))return t;const n=e.focusedNodeId.slice(Ps.length);for(const s of ni(e.tasks,n,e.requirementTaskIds))e.allowedStatuses.has(s.status)&&(!e.showArchived&&wo(s)||t.add(s.id));return t}const rc={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"}},Yx={critical:"bg-red-500",high:"bg-amber-500",medium:"bg-amber-500",low:"bg-blue-500"};function Gx({data:e}){const{t}=ze(["work","common"]),{task:n,agentName:s,selected:o,direction:a="TB"}=e,i=rc[n.status]??rc.pending,l=n.taskType==="scheduled"&&!!n.scheduleConfig,c=l?n.scheduleConfig.every?t("work:task.everyInterval",{interval:n.scheduleConfig.every}):n.scheduleConfig.cron?t("work:task.cronLabel"):"":"",d=a==="LR"?ve.Left:ve.Top,h=a==="LR"?ve.Right:ve.Bottom;return r.jsxs("div",{className:`relative rounded-lg border px-3 py-2 min-w-[180px] max-w-[220px] shadow-md backdrop-blur-sm ${l?`${i.bg} border-blue-500/40 ring-1 ring-blue-500/20`:`${i.bg} ${i.border}`} ${o?"ring-2 ring-brand-500 shadow-brand-500/25 shadow-lg":""}`,children:[r.jsx(rs,{type:"target",position:d,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 ${Yx[n.priority]??"bg-gray-500"}`}),r.jsx("span",{className:`text-[10px] font-medium uppercase tracking-wider ${i.text}`,children:t(`work:status.task.${n.status}`,{defaultValue:n.status.replace("_"," ")})}),l&&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"})}),c]})]}),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(rs,{type:"source",position:h,className:"!bg-border-default !w-2 !h-2"})]})}const oc={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"}},ac={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"done",cancelled:"done",archived:"done"};function Xx({data:e}){const{t}=ze(["work","common"]),{req:n,selected:s,focused:o,direction:a="TB"}=e,i=oc[n.status]??oc.pending,l=a==="LR"?ve.Right:ve.Bottom;return r.jsxs("div",{className:`relative rounded-lg border-2 ${o?"border-solid":"border-dashed"} px-3 py-2 min-w-[180px] max-w-[220px] shadow-lg ${i.bg} ${i.border} ${s||o?"ring-2 ring-brand-500 shadow-brand-500/25":""}`,children:[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 ${i.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(rs,{type:"source",position:l,isConnectable:!1,className:"!bg-border-default !w-2 !h-2"})]})}const Zx={task:Gx,requirement:Xx};function Qx({nodeIds:e,rfRef:t}){const n=Fg();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 Jx=()=>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,e0=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 t0(){return p.useSyncExternalStore(e0,Jx,()=>!1)}const io=200,lo=80;function ic(e,t,n="TB"){const s=a=>{const i=new nc.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 nc.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 m of o)a=Math.min(a,m.position.x),i=Math.max(i,m.position.x+io),l=Math.min(l,m.position.y),c=Math.max(c,m.position.y+lo);const d=i-a,h=c-l,u=n==="TB"?"LR":"TB";if(d>h*3)return{nodes:s(u),direction:u}}return{nodes:o,direction:n}}function n0(e,t){const n=new Map,s=new Map;for(const i of e)s.set(i.id,i),n.set(i.id,new Set);for(const i of t)n.get(i.source)?.add(i.target),n.get(i.target)?.add(i.source);const o=new Set,a=[];for(const i of e){if(o.has(i.id))continue;const l=new Set,c=[i.id];for(;c.length>0;){const d=c.pop();if(!o.has(d)){o.add(d),l.add(d);for(const h of n.get(d)??[])o.has(h)||c.push(h)}}a.push({nodes:e.filter(d=>l.has(d.id)),edges:t.filter(d=>l.has(d.source)&&l.has(d.target))})}return a}function lc(e,t){if(e.length===0)return{nodes:[],direction:"TB"};const n=n0(e,t);if(n.length===1)return ic(e,t);let s="TB";const o=n.map(m=>{const{nodes:f,direction:g}=ic(m.nodes,m.edges);s=g;let x=1/0,w=-1/0,v=1/0,y=-1/0;for(const b of f)x=Math.min(x,b.position.x),w=Math.max(w,b.position.x+io),v=Math.min(v,b.position.y),y=Math.max(y,b.position.y+lo);for(const b of f)b.position.x-=x,b.position.y-=v;return{nodes:f,w:w-x,h:y-v}});o.sort((m,f)=>f.h-m.h);const a=60,i=o.reduce((m,f)=>m+(f.w+a)*(f.h+a),0),l=Math.sqrt(i)*1.1,c=[];let d=0,h=0,u=0;for(const m of o){d>0&&d+m.w>l&&(d=0,h+=u+a,u=0);for(const f of m.nodes)c.push({...f,position:{x:f.position.x+d,y:f.position.y+h}});d+=m.w+a,u=Math.max(u,m.h)}return{nodes:c,direction:s}}function s0(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 co=[{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(od),color:{bg:"bg-green-500/10",border:"border-green-500/30",text:"text-green-600"}}],ma=co.map(e=>e.id);function r0({tasks:e,requirements:t=[],agents:n,showArchived:s,onShowArchivedChange:o,onTaskClick:a,onReqClick:i,mobile:l=!1,onCollapseDAG:c,onDependencyChange:d,selectedTaskId:h,selectedReqId:u,hasDetailPanel:m,defaultExpandedNodeId:f,previewMode:g}){const{t:x}=ze(["work","common"]),w=t0(),[v,y]=p.useState(null),[b,k]=p.useState(null),[C,j]=p.useState(()=>ha("overview",ma)),[A,S]=p.useState(()=>ha("focus",ma)),[T,P]=p.useState(f??null),M=T!==null,D=M?A:C,z=M?S:j,E=ha(M?"focus":"overview",ma),[B,L]=p.useState(s??!1),$=s??B,R=p.useCallback(se=>{const le=typeof se=="function"?se($):se;L(le),o?.(le)},[$,o]);p.useEffect(()=>{s!==void 0&&L(s)},[s]),p.useEffect(()=>{f&&P(f)},[f]);const q=p.useMemo(()=>{const se=new Set;for(const le of co)if(D.has(le.id))for(const fe of le.statuses)se.add(fe);return se},[D]),H=p.useMemo(()=>{const se=new Set;for(const le of e)for(const fe of co)if(fe.statuses.has(le.status)){se.add(fe.id);break}for(const le of t){const fe=ac[le.status];fe&&se.add(fe)}return co.filter(le=>se.has(le.id))},[e,t]),K=p.useCallback(se=>{z(le=>{const fe=new Set(le);return fe.has(se)?fe.delete(se):fe.add(se),fe})},[z]),O=p.useCallback((se,le="success")=>{y({msg:se,type:le}),setTimeout(()=>y(null),2500)},[]),Y=p.useMemo(()=>{const se=new Map;for(const le of n)se.set(le.id,le.name);return se},[n]),_=p.useMemo(()=>{const se=new Map;for(const le of e)se.set(le.id,le);return se},[e]),I=p.useMemo(()=>{const se=new Map;for(const le of t)se.set(le.id,le);return se},[t]),V=T&&yo(T)?T.slice(Ps.length):null,W=p.useMemo(()=>Kx(e,V?{requirementId:V,requirementTaskIds:I.get(V)?.taskIds??[]}:null),[e,V,I]),F=p.useRef(!1),Z=p.useCallback(()=>{F.current=!1,P(null),c?.()},[c]),te=w?"#94a3b8":"#6b7280",ce=p.useCallback((se,le,fe)=>({id:`${se}->${le}`,source:se,target:le,animated:fe==="blocked",markerEnd:{type:Ls.ArrowClosed,width:14,height:14,color:fe==="blocked"?"#ef4444":te},style:{stroke:fe==="blocked"?"#ef4444":te,strokeWidth:1.5,cursor:"pointer"}}),[te]),{initialNodes:oe,initialEdges:be}=p.useMemo(()=>{const se=(ke,pt)=>{const lt=new Set,It=ke.map(We=>(lt.add(We.id),{id:We.id,type:"task",data:{task:We,agentName:We.assignedAgentId?Y.get(We.assignedAgentId):void 0,selected:We.id===h},position:{x:0,y:0}}));for(const We of pt){const nt=`req-${We.id}`;lt.add(nt),It.push({id:nt,type:"requirement",data:{req:We,selected:We.id===u},position:{x:0,y:0}})}const Ot=[];for(const We of ke)if(We.blockedBy)for(const nt of We.blockedBy)lt.has(nt)&&Ot.push(ce(nt,We.id,We.status));const Wt=new Set,_t=(We,nt)=>{const Tt=`${We}->${nt}`;Wt.has(Tt)||(Wt.add(Tt),Ot.push({id:Tt,source:We,target:nt,markerEnd:{type:Ls.ArrowClosed,width:14,height:14,color:"#8b5cf6"},style:{stroke:"#8b5cf6",strokeWidth:1.5,strokeDasharray:"4 2"}}))};for(const We of pt){const nt=`req-${We.id}`;for(const Tt of We.taskIds)lt.has(Tt)&&_t(nt,Tt)}for(const We of ke)if(We.requirementId){const nt=`req-${We.requirementId}`;lt.has(nt)&&_t(nt,We.id)}return{nodes:It,edges:Ot}},le=e.filter(ke=>q.has(ke.status)&&($||!wo(ke))),fe=t.filter(ke=>{const pt=ac[ke.status];return pt&&D.has(pt)}),Q=new Set(fe.filter(ke=>!ad.has(ke.status)).map(ke=>ke.id)),ge=Wx(e,t,Q),Se=e.filter(ke=>ge.has(ke.id)&&($||!wo(ke))),tt=[...new Map([...le,...Se].map(ke=>[ke.id,ke])).values()],{nodes:Qe,edges:Je}=se(tt,fe),ye=(()=>{if(!T)return null;const{nodes:ke,edges:pt}=se(e,t);return ke.some(lt=>lt.id===T)?{allNodes:ke,allEdges:pt}:null})();if(!T||!ye){const ke=Qe,{nodes:pt,direction:lt}=lc(ke,Je);return{initialNodes:pt.map(Ot=>({...Ot,data:{...Ot.data,direction:lt}})),initialEdges:Je}}const{allNodes:He,allEdges:wt}=ye,X=Ux({focusedNodeId:T,requirementTaskIds:I.get(T.slice(Ps.length))?.taskIds??[],tasks:e,allowedStatuses:q,showArchived:$}),ie=He.filter(ke=>X.has(ke.id)).map(ke=>ke.id===T?{...ke,data:{...ke.data,focused:!0}}:ke),xe=wt.filter(ke=>X.has(ke.source)&&X.has(ke.target)),{nodes:je,direction:we}=lc(ie,xe);return{initialNodes:je.map(ke=>({...ke,data:{...ke.data,direction:we}})),initialEdges:xe}},[e,t,Y,I,ce,q,D,$,h,u,T]),[Ne,Ie,Ce]=Hg(oe),[Fe,Be,Re]=Vg(be),$e=p.useRef(null);p.useEffect(()=>{Ie(oe),Be(be),F.current||requestAnimationFrame(()=>{$e.current?.fitView({padding:.2,duration:300})})},[oe,be,Ie,Be]),p.useEffect(()=>{const se=setTimeout(()=>{$e.current?.fitView({padding:.2,duration:300})},50);return()=>clearTimeout(se)},[m]);const Et=p.useCallback(se=>{se&&(F.current=!0)},[]),qe=p.useCallback((se,le)=>{const fe=yo(le.id)?null:_.get(le.id),Q=fe?.requirementId&&I.has(fe.requirementId)?fe.requirementId:null,ge=Vx({nodeId:le.id,focusedNodeId:T,selectedEntityId:u??h??null,requirementIdOfTask:Q,profile:l?"mobile":"desktop"});switch(ge.type){case"exitFocus":Z();return;case"focusRequirement":{if(F.current=!1,P(ge.requirementNodeId),ge.select===null)return;if(ge.select.kind==="requirement"){const Se=I.get(ge.select.requirementId);Se&&i?.(Se)}else{const Se=_.get(ge.select.taskId);Se&&a?.(Se)}return}case"selectRequirement":{const Se=I.get(ge.requirementId);Se&&i?.(Se);return}case"selectTask":{const Se=_.get(ge.taskId);Se&&a?.(Se);return}}},[_,I,a,i,T,u,h,Z,l]),Ge=p.useCallback(async se=>{const{source:le,target:fe}=se;if(!le||!fe||le===fe)return;const Q=_.get(le),ge=_.get(fe);if(!Q||!ge)return;if(ge.blockedBy?.includes(le)){O(x("work:dag.toast.dependencyExists"),"error");return}if(s0(_,le,fe)){O(x("work:dag.toast.cycleError"),"error");return}const Se=[...ge.blockedBy??[],le];try{await ee.tasks.update(fe,{blockedBy:Se}),O(x("work:dag.toast.dependencyAdded")),d?.()}catch(tt){O(x("work:dag.toast.failed",{message:tt instanceof Error?tt.message:String(tt)}),"error")}},[_,O,d,x]),ft=p.useCallback((se,le)=>{k(le)},[]),mt=p.useCallback(async()=>{if(!b)return;const se=_.get(b.target);if(!se){k(null);return}const le=(se.blockedBy??[]).filter(fe=>fe!==b.source);try{await ee.tasks.update(b.target,{blockedBy:le}),O(x("work:dag.toast.dependencyRemoved")),d?.()}catch(fe){O(x("work:dag.toast.failed",{message:fe instanceof Error?fe.message:String(fe)}),"error")}k(null)},[b,_,O,d,x]),re=p.useRef(null),[ue,me]=p.useState(null);if(p.useEffect(()=>{let se=document;const le=()=>{const ge=re.current;if(!ge){me(null);return}let Se=ge.parentElement;for(;Se;){const xe=getComputedStyle(Se).overflowY;if((xe==="auto"||xe==="scroll")&&Se.clientHeight>0)break;Se=Se.parentElement}if(!document.documentElement.classList.contains("mobile-doc-scroll")&&!(Se!==null)){me(null);return}const Je=Se?Se.clientHeight:window.innerHeight,ye=Se?Se.getBoundingClientRect().top:0,He=Se?Se.scrollTop:window.scrollY,X=ge.getBoundingClientRect().top-ye+He,ie=Math.min(Je,window.innerHeight)-X-8;me(Math.max(320,Math.round(ie))),Se&&se!==Se&&(fe.disconnect(),fe.observe(Se),se=Se)},fe=new ResizeObserver(le);le(),fe.observe(document.documentElement),window.addEventListener("resize",le);const Q=new MutationObserver(le);return Q.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>{window.removeEventListener("resize",le),fe.disconnect(),Q.disconnect()}},[]),p.useEffect(()=>{if(ue===null)return;const se=requestAnimationFrame(()=>{$e.current?.fitView({padding:.2})});return()=>cancelAnimationFrame(se)},[ue]),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:x("work:task.dagEmptyTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:x("work:task.dagEmptyDesc")})]})});const Ee=D.size===E.size&&[...E].every(se=>D.has(se))&&!$,pe=b?_.get(b.source):null,Te=b?_.get(b.target):null;return r.jsxs("div",{ref:re,className:"doc-scroll-viewport flex-1 min-h-0 relative",style:{height:ue??"100%"},children:[r.jsxs(zg,{nodes:Ne,edges:Fe,onNodesChange:Ce,onEdgesChange:Re,onNodeClick:qe,onConnect:Ge,onEdgeClick:ft,onMoveEnd:Et,onInit:se=>{$e.current=se},nodeTypes:Zx,fitView:!0,minZoom:.08,maxZoom:2,proOptions:{hideAttribution:!0},connectionLineStyle:{stroke:"#818cf8",strokeWidth:2,strokeDasharray:"6 3"},children:[g&&r.jsx(Qx,{nodeIds:Ne.map(se=>se.id),rfRef:$e}),r.jsx(Gg,{color:w?"#cbd5e1":"#374151",gap:20,size:1}),r.jsx(nx,{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(px,{nodeColor:se=>{const le=se.data?.task,fe=le?.status;return le?.taskType==="scheduled"?"#8b8fa3":fe==="completed"||fe==="accepted"?"#10b981":fe==="in_progress"?"#f59e0b":fe==="blocked"||fe==="failed"?"#ef4444":w?"#94a3b8":"#6b7280"},maskColor:w?"rgba(255,255,255,0.7)":"rgba(0,0,0,0.7)",className:"!bg-surface-secondary !border-border-default"})]}),l&&T&&r.jsxs("button",{onClick:Z,className:"absolute top-3 left-3 z-30 flex items-center gap-2 rounded-xl border border-brand-400/60 bg-brand-600 px-3.5 py-2 shadow-xl shadow-brand-500/35 text-on-brand active:bg-brand-500",title:x("work:dag.showAll"),children:[r.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M3 9V5a2 2 0 0 1 2-2h4M21 9V5a2 2 0 0 0-2-2h-4M3 15v4a2 2 0 0 0 2 2h4M21 15v4a2 2 0 0 1-2 2h-4"})}),r.jsx("span",{className:"text-[12px] font-semibold tracking-wide",children:x("work:dag.showAll")})]}),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:[H.map(se=>{const le=D.has(se.id);return r.jsx("button",{onClick:()=>K(se.id),className:`text-[10px] px-1.5 py-0.5 rounded border transition-colors ${le?`${se.color.bg} ${se.color.border} ${se.color.text}`:"bg-surface-elevated/50 border-border-default/50 text-fg-tertiary"}`,children:x(`work:dag.filter.${se.id}`)},se.id)}),W>0&&r.jsx("button",{onClick:()=>R(se=>!se),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:x("work:dag.archivedToggle",{count:W})}),!Ee&&r.jsx("button",{onClick:()=>{z(new Set(E)),R(!1)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary px-1",children:x("work:dag.reset")})]}),r.jsxs("div",{className:"text-[10px] text-fg-tertiary select-none flex items-center gap-2",children:[!T&&r.jsxs(r.Fragment,{children:[r.jsx("span",{children:x("work:dag.expandHint")}),r.jsx("span",{className:"text-fg-tertiary/50",children:"·"})]}),r.jsx("span",{children:x("work:dag.dragHint")})]})]}),v&&r.jsx("div",{className:`absolute bottom-4 left-1/2 -translate-x-1/2 px-4 py-2 rounded-lg text-xs font-medium shadow-xl border backdrop-blur-sm transition-opacity ${v.type==="success"?"bg-green-500/15 border-green-500/30 text-green-600":"bg-red-500/15 border-red-500/30 text-red-600"}`,children:v.msg}),b&&r.jsx("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-50 backdrop-blur-[2px]",onClick:()=>k(null),children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 shadow-2xl max-w-sm",onClick:se=>se.stopPropagation(),children:[r.jsx("h4",{className:"text-sm font-semibold text-fg-primary mb-2",children:x("work:dag.removeDependencyTitle")}),r.jsx("p",{className:"text-xs text-fg-secondary mb-4 leading-relaxed",children:x("work:dag.removeDependencyBody",{target:Te?.title??b.target.slice(-8),source:pe?.title??b.source.slice(-8)})}),r.jsxs("div",{className:"flex justify-end gap-2",children:[r.jsx("button",{onClick:()=>k(null),className:"px-3 py-1.5 text-xs text-fg-secondary hover:text-fg-primary bg-surface-elevated rounded-lg border border-border-default hover:border-gray-600 transition-colors",children:x("common:cancel")}),r.jsx("button",{onClick:mt,className:"px-3 py-1.5 text-xs text-red-500 bg-red-600/20 hover:bg-red-600/30 rounded-lg border border-red-500/40 hover:border-red-500/60 transition-colors",children:x("common:remove")})]})]})})]})}const _a="grid grid-cols-[auto_1fr] gap-x-3 gap-y-3.5 items-start",vu="grid grid-cols-[auto_1fr] sm:grid-cols-[auto_1fr_auto_1fr] gap-x-5 gap-y-3 items-start",at="pt-2 text-sm text-fg-secondary whitespace-nowrap",vn="w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus:border-brand-500 outline-none",pa="shrink-0 whitespace-nowrap text-[11px] font-medium text-brand-500 hover:text-brand-400";function o0(e){return/^(https?:\/\/|git@|ssh:\/\/|git:\/\/)/i.test(e)}function cc({orgId:e,onCreated:t,onClose:n}){const{t:s}=ze(["work","common"]);Wf(!0);const[o,a]=p.useState(""),[i,l]=p.useState(""),[c,d]=p.useState(""),[h,u]=p.useState("main"),[m,f]=p.useState(!1),[g,x]=p.useState(""),[w,v]=p.useState(!1),y=wr();p.useEffect(()=>{const C=j=>{j.key==="Escape"&&n()};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[n]);const b=p.useCallback(async C=>{if(C?.preventDefault(),v(!0),!(!o.trim()||m)){f(!0),x("");try{const j=c.trim(),A=j?[{...o0(j)?{url:j}:{localPath:j},defaultBranch:h.trim()||"main",role:"primary"}]:[],S=await ee.projects.create({name:o.trim(),description:i.trim()||void 0,repositories:A.length>0?A:void 0,orgId:e??"default"});t(S.project)}catch(j){x(j instanceof Error?j.message:s("project.failedToCreate"))}f(!1)}},[o,i,c,h,e,m,t,s]),k=w&&!o.trim();return Kf.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:b,children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary",children:s("project.newProject")}),r.jsxs("div",{className:_a,children:[r.jsx("label",{className:at,children:s("project.projectName")}),r.jsxs("div",{children:[r.jsx("input",{value:o,onChange:C=>{a(C.target.value),x("")},onBlur:()=>v(!0),placeholder:s("project.projectNamePlaceholder"),className:`${vn} ${k?"!border-red-500":""}`,autoFocus:!y}),k&&r.jsx("p",{className:"text-[11px] text-red-400 mt-1",children:s("project.projectNameRequired")})]}),r.jsx("label",{className:at,children:s("project.description")}),r.jsx("textarea",{value:i,onChange:C=>l(C.target.value),placeholder:s("project.descriptionPlaceholder"),className:`${vn} resize-none`,rows:2}),r.jsx("label",{className:at,children:s("project.repositoryUrl")}),r.jsx("input",{value:c,onChange:C=>d(C.target.value),placeholder:s("project.repositoryPlaceholder"),className:`${vn} placeholder:text-[11px]`}),c.trim()&&r.jsxs(r.Fragment,{children:[r.jsx("label",{className:at,children:s("project.branch")}),r.jsx("input",{value:h,onChange:C=>u(C.target.value),placeholder:s("project.branchPlaceholder"),className:vn})]})]}),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()||m,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-on-brand",children:s(m?"common:creating":"project.createProject")})]})]})}),document.body)}const a0=["waiting_human","running","needs_evidence","in_verification","done","blocked_deps","failed"];function i0(e){return typeof e=="string"&&a0.includes(e)?e:void 0}const l0={waiting_human:"waitingHuman",running:"running",needs_evidence:"needsEvidence",in_verification:"inVerification",done:"done",blocked_deps:"blockedDeps",failed:"ended"},c0={waiting_human:"attention",running:"active",needs_evidence:"blocked",in_verification:"neutral",done:"success",blocked_deps:"neutral",failed:"danger"};function d0(e,t){if(e)return t(`common:threadStage.${l0[e]}`)}function u0(e){const t=e.indexOf(":"),n=t>0?e.slice(0,t):"",s=t>0?e.slice(t+1):e;switch(n){case"commit":return{kind:"commit",short:s.slice(0,8)};case"probe":return{kind:"probe",short:""};case"task":return{kind:"task",short:""};case"deliverable":return{kind:"deliverable",short:""};case"comment":return{kind:"comment",short:""};case"fact":return{kind:"record",short:s.replace(/^fact_/,"").slice(0,8)};case"transcript":return{kind:"transcript",short:""};default:return e.startsWith("dlv_")?{kind:"deliverable",short:""}:e.startsWith("cmt_")||e.startsWith("comment_")?{kind:"comment",short:""}:{kind:"other",short:e.length>18?`${e.slice(0,18)}…`:e}}}function f0(e){if(typeof e!="object"||e===null)return;const t=e.summary;return typeof t=="string"&&t.trim().length>0?t.trim():void 0}function h0({stage:e}){const{t}=ze(),n=i0(e??void 0);if(!n)return null;const s=d0(n,t);if(!s)return null;const o=kn[c0[n]];return r.jsx("span",{"data-thread-stage":n,className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle ${o.chip}`,children:s})}const m0=new Set(["task.completion_evidence","task.rejection_reason","requirement.acceptance_met","work.defect_class","agent.capability_claim","memory.consolidation_suggestion"]),p0=160;function g0(e){const t=new Date(e);if(Number.isNaN(t.getTime()))return e;const n=s=>String(s).padStart(2,"0");return`${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}function x0({item:e,nameOf:t,onOpenSource:n}){const{t:s}=ze(),[o,a]=p.useState(!1),i=f0(e.value),l=(i?.length??0)>p0,c=m0.has(e.predicate)?s(`common:threadStage.evidence.predicate.${e.predicate.replace(/\./g,"_")}`,{defaultValue:e.predicate}):e.predicate;return r.jsxs("div",{className:"border-t border-border-default/40 pt-2.5 first:border-t-0 first:pt-0",children:[r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsx("span",{className:"text-[11px] font-medium text-fg-secondary",children:c}),r.jsx("span",{className:`shrink-0 rounded-full px-1.5 py-0.5 text-[10px] ${e.verification?e.verification.result==="pass"?"bg-status-ok/10 text-status-ok":"bg-status-danger/10 text-status-danger":"bg-surface-secondary text-fg-tertiary"}`,children:e.verification?s(`common:threadStage.evidence.verification.${e.verification.result}`):s("common:threadStage.evidence.unverified")})]}),i?r.jsxs(r.Fragment,{children:[r.jsx("p",{className:`mt-1 whitespace-pre-wrap text-xs leading-relaxed text-fg-primary ${l&&!o?"line-clamp-4":""}`,children:i}),l&&r.jsx("button",{type:"button",onClick:()=>a(d=>!d),className:"mt-1 text-[10.5px] text-brand-500 transition-colors hover:underline",children:s(o?"common:threadStage.evidence.collapse":"common:threadStage.evidence.expand")})]}):r.jsx("p",{className:"mt-1 text-xs text-fg-tertiary",children:s("common:threadStage.evidence.predicateOnly")}),r.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5 text-[10px] text-fg-tertiary",children:[r.jsx("span",{children:s("common:threadStage.evidence.assertedBy",{who:t?.(e.assertedBy)??e.assertedBy})}),r.jsx("span",{"aria-hidden":!0,children:"·"}),r.jsx("span",{title:e.createdAt,children:g0(e.createdAt)}),e.verification?.verifiedBy&&r.jsxs(r.Fragment,{children:[r.jsx("span",{"aria-hidden":!0,children:"·"}),r.jsx("span",{children:s("common:threadStage.evidence.verifiedBy",{who:t?.(e.verification.verifiedBy)??e.verification.verifiedBy})})]}),e.sourceRefs.map(d=>{const h=u0(d),u=s(`common:threadStage.evidence.refKind.${h.kind}`);return r.jsx("button",{type:"button","data-source-ref":d,onClick:()=>n?.(d),title:d,className:"rounded bg-surface-secondary px-1.5 py-0.5 text-fg-secondary transition-colors hover:text-fg-primary",children:h.short?`${u} ${h.short}`:u},d)})]})]})}function b0({evidence:e,nameOf:t,onOpenSource:n}){const{t:s}=ze(),[o,a]=p.useState(!1),i=e.length;return r.jsxs("div",{className:"mt-3 rounded-lg border border-border-default/60 bg-surface-primary/40","data-evidence-fold":!0,children:[r.jsxs("button",{type:"button",onClick:()=>a(l=>!l),"aria-expanded":o,"data-evidence-toggle":!0,className:"w-full px-3 py-2 text-left transition-colors hover:bg-surface-secondary/40",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r.jsx("span",{className:"text-xs font-medium text-fg-primary",children:s("common:threadStage.evidence.title",{count:i})}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:o?"▾":"▸"})]}),r.jsx("p",{className:"mt-0.5 text-[10.5px] leading-relaxed text-fg-tertiary",children:s("common:threadStage.evidence.subtitle")})]}),o&&r.jsx("div",{className:"space-y-2.5 px-3 pb-3","data-evidence-body":!0,children:i===0?r.jsxs("div",{className:"rounded-md border border-dashed border-border-default px-3 py-2",children:[r.jsx("p",{className:"text-xs text-fg-secondary",children:s("common:threadStage.evidence.empty")}),r.jsx("p",{className:"mt-1 text-[10.5px] leading-relaxed text-fg-tertiary",children:s("common:threadStage.evidence.emptyHint")})]}):e.map(l=>r.jsx(x0,{item:l,nameOf:t,onOpenSource:n},l.factId))})]})}const Rn=e=>{if(!e)return;const t=new Date(e).getTime();return Number.isNaN(t)?void 0:t};function y0(e,t){const n=e.findIndex(l=>l.round===t);if(n<0)return{start:0,end:1/0};const s=n>0?e[n-1]:void 0,o=s?Rn(s.lastAt)??Rn(s.firstAt)??0:Rn(e[n].firstAt)??0,i=n===e.length-1?1/0:Rn(e[n].lastAt)??Rn(e[n].firstAt)??1/0;return{start:o,end:i}}function w0(e,t,n){const{start:s,end:o}=y0(t,n);return e.filter(a=>{const i=Rn(a.createdAt);return i===void 0?!1:i>=s&&i<o})}function k0(e,t){const n=t[0];if(!n)return[];const s=Rn(n.firstAt);return s===void 0?[]:e.filter(o=>{const a=Rn(o.createdAt);return a!==void 0&&a<s})}function v0({projects:e,selectedProjectId:t,allSelected:n,taskCounts:s,totalTaskCount:o,onSelectAll:a,onSelectProject:i,onEditProject:l,onCreateProject:c,onCollapse:d,width:h,onResizeStart:u,hidden:m,focused:f,onActivate:g}){const{t:x}=ze(["work","common"]),w=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:m?{display:"none"}:h!=null?{width:h}:void 0,children:[r.jsxs("div",{"data-electron-drag":!0,className:"px-3 h-14 flex items-center shrink-0 gap-2",children:[d&&r.jsx("button",{type:"button","data-no-drag":!0,onClick:d,className:"w-8 h-8 flex items-center justify-center rounded-lg transition-colors shrink-0 bg-brand-500/15 text-brand-500 hover:bg-brand-500/25",title:x("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:x("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:x("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:x("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:x("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 ${w?f?"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 ${w?"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:x("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 b=v.status==="archived"?1:0,k=y.status==="archived"?1:0;return b-k}).map(v=>{const y=!w&&v.id===t,b=s[v.id]??0,k=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?f?"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:x("work:project.statusArchived")}),k&&r.jsx("span",{className:"block text-[10px] text-amber-500/80",children:x("work:project.statusPaused")})]}),l&&r.jsx("button",{type:"button","data-no-drag":!0,title:x("work:project.editProject"),"aria-label":x("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"})})}),b>0&&r.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums shrink-0",children:b})]},v.id)})]})})]}),!m&&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 j0({project:e,onUpdateProject:t}){const{t:n}=ze(["work","common"]),s=e.knowledgeBasePaths??[],[o,a]=p.useState(""),[i,l]=p.useState(!1),[c,d]=p.useState(!0),[h,u]=p.useState([]),[m,f]=p.useState(null),[g,x]=p.useState(null),w=p.useCallback(async()=>{if(e.id){d(!0);try{const{results:S}=await ee.deliverables.search({projectId:e.id,source:"knowledge",limit:200});u(S)}catch(S){f({type:"error",text:`${n("work:project.kbLoadFailed")}: ${String(S)}`})}finally{d(!1)}}},[e.id,n]);p.useEffect(()=>{w()},[w]);const v=async()=>{const S=o.trim();if(!(!S||i))try{const T=[...new Set([...s,S])];await t({knowledgeBasePaths:T}),a(""),await C()}catch(T){f({type:"error",text:`${n("work:project.kbPathsSaveFailed")}: ${String(T)}`})}},y=async()=>{const S=g;if(!S||i)return;x(null);const T=s.filter(P=>P!==S);await t({knowledgeBasePaths:T}),await C(T)},b=typeof window<"u"&&!!window.markusDesktop?.selectDirectory,k=async()=>{try{const S=await window.markusDesktop?.selectDirectory?.(n("work:project.kbBrowseTitle"));S&&a(S)}catch(S){f({type:"error",text:`${n("work:project.kbBrowseFailed")}: ${String(S)}`})}},C=async S=>{if(!i){l(!0),f(null);try{const T=await ee.projects.syncKnowledge(e.id,S);f({type:T.errors.length>0?"error":"success",text:n("work:project.kbSyncResult",{scanned:T.scanned,registered:T.registered,updated:T.updated,outdated:T.outdated,errors:T.errors.length})}),await w()}catch(T){f({type:"error",text:`${n("work:project.kbSyncFailed")}: ${String(T)}`})}finally{l(!1)}}},j=async()=>{await C(s.length?s:void 0)},A=S=>{Gt.navigate(st.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:()=>A(),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:()=>x(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,T)=>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:()=>x(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}-${T}`)),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"}),b&&r.jsx("button",{type:"button",onClick:()=>{k()},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")})]})]}),m&&r.jsx("div",{className:`mb-2 px-2.5 py-1.5 text-[11px] rounded-md ${m.type==="success"?"bg-green-500/15 text-green-600":"bg-red-500/15 text-red-500"}`,children:m.text}),r.jsxs("div",{className:"border-t border-border-default/60 pt-3",children:[r.jsxs("h5",{className:"text-[11px] font-medium text-fg-tertiary mb-2",children:[n("work:project.kbDocsHeading"),h.length>0&&r.jsxs("span",{className:"ml-1 text-fg-muted",children:["(",h.length,")"]})]}),c?r.jsx(uh,{variant:"text",label:n("work:project.kbLoadingDocs"),className:"px-0"}):h.length===0?r.jsx("p",{className:"text-[11px] text-fg-tertiary",children:n("work:project.kbNoDocs")}):r.jsx("div",{className:"max-h-64 overflow-y-auto space-y-0.5",children:h.map(S=>r.jsxs("button",{type:"button",onClick:()=>A(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 N0=new Set(["rejected","cancelled","archived"]);function S0(e){return N0.has(e)}function C0(e,t){let s=t.showClosed||t.includeClosed===!0?e:e.filter(o=>!S0(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 si(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 ri=Symbol.for("yaml.alias"),La=Symbol.for("yaml.document"),$n=Symbol.for("yaml.map"),ju=Symbol.for("yaml.pair"),fn=Symbol.for("yaml.scalar"),Fs=Symbol.for("yaml.seq"),Zt=Symbol.for("yaml.node.type"),Hs=e=>!!e&&typeof e=="object"&&e[Zt]===ri,Sr=e=>!!e&&typeof e=="object"&&e[Zt]===La,Cr=e=>!!e&&typeof e=="object"&&e[Zt]===$n,yt=e=>!!e&&typeof e=="object"&&e[Zt]===ju,rt=e=>!!e&&typeof e=="object"&&e[Zt]===fn,Er=e=>!!e&&typeof e=="object"&&e[Zt]===Fs;function xt(e){if(e&&typeof e=="object")switch(e[Zt]){case $n:case Fs:return!0}return!1}function bt(e){if(e&&typeof e=="object")switch(e[Zt]){case ri:case $n:case fn:case Fs:return!0}return!1}const Nu=e=>(rt(e)||xt(e))&&!!e.anchor,Zn=Symbol("break visit"),E0=Symbol("skip children"),ir=Symbol("remove node");function Vs(e,t){const n=I0(t);Sr(e)?Cs(null,e.contents,n,Object.freeze([e]))===ir&&(e.contents=null):Cs(null,e,n,Object.freeze([]))}Vs.BREAK=Zn;Vs.SKIP=E0;Vs.REMOVE=ir;function Cs(e,t,n,s){const o=T0(e,t,n,s);if(bt(o)||yt(o))return M0(e,s,o),Cs(e,o,n,s);if(typeof o!="symbol"){if(xt(t)){s=Object.freeze(s.concat(t));for(let a=0;a<t.items.length;++a){const i=Cs(a,t.items[a],n,s);if(typeof i=="number")a=i-1;else{if(i===Zn)return Zn;i===ir&&(t.items.splice(a,1),a-=1)}}}else if(yt(t)){s=Object.freeze(s.concat(t));const a=Cs("key",t.key,n,s);if(a===Zn)return Zn;a===ir&&(t.key=null);const i=Cs("value",t.value,n,s);if(i===Zn)return Zn;i===ir&&(t.value=null)}}return o}function I0(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 T0(e,t,n,s){if(typeof n=="function")return n(e,t,s);if(Cr(t))return n.Map?.(e,t,s);if(Er(t))return n.Seq?.(e,t,s);if(yt(t))return n.Pair?.(e,t,s);if(rt(t))return n.Scalar?.(e,t,s);if(Hs(t))return n.Alias?.(e,t,s)}function M0(e,t,n){const s=t[t.length-1];if(xt(s))s.items[e]=n;else if(yt(s))e==="key"?s.key=n:s.value=n;else if(Sr(s))s.contents=n;else{const o=Hs(s)?"alias":"scalar";throw new Error(`Cannot replace node with ${o} parent`)}}const A0={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"},_0=e=>e.replace(/[!,[\]{}]/g,t=>A0[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+_0(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&&bt(t.contents)){const a={};Vs(t.contents,(i,l)=>{bt(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 Su(e){if(/[\x00-\x19\s,[\]{}]/.test(e)){const n=`Anchor must not contain whitespace or control characters: ${JSON.stringify(e)}`;throw new Error(n)}return!0}function Cu(e){const t=new Set;return Vs(e,{Value(n,s){s.anchor&&t.add(s.anchor)}}),t}function Eu(e,t){for(let n=1;;++n){const s=`${e}${n}`;if(!t.has(s))return s}}function L0(e,t){const n=[],s=new Map;let o=null;return{onAnchor:a=>{n.push(a),o??(o=Cu(e));const i=Eu(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)||xt(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 Es(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=Es(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=Es(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=Es(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=Es(e,s,o,a);i===void 0?delete s[o]:i!==a&&(s[o]=i)}return e.call(t,n,s)}function Xt(e,t,n){if(Array.isArray(e))return e.map((s,o)=>Xt(s,String(o),n));if(e&&typeof e.toJSON=="function"){if(!n||!Nu(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 oi{constructor(t){Object.defineProperty(this,Zt,{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(!Sr(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=Xt(this,"",i);if(typeof o=="function")for(const{count:c,res:d}of i.anchors.values())o(d,c);return typeof a=="function"?Es(a,{"":l},"",l):l}}class ai extends oi{constructor(t){super(ri),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=[],Vs(t,{Node:(a,i)=>{(Hs(i)||Nu(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||(Xt(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=uo(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(Su(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 uo(e,t,n){if(Hs(t)){const s=t.resolve(e),o=n&&s&&n.get(s);return o?o.count*o.aliasCount:0}else if(xt(t)){let s=0;for(const o of t.items){const a=uo(e,o,n);a>s&&(s=a)}return s}else if(yt(t)){const s=uo(e,t.key,n),o=uo(e,t.value,n);return Math.max(s,o)}return 1}const Iu=e=>!e||typeof e!="function"&&typeof e!="object";class Pe extends oi{constructor(t){super(fn),this.value=t}toJSON(t,n){return n?.keep?this.value:Xt(this.value,t,n)}toString(){return String(this.value)}}Pe.BLOCK_FOLDED="BLOCK_FOLDED";Pe.BLOCK_LITERAL="BLOCK_LITERAL";Pe.PLAIN="PLAIN";Pe.QUOTE_DOUBLE="QUOTE_DOUBLE";Pe.QUOTE_SINGLE="QUOTE_SINGLE";const R0="tag:yaml.org,2002:";function D0(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 br(e,t,n){if(Sr(e)&&(e=e.contents),bt(e))return e;if(yt(e)){const u=n.schema[$n].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 ai(c.anchor);c={anchor:null,node:null},l.set(e,c)}t?.startsWith("!!")&&(t=R0+t.slice(2));let d=D0(e,t,i.tags);if(!d){if(e&&typeof e.toJSON=="function"&&(e=e.toJSON()),!e||typeof e!="object"){const u=new Pe(e);return c&&(c.node=u),u}d=e instanceof Map?i[$n]:Symbol.iterator in Object(e)?i[Fs]:i[$n]}a&&(a(d),delete n.onTagObj);const h=d?.createNode?d.createNode(n.schema,e,n):typeof d?.nodeClass?.from=="function"?d.nodeClass.from(n.schema,e,n):new Pe(e);return t?h.tag=t:d.default||(h.tag=d.tag),c&&(c.node=h),h}function ko(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 br(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 rr=e=>e==null||typeof e=="object"&&!!e[Symbol.iterator]().next().done;class Tu extends oi{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=>bt(s)||yt(s)?s.clone(t):s),this.range&&(n.range=this.range.slice()),n}addIn(t,n){if(rr(t))this.add(n);else{const[s,...o]=t,a=this.get(s,!0);if(xt(a))a.addIn(o,n);else if(a===void 0&&this.schema)this.set(s,ko(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(xt(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:xt(a)?a.getIn(o,n):void 0}hasAllNullValues(t){return this.items.every(n=>{if(!yt(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 xt(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(xt(a))a.setIn(o,n);else if(a===void 0&&this.schema)this.set(s,ko(this.schema,o,n));else throw new Error(`Expected YAML collection at ${s}. Remaining path: ${o}`)}}}const O0=e=>e.replace(/^(?!$)(?: $)?/gm,"#");function jn(e,t){return/^\n+$/.test(e)?e.substring(1):t?e.replace(/^(?! *$)/gm,t):e}const Qn=(e,t,n)=>e.endsWith(`
9
+ `)?jn(n,t):n.includes(`
10
+ `)?`
11
+ `+jn(n,t):(e.endsWith(" ")?"":" ")+n,Mu="flow",Ra="block",fo="quoted";function Oo(e,t,n="flow",{indentAtStart:s,lineWidth:o=80,minContentWidth:a=20,onFold:i,onOverflow:l}={}){if(!o||o<0)return e;o<a&&(a=0);const c=Math.max(1+a,1+o-t.length);if(e.length<=c)return e;const d=[],h={};let u=o-t.length;typeof s=="number"&&(s>o-Math.max(2,a)?d.push(0):u=o-s);let m,f,g=!1,x=-1,w=-1,v=-1;n===Ra&&(x=dc(e,x,t.length),x!==-1&&(u=x+c));for(let b;b=e[x+=1];){if(n===fo&&b==="\\"){switch(w=x,e[x+1]){case"x":x+=3;break;case"u":x+=5;break;case"U":x+=9;break;default:x+=1}v=x}if(b===`
12
+ `)n===Ra&&(x=dc(e,x,t.length)),u=x+t.length+c,m=void 0;else{if(b===" "&&f&&f!==" "&&f!==`
13
+ `&&f!==" "){const k=e[x+1];k&&k!==" "&&k!==`
14
+ `&&k!==" "&&(m=x)}if(x>=u)if(m)d.push(m),u=m+c,m=void 0;else if(n===fo){for(;f===" "||f===" ";)f=b,b=e[x+=1],g=!0;const k=x>v+1?x-2:w-1;if(h[k])return e;d.push(k),h[k]=!0,u=k+c,m=void 0}else g=!0}f=b}if(g&&l&&l(),d.length===0)return e;i&&i();let y=e.slice(0,d[0]);for(let b=0;b<d.length;++b){const k=d[b],C=d[b+1]||e.length;k===0?y=`
15
+ ${t}${e.slice(0,C)}`:(n===fo&&h[k]&&(y+=`${e[k]}\\`),y+=`
16
+ ${t}${e.slice(k+1,C)}`)}return y}function dc(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}),Po=e=>/^(%|---|\.\.\.)/m.test(e);function $0(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 lr(e,t){const n=JSON.stringify(e);if(t.options.doubleQuotedAsJSON)return n;const{implicitKey:s}=t,o=t.options.doubleQuotedMinMultiLineLength,a=t.indent||(Po(e)?" ":"");let i="",l=0;for(let c=0,d=n[c];d;d=n[++c])if(d===" "&&n[c+1]==="\\"&&n[c+2]==="n"&&(i+=n.slice(l,c)+"\\ ",c+=1,l=c,d="\\"),d==="\\")switch(n[c+1]){case"u":{i+=n.slice(l,c);const h=n.substr(c+2,4);switch(h){case"0000":i+="\\0";break;case"0007":i+="\\a";break;case"000b":i+="\\v";break;case"001b":i+="\\e";break;case"0085":i+="\\N";break;case"00a0":i+="\\_";break;case"2028":i+="\\L";break;case"2029":i+="\\P";break;default:h.substr(0,2)==="00"?i+="\\x"+h.substr(2):i+=n.substr(c,6)}c+=5,l=c+1}break;case"n":if(s||n[c+2]==='"'||n.length<o)c+=1;else{for(i+=n.slice(l,c)+`
19
+
20
+ `;n[c+2]==="\\"&&n[c+3]==="n"&&n[c+4]!=='"';)i+=`
21
+ `,c+=2;i+=a,n[c+2]===" "&&(i+="\\"),c+=1,l=c+1}break;default:c+=1}return i=l?i+n.slice(l):n,s?i:Oo(i,a,fo,$o(t,!1))}function Da(e,t){if(t.options.singleQuote===!1||t.implicitKey&&e.includes(`
22
+ `)||/[ \t]\n|\n[ \t]/.test(e))return lr(e,t);const n=t.indent||(Po(e)?" ":""),s="'"+e.replace(/'/g,"''").replace(/\n+/g,`$&
23
+ ${n}`)+"'";return t.implicitKey?s:Oo(s,n,Mu,$o(t,!1))}function Is(e,t){const{singleQuote:n}=t.options;let s;if(n===!1)s=lr;else{const o=e.includes('"'),a=e.includes("'");o&&!a?s=Da:a&&!o?s=lr:s=n?Da:lr}return s(e,t)}let Oa;try{Oa=new RegExp(`(^|(?<!
24
+ ))
25
+ +(?!
26
+ |$)`,"g")}catch{Oa=/\n+(?!\n|$)/g}function ho({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 Is(n,s);const d=s.indent||(s.forceBlockIndent||Po(n)?" ":""),h=i==="literal"?!0:i==="folded"||t===Pe.BLOCK_FOLDED?!1:t===Pe.BLOCK_LITERAL?!0:!$0(n,c,d.length);if(!n)return h?`|
27
+ `:`>
28
+ `;let u,m;for(m=n.length;m>0;--m){const C=n[m-1];if(C!==`
29
+ `&&C!==" "&&C!==" ")break}let f=n.substring(m);const g=f.indexOf(`
30
+ `);g===-1?u="-":n===f||g!==f.length-1?(u="+",a&&a()):u="",f&&(n=n.slice(0,-f.length),f[f.length-1]===`
31
+ `&&(f=f.slice(0,-1)),f=f.replace(Oa,`$&${d}`));let x=!1,w,v=-1;for(w=0;w<n.length;++w){const C=n[w];if(C===" ")x=!0;else if(C===`
32
+ `)v=w;else break}let y=n.substring(0,v<w?v+1:w);y&&(n=n.substring(y.length),y=y.replace(/\n+/g,`$&${d}`));let k=(x?d?"2":"1":"")+u;if(e&&(k+=" "+l(e.replace(/ ?[\r\n]+/g," ")),o&&o()),!h){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 A=$o(s,!0);i!=="folded"&&t!==Pe.BLOCK_FOLDED&&(A.onOverflow=()=>{j=!0});const S=Oo(`${y}${C}${f}`,d,Ra,A);if(!j)return`>${k}
34
+ ${d}${S}`}return n=n.replace(/\n+/g,`$&${d}`),`|${k}
35
+ ${d}${y}${n}${f}`}function P0(e,t,n,s){const{type:o,value:a}=e,{actualString:i,implicitKey:l,indent:c,indentStep:d,inFlow:h}=t;if(l&&a.includes(`
36
+ `)||h&&/[[\]{},]/.test(a))return Is(a,t);if(/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(a))return l||h||!a.includes(`
37
+ `)?Is(a,t):ho(e,t,n,s);if(!l&&!h&&o!==Pe.PLAIN&&a.includes(`
38
+ `))return ho(e,t,n,s);if(Po(a)){if(c==="")return t.forceBlockIndent=!0,ho(e,t,n,s);if(l&&c===d)return Is(a,t)}const u=a.replace(/\n+/g,`$&
39
+ ${c}`);if(i){const m=x=>x.default&&x.tag!=="tag:yaml.org,2002:str"&&x.test?.test(u),{compat:f,tags:g}=t.doc.schema;if(g.some(m)||f?.some(m))return Is(a,t)}return l?u:Oo(u,c,Mu,$o(t,!1))}function ii(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!==Pe.QUOTE_DOUBLE&&/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(i.value)&&(l=Pe.QUOTE_DOUBLE);const c=h=>{switch(h){case Pe.BLOCK_FOLDED:case Pe.BLOCK_LITERAL:return o||a?Is(i.value,t):ho(i,t,n,s);case Pe.QUOTE_DOUBLE:return lr(i.value,t);case Pe.QUOTE_SINGLE:return Da(i.value,t);case Pe.PLAIN:return P0(i,t,n,s);default:return null}};let d=c(l);if(d===null){const{defaultKeyType:h,defaultStringType:u}=t.options,m=o&&h||u;if(d=c(m),d===null)throw new Error(`Unsupported default string type ${m}`)}return d}function Au(e,t){const n=Object.assign({blockQuote:!0,commentString:O0,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 B0(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 q0(e,t,{anchors:n,doc:s}){if(!s.directives)return"";const o=[],a=(rt(e)||xt(e))&&e.anchor;a&&Su(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 Bs(e,t,n,s){if(yt(e))return e.toString(t,n,s);if(Hs(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=bt(e)?e:t.doc.createNode(e,{onTagObj:c=>o=c});o??(o=B0(t.doc.schema.tags,a));const i=q0(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)?ii(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 z0({key:e,value:t},n,s,o){const{allNullValues:a,doc:i,indent:l,indentStep:c,options:{commentString:d,indentSeq:h,simpleKeys:u}}=n;let m=bt(e)&&e.comment||null;if(u){if(m)throw new Error("With simple keys, key nodes cannot have comments");if(xt(e)||!bt(e)&&typeof e=="object"){const A="With simple keys, collection cannot be used as a key value";throw new Error(A)}}let f=!u&&(!e||m&&t==null&&!n.inFlow||xt(e)||(rt(e)?e.type===Pe.BLOCK_FOLDED||e.type===Pe.BLOCK_LITERAL:typeof e=="object"));n=Object.assign({},n,{allNullValues:!1,implicitKey:!f&&(u||!a),indent:l+c});let g=!1,x=!1,w=Bs(e,n,()=>g=!0,()=>x=!0);if(!f&&!n.inFlow&&w.length>1024){if(u)throw new Error("With simple keys, single line scalar must not span more than 1024 characters");f=!0}if(n.inFlow){if(a||t==null)return g&&s&&s(),w===""?"?":f?`? ${w}`:w}else if(a&&!u||t==null&&f)return w=`? ${w}`,m&&!g?w+=Qn(w,n.indent,d(m)):x&&o&&o(),w;g&&(m=null),f?(m&&(w+=Qn(w,n.indent,d(m))),w=`? ${w}
41
+ ${l}:`):(w=`${w}:`,m&&(w+=Qn(w,n.indent,d(m))));let v,y,b;bt(t)?(v=!!t.spaceBefore,y=t.commentBefore,b=t.comment):(v=!1,y=null,b=null,t&&typeof t=="object"&&(t=i.createNode(t))),n.implicitKey=!1,!f&&!m&&rt(t)&&(n.indentAtStart=w.length+1),x=!1,!h&&c.length>=2&&!n.inFlow&&!f&&Er(t)&&!t.flow&&!t.tag&&!t.anchor&&(n.indent=n.indent.substring(2));let k=!1;const C=Bs(t,n,()=>k=!0,()=>x=!0);let j=" ";if(m||v||y){if(j=v?`
42
+ `:"",y){const A=d(y);j+=`
43
+ ${jn(A,n.indent)}`}C===""&&!n.inFlow?j===`
44
+ `&&b&&(j=`
45
+
46
+ `):j+=`
47
+ ${n.indent}`}else if(!f&&xt(t)){const A=C[0],S=C.indexOf(`
48
+ `),T=S!==-1,P=n.inFlow??t.flow??t.items.length===0;if(T||!P){let M=!1;if(T&&(A==="&"||A==="!")){let D=C.indexOf(" ");A==="&"&&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 w+=j+C,n.inFlow?k&&s&&s():b&&!k?w+=Qn(w,n.indent,d(b)):x&&o&&o(),w}function _u(e,t){(e==="debug"||e==="warn")&&console.warn(t)}const Zr="<<",Nn={identify:e=>e===Zr||typeof e=="symbol"&&e.description===Zr,default:"key",tag:"tag:yaml.org,2002:merge",test:/^<<$/,resolve:()=>Object.assign(new Pe(Symbol(Zr)),{addToJSMap:Lu}),stringify:()=>Zr},F0=(e,t)=>(Nn.identify(t)||rt(t)&&(!t.type||t.type===Pe.PLAIN)&&Nn.identify(t.value))&&e?.doc.schema.tags.some(n=>n.tag===Nn.tag&&n.default);function Lu(e,t,n){const s=Ru(e,n);if(Er(s))for(const o of s.items)ga(e,t,o);else if(Array.isArray(s))for(const o of s)ga(e,t,o);else ga(e,t,s)}function ga(e,t,n){const s=Ru(e,n);if(!Cr(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 Ru(e,t){return e&&Hs(t)?t.resolve(e.doc,e):t}function Du(e,t,{key:n,value:s}){if(bt(n)&&n.addToJSMap)n.addToJSMap(e,t,s);else if(F0(e,n))Lu(e,t,s);else{const o=Xt(n,"",e);if(t instanceof Map)t.set(o,Xt(s,o,e));else if(t instanceof Set)t.add(o);else{const a=H0(n,o,e),i=Xt(s,a,e);a in t?Object.defineProperty(t,a,{value:i,writable:!0,enumerable:!0,configurable:!0}):t[a]=i}}return t}function H0(e,t,n){if(t===null)return"";if(typeof t!="object")return String(t);if(bt(e)&&n?.doc){const s=Au(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)+'..."'),_u(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 li(e,t,n){const s=br(e,void 0,n),o=br(t,void 0,n);return new Dt(s,o)}class Dt{constructor(t,n=null){Object.defineProperty(this,Zt,{value:ju}),this.key=t,this.value=n}clone(t){let{key:n,value:s}=this;return bt(n)&&(n=n.clone(t)),bt(s)&&(s=s.clone(t)),new Dt(n,s)}toJSON(t,n){const s=n?.mapAsMap?new Map:{};return Du(n,s,this)}toString(t,n,s){return t?.doc?z0(this,t,n,s):JSON.stringify(this)}}function Ou(e,t,n){return(t.inFlow??e.flow?W0:V0)(e,t,n)}function V0({comment:e,items:t},n,{blockItemPrefix:s,flowChars:o,itemIndent:a,onChompKeep:i,onComment:l}){const{indent:c,options:{commentString:d}}=n,h=Object.assign({},n,{indent:a,type:null});let u=!1;const m=[];for(let g=0;g<t.length;++g){const x=t[g];let w=null;if(bt(x))!u&&x.spaceBefore&&m.push(""),vo(n,m,x.commentBefore,u),x.comment&&(w=x.comment);else if(yt(x)){const y=bt(x.key)?x.key:null;y&&(!u&&y.spaceBefore&&m.push(""),vo(n,m,y.commentBefore,u))}u=!1;let v=Bs(x,h,()=>w=null,()=>u=!0);w&&(v+=Qn(v,a,d(w))),u&&w&&(u=!1),m.push(s+v)}let f;if(m.length===0)f=o.start+o.end;else{f=m[0];for(let g=1;g<m.length;++g){const x=m[g];f+=x?`
51
+ ${c}${x}`:`
52
+ `}}return e?(f+=`
53
+ `+jn(d(e),c),l&&l()):u&&i&&i(),f}function W0({items:e},t,{flowChars:n,itemIndent:s}){const{indent:o,indentStep:a,flowCollectionPadding:i,options:{commentString:l}}=t;s+=a;const c=Object.assign({},t,{indent:s,inFlow:!0,type:null});let d=!1,h=0;const u=[];for(let g=0;g<e.length;++g){const x=e[g];let w=null;if(bt(x))x.spaceBefore&&u.push(""),vo(t,u,x.commentBefore,!1),x.comment&&(w=x.comment);else if(yt(x)){const y=bt(x.key)?x.key:null;y&&(y.spaceBefore&&u.push(""),vo(t,u,y.commentBefore,!1),y.comment&&(d=!0));const b=bt(x.value)?x.value:null;b?(b.comment&&(w=b.comment),b.commentBefore&&(d=!0)):x.value==null&&y?.comment&&(w=y.comment)}w&&(d=!0);let v=Bs(x,c,()=>w=null);d||(d=u.length>h||v.includes(`
54
+ `)),g<e.length-1?v+=",":t.options.trailingComma&&(t.options.lineWidth>0&&(d||(d=u.reduce((y,b)=>y+b.length+2,2)+(v.length+2)>t.options.lineWidth)),d&&(v+=",")),w&&(v+=Qn(v,s,l(w))),u.push(v),h=u.length}const{start:m,end:f}=n;if(u.length===0)return m+f;if(!d){const g=u.reduce((x,w)=>x+w.length+2,2);d=t.options.lineWidth>0&&g>t.options.lineWidth}if(d){let g=m;for(const x of u)g+=x?`
55
+ ${a}${o}${x}`:`
56
+ `;return`${g}
57
+ ${o}${f}`}else return`${m}${i}${u.join(" ")}${i}${f}`}function vo({indent:e,options:{commentString:t}},n,s,o){if(s&&o&&(s=s.replace(/^\n+/,"")),s){const a=jn(t(s),e);n.push(a.trimStart())}}function Jn(e,t){const n=rt(t)?t.value:t;for(const s of e)if(yt(s)&&(s.key===t||s.key===n||rt(s.key)&&s.key.value===n))return s}class Yt extends Tu{static get tagName(){return"tag:yaml.org,2002:map"}constructor(t){super($n,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(li(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;yt(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=Jn(this.items,s.key),a=this.schema?.sortMapEntries;if(o){if(!n)throw new Error(`Key ${s.key} already set`);rt(o.value)&&Iu(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=Jn(this.items,t);return n?this.items.splice(this.items.indexOf(n),1).length>0:!1}get(t,n){const o=Jn(this.items,t)?.value;return(!n&&rt(o)?o.value:o)??void 0}has(t){return!!Jn(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)Du(n,o,a);return o}toString(t,n,s){if(!t)return JSON.stringify(this);for(const o of this.items)if(!yt(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})),Ou(this,t,{blockItemPrefix:"",flowChars:{start:"{",end:"}"},itemIndent:t.indent||"",onChompKeep:s,onComment:n})}}const Ws={collection:"map",default:!0,nodeClass:Yt,tag:"tag:yaml.org,2002:map",resolve(e,t){return Cr(e)||t("Expected a mapping for this tag"),e},createNode:(e,t,n)=>Yt.from(e,t,n)};class os extends Tu{static get tagName(){return"tag:yaml.org,2002:seq"}constructor(t){super(Fs,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)&&Iu(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(Xt(a,String(o++),n));return s}toString(t,n,s){return t?Ou(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(br(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 Ks={collection:"seq",default:!0,nodeClass:os,tag:"tag:yaml.org,2002:seq",resolve(e,t){return Er(e)||t("Expected a sequence for this tag"),e},createNode:(e,t,n)=>os.from(e,t,n)},Bo={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),ii(e,t,n,s)}},qo={identify:e=>e==null,createNode:()=>new Pe(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^(?:~|[Nn]ull|NULL)?$/,resolve:()=>new Pe(null),stringify:({source:e},t)=>typeof e=="string"&&qo.test.test(e)?e:t.options.nullStr},ci={identify:e=>typeof e=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,resolve:e=>new Pe(e[0]==="t"||e[0]==="T"),stringify({source:e,value:t},n){if(e&&ci.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 on({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 $u={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:on},Pu={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():on(e)}},Bu={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 Pe(parseFloat(e)),n=e.indexOf(".");return n!==-1&&e[e.length-1]==="0"&&(t.minFractionDigits=e.length-n-1),t},stringify:on},zo=e=>typeof e=="bigint"||Number.isInteger(e),di=(e,t,n,{intAsBigInt:s})=>s?BigInt(e):parseInt(e.substring(t),n);function qu(e,t,n){const{value:s}=e;return zo(s)&&s>=0?n+s.toString(t):on(e)}const zu={identify:e=>zo(e)&&e>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^0o[0-7]+$/,resolve:(e,t,n)=>di(e,2,8,n),stringify:e=>qu(e,8,"0o")},Fu={identify:zo,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9]+$/,resolve:(e,t,n)=>di(e,0,10,n),stringify:on},Hu={identify:e=>zo(e)&&e>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^0x[0-9a-fA-F]+$/,resolve:(e,t,n)=>di(e,2,16,n),stringify:e=>qu(e,16,"0x")},K0=[Ws,Ks,Bo,qo,ci,zu,Fu,Hu,$u,Pu,Bu];function uc(e){return typeof e=="bigint"||Number.isInteger(e)}const Jr=({value:e})=>JSON.stringify(e),U0=[{identify:e=>typeof e=="string",default:!0,tag:"tag:yaml.org,2002:str",resolve:e=>e,stringify:Jr},{identify:e=>e==null,createNode:()=>new Pe(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:uc,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})=>uc(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}},G0=[Ws,Ks].concat(U0,Y0),ui={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=Pe.BLOCK_LITERAL),t!==Pe.QUOTE_DOUBLE){const c=Math.max(s.options.lineWidth-s.indent.length,s.options.minContentWidth),d=Math.ceil(l.length/c),h=new Array(d);for(let u=0,m=0;u<d;++u,m+=c)h[u]=l.substr(m,c);l=h.join(t===Pe.BLOCK_LITERAL?`
58
+ `:" ")}return ii({comment:e,type:t,value:l},s,o,a)}};function Vu(e,t){if(Er(e))for(let n=0;n<e.items.length;++n){let s=e.items[n];if(!yt(s)){if(Cr(s)){s.items.length>1&&t("Each pair must have its own sequence indicator");const o=s.items[0]||new Dt(new Pe(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]=yt(s)?s:new Dt(s)}}else t("Expected a sequence for this tag");return e}function Wu(e,t,n){const{replacer:s}=n,o=new os(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(li(l,c,n))}return o}const fi={collection:"seq",default:!1,tag:"tag:yaml.org,2002:pairs",resolve:Vu,createNode:Wu};class Ms extends os{constructor(){super(),this.add=Yt.prototype.add.bind(this),this.delete=Yt.prototype.delete.bind(this),this.get=Yt.prototype.get.bind(this),this.has=Yt.prototype.has.bind(this),this.set=Yt.prototype.set.bind(this),this.tag=Ms.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(yt(o)?(a=Xt(o.key,"",n),i=Xt(o.value,a,n)):a=Xt(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=Wu(t,n,s),a=new this;return a.items=o.items,a}}Ms.tag="tag:yaml.org,2002:omap";const hi={collection:"seq",identify:e=>e instanceof Map,nodeClass:Ms,default:!1,tag:"tag:yaml.org,2002:omap",resolve(e,t){const n=Vu(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 Ms,n)},createNode:(e,t,n)=>Ms.from(e,t,n)};function Ku({value:e,source:t},n){return t&&(e?Uu:Yu).test.test(t)?t:e?n.options.trueStr:n.options.falseStr}const Uu={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 Pe(!0),stringify:Ku},Yu={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 Pe(!1),stringify:Ku},X0={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:on},Z0={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():on(e)}},Q0={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 Pe(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:on},Ir=e=>typeof e=="bigint"||Number.isInteger(e);function Fo(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 mi(e,t,n){const{value:s}=e;if(Ir(s)){const o=s.toString(t);return s<0?"-"+n+o.substr(1):n+o}return on(e)}const J0={identify:Ir,default:!0,tag:"tag:yaml.org,2002:int",format:"BIN",test:/^[-+]?0b[0-1_]+$/,resolve:(e,t,n)=>Fo(e,2,2,n),stringify:e=>mi(e,2,"0b")},eb={identify:Ir,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^[-+]?0[0-7_]+$/,resolve:(e,t,n)=>Fo(e,1,8,n),stringify:e=>mi(e,8,"0")},tb={identify:Ir,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9][0-9_]*$/,resolve:(e,t,n)=>Fo(e,0,10,n),stringify:on},nb={identify:Ir,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^[-+]?0x[0-9a-fA-F_]+$/,resolve:(e,t,n)=>Fo(e,2,16,n),stringify:e=>mi(e,16,"0x")};class As extends Yt{constructor(t){super(t),this.tag=As.tag}add(t){let n;yt(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),Jn(this.items,n.key)||this.items.push(n)}get(t,n){const s=Jn(this.items,t);return!n&&yt(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=Jn(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(li(i,null,s));return a}}As.tag="tag:yaml.org,2002:set";const pi={collection:"map",identify:e=>e instanceof Set,nodeClass:As,default:!1,tag:"tag:yaml.org,2002:set",createNode:(e,t,n)=>As.from(e,t,n),resolve(e,t){if(Cr(e)){if(e.hasAllNullValues(!0))return Object.assign(new As,e);t("Set items must all have null values")}else t("Expected a mapping for this tag");return e}};function gi(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 Gu(e){let{value:t}=e,n=i=>i;if(typeof t=="bigint")n=i=>BigInt(i);else if(isNaN(t)||!isFinite(t))return on(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 Xu={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})=>gi(e,n),stringify:Gu},Zu={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=>gi(e,!1),stringify:Gu},Ho={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(Ho.test);if(!t)throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");const[,n,s,o,a,i,l]=t.map(Number),c=t[7]?Number((t[7]+"00").substr(1,3)):0;let d=Date.UTC(n,s-1,o,a||0,i||0,l||0,c);const h=t[8];if(h&&h!=="Z"){let u=gi(h,!1);Math.abs(u)<30&&(u*=60),d-=6e4*u}return new Date(d)},stringify:({value:e})=>e?.toISOString().replace(/(T00:00:00)?\.000Z$/,"")??""},fc=[Ws,Ks,Bo,qo,Uu,Yu,J0,eb,tb,nb,X0,Z0,Q0,ui,Nn,hi,fi,pi,Xu,Zu,Ho],hc=new Map([["core",K0],["failsafe",[Ws,Ks,Bo]],["json",G0],["yaml11",fc],["yaml-1.1",fc]]),mc={binary:ui,bool:ci,float:Bu,floatExp:Pu,floatNaN:$u,floatTime:Zu,int:Fu,intHex:Hu,intOct:zu,intTime:Xu,map:Ws,merge:Nn,null:qo,omap:hi,pairs:fi,seq:Ks,set:pi,timestamp:Ho},sb={"tag:yaml.org,2002:binary":ui,"tag:yaml.org,2002:merge":Nn,"tag:yaml.org,2002:omap":hi,"tag:yaml.org,2002:pairs":fi,"tag:yaml.org,2002:set":pi,"tag:yaml.org,2002:timestamp":Ho};function xa(e,t,n){const s=hc.get(t);if(s&&!e)return n&&!s.includes(Nn)?s.concat(Nn):s.slice();let o=s;if(!o)if(Array.isArray(e))o=[];else{const a=Array.from(hc.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(Nn)),o.reduce((a,i)=>{const l=typeof i=="string"?mc[i]:i;if(!l){const c=JSON.stringify(i),d=Object.keys(mc).map(h=>JSON.stringify(h)).join(", ");throw new Error(`Unknown custom tag ${c}; use one of ${d}`)}return a.includes(l)||a.push(l),a},[])}const rb=(e,t)=>e.key<t.key?-1:e.key>t.key?1:0;class xi{constructor({compat:t,customTags:n,merge:s,resolveKnownTags:o,schema:a,sortMapEntries:i,toStringDefaults:l}){this.compat=Array.isArray(t)?xa(t,"compat"):t?xa(null,t):null,this.name=typeof a=="string"&&a||"core",this.knownTags=o?sb:{},this.tags=xa(n,this.name,s),this.toStringOptions=l??null,Object.defineProperty(this,$n,{value:Ws}),Object.defineProperty(this,fn,{value:Bo}),Object.defineProperty(this,Fs,{value:Ks}),this.sortMapEntries=typeof i=="function"?i:i===!0?rb:null}clone(){const t=Object.create(xi.prototype,Object.getOwnPropertyDescriptors(this));return t.tags=this.tags.slice(),t}}function ob(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=Au(e,t),{commentString:a}=o.options;if(e.commentBefore){n.length!==1&&n.unshift("");const c=a(e.commentBefore);n.unshift(jn(c,""))}let i=!1,l=null;if(e.contents){if(bt(e.contents)){if(e.contents.spaceBefore&&s&&n.push(""),e.contents.commentBefore){const h=a(e.contents.commentBefore);n.push(jn(h,""))}o.forceBlockIndent=!!e.comment,l=e.contents.comment}const c=l?void 0:()=>i=!0;let d=Bs(e.contents,o,()=>l=null,c);l&&(d+=Qn(d,"",a(l))),(d[0]==="|"||d[0]===">")&&n[n.length-1]==="---"?n[n.length-1]=`--- ${d}`:n.push(d)}else n.push(Bs(e.contents,o));if(e.directives?.docEnd)if(e.comment){const c=a(e.comment);c.includes(`
61
+ `)?(n.push("..."),n.push(jn(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(jn(a(c),"")))}return n.join(`
62
+ `)+`
63
+ `}class Tr{constructor(t,n,s){this.commentBefore=null,this.comment=null,this.errors=[],this.warnings=[],Object.defineProperty(this,Zt,{value:La});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(Tr.prototype,{[Zt]:{value:La}});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=bt(this.contents)?this.contents.clone(t.schema):this.contents,this.range&&(t.range=this.range.slice()),t}add(t){ks(this.contents)&&this.contents.add(t)}addIn(t,n){ks(this.contents)&&this.contents.addIn(t,n)}createAlias(t,n){if(!t.anchor){const s=Cu(this);t.anchor=!n||s.has(n)?Eu(n||"a",s):n}return new ai(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 w=y=>typeof y=="number"||y instanceof String||y instanceof Number,v=n.filter(w).map(String);v.length>0&&(n=n.concat(v)),o=n}else s===void 0&&n&&(s=n,n=void 0);const{aliasDuplicateObjects:a,anchorPrefix:i,flow:l,keepUndefined:c,onTagObj:d,tag:h}=s??{},{onAnchor:u,setAnchors:m,sourceObjects:f}=L0(this,i||"a"),g={aliasDuplicateObjects:a??!0,keepUndefined:c??!1,onAnchor:u,onTagObj:d,replacer:o,schema:this.schema,sourceObjects:f},x=br(t,h,g);return l&&xt(x)&&(x.flow=!0),m(),x}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 ks(this.contents)?this.contents.delete(t):!1}deleteIn(t){return rr(t)?this.contents==null?!1:(this.contents=null,!0):ks(this.contents)?this.contents.deleteIn(t):!1}get(t,n){return xt(this.contents)?this.contents.get(t,n):void 0}getIn(t,n){return rr(t)?!n&&rt(this.contents)?this.contents.value:this.contents:xt(this.contents)?this.contents.getIn(t,n):void 0}has(t){return xt(this.contents)?this.contents.has(t):!1}hasIn(t){return rr(t)?this.contents!==void 0:xt(this.contents)?this.contents.hasIn(t):!1}set(t,n){this.contents==null?this.contents=ko(this.schema,[t],n):ks(this.contents)&&this.contents.set(t,n)}setIn(t,n){rr(t)?this.contents=n:this.contents==null?this.contents=ko(this.schema,Array.from(t),n):ks(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 xi(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=Xt(this.contents,n??"",l);if(typeof a=="function")for(const{count:d,res:h}of l.anchors.values())a(h,d);return typeof i=="function"?Es(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 ob(this,t)}}function ks(e){if(xt(e))return!0;throw new Error("Expected a YAML collection as document contents")}class Qu extends Error{constructor(t,n,s,o){super(),this.name=t,this.code=s,this.message=o,this.pos=n}}class or extends Qu{constructor(t,n,s){super("YAMLParseError",t,n,s)}}class ab extends Qu{constructor(t,n,s){super("YAMLWarning",t,n,s)}}const pc=(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 qs(e,{flow:t,indicator:n,next:s,offset:o,onError:a,parentIndent:i,startOnNewline:l}){let c=!1,d=l,h=l,u="",m="",f=!1,g=!1,x=null,w=null,v=null,y=null,b=null,k=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),x&&(d&&S.type!=="comment"&&S.type!=="newline"&&a(x,"TAB_AS_INDENT","Tabs are not allowed as indentation"),x=null),S.type){case"space":!t&&(n!=="doc-start"||s?.type!=="flow-collection")&&S.source.includes(" ")&&(x=S),h=!0;break;case"comment":{h||a(S,"MISSING_CHAR","Comments must be separated from other tokens by white space characters");const T=S.source.substring(1)||" ";u?u+=m+T:u=T,m="",d=!1;break}case"newline":d?u?u+=S.source:(!k||n!=="seq-item-ind")&&(c=!0):m+=S.source,d=!0,f=!0,(w||v)&&(y=S),h=!0;break;case"anchor":w&&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),w=S,C??(C=S.offset),d=!1,h=!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,h=!1,g=!0;break}case n:(w||v)&&a(S,"BAD_PROP_ORDER",`Anchors and tags must be after the ${S.source} indicator`),k&&a(S,"UNEXPECTED_TOKEN",`Unexpected ${S.source} in ${t??"collection"}`),k=S,d=n==="seq-item-ind"||n==="explicit-key-ind",h=!1;break;case"comma":if(t){b&&a(S,"UNEXPECTED_TOKEN",`Unexpected , in ${t}`),b=S,d=!1,h=!1;break}default:a(S,"UNEXPECTED_TOKEN",`Unexpected ${S.type} token`),d=!1,h=!1}const j=e[e.length-1],A=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"),x&&(d&&x.indent<=i||s?.type==="block-map"||s?.type==="block-seq")&&a(x,"TAB_AS_INDENT","Tabs are not allowed as indentation"),{comma:b,found:k,spaceBefore:c,comment:u,hasNewline:f,anchor:w,tag:v,newlineAfterProp:y,end:A,start:C??A}}function yr(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(yr(t.key)||yr(t.value))return!0}return!1;default:return!0}}function $a(e,t,n){if(t?.type==="flow-collection"){const s=t.end[0];s.indent===e&&(s.source==="]"||s.source==="}")&&yr(t)&&n(s,"BAD_INDENT","Flow end indicator should be more indented than parent",!0)}}function Ju(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 gc="All mapping items must start at the same column";function ib({composeNode:e,composeEmptyNode:t},n,s,o,a){const i=a?.nodeClass??Yt,l=new i(n.schema);n.atRoot&&(n.atRoot=!1);let c=s.offset,d=null;for(const h of s.items){const{start:u,key:m,sep:f,value:g}=h,x=qs(u,{indicator:"explicit-key-ind",next:m??f?.[0],offset:c,onError:o,parentIndent:s.indent,startOnNewline:!0}),w=!x.found;if(w){if(m&&(m.type==="block-seq"?o(c,"BLOCK_AS_IMPLICIT_KEY","A block sequence may not be used as an implicit map key"):"indent"in m&&m.indent!==s.indent&&o(c,"BAD_INDENT",gc)),!x.anchor&&!x.tag&&!f){d=x.end,x.comment&&(l.comment?l.comment+=`
70
+ `+x.comment:l.comment=x.comment);continue}(x.newlineAfterProp||yr(m))&&o(m??u[u.length-1],"MULTILINE_IMPLICIT_KEY","Implicit keys need to be on a single line")}else x.found?.indent!==s.indent&&o(c,"BAD_INDENT",gc);n.atKey=!0;const v=x.end,y=m?e(n,m,x,o):t(n,v,u,null,x,o);n.schema.compat&&$a(s.indent,m,o),n.atKey=!1,Ju(n,l.items,y)&&o(v,"DUPLICATE_KEY","Map keys must be unique");const b=qs(f??[],{indicator:"map-value-ind",next:g,offset:y.range[2],onError:o,parentIndent:s.indent,startOnNewline:!m||m.type==="block-scalar"});if(c=b.end,b.found){w&&(g?.type==="block-map"&&!b.hasNewline&&o(c,"BLOCK_AS_IMPLICIT_KEY","Nested mappings are not allowed in compact mappings"),n.options.strict&&x.start<b.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 k=g?e(n,g,b,o):t(n,c,f,null,b,o);n.schema.compat&&$a(s.indent,g,o),c=k.range[2];const C=new Dt(y,k);n.options.keepSourceTokens&&(C.srcToken=h),l.items.push(C)}else{w&&o(y.range,"MISSING_CHAR","Implicit map keys need to be followed by map values"),b.comment&&(y.comment?y.comment+=`
71
+ `+b.comment:y.comment=b.comment);const k=new Dt(y);n.options.keepSourceTokens&&(k.srcToken=h),l.items.push(k)}}return d&&d<c&&o(d,"IMPOSSIBLE","Map comment with trailing content"),l.range=[s.offset,c,d??c],l}function lb({composeNode:e,composeEmptyNode:t},n,s,o,a){const i=a?.nodeClass??os,l=new i(n.schema);n.atRoot&&(n.atRoot=!1),n.atKey&&(n.atKey=!1);let c=s.offset,d=null;for(const{start:h,value:u}of s.items){const m=qs(h,{indicator:"seq-item-ind",next:u,offset:c,onError:o,parentIndent:s.indent,startOnNewline:!0});if(!m.found)if(m.anchor||m.tag||u)u?.type==="block-seq"?o(m.end,"BAD_INDENT","All sequence items must start at the same column"):o(c,"MISSING_CHAR","Sequence item without - indicator");else{d=m.end,m.comment&&(l.comment=m.comment);continue}const f=u?e(n,u,m,o):t(n,m.end,h,null,m,o);n.schema.compat&&$a(s.indent,u,o),c=f.range[2],l.items.push(f)}return l.range=[s.offset,c,d??c],l}function Mr(e,t,n,s){let o="";if(e){let a=!1,i="";for(const l of e){const{source:c,type:d}=l;switch(d){case"space":a=!0;break;case"comment":{n&&!a&&s(l,"MISSING_CHAR","Comments must be separated from other tokens by white space characters");const h=c.substring(1)||" ";o?o+=i+h:o=h,i="";break}case"newline":o&&(i+=c),a=!0;break;default:s(l,"UNEXPECTED_TOKEN",`Unexpected ${d} at node end`)}t+=c.length}}return{comment:o,offset:t}}const ba="Block collections are not allowed within flow collections",ya=e=>e&&(e.type==="block-map"||e.type==="block-seq");function cb({composeNode:e,composeEmptyNode:t},n,s,o,a){const i=s.start.source==="{",l=i?"flow map":"flow sequence",c=a?.nodeClass??(i?Yt:os),d=new c(n.schema);d.flow=!0;const h=n.atRoot;h&&(n.atRoot=!1),n.atKey&&(n.atKey=!1);let u=s.offset+s.start.source.length;for(let w=0;w<s.items.length;++w){const v=s.items[w],{start:y,key:b,sep:k,value:C}=v,j=qs(y,{flow:l,indicator:"explicit-key-ind",next:b??k?.[0],offset:u,onError:o,parentIndent:s.indent,startOnNewline:!1});if(!j.found){if(!j.anchor&&!j.tag&&!k&&!C){w===0&&j.comma?o(j.comma,"UNEXPECTED_TOKEN",`Unexpected , in ${l}`):w<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&&yr(b)&&o(b,"MULTILINE_IMPLICIT_KEY","Implicit keys of flow sequence pairs need to be on a single line")}if(w===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 A="";e:for(const S of y)switch(S.type){case"comma":case"space":break;case"comment":A=S.source.substring(1);break e;default:break e}if(A){let S=d.items[d.items.length-1];yt(S)&&(S=S.value??S.key),S.comment?S.comment+=`
73
+ `+A:S.comment=A,j.comment=j.comment.substring(A.length+1)}}if(!i&&!k&&!j.found){const A=C?e(n,C,j,o):t(n,j.end,k,null,j,o);d.items.push(A),u=A.range[2],ya(C)&&o(A.range,"BLOCK_IN_FLOW",ba)}else{n.atKey=!0;const A=j.end,S=b?e(n,b,j,o):t(n,A,y,null,j,o);ya(b)&&o(S.range,"BLOCK_IN_FLOW",ba),n.atKey=!1;const T=qs(k??[],{flow:l,indicator:"map-value-ind",next:C,offset:S.range[2],onError:o,parentIndent:s.indent,startOnNewline:!1});if(T.found){if(!i&&!j.found&&n.options.strict){if(k)for(const D of k){if(D===T.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<T.found.offset-1024&&o(T.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(T.start,"MISSING_CHAR",`Missing , or : between ${l} items`));const P=C?e(n,C,T,o):T.found?t(n,T.end,k,null,T,o):null;P?ya(C)&&o(P.range,"BLOCK_IN_FLOW",ba):T.comment&&(S.comment?S.comment+=`
74
+ `+T.comment:S.comment=T.comment);const M=new Dt(S,P);if(n.options.keepSourceTokens&&(M.srcToken=v),i){const D=d;Ju(n,D.items,S)&&o(A,"DUPLICATE_KEY","Map keys must be unique"),D.items.push(M)}else{const D=new Yt(n.schema);D.flow=!0,D.items.push(M);const z=(P??S).range;D.range=[S.range[0],z[1],z[2]],d.items.push(D)}u=P?P.range[2]:T.end}}const m=i?"}":"]",[f,...g]=s.end;let x=u;if(f?.source===m)x=f.offset+f.source.length;else{const w=l[0].toUpperCase()+l.substring(1),v=h?`${w} must end with a ${m}`:`${w} in block collection must be sufficiently indented and end with a ${m}`;o(u,h?"MISSING_CHAR":"BAD_INDENT",v),f&&f.source.length!==1&&g.unshift(f)}if(g.length>0){const w=Mr(g,x,n.options.strict,o);w.comment&&(d.comment?d.comment+=`
75
+ `+w.comment:d.comment=w.comment),d.range=[s.offset,x,w.offset]}else d.range=[s.offset,x,x];return d}function wa(e,t,n,s,o,a){const i=n.type==="block-map"?ib(e,t,n,s,a):n.type==="block-seq"?lb(e,t,n,s,a):cb(e,t,n,s,a),l=i.constructor;return o==="!"||o===l.tagName?(i.tag=l.tagName,i):(o&&(i.tag=o),i)}function db(e,t,n,s,o){const a=s.tag,i=a?t.directives.tagName(a.source,m=>o(a,"TAG_RESOLVE_FAILED",m)):null;if(n.type==="block-seq"){const{anchor:m,newlineAfterProp:f}=s,g=m&&a?m.offset>a.offset?m:a:m??a;g&&(!f||f.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===Yt.tagName&&l==="map"||i===os.tagName&&l==="seq")return wa(e,t,n,o,i);let c=t.schema.tags.find(m=>m.tag===i&&m.collection===l);if(!c){const m=t.schema.knownTags[i];if(m?.collection===l)t.schema.tags.push(Object.assign({},m,{default:!1})),c=m;else return m?o(a,"BAD_COLLECTION_TYPE",`${m.tag} used for ${l} collection, but expects ${m.collection??"scalar"}`,!0):o(a,"TAG_RESOLVE_FAILED",`Unresolved tag: ${i}`,!0),wa(e,t,n,o,i)}const d=wa(e,t,n,o,i,c),h=c.resolve?.(d,m=>o(a,"TAG_RESOLVE_FAILED",m),t.options)??d,u=bt(h)?h:new Pe(h);return u.range=d.range,u.tag=i,c?.format&&(u.format=c.format),u}function ub(e,t,n){const s=t.offset,o=fb(t,e.options.strict,n);if(!o)return{value:"",type:null,comment:"",range:[s,s,s]};const a=o.mode===">"?Pe.BLOCK_FOLDED:Pe.BLOCK_LITERAL,i=t.source?hb(t.source):[];let l=i.length;for(let x=i.length-1;x>=0;--x){const w=i[x][1];if(w===""||w==="\r")l=x;else break}if(l===0){const x=o.chomp==="+"&&i.length>0?`
76
+ `.repeat(Math.max(1,i.length-1)):"";let w=s+o.length;return t.source&&(w+=t.source.length),{value:x,type:a,comment:o.comment,range:[s,w,w]}}let c=t.indent+o.indent,d=t.offset+o.length,h=0;for(let x=0;x<l;++x){const[w,v]=i[x];if(v===""||v==="\r")o.indent===0&&w.length>c&&(c=w.length);else{w.length<c&&n(d+w.length,"MISSING_CHAR","Block scalars with more-indented leading empty lines must use an explicit indentation indicator"),o.indent===0&&(c=w.length),h=x,c===0&&!e.atRoot&&n(d,"BAD_INDENT","Block scalar values in collections must be indented");break}d+=w.length+v.length+1}for(let x=i.length-1;x>=l;--x)i[x][0].length>c&&(l=x+1);let u="",m="",f=!1;for(let x=0;x<h;++x)u+=i[x][0].slice(c)+`
77
+ `;for(let x=h;x<l;++x){let[w,v]=i[x];d+=w.length+v.length+1;const y=v[v.length-1]==="\r";if(y&&(v=v.slice(0,-1)),v&&w.length<c){const k=`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",k),w=""}a===Pe.BLOCK_LITERAL?(u+=m+w.slice(c)+v,m=`
78
+ `):w.length>c||v[0]===" "?(m===" "?m=`
79
+ `:!f&&m===`
80
+ `&&(m=`
81
+
82
+ `),u+=m+w.slice(c)+v,m=`
83
+ `,f=!0):v===""?m===`
84
+ `?u+=`
85
+ `:m=`
86
+ `:(u+=m+v,m=" ",f=!1)}switch(o.chomp){case"-":break;case"+":for(let x=l;x<i.length;++x)u+=`
87
+ `+i[x][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 fb({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 m=1;m<o.length;++m){const f=o[m];if(!l&&(f==="-"||f==="+"))l=f;else{const g=Number(f);!i&&g?i=g:c===-1&&(c=e+m)}}c!==-1&&s(c,"UNEXPECTED_TOKEN",`Block scalar header includes extra characters: ${o}`);let d=!1,h="",u=o.length;for(let m=1;m<t.length;++m){const f=t[m];switch(f.type){case"space":d=!0;case"newline":u+=f.source.length;break;case"comment":n&&!d&&s(f,"MISSING_CHAR","Comments must be separated from other tokens by white space characters"),u+=f.source.length,h=f.source.substring(1);break;case"error":s(f,"UNEXPECTED_TOKEN",f.message),u+=f.source.length;break;default:{const g=`Unexpected token in block scalar header: ${f.type}`;s(f,"UNEXPECTED_TOKEN",g);const x=f.source;x&&typeof x=="string"&&(u+=x.length)}}}return{mode:a,indent:i,chomp:l,comment:h,length:u}}function hb(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 mb(e,t,n){const{offset:s,type:o,source:a,end:i}=e;let l,c;const d=(m,f,g)=>n(s+m,f,g);switch(o){case"scalar":l=Pe.PLAIN,c=pb(a,d);break;case"single-quoted-scalar":l=Pe.QUOTE_SINGLE,c=gb(a,d);break;case"double-quoted-scalar":l=Pe.QUOTE_DOUBLE,c=xb(a,d);break;default:return n(e,"UNEXPECTED_TOKEN",`Expected a flow scalar value, but found: ${o}`),{value:"",type:null,comment:"",range:[s,s+a.length,s+a.length]}}const h=s+a.length,u=Mr(i,h,t,n);return{value:c,type:l,comment:u.comment,range:[s,h,u.offset]}}function pb(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}`),ef(e)}function gb(e,t){return(e[e.length-1]!=="'"||e.length===1)&&t(e.length,"MISSING_CHAR","Missing closing 'quote"),ef(e.slice(1,-1)).replace(/''/g,"'")}function ef(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 xb(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}=bb(e,s);n+=a,s=i}else if(o==="\\"){let a=e[++s];const i=yb[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+=wb(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 bb(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 yb={0:"\0",a:"\x07",b:"\b",e:"\x1B",f:"\f",n:`
105
+ `,r:"\r",t:" ",v:"\v",N:"…",_:" ",L:"\u2028",P:"\u2029"," ":" ",'"':'"',"/":"/","\\":"\\"," ":" "};function wb(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 tf(e,t,n,s){const{value:o,type:a,comment:i,range:l}=t.type==="block-scalar"?ub(e,t,s):mb(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[fn]:c?d=kb(e.schema,o,c,n,s):t.type==="scalar"?d=vb(e,o,t,s):d=e.schema[fn];let h;try{const u=d.resolve(o,m=>s(n??t,"TAG_RESOLVE_FAILED",m),e.options);h=rt(u)?u:new Pe(u)}catch(u){const m=u instanceof Error?u.message:String(u);s(n??t,"TAG_RESOLVE_FAILED",m),h=new Pe(o)}return h.range=l,h.source=o,a&&(h.type=a),c&&(h.tag=c),d.format&&(h.format=d.format),i&&(h.comment=i),h}function kb(e,t,n,s,o){if(n==="!")return e[fn];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[fn])}function vb({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[fn];if(n.compat){const l=n.compat.find(c=>c.default&&c.test?.test(s))??n[fn];if(i.tag!==l.tag){const c=t.tagString(i.tag),d=t.tagString(l.tag),h=`Value may be parsed as either ${c} or ${d}`;a(o,"TAG_RESOLVE_FAILED",h,!0)}}return i}function jb(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 Nb={composeNode:nf,composeEmptyNode:bi};function nf(e,t,n,s){const o=e.atKey,{spaceBefore:a,comment:i,anchor:l,tag:c}=n;let d,h=!0;switch(t.type){case"alias":d=Sb(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=tf(e,t,c,s),l&&(d.anchor=l.source.substring(1));break;case"block-map":case"block-seq":case"flow-collection":try{d=db(Nb,e,t,n,s),l&&(d.anchor=l.source.substring(1))}catch(u){const m=u instanceof Error?u.message:String(u);s(t,"RESOURCE_EXHAUSTION",m)}break;default:{const u=t.type==="error"?t.message:`Unsupported token (type: ${t.type})`;s(t,"UNEXPECTED_TOKEN",u),h=!1}}return d??(d=bi(e,t.offset,void 0,null,n,s)),l&&d.anchor===""&&s(l,"BAD_ALIAS","Anchor cannot be an empty string"),o&&e.options.stringKeys&&(!rt(d)||typeof d.value!="string"||d.tag&&d.tag!=="tag:yaml.org,2002:str")&&s(c??t,"NON_STRING_KEY","With stringKeys, all keys must be strings"),a&&(d.spaceBefore=!0),i&&(t.type==="scalar"&&t.source===""?d.comment=i:d.commentBefore=i),e.options.keepSourceTokens&&h&&(d.srcToken=t),d}function bi(e,t,n,s,{spaceBefore:o,comment:a,anchor:i,tag:l,end:c},d){const h={type:"scalar",offset:jb(t,n,s),indent:-1,source:""},u=tf(e,h,l,d);return i&&(u.anchor=i.source.substring(1),u.anchor===""&&d(i,"BAD_ALIAS","Anchor cannot be an empty string")),o&&(u.spaceBefore=!0),a&&(u.comment=a,u.range[2]=c),u}function Sb({options:e},{offset:t,source:n,end:s},o){const a=new ai(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=Mr(s,i,e.strict,o);return a.range=[t,i,l.offset],l.comment&&(a.comment=l.comment),a}function Cb(e,t,{offset:n,start:s,value:o,end:a},i){const l=Object.assign({_directives:t},e),c=new Tr(void 0,l),d={atKey:!1,atRoot:!0,directives:c.directives,options:c.options,schema:c.schema},h=qs(s,{indicator:"doc-start",next:o??a?.[0],offset:n,onError:i,parentIndent:0,startOnNewline:!0});h.found&&(c.directives.docStart=!0,o&&(o.type==="block-map"||o.type==="block-seq")&&!h.hasNewline&&i(h.end,"MISSING_CHAR","Block collection cannot start on same line with directives-end marker")),c.contents=o?nf(d,o,h,i):bi(d,h.end,s,null,h,i);const u=c.contents.range[2],m=Mr(a,u,!1,i);return m.comment&&(c.comment=m.comment),c.range=[n,u,m.offset],c}function sr(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 xc(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 Eb{constructor(t={}){this.doc=null,this.atDirectives=!1,this.prelude=[],this.errors=[],this.warnings=[],this.onError=(n,s,o,a)=>{const i=sr(n);a?this.warnings.push(new ab(i,s,o)):this.errors.push(new or(i,s,o))},this.directives=new Rt({version:t.version||"1.2"}),this.options=t}decorate(t,n){const{comment:s,afterEmptyLine:o}=xc(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(xt(a)&&!a.flow&&a.items.length>0){let i=a.items[0];yt(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:xc(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=sr(t);a[0]+=n,this.onError(a,"BAD_DIRECTIVE",s,o)}),this.prelude.push(t.source),this.atDirectives=!0;break;case"document":{const n=Cb(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 or(sr(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 or(sr(t),"UNEXPECTED_TOKEN",s));break}this.doc.directives.docEnd=!0;const n=Mr(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 or(sr(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 Tr(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 sf="\uFEFF",rf="",of="",Pa="";function Ib(e){switch(e){case sf:return"byte-order-mark";case rf:return"doc-mode";case of:return"flow-error-end";case Pa: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 en(e){switch(e){case void 0:case" ":case`
115
+ `:case"\r":case" ":return!0;default:return!1}}const bc=new Set("0123456789ABCDEFabcdef"),Tb=new Set("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()"),eo=new Set(",[]{}"),Mb=new Set(` ,[]{}
116
+ \r `),ka=e=>!e||Mb.has(e);class Ab{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==="...")&&en(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]===sf&&(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 rf,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==="...")&&en(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&&!en(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===":")&&en(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(ka),"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("..."))&&en(o[3]))&&!(s===this.indentNext-1&&this.flowLevel===1&&(o[0]==="]"||o[0]==="}")))return this.flowLevel=0,yield of,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(ka),"flow";case'"':case"'":return this.flowKey=!0,yield*this.parseQuotedScalar();case":":{const i=this.charAt(1);if(this.flowKey||en(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=>en(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 Pa,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(en(a)||t&&eo.has(a))break;n=s}else if(en(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 Pa,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(ka),t+=yield*this.pushSpaces(!0);continue e;case"-":case"?":case":":{const n=this.flowLevel>0,s=this.charAt(1);if(en(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(;!en(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(Tb.has(n))n=this.buffer[++t];else if(n==="%"&&bc.has(this.buffer[t+1])&&bc.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 _b{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 _n(e,t){for(let n=0;n<e.length;++n)if(e[n].type===t)return!0;return!1}function yc(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 af(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 vs(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 jo(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 wc(e){if(e.start.type==="flow-seq-start")for(const t of e.items)t.sep&&!t.value&&!_n(t.start,"explicit-key-ind")&&!_n(t.sep,"map-value-ind")&&(t.key&&(t.value=t.key),delete t.key,af(t.value)?t.value.end?jo(t.value.end,t.sep):t.value.end=t.sep:jo(t.start,t.sep),delete t.sep)}class Lb{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 Ab,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=Ib(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"&&wc(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&&yc(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":{yc(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=vs(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)){jo(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(_n(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(af(n.key)&&!_n(n.sep,"newline")){const i=vs(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(_n(n.start,"newline"))Object.assign(n,{key:null,sep:[this.sourceToken]});else{const i=vs(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]}):_n(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&&!_n(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)){jo(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||_n(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=vs(o);wc(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=vs(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=vs(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 Rb(e){const t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new _b||null,prettyErrors:t}}function Db(e,t={}){const{lineCounter:n,prettyErrors:s}=Rb(t),o=new Lb(n?.addNewLine),a=new Eb(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 or(l.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}return s&&n&&(i.errors.forEach(pc(e,n)),i.warnings.forEach(pc(e,n))),i}function kc(e,t,n){let s;typeof t=="function"?s=t:n===void 0&&t&&typeof t=="object"&&(n=t);const o=Db(e,n);if(!o)return null;if(o.warnings.forEach(a=>_u(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 vc(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 Sr(e)&&!s?e.toString(n):new Tr(e,s,n).toString(n)}function Ob({expanded:e,onToggle:t,summary:n,actions:s,children:o,className:a="",summaryClassName:i="",panelClassName:l="",testId:c,disabled:d=!1,panelLabel:h}){const u=p.useId(),m=`${u}-toggle`,f=`${u}-panel`,[g,x]=p.useState(e);p.useEffect(()=>{e&&x(!0)},[e]);const w=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:m,"aria-expanded":e,"aria-controls":f,"aria-disabled":d||void 0,onClick:w,"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:f,role:"region","aria-labelledby":m,"aria-label":h,"data-testid":c?`${c}-panel`:void 0,className:l,children:g?o:null})})})]})}function $b({step:e,index:t,total:n,dependsOnNames:s,roleOptions:o,onClose:a,onSave:i}){const{t:l}=ze(["work","common"]),[c,d]=p.useState(null),[h,u]=p.useState(e.name),[m,f]=p.useState(e.prompt),[g,x]=p.useState(!1),[w,v]=p.useState(null),y=p.useRef(null);p.useEffect(()=>{u(e.name)},[e.name]),p.useEffect(()=>{f(e.prompt)},[e.prompt]),p.useEffect(()=>{const j=A=>{if(A.key==="Escape"){if(c){A.stopPropagation(),d(null),u(e.name),f(e.prompt);return}a()}};return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[c,a,e.name,e.prompt]);const b=async j=>{x(!0),v(null);try{await i(j)}catch(A){v(A instanceof Error?A.message:String(A))}finally{x(!1)}},k=async()=>{d(null);const j=h.trim();if(!j||j===e.name){u(e.name);return}await b({name:j})},C=async()=>{d(null),m!==e.prompt&&await b({prompt:m})};return r.jsxs("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[r.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:a,"aria-hidden":"true"}),r.jsxs("div",{ref:y,role:"dialog","aria-modal":"true","aria-labelledby":"workflow-step-title",className:"relative flex max-h-[88vh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-border-default bg-surface-secondary shadow-2xl","data-testid":"workflow-step-modal",children:[r.jsxs("header",{className:"flex items-start justify-between gap-3 border-b border-border-default/50 px-5 py-3",children:[r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"text-[10px] font-medium uppercase tracking-wider text-fg-muted",children:l("work:task.workflowStepOf","步骤 {{index}} / {{total}}",{index:t+1,total:n})}),c==="name"?r.jsx("input",{autoFocus:!0,value:h,onChange:j=>u(j.target.value),onBlur:()=>{k()},onKeyDown:j=>{j.key==="Enter"&&k()},"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=>{b({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:m,onChange:j=>f(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 放弃本次编辑;保存时服务端会重新校验模板。")}),w?r.jsx("p",{className:"text-[11px] text-red-500",children:w}):null]})]})]})}const Pb={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:"已取消"}},jc={tone:"neutral",key:"runStatusUnknown",label:"未知"};function lf(e){return e?Pb[e]??{...jc,label:e}:jc}const Dn={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"}},cf=new Set(["completed","archived"]),df=new Set(["failed","rejected"]),uf=new Set(["in_progress","review"]);function yi(e){return e==="running"||e==="paused"}function wi(e){const t=new Map;for(const n of e)t.set(n.id,n);return t}function Bb(e,t){return t.get(e)?.name??e}function ki(e,t){return(e.depends_on??[]).map(n=>Bb(n,t))}function qb(e){const t=new Set(e.map(i=>i.id)),n={},s=[];for(const i of e)for(const l of i.depends_on??[])t.has(l)&&s.push({from:l,to:i.id});for(const i of e)n[i.id]=0;for(let i=0;i<e.length;i++){let l=!1;for(const c of e)for(const d of c.depends_on??[]){if(!t.has(d))continue;const h=(n[d]??0)+1;h>(n[c.id]??0)&&(n[c.id]=h,l=!0)}if(!l)break}const o=e.reduce((i,l)=>Math.max(i,n[l.id]??0),0),a=Array.from({length:o+1},()=>[]);for(const i of e)a[n[i.id]??0].push(i.id);return{layers:a,depth:n,edges:s}}function ff(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 hf(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++,cf.has(d.status)?s++:df.has(d.status)?(o++,i.push(c)):uf.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?cf.has(e.status)?"done":df.has(e.status)?"failed":uf.has(e.status)?"active":"pending":"unknown"}const mf="markus_workflows_expanded";function zb(e){try{const t=e(mf);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 Fb(e,t){try{t(mf,JSON.stringify([...e]))}catch{}}function Hb(e,t,n,s){const o=n(e);if(!o||typeof o!="object")throw new Error(ol.t("work:task.workflowYamlParseFailed"));o.name=t;const a=o.displayName;return typeof a=="string"&&a.length>0&&(o.displayName=ol.t("work:task.workflowDuplicateName",{name:a})),s(o)}function Nc({status:e,className:t=""}){const{t:n}=ze(["work"]),s=lf(e),o=Dn[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 Vb({items:e}){const{t}=ze(["work"]),[n,s]=p.useState(!1),o=p.useRef(null);return p.useEffect(()=>{if(!n)return;const a=l=>{o.current?.contains(l.target)||s(!1)},i=l=>{l.key==="Escape"&&s(!1)};return document.addEventListener("mousedown",a),document.addEventListener("keydown",i),()=>{document.removeEventListener("mousedown",a),document.removeEventListener("keydown",i)}},[n]),r.jsxs("div",{className:"relative",ref:o,children:[r.jsx("button",{type:"button","aria-haspopup":"menu","aria-expanded":n,"aria-label":t("work:task.workflowMoreActions","更多操作"),title:t("work:task.workflowMoreActions","更多操作"),onClick:()=>s(a=>!a),className:"flex h-8 w-8 items-center justify-center rounded-lg text-fg-tertiary transition-colors hover:bg-surface-elevated hover:text-fg-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/60",children:r.jsx(Wb,{})}),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 Wb({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 Kb(){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 Ub({steps:e,roleAgentName:t,onOpenStep:n}){const{t:s}=ze(["work"]),o=wi(e),{layers:a}=qb(e),i=new Map(e.map((c,d)=>[c.id,d]));let l=0;return r.jsxs("ol",{className:"space-y-1","data-testid":"workflow-step-flow",children:[a.map((c,d)=>{const h=c.length>1;return r.jsxs("li",{children:[h?r.jsx("p",{className:"mb-1 pl-5 text-[10px] font-medium uppercase tracking-wider text-fg-muted",children:s("work:task.workflowParallel","并行 {{count}} 步",{count:c.length})}):null,r.jsx("div",{className:h?"ml-1 space-y-0.5 border-l border-brand-500/30 pl-2":"space-y-0.5",children:c.map(u=>{const m=o.get(u);if(!m)return null;const f=ki(m,o),g=t?.(m.role),x=(i.get(u)??0)+1;return l+=1,r.jsx("li",{children:r.jsxs("button",{type:"button",onClick:()=>n(m,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:x}),r.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-fg-primary",children:m.name}),f.length>1?r.jsxs("span",{className:"shrink-0 rounded bg-surface-elevated px-1 py-0.5 text-[9px] text-fg-muted",title:f.join("、"),children:["↑",f.length]}):null,r.jsx("span",{className:"hidden shrink-0 text-[10px] text-fg-muted sm:inline",title:m.role,children:g??m.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:h,roleAgentName:u,onSendToAgent:m,onEdit:f,onDuplicate:g,onDelete:x}){const{t:w}=ze(["work","common"]),[v,y]=p.useState(null),b=i[0],k=i.some(S=>yi(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:w("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:w("work:task.workflowScheduled","定时")}):null,r.jsxs("span",{className:"text-[10px] text-fg-muted",children:["v",e.version]}),b?r.jsx(Nc,{status:b.status}):null]}),e.description?r.jsx("span",{className:"mt-0.5 line-clamp-1 block text-[11px] text-fg-tertiary",children:e.description}):null]}),A=r.jsxs(r.Fragment,{children:[k?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"}),w("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:w("work:task.workflowRun","运行")}),r.jsx(Vb,{items:[{key:"edit",label:w("work:task.workflowEditYaml","编辑 YAML"),onSelect:f},{key:"duplicate",label:w("work:task.workflowDuplicate","复制为新工作流"),onSelect:g},{key:"send",label:w("work:task.workflowSendToAgent","发送到智能体对话"),onSelect:m},{key:"delete",label:w("work:task.workflowDelete","删除工作流"),onSelect:x,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(Ob,{expanded:o,onToggle:a,summary:j,actions:A,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:w("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:w("work:task.workflowRetry","重试")})]}):t?r.jsxs("div",{className:"space-y-4",children:[C.length>0?r.jsx(Ub,{steps:C,roleAgentName:u,onOpenStep:(S,T)=>y({step:S,index:T})}):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:w("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:[w("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:w("work:task.workflowRecentRuns","最近运行")}),i.length===0?r.jsx("p",{className:"text-[11px] text-fg-muted",children:w("work:task.workflowNoRecentRuns","暂无运行记录")}):r.jsx("ul",{className:"space-y-0.5",children:i.map(S=>{const T=ff(C,l[S.id]??[]),P=hf(C,T);return r.jsx("li",{children:r.jsxs("button",{type:"button",onClick:()=>d(S),"aria-label":w("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(Nc,{status:S.status}),r.jsx("span",{className:"shrink-0 text-[11px] tabular-nums text-fg-tertiary",children:P.total>0?`${P.done}/${P.total}`:w("work:task.workflowStepCountShort","{{count}} 个任务",{count:S.taskIds.length})}),r.jsx("span",{className:"text-[11px] text-fg-muted",children:Yc(S.startedAt,w)}),S.triggeredBy==="schedule"?r.jsx("span",{className:"shrink-0 text-[10px] text-purple-500",children:w("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(Kb,{})}),v?r.jsx($b,{step:v.step,index:v.index,total:C.length,dependsOnNames:ki(v.step,wi(C)),roleOptions:[...new Set([...C.map(S=>S.role),...Object.keys(b?.roleMapping??{})])],onClose:()=>y(null),onSave:S=>h?.(v.step.id,S)??Promise.resolve()}):null]})}const Sc={done:Dn.success.bar,failed:Dn.danger.bar,active:Dn.info.bar,pending:"bg-fg-muted/50",unknown:"bg-border-default"},va={done:{key:"runStatusCompleted",label:"已完成"},failed:{key:"runStatusFailed",label:"失败"},active:{key:"runStatusRunning",label:"进行中"},pending:{key:"workflowStepPending",label:"待处理"},unknown:{key:"workflowStepNoTask",label:"未创建任务"}};function Gb({workflow:e,run:t,detail:n,tasks:s,tasksLoading:o,onClose:a,onPauseResume:i,onCancel:l,onViewTasks:c,pausing:d,roleAgentName:h,onOpenTask:u}){const{t:m}=ze(["work","common"]),f=p.useRef(null);p.useEffect(()=>{f.current?.focus();const j=A=>{A.key==="Escape"&&a()};return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[a]);const g=t.templateSnapshot?.steps??n?.steps??[],x=wi(g),w=ff(g,s??[]),v=hf(g,w),y=lf(t.status),b=(s??[]).filter(j=>!Object.values(w).some(A=>A?.id===j.id)),k=(s?.length??0)>0&&Object.values(w).every(j=>!j),C=j=>k&&j==="unknown"?{key:"workflowStepUnmatched",label:"未匹配(历史运行)"}:va[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 ${Dn[y.tone].chip}`,children:[r.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${Dn[y.tone].dot}`,"aria-hidden":"true"}),m(`work:task.${y.key}`,y.label)]}),r.jsx("span",{children:Yc(t.startedAt,m)}),t.triggeredBy==="schedule"?r.jsx("span",{className:"text-purple-500",children:m("work:task.workflowScheduled","定时")}):null]})]}),r.jsx("button",{ref:f,type:"button",onClick:a,"aria-label":m("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:m("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:m("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?Dn.danger.bar:Dn.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:m("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:m("work:task.workflowLoading","加载中…")}):r.jsx("ol",{className:"space-y-1",children:g.map((j,A)=>{const S=w[j.id],T=no(S),P=C(T),M=ki(j,x),D=h?.(j.role),z=r.jsxs(r.Fragment,{children:[r.jsx("span",{className:`mt-1.5 h-2 w-2 shrink-0 rounded-full ${Sc[T]}`,"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:[A+1,". ",j.name]}),r.jsx("span",{className:"text-[10px] text-fg-muted",children:m(`work:task.${P.key}`,P.label)})]}),r.jsxs("span",{className:"mt-0.5 flex flex-wrap gap-x-2 text-[10px] text-fg-muted",children:[r.jsx("span",{children:D??j.role}),M.length>0?r.jsx("span",{children:m("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:m("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)})}),b.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:m("work:task.workflowUnmatchedTitle","该运行的任务(未能对应到步骤)")}),r.jsx("p",{className:"mt-0.5 text-[10px] leading-relaxed text-fg-muted",children:m("work:task.workflowUnmatchedHint","这是 2026-10-27 之前的运行:任务没有记录步骤身份,历史无法反推。下列任务仍可直接打开。")}),r.jsx("ul",{className:"mt-1.5 space-y-0.5",children:b.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 ${Sc[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:m(`work:task.${va[no(j)].key}`,va[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:m("work:task.workflowParamsCount","参数 ({{count}})",{count:Object.keys(t.params).length})}),r.jsx("dl",{className:"space-y-1",children:Object.entries(t.params).map(([j,A])=>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:A||"—"})]},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:m("work:task.workflowRoleAssignments","角色分配")}),r.jsx("dl",{className:"space-y-1",children:Object.entries(t.roleMapping).map(([j,A])=>r.jsxs("div",{className:"flex gap-2 text-[11px]",children:[r.jsx("dt",{className:"w-24 shrink-0 truncate text-fg-tertiary",children:j}),r.jsx("dd",{className:"min-w-0 flex-1 truncate text-fg-secondary",children:h?.(j)??A})]},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:[yi(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"?m("work:task.workflowPause","暂停"):m("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:m("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:m("work:task.workflowViewTasks","查看任务")})]})]})]})}function Xb({mode:e,workflow:t,yaml:n,yamlLoading:s,busy:o,error:a,onClose:i,onSubmit:l}){const{t:c}=ze(["work","common"]),[d,h]=p.useState(`${t.name}-copy`),[u,m]=p.useState(n??""),f=p.useRef(null);p.useEffect(()=>{m(n??"")},[n]),p.useEffect(()=>{f.current?.focus();const w=v=>{v.key==="Escape"&&i()};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[i]);const g=e==="edit"?c("work:task.workflowEditTitle","编辑工作流"):e==="duplicate"?c("work:task.workflowDuplicateTitle","复制为新工作流"):c("work:task.workflowDeleteConfirmTitle","删除工作流"),x=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:f,value:d,onChange:w=>h(w.target.value),placeholder:c("work:task.workflowNewNamePlaceholder","例如 feature-development-v2"),className:"input-field w-full font-mono text-xs"}),x?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:w=>m(w.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"&&x,onClick:()=>l({name:e==="duplicate"?d.trim():void 0,yaml:u}),className:`px-4 py-1.5 text-xs font-medium text-white transition-colors disabled:opacity-60 ${e==="delete"?"rounded-lg bg-red-600 hover:bg-red-500":"btn-primary"}`,children:o?c("work:task.workflowSaving","保存中…"):e==="delete"?c("work:task.workflowDelete","删除工作流"):e==="duplicate"?c("work:task.workflowDuplicateBtn","创建副本"):c("work:task.workflowSave","保存")})]})]})]})}const Cc={pending:new Set(["in_progress","blocked","rejected","cancelled","completed"]),in_progress:new Set(["review","blocked","failed","cancelled"]),blocked:new Set(["in_progress","cancelled","failed"]),review:new Set(["completed","in_progress","cancelled"]),completed:new Set(["archived","in_progress"]),failed:new Set(["in_progress","archived"]),rejected:new Set(["archived"]),cancelled:new Set(["archived","in_progress"]),archived:new Set([])},No={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([])},Ec="markus_work_l1_collapsed",Ic="markus_workflows_team",Tc="__all__",Mc=["backlog","kanban","dag","workflows"];function So(e){const t=e.agentId,n=e.activityId;return!t||!n?null:Ha({seq:e.seq,type:e.type,content:e.content??"",metadata:e.metadata,createdAt:e.createdAt??new Date().toISOString()},n,t)}function vi(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 ji({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(lh,{entries:e,isActive:!0,onExpand:()=>n("full"),embedded:!0}):r.jsx(Xc,{entries:e,isActive:!0,onCollapse:()=>n("compact"),embedded:!0})})}function Ni(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 Vt({options:e,value:t,onChange:n,placeholder:s,noMatchesText:o,className:a,disabled:i,size:l}){const[c,d]=p.useState(!1),[h,u]=p.useState(""),m=p.useRef(null),f=p.useRef(null),g=p.useRef(null),x=p.useRef(null),w=Ni(f,c);p.useEffect(()=>{const k=C=>{m.current&&!m.current.contains(C.target)&&x.current&&!x.current.contains(C.target)&&d(!1)};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[]);const v=l==="sm"?"px-2 py-1.5 text-xs":"px-3 py-2 text-sm",y=e.find(k=>k.value===t)?.label??"",b=h?e.filter(k=>k.label.toLowerCase().includes(h.toLowerCase())):e;return r.jsxs("div",{ref:m,className:a??"",children:[r.jsxs("div",{ref:f,onClick:()=>{i||(d(!c),u(""),setTimeout(()=>g.current?.focus(),0))},className:`w-full ${v} bg-surface-elevated border border-border-default rounded-lg focus-within:border-brand-500 outline-none flex items-center ${i?"opacity-50 cursor-not-allowed pointer-events-none":"cursor-pointer"}`,children:[c?r.jsx("input",{ref:g,value:h,onChange:k=>u(k.target.value),onClick:k=>k.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&&w&&r.jsx("div",{ref:x,className:"fixed z-[100] max-h-60 overflow-y-auto bg-surface-elevated border border-border-default rounded-lg shadow-lg",style:w.flipUp?{bottom:window.innerHeight-w.top,left:w.left,width:w.width}:{top:w.top,left:w.left,width:w.width},children:b.length===0?r.jsx("div",{className:`${v} text-fg-tertiary`,children:o??"No matches"}):b.map(k=>r.jsx("div",{onClick:()=>{n(k.value),d(!1),u("")},className:`${v} cursor-pointer hover:bg-brand-500/10 ${k.value===t?"bg-brand-500/10 text-brand-500 font-medium":"text-fg-primary"}`,children:k.label},k.value))})]})}const Zb=[{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 Co({value:e,onChange:t}){const{t:n}=ze("work");return r.jsx("div",{className:"flex flex-wrap gap-2",children:Zb.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 pf({kind:e,entity:t,agents:n,users:s,projects:o,onClose:a}){const i=t.title?.trim()||t.id,l=dh(i),c=t.projectId?o.find(u=>u.id===t.projectId)?.name??t.projectId:"",d=`${e==="requirement"?"📋":"✅"} ${l}`,h=[`@[${i}](${e}:${t.id})`,`[${e}]`,`ID: ${t.id}`,`Title: ${i}`,t.status?`Status: ${t.status}`:"",t.priority?`Priority: ${t.priority}`:"",c?`Project: ${c}`:""].filter(Boolean).join(`
138
+ `);return r.jsx(Zc,{chipKind:e,chipLabel:d,chipContent:h,agents:n,users:s,defaultTarget:Jc(t.createdBy,n,s),onClose:a})}function Qb({options:e,selected:t,onAdd:n,placeholder:s,noMatchesText:o,className:a}){const[i,l]=p.useState(!1),[c,d]=p.useState(""),h=p.useRef(null),u=p.useRef(null),m=p.useRef(null),f=p.useRef(null),g=Ni(u,i);p.useEffect(()=>{const v=y=>{h.current&&!h.current.contains(y.target)&&f.current&&!f.current.contains(y.target)&&l(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]);const x=e.filter(v=>!t.includes(v.value)),w=c?x.filter(v=>v.label.toLowerCase().includes(c.toLowerCase())):x;return r.jsxs("div",{ref:h,className:a??"",children:[r.jsxs("div",{ref:u,onClick:()=>{l(!i),d(""),setTimeout(()=>m.current?.focus(),0)},className:"w-full px-3 py-2 bg-surface-elevated border border-border-default rounded-lg text-sm focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[i?r.jsx("input",{ref:m,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:f,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:w.length===0?r.jsx("div",{className:"px-3 py-2 text-sm text-fg-tertiary",children:o??"No matches"}):w.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 Jb({options:e,onSelect:t,placeholder:n,noMatchesText:s,className:o,itemSuffix:a}){const[i,l]=p.useState(!1),[c,d]=p.useState(""),h=p.useRef(null),u=p.useRef(null),m=p.useRef(null),f=p.useRef(null),g=Ni(u,i);p.useEffect(()=>{const w=v=>{h.current&&!h.current.contains(v.target)&&f.current&&!f.current.contains(v.target)&&l(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[]);const x=c?e.filter(w=>w.label.toLowerCase().includes(c.toLowerCase())):e;return r.jsxs("div",{ref:h,className:o??"",children:[r.jsxs("div",{ref:u,onClick:()=>{l(!i),d(""),setTimeout(()=>m.current?.focus(),0)},className:"w-full px-2 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-[11px] text-fg-secondary focus-within:border-brand-500 outline-none flex items-center cursor-pointer",children:[i?r.jsx("input",{ref:m,value:c,onChange:w=>d(w.target.value),onClick:w=>w.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:f,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:x.length===0?r.jsx("div",{className:"px-3 py-2 text-xs text-fg-tertiary",children:s??"No matches"}):x.map(w=>r.jsxs("div",{onClick:()=>{t(w.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:w.label}),a?.(w)]},w.value))})]})}function zs(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 ey({value:e,onSave:t,className:n,placeholder:s}){const{t:o}=ze(["work","common"]),[a,i]=p.useState(!1),[l,c]=p.useState(e),d=p.useRef(null);p.useEffect(()=>{c(e)},[e]),p.useEffect(()=>{a&&d.current?.focus()},[a]);const h=async()=>{i(!1);const u=l.trim();if(u&&u!==e)try{await t(u)}catch{c(e)}else c(e)};return a?r.jsx("input",{ref:d,value:l,onChange:u=>c(u.target.value),onBlur:()=>{h()},onKeyDown:u=>{u.key==="Enter"&&h(),u.key==="Escape"&&(c(e),i(!1))},className:`bg-transparent border-b border-brand-500/50 outline-none ${n??""}`,placeholder:s}):r.jsx("span",{onClick:()=>i(!0),className:`cursor-pointer hover:border-b hover:border-gray-600 transition-colors ${n??""}`,title:o("work:task.clickToEdit"),children:e||r.jsx("span",{className:"text-fg-tertiary italic",children:s??o("work:task.clickToEdit")})})}function ty({value:e,onSave:t,className:n,placeholder:s}){const{t:o}=ze(["work","common"]),[a,i]=p.useState(!1),[l,c]=p.useState(e),d=p.useRef(null);p.useEffect(()=>{c(e)},[e]),p.useEffect(()=>{a&&d.current&&(d.current.focus(),d.current.style.height="auto",d.current.style.height=d.current.scrollHeight+"px")},[a]);const h=async()=>{i(!1);const u=l.trim();if(u!==e)try{await t(u)}catch{c(e)}else c(e)};return a?r.jsx("textarea",{ref:d,value:l,onChange:u=>{c(u.target.value),u.target.style.height="auto",u.target.style.height=u.target.scrollHeight+"px"},onBlur:()=>{h()},onKeyDown:u=>{u.key==="Escape"&&(c(e),i(!1))},className:`bg-transparent border border-brand-500/30 rounded-lg p-2 outline-none resize-none w-full ${n??""}`,placeholder:s,rows:2}):r.jsx("p",{onClick:()=>i(!0),className:`cursor-pointer hover:bg-surface-elevated/50 rounded-lg transition-colors px-2 py-1 -mx-2 -my-1 ${n??""}`,title:o("work:task.clickToEdit"),children:e||r.jsx("span",{className:"text-fg-tertiary italic",children:s??o("work:task.addDescription")})})}const ny=/^\[([^\]]+?)(?:\s+by\s+([^\]]+))?\]\s*([\s\S]*)$/;function gf(e){const t=e.match(ny);return t?{timestamp:t[1].trim(),author:t[2]?.trim()??"System",content:t[3].trim()}:{timestamp:"",author:"",content:e}}function sy(e,t){if(!e)return"";const n=e.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);if(!n)return e;const s=new Date,o=+n[1],a=+n[2]-1,i=+n[3],l=+n[4],c=+n[5],d=new Date(o,a,i,l,c),h=s.getTime()-d.getTime();return h<6e4?t("work:relative.justNow"):h<36e5?t("work:relative.minutesAgo",{count:Math.floor(h/6e4)}):h<864e5?t("work:relative.hoursAgo",{count:Math.floor(h/36e5)}):h<6048e5?t("work:relative.daysAgo",{count:Math.floor(h/864e5)}):`${o}-${String(a+1).padStart(2,"0")}-${String(i).padStart(2,"0")}`}const Ac=[{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 ry(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return Ac[Math.abs(t)%Ac.length]}function oy({note:e,compact:t}){const{t:n}=ze(["work","common"]),s=gf(e),o=n("work:task.systemAuthor"),a=ry(s.author||o),i=s.author?s.author.split(/[\s_-]+/).map(d=>d[0]).join("").slice(0,2).toUpperCase():"SY",l=sy(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(dr,{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(dr,{content:s.content,className:"text-xs text-fg-secondary"})})]})})]})}const ay=new Set(["rejected","cancelled","archived"]),Eo=[{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"}],_c={pending:kn.neutral.chip,blocked:kn.blocked.chip,failed:kn.danger.chip,rejected:kn.danger.chip},Lc=Object.fromEntries(["pending","in_progress","blocked","review","revision","completed","failed","rejected","cancelled","archived"].map(e=>[e,kn[rh(e)].chip])),Rc={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:kn.danger.chip},iy=[...new Set(Object.values(No).flatMap(e=>[...e]))],Dc=Object.fromEntries(iy.map(e=>[e,kn[nh(e)].chip]));function xf(e){return Object.keys(Lc).reduce((t,n)=>(t[n]={label:e(`work:status.task.${n}`),cls:Lc[n]},t),{})}function bf(e){return Object.keys(_c).reduce((t,n)=>(t[n]={label:e(`work:status.sub.${n}`),cls:_c[n]},t),{})}function ly(e){return Object.keys(Rc).reduce((t,n)=>(t[n]={label:e(`work:priority.${n}`),cls:Rc[n]},t),{})}function Si(e){return Object.keys(Dc).reduce((t,n)=>(t[n]={label:e(`work:status.requirement.${n}`),cls:Dc[n]},t),{})}const Oc=["low","medium","high","urgent"],$c=["pending","in_progress","blocked","review","completed","failed","rejected","cancelled"],Pc=["pending","in_progress","blocked","completed","rejected","cancelled"],es={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"},Bc={idle:"text-green-500",working:"text-blue-500",error:"text-red-500",paused:"text-amber-500",offline:"text-fg-muted"};function cy({agent:e,anchorRect:t,onClose:n}){const{t:s}=ze(["work","common"]),o=p.useRef(null);p.useEffect(()=>{const l=c=>{o.current&&!o.current.contains(c.target)&&n()};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[n]);const a=e.status==="idle"?"bg-green-400":e.status==="working"?"bg-blue-400 animate-pulse":e.status==="error"?"bg-red-400":"bg-gray-500",i=e.status==="idle"?s("work:task.online"):e.status==="working"?s("work:task.working"):e.status==="error"?s("work:task.error"):s("work:task.offline");return r.jsxs("div",{ref:o,className:"fixed z-50 w-56 bg-surface-secondary border border-border-default rounded-xl shadow-2xl p-3 space-y-2",style:{top:t.top+4,left:t.left},children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"w-7 h-7 rounded-full bg-brand-500/15 flex items-center justify-center text-[10px] font-bold text-brand-600 shrink-0",children:e.name.slice(0,2).toUpperCase()}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"text-xs text-fg-primary font-medium truncate",children:e.name}),r.jsx("div",{className:"text-[10px] text-fg-tertiary",children:e.role}),r.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${a}`}),r.jsx("span",{className:"text-[10px] text-fg-secondary",children:i})]})]})]}),r.jsx("button",{onClick:()=>{n(),Gt.navigate(st.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 Vo({comment:e,agents:t,onReply:n}){const{t:s}=ze(["work","common"]),o=e.authorType==="agent"||e.authorType==="system",a=new Date(e.createdAt),i=a.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),l=a.toLocaleDateString([],{month:"short",day:"numeric"}),[c,d]=p.useState(null),[h,u]=p.useState(!1),[m,f]=p.useState([]),[g,x]=p.useState(!1),w=p.useCallback((C,j)=>{const A=t.find(S=>S.name.toLowerCase()===C.toLowerCase());if(A){const S=j.target.getBoundingClientRect();d({agent:A,top:S.bottom,left:S.left})}},[t]),v=p.useMemo(()=>t.map(C=>C.name),[t]),y=p.useCallback(C=>{const j=t.find(A=>A.name.toLowerCase()===e.authorName.toLowerCase());if(j){const A=C.currentTarget.getBoundingClientRect();d({agent:j,top:A.bottom,left:A.left})}},[t,e.authorName]),b=p.useCallback(async()=>{if(h){u(!1);return}const C=e.activityId;if(C&&(u(!0),!(m.length>0))){x(!0);try{const{logs:j}=await ee.agents.getActivityLogs(e.authorId,C),A=j.map(S=>Ha(S,C,e.authorId)).filter(S=>S!==null).map(S=>({...S,ts:new Date(S.createdAt).getTime()}));f(A)}catch{}x(!1)}},[h,m.length,e]),k=p.useMemo(()=>ah(m.map(ih).filter(C=>C!==null)),[m]);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:b,className:"text-fg-tertiary hover:text-brand-400 text-[10px] opacity-0 group-hover:opacity-100 transition-opacity ml-1",children:s(h?"work:task.hideLog":"work:task.viewLog")})]}),e.replyTo&&e.replyToAuthor&&r.jsxs("button",{onClick:()=>{const 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(dr,{content:e.content,className:"text-xs text-fg-primary",onMentionClick:w,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),h&&r.jsx("div",{className:"mt-2 border border-border-subtle rounded-lg overflow-hidden bg-surface-secondary/30",children:g?r.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:s("work:task.loadingExecutionLog")}):k.length===0?r.jsx("div",{className:"p-3 text-xs text-fg-tertiary",children:s("work:task.noExecutionLogAvailable")}):r.jsx(Xc,{entries:m,isActive:!1,onCollapse:()=>u(!1),embedded:!0})})]}),c&&r.jsx(cy,{agent:c.agent,anchorRect:{top:c.top,left:c.left},onClose:()=>d(null)})]})}function dy({task:e,agents:t,users:n,authUser:s}){const{t:o}=ze(["work","common"]),[a,i]=p.useState([]),[l,c]=p.useState([]),d=p.useRef(null),[h,u]=p.useState(new Map);p.useEffect(()=>{c([]),u(new Map),d.current&&(clearTimeout(d.current),d.current=null),ee.tasks.getComments(e.id).then(v=>i(v.comments)).catch(()=>{})},[e.id]),p.useEffect(()=>Bt.on("task:comment",y=>{if(y.payload?.taskId===e.id&&y.payload.comment){const b=y.payload.comment;i(k=>k.some(C=>C.id===b.id)?k:[...k,b]),(b.authorType==="agent"||b.authorId?.startsWith("agt_"))&&(c(k=>{const C=k.filter(j=>j.id!==b.authorId);return C.length===0&&d.current&&(clearTimeout(d.current),d.current=null),C}),u(k=>{const C=new Map(k);return C.delete(b.authorId),C}))}}),[e.id]),p.useEffect(()=>{if(l.length===0)return;const v=new Set(l.map(b=>b.id));return Bt.on("agent:activity_log",b=>{const k=b.payload;if(!k)return;const C=k.agentId;if(!v.has(C))return;const j=So(k);j&&u(A=>vi(A,C,j))})},[l]);const m=p.useMemo(()=>{const v=[];for(const y of e.notes??[]){const b=gf(y);let k;if(b.timestamp){const C=b.timestamp.match(/^(\d{4})[/-](\d{2})[/-](\d{2})\s+(\d{2}):(\d{2})(?::(\d{2}))?/);k=C?new Date(+C[1],+C[2]-1,+C[3],+C[4],+C[5],+(C[6]??0)):new Date(0)}else k=new Date(0);v.push({type:"note",note:y,ts:k})}for(const y of a)v.push({type:"comment",comment:y,ts:new Date(y.createdAt)});return v.sort((y,b)=>y.ts.getTime()-b.ts.getTime()),v},[e.notes,a]),[f,g]=p.useState(null),x=async(v,y,b,k)=>{let C;b.length>0&&(C=(await ee.uploads.upload(b.map(T=>({dataUrl:T.dataUrl,name:T.name})),"comments")).files.map(T=>({type:"image",url:T.url,name:T.name})));const j=await ee.tasks.addComment(e.id,v,s?.name,C,s?.id,y.length>0?y:void 0,k),A=si(j.notifiedAgentIds,t);A.length>0&&(d.current&&clearTimeout(d.current),c(A),d.current=setTimeout(()=>c([]),12e4))},w=p.useCallback(v=>{g({id:v.id,authorName:v.authorName,content:v.content.slice(0,100)})},[]);return r.jsxs("div",{className:"mt-5",id:"task-activity",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:[m.length===0&&r.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6",children:o("work:task.noActivityYet")}),m.map((v,y)=>v.type==="note"?r.jsx(oy,{note:v.note,compact:!0},`n-${y}`):r.jsx(Vo,{comment:v.comment,agents:t,onReply:w},`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=h.get(v.id)??[];return r.jsxs("div",{className:"px-2 py-1.5 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Gt.navigate(st.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(Fa,{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(ji,{entries:y})})]},v.id)})})]}),r.jsx(Gc,{agents:t,humans:n,onSubmit:x,replyTo:f,onCancelReply:()=>g(null),placeholder:o("work:task.commentPlaceholder")})]})}function ja({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(Vo,{comment:i.comment,agents:n},i.key):r.jsx(ch,{entries:i.entries,isStreaming:s},i.key))})}function uy({task:e,isRunning:t,authUser:n,agents:s,reviewSessions:o=[]}){const a=e.id,{t:i}=ze(["work","common"]),[l,c]=p.useState([]),[d,h]=p.useState(new Map),[u,m]=p.useState(new Set),[f,g]=p.useState([]),[x,w]=p.useState(""),[v,y]=p.useState(t),[b,k]=p.useState(!0),[C,j]=p.useState(new Set),[A,S]=p.useState(""),[T,P]=p.useState(!1),[M,D]=p.useState([]),z=p.useRef(null),[E,B]=p.useState(new Map),[L,$]=p.useState([]),[R,q]=p.useState([]),[H,K]=p.useState([]),[O,Y]=p.useState(!1),_=p.useRef(null),I=p.useRef(null),[V,W]=p.useState(new Map),[F,Z]=p.useState(new Set),[te,ce]=p.useState(new Set),oe=p.useCallback(async re=>{Z(ue=>new Set(ue).add(re.id));try{const{activities:ue}=await ee.agents.getActivities(re.reviewerId,{limit:200}),me=Oh(ue,{taskId:a,queuedAt:re.queuedAt,completedAt:re.completedAt}),Ee=[];for(const pe of me){const{logs:Te}=await ee.agents.getActivityLogs(re.reviewerId,pe.id);for(const se of Te){const le=Ha(se,pe.id,re.reviewerId);le&&Ee.push(le)}}W(pe=>new Map(pe).set(re.id,Ee))}catch{W(ue=>new Map(ue).set(re.id,[]))}finally{Z(ue=>{const me=new Set(ue);return me.delete(re.id),me})}},[a]),be=re=>{ce(ue=>{const me=new Set(ue);return me.has(re.id)?(me.delete(re.id),me):(me.add(re.id),me)}),!V.has(re.id)&&!F.has(re.id)&&oe(re)},Ne=p.useMemo(()=>Lh(l,o,"all").map(re=>{if(re.kind==="review")return{kind:"review",session:re.session};const ue=l.findIndex(me=>me.round===re.round);return{kind:"execution",rs:l[ue],rsIdx:ue}}),[l,o]);p.useEffect(()=>{const re=o.filter(me=>me.status==="reviewing"&&te.has(me.id));return re.length===0?void 0:Bt.on("agent:activity_log",me=>{const Ee=me.payload;if(!Ee)return;const pe=Ee.agentId;if(!pe)return;const Te=So(Ee);if(Te)for(const se of re)se.reviewerId===pe&&id(Te.createdAt,{queuedAt:se.queuedAt,completedAt:se.completedAt})&&W(le=>{const fe=le.get(se.id)??[];if(fe.some(ge=>ge.sourceId===Te.sourceId&&ge.seq===Te.seq))return le;const Q=new Map(le);return Q.set(se.id,[...fe,Te]),Q})})},[o,te,a]),p.useEffect(()=>{y(t)},[t]),p.useEffect(()=>{D([]),B(new Map),z.current&&(clearTimeout(z.current),z.current=null)},[a]),p.useEffect(()=>{k(!0),Promise.all([ee.tasks.getLogsSummary(a).catch(()=>({rounds:[]})),ee.tasks.getComments(a).catch(()=>({comments:[]}))]).then(([re,ue])=>{const me=re.rounds;if(c(me),g(ue.comments),me.length===0){k(!1);return}const Ee=me[me.length-1].round;j(new Set([Ee])),ee.tasks.getLogs(a,Ee).catch(()=>({logs:[]})).then(pe=>{h(new Map([[Ee,pe.logs]])),k(!1)})})},[a]),p.useEffect(()=>{const re=e.assignedAgentId;re&&(Y(!0),ee.agents.getActivities(re,{taskId:a,limit:20}).then(ue=>q(ue.activities)).catch(()=>q([])).finally(()=>Y(!1)),ee.agents.workUnits(re,"running").then(ue=>K(ue.units)).catch(()=>K([])))},[a,e.assignedAgentId]);const Ie=oh(H,a),Ce=p.useCallback(re=>{d.has(re)||u.has(re)||(m(ue=>new Set(ue).add(re)),ee.tasks.getLogs(a,re).catch(()=>({logs:[]})).then(ue=>{h(me=>new Map(me).set(re,ue.logs)),m(me=>{const Ee=new Set(me);return Ee.delete(re),Ee})}))},[a,d,u]),Fe=p.useCallback(re=>{j(ue=>{const me=new Set(ue);return me.has(re)?me.delete(re):(me.add(re),d.has(re)||Ce(re)),me})},[d,Ce]);p.useEffect(()=>{const re=Bt.on("task:log",Ee=>{const pe=Ee.payload;if(pe.taskId!==a)return;const Te={id:pe.id,taskId:pe.taskId,agentId:pe.agentId,seq:pe.seq,type:pe.logType,content:pe.content,metadata:pe.metadata,executionRound:pe.executionRound,createdAt:pe.createdAt},se=Te.executionRound??1;c(le=>le.find(Q=>Q.round===se)?le:[...le,{round:se,logCount:0,toolCount:0,firstAt:Te.createdAt,lastAt:Te.createdAt,status:"running"}]),j(le=>le.has(se)?le:new Set(le).add(se)),h(le=>{const fe=le.get(se)??[];return Te.id&&fe.some(Q=>Q.id===Te.id)?le:new Map(le).set(se,[...fe,Te])}),Te.type==="text"&&w(""),Te.type==="status"&&(Te.content==="started"||Te.content==="resumed"?y(!0):["completed","failed","cancelled","execution_finished"].includes(Te.content)&&(y(!1),c(le=>le.map(fe=>fe.round===se?{...fe,status:Te.content}:fe)))),Te.type==="error"&&y(!1)}),ue=Bt.on("task:log:delta",Ee=>{const pe=Ee.payload;pe.taskId===a&&w(Te=>Te+pe.text)}),me=Bt.on("task:comment",Ee=>{const pe=Ee.payload;if(pe.taskId!==a)return;const Te=pe.comment;g(se=>se.some(le=>le.id===Te.id)?se:[...se,Te]),(Te.authorType==="agent"||Te.authorId?.startsWith("agt_"))&&(D(se=>{const le=se.filter(fe=>fe.id!==Te.authorId);return le.length===0&&z.current&&(clearTimeout(z.current),z.current=null),le}),B(se=>{const le=new Map(se);return le.delete(Te.authorId),le}))});return()=>{re(),ue(),me()}},[a]),p.useEffect(()=>{if(M.length===0)return;const re=new Set(M.map(me=>me.id));return Bt.on("agent:activity_log",me=>{const Ee=me.payload;if(!Ee)return;const pe=Ee.agentId;if(!re.has(pe))return;const Te=So(Ee);Te&&B(se=>vi(se,pe,Te))})},[M]);const Be=p.useMemo(()=>{const re=[];for(const[,ue]of d)re.push(...ue);return re.sort((ue,me)=>ue.seq-me.seq),re},[d]),Re=p.useMemo(()=>Be.map(re=>il(re)),[Be]),$e=l.length>1||o.length>0,Et=re=>{const ue=re.target.files;if(ue){for(const me of Array.from(ue)){if(!me.type.startsWith("image/"))continue;const Ee=new FileReader;Ee.onload=()=>{$(pe=>[...pe,{type:"image",url:Ee.result,name:me.name}])},Ee.readAsDataURL(me)}re.target.value=""}},qe=async()=>{if(!(!A.trim()&&L.length===0)){P(!0);try{let re;L.length>0&&(re=(await ee.uploads.upload(L.map(pe=>({dataUrl:pe.url,name:pe.name})),"comments")).files.map(pe=>({type:"image",url:pe.url,name:pe.name})));const ue=await ee.tasks.addComment(a,A,n?.name,re,n?.id);ue.comment&&g(Ee=>Ee.some(pe=>pe.id===ue.comment.id)?Ee:[...Ee,ue.comment]),S(""),$([]);const me=si(ue.notifiedAgentIds,s);me.length>0&&(z.current&&clearTimeout(z.current),D(me),z.current=setTimeout(()=>D([]),12e4))}catch{}P(!1)}},Ge=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,ue)=>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:()=>$(me=>me.filter((Ee,pe)=>pe!==ue)),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:"×"})]},ue))}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"text",value:A,onChange:re=>S(re.target.value),onKeyDown:re=>{re.key==="Enter"&&!re.shiftKey&&(re.preventDefault(),qe())},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:_,accept:"image/*",multiple:!0,onChange:Et,className:"hidden"}),r.jsx("button",{onClick:()=>_.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:()=>{qe()},disabled:T||!A.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(b)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&&!x){const re=e.assignedAgentId?s.find(Q=>Q.id===e.assignedAgentId):void 0,ue=R.length>0,me=re&&re.currentTaskId&&re.currentTaskId!==e.id,Ee=e.status==="pending",pe=e.status==="in_progress",Te=!e.assignedAgentId;let se="📋",le=i("work:task.emptyLogs.default"),fe=i("work:task.emptyLogs.defaultHint");return Te?(se="👤",le=i("work:task.emptyLogs.noAgent"),fe=i("work:task.emptyLogs.noAgentHint")):Ee?(se="⏳",le=i("work:task.emptyLogs.pending"),fe=i("work:task.emptyLogs.pendingHint")):pe&&me?(se="🔄",le=i("work:task.emptyLogs.agentBusy",{agent:re?.name??e.assignedAgentId}),fe=i("work:task.emptyLogs.agentBusyHint")):pe&&(se="⏳",le=i("work:task.emptyLogs.starting"),fe=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:O?r.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-fg-tertiary",children:i("work:task.loadingLogs")}):ue?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:R.length}),Ie&&r.jsxs("span",{className:"ml-1 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")]})]}),r.jsx("div",{className:"space-y-1.5",children:R.map(Q=>{const ge=Q.type==="task"?"🔧":Q.type==="chat"||Q.type==="respond_in_session"?"💬":Q.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:()=>Gt.navigate(st.TEAM,{agentId:e.assignedAgentId}),children:[r.jsx("span",{className:"text-sm shrink-0",children:ge}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("div",{className:"text-xs text-fg-primary truncate",children:Q.label}),r.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[new Date(Q.startedAt).toLocaleString(),Q.endedAt?` — ${Q.totalTools} tools, ${Q.totalTokens.toLocaleString()} tokens`:""]})]}),Q.success?r.jsx("span",{className:"shrink-0 text-[10px] text-fg-tertiary",children:"✓"}):r.jsx("span",{className:"shrink-0 text-[10px] text-red-400",children:"✗"}),r.jsx("span",{className:"shrink-0 text-fg-tertiary text-[10px] opacity-0 group-hover:opacity-100 transition-opacity",children:"→"})]},Q.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:se}),r.jsxs("div",{className:"text-xs",children:[le,r.jsx("br",{}),r.jsx("span",{className:"text-fg-muted",children:fe})]})]})})}),Ge]})}if(!$e)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(ja,{entries:Re,comments:f,agents:s,isExecuting:v}),v&&x&&r.jsx(ll,{content:x}),v&&!x&&Re.length>0&&r.jsx(cl,{})]}),Ge]});const ft=re=>w0(f,l,re.round),mt=k0(f,l);return r.jsxs("div",{className:"flex flex-col min-h-full",children:[r.jsx("div",{ref:I}),r.jsxs("div",{className:"px-4 py-3 flex-1 space-y-2",children:[mt.length>0&&r.jsx("div",{className:"space-y-0.5",children:mt.map(re=>r.jsx(Vo,{comment:re,agents:s},re.id))}),Ne.map(re=>{if(re.kind==="review"){const ge=re.session,Se=te.has(ge.id),tt=ge.status==="reviewing",Qe=V.get(ge.id),Je=F.has(ge.id),ye=tt?"🔄":ge.outcome==="approved"?"✅":ge.outcome==="revision_requested"?"↩️":"⏹";return r.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[r.jsxs("button",{onClick:()=>be(ge),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:ye}),r.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:i("work:task.reviewRoundLabel",{round:ge.round})}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:ge.reviewerName??i("work:task.reviewerUnknown")}),tt&&r.jsx("span",{className:"text-[10px] text-purple-400",children:ge.reviewerType==="human"?i("work:task.reviewWaiting"):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(ge.queuedAt).toLocaleString()}),r.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${Se?"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"})})]})]}),Se&&r.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[ge.note&&r.jsx("p",{className:"whitespace-pre-wrap break-words text-[11px] leading-relaxed text-fg-secondary",children:ge.note}),Je&&r.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:i("work:task.reviewLoading")}),Qe&&Qe.length>0&&r.jsx(ja,{entries:Qe,comments:[],agents:s,isExecuting:!1}),Qe&&Qe.length===0&&r.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:i("work:task.reviewNoTurns")})]})]},ge.id)}const ue=re.rs;re.rsIdx;const me=C.has(ue.round),Ee=ue.round===l[l.length-1].round,pe=d.get(ue.round),Te=u.has(ue.round),se=ft(ue),le=ue.status==="completed"||ue.status==="execution_finished"?"✅":ue.status==="failed"?"❌":ue.status==="cancelled"?"⏹":"🔄",fe=ue.lastAt&&ue.firstAt?Math.max(0,new Date(ue.lastAt).getTime()-new Date(ue.firstAt).getTime()):0,Q=fe>=6e4?`${Math.floor(fe/6e4)}m ${Math.floor(fe%6e4/1e3)}s`:fe>=1e3?`${Math.floor(fe/1e3)}s`:"";return r.jsxs("div",{className:"border border-border-default/50 rounded-lg overflow-hidden",children:[r.jsxs("button",{onClick:()=>Fe(ue.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:le}),r.jsx("span",{className:"text-xs text-fg-secondary font-medium",children:i("work:task.roundHeader",{n:ue.round})}),se.length>0&&r.jsxs("span",{className:"text-[10px] text-blue-400",children:["💬 ",se.length]}),Ee&&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:ue.toolCount})}),Q&&r.jsx("span",{className:"text-[10px] text-fg-tertiary tabular-nums",children:Q}),r.jsx("svg",{className:`w-3 h-3 text-fg-tertiary transition-transform ${me?"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"})})]})]}),me&&r.jsxs("div",{className:"px-3 py-1.5 space-y-0.5",children:[Te&&r.jsx("div",{className:"text-xs text-fg-tertiary py-2 text-center",children:i("work:task.loadingRound",{n:ue.round})}),pe&&r.jsx(ja,{entries:pe.map(ge=>il(ge)),comments:se,agents:s,isExecuting:Ee&&v}),Ee&&v&&x&&r.jsx(ll,{content:x}),Ee&&v&&!x&&!Te&&r.jsx(cl,{})]})]},ue.round)}),M.length>0&&r.jsx("div",{className:"flex flex-col gap-1.5 mt-2",children:M.map(re=>{const ue=E.get(re.id)??[];return r.jsxs("div",{className:"px-3 py-2 rounded-lg cursor-pointer hover:bg-surface-elevated/60 transition-colors",onClick:()=>Gt.navigate(st.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(Fa,{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}),ue.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:"→"})]}),ue.length>0&&r.jsx("div",{className:"ml-9 mt-1",children:r.jsx(ji,{entries:ue})})]},re.id)})})]}),Ge]})}const qc=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 fy({filePath:e,onClose:t,onOpenExternal:n}){const{t:s}=ze(["work","common"]),[o,a]=p.useState([e]),i=o[o.length-1],[l,c]=p.useState(null),[d,h]=p.useState(null),[u,m]=p.useState(!0),[f,g]=p.useState(!1);p.useEffect(()=>{m(!0),h(null),c(null),ee.files.preview(i).then(S=>c(S)).catch(S=>h(String(S))).finally(()=>m(!1))},[i]);const x=S=>a(T=>[...T,S]),w=()=>a(S=>S.length>1?S.slice(0,-1):S),v=o.length>1,y=S=>{ee.files.reveal(S).catch(()=>{})},b=()=>{navigator.clipboard?.writeText(i).then(()=>{g(!0),setTimeout(()=>g(!1),1500)}).catch(()=>{})},k=S=>{S.isDirectory||qc.has(S.ext)?x(S.path):y(S.path)},C=i.split("/").pop()??i,j=l?.type==="directory",A=(S,T)=>{if(T)return"📁";const P=[".md",".markdown"],M=[".png",".jpg",".jpeg",".gif",".webp",".svg"];return P.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:w,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:b,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:f?`${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:()=>k(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:A(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&&!qc.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(sh,{data:{format:(l.extension||"").replace(/^\./,"")||"pdf",streamUrl:l.streamUrl||(l.path?ee.files.streamUrl(l.path):ee.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?ee.files.streamUrl(l.path):ee.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?ee.files.streamUrl(l.path):ee.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("common:filePreview.unsupported")}),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(hh,{content:l.content,format:l.type==="text"?"text":l.type,className:"text-sm text-fg-secondary leading-relaxed",copyVariant:"preview"})})]})]})})}function zc({task:e,agents:t,projects:n,requirements:s,allTasks:o,users:a,onClose:i,onRefresh:l,authUser:c,scrollToComments:d,onScrollToCommentsDone:h,onReqClick:u,onProjectClick:m}){const{t:f}=ze(["work","common"]),g=p.useMemo(()=>xf(f),[f]),[x,w]=p.useState([]),[v,y]=p.useState(""),[b,k]=p.useState(!1),[C,j]=p.useState(!1),[A,S]=p.useState(null),[T,P]=p.useState(null),[M,D]=p.useState(!1),[z,E]=p.useState(!1),[B,L]=p.useState(!1),[$,R]=p.useState(null),[q,H]=p.useState(!1),[K,O]=p.useState(!1),[Y,_]=p.useState("details"),I=p.useRef(null),[V,W]=p.useState("none"),[F,Z]=p.useState(1),[te,ce]=p.useState([]),oe=p.useCallback(async()=>{try{const{results:U}=await ee.deliverables.search({taskId:e.id,limit:200});ce(U.filter(de=>de.status!=="outdated"))}catch{}},[e.id]),be=p.useCallback(U=>{_(U),U==="deliverables"&&oe(),requestAnimationFrame(()=>{I.current?.scrollTo({top:0,behavior:"instant"})})},[oe]),Ne=p.useMemo(()=>[{id:"details"},{id:"activity"},{id:"deliverables"},{id:"history"}],[]),Ie=eh(Ne,Y,be),[Ce,Fe]=p.useState([]),Be=(()=>{const U=e.reviewerId;if(!U)return;const de=t.find(Oe=>Oe.id===U)?.name,De=a.find(Oe=>Oe.id===U)?.name;return e.reviewerType==="human"?De??de:de??De})();p.useEffect(()=>{let U=!0;return ee.tasks.getHistory(e.id).then(de=>{U&&Fe(Mh(de.history,{reviewerId:e.reviewerId,reviewerName:Be,reviewerType:e.reviewerType}))}).catch(()=>{U&&Fe([])}),()=>{U=!1}},[e.id,e.status,e.reviewerId,e.reviewerType,Be,t,a]),p.useEffect(()=>{const U=I.current;if(!U)return;const de=()=>{const{scrollTop:Oe,scrollHeight:Ve,clientHeight:Pt}=U;if(!(Ve>Pt+50)){W("none");return}const as=Oe<30,is=Oe+Pt>=Ve-30;W(as?"top":is?"bottom":"middle")};de(),U.addEventListener("scroll",de,{passive:!0});const De=new ResizeObserver(de);return De.observe(U),()=>{U.removeEventListener("scroll",de),De.disconnect()}},[Y]),p.useEffect(()=>{if(!d)return;_("details");const U=setTimeout(()=>{const de=I.current;de&&de.scrollTo({top:de.scrollHeight,behavior:"smooth"}),h?.()},300);return()=>clearTimeout(U)},[d,h]);const[Re,$e]=p.useState(null),[Et,qe]=p.useState(!1),[Ge,ft]=p.useState(null),[mt,re]=p.useState(!1),[ue,me]=p.useState(e.description),Ee=p.useRef(null),pe=p.useRef(null),Te=p.useRef(80);p.useEffect(()=>{if(mt&&pe.current){const U=pe.current;U.style.height="auto",U.style.height=Math.max(U.scrollHeight,Te.current)+"px",U.focus()}},[mt]);const[se,le]=p.useState(!1),[fe,Q]=p.useState("");p.useEffect(()=>{oe()},[oe,e.updatedAt]),p.useEffect(()=>{const U=["created","updated","removed"].map(de=>Bt.on(`deliverable:${de}`,De=>{const Oe=De.payload;!Oe||Oe.taskId!==e.id||oe()}));return()=>{U.forEach(de=>de())}},[e.id,oe]);const[ge,Se]=p.useState(!1),tt=wr(),Qe=20,Je=p.useCallback(async()=>{try{const U=await ee.tasks.listSubtasks(e.id);w(U.subtasks)}catch{}},[e.id]);p.useEffect(()=>{Je()},[Je,e.updatedAt]);const ye=async U=>{if(!q){H(!0);try{await U(),l(),await Je()}catch(de){$e(String(de).replace("Error: ",""))}finally{H(!1)}}},He=U=>ye(()=>ee.tasks.update(e.id,{priority:U})),wt=U=>ye(()=>ee.tasks.assign(e.id,U||null)),X=U=>ye(()=>ee.tasks.update(e.id,{projectId:U||null})),ie=async()=>{if(!q){H(!0);try{await ee.tasks.pause(e.id),l()}finally{H(!1)}}},xe=U=>{if(U instanceof Uc){if(U.code==="TASK_BLOCKED"){const de=U.data?.dependencyTitles??[];return de.length?f("work:task.errorBlockedDeps",{deps:de.join("、")}):f("work:task.errorBlocked")}if(U.code==="TASK_NOT_BLOCKED")return f("work:task.errorNotBlocked");if(U.code==="TASK_NOT_RETRYABLE")return f("work:task.errorNotRetryable")}return String(U).replace("Error: API error: 400","Server error").replace("Error: ","")},je=async()=>{if(!q){H(!0),$e(null),be("activity");try{await ee.tasks.resume(e.id),l()}catch(U){$e(xe(U))}finally{H(!1)}}},we=async()=>{v.trim()&&(await ee.tasks.createSubtask(e.id,v.trim()),y(""),k(!1),Je(),l())},Le=async U=>{U.status==="completed"||U.status==="cancelled"?await ee.tasks.cancelSubtask(e.id,U.id):await ee.tasks.completeSubtask(e.id,U.id),Je(),l()},ke=async U=>{await ee.tasks.deleteSubtask(e.id,U.id),S(null),Je(),l()},pt=async()=>{if(!q){H(!0),$e(null);try{await ee.tasks.updateStatus(e.id,"in_progress"),l()}catch(U){$e(xe(U))}finally{H(!1)}}},lt=async()=>{if(!q){H(!0),$e(null),be("activity");try{await ee.tasks.retry(e.id),l()}catch(U){$e(xe(U))}finally{H(!1)}}},It=async()=>{if(!q){H(!0),$e(null),be("activity");try{await ee.tasks.runNow(e.id),l()}catch(U){$e(xe(U)),l()}finally{H(!1)}}},Ot=p.useRef(l);Ot.current=l,p.useEffect(()=>Bt.on("task:update",de=>{de.payload.taskId===e.id&&(Je(),oe(),Ot.current())}),[e.id,Je,oe]);const Wt=x.filter(U=>U.status==="completed").length,_t=x.filter(U=>U.status==="cancelled").length,We=Wt+_t,nt=e.status==="in_progress",Tt=e.status==="blocked",Cn=Tt?qa(e,U=>o.find(de=>de.id===U)):void 0,kt=Cn==="hold",Ye=e.status==="completed",et=e.status==="failed",Xe=e.status==="rejected",dt=e.status==="cancelled",Kt=e.status==="archived",Nt=fr(e.status),St=e.taskType==="scheduled"&&!!e.scheduleConfig,Lt=St&&!!e.scheduleConfig?.paused,$t=(()=>{const U=n.find(de=>de.id===e.projectId);return U&&U.name!=="default"?U:void 0})(),Qt=s.find(U=>U.id===e.requirementId);return t.find(U=>U.id===e.assignedAgentId),r.jsxs("div",{className:`flex flex-col w-full overflow-hidden bg-surface-primary shadow-xl shadow-black/8 ring-1 ring-border-default/20 ${tt?"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:[tt&&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," ",r.jsx(h0,{stage:e.threadStage})," ",(()=>{const U=za(e.status,f,Cn);if(U)return r.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle ${U.cls}`,children:U.label});const de=g[e.status];return de?r.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium whitespace-nowrap align-middle ${de.cls}`,children:de.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:th(e.status,f)})})()]})]}),r.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[r.jsx(Qc,{onClick:()=>O(!0),label:f("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(pf,{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:()=>be("details"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${Y==="details"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:f("work:task.detailsTab")}),r.jsxs("button",{onClick:()=>be("activity"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${Y==="activity"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:[f("work:task.activityTab"),(nt||_h(Ce))&&r.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse"})]}),r.jsx("button",{onClick:()=>be("deliverables"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors flex items-center gap-1.5 ${Y==="deliverables"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:(()=>{const U=te.filter(de=>typeof de.reference=="string"&&de.reference.length>0).length;return U>0?f("work:task.deliverablesCount",{count:U}):f("work:task.deliverables")})()}),r.jsx("button",{onClick:()=>be("history"),className:`px-3 py-1.5 text-xs rounded-t-md transition-colors ${Y==="history"?"bg-surface-elevated text-fg-primary font-medium":"text-fg-tertiary hover:text-fg-secondary"}`,children:f("work:task.historyTab")})]}),r.jsxs("div",{className:"flex-1 min-h-0 relative",children:[r.jsxs("div",{ref:I,"data-swipe-owner":!0,className:"h-full overflow-y-auto overflow-x-hidden",onTouchStart:Ie.onTouchStart,onTouchEnd:Ie.onTouchEnd,children:[r.jsxs("div",{className:Y==="activity"?"min-w-0 min-h-full":"hidden",children:[Re&&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:f("work:task.failedToStart")})," ",Re]}),r.jsx(uy,{task:e,isRunning:e.status==="in_progress",authUser:c,agents:t,reviewSessions:Ce})]}),r.jsxs("div",{className:Y==="details"?"":"hidden",children:[r.jsx("div",{className:"px-6 pt-4 pb-3 border-b border-border-default",children:mt?r.jsx("textarea",{ref:pe,value:ue,onChange:U=>{me(U.target.value);const de=U.target;de.style.height="auto",de.style.height=de.scrollHeight+"px"},onBlur:()=>{ue!==e.description&&ye(()=>ee.tasks.update(e.id,{description:ue})),re(!1)},onKeyDown:U=>{U.key==="Escape"&&(U.preventDefault(),me(e.description),re(!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:f("work:task.addDescription")}):r.jsx("div",{ref:Ee,className:"group relative cursor-pointer rounded-lg -mx-2 px-2 -my-1 py-1 hover:bg-surface-elevated/50 transition-colors",onClick:U=>{U.target.closest("a, button, [data-entity-link]")||(Te.current=Math.max(Ee.current?.offsetHeight??80,60),me(e.description),re(!0))},role:"button",tabIndex:0,onKeyDown:U=>U.key==="Enter"&&(me(e.description),re(!0)),children:e.description?r.jsxs("div",{children:[r.jsx("div",{className:tt&&!ge?"line-clamp-3":"",children:r.jsx(dr,{content:e.description,className:"text-sm text-fg-secondary leading-relaxed"})}),tt&&e.description.length>150&&r.jsx("button",{onClick:U=>{U.stopPropagation(),Se(!ge)},className:"text-[11px] text-brand-500 mt-1 font-medium",children:f(ge?"work:task.collapse":"common:showMore")})]}):r.jsx("p",{className:"text-sm text-fg-tertiary italic",children:f("work:task.noDescription")})})}),($t||Qt)&&r.jsxs("div",{className:"px-6 py-2.5 border-b border-border-default flex flex-wrap items-center gap-2",children:[$t&&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 ${m?"cursor-pointer hover:bg-brand-500/20 transition-colors":""}`,onClick:m?()=>m($t.id):void 0,role:m?"button":void 0,tabIndex:m?0:void 0,onKeyDown:m?U=>U.key==="Enter"&&m($t.id):void 0,children:[r.jsx("span",{className:"text-[9px] text-brand-500/60",children:f("work:task.projectLabel")}),$t.name]}),Qt&&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(Qt):void 0,role:u?"button":void 0,tabIndex:u?0:void 0,onKeyDown:u?U=>U.key==="Enter"&&u(Qt):void 0,children:[r.jsx("span",{className:"text-[9px] text-brand-500/60",children:f("work:task.requirementLabel")}),Qt.title.length>40?Qt.title.slice(0,40)+"…":Qt.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:f("work:task.dependencies")})}),e.blockedBy&&e.blockedBy.length>0?r.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:e.blockedBy.map(U=>{const de=o.find(Oe=>Oe.id===U),De=de&&(de.status==="completed"||de.status==="cancelled");return r.jsxs("span",{className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded-full ${De?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:[r.jsx("span",{className:"text-[9px]",children:De?"✓":"⏳"}),r.jsx("span",{className:`font-mono ${De?"line-through opacity-60":""}`,children:de?de.title.slice(0,30):U.slice(-8)}),!Nt&&r.jsx("button",{onClick:async()=>{const Oe=(e.blockedBy??[]).filter(Ve=>Ve!==U);await ee.tasks.update(e.id,{blockedBy:Oe}),l()},className:"ml-0.5 text-current opacity-40 hover:opacity-100 transition-opacity",title:f("work:task.removeDependency"),children:"×"})]},U)})}):r.jsx("p",{className:"text-[11px] text-fg-tertiary mb-2",children:f("work:task.noDependencies")}),kt&&r.jsxs("div",{className:`flex items-center gap-1.5 px-2.5 py-1.5 border rounded-lg text-xs mb-2 ${cr.hold.card} ${kn.blocked.text}`,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:f("work:task.holdHint")})]}),!Nt&&r.jsx(Jb,{options:o.filter(U=>U.id!==e.id&&!(e.blockedBy??[]).includes(U.id)).map(U=>({value:U.id,label:U.title,status:U.status})),placeholder:f("work:task.addDependency"),noMatchesText:f("work:task.noMatches"),itemSuffix:U=>U.status==="completed"||U.status==="archived"?r.jsx("span",{className:"text-[9px] text-green-600 shrink-0",children:"✓"}):U.status==="cancelled"?r.jsx("span",{className:"text-[9px] text-fg-tertiary shrink-0",children:"✕"}):null,onSelect:async U=>{if(!U)return;const de=[...e.blockedBy??[],U];await ee.tasks.update(e.id,{blockedBy:de}),l()}})]}),r.jsx("div",{className:"px-6 py-4 border-b border-border-default/60",children:r.jsxs("div",{className:vu,children:[r.jsx("label",{className:at,children:f("work:task.projectLabel")}),r.jsx(Vt,{size:"sm",disabled:q,options:[{value:"",label:f("work:task.noProject")},...n.map(U=>({value:U.id,label:U.name}))],value:e.projectId??"",onChange:U=>{X(U)},placeholder:f("work:task.noProject"),noMatchesText:f("work:task.noMatches")}),r.jsx("label",{className:at,children:f("work:task.requirementLabel")}),r.jsx(Vt,{size:"sm",disabled:q,options:[{value:"",label:f("work:task.noRequirement")},...s.filter(U=>!e.projectId||U.projectId===e.projectId).map(U=>({value:U.id,label:U.title}))],value:e.requirementId??"",onChange:U=>ye(()=>ee.tasks.update(e.id,{requirementId:U||null})),placeholder:f("work:task.noRequirement"),noMatchesText:f("work:task.noMatches")}),r.jsx("label",{className:at,children:f("work:task.assignee")}),r.jsx(Vt,{size:"sm",disabled:q,options:[{value:"",label:f("work:task.unassigned")},...t.map(U=>({value:U.id,label:`${U.name} (${U.status})`}))],value:e.assignedAgentId??"",onChange:U=>{wt(U)},placeholder:f("work:task.unassigned"),noMatchesText:f("work:task.noMatches")}),r.jsx("label",{className:at,children:f("work:task.reviewer")}),r.jsx(Vt,{size:"sm",disabled:q,options:[...a.map(U=>({value:`human:${U.id}`,label:U.name})),...t.map(U=>({value:`agent:${U.id}`,label:`${U.name} (${U.status})`}))],value:`${e.reviewerType??"agent"}:${e.reviewerId??""}`,onChange:U=>{if(!U)return;const de=U.startsWith("human:"),De=U.replace(/^(human|agent):/,"");(De!==e.reviewerId||(de?"human":"agent")!==(e.reviewerType??"agent"))&&ye(()=>ee.tasks.update(e.id,{reviewerId:De,reviewerType:de?"human":"agent"}))},placeholder:f("work:task.selectReviewer"),noMatchesText:f("work:task.noMatches")}),r.jsx("label",{className:at,children:f("work:task.priority")}),r.jsx(Co,{value:e.priority,onChange:U=>{He(U)}})]})}),r.jsxs("div",{className:"px-6 py-3 border-b border-border-default/60 flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[11px] text-fg-tertiary",children:[e.createdBy&&r.jsx("span",{children:f("work:task.createdBy",{name:zs(e.createdBy,t,a)??e.createdBy})}),e.updatedBy&&r.jsx("span",{children:f("work:task.updatedBy",{name:zs(e.updatedBy,t,a)??e.updatedBy})}),e.createdAt&&r.jsx("span",{children:new Date(e.createdAt).toLocaleDateString()}),e.startedAt&&r.jsx("span",{children:f("work:task.started",{date:new Date(e.startedAt).toLocaleDateString()})}),e.updatedAt&&r.jsx("span",{children:f("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:f("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:[f("work:task.subtasks")," ",x.length>0&&r.jsxs("span",{className:"ml-1.5 text-fg-tertiary font-normal normal-case",children:[f("work:task.subtasksProgress",{done:Wt,total:x.length-_t}),_t>0?` · ${_t} cancelled`:""]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[We>0&&r.jsx("button",{onClick:()=>j(U=>!U),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?f("work:task.hideCompleted"):f("work:task.showCompleted",{count:We})}),r.jsx("button",{onClick:()=>k(!0),className:"text-xs text-brand-500 hover:text-brand-500 transition-colors",children:f("work:task.addSubtask")})]})]}),(()=>{const U=C?x:x.filter(de=>de.status!=="completed"&&de.status!=="cancelled");return U.length>0?r.jsx("div",{className:"space-y-1.5 mb-3",children:U.map(de=>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 ${de.status==="cancelled"?"opacity-50":""}`,children:[r.jsxs("button",{onClick:()=>{Le(de)},className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center transition-colors ${de.status==="completed"?"bg-green-600 border-green-600 text-white":de.status==="cancelled"?"bg-gray-500 border-gray-500 text-white":"border-gray-600 hover:border-brand-500"}`,children:[de.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"})}),de.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 ${de.status==="completed"?"line-through text-fg-tertiary":de.status==="cancelled"?"line-through text-fg-muted":"text-fg-secondary"}`,children:de.title}),r.jsx("button",{onClick:()=>S(de),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-tertiary hover:text-red-500 transition-all text-xs",children:"✕"})]},de.id))}):null})(),x.length===0&&!b&&r.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:f("work:task.noSubtasksYet")}),b&&r.jsxs("div",{className:"flex gap-2 mt-2",children:[r.jsx("input",{autoFocus:!0,value:v,onChange:U=>y(U.target.value),onKeyDown:U=>{U.key==="Enter"&&we(),U.key==="Escape"&&(k(!1),y(""))},placeholder:f("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:()=>{we()},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-on-brand text-xs rounded-lg",children:f("work:task.add")}),r.jsx("button",{onClick:()=>{k(!1),y("")},className:"px-3 py-1.5 border border-border-default text-xs rounded-lg hover:bg-surface-elevated",children:f("common:cancel")})]}),(()=>{const U=te.filter(Oe=>typeof Oe.reference=="string"&&Oe.reference.length>0);if(U.length===0)return null;const de={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},De=U.slice(0,3);return r.jsxs("div",{className:"mt-5",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("p",{className:"text-xs font-semibold text-fg-tertiary uppercase tracking-wider",children:f("work:task.deliverablesCount",{count:U.length})}),U.length>3&&r.jsx("button",{onClick:()=>be("deliverables"),className:"text-[10px] text-brand-500 hover:text-brand-500",children:f("work:task.viewAll")})]}),r.jsx("div",{className:"space-y-1.5",children:De.map(Oe=>{const Ve=/^https?:\/\//i.test(Oe.reference),Pt=Ve?Oe.summary||Oe.reference:Oe.reference.split("/").pop()??Oe.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 ${de[Oe.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Oe.type}),r.jsxs("div",{className:"flex-1 min-w-0",children:[Ve?r.jsxs("a",{href:Oe.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:Oe.reference,children:[Pt," ",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:()=>ft(Oe.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Oe.reference,children:Pt}),Oe.summary&&!Ve&&r.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Oe.summary}),r.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Oe.reference})]})]},Oe.id)})})]})})(),r.jsx(dy,{task:e,agents:t,users:a,authUser:c})]})]}),r.jsx("div",{className:Y==="history"?"":"hidden",children:r.jsx(kf,{entityType:"task",entityId:e.id,statusLabel:U=>g[U]?.label??U})}),r.jsxs("div",{className:Y==="deliverables"?"px-6 py-4":"hidden",children:[(e.evidence?.length??0)>0&&r.jsx(b0,{evidence:e.evidence??[],nameOf:U=>t.find(de=>de.id===U)?.name,onOpenSource:U=>{if(U.startsWith("dlv_")){Gt.navigate(st.DELIVERABLES,{openDeliverable:U});return}document.getElementById("task-activity")?.scrollIntoView({behavior:"smooth",block:"start"})}}),(()=>{const U=te.filter(Ve=>typeof Ve.reference=="string"&&Ve.reference.length>0);if(U.length===0)return r.jsx("div",{className:"flex items-center justify-center py-12 text-xs text-fg-tertiary",children:f("work:task.noDeliverablesYet")});const de={file:"bg-blue-500/15 text-blue-600",document:"bg-blue-500/15 text-blue-600",report:"bg-brand-500/15 text-brand-500",directory:"bg-green-500/15 text-green-600",url:"bg-brand-500/15 text-brand-500",text:"bg-gray-500/15 text-fg-secondary"},De=Math.ceil(U.length/Qe),Oe=U.slice((F-1)*Qe,F*Qe);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:f("work:task.deliverablesCount",{count:U.length})}),De>1&&r.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary",children:[r.jsx("button",{disabled:F<=1,onClick:()=>Z(Ve=>Ve-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,"/",De]}),r.jsx("button",{disabled:F>=De,onClick:()=>Z(Ve=>Ve+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:Oe.map(Ve=>{const Pt=/^https?:\/\//i.test(Ve.reference),an=Pt?Ve.summary||Ve.reference:Ve.reference.split("/").pop()??Ve.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 ${de[Ve.type]??"bg-gray-500/15 text-fg-secondary"}`,children:Ve.type}),r.jsxs("div",{className:"flex-1 min-w-0",children:[Pt?r.jsxs("a",{href:Ve.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:Ve.reference,children:[an," ",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:()=>ft(Ve.reference),className:"text-sm text-brand-500 hover:text-brand-500 font-medium truncate block max-w-full text-left hover:underline",title:Ve.reference,children:an}),Ve.summary&&!Pt&&r.jsx("p",{className:"text-[11px] text-fg-secondary mt-0.5 line-clamp-2",children:Ve.summary}),r.jsx("p",{className:"text-[10px] text-fg-tertiary font-mono truncate mt-0.5",children:Ve.reference})]})]},Ve.id)})})]})})()]})]}),V!=="none"&&V!=="top"&&r.jsx("button",{onClick:()=>I.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:f("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 U=I.current;U&&U.scrollTo({top:U.scrollHeight,behavior:"smooth"})},className:"absolute bottom-22 right-4 md:bottom-18 md:right-3 z-10 w-12 h-12 md:w-8 md:h-8 rounded-full bg-brand-500 md:bg-brand-600/90 border border-brand-400/60 shadow-xl shadow-brand-500/30 md:shadow-lg md:shadow-brand-500/20 flex items-center justify-center text-on-brand hover:bg-brand-400 transition-colors backdrop-blur-sm",title:f("work:task.scrollToBottom"),children:r.jsx("svg",{className:"w-6 h-6 md:w-4 md:h-4",viewBox:"0 0 20 20",fill:"currentColor",children:r.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})})]}),St&&e.scheduleConfig&&r.jsxs("div",{className:`mx-6 mt-3 mb-0 px-4 py-2.5 rounded-lg border text-xs ${Lt?"bg-amber-500/5 border-amber-500/20":"bg-brand-500/5 border-brand-500/20"} ${!nt&&!B&&!e.scheduleConfig.runAt?"cursor-pointer hover:border-brand-500/40 transition-colors":""}`,onClick:()=>{nt||B||e.scheduleConfig?.runAt||(R(Hh(e.scheduleConfig)),L(!0))},children:[r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.jsx("span",{className:Lt?"text-amber-600":"text-brand-500",children:Lt?f("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"})})," ",f("work:task.scheduled")]})}),r.jsx("span",{className:"text-fg-tertiary",children:"·"}),r.jsx("span",{className:"text-fg-secondary",children:e.scheduleConfig.every?f("work:task.scheduleEvery",{interval:e.scheduleConfig.every}):e.scheduleConfig.cron?f("work:task.scheduleCron",{expr:e.scheduleConfig.cron}):e.scheduleConfig.runAt?f("work:task.scheduleOneShot"):f("work:task.scheduleNA")}),!Lt&&e.scheduleConfig.nextRunAt&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"text-fg-tertiary",children:"·"}),r.jsx("span",{className:"text-fg-secondary",children:f("work:task.scheduleNext",{when:(()=>{const U=new Date(e.scheduleConfig.nextRunAt).getTime()-Date.now();if(U<=0)return f("work:task.scheduleDueNow");const de=Math.floor(U/6e4);if(de<60)return f("work:task.scheduleInMinutes",{count:de});const De=Math.floor(de/60);return De<24?f("work:task.scheduleInHoursMinutes",{h:De,m:de%60}):f("work:task.scheduleInDaysHours",{d:Math.floor(De/24),h:De%24})})()})})]}),!nt&&!B&&!e.scheduleConfig.runAt&&r.jsxs("svg",{className:"w-3 h-3 text-brand-500 ml-auto shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),r.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})]}),B&&$?r.jsxs("div",{className:"mt-2 pt-2 border-t border-border-default/50 space-y-2",onClick:U=>U.stopPropagation(),children:[r.jsx(dd,{value:$,onChange:R,compact:!0}),r.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[r.jsx("button",{onClick:async()=>{await ye(()=>ee.tasks.updateSchedule(e.id,cd($))),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:f("common:save")}),r.jsx("button",{onClick:()=>L(!1),className:"px-3 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:f("common:cancel")})]})]}):r.jsxs("div",{className:"flex items-center gap-2 mt-1 text-fg-tertiary",children:[r.jsx("span",{children:f("work:task.scheduleRuns",{current:e.scheduleConfig.currentRuns??0,max:e.scheduleConfig.maxRuns&&e.scheduleConfig.maxRuns>0?f("work:task.scheduleRunsMax",{max:e.scheduleConfig.maxRuns}):""})}),e.scheduleConfig.lastRunAt&&r.jsxs(r.Fragment,{children:[r.jsx("span",{children:"·"}),r.jsx("span",{children:f("work:task.scheduleLast",{when:(()=>{const U=Date.now()-new Date(e.scheduleConfig.lastRunAt).getTime(),de=Math.floor(U/6e4);if(de<1)return f("work:task.noteTimeJustNow");if(de<60)return f("work:task.noteTimeMinutes",{count:de});const De=Math.floor(de/60);return De<24?f("work:task.noteTimeHours",{count:De}):f("work:task.noteTimeDays",{count:Math.floor(De/24)})})()})})]})]})]}),e.status==="review"&&fl(Ce)&&(()=>{const U=fl(Ce),de=U.reviewerType==="human";return 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${de?"":" animate-pulse"}`}),r.jsx("div",{className:"min-w-0 flex-1 text-xs text-fg-primary",children:U.reviewerName?de?f("work:task.reviewWaitingFor",{name:U.reviewerName}):f("work:task.reviewInProgressBy",{agent:U.reviewerName}):f("work:task.reviewInProgress")}),r.jsx("button",{onClick:()=>be("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:f("work:task.reviewViewSession")})]})})(),r.jsx("div",{className:"px-6 py-4 border-t border-border-default flex items-center justify-between gap-2",children:r.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.status==="pending"&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{if(St){qe(!0);return}ye(()=>ee.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_")?f("work:task.startExecution"):f("work:task.approve")}),e.createdBy&&!e.createdBy.startsWith("agt_")?r.jsx("button",{onClick:async()=>{const{count:U}=await ee.tasks.getDependentCount(e.id);P({dependentCount:U})},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:f("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:f("work:task.reject")})]}),e.status==="review"&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{ye(()=>ee.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:f("work:task.approveCheck")}),se?r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("input",{type:"text",value:fe,onChange:U=>Q(U.target.value),onKeyDown:U=>{U.key==="Enter"&&fe.trim()&&(ye(()=>ee.tasks.revision(e.id,fe.trim(),c?.id)),le(!1),Q(""))},placeholder:f("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:()=>{ye(()=>ee.tasks.revision(e.id,fe.trim()||f("work:task.revisionsNeededDefault"),c?.id)),le(!1),Q("")},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:f("common:send")}),r.jsx("button",{onClick:()=>{le(!1),Q("")},className:"px-1.5 py-1 text-xs text-fg-secondary hover:text-fg-primary",children:"✕"})]}):r.jsx("button",{onClick:()=>le(!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:f("work:task.requestRevision")})]}),nt&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>{ie()},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"})]}),f("work:task.pause")]}),r.jsxs("button",{onClick:()=>{lt()},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"})]}),f("work:task.retry")]})]}),Tt&&r.jsx("button",{onClick:()=>{je()},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:f("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"})}),f("work:task.resume")]})}),et&&!St&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>{lt()},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"})]}),f("work:task.retry")]}),r.jsxs("button",{onClick:()=>{pt()},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"})}),f("work:task.continueTask")]})]}),St&&(Ye||et||dt)&&!Kt&&r.jsx("button",{onClick:()=>{It()},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:f("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"})}),f("work:task.runNow")]})}),St&&!nt&&!Kt&&!Xe&&(Lt?r.jsx("button",{onClick:()=>{ye(()=>ee.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:f("work:task.resumeSchedule")}):r.jsx("button",{onClick:()=>{ye(()=>ee.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:f("work:task.pauseSchedule")})),(Ye||et||Xe||dt)&&r.jsx("button",{onClick:()=>E(!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:f("work:task.archive")}),Ye&&!St&&r.jsx("button",{onClick:()=>{pt()},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:f("work:task.reopen")}),!Nt&&e.status!=="pending"&&r.jsx("button",{onClick:async()=>{const{count:U}=await ee.tasks.getDependentCount(e.id);P({dependentCount:U})},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:f("work:task.cancelTask")})]})}),A&&r.jsx(js,{title:f("work:task.deleteSubtaskTitle",{title:A.title}),message:f("work:task.deleteSubtaskMessage"),confirmLabel:f("common:delete"),onConfirm:()=>{ke(A)},onCancel:()=>S(null)}),M&&r.jsx(js,{title:f("work:task.rejectConfirmTitle"),message:f("work:task.rejectConfirmMessage"),confirmLabel:f("work:task.reject"),onConfirm:()=>{D(!1),ye(()=>ee.tasks.reject(e.id))},onCancel:()=>D(!1)}),z&&r.jsx(js,{title:f("work:task.archiveConfirmTitle"),message:f(St?"work:task.archiveScheduledConfirmMessage":"work:task.archiveConfirmMessage"),confirmLabel:f("work:task.archive"),onConfirm:()=>{E(!1),ye(()=>ee.tasks.archive(e.id))},onCancel:()=>E(!1)}),T&&T.dependentCount>0?r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>P(null),children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 max-w-md w-full shadow-2xl",onClick:U=>U.stopPropagation(),children:[r.jsx("h3",{className:"text-base font-semibold text-fg-primary mb-2",children:f("work:task.cancelTaskModalTitle")}),r.jsxs("p",{className:"text-sm text-fg-secondary mb-4",children:[St&&r.jsx(r.Fragment,{children:r.jsx("span",{className:"block mb-1 text-amber-600",children:f("work:task.cancelScheduledConfirmMessage")})}),f("work:task.cancelTaskDependent",{count:T.dependentCount})]}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsxs("button",{onClick:()=>{P(null),ye(()=>ee.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:f("work:task.cancelTaskOnly")}),r.jsx("span",{className:"block text-xs text-fg-tertiary mt-0.5",children:f("work:task.cancelTaskOnlyHint")})]}),r.jsxs("button",{onClick:()=>{P(null),ye(()=>ee.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:f("work:task.cancelWithDependents")}),r.jsx("span",{className:"block text-xs text-red-500/70 mt-0.5",children:f("work:task.cancelWithDependentsHint",{count:T.dependentCount})})]}),r.jsx("button",{onClick:()=>P(null),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:f("work:task.keepTaskRunning")})]})]})}):T&&r.jsx(js,{title:f("work:task.cancelTaskModalTitle"),message:f(St?"work:task.cancelScheduledConfirmMessage":"work:task.cancelConfirmMessage"),confirmLabel:f("work:task.cancelTask"),onConfirm:()=>{P(null),ye(()=>ee.tasks.cancel(e.id))},onCancel:()=>P(null)}),Ge&&r.jsx(fy,{filePath:Ge,onClose:()=>ft(null),onOpenExternal:()=>{ft(null),ee.deliverables.search({taskId:e.id,limit:100}).then(({results:U})=>{const de=U.find(De=>De.reference===Ge);de?Gt.navigate(st.DELIVERABLES,{openDeliverable:de.id}):Gt.navigate(st.DELIVERABLES)}).catch(()=>Gt.navigate(st.DELIVERABLES))}}),Et&&e.scheduleConfig&&r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[60]",onClick:()=>qe(!1),children:r.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 w-[380px] shadow-2xl",onClick:U=>U.stopPropagation(),children:[r.jsx("h3",{className:"font-semibold text-base mb-2",children:f("work:task.scheduleApproveTitle")}),r.jsx("p",{className:"text-sm text-fg-secondary mb-5 leading-relaxed",children:f("work:task.scheduleApproveDesc",{schedule:e.scheduleConfig.cron?`Cron: ${e.scheduleConfig.cron}`:e.scheduleConfig.every?f("work:task.scheduleEvery",{interval:e.scheduleConfig.every}):"",nextRun:e.scheduleConfig.nextRunAt?new Date(e.scheduleConfig.nextRunAt).toLocaleString():f("work:task.scheduleNA")})}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsx("button",{disabled:q,onClick:()=>{qe(!1),ye(()=>ee.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:f("work:task.scheduleApproveRunNow")}),r.jsx("button",{disabled:q,onClick:()=>{qe(!1),ye(()=>ee.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:f("work:task.scheduleApproveWait")}),r.jsx("button",{onClick:()=>qe(!1),className:"w-full px-4 py-2 text-sm text-fg-tertiary hover:text-fg-secondary",children:f("common:cancel")})]})]})})]})}function hy({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]),h=p.useMemo(()=>new Set(l.map(M=>M.assignedAgentId).filter(Boolean)),[l]),u=p.useMemo(()=>s.filter(M=>h.has(M.id)),[s,h]),[m,f]=p.useState(!1),[g,x]=p.useState(""),[w,v]=p.useState("main"),[y,b]=p.useState(!1),[k,C]=p.useState(!1),{t:j}=ze(["work","common"]),A=[{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){b(!0);try{await a({status:M}),i()}finally{b(!1)}}},T=async()=>{const M=g.trim();if(!M)return;const D=[...e.repositories??[],{url:"",localPath:M,defaultBranch:w||"main"}];await a({repositories:D}),x(""),v("main"),f(!1),i()},P=async M=>{const D=(e.repositories??[]).filter((z,E)=>E!==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(ty,{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:A.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(wn,{label:j("work:project.statTotal"),value:d.total,color:"text-fg-primary"}),r.jsx(wn,{label:j("work:project.statCompleted"),value:d.completed,color:"text-green-600"}),r.jsx(wn,{label:j("work:project.statInProgress"),value:d.inProgress,color:"text-brand-500"}),r.jsx(wn,{label:j("work:project.statInReview"),value:d.inReview,color:"text-brand-500"}),r.jsx(wn,{label:j("work:project.statBlocked"),value:d.blocked,color:"text-amber-600"}),r.jsx(wn,{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(wn,{label:j("work:project.statTotal"),value:d.reqs,color:"text-fg-primary"}),r.jsx(wn,{label:j("work:project.statCompleted"),value:d.reqsDone,color:"text-green-600"}),r.jsx(wn,{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(E=>E.assignedAgentId===M.id),z=D.filter(E=>!fr(E.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:()=>f(!m),className:"text-[10px] text-brand-500 hover:text-brand-500",children:j(m?"common:cancel":"work:project.addRepo")})]}),(e.repositories??[]).length===0&&!m&&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:()=>P(D),className:"text-fg-tertiary hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",title:j("work:project.removeRepo"),children:r.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},D)),m&&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=>x(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:w,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:T,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(j0,{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")})]}),k&&r.jsx(js,{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 wn({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 mo={pending:"todo",in_progress:"in_progress",completed:"done",rejected:"closed",cancelled:"closed",archived:"closed"},yf={failed:"rejected",todo:"pending",in_progress:"in_progress",review:"in_progress",done:"completed",closed:"cancelled"},my={urgent:0,high:1,medium:2,low:3},Io={failed:0,todo:1,in_progress:2,review:3,done:4,closed:5},Fc={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"},py={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 wf(e){for(const t of Eo)if(t.statuses.includes(e))return t.id;return"closed"}function Hc(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,display:o}){const[a,i]=p.useState(!1),l=p.useRef(null),c=p.useRef(null),d=t.find(u=>u.value===e),h=o??d;return p.useEffect(()=>{if(!a)return;const u=m=>{c.current&&!c.current.contains(m.target)&&l.current&&!l.current.contains(m.target)&&i(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[a]),r.jsxs("div",{className:"relative",children:[r.jsx("button",{ref:l,onClick:()=>i(u=>!u),className:`text-[11px] px-2 py-0.5 rounded-full font-medium transition-colors cursor-pointer hover:ring-1 hover:ring-current/30 ${h?.cls??"bg-gray-500/15 text-fg-tertiary"}`,children:h?.label??e}),a&&r.jsx("div",{ref:c,className:"absolute top-full left-0 mt-1 w-40 bg-surface-overlay border border-border-default rounded-lg shadow-xl z-50 py-1 max-h-64 overflow-y-auto",children:t.map(u=>{const m=u.value===e,f=m||!s||s.has(u.value);return r.jsxs("button",{disabled:!f,onClick:()=>{!m&&f&&n(u.value),i(!1)},className:`w-full text-left px-3 py-1.5 text-[11px] flex items-center gap-2 transition-colors ${m?"bg-surface-elevated":f?"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 ${f?u.cls.split(" ")[0]:"bg-gray-600"}`}),r.jsx("span",{className:`font-medium ${m?"text-fg-primary":f?"text-fg-secondary":"text-fg-muted"}`,children:u.label}),m&&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"})})]},u.value)})})]})}function gy({onQuickCreateReq:e,onQuickCreateTask:t}){const{t:n}=ze(["work","common"]),[s,o]=p.useState("req"),[a,i]=p.useState(!1),[l,c]=p.useState(""),d=p.useRef(null),h=p.useRef(null);p.useEffect(()=>{a&&(d.current?.focus({preventScroll:!0}),h.current?.scrollIntoView({block:"nearest",inline:"start"}))},[a]);const u=()=>{const m=l.trim();c(""),i(!1),m&&(s==="req"?e(m):t(m))};return r.jsxs("div",{ref:h,className:"flex items-center gap-2 px-3 md:px-6 py-2.5 md:py-2 border-l-2 border-l-transparent hover:bg-surface-elevated/30 transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx("button",{type:"button",onMouseDown:m=>m.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:m=>m.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:m=>c(m.target.value),onKeyDown:m=>{m.key==="Enter"?u():m.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 Vc({row:e,idx:t,dragIdx:n,agentMap:s,projMap:o,onTaskClick:a,onReqClick:i,onRowDragStart:l,onRowDragEnd:c,handleStatusChange:d,handlePriorityChange:h,selected:u,isMobile:m,blockedReason:f}){const{t:g}=ze(["work","common"]),x=p.useMemo(()=>xf(g),[g]),w=p.useMemo(()=>Si(g),[g]),v=p.useMemo(()=>ly(g),[g]),y=e.data.status,b=e.data.priority,k=f==="hold",C=e.kind==="task"?za(y,g,f)??void 0:void 0,j=e.kind==="task"?s.get(e.data.assignedAgentId??""):void 0,A=(()=>{const T=o.get((e.kind==="task",e.data.projectId??""));return T&&T.name!=="default"?T:void 0})(),S=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 m?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 ${Fc[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:[S,k&&r.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded font-semibold ${cr.hold.chip}`,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:T=>T.stopPropagation(),children:r.jsx(ro,{value:y,display:C,options:e.kind==="task"?$c.map(T=>({value:T,label:x[T]?.label??T,cls:x[T]?.cls??"bg-gray-500/15 text-fg-tertiary"})):Pc.map(T=>({value:T,label:w[T]?.label??T,cls:w[T]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?Cc[y]:No[y],onSelect:T=>{d(e,T)}})}),r.jsx("div",{onClick:T=>T.stopPropagation(),children:r.jsx(ro,{value:b,options:Oc.map(T=>({value:T,label:v[T]?.label??T,cls:v[T]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:T=>{h(e,T)}})}),j&&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 ${es[j.status]??"bg-gray-500"}`}),r.jsx("span",{className:`${Bc[j.status]??"text-fg-secondary"}`,children:j.name})]}),A?.name&&r.jsx("span",{className:"text-[10px] text-brand-400/70 truncate max-w-[80px]",children:A.name}),r.jsx("span",{className:"text-[9px] text-fg-muted ml-auto",children:Hc(e.data.updatedAt??"",g)})]})]}):r.jsxs("div",{"data-work-item-id":e.data.id,draggable:!0,onDragStart:T=>l(T,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 ${Fc[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:S}),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}),k&&r.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded font-semibold shrink-0 ${cr.hold.chip}`,children:"⚠"})]}),r.jsx("div",{className:"w-[130px] shrink-0",onClick:T=>T.stopPropagation(),children:r.jsx(ro,{value:y,display:C,options:e.kind==="task"?$c.map(T=>({value:T,label:x[T]?.label??T,cls:x[T]?.cls??"bg-gray-500/15 text-fg-tertiary"})):Pc.map(T=>({value:T,label:w[T]?.label??T,cls:w[T]?.cls??"bg-gray-500/15 text-fg-tertiary"})),allowedValues:e.kind==="task"?Cc[y]:No[y],onSelect:T=>{d(e,T)}})}),r.jsx("div",{className:"w-[100px] shrink-0",onClick:T=>T.stopPropagation(),children:r.jsx(ro,{value:b,options:Oc.map(T=>({value:T,label:v[T]?.label??T,cls:v[T]?.cls??"bg-gray-500/15 text-fg-tertiary"})),onSelect:T=>{h(e,T)}})}),r.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:j?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 ${es[j.status]??"bg-gray-500"}`}),r.jsx("span",{className:`font-medium ${Bc[j.status]??"text-fg-secondary"}`,children:j.name})]}):r.jsx("span",{className:"text-fg-muted",children:"—"})}),r.jsx("div",{className:"w-[120px] shrink-0 text-[11px] truncate",children:A?.name?r.jsx("span",{className:"text-brand-400/70",children:A.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:Hc(e.data.updatedAt??"",g)})]})}function xy({tasks:e,requirements:t,agents:n,projects:s,onTaskClick:o,onReqClick:a,onRefresh:i,selectedTaskId:l,selectedReqId:c,onQuickCreateReq:d,onQuickCreateTask:h,onLoadMore:u,hasMore:m,loadingMore:f}){const{t:g}=ze(["work","common"]),x=wr(),[w,v]=p.useState("status"),[y,b]=p.useState(null),[k,C]=p.useState(null),j=p.useMemo(()=>{const O=new Map;for(const Y of e)O.set(Y.id,Y);return O},[e]),A=p.useCallback(O=>{if(O.status==="blocked")return qa(O,Y=>j.get(Y))},[j]),S=p.useMemo(()=>{const O=[];for(const Y of e){const _=wf(Y.status);O.push({kind:"task",data:Y,group:_,groupOrder:Io[_]??5})}for(const Y of t){const _=mo[Y.status]??"todo";O.push({kind:"req",data:Y,group:_,groupOrder:Io[_]??5})}if(w==="status")O.sort((Y,_)=>{if(Y.groupOrder!==_.groupOrder)return Y.groupOrder-_.groupOrder;const I=new Date(Y.data.updatedAt??0).getTime();return new Date(_.data.updatedAt??0).getTime()-I});else{const Y=_=>my[_.data.priority]??2;O.sort((_,I)=>{const V=Y(_),W=Y(I);return V!==W?V-W:new Date(I.data.updatedAt??0).getTime()-new Date(_.data.updatedAt??0).getTime()})}return O},[e,t,w]),T=async(O,Y)=>{try{O.kind==="task"?await ee.tasks.updateStatus(O.data.id,Y):await ee.requirements.updateStatus(O.data.id,Y),i()}catch{}},P=async(O,Y)=>{try{O.kind==="task"?await ee.tasks.update(O.data.id,{priority:Y}):await ee.requirements.update(O.data.id,{priority:Y}),i()}catch{}},M=(O,Y)=>{b(Y),O.dataTransfer.effectAllowed="move",O.dataTransfer.setData("text/plain",String(Y)),O.currentTarget.style.opacity="0.4"},D=O=>{O.currentTarget.style.opacity="1",b(null),C(null)},z=(O,Y)=>{O.preventDefault(),O.dataTransfer.dropEffect="move",k!==Y&&C(Y)},E=async(O,Y)=>{if(O.preventDefault(),C(null),y==null)return;const _=S[y];if(!_||_.group===Y)return;const I=Eo.find(V=>V.id===Y);if(I){try{if(_.kind==="task"){if(_.data.status==="pending")return;await ee.tasks.updateStatus(_.data.id,I.dropStatus)}else{const V=yf[Y];V&&await ee.requirements.updateStatus(_.data.id,V)}i()}catch{}b(null)}},B=p.useMemo(()=>new Map(n.map(O=>[O.id,O])),[n]),L=p.useMemo(()=>new Map(s.map(O=>[O.id,O])),[s]),$=["todo","in_progress","review","done"],R=p.useMemo(()=>{const O={};for(const Y of S)O[Y.group]=(O[Y.group]??0)+1;return O},[S]),{rowsByGroup:q,rowIndexMap:H}=p.useMemo(()=>{const O=new Map,Y=new Map;for(let _=0;_<S.length;_++){const I=S[_];Y.set(I,_);const V=O.get(I.group)??[];V.push(I),O.set(I.group,V)}return{rowsByGroup:O,rowIndexMap:Y}},[S]),K=p.useMemo(()=>{if(w!=="status")return null;const O=new Set(S.map(I=>I.group)),Y=[],_=new Set;O.has("failed")&&(Y.push("failed"),_.add("failed"));for(const I of $)Y.push(I),_.add(I);for(const I of S)_.has(I.group)||(Y.push(I.group),_.add(I.group));return Y},[S,w]);return r.jsx("div",{className:`flex-1 min-h-0 overflow-auto bg-surface-primary ${x?"overflow-x-hidden w-full":""}`,onScroll:O=>{if(!u||!m)return;const Y=O.currentTarget;Y.scrollTop+Y.clientHeight>=Y.scrollHeight-240&&u()},children:r.jsxs("div",{className:x?"w-full":"w-fit min-w-full",children:[!x&&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 ${w==="status"?"text-brand-500":"hover:text-fg-secondary"}`,children:[g("work:filters.status")," ",w==="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 ${w==="priority"?"text-brand-500":"hover:text-fg-secondary"}`,children:[g("work:filters.priority")," ",w==="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:[w==="status"&&K?K.map(O=>{const Y=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 ${py[O]??""} ${k===O?"ring-1 ring-brand-500/40":""}`,onDragOver:_=>z(_,O),onDragLeave:()=>C(null),onDrop:_=>{E(_,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:R[O]??0})]}),Y.map(_=>r.jsx(Vc,{row:_,idx:H.get(_)??0,dragIdx:y,agentMap:B,projMap:L,onTaskClick:o,onReqClick:a,onRowDragStart:M,onRowDragEnd:D,handleStatusChange:T,handlePriorityChange:P,selected:_.kind==="task"?_.data.id===l:_.data.id===c,isMobile:x,blockedReason:_.kind==="task"?A(_.data):void 0},`${_.kind}-${_.data.id}`)),O==="todo"&&r.jsx(gy,{onQuickCreateReq:d,onQuickCreateTask:h})]},O)}):S.map((O,Y)=>r.jsx(Vc,{row:O,idx:Y,dragIdx:y,agentMap:B,projMap:L,onTaskClick:o,onReqClick:a,onRowDragStart:M,onRowDragEnd:D,handleStatusChange:T,handlePriorityChange:P,selected:O.kind==="task"?O.data.id===l:O.data.id===c,isMobile:x,blockedReason:O.kind==="task"?A(O.data):void 0},`${O.kind}-${O.data.id}`)),f&&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","正在加载更多…")]}),!f&&m&&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 Ba(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,60)||"workflow"}function by(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=Ba(l.title).replace(/[^a-z0-9-]/g,"").slice(0,30)||"step";o.has(c)&&(c=`${c}-${l.id.slice(-4)}`),o.add(c),n.set(l.id,c)}const a=new Map,i=new Set;for(const l of e){const c=l.assignedAgentId;if(c&&!a.has(c)){const d=t[c]??"worker";let h=Ba(d).replace(/[^a-z0-9-]/g,"")||"worker";i.has(h)&&(h=`${h}-${c.slice(-4)}`),i.add(h),a.set(c,h)}}return e.map(l=>({id:n.get(l.id),name:l.title,role:a.get(l.assignedAgentId)??"worker",prompt:l.description||l.title,depends_on:(l.blockedBy??[]).filter(c=>s.has(c)).map(c=>n.get(c)).filter(Boolean)}))}function oo(e){return/[:#\[\]{}&*!|>'"%@`\n]/.test(e)||e.startsWith(" ")||e.endsWith(" ")?JSON.stringify(e):e}function yy(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 wy({req:e,tasks:t,agents:n,teamId:s,onClose:o,onSaved:a}){const{t:i}=ze(["work"]),l=p.useMemo(()=>{const T={};for(const P of n)T[P.id]=P.name;return T},[n]),c=p.useMemo(()=>by(t,l),[t,l]),[d,h]=p.useState(()=>Ba(e.title)),[u,m]=p.useState(e.description||e.title),[f,g]=p.useState(c),[x,w]=p.useState(!1),[v,y]=p.useState(null),b=(T,P,M)=>{g(D=>D.map((z,E)=>E===T?{...z,[P]:M}:z))},k=T=>{const P=f[T]?.id;g(M=>M.filter((D,z)=>z!==T).map(D=>({...D,depends_on:D.depends_on.filter(z=>z!==P)})))},[C,j]=p.useState(!1),A=async()=>{if(d.trim()){w(!0),y(null);try{const T=yy(d.trim(),u,f);await ee.workflows.create(s,d.trim(),T),j(!0),setTimeout(()=>a(),800)}catch(T){y(String(T))}w(!1)}},S=p.useMemo(()=>[...new Set(f.map(T=>T.role))],[f]);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:T=>T.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:T=>h(T.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(T=>r.jsx("span",{className:"px-2 py-0.5 text-[10px] font-medium bg-brand-500/10 text-brand-500 rounded-full",children:T},T))})]})]}),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:T=>m(T.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")," (",f.length,")"]}),r.jsx("div",{className:"space-y-2",children:f.map((T,P)=>r.jsx("div",{className:"bg-surface-secondary border border-border-default/40 rounded-xl p-3 group",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"shrink-0 w-7 h-7 rounded-full bg-brand-500/15 flex items-center justify-center text-[11px] font-bold text-brand-500 mt-0.5",children:P+1}),r.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{value:T.name,onChange:M=>b(P,"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:T.role,onChange:M=>b(P,"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")})]}),T.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"),":"]}),T.depends_on.map(M=>{const D=f.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:T.prompt})]}),r.jsx("button",{onClick:()=>k(P),className:"shrink-0 opacity-0 group-hover:opacity-100 text-fg-muted hover:text-red-500 p-1 rounded transition-all",title:i("work:task.removeStep","Remove step"),children:r.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})},T.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:A,disabled:x||C||!d.trim()||f.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:x?i("work:task.saving","Saving..."):C?i("work:task.workflowSavedSuccess","Saved!"):i("work:task.saveWorkflow","Save Workflow")})]})]})})}function Wc({teamId:e,agents:t,compact:n}){const{t:s}=ze(["work"]),o=p.useMemo(()=>e?t.find(i=>i.teamId===e&&i.agentRole==="manager"):t.find(i=>i.agentRole==="manager"),[t,e]),a=()=>{o&&Gt.navigate(st.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 ky({teamId:e,defaultTeamId:t,projectId:n,agents:s,users:o,projects:a,onViewRunTasks:i}){const{t:l}=ze(["work"]),[c,d]=p.useState([]),[h,u]=p.useState({}),[m,f]=p.useState(!1),[g,x]=p.useState(null),[w,v]=p.useState({}),[y,b]=p.useState(!1),[k,C]=p.useState(null),[j,A]=p.useState([]),[S,T]=p.useState(()=>{try{const X=localStorage.getItem(Ic);if(X)return X===Tc?null:X}catch{}return t??null}),[P,M]=p.useState(()=>zb(X=>{try{return localStorage.getItem(X)}catch{return null}})),[D,z]=p.useState({}),[E,B]=p.useState({}),[L,$]=p.useState({}),[R,q]=p.useState({}),[H,K]=p.useState(null),[O,Y]=p.useState(null),[_,I]=p.useState(null),[V,W]=p.useState(null),[F,Z]=p.useState(null),[te,ce]=p.useState(null),[oe,be]=p.useState([]),[Ne,Ie]=p.useState({}),[Ce,Fe]=p.useState(null),[Be,Re]=p.useState({}),$e=e??S,Et=X=>{if(X!==S){T(X),d([]),u({});try{localStorage.setItem(Ic,X??Tc)}catch{}}};p.useEffect(()=>{e||ee.teams.list().then(({teams:X})=>{A(X.map(ie=>({id:ie.id,name:ie.name})))}).catch(()=>{})},[e]),p.useMemo(()=>{const X={};for(const ie of s)X[ie.id]=ie.name;return X},[s]);const qe=p.useCallback(async()=>{const X=$e?[$e]:j.map(ie=>ie.id);if(X.length!==0){f(!0);try{const ie=[],xe={},je={};await Promise.all(X.map(async we=>{try{const{workflows:Le}=await ee.workflows.list(we);for(const ke of Le)je[ke.name]=we;ie.push(...Le),await Promise.all(Le.map(async ke=>{try{const{runs:pt}=await ee.workflows.listRuns(we,ke.name,5);xe[ke.name]=pt}catch{}}))}catch{}})),d(ie),u(xe),Re(je)}catch{}f(!1)}},[$e,j]);p.useEffect(()=>{qe()},[qe]);const Ge=X=>$e??Be[X],ft=p.useCallback(X=>{M(X),Fb(X,(ie,xe)=>{try{localStorage.setItem(ie,xe)}catch{}})},[]),mt=X=>{const ie=new Set(P);ie.has(X)?ie.delete(X):ie.add(X),ft(ie)},re=X=>B(ie=>({...ie,[X]:"idle"}));p.useEffect(()=>{for(const X of P){if(D[X]||E[X]==="loading"||E[X]==="error")continue;const ie=Ge(X);ie&&(B(xe=>({...xe,[X]:"loading"})),ee.workflows.get(ie,X).then(({template:xe,yaml:je})=>{z(we=>({...we,[X]:{...xe,yaml:je}})),B(we=>({...we,[X]:"ready"}))}).catch(()=>B(xe=>({...xe,[X]:"error"}))))}},[P,D,E,$e,Be]);const ue=p.useRef(new Set),me=p.useCallback(async X=>{if(!(!X.requirementId||ue.current.has(X.id))){ue.current.add(X.id),q(ie=>({...ie,[X.id]:!0}));try{const{tasks:ie}=await ee.tasks.list({requirementId:X.requirementId,pageSize:200}),xe=new Set(X.taskIds),je=xe.size>0?ie.filter(we=>xe.has(we.id)):ie;$(we=>({...we,[X.id]:je.map(Le=>({id:Le.id,title:Le.title,status:Le.status,workflowStepId:Le.workflowStepId,workflowRunId:Le.workflowRunId}))}))}catch{$(ie=>({...ie,[X.id]:[]}))}finally{ue.current.delete(X.id),q(ie=>({...ie,[X.id]:!1}))}}},[]);p.useEffect(()=>{for(const X of c){const ie=(h[X.name]??[])[0];ie&&L[ie.id]===void 0&&!R[ie.id]&&me(ie)}},[c,h,L,R,me]);const Ee=p.useMemo(()=>{const X=[];for(const ie of Object.values(h))for(const xe of ie)yi(xe.status)&&X.push(xe.id);return X.sort().join(",")},[h]);p.useEffect(()=>{if(!Ee)return;const X=window.setInterval(()=>{document.hidden||qe()},4e3);return()=>window.clearInterval(X)},[Ee,qe]);const pe=async(X,ie)=>{const xe=D[ie.name]?.yaml;if(I({mode:X,workflow:ie,yaml:xe,yamlLoading:X!=="delete"&&!xe,error:null}),X==="delete"||xe)return;const je=Ge(ie.name);if(!je){I(we=>we&&{...we,yamlLoading:!1,error:l("work:task.workflowNoTeam","无法确定此工作流所属的团队")});return}try{const{template:we,yaml:Le}=await ee.workflows.get(je,ie.name);z(ke=>({...ke,[ie.name]:{...we,yaml:Le}})),B(ke=>({...ke,[ie.name]:"ready"})),I(ke=>ke&&ke.workflow.name===ie.name?{...ke,yaml:Le,yamlLoading:!1}:ke)}catch(we){I(Le=>Le&&{...Le,yamlLoading:!1,error:we instanceof Error?we.message:String(we)})}},Te=async({name:X,yaml:ie})=>{if(!_)return;const xe=Ge(_.workflow.name);if(!xe){I(je=>je&&{...je,error:l("work:task.workflowNoTeam","无法确定此工作流所属的团队")});return}I(je=>je&&{...je,busy:!0,error:null});try{if(_.mode==="edit")await ee.workflows.update(xe,_.workflow.name,ie??"");else if(_.mode==="duplicate"){const we=X??"",Le=Hb(ie??"",we,kc,vc);await ee.workflows.create(xe,we,Le)}else await ee.workflows.remove(xe,_.workflow.name);const je=_.workflow.name;I(null),z(we=>{const Le={...we};return delete Le[je],Le}),B(we=>({...we,[je]:"idle"})),Ft(),await qe()}catch(je){I(we=>we&&{...we,busy:!1,error:je instanceof Error?je.message:String(je)})}},se=X=>{const ie={};for(const Le of X.params??[])Le.default&&(ie[Le.name]=Le.default);v(ie),C(null),be([]),Ie({});const xe=localStorage.getItem(`markus_wf_project_${X.name}`)??localStorage.getItem("markus_wf_project_last"),je=xe&&a.some(Le=>Le.id===xe)?xe:null;Fe(n??je??a[0]?.id??null),x(X);const we=Ge(X.name);we&&ee.workflows.roles(we,X.name).then(({roles:Le})=>be(Le)).catch(()=>{})},le=async()=>{const X=Ce??a[0]?.id,ie=g?Ge(g.name):void 0;if(!g||!ie||!X){C(X?l("work:task.workflowNoTeam","Cannot determine team for this workflow"):l("work:task.workflowNoProject","Please select a project"));return}b(!0),C(null);try{let xe;if(oe.length>0){xe={};for(const je of oe)xe[je.role]=Ne[je.role]??je.recommended??""}await ee.workflows.startRun(ie,g.name,X,w,xe),localStorage.setItem(`markus_wf_project_${g.name}`,X),localStorage.setItem("markus_wf_project_last",X),x(null),qe()}catch(xe){C(String(xe))}b(!1)};if(!$e&&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(m&&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 fe=async X=>{W(X),Z(null);try{await ee.workflows.cancelRun(X),qe()}catch{}W(null)},Q=async X=>{ce(X.id);try{X.status==="running"?await ee.workflows.pauseRun(X.id):X.status==="paused"&&await ee.workflows.resumeRun(X.id),qe()}catch{}ce(null)},ge=X=>{X.requirementId&&i&&i(X.requirementId)},Se=g&&(g.params??[]).some(X=>X.required&&!w[X.name]?.trim()),tt=X=>{Gt.navigate(st.WORK,{openTask:X})},Qe=async(X,ie,xe)=>{const je=Ge(X);if(!je)throw new Error(l("work:task.workflowNoTeam","无法确定此工作流所属的团队"));let we=D[X]?.yaml;if(!we&&(we=(await ee.workflows.get(je,X)).yaml,!we))throw new Error(l("work:task.workflowNoYaml","模板缺少原始 YAML,无法编辑"));const Le=kc(we),ke=Le?.steps?.find(It=>It?.id===ie);if(!Le||!ke)throw new Error(l("work:task.stepNotFound",{stepId:ie}));xe.name!==void 0&&(ke.name=xe.name),xe.role!==void 0&&(ke.role=xe.role),xe.prompt!==void 0&&(ke.prompt=xe.prompt),await ee.workflows.update(je,X,vc(Le)),Ft();const{template:pt,yaml:lt}=await ee.workflows.get(je,X);z(It=>({...It,[X]:{...pt,yaml:lt}})),B(It=>({...It,[X]:"ready"}))},Je=X=>Y(X),ye=X=>X.displayName||X.name,He=X=>`@[${X.displayName||X.name}](workflow:${X.name})`,wt=X=>{const ie=Ge(X.name),xe=ie?s.find(je=>je.teamId===ie&&je.agentRole==="manager"):void 0;return Jc(xe?.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:()=>Et(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:()=>Et(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&&!m?r.jsx("div",{className:"flex-1 flex items-center justify-center px-4",children:r.jsx(Wc,{teamId:$e,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 ie=h[X.name]??[],xe=ie[0],je=we=>{const Le=xe?.roleMapping?.[we];return Le?s.find(ke=>ke.id===Le)?.name:void 0};return r.jsx(Yb,{workflow:X,detail:D[X.name],detailState:E[X.name]??"idle",onRetryDetail:()=>re(X.name),expanded:P.has(X.name),onToggle:()=>mt(X.name),runs:ie,runTasks:L,onRun:()=>se(X),onOpenRun:we=>{K(we),me(we)},onSaveStep:(we,Le)=>Qe(X.name,we,Le),roleAgentName:je,onSendToAgent:()=>Je(X),onEdit:()=>{pe("edit",X)},onDuplicate:()=>{pe("duplicate",X)},onDelete:()=>{pe("delete",X)}},X.name)}),r.jsx(Wc,{teamId:$e,agents:s,compact:!0})]}),H&&r.jsx(Gb,{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:R[H.id],onClose:()=>K(null),onPauseResume:()=>{Q(H)},onCancel:()=>Z(H.id),onViewTasks:()=>{ge(H),K(null)},pausing:te===H.id,onOpenTask:X=>{K(null),tt(X)},roleAgentName:X=>{const ie=H.roleMapping?.[X];return ie?s.find(xe=>xe.id===ie)?.name:void 0}}),_&&r.jsx(Xb,{mode:_.mode,workflow:_.workflow,yaml:_.yaml,yamlLoading:_.yamlLoading,busy:_.busy,error:_.error,onClose:()=>I(null),onSubmit:Te}),O&&r.jsx(Zc,{chipKind:"workflow",chipLabel:ye(O),chipContent:He(O),agents:s,users:o,defaultTarget:wt(O),onClose:()=>Y(null)}),g&&r.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50",onClick:()=>x(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(Vt,{options:[{value:"",label:"—"},...X.options.map(ie=>({value:ie,label:ie}))],value:w[X.name]??"",onChange:ie=>v(xe=>({...xe,[X.name]:ie})),placeholder:"—",className:"w-full"}):r.jsx("textarea",{value:w[X.name]??"",onChange:ie=>{v(we=>({...we,[X.name]:ie.target.value}));const xe=ie.target;xe.style.height="auto";const je=parseFloat(getComputedStyle(xe).lineHeight)||18;xe.style.height=Math.min(xe.scrollHeight,je*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))}),oe.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:oe.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(Vt,{options:X.candidates.map(ie=>({value:ie.agentId,label:ie.agentName+(ie.agentId===X.recommended?" ★":"")})),value:Ne[X.role]??X.recommended??"",onChange:ie=>Ie(xe=>({...xe,[X.role]:ie})),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(Vt,{options:[{value:"",label:l("work:task.workflowSelectProject","— Select a project —")},...a.map(X=>({value:X.id,label:X.name}))],value:Ce??"",onChange:X=>{const ie=X||null;Fe(ie),C(null),ie&&localStorage.setItem("markus_wf_project_last",ie)},placeholder:l("work:task.workflowSelectProject","— Select a project —"),className:"w-full"})]}),k&&r.jsx("p",{className:"text-xs text-red-400 mb-3",children:k}),r.jsxs("div",{className:"flex justify-end gap-2",children:[r.jsx("button",{onClick:()=>x(null),className:"btn-secondary text-xs px-4 py-1.5",children:l("work:task.workflowCancel","Cancel")}),r.jsx("button",{onClick:le,disabled:y||!!Se,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(h).flat().find(we=>we.id===F),ie=X?L[X.id]:void 0,xe=X?.taskIds.length??0,je=ie?ie.filter(we=>!fr(we.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:we=>we.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.")}),je!==null?r.jsx("p",{className:"text-xs font-medium text-fg-primary mb-5",children:l("work:task.workflowCancelScope","将取消 {{count}} 个未完成任务(该运行共 {{total}} 个)",{count:je,total:xe})}):r.jsx("p",{className:"text-xs text-fg-tertiary mb-5",children:l("work:task.workflowCancelScopeUnknown","该运行共有 {{total}} 个任务(正在统计其中未完成的数量)",{total:xe})}),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:()=>fe(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 Ly({authUser:e,previewMode:t,previewData:n}={}){const{t:s}=ze(["work","common"]),o=Uf(st.WORK),a=p.useMemo(()=>Eo.map(N=>({...N,label:s(`work:boardColumn.${N.id}`)})),[s]),i=p.useMemo(()=>bf(s),[s]),l=p.useMemo(()=>Si(s),[s]),c=wr(),d=Yf(),h=d?.leftCollapsed??!1,u=p.useRef(null),[m,f]=p.useState(0);p.useEffect(()=>{const N=u.current;if(!N)return;const G=new ResizeObserver(([J])=>f(J.contentRect.width));return G.observe(N),f(N.clientWidth),()=>G.disconnect()},[]);const[g,x]=p.useState(()=>{if(t)return!1;try{return localStorage.getItem(Ec)==="1"}catch{return!1}}),w=p.useCallback(N=>{x(N);try{localStorage.setItem(Ec,N?"1":"0")}catch{}},[]),v=p.useRef(h);p.useEffect(()=>{t||c||v.current!==h&&(v.current=h,x(h))},[h,t,c]);const y=Gf({side:"left",defaultWidth:240,minWidth:180,maxWidth:360,storageKey:"markus_work_l1"}),b=6,k=!c&&!g?y.width+b:0,C=Math.max(0,(m||window.innerWidth)-k-b-8),j=Math.max(320,Math.round(C/2)),[A,S]=p.useState("auto"),T=Math.max(320,C-280),P=A==="auto"?Math.min(j,T):A,M=Math.max(320,Math.min(P,T)),D=p.useRef(M);D.current=M;const z=p.useRef(T);z.current=T;const E=p.useCallback(N=>{N.preventDefault();const G=N.clientX,J=D.current,ae=Ae=>{const Me=Math.max(320,Math.min(z.current,J+(G-Ae.clientX)));S(Me)},he=()=>{document.removeEventListener("mousemove",ae),document.removeEventListener("mouseup",he),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",ae),document.addEventListener("mouseup",he),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]),[B,L]=p.useState(!1),$=p.useRef(B);$.current=B,p.useEffect(()=>(al(st.WORK,c&&B?1:0),()=>al(st.WORK,0)),[c,B]);const[R,q]=p.useState(n?.projects??[]),[H,K]=p.useState("all"),[O,Y]=p.useState(null),[_,I]=p.useState("closed"),[V,W]=p.useState("projects"),[F,Z]=p.useState(n?.board??{}),[te,ce]=p.useState({}),[oe,be]=p.useState(n?.agents??[]),[Ne,Ie]=p.useState([]),[Ce,Fe]=p.useState(n?.users??[]),[Be,Re]=p.useState(n?.allRequirements??[]),[$e,Et]=p.useState(!n),[qe,Ge]=p.useState(""),ft=p.useCallback(()=>{Ko(O??""),hn(!0)},[O]),mt=async N=>{if(!O){In(N),ft();return}try{const{requirement:G}=await ee.requirements.create({title:N,description:N,priority:"medium",projectId:O});ht(s("work:task.quickAddReqDone",{title:N})),zt(),G&&xn(G)}catch(G){ht(s("work:task.errorGeneric",{message:String(G)}))}},re=N=>{se(N),He(O??""),pe(!0),ht(s("work:task.quickAddTaskHint"))},[ue,me]=p.useState(!1),[Ee,pe]=p.useState(!1),[Te,se]=p.useState(""),[le,fe]=p.useState(""),[Q,ge]=p.useState("medium"),[Se,tt]=p.useState(""),[Qe,Je]=p.useState(""),[ye,He]=p.useState(""),[wt,X]=p.useState(""),[ie,xe]=p.useState([]),[je,we]=p.useState("standard"),[Le,ke]=p.useState(()=>Sa()),[pt,lt]=p.useState(""),[It,Ot]=p.useState(!1),[Wt,_t]=p.useState(null),[We,nt]=p.useState(!1),[Tt,Cn]=p.useState(""),[kt,Ye]=p.useState(null),[et,Xe]=p.useState(()=>n?.initialSelectedReqId&&n.allRequirements?n.allRequirements.find(N=>N.id===n.initialSelectedReqId)??null:null);p.useEffect(()=>{n?.initialSelectedReqId&&et&&I("item")},[]);const[dt,Kt]=p.useState(new Set),[Nt,St]=p.useState(!1),[Lt,$t]=p.useState(new Set),Qt=p.useRef(new Set),[U,de]=p.useState(null),[De,Oe]=p.useState(n?.initialBoardType??"backlog"),[Ve,Pt]=p.useState(null),[an,as]=p.useState(null),[is,Us]=p.useState([]);p.useEffect(()=>Xf(st.WORK,()=>Rr.current),[]),p.useEffect(()=>Zf((N,G)=>{N===st.WORK&&Mc.includes(G)&&Oe(G)}),[]);const Wo=p.useRef(null),[qt,Pn]=p.useState(!1),[Bn,Ys]=p.useState(null),[ls,En]=p.useState(!1),qn=p.useRef(null),cs=p.useRef(null),[Gs,hn]=p.useState(!1),[zn,In]=p.useState(""),[Fn,Xs]=p.useState(""),[Ci,vf]=p.useState("medium"),[Ar,Ko]=p.useState(""),[ds,Hn]=p.useState(null),[Ei,Ii]=p.useState(""),[Ti,Tn]=p.useState(""),[Uo,Mi]=p.useState(!1),[Ai,us]=p.useState(""),ht=p.useCallback(N=>{Ge(N),setTimeout(()=>Ge(""),3e3)},[]);p.useEffect(()=>{const N=G=>{G.key==="Escape"&&(Wt?_t(null):We?(nt(!1),Cn("")):ds?(Hn(null),us("")):Ee?(pe(!1),lt("")):Gs?(hn(!1),In(""),Xs(""),Tn("")):ls?En(!1):_!=="closed"&&(I("closed"),Ye(null),Xe(null),c&&$.current&&L(!1)))};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[Wt,We,ds,Ee,Gs,ls,_,c]);const Ut=R.find(N=>N.id===O)??null,jf=Ut?.teamIds?.[0]??null,Nf=p.useMemo(()=>R.filter(N=>N.status!=="archived"),[R]),_i=p.useCallback(()=>{O&&(Ye(null),Xe(null),I("project"),S("auto"),c&&L(!0))},[O,c]),_r=p.useCallback(()=>{if(_==="project"){I("closed"),c&&L(!1);return}_i()},[_,_i,c]);p.useEffect(()=>{Qt.current=Lt},[Lt]);const Vn=p.useCallback(async()=>{try{const{projects:N}=await ee.projects.list();q(N)}catch{}},[]),At=p.useCallback(async()=>{const N={};H==="project"&&O&&(N.projectId=O);try{const{board:G,counts:J}=await ee.tasks.board(N);Z(G),ce(J??{})}catch{}},[H,O]),Lr=p.useMemo(()=>Object.keys(te).filter(N=>(F[N]?.length??0)<(te[N]??0)),[F,te]),[Yo,Li]=p.useState(!1),Ri=p.useCallback(async()=>{if(Yo)return;const N=Lr;if(N.length!==0){Li(!0);try{const J={};H==="project"&&O&&(J.projectId=O);const ae=await Promise.all(N.map(async he=>{const Ae=F[he]?.length??0,Me=Math.floor(Ae/100)+1;try{const ne=await ee.tasks.list({...J,status:he,page:Me,pageSize:100});return{status:he,tasks:ne.tasks??[]}}catch{return{status:he,tasks:[]}}}));Z(he=>{const Ae={...he};for(const{status:Me,tasks:ne}of ae){if(!ne.length)continue;const gt=new Set((Ae[Me]??[]).map(Mt=>Mt.id)),dn=ne.filter(Mt=>!gt.has(Mt.id));dn.length&&(Ae[Me]=[...Ae[Me]??[],...dn])}return Ae})}finally{Li(!1)}}},[Yo,Lr,F,H,O]),Zs=p.useCallback(async()=>{try{const{agents:N}=await ee.agents.list();be(N)}catch{}},[]),Di=p.useCallback(async()=>{try{const{teams:N}=await ee.teams.list();Ie(N.map(G=>({id:G.id,name:G.name})))}catch{}},[]),Oi=p.useCallback(async()=>{try{const{users:N}=await ee.users.list(e?.orgId);Fe(N)}catch{}},[e?.orgId]),zt=p.useCallback(async()=>{try{const{requirements:N}=await ee.requirements.list({});Re(N)}catch{}},[]),$i=p.useCallback(async()=>{await Promise.all([Vn(),At(),Zs(),Oi(),zt(),Di()]),Et(!1)},[Vn,At,Zs,Oi,zt,Di]);p.useEffect(()=>{t||$i()},[t,$i]),p.useEffect(()=>{!t||!n||(q(n.projects??[]),Z(n.board??{}),be(n.agents??[]),Fe(n.users??[]),Re(n.allRequirements??[]))},[t,n]);const mn=p.useCallback(()=>{!c||$.current||(L(!0),history.pushState({mobileDetail:st.WORK},"",window.location.hash))},[c]),Go=p.useCallback(N=>{W("items"),Ye(G=>G?.id===N.id&&_==="item"?(I("closed"),c&&$.current&&L(!1),null):(I("item"),S("auto"),mn(),N)),Xe(null)},[c,_,mn]),Xo=p.useCallback(N=>{W("items"),Xe(G=>G?.id===N.id&&_==="item"?(I("closed"),c&&$.current&&L(!1),null):(I("item"),S("auto"),mn(),N)),Ye(null)},[c,_,mn]),Wn=p.useCallback(()=>{Ye(null),Xe(null),I("closed"),c&&$.current&&L(!1)},[c]),pn=p.useRef(kt);pn.current=kt;const gn=p.useRef(et);gn.current=et;const Kn=p.useRef(_);Kn.current=_;const fs=p.useRef(V);fs.current=V;const hs=p.useRef(g);hs.current=g;const Rr=p.useRef(De);Rr.current=De;const Sf=p.useCallback(()=>{Ye(null),gn.current||(I("closed"),c&&$.current&&L(!1))},[c]);p.useEffect(()=>{if(!c)return;const N=()=>{$.current&&(L(!1),Ye(null),Xe(null),I("closed"))};return window.addEventListener("popstate",N),()=>window.removeEventListener("popstate",N)},[c]),p.useEffect(()=>{if(t||!o)return;At(),Zs(),zt();const N=pn.current?12e4:45e3,G=setInterval(()=>{At(),Zs(),zt()},N);let J=null;const ae=()=>{J||(J=setTimeout(()=>{J=null,At()},800))};let he=null;const Ae=()=>{he||(he=setTimeout(()=>{he=null,zt()},800))},Me=Bt.on("task:update",ot=>{Ft("/taskboard"),ae();const _e=ot?.payload;_e?.taskId&&(Ye(ut=>{if(!ut||ut.id!==_e.taskId)return ut;const Ue={};return typeof _e.status=="string"&&(Ue.status=_e.status),Array.isArray(_e.deliverables)&&(Ue.deliverables=_e.deliverables),Array.isArray(_e.notes)&&(Ue.notes=_e.notes),_e.result!==void 0&&(Ue.result=_e.result),{...ut,...Ue}}),pn.current?.id===_e.taskId&&(Ft("/tasks/"+_e.taskId),ee.tasks.get(_e.taskId).then(ut=>{ut.task&&Ye(Ue=>Ue?.id===ut.task.id?ut.task:Ue)}).catch(()=>{})))}),ne=Bt.on("task:create",()=>{ae()}),dn=["requirement:created","requirement:approved","requirement:rejected","requirement:updated","requirement:completed","requirement:cancelled","requirement:resubmitted"].map(ot=>Bt.on(ot,_e=>{Ft("/requirements"),Ae();const ut=_e?.payload,Ue=ut?.id??ut?.requirementId;Ue&&gn.current?.id===Ue&&(Ft("/requirements/"+Ue),ee.requirements.get(Ue).then(yn=>{yn.requirement&&Xe(Gn=>Gn?.id===yn.requirement.id?yn.requirement:Gn)}).catch(()=>{}))})),Mt=()=>{Ft("/taskboard"),Ft("/tasks"),Ft("/requirements"),At(),zt(),pn.current&&ee.tasks.get(pn.current.id).then(ot=>{ot.task&&Ye(_e=>_e?.id===ot.task.id?ot.task:_e)}).catch(()=>{}),gn.current&&ee.requirements.get(gn.current.id).then(ot=>{ot.requirement&&Xe(_e=>_e?.id===ot.requirement.id?ot.requirement:_e)}).catch(()=>{})};return window.addEventListener("markus:data-changed",Mt),()=>{clearInterval(G),Me(),ne(),dn.forEach(ot=>ot()),window.removeEventListener("markus:data-changed",Mt),J&&clearTimeout(J),he&&clearTimeout(he)}},[t,o,At,Zs,zt]);const Pi=p.useRef(F);Pi.current=F;const Bi=p.useRef(Be);Bi.current=Be,p.useEffect(()=>{const N=pn.current;if(!N)return;const J=Object.values(F).flat().find(ae=>ae.id===N.id);J&&J.updatedAt!==N.updatedAt&&Ye(ae=>ae&&ae.id===J.id?{...J,evidence:ae.evidence}:J)},[F]),p.useEffect(()=>{const N=gn.current;if(!N)return;const G=Be.find(J=>J.id===N.id);G&&G.updatedAt!==N.updatedAt&&Xe(G)},[Be]);const ln=p.useCallback(N=>{if(!N){$t(new Set),Y(null),K("all"),history.replaceState(null,"",Fr(st.WORK)),ee.tasks.board({}).then(G=>Z(G.board)).catch(()=>{});return}Y(N),K("project"),$t(new Set),history.replaceState(null,"",Fr(st.WORK,N)),ee.tasks.board({projectId:N}).then(G=>Z(G.board)).catch(()=>{})},[]),[Zo,Qs]=p.useState(!1),ms=p.useCallback((N,G)=>{Ye(N),Xe(null),I("item"),W("items"),S("auto"),G?.scrollToComments&&Qs(!0),mn()},[mn]),xn=p.useCallback((N,G)=>{Xe(N),Ye(null),I("item"),W("items"),S("auto"),G?.scrollToComments&&Qs(!0),mn()},[mn]),qi=p.useCallback(N=>{ln(N.projectId),Ys(null),Kt(new Set),$t(new Set),St(!1),Pn(!0),as(N),Us([]),ee.tasks.list({requirementId:N.id,pageSize:200}).then(({tasks:G})=>{G?.length&&Us(G)}).catch(()=>{}),xn(N),Pt(`req-${N.id}`),Oe("dag")},[ln,xn]),ps=p.useRef(null);p.useEffect(()=>{const N=ps.current||localStorage.getItem("markus_nav_openTask");if(!N)return;const J=Object.values(F).flat().find(ae=>ae.id===N);J?(ps.current=null,ln(J.projectId),ms(J),localStorage.removeItem("markus_nav_openTask")):ps.current||(ps.current=N,localStorage.removeItem("markus_nav_openTask"),ee.tasks.get(N).then(ae=>{ae.task&&(ps.current=null,ln(ae.task.projectId),ms(ae.task))}).catch(()=>{ps.current=null,ht(s("work:task.notFound",{id:N}))}))},[F,ms,ln,o,ht,s]);const gs=p.useRef(null);p.useEffect(()=>{const N=gs.current||localStorage.getItem("markus_nav_openRequirement");if(!N)return;const G=Be.find(J=>J.id===N);G?(gs.current=null,ln(G.projectId),xn(G),localStorage.removeItem("markus_nav_openRequirement")):gs.current||(gs.current=N,localStorage.removeItem("markus_nav_openRequirement"),ee.requirements.get(N).then(J=>{J.requirement&&(gs.current=null,ln(J.requirement.projectId),xn(J.requirement))}).catch(()=>{gs.current=null}))},[Be,xn,ln,o]);const Jt=p.useCallback((N,G)=>{$t(new Set),Y(N),K("project"),W(g?"items":"projects"),G?.keepItemDetail||(Ye(null),Xe(null),I(J=>J==="closed"?J:"project")),history.replaceState(null,"",Fr(st.WORK,N))},[g]),cn=p.useCallback(N=>{$t(new Set),Y(null),K("all"),W(g?"items":"projects"),N?.keepItemDetail||(Ye(null),Xe(null),I(G=>G==="closed"?G:G==="project"?"closed":"empty")),history.replaceState(null,"",Fr(st.WORK))},[g]),Un=p.useRef(!1);p.useEffect(()=>{if(Un.current)return;const N=window.location.hash.slice(1).split("/");if(Hr(N[0])===st.WORK&&N[1]){Un.current=!0,Jt(N[1],{keepItemDetail:!0});return}const G=localStorage.getItem("markus_nav_projectId");if(G){Un.current=!0,localStorage.removeItem("markus_nav_projectId"),Jt(G,{keepItemDetail:!0});return}Un.current=!0,cn({keepItemDetail:!0})},[]),p.useEffect(()=>{if(!$e){if(!O){Un.current=!0,H!=="all"&&K("all");return}if(R.some(N=>N.id===O)){Un.current=!0;return}Un.current=!0,cn({keepItemDetail:!0})}},[$e,R,O,cn,H]);const Cf=p.useRef(Hr(window.location.hash.slice(1).split("/")[0]));p.useEffect(()=>{if(t)return;const N=()=>{const J=window.location.hash.slice(1).split("/"),ae=Hr(J[0]);Cf.current=ae,ae===st.WORK&&(J[1]?Jt(J[1],{keepItemDetail:!0}):cn({keepItemDetail:!0}))},G=async J=>{const ae=J.detail;if(Hr(ae.page)===st.WORK){if(ae.params?.openTask){const he=ae.params.openTask,Ae=ae.params.scrollToComments==="true";localStorage.removeItem("markus_nav_openTask");let Me=Object.values(Pi.current).flat().find(ne=>ne.id===he);if(!Me)try{Me=(await ee.tasks.get(he)).task}catch{}Me?(ln(Me.projectId),ms(Me,{scrollToComments:Ae})):ht(s("work:task.notFound",{id:he}))}if(ae.params?.openRequirement){const he=ae.params.openRequirement,Ae=ae.params.scrollToComments==="true";let Me=Bi.current.find(ne=>ne.id===he);if(!Me)try{Me=(await ee.requirements.get(he)).requirement}catch{}Me&&(ln(Me.projectId),xn(Me,{scrollToComments:Ae}))}if(ae.params?.projectId&&Jt(ae.params.projectId),ae.params?.statusFilter){const he=ae.params.statusFilter;localStorage.removeItem("markus_nav_statusFilter"),ay.has(he)&&Pn(!0),Ys(he)}}};return window.addEventListener("markus:navigate",G),window.addEventListener("hashchange",N),()=>{window.removeEventListener("markus:navigate",G),window.removeEventListener("hashchange",N)}},[t]);const Ef=N=>{me(!1),ht(s("work:task.projectCreated")),q(G=>G.some(J=>J.id===N.id)?G:[...G,N]),Jt(N.id),Vn()},If=async N=>{try{await ee.projects.delete(N),O===N&&cn(),ht(s("work:task.projectDeleted")),Vn(),At()}catch(G){ht(s("work:task.errorGeneric",{message:String(G)}))}},zi=async()=>{if(!Te||!Se||!Qe||It)return;lt("");const N=Qe.startsWith("human:"),G=Qe.replace(/^(human|agent):/,"");if(Se===G&&!N){ht(s("work:task.assignedReviewerDifferent"));return}const J=ye||void 0,ae=wt||void 0;Ot(!0);try{const{task:he}=await ee.tasks.create(Te,le,Se,G,Q,J,ie.length>0?ie:void 0,ae,je!=="standard"?je:void 0,je==="scheduled"?cd(Le):void 0,N?"human":"agent");se(""),fe(""),xe([]),X(""),we("standard"),ke(Sa()),pe(!1),At(),he&&ms(he)}catch(he){const Me=`work:task.errorCode_${(he instanceof Uc?he.code:void 0)||"unknown"}`,ne=s(Me,{defaultValue:""});lt(ne||s("work:task.errorCreatingTask",{message:he instanceof Error?he.message:String(he)}))}finally{Ot(!1)}},Fi=async()=>{if(!(!Tt.trim()||!ye))try{const{requirement:N}=await ee.requirements.create({title:Tt.trim(),description:Tt.trim(),priority:"medium",projectId:ye});Cn(""),nt(!1),ht(s("work:task.requirementCreated")),zt(),N&&X(N.id)}catch(N){lt(N instanceof Error?N.message:String(N))}},xs=N=>{window.dispatchEvent(new CustomEvent("markus:mark-read-by-ref",{detail:N}))},Hi=()=>{Ft("/taskboard"),At(),kt&&(xs({taskId:kt.id}),Ft("/tasks/"+kt.id),ee.tasks.get(kt.id).then(N=>{N.task&&Ye(G=>G?.id===N.task.id?N.task:G)}).catch(()=>{}))},Yn=()=>{Ft("/requirements"),zt(),et&&(Ft("/requirements/"+et.id),ee.requirements.get(et.id).then(N=>{N.requirement&&Xe(G=>G?.id===N.requirement.id?N.requirement:G)}).catch(()=>{}))},Vi=async()=>{if(!Uo){if(!zn.trim()){Tn(s("work:task.pleaseReqTitle"));return}if(!Fn.trim()){Tn(s("work:task.pleaseReqDesc"));return}if(!Ar){Tn(s("work:task.pleaseReqProject"));return}Tn(""),Mi(!0);try{const{requirement:N}=await ee.requirements.create({title:zn.trim(),description:Fn.trim(),priority:Ci,projectId:Ar});ht(s("work:task.requirementCreated")),In(""),Xs(""),hn(!1),zt(),N&&xn(N)}catch(N){Tn(N instanceof Error?N.message:String(N))}finally{Mi(!1)}}},Qo=async N=>{try{await ee.requirements.approve(N),ht(s("work:task.requirementApproved")),xs({requirementId:N}),Yn(),At()}catch(G){ht(s("work:task.errorGeneric",{message:String(G)}))}},Tf=async()=>{if(ds){us("");try{await ee.requirements.reject(ds,Ei),ht(s("work:task.requirementRejected")),xs({requirementId:ds}),Hn(null),Ii(""),us(""),Yn()}catch(N){us(N instanceof Error?N.message:String(N))}}},Wi=async N=>{try{await ee.requirements.cancel(N),ht(s("work:task.requirementCancelled")),xs({requirementId:N}),Yn()}catch(G){ht(s("work:task.errorGeneric",{message:String(G)}))}},Mf=(N,G)=>{qn.current=G,cs.current=null,N.dataTransfer.effectAllowed="move",N.dataTransfer.setData("text/plain",`task:${G.id}`),N.currentTarget.style.opacity="0.4"},Af=(N,G)=>{cs.current=G,qn.current=null,N.dataTransfer.effectAllowed="move",N.dataTransfer.setData("text/plain",`req:${G.id}`),N.currentTarget.style.opacity="0.4"},Ki=N=>{N.currentTarget.style.opacity="1",qn.current=null,cs.current=null,de(null)},_f=(N,G)=>{N.preventDefault(),N.dataTransfer.dropEffect="move",U!==G&&de(G)},Lf=(N,G)=>{const J=N.currentTarget.getBoundingClientRect(),{clientX:ae,clientY:he}=N;(ae<J.left||ae>J.right||he<J.top||he>J.bottom)&&U===G&&de(null)},Rf=async(N,G)=>{N.preventDefault(),de(null);const J=qn.current,ae=cs.current;if(J){const he=a.find(Me=>Me.id===G);if(!he)return;const Ae=he.dropStatus;if(J.status===Ae||J.status==="pending")return;try{await ee.tasks.updateStatus(J.id,Ae),At()}catch{}}else if(ae){const he=yf[G];if(!he||ae.status===he)return;try{await ee.requirements.updateStatus(ae.id,he),zt()}catch{}}},Ui=N=>{Kt(G=>{const J=new Set(G);return J.has(N)?J.delete(N):J.add(N),J})},Dr=N=>{Jt(N)},Df=new Set(["rejected","cancelled","archived"]),Jo=N=>Df.has(N.status),Js=(N,G=!1)=>C0(N,{showClosed:qt,includeClosed:G,statusFilter:Bn,viewMode:H,selectedProjectId:O,projectFilter:Lt,agentFilter:dt,myTasksOnly:Nt,currentUserId:e?.id}),Of=p.useMemo(()=>{const N=new Map;for(const G of Object.values(F))for(const J of G)N.set(J.id,J);return N},[F]),$f=p.useMemo(()=>new Set(oe.map(N=>N.id)),[oe]),Yi=N=>N.statuses.flatMap(G=>Js(F[G]??[])),bn=p.useMemo(()=>{let N=Be;return qt||(N=N.filter(G=>!Jo(G))),H==="project"&&O&&(N=N.filter(G=>G.projectId===O)),Lt.size>0&&(N=N.filter(G=>G.projectId&&Lt.has(G.projectId))),dt.size>0&&(N=N.filter(G=>dt.has(G.createdBy))),Nt&&e?.id&&(N=N.filter(G=>G.createdBy===e.id)),N},[Be,qt,H,O,Lt,dt,Nt,e?.id,$f]),Gi=p.useCallback(N=>bn.filter(G=>mo[G.status]===N.id),[bn]),Pf=a.filter(N=>{if(N.id==="failed"||N.id==="closed"){const G=Yi(N),J=Gi(N);return G.length+J.length>0}return!0}),er=((te.archived??0)+(te.rejected??0)+(te.cancelled??0)||Object.values(F).flat().filter(N=>Jo(N)).length)+Be.filter(N=>Jo(N)).length,Xi=p.useMemo(()=>{const N=Object.values(F).flat(),G=new Set;for(const J of N)J.assignedAgentId&&!fr(J.status)&&(!O||J.projectId===O)&&G.add(J.assignedAgentId);return[...oe].sort((J,ae)=>{const he=G.has(J.id)?0:1,Ae=G.has(ae.id)?0:1;return he-Ae})},[oe,F,O]),Or=p.useMemo(()=>{const N=new Map,G=[];for(const ae of Xi)if(ae.teamId){const he=N.get(ae.teamId)??[];he.push(ae.id),N.set(ae.teamId,he)}else G.push(ae);const J=[];for(const ae of G)J.push({kind:"agent",agent:ae});for(const ae of Ne){const he=N.get(ae.id);he&&he.length>0&&J.push({kind:"team",id:ae.id,name:ae.name,agentIds:he})}return J},[Xi,Ne]);p.useMemo(()=>{const N=Object.values(F).flat(),G=new Set;for(const ae of N)ae.projectId&&!fr(ae.status)&&G.add(ae.projectId);return[...qt?R:R.filter(ae=>ae.status!=="archived")].sort((ae,he)=>{const Ae=ae.status==="archived"?1:0,Me=he.status==="archived"?1:0;if(Ae!==Me)return Ae-Me;const ne=G.has(ae.id)?0:1,gt=G.has(he.id)?0:1;return ne!==gt?ne-gt:ae.name.localeCompare(he.name)})},[R,F,qt]);const $r=p.useMemo(()=>[...R].sort((N,G)=>{const J=N.status==="archived"?1:0,ae=G.status==="archived"?1:0;return J!==ae?J-ae:N.name.localeCompare(G.name)}),[R]),Pr=p.useMemo(()=>{const N={};for(const G of Object.values(F))for(const J of G){const ae=J.projectId??"__none__";N[ae]=(N[ae]??0)+1}return N},[F]),Br=Object.values(Pr).reduce((N,G)=>N+G,0),Bf=O?Pr[O]??0:Br,Zi=p.useMemo(()=>{const N=Js(Object.values(F).flat()),G=[];if(De==="kanban"){for(const ae of Eo){const he=ae.statuses.flatMap(ne=>N.filter(gt=>gt.status===ne)),Me=[...bn.filter(ne=>mo[ne.status]===ae.id).map(ne=>({kind:"req",data:ne,time:new Date(ne.updatedAt??ne.createdAt).getTime()})),...he.map(ne=>({kind:"task",data:ne,time:new Date(ne.updatedAt??ne.createdAt??0).getTime()}))];Me.sort((ne,gt)=>gt.time-ne.time);for(const ne of Me)ne.kind==="req"?G.push({kind:"req",data:ne.data}):G.push({kind:"task",data:ne.data})}return G}const J=[];for(const ae of N){const he=wf(ae.status);J.push({kind:"task",data:ae,groupOrder:Io[he]??5,time:new Date(ae.updatedAt??ae.createdAt??0).getTime()})}for(const ae of bn){const he=mo[ae.status]??"todo";J.push({kind:"req",data:ae,groupOrder:Io[he]??5,time:new Date(ae.updatedAt??ae.createdAt).getTime()})}return J.sort((ae,he)=>ae.groupOrder!==he.groupOrder?ae.groupOrder-he.groupOrder:he.time-ae.time),J.map(ae=>ae.kind==="req"?{kind:"req",data:ae.data}:{kind:"task",data:ae.data})},[F,bn,De,qt,Bn,O,Lt,dt,Nt,e?.id,H]),qr=p.useRef(Zi);qr.current=Zi;const Qi=p.useRef($r);Qi.current=$r;const ea=p.useRef(O);ea.current=O;const bs=p.useCallback(N=>{N.kind==="req"?(Xe(N.data),Ye(null)):(Ye(N.data),Xe(null)),I("item"),S("auto"),W("items")},[]),Ji=p.useCallback(()=>{if(Kn.current==="item"||Kn.current==="empty"){I("closed"),Ye(null),Xe(null);return}if(pn.current||gn.current){I("item"),S("auto"),W("items");return}const N=qr.current;if(N.length>0){bs(N[0]);return}Ye(null),Xe(null),I("empty"),S("auto")},[bs]);p.useEffect(()=>{if(!c)if(g){if(W("items"),Kn.current==="project")if(pn.current||gn.current)I("item");else{const N=qr.current;N.length>0?bs(N[0]):I("closed")}}else fs.current==="items"&&Kn.current==="closed"||!g&&Kn.current==="closed"&&W("projects")},[g,c,bs]);const tr=d?.keyboardPane??"content",el=p.useRef(tr);if(p.useEffect(()=>{if(t||c||!o)return;const N=el.current;el.current=tr,tr==="l1"&&(W("projects"),N!=="l1"&&hs.current&&(w(!1),d?.setLeftCollapsed(!1)))},[tr,t,c,o,w,d]),p.useEffect(()=>{if(t||c||!o)return;const N=navigator.platform.toUpperCase().includes("MAC"),G=J=>{if(d?.keyboardPane==="l0")return;const ae=N?J.metaKey&&!J.ctrlKey:J.ctrlKey&&!J.metaKey;if(J.ctrlKey&&!J.metaKey&&J.key==="Tab"){J.preventDefault();const _e=Mc,ut=_e.indexOf(Rr.current),Ue=J.shiftKey?_e[(ut-1+_e.length)%_e.length]:_e[(ut+1)%_e.length];Oe(Ue);return}if(ae&&!J.altKey&&!J.shiftKey){const _e=J.key.toLowerCase();if(_e==="j"){J.preventDefault(),_r();return}if(_e==="l"){J.preventDefault(),Ji();return}}if(ae||J.altKey||J.ctrlKey||J.metaKey||Jf(J.target))return;const he=J.key.length===1?J.key.toLowerCase():J.key;if(he==="h"||he==="ArrowLeft"){if(hs.current){J.preventDefault(),w(!1),d?.setLeftCollapsed(!1),W("projects"),d?.setKeyboardPane("l1");return}if(fs.current==="items"){J.preventDefault(),W("projects"),d?.setKeyboardPane("l1");return}J.preventDefault(),d?.setL0FocusPageId(st.WORK),d?.setLeftCollapsed(!1),d?.setKeyboardPane("l0");return}if((he==="l"||he==="ArrowRight"||he==="Tab"&&!J.shiftKey)&&!hs.current&&fs.current==="projects"){J.preventDefault(),W("items"),d?.setKeyboardPane("content");return}if((he==="l"||he==="ArrowRight")&&(hs.current||fs.current==="items")){J.preventDefault();return}const Ae=he==="j"||he==="ArrowDown"?1:he==="k"||he==="ArrowUp"?-1:0;if(!Ae)return;if((hs.current?"items":fs.current)==="projects"){J.preventDefault(),d?.setKeyboardPane("l1");const _e=Qi.current,ut=_e.length+1;if(_e.length===0)return;const Ue=ea.current==null?0:_e.findIndex(ys=>ys.id===ea.current)+1,yn=Ue<0?0:Ue,Gn=Math.max(0,Math.min(ut-1,yn+Ae));if(Gn===0)cn(),requestAnimationFrame(()=>{document.querySelector('[data-project-id="__all__"]')?.scrollIntoView({block:"nearest"})});else{const ys=_e[Gn-1];Jt(ys.id),Kn.current!=="closed"&&(I("project"),Ye(null),Xe(null)),requestAnimationFrame(()=>{document.querySelector(`[data-project-id="${ys.id}"]`)?.scrollIntoView({block:"nearest"})})}return}const ne=Rr.current;if(ne!=="backlog"&&ne!=="kanban")return;J.preventDefault(),d?.setKeyboardPane("content");const gt=qr.current;if(gt.length===0){I(_e=>_e==="closed"?"empty":_e);return}const dn=pn.current?.id??gn.current?.id??null;let Mt=dn?gt.findIndex(_e=>_e.data.id===dn):-1;Mt<0&&(Mt=Ae>0?-1:0);const ot=Math.max(0,Math.min(gt.length-1,Mt+Ae));bs(gt[ot]),requestAnimationFrame(()=>{document.querySelector(`[data-work-item-id="${gt[ot].data.id}"]`)?.scrollIntoView({block:"nearest"})})};return document.addEventListener("keydown",G,!0),()=>document.removeEventListener("keydown",G,!0)},[t,c,o,_r,Ji,Jt,cn,bs,w,d]),$e)return r.jsx(fh,{label:s("work:task.loadingPage")});const tl=_!=="closed"||!!(kt||et),zr=!c&&!!(kt&&et)&&_==="item",nl=c?B:tl;return r.jsxs("div",{ref:u,className:"flex-1 overflow-hidden flex bg-surface-primary",children:[!c&&r.jsx(v0,{projects:$r,selectedProjectId:O,allSelected:H==="all"&&!O,taskCounts:Pr,totalTaskCount:Br,onSelectAll:()=>{cn(),W("projects")},onSelectProject:N=>{Jt(N),W("projects")},onEditProject:N=>{Jt(N),Ye(null),Xe(null),I("project"),W("projects")},onCreateProject:()=>me(!0),onCollapse:()=>{const N=!g;w(N),d?.setLeftCollapsed(N)},width:y.width,onResizeStart:y.onResizeStart,hidden:g,focused:tr==="l1"&&V==="projects"&&!g,onActivate:()=>W("projects")}),r.jsxs("div",{"data-keyboard-pane":"content",onPointerDown:()=>W("items"),className:`${c?"flex-1 min-w-0":zr?"w-0 shrink-0 overflow-hidden":"flex-1 min-w-0"} overflow-hidden flex flex-col bg-surface-primary`,style:c&&B?{display:"none"}:void 0,children:[qe&&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:qe}),c?r.jsxs("div",{className:"shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2 px-3 h-11",children:[r.jsx(Qf,{}),Ut?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:Ut.name}),r.jsx("button",{onClick:_r,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors shrink-0 ${_==="project"?"bg-surface-overlay text-fg-primary":"text-fg-tertiary"}`,children:r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3"}),r.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):r.jsx("h2",{className:"text-sm font-semibold text-fg-primary min-w-0 flex-1 truncate",children:s("work:task.projectsCount",{count:R.length})}),r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx("button",{onClick:()=>me(!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:ft,className:"px-2 py-1 text-[11px] bg-brand-600 text-on-brand rounded-md",children:s("work:task.shortReq")}),r.jsx("button",{onClick:()=>{He(O??""),pe(!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:()=>Oe(N),className:`px-2 py-0.5 text-[10px] font-medium whitespace-nowrap transition-colors ${De===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))}),er>0&&r.jsx("button",{onClick:()=>Pn(N=>!N),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${qt?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary"}`,children:qt?s("work:task.hideArchived"):s("work:task.archivedCount",{count:er})}),r.jsx("div",{className:"flex-1"}),Bn&&r.jsxs("button",{onClick:()=>Ys(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.${Bn==="in_progress"?"inProgress":Bn}`),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"})]})]}),(Nf.length>1||oe.length>0||e?.id)&&r.jsxs("button",{onClick:()=>En(!0),className:`px-2 py-1 text-[11px] rounded-md font-medium transition-colors flex items-center gap-1 ${dt.size>0||Nt?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/30":"border border-border-default text-fg-secondary"}`,children:[r.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})}),r.jsx("span",{children:dt.size+(Nt?1:0)>0?s("work:task.filterWithCount",{count:dt.size+(Nt?1:0)}):s("work:task.filter")})]})]})]}):r.jsxs("div",{"data-electron-drag":!0,className:"flex items-center gap-3 px-6 h-14 shrink-0",children:[r.jsx("button",{"data-no-drag":!0,type:"button",onClick:()=>{const N=!g;w(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"})]})}),Ut?r.jsxs("div",{"data-no-drag":!0,className:"flex items-center gap-1 shrink-0 min-w-0",children:[r.jsx(ey,{value:Ut.name,onSave:async N=>{await ee.projects.update(Ut.id,{name:N}),Vn()},className:"text-sm font-semibold text-fg-primary"}),r.jsx("button",{onClick:_r,className:`w-6 h-6 flex items-center justify-center rounded-md transition-colors ${_==="project"?"bg-surface-overlay text-fg-primary":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,title:`${s("work:project.settingsTitle")} (⌘J)`,children:r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3"}),r.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})})]}):r.jsx("h2",{className:"text-sm font-semibold text-fg-primary shrink-0",children:s("work:task.projectsCount",{count:R.length})}),er>0&&r.jsx("button",{onClick:()=>Pn(N=>!N),className:`text-[10px] shrink-0 px-2 py-0.5 rounded-md transition-colors ${qt?"bg-surface-overlay text-fg-secondary":"text-fg-tertiary hover:text-fg-secondary"}`,children:qt?s("work:task.hideArchivedWithCount",{count:er}):s("work:task.archivedCount",{count:er})}),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:()=>Oe(N),className:`px-2.5 py-1 text-[10px] font-medium transition-colors ${De===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:()=>me(!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:ft,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:()=>{He(O??""),pe(!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&&De!=="workflows"&&(Or.length>0||e?.id)&&(Bf>0||bn.length>0||dt.size>0||Nt)&&r.jsxs("div",{className:"px-6 py-1.5 flex items-center gap-1.5 overflow-x-auto scrollbar-hide shrink-0",children:[r.jsx("button",{type:"button",onClick:()=>{Kt(new Set),St(!1)},className:`text-[10px] text-fg-tertiary hover:text-fg-secondary px-2 py-1 rounded-md bg-surface-elevated/60 hover:bg-surface-overlay shrink-0 transition-all ${dt.size>0||Nt?"visible opacity-100":"invisible opacity-0"}`,children:s("work:task.clear")}),e?.id&&r.jsx("button",{type:"button",onClick:()=>St(N=>!N),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${Nt?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:s("work:task.myTasks")}),Or.map(N=>{if(N.kind==="team"){const ae=N.agentIds.every(Ae=>dt.has(Ae)),he=!ae&&N.agentIds.some(Ae=>dt.has(Ae));return r.jsxs("button",{onClick:()=>{Kt(Ae=>{const Me=new Set(Ae);if(ae)for(const ne of N.agentIds)Me.delete(ne);else for(const ne of N.agentIds)Me.add(ne);return Me})},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${ae?"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,J=dt.has(G.id);return r.jsxs("button",{onClick:()=>Ui(G.id),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] shrink-0 transition-all ${J?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"text-fg-tertiary hover:bg-surface-elevated hover:text-fg-secondary"}`,children:[r.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${J?"bg-brand-600 text-on-brand":"bg-surface-overlay text-fg-secondary"}`,children:G.name[0]?.toUpperCase()}),G.name]},G.id)})]}),R.length===0?r.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:r.jsxs("div",{className:"max-w-sm w-full text-center space-y-3",children:[r.jsx("div",{className:"w-12 h-12 mx-auto rounded-xl bg-brand-500/10 flex items-center justify-center",children:r.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-brand-500",children:r.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),r.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:s("work:task.emptyNoProjectsTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:s("work:task.emptyNoProjectsHint")}),r.jsx("button",{onClick:()=>me(!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")})]})}):Js(Object.values(F).flat()).length===0&&bn.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||Nt?r.jsxs(r.Fragment,{children:[r.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:s("work:task.emptyFilteredTitle",{defaultValue:"No matching work"})}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:s("work:task.emptyFilteredHint",{defaultValue:"Nothing matches the current assignee filter. Clear filters to see all items in this project."})}),r.jsx("button",{type:"button",onClick:()=>{Kt(new Set),St(!1)},className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg font-medium transition-colors",children:s("work:task.clear")})]}):r.jsxs(r.Fragment,{children:[r.jsx("h3",{className:"text-sm font-medium text-fg-secondary",children:s("work:task.emptyNoReqsTitle")}),r.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed whitespace-pre-line",children:s("work:task.emptyNoReqsHint")}),r.jsxs("div",{className:"flex items-center justify-center gap-2 pt-1",children:[r.jsx("button",{onClick:ft,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:()=>{He(O??""),pe(!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:()=>cn(),className:"inline text-brand-500 hover:text-brand-500 hover:underline",children:s("work:allProjects")})]})]})]})}):De==="backlog"?r.jsx("div",{className:"flex-1 min-h-0 flex flex-col",children:r.jsx(xy,{tasks:Js(Object.values(F).flat()),requirements:bn,agents:oe,projects:R,onTaskClick:N=>Go(N),onReqClick:N=>Xo(N),onRefresh:()=>{At(),zt()},selectedTaskId:kt?.id,selectedReqId:et?.id,onQuickCreateReq:mt,onQuickCreateTask:re,onLoadMore:()=>{Ri()},hasMore:Lr.length>0,loadingMore:Yo})}):De==="workflows"?r.jsx("div",{className:"flex-1 min-h-0 flex flex-col relative",children:r.jsx(ky,{teamId:null,defaultTeamId:jf,projectId:O,agents:oe,users:Ce,projects:R,onViewRunTasks:N=>{const G=Be.find(J=>J.id===N);G?qi(G):ee.requirements.get(N).then(J=>{J.requirement&&(Re(ae=>[...ae,J.requirement]),qi(J.requirement))}).catch(()=>{})}})}):De==="dag"?r.jsxs("div",{className:"flex-1 min-h-0 flex flex-col relative",children:[r.jsx(r0,{tasks:(()=>{const N=Js(Object.values(F).flat(),!0);if(t&&et){const J=new Set(et.taskIds??[]);return N.filter(ae=>J.has(ae.id))}if(is.length===0)return N;const G=new Map(N.map(J=>[J.id,J]));for(const J of is)G.set(J.id,J);return[...G.values()]})(),requirements:(()=>{const N=t&&et?[et]:bn;return!an||N.some(G=>G.id===an.id)?N:[an,...N]})(),agents:oe,showArchived:qt,onShowArchivedChange:Pn,onTaskClick:ms,onReqClick:xn,mobile:c,onCollapseDAG:()=>{Pt(null),as(null),Us([])},onDependencyChange:At,selectedTaskId:kt?.id,selectedReqId:et?.id,hasDetailPanel:tl,defaultExpandedNodeId:Ve??(t&&et?`req-${et.id}`:void 0),previewMode:t}),c&&r.jsx("button",{onClick:()=>Oe("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:()=>Oe("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:Wo,className:"flex-1 min-h-0 overflow-auto px-4 py-5",onScroll:N=>{if(Lr.length===0)return;const G=N.currentTarget;G.scrollTop+G.clientHeight>=G.scrollHeight-240&&Ri()},children:r.jsx("div",{className:"flex gap-3 items-stretch",children:Pf.map(N=>{const G=Yi(N),J=Gi(N),ae=G.length+J.length,he=U===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:Ae=>_f(Ae,N.id),onDragLeave:Ae=>Lf(Ae,N.id),onDrop:Ae=>{Rf(Ae,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:ae})]}),r.jsx("div",{className:"space-y-2 px-2 py-2",children:(()=>{const Ae=[...J.map(Me=>({kind:"req",data:Me,time:new Date(Me.updatedAt??Me.createdAt).getTime()})),...G.map(Me=>({kind:"task",data:Me,time:new Date(Me.updatedAt??Me.createdAt??0).getTime()}))];return Ae.sort((Me,ne)=>ne.time-Me.time),Ae.map(Me=>{if(Me.kind==="req"){const ne=Me.data,gt=l[ne.status]??{label:ne.status,cls:"bg-gray-500/15 text-fg-secondary"},Mt=ne.source==="agent"&&ne.status==="pending",ot=H==="all"&&ne.projectId?R.find(Ue=>Ue.id===ne.projectId):null,_e=zs(ne.createdBy,oe,Ce)??ne.createdBy.slice(0,10),ut=et?.id===ne.id;return r.jsxs("div",{"data-work-item-id":ne.id,role:"button",tabIndex:0,draggable:!0,onDragStart:Ue=>Af(Ue,ne),onDragEnd:Ki,onClick:()=>Xo(ne),onKeyDown:Ue=>Ue.key==="Enter"&&Xo(ne),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
+ ${ut?"!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 ${gt.cls}`,children:gt.label})]}),r.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:ne.title}),ne.description&&r.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:ne.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:[ot&&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:ot.name,children:ot.name}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:ne.priority}),r.jsx("span",{className:"text-[10px] text-fg-muted",children:s("work:task.byCreator",{name:_e})})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[ne.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:ne.goalConfig.completionCriteria,children:["🎯 ",ne.goalConfig.currentIteration,"/",ne.goalConfig.maxIterations]}),ne.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:["📋 ",ne.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:Ue=>{Ue.stopPropagation(),Qo(ne.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:Ue=>{Ue.stopPropagation(),Hn(ne.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-${ne.id}`)}else{const ne=Me.data,gt=ne.subtasks?.length??0,dn=i[ne.status],Mt=ne.status==="pending",ot=ne.taskType==="scheduled"&&!!ne.scheduleConfig,_e=ot?ne.scheduleConfig.every?s("work:task.everyInterval",{interval:ne.scheduleConfig.every}):ne.scheduleConfig.cron?s("work:task.cronLabel"):s("work:task.scheduledShort"):null,ut=H==="all"&&ne.projectId?(()=>{const Ct=R.find(qf=>qf.id===ne.projectId)?.name;return Ct&&Ct!=="default"?Ct:null})():null,Ue=ne.requirementId?Be.find(Ct=>Ct.id===ne.requirementId)?.title:null,yn=ne.createdBy?zs(ne.createdBy,oe,Ce)??ne.createdBy:null,Gn=kt?.id===ne.id,ys={urgent:"bg-red-500",high:"bg-amber-500",medium:"bg-blue-500",low:"bg-gray-400"},sl=ne.status==="blocked"?qa(ne,Ct=>Of.get(Ct)):void 0,rl=sl==="hold";return r.jsxs("div",{"data-work-item-id":ne.id,role:"button",tabIndex:0,"aria-label":ne.title,draggable:!Mt,onDragStart:Ct=>!Mt&&Mf(Ct,ne),onDragEnd:Ki,onClick:()=>Go(ne),onKeyDown:Ct=>Ct.key==="Enter"&&Go(ne),className:`group rounded-lg p-2.5 border border-transparent transition-all ${rl?`${cr.hold.card} cursor-pointer`:Mt?"bg-amber-500/[0.06] border-amber-500/30 ring-1 ring-amber-500/15 cursor-pointer":ot?"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"} ${Gn?"!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 ${ys[ne.priority]??"bg-gray-400"}`,title:ne.priority}),ot&&r.jsx("span",{className:"text-blue-500 shrink-0",title:_e??"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"})})}),ot&&_e&&r.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-md bg-blue-500/10 text-blue-500 whitespace-nowrap",children:_e}),(()=>{const Ct=za(ne.status,s,sl)??dn;return Ct?r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md ml-auto shrink-0 ${Ct.cls}`,children:Ct.label}):null})(),rl&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md shrink-0 font-medium ${cr.hold.chip}`,children:"⚠"})]}),r.jsx("div",{className:"text-[13px] font-medium leading-snug text-fg-primary line-clamp-2 mb-1",children:ne.title}),ne.description&&r.jsx("div",{className:"text-[11px] text-fg-tertiary line-clamp-1 mb-1.5",children:ne.description}),(ut||Ue||ne.blockedBy&&ne.blockedBy.length>0)&&r.jsxs("div",{className:"flex flex-wrap gap-1 mb-1.5",children:[ut&&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:ut,children:ut}),Ue&&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:Ue,children:["# ",Ue]}),ne.blockedBy&&ne.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:["⏳ ",s("work:dag.depCount",{count:ne.blockedBy.length})]})]}),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:yn&&r.jsx("span",{className:"text-[10px] text-fg-muted",title:s("work:task.byCreator",{name:yn}),children:s("work:task.byCreator",{name:yn})})}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[gt>0&&r.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["⋮ ",gt]}),ne.notes&&ne.notes.length>0&&r.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["📝 ",ne.notes.length]}),ne.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 ${es[oe.find(Ct=>Ct.id===ne.assignedAgentId)?.status??""]??"bg-gray-500"}`}),oe.find(Ct=>Ct.id===ne.assignedAgentId)?.name??ne.assignedAgentId.slice(0,8)]})]})]})]},ne.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&&nl&&r.jsx("div",{className:"w-1.5 shrink-0 cursor-col-resize group relative flex items-center justify-center",onMouseDown:E,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"})}),nl&&r.jsx("div",{className:`${c||zr?"flex-1":"shrink-0"} overflow-hidden min-w-0 flex border-l border-border-default/60`,style:c||zr?void 0:{width:M},children:_==="project"&&Ut?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:Wn,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(hy,{project:Ut,tasks:Object.values(F).flat().filter(N=>N.projectId===Ut.id),requirements:Be.filter(N=>N.projectId===Ut.id),agents:oe,onDeleteProject:()=>If(Ut.id),onUpdateProject:async N=>{await ee.projects.update(Ut.id,N),Vn()},onRefresh:()=>{Vn()}})]}):_==="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:ft,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:()=>{He(O??""),pe(!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:Wn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:s("common:close")})]})}):zr?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:r.jsx(Kc,{req:et,agents:oe,projects:R,allTasks:Object.values(F).flat(),users:Ce,onClose:()=>{Xe(null),kt||Wn()},onApprove:N=>{Qo(N)},onReject:N=>{Hn(N)},onCancel:N=>{Wi(N),Xe(null)},onStatusChange:async(N,G)=>{try{await ee.requirements.updateStatus(N,G),ht(`Requirement status → ${G}`),xs({requirementId:N}),Yn(),At()}catch(J){ht(`Error: ${J}`)}},onRefresh:Yn,authUser:e,onTaskClick:N=>{Ye(N),I("item")},onCreateTask:(N,G)=>{X(N),G&&He(G),pe(!0)},onProjectClick:Dr,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(zc,{task:kt,agents:oe,projects:R,requirements:Be,allTasks:Object.values(F).flat(),users:Ce,onClose:Sf,onRefresh:Hi,authUser:e,scrollToComments:Zo,onScrollToCommentsDone:()=>Qs(!1),onReqClick:N=>{Xe(G=>G?.id===N.id?null:N),I("item")},onProjectClick:Dr})})]}):kt?r.jsx(zc,{task:kt,agents:oe,projects:R,requirements:Be,allTasks:Object.values(F).flat(),users:Ce,onClose:Wn,onRefresh:Hi,authUser:e,scrollToComments:Zo,onScrollToCommentsDone:()=>Qs(!1),onReqClick:N=>{Xe(N),Ye(null),I("item")},onProjectClick:Dr}):et?r.jsx(Kc,{req:et,agents:oe,projects:R,allTasks:Object.values(F).flat(),users:Ce,onClose:Wn,onApprove:N=>{Qo(N)},onReject:N=>{Hn(N)},onCancel:N=>{Wi(N),Wn()},onStatusChange:async(N,G)=>{try{await ee.requirements.updateStatus(N,G),ht(`Requirement status → ${G}`),xs({requirementId:N}),Yn(),At()}catch(J){ht(`Error: ${J}`)}},scrollToComments:Zo,onScrollToCommentsDone:()=>Qs(!1),onRefresh:Yn,authUser:e,onTaskClick:N=>{Ye(N),Xe(null),I("item"),mn()},onCreateTask:(N,G)=>{X(N),G&&He(G),pe(!0)},onProjectClick:Dr,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:Wn,className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:s("common:close")})]})})}),ue&&r.jsx(cc,{orgId:e?.orgId,onCreated:Ef,onClose:()=>me(!1)}),Wt&&r.jsx(cc,{orgId:e?.orgId,onCreated:N=>{q(G=>G.some(J=>J.id===N.id)?G:[...G,N]),Wt==="task"?(He(N.id),X("")):Ko(N.id),_t(null),ht(s("work:task.projectCreated"))},onClose:()=>_t(null)}),Ee&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{pe(!1),lt("")},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:_a,children:[r.jsx("label",{className:at,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:()=>we(N),"aria-pressed":je===N,className:`flex-1 px-3 py-1.5 text-sm rounded-md transition-colors ${je===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:at,children:s("work:task.titleLabel")}),r.jsx("input",{autoFocus:!c,value:Te,onChange:N=>se(N.target.value),onKeyDown:N=>{N.key==="Enter"&&zi()},className:vn}),r.jsx("label",{className:at,children:s("work:task.descriptionField")}),r.jsx("textarea",{value:le,onChange:N=>fe(N.target.value),rows:2,className:`${vn} resize-none`}),r.jsx("label",{className:at,children:s("work:task.priorityField")}),r.jsx(Co,{value:Q,onChange:ge}),r.jsx("label",{className:at,children:s("work:task.projectLabel")}),r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx(Vt,{className:"flex-1",options:[{value:"",label:s("work:task.noProject")},...R.map(N=>({value:N.id,label:N.name}))],value:ye,onChange:N=>{He(N),X("")},placeholder:s("work:task.noProject"),noMatchesText:s("work:task.noMatches")}),r.jsx("button",{type:"button",onClick:()=>_t("task"),className:pa,children:s("work:task.newProjectInline")})]}),r.jsx("label",{className:at,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(Vt,{className:"flex-1",options:[{value:"",label:s("work:task.selectRequirement")},...Be.filter(N=>N.status==="in_progress"&&(!ye||N.projectId===ye)).map(N=>({value:N.id,label:N.title}))],value:wt,onChange:X,placeholder:s("work:task.selectRequirement"),noMatchesText:s("work:task.noMatches")}),r.jsx("button",{type:"button",onClick:()=>{nt(!0),lt("")},className:pa,children:s("work:task.newRequirementInline")})]}),We&&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:Tt,onChange:N=>Cn(N.target.value),placeholder:s("work:task.newReqInlinePlaceholder"),onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),Fi())},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:()=>{Fi()},disabled:!Tt.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(ye?"work:task.newReqInlineHint":"work:task.newReqInlineNeedProject")})]})]}),r.jsxs("label",{className:at,children:[s("work:task.assignToRequired"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx(Vt,{options:oe.map(N=>({value:N.id,label:`${N.name} (${N.status})`})),value:Se,onChange:tt,placeholder:s("work:task.selectAgent"),noMatchesText:s("work:task.noMatches")}),r.jsxs("label",{className:at,children:[s("work:task.reviewerRequired"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx(Vt,{options:[...Ce.map(N=>({value:`human:${N.id}`,label:N.name})),...oe.filter(N=>N.id!==Se).map(N=>({value:`agent:${N.id}`,label:`${N.name} (${N.status})`}))],value:Qe,onChange:Je,placeholder:s("work:task.selectReviewer"),noMatchesText:s("work:task.noMatches")}),je==="scheduled"&&r.jsx("div",{className:"col-span-2",children:r.jsx(dd,{value:Le,onChange:ke})}),r.jsx("label",{className:at,children:s("work:task.blockedBy")}),r.jsxs("div",{className:"min-w-0",children:[r.jsx(Qb,{options:Object.values(F).flat().filter(N=>N.status!=="completed"&&N.status!=="cancelled").map(N=>({value:N.id,label:N.title})),selected:ie,onAdd:N=>xe([...ie,N]),placeholder:s("work:task.selectDependency"),noMatchesText:s("work:task.noMatches")}),ie.length>0&&r.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:ie.map(N=>{const G=Object.values(F).flat().find(J=>J.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:()=>xe(ie.filter(J=>J!==N)),className:"ml-0.5 text-amber-600/60 hover:text-amber-600",children:"×"})]},N)})})]})]}),pt&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:pt}),r.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[r.jsx("button",{onClick:()=>{pe(!1),lt("")},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:()=>{zi()},disabled:!Te.trim()||!Se||!Qe||It,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 rounded-lg text-on-brand disabled:opacity-50",children:s(It?"common:creating":"common:create")})]})]})}),Gs&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{hn(!1),In(""),Xs(""),Tn("")},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:_a,children:[r.jsxs("label",{className:at,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(Vt,{className:"flex-1",options:R.map(N=>({value:N.id,label:N.name})),value:Ar,onChange:Ko,placeholder:s("work:task.selectProject"),noMatchesText:s("work:task.noMatches")}),r.jsx("button",{type:"button",onClick:()=>_t("req"),className:pa,children:s("work:task.newProjectInline")})]}),r.jsxs("label",{className:at,children:[s("work:task.titleField"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx("input",{value:zn,onChange:N=>In(N.target.value),placeholder:s("work:task.reqTitleExample"),className:vn,autoFocus:!c,onKeyDown:N=>{N.key==="Enter"&&zn.trim()&&Vi()}}),r.jsxs("label",{className:at,children:[s("work:task.descriptionField"),r.jsx("span",{className:"text-red-500",children:" *"})]}),r.jsx("textarea",{value:Fn,onChange:N=>Xs(N.target.value),placeholder:s("work:task.reqDescPlaceholder"),rows:3,className:`${vn} resize-none`}),r.jsx("label",{className:at,children:s("work:task.priorityField")}),r.jsx(Co,{value:Ci,onChange:vf})]}),Ti&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Ti}),r.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[r.jsx("button",{onClick:()=>{hn(!1),In(""),Xs(""),Tn("")},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:()=>{Vi()},disabled:!zn.trim()||!Fn.trim()||!Ar||Uo,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(Uo?"common:creating":"common:create")})]})]})}),ds&&r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onClick:()=>{Hn(null),us("")},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:Ei,onChange:N=>Ii(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})]}),Ai&&r.jsx("div",{className:"px-3 py-2 bg-red-500/15 text-red-500 text-xs rounded-lg",children:Ai}),r.jsxs("div",{className:"flex justify-end gap-3",children:[r.jsx("button",{onClick:()=>{Hn(null),us("")},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:()=>{Tf()},className:"px-4 py-2 text-sm bg-red-600 hover:bg-red-500 rounded-lg text-white",children:s("work:task.reject")})]})]})}),ls&&r.jsxs("div",{className:"fixed inset-0 z-[60] flex flex-col justify-end",onClick:()=>En(!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||Nt)&&r.jsx("button",{onClick:()=>{Kt(new Set),St(!1)},className:"text-[11px] text-brand-500 font-medium",children:s("work:task.clearAll")}),r.jsx("button",{onClick:()=>En(!1),className:"w-7 h-7 flex items-center justify-center rounded-full bg-surface-elevated text-fg-tertiary",children:r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),R.length>0&&r.jsxs("div",{className:"px-4 py-3",children:[r.jsx("div",{className:"text-[11px] text-fg-tertiary font-medium uppercase tracking-wider mb-2",children:s("work:task.projectsFilterGroup")}),r.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[r.jsxs("button",{type:"button",onClick:()=>{cn(),En(!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"),Br>0&&r.jsx("span",{className:"text-[9px] text-fg-tertiary",children:Br})]}),$r.map(N=>{const G=O===N.id,J=Pr[N.id]??0;return r.jsxs("button",{type:"button",onClick:()=>{Jt(N.id),En(!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,J>0&&r.jsx("span",{className:"text-[9px] text-fg-tertiary",children:J})]},N.id)})]})]}),e?.id&&r.jsx("div",{className:"px-4 py-3 border-t border-border-default/40",children:r.jsx("button",{type:"button",onClick:()=>St(N=>!N),className:`w-full text-left px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${Nt?"bg-green-600/20 text-green-500 ring-1 ring-green-500/40":"bg-surface-elevated text-fg-secondary"}`,children:s("work:task.myTasks")})}),Or.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:Or.map(N=>{if(N.kind==="team"){const ae=N.agentIds.every(Ae=>dt.has(Ae)),he=!ae&&N.agentIds.some(Ae=>dt.has(Ae));return r.jsxs("button",{onClick:()=>{Kt(Ae=>{const Me=new Set(Ae);if(ae)for(const ne of N.agentIds)Me.delete(ne);else for(const ne of N.agentIds)Me.add(ne);return Me})},className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${ae?"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,J=dt.has(G.id);return r.jsxs("button",{onClick:()=>Ui(G.id),className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[11px] transition-all ${J?"bg-brand-600/20 text-brand-500 ring-1 ring-brand-500/40":"bg-surface-elevated text-fg-secondary"}`,children:[r.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-bold shrink-0 ${J?"bg-brand-600 text-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 vy({requirementId:e,createdBy:t,agents:n,users:s,authUser:o}){const{t:a}=ze(["work","common"]),[i,l]=p.useState([]),[c,d]=p.useState([]),h=p.useRef(null),[u,m]=p.useState(new Map);p.useEffect(()=>{d([]),m(new Map),h.current&&(clearTimeout(h.current),h.current=null),ee.requirements.getComments(e).then(v=>l(v.comments)).catch(()=>{})},[e]),p.useEffect(()=>Bt.on("requirement:comment",y=>{if(y.payload?.requirementId===e&&y.payload.comment){const b=y.payload.comment;l(k=>k.some(C=>C.id===b.id)?k:[...k,b]),(b.authorType==="agent"||b.authorId?.startsWith("agt_"))&&(d(k=>{const C=k.filter(j=>j.id!==b.authorId);return C.length===0&&h.current&&(clearTimeout(h.current),h.current=null),C}),m(k=>{const C=new Map(k);return C.delete(b.authorId),C}))}}),[e]),p.useEffect(()=>{if(c.length===0)return;const v=new Set(c.map(b=>b.id));return Bt.on("agent:activity_log",b=>{const k=b.payload;if(!k)return;const C=k.agentId;if(!v.has(C))return;const j=So(k);j&&m(A=>vi(A,C,j))})},[c]);const[f,g]=p.useState(null),x=async(v,y,b,k)=>{let C;b.length>0&&(C=(await ee.uploads.upload(b.map(T=>({dataUrl:T.dataUrl,name:T.name})),"comments")).files.map(T=>({type:"image",url:T.url,name:T.name})));const j=await ee.requirements.addComment(e,v,o?.name,C,o?.id,y.length>0?y:void 0,k),A=si(j.notifiedAgentIds,n);A.length>0&&(h.current&&clearTimeout(h.current),d(A),h.current=setTimeout(()=>d([]),12e4))},w=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(Vo,{comment:v,agents:n,onReply:w},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:()=>Gt.navigate(st.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(Fa,{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(ji,{entries:y})})]},v.id)})})]}),r.jsx(Gc,{agents:n,humans:s,onSubmit:x,replyTo:f,onCancelReply:()=>g(null)})]})}function Kc({req:e,agents:t,projects:n,allTasks:s,users:o,onClose:a,onApprove:i,onReject:l,onCancel:c,onStatusChange:d,onRefresh:h,authUser:u,scrollToComments:m,onScrollToCommentsDone:f,onTaskClick:g,onCreateTask:x,onProjectClick:w,previewMode:v}){const{t:y}=ze(["work","common"]),b=p.useMemo(()=>Si(y),[y]),k=p.useMemo(()=>bf(y),[y]),C=wr(),[j,A]=p.useState(!1),[S,T]=p.useState(e.description),[P,M]=p.useState(!1),[D,z]=p.useState(!1),[E,B]=p.useState(!1);p.useEffect(()=>{if(!E)return;const Q=ge=>{ge.key==="Escape"&&B(!1)};return document.addEventListener("keydown",Q),()=>document.removeEventListener("keydown",Q)},[E]);const[L,$]=p.useState(!1),[R,q]=p.useState(null),[H,K]=p.useState(!1),[O,Y]=p.useState(null),_=p.useMemo(()=>s.filter(Q=>Q.requirementId===e.id&&Q.status==="pending").length,[s,e.id]),I=async()=>{Y(null),K(!0);try{const Q=await ee.requirements.approveTasksBulk(e.id,{dryRun:!0});q({phase:"preview",...Q})}catch(Q){Y(Q instanceof Error?Q.message:String(Q))}finally{K(!1)}},V=async()=>{Y(null),K(!0);try{const Q=await ee.requirements.approveTasksBulk(e.id,{runNow:!0});q({phase:"result",...Q}),h?.()}catch(Q){Y(Q instanceof Error?Q.message:String(Q))}finally{K(!1)}},[W,F]=p.useState(!1),Z=p.useRef(null),[te,ce]=p.useState("none"),oe=p.useRef(null),be=p.useRef(null),Ne=p.useRef(80);p.useEffect(()=>{const Q=Z.current;if(!Q)return;const ge=()=>{const{scrollTop:tt,scrollHeight:Qe,clientHeight:Je}=Q;if(!(Qe>Je+50)){ce("none");return}const He=tt<30,wt=tt+Je>=Qe-30;ce(He?"top":wt?"bottom":"middle")};ge(),Q.addEventListener("scroll",ge,{passive:!0});const Se=new ResizeObserver(ge);return Se.observe(Q),()=>{Q.removeEventListener("scroll",ge),Se.disconnect()}},[]),p.useEffect(()=>{if(j&&be.current){const Q=be.current;Q.style.height="auto",Q.style.height=Math.max(Q.scrollHeight,Ne.current)+"px",Q.focus()}},[j]),p.useEffect(()=>{if(!m)return;const Q=setTimeout(()=>{const ge=Z.current;ge&&ge.scrollTo({top:ge.scrollHeight,behavior:"smooth"}),f?.()},300);return()=>clearTimeout(Q)},[m,f]);const Ie=b[e.status]??{label:e.status,cls:"bg-gray-500/15 text-fg-secondary"},Ce=e.source==="agent",Fe=Ce&&e.status==="pending",Be=e.status==="pending"||e.status==="in_progress",Re=ad.has(e.status),$e=e.projectId?n.find(Q=>Q.id===e.projectId):null,Et=zs(e.createdBy,t,o)??e.createdBy.slice(0,12),qe=s.filter(Q=>e.taskIds.includes(Q.id)),Ge=$e?.teamIds?.[0]??null;p.useMemo(()=>new Map(qe.map(Q=>[Q.id,Q])),[qe]);const ft=qe.length>=2;p.useEffect(()=>{T(e.description),A(!1)},[e.id,e.description]);const[mt,re]=p.useState(!1),[ue,me]=p.useState(e.title),[Ee,pe]=p.useState(!1),[Te,se]=p.useState((e.tags??[]).join(", ")),le=p.useRef(null);p.useEffect(()=>{me(e.title),re(!1)},[e.id,e.title]),p.useEffect(()=>{se((e.tags??[]).join(", ")),pe(!1)},[e.id,e.tags]),p.useEffect(()=>{mt&&le.current?.focus()},[mt]);const fe=async Q=>{try{await ee.requirements.update(e.id,Q),h?.()}catch{}};return r.jsxs("div",{className:`flex flex-col w-full overflow-hidden bg-surface-primary shadow-xl shadow-black/8 ring-1 ring-border-default/20 ${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:[mt?r.jsx("input",{ref:le,value:ue,onChange:Q=>me(Q.target.value),onBlur:()=>{const Q=ue.trim();Q&&Q!==e.title&&fe({title:Q}),re(!1)},onKeyDown:Q=>{Q.key==="Enter"&&Q.target.blur(),Q.key==="Escape"&&(me(e.title),re(!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 ${Re?"":"cursor-text hover:bg-surface-elevated/60"}`,onClick:Re?void 0:()=>re(!0),role:Re?void 0:"button",tabIndex:Re?void 0:0,onKeyDown:Re?void 0:Q=>Q.key==="Enter"&&re(!0),title:Re?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 ${Ie.cls}`,children:Ie.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(Qc,{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(pf,{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:be,value:S,onChange:Q=>{T(Q.target.value);const ge=Q.target;ge.style.height="auto",ge.style.height=ge.scrollHeight+"px"},onBlur:async()=>{if(S!==e.description){M(!0);try{await ee.requirements.update(e.id,{description:S}),h?.()}catch{}finally{M(!1)}}A(!1)},onKeyDown:Q=>{Q.key==="Escape"&&(Q.preventDefault(),T(e.description),A(!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:oe,className:`group relative rounded-lg -mx-2 px-2 -my-1 py-1 transition-colors ${Re?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:Re?void 0:Q=>{Q.target.closest("a, button, [data-entity-link]")||(Ne.current=Math.max(oe.current?.offsetHeight??80,60),T(e.description),A(!0))},role:Re?void 0:"button",tabIndex:Re?void 0:0,onKeyDown:Re?void 0:Q=>Q.key==="Enter"&&(T(e.description),A(!0)),children:e.description?r.jsx(dr,{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:vu,children:[r.jsx("label",{className:at,children:y("work:task.projectLabel")}),r.jsx(Vt,{size:"sm",disabled:Re,options:[{value:"",label:y("work:task.noProject")},...n.map(Q=>({value:Q.id,label:Q.name}))],value:e.projectId??"",onChange:Q=>{fe({projectId:Q||null})},placeholder:y("work:task.noProject"),noMatchesText:y("work:task.noMatches")}),r.jsx("label",{className:at,children:y("work:task.priority")}),r.jsx(Co,{value:e.priority,onChange:Q=>{fe({priority:Q})}}),r.jsx("label",{className:at,children:y("work:task.tagsLabel")}),Ee&&!Re?r.jsx("input",{autoFocus:!0,value:Te,onChange:Q=>se(Q.target.value),onBlur:()=>{const Q=Te.split(",").map(Se=>Se.trim()).filter(Boolean),ge=e.tags??[];Q.join("\0")!==ge.join("\0")&&fe({tags:Q}),pe(!1)},onKeyDown:Q=>{Q.key==="Enter"&&Q.target.blur(),Q.key==="Escape"&&(se((e.tags??[]).join(", ")),pe(!1))},placeholder:y("work:task.tagsPlaceholder"),className:`${vn} !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 ${Re?"":"cursor-pointer hover:bg-surface-elevated/50"}`,onClick:Re?void 0:()=>pe(!0),role:Re?void 0:"button",tabIndex:Re?void 0:0,onKeyDown:Re?void 0:Q=>Q.key==="Enter"&&pe(!0),children:e.tags&&e.tags.length>0?e.tags.map(Q=>r.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",Q]},Q)):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:Et}),Ce&&r.jsx("span",{className:"text-brand-500 ml-1",children:y("work:task.agentTag")})]}),r.jsx("span",{children:new Date(e.createdAt).toLocaleString()}),w&&$e&&r.jsxs("button",{onClick:()=>w($e.id),className:"hover:text-fg-secondary transition-colors",children:[y("work:task.projectLabel"),": ",$e.name]}),e.approvedBy&&r.jsxs("span",{children:[y("work:task.approvedBy"),": ",r.jsx("span",{className:"text-fg-secondary",children:zs(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(Q=>r.jsxs("span",{className:"text-[10px] bg-surface-elevated text-fg-secondary px-2 py-0.5 rounded-full",children:["#",Q]},Q))}),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:qe.length})}),r.jsxs("div",{className:"flex items-center gap-2",children:[ft&&Ge&&r.jsxs("button",{onClick:()=>$(!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")]}),!Re&&x&&r.jsxs("button",{onClick:()=>x(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")]})]})]}),qe.length>0?(()=>{const Q=new Map(qe.map(ye=>[ye.id,ye]));if(!qe.some(ye=>ye.blockedBy?.some(He=>Q.has(He))))return r.jsx("div",{className:"space-y-1.5",children:qe.map(ye=>{const He=k[ye.status];return r.jsxs("div",{onClick:()=>g?.(ye),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 ${es[ye.status]??"bg-gray-500"}`}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:ye.title}),He&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${He.cls}`,children:He.label})]},ye.id)})});const Se=new Map,tt=new Set;for(const ye of qe)for(const He of ye.blockedBy??[])if(Q.has(He)){tt.add(ye.id);const wt=Se.get(He)??[];wt.push(ye.id),Se.set(He,wt)}const Qe=qe.filter(ye=>!tt.has(ye.id)),Je=(ye,He)=>{const wt=k[ye.status],X=(Se.get(ye.id)??[]).map(ie=>Q.get(ie)).filter(Boolean);return r.jsxs("div",{children:[r.jsxs("div",{onClick:()=>g?.(ye),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:He>0?{marginLeft:He*20}:void 0,children:[He>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 ${es[ye.status]??"bg-gray-500"}`}),r.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:ye.title}),wt&&r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded shrink-0 ${wt.cls}`,children:wt.label})]}),X.map(ie=>Je(ie,He+1))]},ye.id)};return r.jsx("div",{className:"space-y-1.5",children:Qe.map(ye=>Je(ye,0))})})():r.jsx("div",{className:"text-xs text-fg-tertiary italic py-2",children:y("work:requirement.noLinkedTasks")})]}),!v&&r.jsx(vy,{requirementId:e.id,createdBy:e.createdBy,agents:t,users:o,authUser:u}),!v&&r.jsx(kf,{entityType:"requirement",entityId:e.id,statusLabel:Q=>b[Q]?.label??Q})]}),te!=="none"&&te!=="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"})})}),te!=="none"&&te!=="bottom"&&r.jsx("button",{onClick:()=>{const Q=Z.current;Q&&Q.scrollTo({top:Q.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:[_>0&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>{I()},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:_})}),R&&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:Q=>Q.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:R.phase==="preview"?y("work:requirement.bulkApproveTitle","批量批准待批任务"):y("work:requirement.bulkApproveDone","批量批准结果")}),R.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:R.approved.length})}),R.phase==="result"&&r.jsx("p",{className:"mt-1 text-xs text-fg-secondary",children:y("work:requirement.bulkApproveSummary","成功 {{ok}} · 跳过 {{skip}} · 失败 {{fail}}",{ok:R.approved.length,skip:R.skipped.length,fail:R.failed.length})})]}),r.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-3 space-y-3",children:[R.approved.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary mb-1",children:R.phase==="preview"?y("work:requirement.bulkApproveWillApprove","将批准"):y("work:requirement.bulkApproveApproved","已批准")}),r.jsx("ul",{className:"space-y-0.5",children:R.approved.map(Q=>r.jsxs("li",{className:"text-xs text-fg-secondary truncate",children:["· ",Q.title]},Q.id))})]}),R.skipped.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary mb-1",children:y("work:requirement.bulkApproveSkipped","跳过(不满足批准条件)")}),r.jsx("ul",{className:"space-y-0.5",children:R.skipped.map(Q=>r.jsxs("li",{className:"text-xs text-fg-tertiary truncate",children:["· ",Q.title||Q.id," — ",Q.reason]},Q.id))})]}),R.failed.length>0&&r.jsxs("div",{children:[r.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-red-500 mb-1",children:y("work:requirement.bulkApproveFailed","失败")}),r.jsx("ul",{className:"space-y-0.5",children:R.failed.map(Q=>r.jsxs("li",{className:"text-xs text-red-500 truncate",children:["· ",Q.title," — ",Q.error]},Q.id))})]}),R.approved.length===0&&R.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:R.phase==="preview"?y("common:cancel"):y("common:close")}),R.phase==="preview"&&r.jsx("button",{onClick:()=>{V()},disabled:H||R.approved.length===0,className:"px-3 py-1.5 text-xs rounded-lg bg-green-600 hover:bg-green-500 text-white font-medium transition-colors disabled:opacity-60",children:H?y("work:requirement.bulkApproving","批准中…"):y("work:requirement.bulkApproveConfirm","确认批准并开始")})]})]})})]}),Fe&&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")})]}),!Fe&&d&&!Re&&r.jsxs("div",{className:"relative",children:[r.jsxs("button",{type:"button",onClick:()=>B(Q=>!Q),"aria-haspopup":"menu","aria-expanded":E,"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 ${es[e.status]??"bg-fg-muted"}`,"aria-hidden":"true"}),b[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"})})]}),E&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fixed inset-0 z-20",onClick:()=>B(!1),"aria-hidden":"true"}),r.jsx("div",{role:"menu",className:"absolute bottom-full left-0 mb-1 z-30 w-52 overflow-hidden rounded-xl border border-border-default bg-surface-secondary py-1 shadow-xl",children:(()=>{const Q=[...No[e.status]??[]].filter(ge=>ge!=="cancelled"&&!(Fe&&ge==="rejected"));return Q.length===0?r.jsx("p",{className:"px-3 py-2 text-[11px] text-fg-tertiary",children:y("work:requirement.noStatusChange","暂无可用状态变更")}):Q.map(ge=>r.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{B(!1),d(e.id,ge)},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 ${es[ge]??"bg-fg-muted"}`,"aria-hidden":"true"}),r.jsx("span",{className:"flex-1",children:b[ge]?.label??ge}),ge==="completed"&&r.jsx("span",{className:"text-[10px] text-fg-muted",children:y("work:requirement.terminalHint","终态")})]},ge))})()})]})]}),Re&&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"}),Be&&!Fe&&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(js,{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&&Ge&&r.jsx(wy,{req:e,tasks:qe,agents:t,teamId:Ge,onClose:()=>$(!1),onSaved:()=>$(!1)})]})}function kf({entityType:e,entityId:t,statusLabel:n}){const{t:s}=ze(["work","common"]),[o,a]=p.useState([]),[i,l]=p.useState(!0),[c,d]=p.useState(!1);if(p.useEffect(()=>{l(!0),(e==="task"?ee.tasks.getHistory:ee.requirements.getHistory)(t).then(g=>a(g.history)).catch(()=>a([])).finally(()=>l(!1))},[e,t]),i)return r.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary",children:s("work:task.loadingHistory","Loading history...")});if(o.length===0)return r.jsx("div",{className:"px-6 py-4 text-xs text-fg-tertiary italic",children:s("work:task.noHistory","No status change history.")});const h=c?o:o.slice(-5),u=o.length>5&&!c,m=f=>{const g=f.changedByName||f.changedById||(f.changedByType==="human"?s("common:actor.user"):f.changedByType==="agent"?s("common:actor.agent"):s("common:actor.system")),x=f.changedByType==="human"?"bg-blue-500/20 text-blue-500":f.changedByType==="agent"?"bg-brand-500/20 text-brand-500":"bg-gray-500/20 text-fg-tertiary";return r.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium shrink-0 ${x}`,children:g})};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:s("work:task.statusHistory","Status History")}),u&&r.jsx("button",{onClick:()=>d(!0),className:"text-[11px] text-brand-500 hover:underline mb-2",children:s("work:task.showAllHistory",{count:o.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:h.map(f=>r.jsxs("div",{className:"flex items-start gap-3 relative",children:[r.jsx("div",{className:"w-1.5 h-1.5 rounded-full mt-[7px] shrink-0 relative z-10",style:{background:f.changedByType==="human"?"#3b82f6":f.changedByType==="agent"?"var(--color-brand-500)":"#6b7280"}}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[m(f),r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-fg-tertiary line-through",children:n(f.fromStatus)}),r.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"→"}),r.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-brand-500/15 text-brand-500 font-medium",children:n(f.toStatus)})]}),f.reason&&r.jsx("p",{className:"text-[10px] text-fg-secondary mt-0.5 leading-snug",children:f.reason}),r.jsx("p",{className:"text-[9px] text-fg-tertiary mt-0.5",children:new Date(f.createdAt).toLocaleString()})]})]},f.id))})]})]})}export{Ly as WorkPage,ky as WorkflowsPanel};