@rudderhq/server 0.2.7-canary.21 → 0.2.7-canary.22

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 (79) hide show
  1. package/package.json +13 -13
  2. package/ui-dist/assets/{_basePickBy-BW39axrR.js → _basePickBy-CD-7Z_jN.js} +1 -1
  3. package/ui-dist/assets/{_baseUniq-CYx-myFK.js → _baseUniq-CzQLGbtB.js} +1 -1
  4. package/ui-dist/assets/{arc-ObJWHZo6.js → arc-CjtF_Ren.js} +1 -1
  5. package/ui-dist/assets/{architectureDiagram-2XIMDMQ5-Blr4CYlg.js → architectureDiagram-2XIMDMQ5-sV7uLBl5.js} +1 -1
  6. package/ui-dist/assets/{blockDiagram-WCTKOSBZ-BZWjNRc8.js → blockDiagram-WCTKOSBZ-NGVDHpcW.js} +1 -1
  7. package/ui-dist/assets/{c4Diagram-IC4MRINW-B6WOdMDy.js → c4Diagram-IC4MRINW-DrZWSRZy.js} +1 -1
  8. package/ui-dist/assets/channel-CVPeuk8A.js +1 -0
  9. package/ui-dist/assets/{chunk-4BX2VUAB-DUjx-7w-.js → chunk-4BX2VUAB-CXiI5Zxj.js} +1 -1
  10. package/ui-dist/assets/{chunk-55IACEB6-DXr3t_UE.js → chunk-55IACEB6-BHgWSKNA.js} +1 -1
  11. package/ui-dist/assets/{chunk-FMBD7UC4-kX2jCLOW.js → chunk-FMBD7UC4-DlfWhCeg.js} +1 -1
  12. package/ui-dist/assets/{chunk-JSJVCQXG-2yOkMW6g.js → chunk-JSJVCQXG-BvgMJz5N.js} +1 -1
  13. package/ui-dist/assets/{chunk-KX2RTZJC-BWenKiow.js → chunk-KX2RTZJC-DNOel2qU.js} +1 -1
  14. package/ui-dist/assets/{chunk-NQ4KR5QH-Q9n5qcus.js → chunk-NQ4KR5QH-Cqbc6zOn.js} +1 -1
  15. package/ui-dist/assets/{chunk-QZHKN3VN-B5jSJ0a3.js → chunk-QZHKN3VN-DiaVbBqT.js} +1 -1
  16. package/ui-dist/assets/{chunk-WL4C6EOR-Bkr_yLYN.js → chunk-WL4C6EOR-IWXjfoWY.js} +1 -1
  17. package/ui-dist/assets/classDiagram-VBA2DB6C-DECsXiYo.js +1 -0
  18. package/ui-dist/assets/classDiagram-v2-RAHNMMFH-DECsXiYo.js +1 -0
  19. package/ui-dist/assets/clone-DJBMNZbG.js +1 -0
  20. package/ui-dist/assets/{cose-bilkent-S5V4N54A-DRO4Y5Rl.js → cose-bilkent-S5V4N54A-C5tDUuDS.js} +1 -1
  21. package/ui-dist/assets/{dagre-KLK3FWXG-CPUT9hv6.js → dagre-KLK3FWXG-DcfSsEBq.js} +1 -1
  22. package/ui-dist/assets/{diagram-E7M64L7V-B-pjM3y1.js → diagram-E7M64L7V-4pD0Z5q8.js} +1 -1
  23. package/ui-dist/assets/{diagram-IFDJBPK2-CXdt1-56.js → diagram-IFDJBPK2-BDJ6ZWZb.js} +1 -1
  24. package/ui-dist/assets/{diagram-P4PSJMXO-5ftNFGkT.js → diagram-P4PSJMXO-4JlUr5_d.js} +1 -1
  25. package/ui-dist/assets/{erDiagram-INFDFZHY-DV3KdTGA.js → erDiagram-INFDFZHY-CKPTwwLW.js} +1 -1
  26. package/ui-dist/assets/{flowDiagram-PKNHOUZH-CVug8rFb.js → flowDiagram-PKNHOUZH-OpXKp4se.js} +1 -1
  27. package/ui-dist/assets/{ganttDiagram-A5KZAMGK-0jRLughg.js → ganttDiagram-A5KZAMGK-C27rKcZK.js} +1 -1
  28. package/ui-dist/assets/{gitGraphDiagram-K3NZZRJ6-BcUkTTqS.js → gitGraphDiagram-K3NZZRJ6-RMvHz1GX.js} +1 -1
  29. package/ui-dist/assets/{graph-DbHgR2Ub.js → graph-DBGDvFJJ.js} +1 -1
  30. package/ui-dist/assets/{index-CG72w6I6.js → index-BF94W45f.js} +1 -1
  31. package/ui-dist/assets/{index-nbjx7VzW.js → index-BNFWBcMX.js} +1 -1
  32. package/ui-dist/assets/{index-CveM11TV.js → index-BhoFRFOJ.js} +4 -4
  33. package/ui-dist/assets/{index-kgevp2HG.js → index-BjDcoM23.js} +1 -1
  34. package/ui-dist/assets/{index-BfplXq-F.js → index-Br5zwB0Z.js} +1 -1
  35. package/ui-dist/assets/{index-DCtxYhhT.js → index-BwOeluhm.js} +1 -1
  36. package/ui-dist/assets/{index-gUYia7os.js → index-CBJ1GRlx.js} +1 -1
  37. package/ui-dist/assets/index-CHQR9LPn.css +1 -0
  38. package/ui-dist/assets/{index-BxRgZJLt.js → index-CUmK5YNa.js} +1 -1
  39. package/ui-dist/assets/{index-CRpHAVOZ.js → index-Cnn7Ze7A.js} +1 -1
  40. package/ui-dist/assets/{index-CFbFr4ex.js → index-CxutLWF3.js} +1 -1
  41. package/ui-dist/assets/{index-Chg20wCg.js → index-CzGK9k2W.js} +1 -1
  42. package/ui-dist/assets/{index-yRsrqfY8.js → index-D7g9B35Q.js} +1 -1
  43. package/ui-dist/assets/{index-BmsLGvk8.js → index-DQIgDJJD.js} +1 -1
  44. package/ui-dist/assets/{index-C1tHyH8k.js → index-DRi3oX80.js} +1 -1
  45. package/ui-dist/assets/{index-DFW_78Yw.js → index-D_H502gP.js} +1 -1
  46. package/ui-dist/assets/{index-Cmtp6C3D.js → index-DooRYrN2.js} +1 -1
  47. package/ui-dist/assets/{index-Csahsk0b.js → index-DtA8NpRC.js} +1 -1
  48. package/ui-dist/assets/{index-BZEL7Egt.js → index-DyAGGhVR.js} +1 -1
  49. package/ui-dist/assets/{index-Dy1tUMNo.js → index-HtPOAsph.js} +1 -1
  50. package/ui-dist/assets/{index-MQzptRcp.js → index-IQg-mKY2.js} +1 -1
  51. package/ui-dist/assets/{index-B8gsfmlA.js → index-PghKETw5.js} +1 -1
  52. package/ui-dist/assets/{index-BltRQQBc.js → index-RDOFpY3r.js} +1 -1
  53. package/ui-dist/assets/{index-DUkFTf41.js → index-RV97u8HI.js} +1 -1
  54. package/ui-dist/assets/{infoDiagram-LFFYTUFH-Odm8F9l9.js → infoDiagram-LFFYTUFH-CCPehB1n.js} +1 -1
  55. package/ui-dist/assets/{ishikawaDiagram-PHBUUO56-CCMFTpbo.js → ishikawaDiagram-PHBUUO56-QRUyM-bG.js} +1 -1
  56. package/ui-dist/assets/{journeyDiagram-4ABVD52K-B7FWgWom.js → journeyDiagram-4ABVD52K-C-WTAun9.js} +1 -1
  57. package/ui-dist/assets/{kanban-definition-K7BYSVSG-CoM0N1fu.js → kanban-definition-K7BYSVSG-CoDdCWNo.js} +1 -1
  58. package/ui-dist/assets/{layout-JPAkdNEI.js → layout-BcfquhXG.js} +1 -1
  59. package/ui-dist/assets/{linear-Bawo73nN.js → linear-CExWNwJu.js} +1 -1
  60. package/ui-dist/assets/{mermaid.core-DzTz01fK.js → mermaid.core-D3HFVWWP.js} +4 -4
  61. package/ui-dist/assets/{mindmap-definition-YRQLILUH-dYsHJ-JJ.js → mindmap-definition-YRQLILUH-DIDhRQwy.js} +1 -1
  62. package/ui-dist/assets/{pieDiagram-SKSYHLDU-D2-x6Aj2.js → pieDiagram-SKSYHLDU-CjRK9Kys.js} +1 -1
  63. package/ui-dist/assets/{quadrantDiagram-337W2JSQ-CRp2Z7Ot.js → quadrantDiagram-337W2JSQ-Dm0v6QP8.js} +1 -1
  64. package/ui-dist/assets/{requirementDiagram-Z7DCOOCP-BxN4-jxT.js → requirementDiagram-Z7DCOOCP-BOXs5Exi.js} +1 -1
  65. package/ui-dist/assets/{sankeyDiagram-WA2Y5GQK-BIlfeT0o.js → sankeyDiagram-WA2Y5GQK-BeewOrIM.js} +1 -1
  66. package/ui-dist/assets/{sequenceDiagram-2WXFIKYE-6X0_wZqE.js → sequenceDiagram-2WXFIKYE-05PicUdw.js} +1 -1
  67. package/ui-dist/assets/{stateDiagram-RAJIS63D-BpoBQP2J.js → stateDiagram-RAJIS63D-DfqrUrOu.js} +1 -1
  68. package/ui-dist/assets/stateDiagram-v2-FVOUBMTO-DnlcW2tI.js +1 -0
  69. package/ui-dist/assets/{timeline-definition-YZTLITO2-B0yD1bfI.js → timeline-definition-YZTLITO2-BkgwCWCZ.js} +1 -1
  70. package/ui-dist/assets/{treemap-KZPCXAKY-cG-oYcM9.js → treemap-KZPCXAKY-Cz2TPBTj.js} +1 -1
  71. package/ui-dist/assets/{vennDiagram-LZ73GAT5-BgyYKFJG.js → vennDiagram-LZ73GAT5-DiMknW2W.js} +1 -1
  72. package/ui-dist/assets/{xychartDiagram-JWTSCODW-Bc4XZyRb.js → xychartDiagram-JWTSCODW-CmGBeabL.js} +1 -1
  73. package/ui-dist/index.html +2 -2
  74. package/ui-dist/assets/channel-BEvtmbAo.js +0 -1
  75. package/ui-dist/assets/classDiagram-VBA2DB6C-BTvnQ6po.js +0 -1
  76. package/ui-dist/assets/classDiagram-v2-RAHNMMFH-BTvnQ6po.js +0 -1
  77. package/ui-dist/assets/clone-DctiArPS.js +0 -1
  78. package/ui-dist/assets/index-CiJCsBUz.css +0 -1
  79. package/ui-dist/assets/stateDiagram-v2-FVOUBMTO-DPjAE3fE.js +0 -1
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Dy1tUMNo.js","assets/index-Chg20wCg.js","assets/index-MQzptRcp.js","assets/index-BfplXq-F.js","assets/index-BZEL7Egt.js","assets/index-BxRgZJLt.js","assets/index-CG72w6I6.js","assets/index-DFW_78Yw.js","assets/index-BltRQQBc.js","assets/index-yRsrqfY8.js","assets/index-nbjx7VzW.js","assets/index-DUkFTf41.js","assets/index-gUYia7os.js","assets/index-CRpHAVOZ.js","assets/index-kgevp2HG.js","assets/index-BmsLGvk8.js","assets/index-CFbFr4ex.js","assets/index-C1tHyH8k.js","assets/index-B8gsfmlA.js","assets/index-DCtxYhhT.js","assets/dockerfile-BKs6k2Af.js","assets/simple-mode-GW_nhZxv.js","assets/factor-kuTfRLto.js","assets/nsis-LdVXkNf5.js","assets/pug-DeIclll2.js","assets/javascript-iXu5QeM3.js","assets/index-Cmtp6C3D.js","assets/index-Csahsk0b.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-HtPOAsph.js","assets/index-CzGK9k2W.js","assets/index-IQg-mKY2.js","assets/index-Br5zwB0Z.js","assets/index-DyAGGhVR.js","assets/index-CUmK5YNa.js","assets/index-BF94W45f.js","assets/index-D_H502gP.js","assets/index-RDOFpY3r.js","assets/index-D7g9B35Q.js","assets/index-BNFWBcMX.js","assets/index-RV97u8HI.js","assets/index-CBJ1GRlx.js","assets/index-Cnn7Ze7A.js","assets/index-BjDcoM23.js","assets/index-DQIgDJJD.js","assets/index-CxutLWF3.js","assets/index-DRi3oX80.js","assets/index-PghKETw5.js","assets/index-BwOeluhm.js","assets/dockerfile-BKs6k2Af.js","assets/simple-mode-GW_nhZxv.js","assets/factor-kuTfRLto.js","assets/nsis-LdVXkNf5.js","assets/pug-DeIclll2.js","assets/javascript-iXu5QeM3.js","assets/index-DooRYrN2.js","assets/index-DtA8NpRC.js"])))=>i.map(i=>d[i]);
2
2
  var B9e=Object.defineProperty;var rG=e=>{throw TypeError(e)};var U9e=(e,t,n)=>t in e?B9e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Bi=(e,t,n)=>U9e(e,typeof t!="symbol"?t+"":t,n),DT=(e,t,n)=>t.has(e)||rG("Cannot "+n);var ze=(e,t,n)=>(DT(e,t,"read from private field"),n?n.call(e):t.get(e)),An=(e,t,n)=>t.has(e)?rG("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Zt=(e,t,n,r)=>(DT(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),xr=(e,t,n)=>(DT(e,t,"access private method"),n);var Ow=(e,t,n,r)=>({set _(i){Zt(e,t,i,n)},get _(){return ze(e,t,r)}});function boe(e,t){for(var n=0;n<t.length;n++){const r=t[n];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in e)){const a=Object.getOwnPropertyDescriptor(r,i);a&&Object.defineProperty(e,i,a.get?a:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const a of i)if(a.type==="childList")for(const o of a.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(i){const a={};return i.integrity&&(a.integrity=i.integrity),i.referrerPolicy&&(a.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?a.credentials="include":i.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function r(i){if(i.ep)return;i.ep=!0;const a=n(i);fetch(i.href,a)}})();var sG=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function U5(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function J_t(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if(typeof t=="function"){var n=function r(){return this instanceof r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(r){var i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,i.get?i:{enumerable:!0,get:function(){return e[r]}})}),n}var LT={exports:{}},Bb={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.js
@@ -1294,7 +1294,7 @@ When you submit the join request, use:
1294
1294
  `))};if((Qt.mac||Qt.android)&&f.from==o-1&&/^\. ?$/.test(r.text)&&t.contentDOM.getAttribute("autocorrect")=="off"&&(f={from:l,to:c,insert:ls.of([r.text.replace("."," ")])}),this.pendingContextChange=f,!t.state.readOnly){let h=this.to-this.from+(f.to-f.from+f.insert.length);Oq(t,f,bt.single(this.toEditorPos(r.selectionStart,h),this.toEditorPos(r.selectionEnd,h)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)),f.from<f.to&&!f.insert.length&&t.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(n.text.slice(Math.max(0,r.updateRangeStart-1),Math.min(n.text.length,r.updateRangeStart+1)))&&this.handlers.compositionend(r)},this.handlers.characterboundsupdate=r=>{let i=[],a=null;for(let o=this.toEditorPos(r.rangeStart),l=this.toEditorPos(r.rangeEnd);o<l;o++){let c=t.coordsForChar(o);a=c&&new DOMRect(c.left,c.top,c.right-c.left,c.bottom-c.top)||a||new DOMRect,i.push(a)}n.updateCharacterBounds(r.rangeStart,i)},this.handlers.textformatupdate=r=>{let i=[];for(let a of r.getTextFormats()){let o=a.underlineStyle,l=a.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let c=this.toEditorPos(a.rangeStart),u=this.toEditorPos(a.rangeEnd);if(c<u){let d=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;i.push($n.mark({attributes:{style:d}}).range(c,u))}}}t.dispatch({effects:K3e.of($n.set(i))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:r}=this.composing;this.composing=null,r&&this.reset(t.state)}};for(let r in this.handlers)n.addEventListener(r,this.handlers[r]);this.measureReq={read:r=>{this.editContext.updateControlBounds(r.contentDOM.getBoundingClientRect());let i=A6(r.root);i&&i.rangeCount&&this.editContext.updateSelectionBounds(i.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let n=0,r=!1,i=this.pendingContextChange;return t.changes.iterChanges((a,o,l,c,u)=>{if(r)return;let d=u.length-(o-a);if(i&&o>=i.to)if(i.from==a&&i.to==o&&i.insert.eq(u)){i=this.pendingContextChange=null,n+=d,this.to+=d;return}else i=null,this.revertPending(t.state);if(a+=n,o+=n,o<=this.from)this.from+=d,this.to+=d;else if(a<this.to){if(a<this.from||o>this.to||this.to-this.from+u.length>3e4){r=!0;return}this.editContext.updateText(this.toContextPos(a),this.toContextPos(o),u.toString()),this.to+=d}n+=d}),i&&!r&&this.revertPending(t.state),!r}update(t){let n=this.pendingContextChange,r=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(r.from,r.to)&&t.transactions.some(i=>!i.isUserEvent("input.type")&&i.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.reset(t.state)):(t.docChanged||t.selectionSet||n)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:n}=t.selection.main;this.from=Math.max(0,n-1e4),this.to=Math.min(t.doc.length,n+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let n=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(n.from),this.toContextPos(n.from+n.insert.length),t.doc.sliceString(n.from,n.to))}setSelection(t){let{main:n}=t.selection,r=this.toContextPos(Math.max(this.from,Math.min(this.to,n.anchor))),i=this.toContextPos(n.head);(this.editContext.selectionStart!=r||this.editContext.selectionEnd!=i)&&this.editContext.updateSelection(r,i)}rangeIsValid(t){let{head:n}=t.selection.main;return!(this.from>0&&n-this.from<500||this.to<t.doc.length&&this.to-n<500||this.to-this.from>1e4*3)}toEditorPos(t,n=this.to-this.from){t=Math.min(t,n);let r=this.composing;return r&&r.drifted?r.editorBase+(t-r.contextBase):t+this.from}toContextPos(t){let n=this.composing;return n&&n.drifted?n.contextBase+(t-n.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class Yt{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var n;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:r}=t;this.dispatchTransactions=t.dispatchTransactions||r&&(i=>i.forEach(a=>r(a,this)))||(i=>this.update(i)),this.dispatch=this.dispatch.bind(this),this._root=t.root||$it(t.parent)||document,this.viewState=new bte(this,t.state||Yr.create(t)),t.scrollTo&&t.scrollTo.is(p9)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(l3).map(i=>new xM(i));for(let i of this.plugins)i.update(this);this.observer=new oot(this),this.inputState=new Tat(this),this.inputState.ensureHandlers(this.plugins),this.docView=new ite(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((n=document.fonts)===null||n===void 0)&&n.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...t){let n=t.length==1&&t[0]instanceof ja?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(n,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let n=!1,r=!1,i,a=this.state;for(let h of t){if(h.startState!=a)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");a=h.state}if(this.destroyed){this.viewState.state=a;return}let o=this.hasFocus,l=0,c=null;t.some(h=>h.annotation(a5e))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,c=o5e(a,o),c||(l=1));let u=this.observer.delayedAndroidKey,d=null;if(u?(this.observer.clearDelayedAndroidKey(),d=this.observer.readChange(),(d&&!this.state.doc.eq(a.doc)||!this.state.selection.eq(a.selection))&&(d=null)):this.observer.clear(),a.facet(Yr.phrases)!=this.state.facet(Yr.phrases))return this.setState(a);i=$N.create(this,a,t),i.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let h of t){if(f&&(f=f.map(h.changes)),h.scrollIntoView){let{main:g}=h.state.selection;f=new _3(g.empty?g:bt.cursor(g.head,g.head>g.anchor?-1:1))}for(let g of h.effects)g.is(p9)&&(f=g.value.clip(this.state))}this.viewState.update(i,f),this.bidiCache=qN.update(this.bidiCache,i.changes),i.empty||(this.updatePlugins(i),this.inputState.update(i)),n=this.docView.update(i),this.state.facet(Vy)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(n,t.some(h=>h.isUserEvent("select.pointer")))}finally{this.updateState=0}if(i.startState.facet(w9)!=i.state.facet(w9)&&(this.viewState.mustMeasureContent=!0),(n||r||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),n&&this.docViewUpdate(),!i.empty)for(let h of this.state.facet(NL))try{h(i)}catch(g){rc(this.state,g,"update listener")}(c||d)&&Promise.resolve().then(()=>{c&&this.state==c.startState&&this.dispatch(c),d&&!X3e(this,d)&&u.force&&S3(this.contentDOM,u.key,u.keyCode)})}setState(t){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=t;return}this.updateState=2;let n=this.hasFocus;try{for(let r of this.plugins)r.destroy(this);this.viewState=new bte(this,t),this.plugins=t.facet(l3).map(r=>new xM(r)),this.pluginMap.clear();for(let r of this.plugins)r.update(this);this.docView.destroy(),this.docView=new ite(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}n&&this.focus(),this.requestMeasure()}updatePlugins(t){let n=t.startState.facet(l3),r=t.state.facet(l3);if(n!=r){let i=[];for(let a of r){let o=n.indexOf(a);if(o<0)i.push(new xM(a));else{let l=this.plugins[o];l.mustUpdate=t,i.push(l)}}for(let a of this.plugins)a.mustUpdate!=t&&a.destroy(this);this.plugins=i,this.pluginMap.clear()}else for(let i of this.plugins)i.mustUpdate=t;for(let i=0;i<this.plugins.length;i++)this.plugins[i].update(this);n!=r&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let n=t.value;if(n&&n.docViewUpdate)try{n.docViewUpdate(this)}catch(r){rc(this.state,r,"doc view update listener")}}}measure(t=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,t&&this.observer.forceFlush();let n=null,r=this.viewState.scrollParent,i=this.viewState.getScrollOffset(),{scrollAnchorPos:a,scrollAnchorHeight:o}=this.viewState;Math.abs(i-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(_3e(r||this.win))a=-1,o=this.viewState.heightMap.height;else{let g=this.viewState.scrollAnchorAt(i);a=g.from,o=g.top}this.updateState=1;let c=this.viewState.measure();if(!c&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let u=[];c&4||([this.measureRequests,u]=[u,this.measureRequests]);let d=u.map(g=>{try{return g.read(this)}catch(b){return rc(this.state,b),jte}}),f=$N.create(this,this.state,[]),h=!1;f.flags|=c,n?n.flags|=c:n=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),h=this.docView.update(f),h&&this.docViewUpdate());for(let g=0;g<u.length;g++)if(d[g]!=jte)try{let b=u[g];b.write&&b.write(d[g],this)}catch(b){rc(this.state,b)}if(h&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let b=((a<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(a).top)-o)/this.scaleY;if((b>1||b<-1)&&(r==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){i=i+b,r?r.scrollTop+=b:this.win.scrollBy(0,b),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(n&&!n.empty)for(let l of this.state.facet(NL))l(n)}get themeClasses(){return TL+" "+(this.state.facet(EL)?d5e:u5e)+" "+this.state.facet(w9)}updateAttrs(){let t=Nte(this,H3e,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),n={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(Gm)?"true":"false",class:"cm-content",style:`${Qt.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(n["aria-readonly"]="true"),Nte(this,Iq,n);let r=this.observer.ignore(()=>{let i=Xee(this.contentDOM,this.contentAttrs,n),a=Xee(this.dom,this.editorAttrs,t);return i||a});return this.editorAttrs=t,this.contentAttrs=n,r}showAnnouncements(t){let n=!0;for(let r of t)for(let i of r.effects)if(i.is(Yt.announce)){n&&(this.announceDOM.textContent=""),n=!1;let a=this.announceDOM.appendChild(document.createElement("div"));a.textContent=i.value}}mountStyles(){this.styleModules=this.state.facet(Vy);let t=this.state.facet(Yt.cspNonce);Bp.mount(this.root,this.styleModules.concat(iot).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let n=0;n<this.measureRequests.length;n++)if(this.measureRequests[n].key===t.key){this.measureRequests[n]=t;return}}this.measureRequests.push(t)}}plugin(t){let n=this.pluginMap.get(t);return(n===void 0||n&&n.plugin!=t)&&this.pluginMap.set(t,n=this.plugins.find(r=>r.plugin==t)||null),n&&n.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,n,r){return wM(this,t,ate(this,t,n,r))}moveByGroup(t,n){return wM(this,t,ate(this,t,n,r=>vat(this,t.head,r)))}visualLineSide(t,n){let r=this.bidiSpans(t),i=this.textDirectionAt(t.from),a=r[n?r.length-1:0];return bt.cursor(a.side(n,i)+t.from,a.forward(!n,i)?1:-1)}moveToLineBoundary(t,n,r=!0){return yat(this,t,n,r)}moveVertically(t,n,r){return wM(this,t,wat(this,t,n,r))}domAtPos(t,n=1){return this.docView.domAtPos(t,n)}posAtDOM(t,n=0){return this.docView.posFromDOM(t,n)}posAtCoords(t,n=!0){this.readMeasured();let r=_L(this,t,n);return r&&r.pos}posAndSideAtCoords(t,n=!0){return this.readMeasured(),_L(this,t,n)}coordsAtPos(t,n=1){this.readMeasured();let r=this.docView.coordsAt(t,n);if(!r||r.left==r.right)return r;let i=this.state.doc.lineAt(t),a=this.bidiSpans(i),o=a[Af.find(a,t-i.from,-1,n)];return LN(r,o.dir==Hs.LTR==n>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(B3e)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>uot)return R3e(t.length);let n=this.textDirectionAt(t.from),r;for(let a of this.bidiCache)if(a.from==t.from&&a.dir==n&&(a.fresh||M3e(a.isolates,r=nte(this,t))))return a.order;r||(r=nte(this,t));let i=Vit(t.text,n,r);return this.bidiCache.push(new qN(t.from,t.to,n,r,!0,i)),i}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||Qt.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{S3e(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,n={}){return p9.of(new _3(typeof t=="number"?bt.cursor(t):t,n.y,n.x,n.yMargin,n.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:n}=this.scrollDOM,r=this.viewState.scrollAnchorAt(t);return p9.of(new _3(bt.cursor(r.from),"start","start",r.top-t,n,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return ia.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return ia.define(()=>({}),{eventObservers:t})}static theme(t,n){let r=Bp.newName(),i=[w9.of(r),Vy.of(IL(`.${r}`,t))];return n&&n.dark&&i.push(EL.of(!0)),i}static baseTheme(t){return lg.lowest(Vy.of(IL("."+TL,t,f5e)))}static findFromDOM(t){var n;let r=t.querySelector(".cm-content"),i=r&&Zi.get(r)||Zi.get(t);return((n=i==null?void 0:i.root)===null||n===void 0?void 0:n.view)||null}}Yt.styleModule=Vy;Yt.inputHandler=F3e;Yt.clipboardInputFilter=Eq;Yt.clipboardOutputFilter=Tq;Yt.scrollHandler=q3e;Yt.focusChangeEffect=z3e;Yt.perLineTextDirection=B3e;Yt.exceptionSink=$3e;Yt.updateListener=NL;Yt.editable=Gm;Yt.mouseSelectionStyle=L3e;Yt.dragMovesSelection=D3e;Yt.clickAddsSelectionRange=P3e;Yt.decorations=H_;Yt.blockWrappers=V3e;Yt.outerDecorations=Mq;Yt.atomicRanges=K7;Yt.bidiIsolatedRanges=W3e;Yt.scrollMargins=Z3e;Yt.darkTheme=EL;Yt.cspNonce=Jt.define({combine:e=>e.length?e[0]:""});Yt.contentAttributes=Iq;Yt.editorAttributes=H3e;Yt.lineWrapping=Yt.contentAttributes.of({class:"cm-lineWrapping"});Yt.announce=ir.define();const uot=4096,jte={};class qN{constructor(t,n,r,i,a,o){this.from=t,this.to=n,this.dir=r,this.isolates=i,this.fresh=a,this.order=o}static update(t,n){if(n.empty&&!t.some(a=>a.fresh))return t;let r=[],i=t.length?t[t.length-1].dir:Hs.LTR;for(let a=Math.max(0,t.length-10);a<t.length;a++){let o=t[a];o.dir==i&&!n.touchesRange(o.from,o.to)&&r.push(new qN(n.mapPos(o.from,1),n.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return r}}function Nte(e,t,n){for(let r=e.state.facet(t),i=r.length-1;i>=0;i--){let a=r[i],o=typeof a=="function"?a(e):a;o&&Sq(o,n)}return n}const dot=Qt.mac?"mac":Qt.windows?"win":Qt.linux?"linux":"key";function fot(e,t){const n=e.split(/-(?!$)/);let r=n[n.length-1];r=="Space"&&(r=" ");let i,a,o,l;for(let c=0;c<n.length-1;++c){const u=n[c];if(/^(cmd|meta|m)$/i.test(u))l=!0;else if(/^a(lt)?$/i.test(u))i=!0;else if(/^(c|ctrl|control)$/i.test(u))a=!0;else if(/^s(hift)?$/i.test(u))o=!0;else if(/^mod$/i.test(u))t=="mac"?l=!0:a=!0;else throw new Error("Unrecognized modifier name: "+u)}return i&&(r="Alt-"+r),a&&(r="Ctrl-"+r),l&&(r="Meta-"+r),o&&(r="Shift-"+r),r}function k9(e,t,n){return t.altKey&&(e="Alt-"+e),t.ctrlKey&&(e="Ctrl-"+e),t.metaKey&&(e="Meta-"+e),n!==!1&&t.shiftKey&&(e="Shift-"+e),e}const mot=lg.default(Yt.domEventHandlers({keydown(e,t){return h5e(m5e(t.state),e,t,"editor")}})),H7=Jt.define({enables:mot}),Cte=new WeakMap;function m5e(e){let t=e.facet(H7),n=Cte.get(t);return n||Cte.set(t,n=got(t.reduce((r,i)=>r.concat(i),[]))),n}function hot(e,t,n){return h5e(m5e(e.state),t,e,n)}let Dh=null;const pot=4e3;function got(e,t=dot){let n=Object.create(null),r=Object.create(null),i=(o,l)=>{let c=r[o];if(c==null)r[o]=l;else if(c!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},a=(o,l,c,u,d)=>{var f,h;let g=n[o]||(n[o]=Object.create(null)),b=l.split(/ (?!$)/).map(k=>fot(k,t));for(let k=1;k<b.length;k++){let w=b.slice(0,k).join(" ");i(w,!0),g[w]||(g[w]={preventDefault:!0,stopPropagation:!1,run:[N=>{let C=Dh={view:N,prefix:w,scope:o};return setTimeout(()=>{Dh==C&&(Dh=null)},pot),!0}]})}let v=b.join(" ");i(v,!1);let j=g[v]||(g[v]={preventDefault:!1,stopPropagation:!1,run:((h=(f=g._any)===null||f===void 0?void 0:f.run)===null||h===void 0?void 0:h.slice())||[]});c&&j.run.push(c),u&&(j.preventDefault=!0),d&&(j.stopPropagation=!0)};for(let o of e){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let u of l){let d=n[u]||(n[u]=Object.create(null));d._any||(d._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=o;for(let h in d)d[h].run.push(g=>f(g,ML))}let c=o[t]||o.key;if(c)for(let u of l)a(u,c,o.run,o.preventDefault,o.stopPropagation),o.shift&&a(u,"Shift-"+c,o.shift,o.preventDefault,o.stopPropagation)}return n}let ML=null;function h5e(e,t,n,r){ML=t;let i=Tit(t),a=Xl(i,0),o=wf(a)==i.length&&i!=" ",l="",c=!1,u=!1,d=!1;Dh&&Dh.view==n&&Dh.scope==r&&(l=Dh.prefix+" ",n5e.indexOf(t.keyCode)<0&&(u=!0,Dh=null));let f=new Set,h=j=>{if(j){for(let k of j.run)if(!f.has(k)&&(f.add(k),k(n)))return j.stopPropagation&&(d=!0),!0;j.preventDefault&&(j.stopPropagation&&(d=!0),u=!0)}return!1},g=e[r],b,v;return g&&(h(g[l+k9(i,t,!o)])?c=!0:o&&(t.altKey||t.metaKey||t.ctrlKey)&&!(Qt.windows&&t.ctrlKey&&t.altKey)&&!(Qt.mac&&t.altKey&&!(t.ctrlKey||t.metaKey))&&(b=Up[t.keyCode])&&b!=i?(h(g[l+k9(b,t,!0)])||t.shiftKey&&(v=S6[t.keyCode])!=i&&v!=b&&h(g[l+k9(v,t,!1)]))&&(c=!0):o&&t.shiftKey&&h(g[l+k9(i,t,!0)])&&(c=!0),!c&&h(g._any)&&(c=!0)),u&&(c=!0),c&&d&&t.stopPropagation(),ML=null,c}class A2{constructor(t,n,r,i,a){this.className=t,this.left=n,this.top=r,this.width=i,this.height=a}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,n){return n.className!=this.className?!1:(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",this.width!=null&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,n,r){if(r.empty){let i=t.coordsAtPos(r.head,r.assoc||1);if(!i)return[];let a=p5e(t);return[new A2(n,i.left-a.left,i.top-a.top,null,i.bottom-i.top)]}else return xot(t,n,r)}}function p5e(e){let t=e.scrollDOM.getBoundingClientRect();return{left:(e.textDirection==Hs.LTR?t.left:t.right-e.scrollDOM.clientWidth*e.scaleX)-e.scrollDOM.scrollLeft*e.scaleX,top:t.top-e.scrollDOM.scrollTop*e.scaleY}}function Ste(e,t,n,r){let i=e.coordsAtPos(t,n*2);if(!i)return r;let a=e.dom.getBoundingClientRect(),o=(i.top+i.bottom)/2,l=e.posAtCoords({x:a.left+1,y:o}),c=e.posAtCoords({x:a.right-1,y:o});return l==null||c==null?r:{from:Math.max(r.from,Math.min(l,c)),to:Math.min(r.to,Math.max(l,c))}}function xot(e,t,n){if(n.to<=e.viewport.from||n.from>=e.viewport.to)return[];let r=Math.max(n.from,e.viewport.from),i=Math.min(n.to,e.viewport.to),a=e.textDirection==Hs.LTR,o=e.contentDOM,l=o.getBoundingClientRect(),c=p5e(e),u=o.querySelector(".cm-line"),d=u&&window.getComputedStyle(u),f=l.left+(d?parseInt(d.paddingLeft)+Math.min(0,parseInt(d.textIndent)):0),h=l.right-(d?parseInt(d.paddingRight):0),g=SL(e,r,1),b=SL(e,i,-1),v=g.type==Do.Text?g:null,j=b.type==Do.Text?b:null;if(v&&(e.lineWrapping||g.widgetLineBreaks)&&(v=Ste(e,r,1,v)),j&&(e.lineWrapping||b.widgetLineBreaks)&&(j=Ste(e,i,-1,j)),v&&j&&v.from==j.from&&v.to==j.to)return w(N(n.from,n.to,v));{let A=v?N(n.from,null,v):C(g,!1),_=j?N(null,n.to,j):C(b,!0),E=[];return(v||g).to<(j||b).from-(v&&j?1:0)||g.widgetLineBreaks>1&&A.bottom+e.defaultLineHeight/2<_.top?E.push(k(f,A.bottom,h,_.top)):A.bottom<_.top&&e.elementAtHeight((A.bottom+_.top)/2).type==Do.Text&&(A.bottom=_.top=(A.bottom+_.top)/2),w(A).concat(E).concat(w(_))}function k(A,_,E,T){return new A2(t,A-c.left,_-c.top,Math.max(0,E-A),T-_)}function w({top:A,bottom:_,horizontal:E}){let T=[];for(let M=0;M<E.length;M+=2)T.push(k(E[M],A,E[M+1],_));return T}function N(A,_,E){let T=1e9,M=-1e9,O=[];function P(Q,ee,B,F,Z){let W=e.coordsAtPos(Q,Q==E.to?-2:2),$=e.coordsAtPos(B,B==E.from?2:-2);!W||!$||(T=Math.min(W.top,$.top,T),M=Math.max(W.bottom,$.bottom,M),Z==Hs.LTR?O.push(a&&ee?f:W.left,a&&F?h:$.right):O.push(!a&&F?f:$.left,!a&&ee?h:W.right))}let z=A??E.from,L=_??E.to;for(let Q of e.visibleRanges)if(Q.to>z&&Q.from<L)for(let ee=Math.max(Q.from,z),B=Math.min(Q.to,L);;){let F=e.state.doc.lineAt(ee);for(let Z of e.bidiSpans(F)){let W=Z.from+F.from,$=Z.to+F.from;if(W>=B)break;$>ee&&P(Math.max(W,ee),A==null&&W<=z,Math.min($,B),_==null&&$>=L,Z.dir)}if(ee=F.to+1,ee>=B)break}return O.length==0&&P(z,A==null,L,_==null,e.textDirection),{top:T,bottom:M,horizontal:O}}function C(A,_){let E=l.top+(_?A.top:A.bottom);return{top:E,bottom:E,horizontal:[]}}}function bot(e,t){return e.constructor==t.constructor&&e.eq(t)}class yot{constructor(t,n){this.view=t,this.layer=n,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),n.above&&this.dom.classList.add("cm-layer-above"),n.class&&this.dom.classList.add(n.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),n.mount&&n.mount(this.dom,t)}update(t){t.startState.facet(Wk)!=t.state.facet(Wk)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){this.layer.updateOnDocViewUpdate!==!1&&t.requestMeasure(this.measureReq)}setOrder(t){let n=0,r=t.facet(Wk);for(;n<r.length&&r[n]!=this.layer;)n++;this.dom.style.zIndex=String((this.layer.above?150:-1)-n)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:t,scaleY:n}=this.view;(t!=this.scaleX||n!=this.scaleY)&&(this.scaleX=t,this.scaleY=n,this.dom.style.transform=`scale(${1/t}, ${1/n})`)}draw(t){if(t.length!=this.drawn.length||t.some((n,r)=>!bot(n,this.drawn[r]))){let n=this.dom.firstChild,r=0;for(let i of t)i.update&&n&&i.constructor&&this.drawn[r].constructor&&i.update(n,this.drawn[r])?(n=n.nextSibling,r++):this.dom.insertBefore(i.draw(),n);for(;n;){let i=n.nextSibling;n.remove(),n=i}this.drawn=t,Qt.safari&&Qt.safari_version>=26&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Wk=Jt.define();function g5e(e){return[ia.define(t=>new yot(t,e)),Wk.of(e)]}const E5=Jt.define({combine(e){return im(e,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(t,n)=>Math.min(t,n),drawRangeCursor:(t,n)=>t||n})}});function vot(e={}){return[E5.of(e),wot,kot,jot,U3e.of(!0)]}function x5e(e){return e.startState.facet(E5)!=e.state.facet(E5)}const wot=g5e({above:!0,markers(e){let{state:t}=e,n=t.facet(E5),r=[];for(let i of t.selection.ranges){let a=i==t.selection.main;if(i.empty||n.drawRangeCursor&&!(a&&Qt.ios&&n.iosSelectionHandles)){let o=a?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=i.empty?i:bt.cursor(i.head,i.assoc);for(let c of A2.forRange(e,o,l))r.push(c)}}return r},update(e,t){e.transactions.some(r=>r.selection)&&(t.style.animationName=t.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let n=x5e(e);return n&&_te(e.state,t),e.docChanged||e.selectionSet||n},mount(e,t){_te(t.state,e)},class:"cm-cursorLayer"});function _te(e,t){t.style.animationDuration=e.facet(E5).cursorBlinkRate+"ms"}const kot=g5e({above:!1,markers(e){let t=[],{main:n,ranges:r}=e.state.selection;for(let i of r)if(!i.empty)for(let a of A2.forRange(e,"cm-selectionBackground",i))t.push(a);if(Qt.ios&&!n.empty&&e.state.facet(E5).iosSelectionHandles){for(let i of A2.forRange(e,"cm-selectionHandle cm-selectionHandle-start",bt.cursor(n.from,1)))t.push(i);for(let i of A2.forRange(e,"cm-selectionHandle cm-selectionHandle-end",bt.cursor(n.to,1)))t.push(i)}return t},update(e,t){return e.docChanged||e.selectionSet||e.viewportChanged||x5e(e)},class:"cm-selectionLayer"}),jot=lg.highest(Yt.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),b5e=ir.define({map(e,t){return e==null?null:t.mapPos(e)}}),Zy=qo.define({create(){return null},update(e,t){return e!=null&&(e=t.changes.mapPos(e)),t.effects.reduce((n,r)=>r.is(b5e)?r.value:n,e)}}),Not=ia.fromClass(class{constructor(e){this.view=e,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(e){var t;let n=e.state.field(Zy);n==null?this.cursor!=null&&((t=this.cursor)===null||t===void 0||t.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(e.startState.field(Zy)!=n||e.docChanged||e.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:e}=this,t=e.state.field(Zy),n=t!=null&&e.coordsAtPos(t);if(!n)return null;let r=e.scrollDOM.getBoundingClientRect();return{left:n.left-r.left+e.scrollDOM.scrollLeft*e.scaleX,top:n.top-r.top+e.scrollDOM.scrollTop*e.scaleY,height:n.bottom-n.top}}drawCursor(e){if(this.cursor){let{scaleX:t,scaleY:n}=this.view;e?(this.cursor.style.left=e.left/t+"px",this.cursor.style.top=e.top/n+"px",this.cursor.style.height=e.height/n+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(e){this.view.state.field(Zy)!=e&&this.view.dispatch({effects:b5e.of(e)})}},{eventObservers:{dragover(e){this.setDropPos(this.view.posAtCoords({x:e.clientX,y:e.clientY}))},dragleave(e){(e.target==this.view.contentDOM||!this.view.contentDOM.contains(e.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function Cot(){return[Zy,Not]}function Ate(e,t,n,r,i){t.lastIndex=0;for(let a=e.iterRange(n,r),o=n,l;!a.next().done;o+=a.value.length)if(!a.lineBreak)for(;l=t.exec(a.value);)i(o+l.index,l)}function Sot(e,t){let n=e.visibleRanges;if(n.length==1&&n[0].from==e.viewport.from&&n[0].to==e.viewport.to)return n;let r=[];for(let{from:i,to:a}of n)i=Math.max(e.state.doc.lineAt(i).from,i-t),a=Math.min(e.state.doc.lineAt(a).to,a+t),r.length&&r[r.length-1].to>=i?r[r.length-1].to=a:r.push({from:i,to:a});return r}class _ot{constructor(t){const{regexp:n,decoration:r,decorate:i,boundary:a,maxLength:o=1e3}=t;if(!n.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=n,i)this.addMatch=(l,c,u,d)=>i(d,u,u+l[0].length,l,c);else if(typeof r=="function")this.addMatch=(l,c,u,d)=>{let f=r(l,c,u);f&&d(u,u+l[0].length,f)};else if(r)this.addMatch=(l,c,u,d)=>d(u,u+l[0].length,r);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=a,this.maxLength=o}createDeco(t){let n=new S1,r=n.add.bind(n);for(let{from:i,to:a}of Sot(t,this.maxLength))Ate(t.state.doc,this.regexp,i,a,(o,l)=>this.addMatch(l,t,o,r));return n.finish()}updateDeco(t,n){let r=1e9,i=-1;return t.docChanged&&t.changes.iterChanges((a,o,l,c)=>{c>=t.view.viewport.from&&l<=t.view.viewport.to&&(r=Math.min(l,r),i=Math.max(c,i))}),t.viewportMoved||i-r>1e3?this.createDeco(t.view):i>-1?this.updateRange(t.view,n.map(t.changes),r,i):n}updateRange(t,n,r,i){for(let a of t.visibleRanges){let o=Math.max(a.from,r),l=Math.min(a.to,i);if(l>=o){let c=t.state.doc.lineAt(o),u=c.to<l?t.state.doc.lineAt(l):c,d=Math.max(a.from,c.from),f=Math.min(a.to,u.to);if(this.boundary){for(;o>c.from;o--)if(this.boundary.test(c.text[o-1-c.from])){d=o;break}for(;l<u.to;l++)if(this.boundary.test(u.text[l-u.from])){f=l;break}}let h=[],g,b=(v,j,k)=>h.push(k.range(v,j));if(c==u)for(this.regexp.lastIndex=d-c.from;(g=this.regexp.exec(c.text))&&g.index<f-c.from;)this.addMatch(g,t,g.index+c.from,b);else Ate(t.state.doc,this.regexp,d,f,(v,j)=>this.addMatch(j,t,v,b));n=n.update({filterFrom:d,filterTo:f,filter:(v,j)=>v<d||j>f,add:h})}}return n}}const RL=/x/.unicode!=null?"gu":"g",Aot=new RegExp(`[\0-\b
1295
1295
  --Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\uFEFF-]`,RL),Eot={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let NM=null;function Tot(){var e;if(NM==null&&typeof document<"u"&&document.body){let t=document.body.style;NM=((e=t.tabSize)!==null&&e!==void 0?e:t.MozTabSize)!=null}return NM||!1}const Zk=Jt.define({combine(e){let t=im(e,{render:null,specialChars:Aot,addSpecialChars:null});return(t.replaceTabs=!Tot())&&(t.specialChars=new RegExp(" |"+t.specialChars.source,RL)),t.addSpecialChars&&(t.specialChars=new RegExp(t.specialChars.source+"|"+t.addSpecialChars.source,RL)),t}});function Iot(e={}){return[Zk.of(e),Mot()]}let Ete=null;function Mot(){return Ete||(Ete=ia.fromClass(class{constructor(e){this.view=e,this.decorations=$n.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(e.state.facet(Zk)),this.decorations=this.decorator.createDeco(e)}makeDecorator(e){return new _ot({regexp:e.specialChars,decoration:(t,n,r)=>{let{doc:i}=n.state,a=Xl(t[0],0);if(a==9){let o=i.lineAt(r),l=n.state.tabSize,c=I4(o.text,l,r-o.from);return $n.replace({widget:new Dot((l-c%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[a]||(this.decorationCache[a]=$n.replace({widget:new Pot(e,a)}))},boundary:e.replaceTabs?void 0:/[^]/})}update(e){let t=e.state.facet(Zk);e.startState.facet(Zk)!=t?(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(e.view)):this.decorations=this.decorator.updateDeco(e,this.decorations)}},{decorations:e=>e.decorations}))}const Rot="•";function Oot(e){return e>=32?Rot:e==10?"␤":String.fromCharCode(9216+e)}class Pot extends am{constructor(t,n){super(),this.options=t,this.code=n}eq(t){return t.code==this.code}toDOM(t){let n=Oot(this.code),r=t.state.phrase("Control character")+" "+(Eot[this.code]||"0x"+this.code.toString(16)),i=this.options.render&&this.options.render(this.code,r,n);if(i)return i;let a=document.createElement("span");return a.textContent=n,a.title=r,a.setAttribute("aria-label",r),a.className="cm-specialChar",a}ignoreEvent(){return!1}}class Dot extends am{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent=" ",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}function Lot(){return Fot}const $ot=$n.line({class:"cm-activeLine"}),Fot=ia.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.docChanged||e.selectionSet)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=-1,n=[];for(let r of e.state.selection.ranges){let i=e.lineBlockAt(r.head);i.from>t&&(n.push($ot.range(i.from)),t=i.from)}return $n.set(n)}},{decorations:e=>e.decorations}),OL=2e3;function zot(e,t,n){let r=Math.min(t.line,n.line),i=Math.max(t.line,n.line),a=[];if(t.off>OL||n.off>OL||t.col<0||n.col<0){let o=Math.min(t.off,n.off),l=Math.max(t.off,n.off);for(let c=r;c<=i;c++){let u=e.doc.line(c);u.length<=l&&a.push(bt.range(u.from+o,u.to+l))}}else{let o=Math.min(t.col,n.col),l=Math.max(t.col,n.col);for(let c=r;c<=i;c++){let u=e.doc.line(c),d=mL(u.text,o,e.tabSize,!0);if(d<0)a.push(bt.cursor(u.to));else{let f=mL(u.text,l,e.tabSize);a.push(bt.range(u.from+d,u.from+f))}}}return a}function Bot(e,t){let n=e.coordsAtPos(e.viewport.from);return n?Math.round(Math.abs((n.left-t)/e.defaultCharacterWidth)):-1}function Tte(e,t){let n=e.posAtCoords({x:t.clientX,y:t.clientY},!1),r=e.state.doc.lineAt(n),i=n-r.from,a=i>OL?-1:i==r.length?Bot(e,t.clientX):I4(r.text,e.state.tabSize,n-r.from);return{line:r.number,col:a,off:i}}function Uot(e,t){let n=Tte(e,t),r=e.state.selection;return n?{update(i){if(i.docChanged){let a=i.changes.mapPos(i.startState.doc.line(n.line).from),o=i.state.doc.lineAt(a);n={line:o.number,col:n.col,off:Math.min(n.off,o.length)},r=r.map(i.changes)}},get(i,a,o){let l=Tte(e,i);if(!l)return r;let c=zot(e.state,n,l);return c.length?o?bt.create(c.concat(r.ranges)):bt.create(c):r}}:null}function qot(e){let t=(n=>n.altKey&&n.button==0);return Yt.mouseSelectionStyle.of((n,r)=>t(r)?Uot(n,r):null)}const Kot={Alt:[18,e=>!!e.altKey],Control:[17,e=>!!e.ctrlKey],Shift:[16,e=>!!e.shiftKey],Meta:[91,e=>!!e.metaKey]},Hot={style:"cursor: crosshair"};function Vot(e={}){let[t,n]=Kot[e.key||"Alt"],r=ia.fromClass(class{constructor(i){this.view=i,this.isDown=!1}set(i){this.isDown!=i&&(this.isDown=i,this.view.update([]))}},{eventObservers:{keydown(i){this.set(i.keyCode==t||n(i))},keyup(i){(i.keyCode==t||!n(i))&&this.set(!1)},mousemove(i){this.set(n(i))}}});return[r,Yt.contentAttributes.of(i=>{var a;return!((a=i.plugin(r))===null||a===void 0)&&a.isDown?Hot:null})]}const j9="-10000px";class y5e{constructor(t,n,r,i){this.facet=n,this.createTooltipView=r,this.removeTooltipView=i,this.input=t.state.facet(n),this.tooltips=this.input.filter(o=>o);let a=null;this.tooltipViews=this.tooltips.map(o=>a=r(o,a))}update(t,n){var r;let i=t.state.facet(this.facet),a=i.filter(c=>c);if(i===this.input){for(let c of this.tooltipViews)c.update&&c.update(t);return!1}let o=[],l=n?[]:null;for(let c=0;c<a.length;c++){let u=a[c],d=-1;if(u){for(let f=0;f<this.tooltips.length;f++){let h=this.tooltips[f];h&&h.create==u.create&&(d=f)}if(d<0)o[c]=this.createTooltipView(u,c?o[c-1]:null),l&&(l[c]=!!u.above);else{let f=o[c]=this.tooltipViews[d];l&&(l[c]=n[d]),f.update&&f.update(t)}}}for(let c of this.tooltipViews)o.indexOf(c)<0&&(this.removeTooltipView(c),(r=c.destroy)===null||r===void 0||r.call(c));return n&&(l.forEach((c,u)=>n[u]=c),n.length=l.length),this.input=i,this.tooltips=a,this.tooltipViews=o,!0}}function Wot(e){let t=e.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:t.clientHeight,right:t.clientWidth}}const CM=Jt.define({combine:e=>{var t,n,r;return{position:Qt.ios?"absolute":((t=e.find(i=>i.position))===null||t===void 0?void 0:t.position)||"fixed",parent:((n=e.find(i=>i.parent))===null||n===void 0?void 0:n.parent)||null,tooltipSpace:((r=e.find(i=>i.tooltipSpace))===null||r===void 0?void 0:r.tooltipSpace)||Wot}}}),Ite=new WeakMap,Lq=ia.fromClass(class{constructor(e){this.view=e,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let t=e.state.facet(CM);this.position=t.position,this.parent=t.parent,this.classes=e.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new y5e(e,$q,(n,r)=>this.createTooltip(n,r),n=>{this.resizeObserver&&this.resizeObserver.unobserve(n.dom),n.dom.remove()}),this.above=this.manager.tooltips.map(n=>!!n.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(n=>{Date.now()>this.lastTransaction-50&&n.length>0&&n[n.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),e.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let e of this.manager.tooltipViews)this.intersectionObserver.observe(e.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(e){e.transactions.length&&(this.lastTransaction=Date.now());let t=this.manager.update(e,this.above);t&&this.observeIntersection();let n=t||e.geometryChanged,r=e.state.facet(CM);if(r.position!=this.position&&!this.madeAbsolute){this.position=r.position;for(let i of this.manager.tooltipViews)i.dom.style.position=this.position;n=!0}if(r.parent!=this.parent){this.parent&&this.container.remove(),this.parent=r.parent,this.createContainer();for(let i of this.manager.tooltipViews)this.container.appendChild(i.dom);n=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);n&&this.maybeMeasure()}createTooltip(e,t){let n=e.create(this.view),r=t?t.dom:null;if(n.dom.classList.add("cm-tooltip"),e.arrow&&!n.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let i=document.createElement("div");i.className="cm-tooltip-arrow",n.dom.appendChild(i)}return n.dom.style.position=this.position,n.dom.style.top=j9,n.dom.style.left="0px",this.container.insertBefore(n.dom,r),n.mount&&n.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(n.dom),n}destroy(){var e,t,n;this.view.win.removeEventListener("resize",this.measureSoon);for(let r of this.manager.tooltipViews)r.dom.remove(),(e=r.destroy)===null||e===void 0||e.call(r);this.parent&&this.container.remove(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(n=this.intersectionObserver)===null||n===void 0||n.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let e=1,t=1,n=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:a}=this.manager.tooltipViews[0];if(Qt.safari){let o=a.getBoundingClientRect();n=Math.abs(o.top+1e4)>1||Math.abs(o.left)>1}else n=!!a.offsetParent&&a.offsetParent!=this.container.ownerDocument.body}if(n||this.position=="absolute")if(this.parent){let a=this.parent.getBoundingClientRect();a.width&&a.height&&(e=a.width/this.parent.offsetWidth,t=a.height/this.parent.offsetHeight)}else({scaleX:e,scaleY:t}=this.view.viewState);let r=this.view.scrollDOM.getBoundingClientRect(),i=Rq(this.view);return{visible:{left:r.left+i.left,top:r.top+i.top,right:r.right-i.right,bottom:r.bottom-i.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((a,o)=>{let l=this.manager.tooltipViews[o];return l.getCoords?l.getCoords(a.pos):this.view.coordsAtPos(a.pos)}),size:this.manager.tooltipViews.map(({dom:a})=>a.getBoundingClientRect()),space:this.view.state.facet(CM).tooltipSpace(this.view),scaleX:e,scaleY:t,makeAbsolute:n}}writeMeasure(e){var t;if(e.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:n,space:r,scaleX:i,scaleY:a}=e,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let c=this.manager.tooltips[l],u=this.manager.tooltipViews[l],{dom:d}=u,f=e.pos[l],h=e.size[l];if(!f||c.clip!==!1&&(f.bottom<=Math.max(n.top,r.top)||f.top>=Math.min(n.bottom,r.bottom)||f.right<Math.max(n.left,r.left)-.1||f.left>Math.min(n.right,r.right)+.1)){d.style.top=j9;continue}let g=c.arrow?u.dom.querySelector(".cm-tooltip-arrow"):null,b=g?7:0,v=h.right-h.left,j=(t=Ite.get(u))!==null&&t!==void 0?t:h.bottom-h.top,k=u.offset||Got,w=this.view.textDirection==Hs.LTR,N=h.width>r.right-r.left?w?r.left:r.right-h.width:w?Math.max(r.left,Math.min(f.left-(g?14:0)+k.x,r.right-v)):Math.min(Math.max(r.left,f.left-v+(g?14:0)-k.x),r.right-v),C=this.above[l];!c.strictSide&&(C?f.top-j-b-k.y<r.top:f.bottom+j+b+k.y>r.bottom)&&C==r.bottom-f.bottom>f.top-r.top&&(C=this.above[l]=!C);let A=(C?f.top-r.top:r.bottom-f.bottom)-b;if(A<j&&u.resize!==!1){if(A<this.view.defaultLineHeight){d.style.top=j9;continue}Ite.set(u,j),d.style.height=(j=A)/a+"px"}else d.style.height&&(d.style.height="");let _=C?f.top-j-b-k.y:f.bottom+b+k.y,E=N+v;if(u.overlap!==!0)for(let T of o)T.left<E&&T.right>N&&T.top<_+j&&T.bottom>_&&(_=C?T.top-j-2-b:T.bottom+b+2);if(this.position=="absolute"?(d.style.top=(_-e.parent.top)/a+"px",Mte(d,(N-e.parent.left)/i)):(d.style.top=_/a+"px",Mte(d,N/i)),g){let T=f.left+(w?k.x:-k.x)-(N+14-7);g.style.left=T/i+"px"}u.overlap!==!0&&o.push({left:N,top:_,right:E,bottom:_+j}),d.classList.toggle("cm-tooltip-above",C),d.classList.toggle("cm-tooltip-below",!C),u.positioned&&u.positioned(e.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let e of this.manager.tooltipViews)e.dom.style.top=j9}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Mte(e,t){let n=parseInt(e.style.left,10);(isNaN(n)||Math.abs(t-n)>1)&&(e.style.left=t+"px")}const Zot=Yt.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),Got={x:0,y:0},$q=Jt.define({enables:[Lq,Zot]}),KN=Jt.define({combine:e=>e.reduce((t,n)=>t.concat(n),[])});class G_{static create(t){return new G_(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new y5e(t,KN,(n,r)=>this.createHostedView(n,r),n=>n.dom.remove())}createHostedView(t,n){let r=t.create(this.view);return r.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(r.dom,n?n.dom.nextSibling:this.dom.firstChild),this.mounted&&r.mount&&r.mount(this.view),r}mount(t){for(let n of this.manager.tooltipViews)n.mount&&n.mount(t);this.mounted=!0}positioned(t){for(let n of this.manager.tooltipViews)n.positioned&&n.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let n of this.manager.tooltipViews)(t=n.destroy)===null||t===void 0||t.call(n)}passProp(t){let n;for(let r of this.manager.tooltipViews){let i=r[t];if(i!==void 0){if(n===void 0)n=i;else if(n!==i)return}}return n}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const Qot=$q.compute([KN],e=>{let t=e.facet(KN);return t.length===0?null:{pos:Math.min(...t.map(n=>n.pos)),end:Math.max(...t.map(n=>{var r;return(r=n.end)!==null&&r!==void 0?r:n.pos})),create:G_.create,above:t[0].above,arrow:t.some(n=>n.arrow)}});class Yot{constructor(t,n,r,i,a){this.view=t,this.source=n,this.field=r,this.setHover=i,this.hoverTime=a,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;t<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-t):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:t,lastMove:n}=this,r=t.docView.tile.nearest(n.target);if(!r)return;let i,a=1;if(r.isWidget())i=r.posAtStart;else{if(i=t.posAtCoords(n),i==null)return;let l=t.coordsAtPos(i);if(!l||n.y<l.top||n.y>l.bottom||n.x<l.left-t.defaultCharacterWidth||n.x>l.right+t.defaultCharacterWidth)return;let c=t.bidiSpans(t.state.doc.lineAt(i)).find(d=>d.from<=i&&d.to>=i),u=c&&c.dir==Hs.RTL?-1:1;a=n.x<l.left?-u:u}let o=this.source(t,i,a);if(o!=null&&o.then){let l=this.pending={pos:i};o.then(c=>{this.pending==l&&(this.pending=null,c&&!(Array.isArray(c)&&!c.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(c)?c:[c])}))},c=>rc(t.state,c,"hover tooltip"))}else o&&!(Array.isArray(o)&&!o.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(o)?o:[o])})}get tooltip(){let t=this.view.plugin(Lq),n=t?t.manager.tooltips.findIndex(r=>r.create==G_.create):-1;return n>-1?t.manager.tooltipViews[n]:null}mousemove(t){var n,r;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:i,tooltip:a}=this;if(i.length&&a&&!Jot(a.dom,t)||this.pending){let{pos:o}=i[0]||this.pending,l=(r=(n=i[0])===null||n===void 0?void 0:n.end)!==null&&r!==void 0?r:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!Xot(this.view,o,l,t.clientX,t.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:n}=this;if(n.length){let{tooltip:r}=this;r&&r.dom.contains(t.relatedTarget)?this.watchTooltipLeave(r.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let n=r=>{t.removeEventListener("mouseleave",n),this.active.length&&!this.view.dom.contains(r.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",n)}destroy(){clearTimeout(this.hoverTimeout),clearTimeout(this.restartTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const N9=4;function Jot(e,t){let{left:n,right:r,top:i,bottom:a}=e.getBoundingClientRect(),o;if(o=e.querySelector(".cm-tooltip-arrow")){let l=o.getBoundingClientRect();i=Math.min(l.top,i),a=Math.max(l.bottom,a)}return t.clientX>=n-N9&&t.clientX<=r+N9&&t.clientY>=i-N9&&t.clientY<=a+N9}function Xot(e,t,n,r,i,a){let o=e.scrollDOM.getBoundingClientRect(),l=e.documentTop+e.documentPadding.top+e.contentHeight;if(o.left>r||o.right<r||o.top>i||Math.min(o.bottom,l)<i)return!1;let c=e.posAtCoords({x:r,y:i},!1);return c>=t&&c<=n}function elt(e,t={}){let n=ir.define(),r=qo.define({create(){return[]},update(i,a){if(i.length&&(t.hideOnChange&&(a.docChanged||a.selection)?i=[]:t.hideOn&&(i=i.filter(o=>!t.hideOn(a,o))),a.docChanged)){let o=[];for(let l of i){let c=a.changes.mapPos(l.pos,-1,To.TrackDel);if(c!=null){let u=Object.assign(Object.create(null),l);u.pos=c,u.end!=null&&(u.end=a.changes.mapPos(u.end)),o.push(u)}}i=o}for(let o of a.effects)o.is(n)&&(i=o.value),o.is(tlt)&&(i=[]);return i},provide:i=>KN.from(i)});return{active:r,extension:[r,ia.define(i=>new Yot(i,e,r,n,t.hoverTime||300)),Qot]}}function v5e(e,t){let n=e.plugin(Lq);if(!n)return null;let r=n.manager.tooltips.indexOf(t);return r<0?null:n.manager.tooltipViews[r]}const tlt=ir.define(),Rte=Jt.define({combine(e){let t,n;for(let r of e)t=t||r.topContainer,n=n||r.bottomContainer;return{topContainer:t,bottomContainer:n}}});function Fq(e,t){let n=e.plugin(w5e),r=n?n.specs.indexOf(t):-1;return r>-1?n.panels[r]:null}const w5e=ia.fromClass(class{constructor(e){this.input=e.state.facet(T6),this.specs=this.input.filter(n=>n),this.panels=this.specs.map(n=>n(e));let t=e.state.facet(Rte);this.top=new C9(e,!0,t.topContainer),this.bottom=new C9(e,!1,t.bottomContainer),this.top.sync(this.panels.filter(n=>n.top)),this.bottom.sync(this.panels.filter(n=>!n.top));for(let n of this.panels)n.dom.classList.add("cm-panel"),n.mount&&n.mount()}update(e){let t=e.state.facet(Rte);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new C9(e.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new C9(e.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let n=e.state.facet(T6);if(n!=this.input){let r=n.filter(c=>c),i=[],a=[],o=[],l=[];for(let c of r){let u=this.specs.indexOf(c),d;u<0?(d=c(e.view),l.push(d)):(d=this.panels[u],d.update&&d.update(e)),i.push(d),(d.top?a:o).push(d)}this.specs=r,this.panels=i,this.top.sync(a),this.bottom.sync(o);for(let c of l)c.dom.classList.add("cm-panel"),c.mount&&c.mount()}else for(let r of this.panels)r.update&&r.update(e)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:e=>Yt.scrollMargins.of(t=>{let n=t.plugin(e);return n&&{top:n.top.scrollMargin(),bottom:n.bottom.scrollMargin()}})});class C9{constructor(t,n,r){this.view=t,this.top=n,this.container=r,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let n of this.panels)n.destroy&&t.indexOf(n)<0&&n.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let n=this.container||this.view.dom;n.insertBefore(this.dom,this.top?n.firstChild:null)}let t=this.dom.firstChild;for(let n of this.panels)if(n.dom.parentNode==this.dom){for(;t!=n.dom;)t=Ote(t);t=t.nextSibling}else this.dom.insertBefore(n.dom,t);for(;t;)t=Ote(t)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}}function Ote(e){let t=e.nextSibling;return e.remove(),t}const T6=Jt.define({enables:w5e});function nlt(e,t){let n,r=new Promise(o=>n=o),i=o=>rlt(o,t,n);e.state.field(SM,!1)?e.dispatch({effects:k5e.of(i)}):e.dispatch({effects:ir.appendConfig.of(SM.init(()=>[i]))});let a=j5e.of(i);return{close:a,result:r.then(o=>((e.win.queueMicrotask||(c=>e.win.setTimeout(c,10)))(()=>{e.state.field(SM).indexOf(i)>-1&&e.dispatch({effects:a})}),o))}}const SM=qo.define({create(){return[]},update(e,t){for(let n of t.effects)n.is(k5e)?e=[n.value].concat(e):n.is(j5e)&&(e=e.filter(r=>r!=n.value));return e},provide:e=>T6.computeN([e],t=>t.field(e))}),k5e=ir.define(),j5e=ir.define();function rlt(e,t,n){let r=t.content?t.content(e,()=>o(null)):null;if(!r){if(r=Ps("form"),t.input){let l=Ps("input",t.input);/^(text|password|number|email|tel|url)$/.test(l.type)&&l.classList.add("cm-textfield"),l.name||(l.name="input"),r.appendChild(Ps("label",(t.label||"")+": ",l))}else r.appendChild(document.createTextNode(t.label||""));r.appendChild(document.createTextNode(" ")),r.appendChild(Ps("button",{class:"cm-button",type:"submit"},t.submitLabel||"OK"))}let i=r.nodeName=="FORM"?[r]:r.querySelectorAll("form");for(let l=0;l<i.length;l++){let c=i[l];c.addEventListener("keydown",u=>{u.keyCode==27?(u.preventDefault(),o(null)):u.keyCode==13&&(u.preventDefault(),o(c))}),c.addEventListener("submit",u=>{u.preventDefault(),o(c)})}let a=Ps("div",r,Ps("button",{onclick:()=>o(null),"aria-label":e.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));t.class&&(a.className=t.class),a.classList.add("cm-dialog");function o(l){a.contains(a.ownerDocument.activeElement)&&e.focus(),n(l)}return{dom:a,top:t.top,mount:()=>{if(t.focus){let l;typeof t.focus=="string"?l=r.querySelector(t.focus):l=r.querySelector("input")||r.querySelector("button"),l&&"select"in l?l.select():l&&"focus"in l&&l.focus()}}}}class A1 extends zp{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}A1.prototype.elementClass="";A1.prototype.toDOM=void 0;A1.prototype.mapMode=To.TrackBefore;A1.prototype.startSide=A1.prototype.endSide=-1;A1.prototype.point=!0;const Gk=Jt.define(),slt=Jt.define(),ilt={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>Lr.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Cv=Jt.define();function alt(e){return[N5e(),Cv.of({...ilt,...e})]}const Pte=Jt.define({combine:e=>e.some(t=>t)});function N5e(e){return[olt]}const olt=ia.fromClass(class{constructor(e){this.view=e,this.domAfter=null,this.prevViewport=e.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=e.state.facet(Cv).map(t=>new Lte(e,t)),this.fixed=!e.state.facet(Pte);for(let t of this.gutters)t.config.side=="after"?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),e.scrollDOM.insertBefore(this.dom,e.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(e){if(this.updateGutters(e)){let t=this.prevViewport,n=e.view.viewport,r=Math.min(t.to,n.to)-Math.max(t.from,n.from);this.syncGutters(r<(n.to-n.from)*.8)}if(e.geometryChanged){let t=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=t,this.domAfter&&(this.domAfter.style.minHeight=t)}this.view.state.facet(Pte)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=e.view.viewport}syncGutters(e){let t=this.dom.nextSibling;e&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let n=Lr.iter(this.view.state.facet(Gk),this.view.viewport.from),r=[],i=this.gutters.map(a=>new llt(a,this.view.viewport,-this.view.documentPadding.top));for(let a of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(a.type)){let o=!0;for(let l of a.type)if(l.type==Do.Text&&o){PL(n,r,l.from);for(let c of i)c.line(this.view,l,r);o=!1}else if(l.widget)for(let c of i)c.widget(this.view,l)}else if(a.type==Do.Text){PL(n,r,a.from);for(let o of i)o.line(this.view,a,r)}else if(a.widget)for(let o of i)o.widget(this.view,a);for(let a of i)a.finish();e&&(this.view.scrollDOM.insertBefore(this.dom,t),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(e){let t=e.startState.facet(Cv),n=e.state.facet(Cv),r=e.docChanged||e.heightChanged||e.viewportChanged||!Lr.eq(e.startState.facet(Gk),e.state.facet(Gk),e.view.viewport.from,e.view.viewport.to);if(t==n)for(let i of this.gutters)i.update(e)&&(r=!0);else{r=!0;let i=[];for(let a of n){let o=t.indexOf(a);o<0?i.push(new Lte(this.view,a)):(this.gutters[o].update(e),i.push(this.gutters[o]))}for(let a of this.gutters)a.dom.remove(),i.indexOf(a)<0&&a.destroy();for(let a of i)a.config.side=="after"?this.getDOMAfter().appendChild(a.dom):this.dom.appendChild(a.dom);this.gutters=i}return r}destroy(){for(let e of this.gutters)e.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:e=>Yt.scrollMargins.of(t=>{let n=t.plugin(e);if(!n||n.gutters.length==0||!n.fixed)return null;let r=n.dom.offsetWidth*t.scaleX,i=n.domAfter?n.domAfter.offsetWidth*t.scaleX:0;return t.textDirection==Hs.LTR?{left:r,right:i}:{right:r,left:i}})});function Dte(e){return Array.isArray(e)?e:[e]}function PL(e,t,n){for(;e.value&&e.from<=n;)e.from==n&&t.push(e.value),e.next()}class llt{constructor(t,n,r){this.gutter=t,this.height=r,this.i=0,this.cursor=Lr.iter(t.markers,n.from)}addElement(t,n,r){let{gutter:i}=this,a=(n.top-this.height)/t.scaleY,o=n.height/t.scaleY;if(this.i==i.elements.length){let l=new C5e(t,o,a,r);i.elements.push(l),i.dom.appendChild(l.dom)}else i.elements[this.i].update(t,o,a,r);this.height=n.bottom,this.i++}line(t,n,r){let i=[];PL(this.cursor,i,n.from),r.length&&(i=i.concat(r));let a=this.gutter.config.lineMarker(t,n,i);a&&i.unshift(a);let o=this.gutter;i.length==0&&!o.config.renderEmptyElements||this.addElement(t,n,i)}widget(t,n){let r=this.gutter.config.widgetMarker(t,n.widget,n),i=r?[r]:null;for(let a of t.state.facet(slt)){let o=a(t,n.widget,n);o&&(i||(i=[])).push(o)}i&&this.addElement(t,n,i)}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let n=t.elements.pop();t.dom.removeChild(n.dom),n.destroy()}}}class Lte{constructor(t,n){this.view=t,this.config=n,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let r in n.domEventHandlers)this.dom.addEventListener(r,i=>{let a=i.target,o;if(a!=this.dom&&this.dom.contains(a)){for(;a.parentNode!=this.dom;)a=a.parentNode;let c=a.getBoundingClientRect();o=(c.top+c.bottom)/2}else o=i.clientY;let l=t.lineBlockAtHeight(o-t.documentTop);n.domEventHandlers[r](t,l,i)&&i.preventDefault()});this.markers=Dte(n.markers(t)),n.initialSpacer&&(this.spacer=new C5e(t,0,0,[n.initialSpacer(t)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(t){let n=this.markers;if(this.markers=Dte(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let i=this.config.updateSpacer(this.spacer.markers[0],t);i!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[i])}let r=t.view.viewport;return!Lr.eq(this.markers,n,r.from,r.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(t):!1)}destroy(){for(let t of this.elements)t.destroy()}}class C5e{constructor(t,n,r,i){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,n,r,i)}update(t,n,r,i){this.height!=n&&(this.height=n,this.dom.style.height=n+"px"),this.above!=r&&(this.dom.style.marginTop=(this.above=r)?r+"px":""),clt(this.markers,i)||this.setMarkers(t,i)}setMarkers(t,n){let r="cm-gutterElement",i=this.dom.firstChild;for(let a=0,o=0;;){let l=o,c=a<n.length?n[a++]:null,u=!1;if(c){let d=c.elementClass;d&&(r+=" "+d);for(let f=o;f<this.markers.length;f++)if(this.markers[f].compare(c)){l=f,u=!0;break}}else l=this.markers.length;for(;o<l;){let d=this.markers[o++];if(d.toDOM){d.destroy(i);let f=i.nextSibling;i.remove(),i=f}}if(!c)break;c.toDOM&&(u?i=i.nextSibling:this.dom.insertBefore(c.toDOM(t),i)),u&&o++}this.dom.className=r,this.markers=n}destroy(){this.setMarkers(null,[])}}function clt(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].compare(t[n]))return!1;return!0}const ult=Jt.define(),dlt=Jt.define(),c3=Jt.define({combine(e){return im(e,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,n){let r=Object.assign({},t);for(let i in n){let a=r[i],o=n[i];r[i]=a?(l,c,u)=>a(l,c,u)||o(l,c,u):o}return r}})}});class _M extends A1{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function AM(e,t){return e.state.facet(c3).formatNumber(t,e.state)}const flt=Cv.compute([c3],e=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(t){return t.state.facet(ult)},lineMarker(t,n,r){return r.some(i=>i.toDOM)?null:new _M(AM(t,t.state.doc.lineAt(n.from).number))},widgetMarker:(t,n,r)=>{for(let i of t.state.facet(dlt)){let a=i(t,n,r);if(a)return a}return null},lineMarkerChange:t=>t.startState.facet(c3)!=t.state.facet(c3),initialSpacer(t){return new _M(AM(t,$te(t.state.doc.lines)))},updateSpacer(t,n){let r=AM(n.view,$te(n.view.state.doc.lines));return r==t.number?t:new _M(r)},domEventHandlers:e.facet(c3).domEventHandlers,side:"before"}));function S5e(e={}){return[c3.of(e),N5e(),flt]}function $te(e){let t=9;for(;t<e;)t=t*10+9;return t}const mlt=new class extends A1{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},hlt=Gk.compute(["selection"],e=>{let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.head).from;i>n&&(n=i,t.push(mlt.range(i)))}return Lr.of(t)});function plt(){return hlt}const glt=1024;let xlt=0,vu=class{constructor(t,n){this.from=t,this.to=n}};class Or{constructor(t={}){this.id=xlt++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=t.combine||null}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof t!="function"&&(t=Ll.match(t)),n=>{let r=t(n);return r===void 0?null:[this,r]}}}Or.closedBy=new Or({deserialize:e=>e.split(" ")});Or.openedBy=new Or({deserialize:e=>e.split(" ")});Or.group=new Or({deserialize:e=>e.split(" ")});Or.isolate=new Or({deserialize:e=>{if(e&&e!="rtl"&&e!="ltr"&&e!="auto")throw new RangeError("Invalid value for isolate: "+e);return e||"auto"}});Or.contextHash=new Or({perNode:!0});Or.lookAhead=new Or({perNode:!0});Or.mounted=new Or({perNode:!0});class A3{constructor(t,n,r,i=!1){this.tree=t,this.overlay=n,this.parser=r,this.bracketed=i}static get(t){return t&&t.props&&t.props[Or.mounted.id]}}const blt=Object.create(null);class Ll{constructor(t,n,r,i=0){this.name=t,this.props=n,this.id=r,this.flags=i}static define(t){let n=t.props&&t.props.length?Object.create(null):blt,r=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),i=new Ll(t.name||"",n,t.id,r);if(t.props){for(let a of t.props)if(Array.isArray(a)||(a=a(i)),a){if(a[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");n[a[0].id]=a[1]}}return i}prop(t){return this.props[t.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(t){if(typeof t=="string"){if(this.name==t)return!0;let n=this.prop(Or.group);return n?n.indexOf(t)>-1:!1}return this.id==t}static match(t){let n=Object.create(null);for(let r in t)for(let i of r.split(" "))n[i]=t[r];return r=>{for(let i=r.prop(Or.group),a=-1;a<(i?i.length:0);a++){let o=n[a<0?r.name:i[a]];if(o)return o}}}}Ll.none=new Ll("",Object.create(null),0,8);class zq{constructor(t){this.types=t;for(let n=0;n<t.length;n++)if(t[n].id!=n)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...t){let n=[];for(let r of this.types){let i=null;for(let a of t){let o=a(r);if(o){i||(i=Object.assign({},r.props));let l=o[1],c=o[0];c.combine&&c.id in i&&(l=c.combine(i[c.id],l)),i[c.id]=l}}n.push(i?new Ll(r.name,i,r.id,r.flags):r)}return new zq(n)}}const S9=new WeakMap,Fte=new WeakMap;var Ks;(function(e){e[e.ExcludeBuffers=1]="ExcludeBuffers",e[e.IncludeAnonymous=2]="IncludeAnonymous",e[e.IgnoreMounts=4]="IgnoreMounts",e[e.IgnoreOverlays=8]="IgnoreOverlays",e[e.EnterBracketed=16]="EnterBracketed"})(Ks||(Ks={}));class Vs{constructor(t,n,r,i,a){if(this.type=t,this.children=n,this.positions=r,this.length=i,this.props=null,a&&a.length){this.props=Object.create(null);for(let[o,l]of a)this.props[typeof o=="number"?o:o.id]=l}}toString(){let t=A3.get(this);if(t&&!t.overlay)return t.tree.toString();let n="";for(let r of this.children){let i=r.toString();i&&(n&&(n+=","),n+=i)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(n.length?"("+n+")":""):n}cursor(t=0){return new HN(this.topNode,t)}cursorAt(t,n=0,r=0){let i=S9.get(this)||this.topNode,a=new HN(i);return a.moveTo(t,n),S9.set(this,a._tree),a}get topNode(){return new al(this,0,0,null)}resolve(t,n=0){let r=I6(S9.get(this)||this.topNode,t,n,!1);return S9.set(this,r),r}resolveInner(t,n=0){let r=I6(Fte.get(this)||this.topNode,t,n,!0);return Fte.set(this,r),r}resolveStack(t,n=0){return wlt(this,t,n)}iterate(t){let{enter:n,leave:r,from:i=0,to:a=this.length}=t,o=t.mode||0,l=(o&Ks.IncludeAnonymous)>0;for(let c=this.cursor(o|Ks.IncludeAnonymous);;){let u=!1;if(c.from<=a&&c.to>=i&&(!l&&c.type.isAnonymous||n(c)!==!1)){if(c.firstChild())continue;u=!0}for(;u&&r&&(l||!c.type.isAnonymous)&&r(c),!c.nextSibling();){if(!c.parent())return;u=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let n in this.props)t.push([+n,this.props[n]]);return t}balance(t={}){return this.children.length<=8?this:qq(Ll.none,this.children,this.positions,0,this.children.length,0,this.length,(n,r,i)=>new Vs(this.type,n,r,i,this.propValues),t.makeTree||((n,r,i)=>new Vs(Ll.none,n,r,i)))}static build(t){return klt(t)}}Vs.empty=new Vs(Ll.none,[],[],0);class Bq{constructor(t,n){this.buffer=t,this.index=n}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new Bq(this.buffer,this.index)}}class Kp{constructor(t,n,r){this.buffer=t,this.length=n,this.set=r}get type(){return Ll.none}toString(){let t=[];for(let n=0;n<this.buffer.length;)t.push(this.childString(n)),n=this.buffer[n+3];return t.join(",")}childString(t){let n=this.buffer[t],r=this.buffer[t+3],i=this.set.types[n],a=i.name;if(/\W/.test(a)&&!i.isError&&(a=JSON.stringify(a)),t+=4,r==t)return a;let o=[];for(;t<r;)o.push(this.childString(t)),t=this.buffer[t+3];return a+"("+o.join(",")+")"}findChild(t,n,r,i,a){let{buffer:o}=this,l=-1;for(let c=t;c!=n&&!(_5e(a,i,o[c+1],o[c+2])&&(l=c,r>0));c=o[c+3]);return l}slice(t,n,r){let i=this.buffer,a=new Uint16Array(n-t),o=0;for(let l=t,c=0;l<n;){a[c++]=i[l++],a[c++]=i[l++]-r;let u=a[c++]=i[l++]-r;a[c++]=i[l++]-t,o=Math.max(o,u)}return new Kp(a,o,this.set)}}function _5e(e,t,n,r){switch(e){case-2:return n<t;case-1:return r>=t&&n<t;case 0:return n<t&&r>t;case 1:return n<=t&&r>t;case 2:return r>t;case 4:return!0}}function I6(e,t,n,r){for(var i;e.from==e.to||(n<1?e.from>=t:e.from>t)||(n>-1?e.to<=t:e.to<t);){let o=!r&&e instanceof al&&e.index<0?null:e.parent;if(!o)return e;e=o}let a=r?0:Ks.IgnoreOverlays;if(r)for(let o=e,l=o.parent;l;o=l,l=o.parent)o instanceof al&&o.index<0&&((i=l.enter(t,n,a))===null||i===void 0?void 0:i.from)!=o.from&&(e=l);for(;;){let o=e.enter(t,n,a);if(!o)return e;e=o}}class A5e{cursor(t=0){return new HN(this,t)}getChild(t,n=null,r=null){let i=zte(this,t,n,r);return i.length?i[0]:null}getChildren(t,n=null,r=null){return zte(this,t,n,r)}resolve(t,n=0){return I6(this,t,n,!1)}resolveInner(t,n=0){return I6(this,t,n,!0)}matchContext(t){return DL(this.parent,t)}enterUnfinishedNodesBefore(t){let n=this.childBefore(t),r=this;for(;n;){let i=n.lastChild;if(!i||i.to!=n.to)break;i.type.isError&&i.from==i.to?(r=n,n=i.prevSibling):n=i}return r}get node(){return this}get next(){return this.parent}}class al extends A5e{constructor(t,n,r,i){super(),this._tree=t,this.from=n,this.index=r,this._parent=i}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,n,r,i,a=0){for(let o=this;;){for(let{children:l,positions:c}=o._tree,u=n>0?l.length:-1;t!=u;t+=n){let d=l[t],f=c[t]+o.from,h;if(!(!(a&Ks.EnterBracketed&&d instanceof Vs&&(h=A3.get(d))&&!h.overlay&&h.bracketed&&r>=f&&r<=f+d.length)&&!_5e(i,r,f,f+d.length))){if(d instanceof Kp){if(a&Ks.ExcludeBuffers)continue;let g=d.findChild(0,d.buffer.length,n,r-f,i);if(g>-1)return new Ef(new ylt(o,d,t,f),null,g)}else if(a&Ks.IncludeAnonymous||!d.type.isAnonymous||Uq(d)){let g;if(!(a&Ks.IgnoreMounts)&&(g=A3.get(d))&&!g.overlay)return new al(g.tree,f,t,o);let b=new al(d,f,t,o);return a&Ks.IncludeAnonymous||!b.type.isAnonymous?b:b.nextChild(n<0?d.children.length-1:0,n,r,i,a)}}}if(a&Ks.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?t=o.index+n:t=n<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}prop(t){return this._tree.prop(t)}enter(t,n,r=0){let i;if(!(r&Ks.IgnoreOverlays)&&(i=A3.get(this._tree))&&i.overlay){let a=t-this.from,o=r&Ks.EnterBracketed&&i.bracketed;for(let{from:l,to:c}of i.overlay)if((n>0||o?l<=a:l<a)&&(n<0||o?c>=a:c>a))return new al(i.tree,i.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,n,r)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function zte(e,t,n,r){let i=e.cursor(),a=[];if(!i.firstChild())return a;if(n!=null){for(let o=!1;!o;)if(o=i.type.is(n),!i.nextSibling())return a}for(;;){if(r!=null&&i.type.is(r))return a;if(i.type.is(t)&&a.push(i.node),!i.nextSibling())return r==null?a:[]}}function DL(e,t,n=t.length-1){for(let r=e;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(t[n]&&t[n]!=r.name)return!1;n--}}return!0}class ylt{constructor(t,n,r,i){this.parent=t,this.buffer=n,this.index=r,this.start=i}}class Ef extends A5e{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(t,n,r){super(),this.context=t,this._parent=n,this.index=r,this.type=t.buffer.set.types[t.buffer.buffer[r]]}child(t,n,r){let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],t,n-this.context.start,r);return a<0?null:new Ef(this.context,this,a)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}prop(t){return this.type.prop(t)}enter(t,n,r=0){if(r&Ks.ExcludeBuffers)return null;let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],n>0?1:-1,t-this.context.start,n);return a<0?null:new Ef(this.context,this,a)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,n=t.buffer[this.index+3];return n<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new Ef(this.context,this._parent,n):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,n=this._parent?this._parent.index+4:0;return this.index==n?this.externalSibling(-1):new Ef(this.context,this._parent,t.findChild(n,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],n=[],{buffer:r}=this.context,i=this.index+4,a=r.buffer[this.index+3];if(a>i){let o=r.buffer[this.index+1];t.push(r.slice(i,a,o)),n.push(0)}return new Vs(this.type,t,n,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function E5e(e){if(!e.length)return null;let t=0,n=e[0];for(let a=1;a<e.length;a++){let o=e[a];(o.from>n.from||o.to<n.to)&&(n=o,t=a)}let r=n instanceof al&&n.index<0?null:n.parent,i=e.slice();return r?i[t]=r:i.splice(t,1),new vlt(i,n)}class vlt{constructor(t,n){this.heads=t,this.node=n}get next(){return E5e(this.heads)}}function wlt(e,t,n){let r=e.resolveInner(t,n),i=null;for(let a=r instanceof al?r:r.context.parent;a;a=a.parent)if(a.index<0){let o=a.parent;(i||(i=[r])).push(o.resolve(t,n)),a=o}else{let o=A3.get(a.tree);if(o&&o.overlay&&o.overlay[0].from<=t&&o.overlay[o.overlay.length-1].to>=t){let l=new al(o.tree,o.overlay[0].from+a.from,-1,a);(i||(i=[r])).push(I6(l,t,n,!1))}}return i?E5e(i):r}class HN{get name(){return this.type.name}constructor(t,n=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=n&~Ks.EnterBracketed,t instanceof al)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let r=t._parent;r;r=r._parent)this.stack.unshift(r.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return t?(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0):!1}yieldBuf(t,n){this.index=t;let{start:r,buffer:i}=this.buffer;return this.type=n||i.set.types[i.buffer[t]],this.from=r+i.buffer[t+1],this.to=r+i.buffer[t+2],!0}yield(t){return t?t instanceof al?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,n,r){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,n,r,this.mode));let{buffer:i}=this.buffer,a=i.findChild(this.index+4,i.buffer[this.index+3],t,n-this.buffer.start,r);return a<0?!1:(this.stack.push(this.index),this.yieldBuf(a))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,n,r=this.mode){return this.buffer?r&Ks.ExcludeBuffers?!1:this.enterChild(1,t,n):this.yield(this._tree.enter(t,n,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&Ks.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&Ks.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode)):!1;let{buffer:n}=this.buffer,r=this.stack.length-1;if(t<0){let i=r<0?0:this.stack[r]+4;if(this.index!=i)return this.yieldBuf(n.findChild(i,this.index,-1,0,4))}else{let i=n.buffer[this.index+3];if(i<(r<0?n.buffer.length:n.buffer[this.stack[r]+3]))return this.yieldBuf(i)}return r<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let n,r,{buffer:i}=this;if(i){if(t>0){if(this.index<i.buffer.buffer.length)return!1}else for(let a=0;a<this.index;a++)if(i.buffer.buffer[a+3]<this.index)return!1;({index:n,parent:r}=i)}else({index:n,_parent:r}=this._tree);for(;r;{index:n,_parent:r}=r)if(n>-1)for(let a=n+t,o=t<0?-1:r._tree.children.length;a!=o;a+=t){let l=r._tree.children[a];if(this.mode&Ks.IncludeAnonymous||l instanceof Kp||!l.type.isAnonymous||Uq(l))return!1}return!0}move(t,n){if(n&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,n=0){for(;(this.from==this.to||(n<1?this.from>=t:this.from>t)||(n>-1?this.to<=t:this.to<t))&&this.parent(););for(;this.enterChild(1,t,n););return this}get node(){if(!this.buffer)return this._tree;let t=this.bufferNode,n=null,r=0;if(t&&t.context==this.buffer)e:for(let i=this.index,a=this.stack.length;a>=0;){for(let o=t;o;o=o._parent)if(o.index==i){if(i==this.index)return o;n=o,r=a+1;break e}i=this.stack[--a]}for(let i=r;i<this.stack.length;i++)n=new Ef(this.buffer,n,this.stack[i]);return this.bufferNode=new Ef(this.buffer,n,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(t,n){for(let r=0;;){let i=!1;if(this.type.isAnonymous||t(this)!==!1){if(this.firstChild()){r++;continue}this.type.isAnonymous||(i=!0)}for(;;){if(i&&n&&n(this),i=this.type.isAnonymous,!r)return;if(this.nextSibling())break;this.parent(),r--,i=!0}}}matchContext(t){if(!this.buffer)return DL(this.node.parent,t);let{buffer:n}=this.buffer,{types:r}=n.set;for(let i=t.length-1,a=this.stack.length-1;i>=0;a--){if(a<0)return DL(this._tree,t,i);let o=r[n.buffer[this.stack[a]]];if(!o.isAnonymous){if(t[i]&&t[i]!=o.name)return!1;i--}}return!0}}function Uq(e){return e.children.some(t=>t instanceof Kp||!t.type.isAnonymous||Uq(t))}function klt(e){var t;let{buffer:n,nodeSet:r,maxBufferLength:i=glt,reused:a=[],minRepeatType:o=r.types.length}=e,l=Array.isArray(n)?new Bq(n,n.length):n,c=r.types,u=0,d=0;function f(A,_,E,T,M,O){let{id:P,start:z,end:L,size:Q}=l,ee=d,B=u;if(Q<0)if(l.next(),Q==-1){let Y=a[P];E.push(Y),T.push(z-A);return}else if(Q==-3){u=P;return}else if(Q==-4){d=P;return}else throw new RangeError(`Unrecognized record size: ${Q}`);let F=c[P],Z,W,$=z-A;if(L-z<=i&&(W=j(l.pos-_,M))){let Y=new Uint16Array(W.size-W.skip),V=l.pos-W.size,H=Y.length;for(;l.pos>V;)H=k(W.start,Y,H);Z=new Kp(Y,L-W.start,r),$=W.start-A}else{let Y=l.pos-Q;l.next();let V=[],H=[],ae=P>=o?P:-1,le=0,fe=L;for(;l.pos>Y;)ae>=0&&l.id==ae&&l.size>=0?(l.end<=fe-i&&(b(V,H,z,le,l.end,fe,ae,ee,B),le=V.length,fe=l.end),l.next()):O>2500?h(z,Y,V,H):f(z,Y,V,H,ae,O+1);if(ae>=0&&le>0&&le<V.length&&b(V,H,z,le,z,fe,ae,ee,B),V.reverse(),H.reverse(),ae>-1&&le>0){let U=g(F,B);Z=qq(F,V,H,0,V.length,0,L-z,U,U)}else Z=v(F,V,H,L-z,ee-L,B)}E.push(Z),T.push($)}function h(A,_,E,T){let M=[],O=0,P=-1;for(;l.pos>_;){let{id:z,start:L,end:Q,size:ee}=l;if(ee>4)l.next();else{if(P>-1&&L<P)break;P<0&&(P=Q-i),M.push(z,L,Q),O++,l.next()}}if(O){let z=new Uint16Array(O*4),L=M[M.length-2];for(let Q=M.length-3,ee=0;Q>=0;Q-=3)z[ee++]=M[Q],z[ee++]=M[Q+1]-L,z[ee++]=M[Q+2]-L,z[ee++]=ee;E.push(new Kp(z,M[2]-L,r)),T.push(L-A)}}function g(A,_){return(E,T,M)=>{let O=0,P=E.length-1,z,L;if(P>=0&&(z=E[P])instanceof Vs){if(!P&&z.type==A&&z.length==M)return z;(L=z.prop(Or.lookAhead))&&(O=T[P]+z.length+L)}return v(A,E,T,M,O,_)}}function b(A,_,E,T,M,O,P,z,L){let Q=[],ee=[];for(;A.length>T;)Q.push(A.pop()),ee.push(_.pop()+E-M);A.push(v(r.types[P],Q,ee,O-M,z-O,L)),_.push(M-E)}function v(A,_,E,T,M,O,P){if(O){let z=[Or.contextHash,O];P=P?[z].concat(P):[z]}if(M>25){let z=[Or.lookAhead,M];P=P?[z].concat(P):[z]}return new Vs(A,_,E,T,P)}function j(A,_){let E=l.fork(),T=0,M=0,O=0,P=E.end-i,z={size:0,start:0,skip:0};e:for(let L=E.pos-A;E.pos>L;){let Q=E.size;if(E.id==_&&Q>=0){z.size=T,z.start=M,z.skip=O,O+=4,T+=4,E.next();continue}let ee=E.pos-Q;if(Q<0||ee<L||E.start<P)break;let B=E.id>=o?4:0,F=E.start;for(E.next();E.pos>ee;){if(E.size<0)if(E.size==-3||E.size==-4)B+=4;else break e;else E.id>=o&&(B+=4);E.next()}M=F,T+=Q,O+=B}return(_<0||T==A)&&(z.size=T,z.start=M,z.skip=O),z.size>4?z:void 0}function k(A,_,E){let{id:T,start:M,end:O,size:P}=l;if(l.next(),P>=0&&T<o){let z=E;if(P>4){let L=l.pos-(P-4);for(;l.pos>L;)E=k(A,_,E)}_[--E]=z,_[--E]=O-A,_[--E]=M-A,_[--E]=T}else P==-3?u=T:P==-4&&(d=T);return E}let w=[],N=[];for(;l.pos>0;)f(e.start||0,e.bufferStart||0,w,N,-1,0);let C=(t=e.length)!==null&&t!==void 0?t:w.length?N[0]+w[0].length:0;return new Vs(c[e.topID],w.reverse(),N.reverse(),C)}const Bte=new WeakMap;function Qk(e,t){if(!e.isAnonymous||t instanceof Kp||t.type!=e)return 1;let n=Bte.get(t);if(n==null){n=1;for(let r of t.children){if(r.type!=e||!(r instanceof Vs)){n=1;break}n+=Qk(e,r)}Bte.set(t,n)}return n}function qq(e,t,n,r,i,a,o,l,c){let u=0;for(let b=r;b<i;b++)u+=Qk(e,t[b]);let d=Math.ceil(u*1.5/8),f=[],h=[];function g(b,v,j,k,w){for(let N=j;N<k;){let C=N,A=v[N],_=Qk(e,b[N]);for(N++;N<k;N++){let E=Qk(e,b[N]);if(_+E>=d)break;_+=E}if(N==C+1){if(_>d){let E=b[C];g(E.children,E.positions,0,E.children.length,v[C]+w);continue}f.push(b[C])}else{let E=v[N-1]+b[N-1].length-A;f.push(qq(e,b,v,C,N,A,E,null,c))}h.push(A+w-a)}}return g(t,n,r,i,0),(l||c)(f,h,o)}class lAt{constructor(){this.map=new WeakMap}setBuffer(t,n,r){let i=this.map.get(t);i||this.map.set(t,i=new Map),i.set(n,r)}getBuffer(t,n){let r=this.map.get(t);return r&&r.get(n)}set(t,n){t instanceof Ef?this.setBuffer(t.context.buffer,t.index,n):t instanceof al&&this.map.set(t.tree,n)}get(t){return t instanceof Ef?this.getBuffer(t.context.buffer,t.index):t instanceof al?this.map.get(t.tree):void 0}cursorSet(t,n){t.buffer?this.setBuffer(t.buffer.buffer,t.index,n):this.map.set(t.tree,n)}cursorGet(t){return t.buffer?this.getBuffer(t.buffer.buffer,t.index):this.map.get(t.tree)}}class o1{constructor(t,n,r,i,a=!1,o=!1){this.from=t,this.to=n,this.tree=r,this.offset=i,this.open=(a?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(t,n=[],r=!1){let i=[new o1(0,t.length,t,0,!1,r)];for(let a of n)a.to>t.length&&i.push(a);return i}static applyChanges(t,n,r=128){if(!n.length)return t;let i=[],a=1,o=t.length?t[0]:null;for(let l=0,c=0,u=0;;l++){let d=l<n.length?n[l]:null,f=d?d.fromA:1e9;if(f-c>=r)for(;o&&o.from<f;){let h=o;if(c>=h.from||f<=h.to||u){let g=Math.max(h.from,c)-u,b=Math.min(h.to,f)-u;h=g>=b?null:new o1(g,b,h.tree,h.offset+u,l>0,!!d)}if(h&&i.push(h),o.to>f)break;o=a<t.length?t[a++]:null}if(!d)break;c=d.toA,u=d.toA-d.toB}return i}}class T5e{startParse(t,n,r){return typeof t=="string"&&(t=new jlt(t)),r=r?r.length?r.map(i=>new vu(i.from,i.to)):[new vu(0,0)]:[new vu(0,t.length)],this.createParse(t,n||[],r)}parse(t,n,r){let i=this.startParse(t,n,r);for(;;){let a=i.advance();if(a)return a}}}class jlt{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,n){return this.string.slice(t,n)}}function cAt(e){return(t,n,r,i)=>new Clt(t,e,n,r,i)}class Ute{constructor(t,n,r,i,a,o){this.parser=t,this.parse=n,this.overlay=r,this.bracketed=i,this.target=a,this.from=o}}function qte(e){if(!e.length||e.some(t=>t.from>=t.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(e))}class Nlt{constructor(t,n,r,i,a,o,l,c){this.parser=t,this.predicate=n,this.mounts=r,this.index=i,this.start=a,this.bracketed=o,this.target=l,this.prev=c,this.depth=0,this.ranges=[]}}const LL=new Or({perNode:!0});class Clt{constructor(t,n,r,i,a){this.nest=n,this.input=r,this.fragments=i,this.ranges=a,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=t}advance(){if(this.baseParse){let r=this.baseParse.advance();if(!r)return null;if(this.baseParse=null,this.baseTree=r,this.startInner(),this.stoppedAt!=null)for(let i of this.inner)i.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let r=this.baseTree;return this.stoppedAt!=null&&(r=new Vs(r.type,r.children,r.positions,r.length,r.propValues.concat([[LL,this.stoppedAt]]))),r}let t=this.inner[this.innerDone],n=t.parse.advance();if(n){this.innerDone++;let r=Object.assign(Object.create(null),t.target.props);r[Or.mounted.id]=new A3(n,t.overlay,t.parser,t.bracketed),t.target.props=r}return null}get parsedPos(){if(this.baseParse)return 0;let t=this.input.length;for(let n=this.innerDone;n<this.inner.length;n++)this.inner[n].from<t&&(t=Math.min(t,this.inner[n].parse.parsedPos));return t}stopAt(t){if(this.stoppedAt=t,this.baseParse)this.baseParse.stopAt(t);else for(let n=this.innerDone;n<this.inner.length;n++)this.inner[n].parse.stopAt(t)}startInner(){let t=new Alt(this.fragments),n=null,r=null,i=new HN(new al(this.baseTree,this.ranges[0].from,0,null),Ks.IncludeAnonymous|Ks.IgnoreMounts);e:for(let a,o;;){let l=!0,c;if(this.stoppedAt!=null&&i.from>=this.stoppedAt)l=!1;else if(t.hasNode(i)){if(n){let u=n.mounts.find(d=>d.frag.from<=i.from&&d.frag.to>=i.to&&d.mount.overlay);if(u)for(let d of u.mount.overlay){let f=d.from+u.pos,h=d.to+u.pos;f>=i.from&&h<=i.to&&!n.ranges.some(g=>g.from<h&&g.to>f)&&n.ranges.push({from:f,to:h})}}l=!1}else if(r&&(o=Slt(r.ranges,i.from,i.to)))l=o!=2;else if(!i.type.isAnonymous&&(a=this.nest(i,this.input))&&(i.from<i.to||!a.overlay)){i.tree||(_lt(i),n&&n.depth++,r&&r.depth++);let u=t.findMounts(i.from,a.parser);if(typeof a.overlay=="function")n=new Nlt(a.parser,a.overlay,u,this.inner.length,i.from,!!a.bracketed,i.tree,n);else{let d=Vte(this.ranges,a.overlay||(i.from<i.to?[new vu(i.from,i.to)]:[]));d.length&&qte(d),(d.length||!a.overlay)&&this.inner.push(new Ute(a.parser,d.length?a.parser.startParse(this.input,Wte(u,d),d):a.parser.startParse(""),a.overlay?a.overlay.map(f=>new vu(f.from-i.from,f.to-i.from)):null,!!a.bracketed,i.tree,d.length?d[0].from:i.from)),a.overlay?d.length&&(r={ranges:d,depth:0,prev:r}):l=!1}}else if(n&&(c=n.predicate(i))&&(c===!0&&(c=new vu(i.from,i.to)),c.from<c.to)){let u=n.ranges.length-1;u>=0&&n.ranges[u].to==c.from?n.ranges[u]={from:n.ranges[u].from,to:c.to}:n.ranges.push(c)}if(l&&i.firstChild())n&&n.depth++,r&&r.depth++;else for(;!i.nextSibling();){if(!i.parent())break e;if(n&&!--n.depth){let u=Vte(this.ranges,n.ranges);u.length&&(qte(u),this.inner.splice(n.index,0,new Ute(n.parser,n.parser.startParse(this.input,Wte(n.mounts,u),u),n.ranges.map(d=>new vu(d.from-n.start,d.to-n.start)),n.bracketed,n.target,u[0].from))),n=n.prev}r&&!--r.depth&&(r=r.prev)}}}}function Slt(e,t,n){for(let r of e){if(r.from>=n)break;if(r.to>t)return r.from<=t&&r.to>=n?2:1}return 0}function Kte(e,t,n,r,i,a){if(t<n){let o=e.buffer[t+1];r.push(e.slice(t,n,o)),i.push(o-a)}}function _lt(e){let{node:t}=e,n=[],r=t.context.buffer;do n.push(e.index),e.parent();while(!e.tree);let i=e.tree,a=i.children.indexOf(r),o=i.children[a],l=o.buffer,c=[a];function u(d,f,h,g,b,v){let j=n[v],k=[],w=[];Kte(o,d,j,k,w,g);let N=l[j+1],C=l[j+2];c.push(k.length);let A=v?u(j+4,l[j+3],o.set.types[l[j]],N,C-N,v-1):t.toTree();return k.push(A),w.push(N-g),Kte(o,l[j+3],f,k,w,g),new Vs(h,k,w,b)}i.children[a]=u(0,l.length,Ll.none,0,o.length,n.length-1);for(let d of c){let f=e.tree.children[d],h=e.tree.positions[d];e.yield(new al(f,h+e.from,d,e._tree))}}class Hte{constructor(t,n){this.offset=n,this.done=!1,this.cursor=t.cursor(Ks.IncludeAnonymous|Ks.IgnoreMounts)}moveTo(t){let{cursor:n}=this,r=t-this.offset;for(;!this.done&&n.from<r;)n.to>=t&&n.enter(r,1,Ks.IgnoreOverlays|Ks.ExcludeBuffers)||n.next(!1)||(this.done=!0)}hasNode(t){if(this.moveTo(t.from),!this.done&&this.cursor.from+this.offset==t.from&&this.cursor.tree)for(let n=this.cursor.tree;;){if(n==t.tree)return!0;if(n.children.length&&n.positions[0]==0&&n.children[0]instanceof Vs)n=n.children[0];else break}return!1}}class Alt{constructor(t){var n;if(this.fragments=t,this.curTo=0,this.fragI=0,t.length){let r=this.curFrag=t[0];this.curTo=(n=r.tree.prop(LL))!==null&&n!==void 0?n:r.to,this.inner=new Hte(r.tree,-r.offset)}else this.curFrag=this.inner=null}hasNode(t){for(;this.curFrag&&t.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=t.from&&this.curTo>=t.to&&this.inner.hasNode(t)}nextFrag(){var t;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let n=this.curFrag=this.fragments[this.fragI];this.curTo=(t=n.tree.prop(LL))!==null&&t!==void 0?t:n.to,this.inner=new Hte(n.tree,-n.offset)}}findMounts(t,n){var r;let i=[];if(this.inner){this.inner.cursor.moveTo(t,1);for(let a=this.inner.cursor.node;a;a=a.parent){let o=(r=a.tree)===null||r===void 0?void 0:r.prop(Or.mounted);if(o&&o.parser==n)for(let l=this.fragI;l<this.fragments.length;l++){let c=this.fragments[l];if(c.from>=a.to)break;c.tree==this.curFrag.tree&&i.push({frag:c,pos:a.from-c.offset,mount:o})}}}return i}}function Vte(e,t){let n=null,r=t;for(let i=1,a=0;i<e.length;i++){let o=e[i-1].to,l=e[i].from;for(;a<r.length;a++){let c=r[a];if(c.from>=l)break;c.to<=o||(n||(r=n=t.slice()),c.from<o?(n[a]=new vu(c.from,o),c.to>l&&n.splice(a+1,0,new vu(l,c.to))):c.to>l?n[a--]=new vu(l,c.to):n.splice(a--,1))}}return r}function Elt(e,t,n,r){let i=0,a=0,o=!1,l=!1,c=-1e9,u=[];for(;;){let d=i==e.length?1e9:o?e[i].to:e[i].from,f=a==t.length?1e9:l?t[a].to:t[a].from;if(o!=l){let h=Math.max(c,n),g=Math.min(d,f,r);h<g&&u.push(new vu(h,g))}if(c=Math.min(d,f),c==1e9)break;d==c&&(o?(o=!1,i++):o=!0),f==c&&(l?(l=!1,a++):l=!0)}return u}function Wte(e,t){let n=[];for(let{pos:r,mount:i,frag:a}of e){let o=r+(i.overlay?i.overlay[0].from:0),l=o+i.tree.length,c=Math.max(a.from,o),u=Math.min(a.to,l);if(i.overlay){let d=i.overlay.map(h=>new vu(h.from+r,h.to+r)),f=Elt(t,d,c,u);for(let h=0,g=c;;h++){let b=h==f.length,v=b?u:f[h].from;if(v>g&&n.push(new o1(g,v,i.tree,-o,a.from>=g||a.openStart,a.to<=v||a.openEnd)),b)break;g=f[h].to}}else n.push(new o1(c,u,i.tree,-o,a.from>=o||a.openStart,a.to<=l||a.openEnd))}return n}let Tlt=0;class hu{constructor(t,n,r,i){this.name=t,this.set=n,this.base=r,this.modified=i,this.id=Tlt++}toString(){let{name:t}=this;for(let n of this.modified)n.name&&(t=`${n.name}(${t})`);return t}static define(t,n){let r=typeof t=="string"?t:"?";if(t instanceof hu&&(n=t),n!=null&&n.base)throw new Error("Can not derive from a modified tag");let i=new hu(r,[],null,[]);if(i.set.push(i),n)for(let a of n.set)i.set.push(a);return i}static defineModifier(t){let n=new VN(t);return r=>r.modified.indexOf(n)>-1?r:VN.get(r.base||r,r.modified.concat(n).sort((i,a)=>i.id-a.id))}}let Ilt=0;class VN{constructor(t){this.name=t,this.instances=[],this.id=Ilt++}static get(t,n){if(!n.length)return t;let r=n[0].instances.find(l=>l.base==t&&Mlt(n,l.modified));if(r)return r;let i=[],a=new hu(t.name,i,t,n);for(let l of n)l.instances.push(a);let o=Rlt(n);for(let l of t.set)if(!l.modified.length)for(let c of o)i.push(VN.get(l,c));return a}}function Mlt(e,t){return e.length==t.length&&e.every((n,r)=>n==t[r])}function Rlt(e){let t=[[]];for(let n=0;n<e.length;n++)for(let r=0,i=t.length;r<i;r++)t.push(t[r].concat(e[n]));return t.sort((n,r)=>r.length-n.length)}function Olt(e){let t=Object.create(null);for(let n in e){let r=e[n];Array.isArray(r)||(r=[r]);for(let i of n.split(" "))if(i){let a=[],o=2,l=i;for(let f=0;;){if(l=="..."&&f>0&&f+3==i.length){o=1;break}let h=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!h)throw new RangeError("Invalid path: "+i);if(a.push(h[0]=="*"?"":h[0][0]=='"'?JSON.parse(h[0]):h[0]),f+=h[0].length,f==i.length)break;let g=i[f++];if(f==i.length&&g=="!"){o=0;break}if(g!="/")throw new RangeError("Invalid path: "+i);l=i.slice(f)}let c=a.length-1,u=a[c];if(!u)throw new RangeError("Invalid path: "+i);let d=new M6(r,o,c>0?a.slice(0,c):null);t[u]=d.sort(t[u])}}return I5e.add(t)}const I5e=new Or({combine(e,t){let n,r,i;for(;e||t;){if(!e||t&&e.depth>=t.depth?(i=t,t=t.next):(i=e,e=e.next),n&&n.mode==i.mode&&!i.context&&!n.context)continue;let a=new M6(i.tags,i.mode,i.context);n?n.next=a:r=a,n=a}return r}});class M6{constructor(t,n,r,i){this.tags=t,this.mode=n,this.context=r,this.next=i}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(t){return!t||t.depth<this.depth?(this.next=t,this):(t.next=this.sort(t.next),t)}get depth(){return this.context?this.context.length:0}}M6.empty=new M6([],2,null);function M5e(e,t){let n=Object.create(null);for(let a of e)if(!Array.isArray(a.tag))n[a.tag.id]=a.class;else for(let o of a.tag)n[o.id]=a.class;let{scope:r,all:i=null}=t||{};return{style:a=>{let o=i;for(let l of a)for(let c of l.set){let u=n[c.id];if(u){o=o?o+" "+u:u;break}}return o},scope:r}}function Plt(e,t){let n=null;for(let r of e){let i=r.style(t);i&&(n=n?n+" "+i:i)}return n}function Dlt(e,t,n,r=0,i=e.length){let a=new Llt(r,Array.isArray(t)?t:[t],n);a.highlightRange(e.cursor(),r,i,"",a.highlighters),a.flush(i)}class Llt{constructor(t,n,r){this.at=t,this.highlighters=n,this.span=r,this.class=""}startSpan(t,n){n!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=n)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,n,r,i,a){let{type:o,from:l,to:c}=t;if(l>=r||c<=n)return;o.isTop&&(a=this.highlighters.filter(g=>!g.scope||g.scope(o)));let u=i,d=$lt(t)||M6.empty,f=Plt(a,d.tags);if(f&&(u&&(u+=" "),u+=f,d.mode==1&&(i+=(i?" ":"")+f)),this.startSpan(Math.max(n,l),u),d.opaque)return;let h=t.tree&&t.tree.prop(Or.mounted);if(h&&h.overlay){let g=t.node.enter(h.overlay[0].from+l,1),b=this.highlighters.filter(j=>!j.scope||j.scope(h.tree.type)),v=t.firstChild();for(let j=0,k=l;;j++){let w=j<h.overlay.length?h.overlay[j]:null,N=w?w.from+l:c,C=Math.max(n,k),A=Math.min(r,N);if(C<A&&v)for(;t.from<A&&(this.highlightRange(t,C,A,i,a),this.startSpan(Math.min(A,t.to),u),!(t.to>=N||!t.nextSibling())););if(!w||N>r)break;k=w.to+l,k>n&&(this.highlightRange(g.cursor(),Math.max(n,w.from+l),Math.min(r,k),"",b),this.startSpan(Math.min(r,k),u))}v&&t.parent()}else if(t.firstChild()){h&&(i="");do if(!(t.to<=n)){if(t.from>=r)break;this.highlightRange(t,n,r,i,a),this.startSpan(Math.min(r,t.to),u)}while(t.nextSibling());t.parent()}}}function $lt(e){let t=e.type.prop(I5e);for(;t&&t.context&&!e.matchContext(t.context);)t=t.next;return t||null}const Ht=hu.define,_9=Ht(),Mh=Ht(),Zte=Ht(Mh),Gte=Ht(Mh),Rh=Ht(),A9=Ht(Rh),EM=Ht(Rh),of=Ht(),Pg=Ht(of),Xd=Ht(),ef=Ht(),$L=Ht(),iy=Ht($L),E9=Ht(),dt={comment:_9,lineComment:Ht(_9),blockComment:Ht(_9),docComment:Ht(_9),name:Mh,variableName:Ht(Mh),typeName:Zte,tagName:Ht(Zte),propertyName:Gte,attributeName:Ht(Gte),className:Ht(Mh),labelName:Ht(Mh),namespace:Ht(Mh),macroName:Ht(Mh),literal:Rh,string:A9,docString:Ht(A9),character:Ht(A9),attributeValue:Ht(A9),number:EM,integer:Ht(EM),float:Ht(EM),bool:Ht(Rh),regexp:Ht(Rh),escape:Ht(Rh),color:Ht(Rh),url:Ht(Rh),keyword:Xd,self:Ht(Xd),null:Ht(Xd),atom:Ht(Xd),unit:Ht(Xd),modifier:Ht(Xd),operatorKeyword:Ht(Xd),controlKeyword:Ht(Xd),definitionKeyword:Ht(Xd),moduleKeyword:Ht(Xd),operator:ef,derefOperator:Ht(ef),arithmeticOperator:Ht(ef),logicOperator:Ht(ef),bitwiseOperator:Ht(ef),compareOperator:Ht(ef),updateOperator:Ht(ef),definitionOperator:Ht(ef),typeOperator:Ht(ef),controlOperator:Ht(ef),punctuation:$L,separator:Ht($L),bracket:iy,angleBracket:Ht(iy),squareBracket:Ht(iy),paren:Ht(iy),brace:Ht(iy),content:of,heading:Pg,heading1:Ht(Pg),heading2:Ht(Pg),heading3:Ht(Pg),heading4:Ht(Pg),heading5:Ht(Pg),heading6:Ht(Pg),contentSeparator:Ht(of),list:Ht(of),quote:Ht(of),emphasis:Ht(of),strong:Ht(of),link:Ht(of),monospace:Ht(of),strikethrough:Ht(of),inserted:Ht(),deleted:Ht(),changed:Ht(),invalid:Ht(),meta:E9,documentMeta:Ht(E9),annotation:Ht(E9),processingInstruction:Ht(E9),definition:hu.defineModifier("definition"),constant:hu.defineModifier("constant"),function:hu.defineModifier("function"),standard:hu.defineModifier("standard"),local:hu.defineModifier("local"),special:hu.defineModifier("special")};for(let e in dt){let t=dt[e];t instanceof hu&&(t.name=e)}M5e([{tag:dt.link,class:"tok-link"},{tag:dt.heading,class:"tok-heading"},{tag:dt.emphasis,class:"tok-emphasis"},{tag:dt.strong,class:"tok-strong"},{tag:dt.keyword,class:"tok-keyword"},{tag:dt.atom,class:"tok-atom"},{tag:dt.bool,class:"tok-bool"},{tag:dt.url,class:"tok-url"},{tag:dt.labelName,class:"tok-labelName"},{tag:dt.inserted,class:"tok-inserted"},{tag:dt.deleted,class:"tok-deleted"},{tag:dt.literal,class:"tok-literal"},{tag:dt.string,class:"tok-string"},{tag:dt.number,class:"tok-number"},{tag:[dt.regexp,dt.escape,dt.special(dt.string)],class:"tok-string2"},{tag:dt.variableName,class:"tok-variableName"},{tag:dt.local(dt.variableName),class:"tok-variableName tok-local"},{tag:dt.definition(dt.variableName),class:"tok-variableName tok-definition"},{tag:dt.special(dt.variableName),class:"tok-variableName2"},{tag:dt.definition(dt.propertyName),class:"tok-propertyName tok-definition"},{tag:dt.typeName,class:"tok-typeName"},{tag:dt.namespace,class:"tok-namespace"},{tag:dt.className,class:"tok-className"},{tag:dt.macroName,class:"tok-macroName"},{tag:dt.propertyName,class:"tok-propertyName"},{tag:dt.operator,class:"tok-operator"},{tag:dt.comment,class:"tok-comment"},{tag:dt.meta,class:"tok-meta"},{tag:dt.invalid,class:"tok-invalid"},{tag:dt.punctuation,class:"tok-punctuation"}]);var TM;const a2=new Or;function R5e(e){return Jt.define({combine:e?t=>t.concat(e):void 0})}const Flt=new Or;class wu{constructor(t,n,r=[],i=""){this.data=t,this.name=i,Yr.prototype.hasOwnProperty("tree")||Object.defineProperty(Yr.prototype,"tree",{get(){return Bo(this)}}),this.parser=n,this.extension=[Hp.of(this),Yr.languageData.of((a,o,l)=>{let c=Qte(a,o,l),u=c.type.prop(a2);if(!u)return[];let d=a.facet(u),f=c.type.prop(Flt);if(f){let h=c.resolve(o-c.from,l);for(let g of f)if(g.test(h,a)){let b=a.facet(g.facet);return g.type=="replace"?b:b.concat(d)}}return d})].concat(r)}isActiveAt(t,n,r=-1){return Qte(t,n,r).type.prop(a2)==this.data}findRegions(t){let n=t.facet(Hp);if((n==null?void 0:n.data)==this.data)return[{from:0,to:t.doc.length}];if(!n||!n.allowsNesting)return[];let r=[],i=(a,o)=>{if(a.prop(a2)==this.data){r.push({from:o,to:o+a.length});return}let l=a.prop(Or.mounted);if(l){if(l.tree.prop(a2)==this.data){if(l.overlay)for(let c of l.overlay)r.push({from:c.from+o,to:c.to+o});else r.push({from:o,to:o+a.length});return}else if(l.overlay){let c=r.length;if(i(l.tree,l.overlay[0].from+o),r.length>c)return}}for(let c=0;c<a.children.length;c++){let u=a.children[c];u instanceof Vs&&i(u,a.positions[c]+o)}};return i(Bo(t),0),r}get allowsNesting(){return!0}}wu.setState=ir.define();function Qte(e,t,n){let r=e.facet(Hp),i=Bo(e).topNode;if(!r||r.allowsNesting)for(let a=i;a;a=a.enter(t,n,Ks.ExcludeBuffers|Ks.EnterBracketed))a.type.isTop&&(i=a);return i}class FL extends wu{constructor(t,n,r){super(t,n,[],r),this.parser=n}static define(t){let n=R5e(t.languageData);return new FL(n,t.parser.configure({props:[a2.add(r=>r.isTop?n:void 0)]}),t.name)}configure(t,n){return new FL(this.data,this.parser.configure(t),n||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function Bo(e){let t=e.field(wu.state,!1);return t?t.tree:Vs.empty}class zlt{constructor(t){this.doc=t,this.cursorPos=0,this.string="",this.cursor=t.iter()}get length(){return this.doc.length}syncTo(t){return this.string=this.cursor.next(t-this.cursorPos).value,this.cursorPos=t+this.string.length,this.cursorPos-this.string.length}chunk(t){return this.syncTo(t),this.string}get lineChunks(){return!0}read(t,n){let r=this.cursorPos-this.string.length;return t<r||n>=this.cursorPos?this.doc.sliceString(t,n):this.string.slice(t-r,n-r)}}let ay=null;class T5{constructor(t,n,r=[],i,a,o,l,c){this.parser=t,this.state=n,this.fragments=r,this.tree=i,this.treeLen=a,this.viewport=o,this.skipped=l,this.scheduleOn=c,this.parse=null,this.tempSkipped=[]}static create(t,n,r){return new T5(t,n,[],Vs.empty,0,r,[],null)}startParse(){return this.parser.startParse(new zlt(this.state.doc),this.fragments)}work(t,n){return n!=null&&n>=this.state.doc.length&&(n=void 0),this.tree!=Vs.empty&&this.isDone(n??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof t=="number"){let i=Date.now()+t;t=()=>Date.now()>i}for(this.parse||(this.parse=this.startParse()),n!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>n)&&n<this.state.doc.length&&this.parse.stopAt(n);;){let i=this.parse.advance();if(i)if(this.fragments=this.withoutTempSkipped(o1.addTree(i,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=i,this.parse=null,this.treeLen<(n??this.state.doc.length))this.parse=this.startParse();else return!0;if(t())return!1}})}takeTree(){let t,n;this.parse&&(t=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext(()=>{for(;!(n=this.parse.advance()););}),this.treeLen=t,this.tree=n,this.fragments=this.withoutTempSkipped(o1.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let n=ay;ay=this;try{return t()}finally{ay=n}}withoutTempSkipped(t){for(let n;n=this.tempSkipped.pop();)t=Yte(t,n.from,n.to);return t}changes(t,n){let{fragments:r,tree:i,treeLen:a,viewport:o,skipped:l}=this;if(this.takeTree(),!t.empty){let c=[];if(t.iterChangedRanges((u,d,f,h)=>c.push({fromA:u,toA:d,fromB:f,toB:h})),r=o1.applyChanges(r,c),i=Vs.empty,a=0,o={from:t.mapPos(o.from,-1),to:t.mapPos(o.to,1)},this.skipped.length){l=[];for(let u of this.skipped){let d=t.mapPos(u.from,1),f=t.mapPos(u.to,-1);d<f&&l.push({from:d,to:f})}}}return new T5(this.parser,n,r,i,a,o,l,this.scheduleOn)}updateViewport(t){if(this.viewport.from==t.from&&this.viewport.to==t.to)return!1;this.viewport=t;let n=this.skipped.length;for(let r=0;r<this.skipped.length;r++){let{from:i,to:a}=this.skipped[r];i<t.to&&a>t.from&&(this.fragments=Yte(this.fragments,i,a),this.skipped.splice(r--,1))}return this.skipped.length>=n?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,n){this.skipped.push({from:t,to:n})}static getSkippingParser(t){return new class extends T5e{createParse(n,r,i){let a=i[0].from,o=i[i.length-1].to;return{parsedPos:a,advance(){let c=ay;if(c){for(let u of i)c.tempSkipped.push(u);t&&(c.scheduleOn=c.scheduleOn?Promise.all([c.scheduleOn,t]):t)}return this.parsedPos=o,new Vs(Ll.none,[],[],o-a)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let n=this.fragments;return this.treeLen>=t&&n.length&&n[0].from==0&&n[0].to>=t}static get(){return ay}}function Yte(e,t,n){return o1.applyChanges(e,[{fromA:t,toA:n,fromB:t,toB:n}])}class I5{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let n=this.context.changes(t.changes,t.state),r=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),n.viewport.to);return n.work(20,r)||n.takeTree(),new I5(n)}static init(t){let n=Math.min(3e3,t.doc.length),r=T5.create(t.facet(Hp).parser,t,{from:0,to:n});return r.work(20,n)||r.takeTree(),new I5(r)}}wu.state=qo.define({create:I5.init,update(e,t){for(let n of t.effects)if(n.is(wu.setState))return n.value;return t.startState.facet(Hp)!=t.state.facet(Hp)?I5.init(t.state):e.apply(t)}});let O5e=e=>{let t=setTimeout(()=>e(),500);return()=>clearTimeout(t)};typeof requestIdleCallback<"u"&&(O5e=e=>{let t=-1,n=setTimeout(()=>{t=requestIdleCallback(e,{timeout:400})},100);return()=>t<0?clearTimeout(n):cancelIdleCallback(t)});const IM=typeof navigator<"u"&&(!((TM=navigator.scheduling)===null||TM===void 0)&&TM.isInputPending)?()=>navigator.scheduling.isInputPending():null,Blt=ia.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let n=this.view.state.field(wu.state).context;(n.updateViewport(t.view.viewport)||this.view.viewport.to>n.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(n)}scheduleWork(){if(this.working)return;let{state:t}=this.view,n=t.field(wu.state);(n.tree!=n.context.tree||!n.context.isDone(t.doc.length))&&(this.working=O5e(this.work))}work(t){this.working=null;let n=Date.now();if(this.chunkEnd<n&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=n+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:r,viewport:{to:i}}=this.view,a=r.field(wu.state);if(a.tree==a.context.tree&&a.context.isDone(i+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,t&&!IM?Math.max(25,t.timeRemaining()-5):1e9),l=a.context.treeLen<i&&r.doc.length>i+1e3,c=a.context.work(()=>IM&&IM()||Date.now()>o,i+(l?0:1e5));this.chunkBudget-=Date.now()-n,(c||this.chunkBudget<=0)&&(a.context.takeTree(),this.view.dispatch({effects:wu.setState.of(new I5(a.context))})),this.chunkBudget>0&&!(c&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(a.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(n=>rc(this.view.state,n)).then(()=>this.workScheduled--),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Hp=Jt.define({combine(e){return e.length?e[0]:null},enables:e=>[wu.state,Blt,Yt.contentAttributes.compute([e],t=>{let n=t.facet(e);return n&&n.name?{"data-language":n.name}:{}})]});class Ult{constructor(t,n=[]){this.language=t,this.support=n,this.extension=[t,n]}}class ot{constructor(t,n,r,i,a,o=void 0){this.name=t,this.alias=n,this.extensions=r,this.filename=i,this.loadFunc=a,this.support=o,this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then(t=>this.support=t,t=>{throw this.loading=null,t}))}static of(t){let{load:n,support:r}=t;if(!n){if(!r)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");n=()=>Promise.resolve(r)}return new ot(t.name,(t.alias||[]).concat(t.name).map(i=>i.toLowerCase()),t.extensions||[],t.filename,n,r)}static matchFilename(t,n){for(let i of t)if(i.filename&&i.filename.test(n))return i;let r=/\.([^.]+)$/.exec(n);if(r){for(let i of t)if(i.extensions.indexOf(r[1])>-1)return i}return null}static matchLanguageName(t,n,r=!0){n=n.toLowerCase();for(let i of t)if(i.alias.some(a=>a==n))return i;if(r)for(let i of t)for(let a of i.alias){let o=n.indexOf(a);if(o>-1&&(a.length>2||!/\w/.test(n[o-1])&&!/\w/.test(n[o+a.length])))return i}return null}}const qlt=Jt.define(),Q_=Jt.define({combine:e=>{if(!e.length)return" ";let t=e[0];if(!t||/\S/.test(t)||Array.from(t).some(n=>n!=t[0]))throw new Error("Invalid indent unit: "+JSON.stringify(e[0]));return t}});function h0(e){let t=e.facet(Q_);return t.charCodeAt(0)==9?e.tabSize*t.length:t.length}function R6(e,t){let n="",r=e.tabSize,i=e.facet(Q_)[0];if(i==" "){for(;t>=r;)n+=" ",t-=r;i=" "}for(let a=0;a<t;a++)n+=i;return n}function Kq(e,t){e instanceof Yr&&(e=new Y_(e));for(let r of e.state.facet(qlt)){let i=r(e,t);if(i!==void 0)return i}let n=Bo(e.state);return n.length>=t?Klt(e,n,t):null}class Y_{constructor(t,n={}){this.state=t,this.options=n,this.unit=h0(t)}lineAt(t,n=1){let r=this.state.doc.lineAt(t),{simulateBreak:i,simulateDoubleBreak:a}=this.options;return i!=null&&i>=r.from&&i<=r.to?a&&i==t?{text:"",from:t}:(n<0?i<t:i<=t)?{text:r.text.slice(i-r.from),from:i}:{text:r.text.slice(0,i-r.from),from:r.from}:r}textAfterPos(t,n=1){if(this.options.simulateDoubleBreak&&t==this.options.simulateBreak)return"";let{text:r,from:i}=this.lineAt(t,n);return r.slice(t-i,Math.min(r.length,t+100-i))}column(t,n=1){let{text:r,from:i}=this.lineAt(t,n),a=this.countColumn(r,t-i),o=this.options.overrideIndentation?this.options.overrideIndentation(i):-1;return o>-1&&(a+=o-this.countColumn(r,r.search(/\S|$/))),a}countColumn(t,n=t.length){return I4(t,this.state.tabSize,n)}lineIndent(t,n=1){let{text:r,from:i}=this.lineAt(t,n),a=this.options.overrideIndentation;if(a){let o=a(i);if(o>-1)return o}return this.countColumn(r,r.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const P5e=new Or;function Klt(e,t,n){let r=t.resolveStack(n),i=t.resolveInner(n,-1).resolve(n,0).enterUnfinishedNodesBefore(n);if(i!=r.node){let a=[];for(let o=i;o&&!(o.from<r.node.from||o.to>r.node.to||o.from==r.node.from&&o.type==r.node.type);o=o.parent)a.push(o);for(let o=a.length-1;o>=0;o--)r={node:a[o],next:r}}return D5e(r,e,n)}function D5e(e,t,n){for(let r=e;r;r=r.next){let i=Vlt(r.node);if(i)return i(Hq.create(t,n,r))}return 0}function Hlt(e){return e.pos==e.options.simulateBreak&&e.options.simulateDoubleBreak}function Vlt(e){let t=e.type.prop(P5e);if(t)return t;let n=e.firstChild,r;if(n&&(r=n.type.prop(Or.closedBy))){let i=e.lastChild,a=i&&r.indexOf(i.name)>-1;return o=>L5e(o,!0,1,void 0,a&&!Hlt(o)?i.from:void 0)}return e.parent==null?Wlt:null}function Wlt(){return 0}class Hq extends Y_{constructor(t,n,r){super(t.state,t.options),this.base=t,this.pos=n,this.context=r}get node(){return this.context.node}static create(t,n,r){return new Hq(t,n,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(t){let n=this.state.doc.lineAt(t.from);for(;;){let r=t.resolve(n.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(Zlt(r,t))break;n=this.state.doc.lineAt(r.from)}return this.lineIndent(n.from)}continue(){return D5e(this.context.next,this.base,this.pos)}}function Zlt(e,t){for(let n=t;n;n=n.parent)if(e==n)return!0;return!1}function Glt(e){let t=e.node,n=t.childAfter(t.from),r=t.lastChild;if(!n)return null;let i=e.options.simulateBreak,a=e.state.doc.lineAt(n.from),o=i==null||i<=a.from?a.to:Math.min(a.to,i);for(let l=n.to;;){let c=t.childAfter(l);if(!c||c==r)return null;if(!c.type.isSkipped){if(c.from>=o)return null;let u=/^ */.exec(a.text.slice(n.to-a.from))[0].length;return{from:n.from,to:n.to+u}}l=c.to}}function dAt({closing:e,align:t=!0,units:n=1}){return r=>L5e(r,t,n,e)}function L5e(e,t,n,r,i){let a=e.textAfter,o=a.match(/^\s*/)[0].length,l=r&&a.slice(o,o+r.length)==r||i==e.pos+o,c=t?Glt(e):null;return c?l?e.column(c.from):e.column(c.to):e.baseIndent+(l?0:e.unit*n)}const fAt=e=>e.baseIndent;function mAt({except:e,units:t=1}={}){return n=>{let r=e&&e.test(n.textAfter);return n.baseIndent+(r?0:t*n.unit)}}const Qlt=200;function Ylt(){return Yr.transactionFilter.of(e=>{if(!e.docChanged||!e.isUserEvent("input.type")&&!e.isUserEvent("input.complete"))return e;let t=e.startState.languageDataAt("indentOnInput",e.startState.selection.main.head);if(!t.length)return e;let n=e.newDoc,{head:r}=e.newSelection.main,i=n.lineAt(r);if(r>i.from+Qlt)return e;let a=n.sliceString(i.from,r);if(!t.some(u=>u.test(a)))return e;let{state:o}=e,l=-1,c=[];for(let{head:u}of o.selection.ranges){let d=o.doc.lineAt(u);if(d.from==l)continue;l=d.from;let f=Kq(o,d.from);if(f==null)continue;let h=/^\s*/.exec(d.text)[0],g=R6(o,f);h!=g&&c.push({from:d.from,to:d.from+h.length,insert:g})}return c.length?[e,{changes:c,sequential:!0}]:e})}const Jlt=Jt.define(),Xlt=new Or;function hAt(e){let t=e.firstChild,n=e.lastChild;return t&&t.to<n.from?{from:t.to,to:n.type.isError?e.to:n.from}:null}function ect(e,t,n){let r=Bo(e);if(r.length<n)return null;let i=r.resolveStack(n,1),a=null;for(let o=i;o;o=o.next){let l=o.node;if(l.to<=n||l.from>n)continue;if(a&&l.from<t)break;let c=l.type.prop(Xlt);if(c&&(l.to<r.length-50||r.length==e.doc.length||!tct(l))){let u=c(l,e);u&&u.from<=n&&u.from>=t&&u.to>n&&(a=u)}}return a}function tct(e){let t=e.lastChild;return t&&t.to==e.to&&t.type.isError}function WN(e,t,n){for(let r of e.facet(Jlt)){let i=r(e,t,n);if(i)return i}return ect(e,t,n)}function $5e(e,t){let n=t.mapPos(e.from,1),r=t.mapPos(e.to,-1);return n>=r?void 0:{from:n,to:r}}const J_=ir.define({map:$5e}),V7=ir.define({map:$5e});function F5e(e){let t=[];for(let{head:n}of e.state.selection.ranges)t.some(r=>r.from<=n&&r.to>=n)||t.push(e.lineBlockAt(n));return t}const p0=qo.define({create(){return $n.none},update(e,t){t.isUserEvent("delete")&&t.changes.iterChangedRanges((n,r)=>e=Jte(e,n,r)),e=e.map(t.changes);for(let n of t.effects)if(n.is(J_)&&!nct(e,n.value.from,n.value.to)){let{preparePlaceholder:r}=t.state.facet(U5e),i=r?$n.replace({widget:new cct(r(t.state,n.value))}):Xte;e=e.update({add:[i.range(n.value.from,n.value.to)]})}else n.is(V7)&&(e=e.update({filter:(r,i)=>n.value.from!=r||n.value.to!=i,filterFrom:n.value.from,filterTo:n.value.to}));return t.selection&&(e=Jte(e,t.selection.main.head)),e},provide:e=>Yt.decorations.from(e),toJSON(e,t){let n=[];return e.between(0,t.doc.length,(r,i)=>{n.push(r,i)}),n},fromJSON(e){if(!Array.isArray(e)||e.length%2)throw new RangeError("Invalid JSON for fold state");let t=[];for(let n=0;n<e.length;){let r=e[n++],i=e[n++];if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid JSON for fold state");t.push(Xte.range(r,i))}return $n.set(t,!0)}});function Jte(e,t,n=t){let r=!1;return e.between(t,n,(i,a)=>{i<n&&a>t&&(r=!0)}),r?e.update({filterFrom:t,filterTo:n,filter:(i,a)=>i>=n||a<=t}):e}function ZN(e,t,n){var r;let i=null;return(r=e.field(p0,!1))===null||r===void 0||r.between(t,n,(a,o)=>{(!i||i.from>a)&&(i={from:a,to:o})}),i}function nct(e,t,n){let r=!1;return e.between(t,t,(i,a)=>{i==t&&a==n&&(r=!0)}),r}function z5e(e,t){return e.field(p0,!1)?t:t.concat(ir.appendConfig.of(q5e()))}const rct=e=>{for(let t of F5e(e)){let n=WN(e.state,t.from,t.to);if(n)return e.dispatch({effects:z5e(e.state,[J_.of(n),B5e(e,n)])}),!0}return!1},sct=e=>{if(!e.state.field(p0,!1))return!1;let t=[];for(let n of F5e(e)){let r=ZN(e.state,n.from,n.to);r&&t.push(V7.of(r),B5e(e,r,!1))}return t.length&&e.dispatch({effects:t}),t.length>0};function B5e(e,t,n=!0){let r=e.state.doc.lineAt(t.from).number,i=e.state.doc.lineAt(t.to).number;return Yt.announce.of(`${e.state.phrase(n?"Folded lines":"Unfolded lines")} ${r} ${e.state.phrase("to")} ${i}.`)}const ict=e=>{let{state:t}=e,n=[];for(let r=0;r<t.doc.length;){let i=e.lineBlockAt(r),a=WN(t,i.from,i.to);a&&n.push(J_.of(a)),r=(a?e.lineBlockAt(a.to):i).to+1}return n.length&&e.dispatch({effects:z5e(e.state,n)}),!!n.length},act=e=>{let t=e.state.field(p0,!1);if(!t||!t.size)return!1;let n=[];return t.between(0,e.state.doc.length,(r,i)=>{n.push(V7.of({from:r,to:i}))}),e.dispatch({effects:n}),!0},oct=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:rct},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:sct},{key:"Ctrl-Alt-[",run:ict},{key:"Ctrl-Alt-]",run:act}],lct={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},U5e=Jt.define({combine(e){return im(e,lct)}});function q5e(e){return[p0,fct]}function K5e(e,t){let{state:n}=e,r=n.facet(U5e),i=o=>{let l=e.lineBlockAt(e.posAtDOM(o.target)),c=ZN(e.state,l.from,l.to);c&&e.dispatch({effects:V7.of(c)}),o.preventDefault()};if(r.placeholderDOM)return r.placeholderDOM(e,i,t);let a=document.createElement("span");return a.textContent=r.placeholderText,a.setAttribute("aria-label",n.phrase("folded code")),a.title=n.phrase("unfold"),a.className="cm-foldPlaceholder",a.onclick=i,a}const Xte=$n.replace({widget:new class extends am{toDOM(e){return K5e(e,null)}}});class cct extends am{constructor(t){super(),this.value=t}eq(t){return this.value==t.value}toDOM(t){return K5e(t,this.value)}}const uct={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class MM extends A1{constructor(t,n){super(),this.config=t,this.open=n}eq(t){return this.config==t.config&&this.open==t.open}toDOM(t){if(this.config.markerDOM)return this.config.markerDOM(this.open);let n=document.createElement("span");return n.textContent=this.open?this.config.openText:this.config.closedText,n.title=t.state.phrase(this.open?"Fold line":"Unfold line"),n}}function dct(e={}){let t={...uct,...e},n=new MM(t,!0),r=new MM(t,!1),i=ia.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet(Hp)!=o.state.facet(Hp)||o.startState.field(p0,!1)!=o.state.field(p0,!1)||Bo(o.startState)!=Bo(o.state)||t.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let l=new S1;for(let c of o.viewportLineBlocks){let u=ZN(o.state,c.from,c.to)?r:WN(o.state,c.from,c.to)?n:null;u&&l.add(c.from,c.from,u)}return l.finish()}}),{domEventHandlers:a}=t;return[i,alt({class:"cm-foldGutter",markers(o){var l;return((l=o.plugin(i))===null||l===void 0?void 0:l.markers)||Lr.empty},initialSpacer(){return new MM(t,!1)},domEventHandlers:{...a,click:(o,l,c)=>{if(a.click&&a.click(o,l,c))return!0;let u=ZN(o.state,l.from,l.to);if(u)return o.dispatch({effects:V7.of(u)}),!0;let d=WN(o.state,l.from,l.to);return d?(o.dispatch({effects:J_.of(d)}),!0):!1}}}),q5e()]}const fct=Yt.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class W7{constructor(t,n){this.specs=t;let r;function i(l){let c=Bp.newName();return(r||(r=Object.create(null)))["."+c]=l,c}const a=typeof n.all=="string"?n.all:n.all?i(n.all):void 0,o=n.scope;this.scope=o instanceof wu?l=>l.prop(a2)==o.data:o?l=>l==o:void 0,this.style=M5e(t.map(l=>({tag:l.tag,class:l.class||i(Object.assign({},l,{tag:null}))})),{all:a}).style,this.module=r?new Bp(r):null,this.themeType=n.themeType}static define(t,n){return new W7(t,n||{})}}const zL=Jt.define(),H5e=Jt.define({combine(e){return e.length?[e[0]]:null}});function RM(e){let t=e.facet(zL);return t.length?t:e.facet(H5e)}function V5e(e,t){let n=[hct],r;return e instanceof W7&&(e.module&&n.push(Yt.styleModule.of(e.module)),r=e.themeType),t!=null&&t.fallback?n.push(H5e.of(e)):r?n.push(zL.computeN([Yt.darkTheme],i=>i.facet(Yt.darkTheme)==(r=="dark")?[e]:[])):n.push(zL.of(e)),n}class mct{constructor(t){this.markCache=Object.create(null),this.tree=Bo(t.state),this.decorations=this.buildDeco(t,RM(t.state)),this.decoratedTo=t.viewport.to}update(t){let n=Bo(t.state),r=RM(t.state),i=r!=RM(t.startState),{viewport:a}=t.view,o=t.changes.mapPos(this.decoratedTo,1);n.length<a.to&&!i&&n.type==this.tree.type&&o>=a.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=o):(n!=this.tree||t.viewportChanged||i)&&(this.tree=n,this.decorations=this.buildDeco(t.view,r),this.decoratedTo=a.to)}buildDeco(t,n){if(!n||!this.tree.length)return $n.none;let r=new S1;for(let{from:i,to:a}of t.visibleRanges)Dlt(this.tree,n,(o,l,c)=>{r.add(o,l,this.markCache[c]||(this.markCache[c]=$n.mark({class:c})))},i,a);return r.finish()}}const hct=lg.high(ia.fromClass(mct,{decorations:e=>e.decorations})),pct=W7.define([{tag:dt.meta,color:"#404740"},{tag:dt.link,textDecoration:"underline"},{tag:dt.heading,textDecoration:"underline",fontWeight:"bold"},{tag:dt.emphasis,fontStyle:"italic"},{tag:dt.strong,fontWeight:"bold"},{tag:dt.strikethrough,textDecoration:"line-through"},{tag:dt.keyword,color:"#708"},{tag:[dt.atom,dt.bool,dt.url,dt.contentSeparator,dt.labelName],color:"#219"},{tag:[dt.literal,dt.inserted],color:"#164"},{tag:[dt.string,dt.deleted],color:"#a11"},{tag:[dt.regexp,dt.escape,dt.special(dt.string)],color:"#e40"},{tag:dt.definition(dt.variableName),color:"#00f"},{tag:dt.local(dt.variableName),color:"#30a"},{tag:[dt.typeName,dt.namespace],color:"#085"},{tag:dt.className,color:"#167"},{tag:[dt.special(dt.variableName),dt.macroName],color:"#256"},{tag:dt.definition(dt.propertyName),color:"#00c"},{tag:dt.comment,color:"#940"},{tag:dt.invalid,color:"#f00"}]),gct=Yt.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),W5e=1e4,Z5e="()[]{}",G5e=Jt.define({combine(e){return im(e,{afterCursor:!0,brackets:Z5e,maxScanDistance:W5e,renderMatch:yct})}}),xct=$n.mark({class:"cm-matchingBracket"}),bct=$n.mark({class:"cm-nonmatchingBracket"});function yct(e){let t=[],n=e.matched?xct:bct;return t.push(n.range(e.start.from,e.start.to)),e.end&&t.push(n.range(e.end.from,e.end.to)),t}function ene(e){let t=[],n=e.facet(G5e);for(let r of e.selection.ranges){if(!r.empty)continue;let i=Tf(e,r.head,-1,n)||r.head>0&&Tf(e,r.head-1,1,n)||n.afterCursor&&(Tf(e,r.head,1,n)||r.head<e.doc.length&&Tf(e,r.head+1,-1,n));i&&(t=t.concat(n.renderMatch(i,e)))}return $n.set(t,!0)}const vct=ia.fromClass(class{constructor(e){this.paused=!1,this.decorations=ene(e.state)}update(e){(e.docChanged||e.selectionSet||this.paused)&&(e.view.composing?(this.decorations=this.decorations.map(e.changes),this.paused=!0):(this.decorations=ene(e.state),this.paused=!1))}},{decorations:e=>e.decorations}),wct=[vct,gct];function kct(e={}){return[G5e.of(e),wct]}const jct=new Or;function BL(e,t,n){let r=e.prop(t<0?Or.openedBy:Or.closedBy);if(r)return r;if(e.name.length==1){let i=n.indexOf(e.name);if(i>-1&&i%2==(t<0?1:0))return[n[i+t]]}return null}function UL(e){let t=e.type.prop(jct);return t?t(e.node):e}function Tf(e,t,n,r={}){let i=r.maxScanDistance||W5e,a=r.brackets||Z5e,o=Bo(e),l=o.resolveInner(t,n);for(let c=l;c;c=c.parent){let u=BL(c.type,n,a);if(u&&c.from<c.to){let d=UL(c);if(d&&(n>0?t>=d.from&&t<d.to:t>d.from&&t<=d.to))return Nct(e,t,n,c,d,u,a)}}return Cct(e,t,n,o,l.type,i,a)}function Nct(e,t,n,r,i,a,o){let l=r.parent,c={from:i.from,to:i.to},u=0,d=l==null?void 0:l.cursor();if(d&&(n<0?d.childBefore(r.from):d.childAfter(r.to)))do if(n<0?d.to<=r.from:d.from>=r.to){if(u==0&&a.indexOf(d.type.name)>-1&&d.from<d.to){let f=UL(d);return{start:c,end:f?{from:f.from,to:f.to}:void 0,matched:!0}}else if(BL(d.type,n,o))u++;else if(BL(d.type,-n,o)){if(u==0){let f=UL(d);return{start:c,end:f&&f.from<f.to?{from:f.from,to:f.to}:void 0,matched:!1}}u--}}while(n<0?d.prevSibling():d.nextSibling());return{start:c,matched:!1}}function Cct(e,t,n,r,i,a,o){let l=n<0?e.sliceDoc(t-1,t):e.sliceDoc(t,t+1),c=o.indexOf(l);if(c<0||c%2==0!=n>0)return null;let u={from:n<0?t-1:t,to:n>0?t+1:t},d=e.doc.iterRange(t,n>0?e.doc.length:0),f=0;for(let h=0;!d.next().done&&h<=a;){let g=d.value;n<0&&(h+=g.length);let b=t+h*n;for(let v=n>0?0:g.length-1,j=n>0?g.length:-1;v!=j;v+=n){let k=o.indexOf(g[v]);if(!(k<0||r.resolveInner(b+v,1).type!=i))if(k%2==0==n>0)f++;else{if(f==1)return{start:u,end:{from:b+v,to:b+v+1},matched:k>>1==c>>1};f--}}n>0&&(h+=g.length)}return d.done?{start:u,matched:!1}:null}function tne(e,t,n,r=0,i=0){t==null&&(t=e.search(/[^\s\u00a0]/),t==-1&&(t=e.length));let a=i;for(let o=r;o<t;o++)e.charCodeAt(o)==9?a+=n-a%n:a++;return a}class Q5e{constructor(t,n,r,i){this.string=t,this.tabSize=n,this.indentUnit=r,this.overrideIndent=i,this.pos=0,this.start=0,this.lastColumnPos=0,this.lastColumnValue=0}eol(){return this.pos>=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)}eat(t){let n=this.string.charAt(this.pos),r;if(typeof t=="string"?r=n==t:r=n&&(t instanceof RegExp?t.test(n):t(n)),r)return++this.pos,n}eatWhile(t){let n=this.pos;for(;this.eat(t););return this.pos>n}eatSpace(){let t=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>t}skipToEnd(){this.pos=this.string.length}skipTo(t){let n=this.string.indexOf(t,this.pos);if(n>-1)return this.pos=n,!0}backUp(t){this.pos-=t}column(){return this.lastColumnPos<this.start&&(this.lastColumnValue=tne(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){var t;return(t=this.overrideIndent)!==null&&t!==void 0?t:tne(this.string,null,this.tabSize)}match(t,n,r){if(typeof t=="string"){let i=o=>r?o.toLowerCase():o,a=this.string.substr(this.pos,t.length);return i(a)==i(t)?(n!==!1&&(this.pos+=t.length),!0):null}else{let i=this.string.slice(this.pos).match(t);return i&&i.index>0?null:(i&&n!==!1&&(this.pos+=i[0].length),i)}}current(){return this.string.slice(this.start,this.pos)}}function Sct(e){return{name:e.name||"",token:e.token,blankLine:e.blankLine||(()=>{}),startState:e.startState||(()=>!0),copyState:e.copyState||_ct,indent:e.indent||(()=>null),languageData:e.languageData||{},tokenTable:e.tokenTable||Zq,mergeTokens:e.mergeTokens!==!1}}function _ct(e){if(typeof e!="object")return e;let t={};for(let n in e){let r=e[n];t[n]=r instanceof Array?r.slice():r}return t}const nne=new WeakMap;class Vq extends wu{constructor(t){let n=R5e(t.languageData),r=Sct(t),i,a=new class extends T5e{createParse(o,l,c){return new Ect(i,o,l,c)}};super(n,a,[],t.name),this.topNode=Mct(n,this),i=this,this.streamParser=r,this.stateAfter=new Or({perNode:!0}),this.tokenTable=t.tokenTable?new e4e(r.tokenTable):Ict}static define(t){return new Vq(t)}getIndent(t){let n,{overrideIndentation:r}=t.options;r&&(n=nne.get(t.state),n!=null&&n<t.pos-1e4&&(n=void 0));let i=Wq(this,t.node.tree,t.node.from,t.node.from,n??t.pos),a,o;if(i?(o=i.state,a=i.pos+1):(o=this.streamParser.startState(t.unit),a=t.node.from),t.pos-a>1e4)return null;for(;a<t.pos;){let c=t.state.doc.lineAt(a),u=Math.min(t.pos,c.to);if(c.length){let d=r?r(c.from):-1,f=new Q5e(c.text,t.state.tabSize,t.unit,d<0?void 0:d);for(;f.pos<u-c.from;)J5e(this.streamParser.token,f,o)}else this.streamParser.blankLine(o,t.unit);if(u==t.pos)break;a=c.to+1}let l=t.lineAt(t.pos);return r&&n==null&&nne.set(t.state,l.from),this.streamParser.indent(o,/^\s*(.*)/.exec(l.text)[1],t)}get allowsNesting(){return!1}}function Wq(e,t,n,r,i){let a=n>=r&&n+t.length<=i&&t.prop(e.stateAfter);if(a)return{state:e.streamParser.copyState(a),pos:n+t.length};for(let o=t.children.length-1;o>=0;o--){let l=t.children[o],c=n+t.positions[o],u=l instanceof Vs&&c<i&&Wq(e,l,c,r,i);if(u)return u}return null}function Y5e(e,t,n,r,i){if(i&&n<=0&&r>=t.length)return t;!i&&n==0&&t.type==e.topNode&&(i=!0);for(let a=t.children.length-1;a>=0;a--){let o=t.positions[a],l=t.children[a],c;if(o<r&&l instanceof Vs){if(!(c=Y5e(e,l,n-o,r-o,i)))break;return i?new Vs(t.type,t.children.slice(0,a).concat(c),t.positions.slice(0,a+1),o+c.length):c}}return null}function Act(e,t,n,r,i){for(let a of t){let o=a.from+(a.openStart?25:0),l=a.to-(a.openEnd?25:0),c=o<=n&&l>n&&Wq(e,a.tree,0-a.offset,n,l),u;if(c&&c.pos<=r&&(u=Y5e(e,a.tree,n+a.offset,c.pos+a.offset,!1)))return{state:c.state,tree:u}}return{state:e.streamParser.startState(i?h0(i):4),tree:Vs.empty}}class Ect{constructor(t,n,r,i){this.lang=t,this.input=n,this.fragments=r,this.ranges=i,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=i[i.length-1].to;let a=T5.get(),o=i[0].from,{state:l,tree:c}=Act(t,r,o,this.to,a==null?void 0:a.state);this.state=l,this.parsedPos=this.chunkStart=o+c.length;for(let u=0;u<c.children.length;u++)this.chunks.push(c.children[u]),this.chunkPos.push(c.positions[u]);a&&this.parsedPos<a.viewport.from-1e5&&i.some(u=>u.from<=a.viewport.from&&u.to>=a.viewport.from)&&(this.state=this.lang.streamParser.startState(h0(a.state)),a.skipUntilInView(this.parsedPos,a.viewport.from),this.parsedPos=a.viewport.from),this.moveRangeIndex()}advance(){let t=T5.get(),n=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),r=Math.min(n,this.chunkStart+512);for(t&&(r=Math.min(r,t.viewport.to));this.parsedPos<r;)this.parseLine(t);return this.chunkStart<this.parsedPos&&this.finishChunk(),this.parsedPos>=n?this.finish():t&&this.parsedPos>=t.viewport.to?(t.skipUntilInView(this.parsedPos,n),this.finish()):null}stopAt(t){this.stoppedAt=t}lineAfter(t){let n=this.input.chunk(t);if(this.input.lineChunks)n==`
1296
1296
  `&&(n="");else{let r=n.indexOf(`
1297
- `);r>-1&&(n=n.slice(0,r))}return t+n.length<=this.to?n:n.slice(0,this.to-t)}nextLine(){let t=this.parsedPos,n=this.lineAfter(t),r=t+n.length;for(let i=this.rangeIndex;;){let a=this.ranges[i].to;if(a>=r||(n=n.slice(0,a-(r-n.length)),i++,i==this.ranges.length))break;let o=this.ranges[i].from,l=this.lineAfter(o);n+=l,r=o+l.length}return{line:n,end:r}}skipGapsTo(t,n,r){for(;;){let i=this.ranges[this.rangeIndex].to,a=t+n;if(r>0?i>a:i>=a)break;let o=this.ranges[++this.rangeIndex].from;n+=o-i}return n}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(t,n,r,i){let a=4;if(this.ranges.length>1){i=this.skipGapsTo(n,i,1),n+=i;let l=this.chunk.length;i=this.skipGapsTo(r,i,-1),r+=i,a+=this.chunk.length-l}let o=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&a==4&&o>=0&&this.chunk[o]==t&&this.chunk[o+2]==n?this.chunk[o+2]=r:this.chunk.push(t,n,r,a),i}parseLine(t){let{line:n,end:r}=this.nextLine(),i=0,{streamParser:a}=this.lang,o=new Q5e(n,t?t.state.tabSize:4,t?h0(t.state):2);if(o.eol())a.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=J5e(a.token,o,this.state);if(l&&(i=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,i)),o.start>1e4)break}this.parsedPos=r,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let t=Vs.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:Tct,topID:0,maxBufferLength:512,reused:this.chunkReused});t=new Vs(t.type,t.children,t.positions,t.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(t),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new Vs(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function J5e(e,t,n){t.start=t.pos;for(let r=0;r<10;r++){let i=e(t,n);if(t.pos>t.start)return i}throw new Error("Stream parser failed to advance stream.")}const Zq=Object.create(null),O6=[Ll.none],Tct=new zq(O6),rne=[],sne=Object.create(null),X5e=Object.create(null);for(let[e,t]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])X5e[e]=t4e(Zq,t);class e4e{constructor(t){this.extra=t,this.table=Object.assign(Object.create(null),X5e)}resolve(t){return t?this.table[t]||(this.table[t]=t4e(this.extra,t)):0}}const Ict=new e4e(Zq);function OM(e,t){rne.indexOf(e)>-1||(rne.push(e),console.warn(t))}function t4e(e,t){let n=[];for(let l of t.split(" ")){let c=[];for(let u of l.split(".")){let d=e[u]||dt[u];d?typeof d=="function"?c.length?c=c.map(d):OM(u,`Modifier ${u} used at start of tag`):c.length?OM(u,`Tag ${u} used as modifier`):c=Array.isArray(d)?d:[d]:OM(u,`Unknown highlighting tag ${u}`)}for(let u of c)n.push(u)}if(!n.length)return 0;let r=t.replace(/ /g,"_"),i=r+" "+n.map(l=>l.id),a=sne[i];if(a)return a.id;let o=sne[i]=Ll.define({id:O6.length,name:r,props:[Olt({[r]:n})]});return O6.push(o),o.id}function Mct(e,t){let n=Ll.define({id:O6.length,name:"Document",props:[a2.add(()=>e),P5e.add(()=>r=>t.getIndent(r))],top:!0});return O6.push(n),n}Hs.RTL,Hs.LTR;class n4e{constructor(t,n,r,i){this.state=t,this.pos=n,this.explicit=r,this.view=i,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(t){let n=Bo(this.state).resolveInner(this.pos,-1);for(;n&&t.indexOf(n.name)<0;)n=n.parent;return n?{from:n.from,to:this.pos,text:this.state.sliceDoc(n.from,this.pos),type:n.type}:null}matchBefore(t){let n=this.state.doc.lineAt(this.pos),r=Math.max(n.from,this.pos-250),i=n.text.slice(r-n.from,this.pos-n.from),a=i.search(r4e(t,!1));return a<0?null:{from:r+a,to:this.pos,text:i.slice(a)}}get aborted(){return this.abortListeners==null}addEventListener(t,n,r){t=="abort"&&this.abortListeners&&(this.abortListeners.push(n),r&&r.onDocChange&&(this.abortOnDocChange=!0))}}function ine(e){let t=Object.keys(e).join(""),n=/\w/.test(t);return n&&(t=t.replace(/\w/g,"")),`[${n?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}function Rct(e){let t=Object.create(null),n=Object.create(null);for(let{label:i}of e){t[i[0]]=!0;for(let a=1;a<i.length;a++)n[i[a]]=!0}let r=ine(t)+ine(n)+"*$";return[new RegExp("^"+r),new RegExp(r)]}function Oct(e){let t=e.map(i=>typeof i=="string"?{label:i}:i),[n,r]=t.every(i=>/^\w+$/.test(i.label))?[/\w*$/,/\w+$/]:Rct(t);return i=>{let a=i.matchBefore(r);return a||i.explicit?{from:a?a.from:i.pos,options:t,validFor:n}:null}}function pAt(e,t){return n=>{for(let r=Bo(n.state).resolveInner(n.pos,-1);r;r=r.parent){if(e.indexOf(r.name)>-1)return null;if(r.type.isTop)break}return t(n)}}class ane{constructor(t,n,r,i){this.completion=t,this.source=n,this.match=r,this.score=i}}function E2(e){return e.selection.main.from}function r4e(e,t){var n;let{source:r}=e,i=t&&r[0]!="^",a=r[r.length-1]!="$";return!i&&!a?e:new RegExp(`${i?"^":""}(?:${r})${a?"$":""}`,(n=e.flags)!==null&&n!==void 0?n:e.ignoreCase?"i":"")}const Gq=q1.define();function Pct(e,t,n,r){let{main:i}=e.selection,a=n-i.from,o=r-i.from;return{...e.changeByRange(l=>{if(l!=i&&n!=r&&e.sliceDoc(l.from+a,l.from+o)!=e.sliceDoc(n,r))return{range:l};let c=e.toText(t);return{changes:{from:l.from+a,to:r==i.from?l.to:l.from+o,insert:c},range:bt.cursor(l.from+a+c.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const one=new WeakMap;function Dct(e){if(!Array.isArray(e))return e;let t=one.get(e);return t||one.set(e,t=Oct(e)),t}const GN=ir.define(),P6=ir.define();class Lct{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let n=0;n<t.length;){let r=Xl(t,n),i=wf(r);this.chars.push(r);let a=t.slice(n,n+i),o=a.toUpperCase();this.folded.push(Xl(o==a?a.toLowerCase():o,0)),n+=i}this.astral=t.length!=this.chars.length}ret(t,n){return this.score=t,this.matched=n,this}match(t){if(this.pattern.length==0)return this.ret(-100,[]);if(t.length<this.pattern.length)return null;let{chars:n,folded:r,any:i,precise:a,byWord:o}=this;if(n.length==1){let w=Xl(t,0),N=wf(w),C=N==t.length?0:-100;if(w!=n[0])if(w==r[0])C+=-200;else return null;return this.ret(C,[0,N])}let l=t.indexOf(this.pattern);if(l==0)return this.ret(t.length==this.pattern.length?0:-100,[0,this.pattern.length]);let c=n.length,u=0;if(l<0){for(let w=0,N=Math.min(t.length,200);w<N&&u<c;){let C=Xl(t,w);(C==n[u]||C==r[u])&&(i[u++]=w),w+=wf(C)}if(u<c)return null}let d=0,f=0,h=!1,g=0,b=-1,v=-1,j=/[a-z]/.test(t),k=!0;for(let w=0,N=Math.min(t.length,200),C=0;w<N&&f<c;){let A=Xl(t,w);l<0&&(d<c&&A==n[d]&&(a[d++]=w),g<c&&(A==n[g]||A==r[g]?(g==0&&(b=w),v=w+1,g++):g=0));let _,E=A<255?A>=48&&A<=57||A>=97&&A<=122?2:A>=65&&A<=90?1:0:(_=wq(A))!=_.toLowerCase()?1:_!=_.toUpperCase()?2:0;(!w||E==1&&j||C==0&&E!=0)&&(n[f]==A||r[f]==A&&(h=!0)?o[f++]=w:o.length&&(k=!1)),C=E,w+=wf(A)}return f==c&&o[0]==0&&k?this.result(-100+(h?-200:0),o,t):g==c&&b==0?this.ret(-200-t.length+(v==t.length?0:-100),[0,v]):l>-1?this.ret(-700-t.length,[l,l+this.pattern.length]):g==c?this.ret(-900-t.length,[b,v]):f==c?this.result(-100+(h?-200:0)+-700+(k?0:-1100),o,t):n.length==2?null:this.result((i[0]?-700:0)+-200+-1100,i,t)}result(t,n,r){let i=[],a=0;for(let o of n){let l=o+(this.astral?wf(Xl(r,o)):1);a&&i[a-1]==o?i[a-1]=l:(i[a++]=o,i[a++]=l)}return this.ret(t-r.length,i)}}class $ct{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.length<this.pattern.length)return null;let n=t.slice(0,this.pattern.length),r=n==this.pattern?0:n.toLowerCase()==this.folded?-200:null;return r==null?null:(this.matched=[0,n.length],this.score=r+(t.length==this.pattern.length?0:-100),this)}}const ao=Jt.define({combine(e){return im(e,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Fct,filterStrict:!1,compareCompletions:(t,n)=>(t.sortText||t.label).localeCompare(n.sortText||n.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,n)=>t&&n,closeOnBlur:(t,n)=>t&&n,icons:(t,n)=>t&&n,tooltipClass:(t,n)=>r=>lne(t(r),n(r)),optionClass:(t,n)=>r=>lne(t(r),n(r)),addToOptions:(t,n)=>t.concat(n),filterStrict:(t,n)=>t||n})}});function lne(e,t){return e?t?e+" "+t:e:t}function Fct(e,t,n,r,i,a){let o=e.textDirection==Hs.RTL,l=o,c=!1,u="top",d,f,h=t.left-i.left,g=i.right-t.right,b=r.right-r.left,v=r.bottom-r.top;if(l&&h<Math.min(b,g)?l=!1:!l&&g<Math.min(b,h)&&(l=!0),b<=(l?h:g))d=Math.max(i.top,Math.min(n.top,i.bottom-v))-t.top,f=Math.min(400,l?h:g);else{c=!0,f=Math.min(400,(o?t.right:i.right-t.left)-30);let w=i.bottom-t.bottom;w>=v||w>t.top?d=n.bottom-t.top:(u="bottom",d=t.bottom-n.top)}let j=(t.bottom-t.top)/a.offsetHeight,k=(t.right-t.left)/a.offsetWidth;return{style:`${u}: ${d/j}px; max-width: ${f/k}px`,class:"cm-completionInfo-"+(c?o?"left-narrow":"right-narrow":l?"left":"right")}}const Qq=ir.define();function zct(e){let t=e.addToOptions.slice();return e.icons&&t.push({render(n){let r=document.createElement("div");return r.classList.add("cm-completionIcon"),n.type&&r.classList.add(...n.type.split(/\s+/g).map(i=>"cm-completionIcon-"+i)),r.setAttribute("aria-hidden","true"),r},position:20}),t.push({render(n,r,i,a){let o=document.createElement("span");o.className="cm-completionLabel";let l=n.displayLabel||n.label,c=0;for(let u=0;u<a.length;){let d=a[u++],f=a[u++];d>c&&o.appendChild(document.createTextNode(l.slice(c,d)));let h=o.appendChild(document.createElement("span"));h.appendChild(document.createTextNode(l.slice(d,f))),h.className="cm-completionMatchedText",c=f}return c<l.length&&o.appendChild(document.createTextNode(l.slice(c))),o},position:50},{render(n){if(!n.detail)return null;let r=document.createElement("span");return r.className="cm-completionDetail",r.textContent=n.detail,r},position:80}),t.sort((n,r)=>n.position-r.position).map(n=>n.render)}function PM(e,t,n){if(e<=n)return{from:0,to:e};if(t<0&&(t=0),t<=e>>1){let i=Math.floor(t/n);return{from:i*n,to:(i+1)*n}}let r=Math.floor((e-t)/n);return{from:e-(r+1)*n,to:e-r*n}}class Bct{constructor(t,n,r){this.view=t,this.stateField=n,this.applyCompletion=r,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:c=>this.placeInfo(c),key:this},this.space=null,this.currentClass="";let i=t.state.field(n),{options:a,selected:o}=i.open,l=t.state.facet(ao);this.optionContent=zct(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=PM(a.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",c=>{let{options:u}=t.state.field(n).open;for(let d=c.target,f;d&&d!=this.dom;d=d.parentNode)if(d.nodeName=="LI"&&(f=/-(\d+)$/.exec(d.id))&&+f[1]<u.length){this.applyCompletion(t,u[+f[1]]),c.preventDefault();return}if(c.target==this.list){let d=this.list.classList.contains("cm-completionListIncompleteTop")&&c.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&c.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;d!=null&&(t.dispatch({effects:Qq.of(d)}),c.preventDefault())}}),this.dom.addEventListener("focusout",c=>{let u=t.state.field(this.stateField,!1);u&&u.tooltip&&t.state.facet(ao).closeOnBlur&&c.relatedTarget!=t.contentDOM&&t.dispatch({effects:P6.of(null)})}),this.showOptions(a,i.id)}mount(){this.updateSel()}showOptions(t,n){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,n,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var n;let r=t.state.field(this.stateField),i=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),r!=i){let{options:a,selected:o,disabled:l}=r.open;(!i.open||i.open.options!=a)&&(this.range=PM(a.length,o,t.state.facet(ao).maxRenderedOptions),this.showOptions(a,r.id)),this.updateSel(),l!=((n=i.open)===null||n===void 0?void 0:n.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(t){let n=this.tooltipClass(t);if(n!=this.currentClass){for(let r of this.currentClass.split(" "))r&&this.dom.classList.remove(r);for(let r of n.split(" "))r&&this.dom.classList.add(r);this.currentClass=n}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),n=t.open;(n.selected>-1&&n.selected<this.range.from||n.selected>=this.range.to)&&(this.range=PM(n.options.length,n.selected,this.view.state.facet(ao).maxRenderedOptions),this.showOptions(n.options,t.id));let r=this.updateSelectedOption(n.selected);if(r){this.destroyInfo();let{completion:i}=n.options[n.selected],{info:a}=i;if(!a)return;let o=typeof a=="string"?document.createTextNode(a):a(i);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(l,i)}).catch(l=>rc(this.view.state,l,"completion info")):(this.addInfoPane(o,i),r.setAttribute("aria-describedby",this.info.id))}}addInfoPane(t,n){this.destroyInfo();let r=this.info=document.createElement("div");if(r.className="cm-tooltip cm-completionInfo",r.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),t.nodeType!=null)r.appendChild(t),this.infoDestroy=null;else{let{dom:i,destroy:a}=t;r.appendChild(i),this.infoDestroy=a||null}this.dom.appendChild(r),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let n=null;for(let r=this.list.firstChild,i=this.range.from;r;r=r.nextSibling,i++)r.nodeName!="LI"||!r.id?i--:i==t?r.hasAttribute("aria-selected")||(r.setAttribute("aria-selected","true"),n=r):r.hasAttribute("aria-selected")&&(r.removeAttribute("aria-selected"),r.removeAttribute("aria-describedby"));return n&&qct(this.list,n),n}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let n=this.dom.getBoundingClientRect(),r=this.info.getBoundingClientRect(),i=t.getBoundingClientRect(),a=this.space;if(!a){let o=this.dom.ownerDocument.documentElement;a={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return i.top>Math.min(a.bottom,n.bottom)-10||i.bottom<Math.max(a.top,n.top)+10?null:this.view.state.facet(ao).positionInfo(this.view,n,i,r,a,this.dom)}placeInfo(t){this.info&&(t?(t.style&&(this.info.style.cssText=t.style),this.info.className="cm-tooltip cm-completionInfo "+(t.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(t,n,r){const i=document.createElement("ul");i.id=n,i.setAttribute("role","listbox"),i.setAttribute("aria-expanded","true"),i.setAttribute("aria-label",this.view.state.phrase("Completions")),i.addEventListener("mousedown",o=>{o.target==i&&o.preventDefault()});let a=null;for(let o=r.from;o<r.to;o++){let{completion:l,match:c}=t[o],{section:u}=l;if(u){let h=typeof u=="string"?u:u.name;if(h!=a&&(o>r.from||r.from==0))if(a=h,typeof u!="string"&&u.header)i.appendChild(u.header(u));else{let g=i.appendChild(document.createElement("completion-section"));g.textContent=h}}const d=i.appendChild(document.createElement("li"));d.id=n+"-"+o,d.setAttribute("role","option");let f=this.optionClass(l);f&&(d.className=f);for(let h of this.optionContent){let g=h(l,this.view.state,this.view,c);g&&d.appendChild(g)}}return r.from&&i.classList.add("cm-completionListIncompleteTop"),r.to<t.length&&i.classList.add("cm-completionListIncompleteBottom"),i}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function Uct(e,t){return n=>new Bct(n,e,t)}function qct(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.height/e.offsetHeight;r.top<n.top?e.scrollTop-=(n.top-r.top)/i:r.bottom>n.bottom&&(e.scrollTop+=(r.bottom-n.bottom)/i)}function cne(e){return(e.boost||0)*100+(e.apply?10:0)+(e.info?5:0)+(e.type?1:0)}function Kct(e,t){let n=[],r=null,i=null,a=d=>{n.push(d);let{section:f}=d.completion;if(f){r||(r=[]);let h=typeof f=="string"?f:f.name;r.some(g=>g.name==h)||r.push(typeof f=="string"?{name:h}:f)}},o=t.facet(ao);for(let d of e)if(d.hasResult()){let f=d.result.getMatch;if(d.result.filter===!1)for(let h of d.result.options)a(new ane(h,d.source,f?f(h):[],1e9-n.length));else{let h=t.sliceDoc(d.from,d.to),g,b=o.filterStrict?new $ct(h):new Lct(h);for(let v of d.result.options)if(g=b.match(v.label)){let j=v.displayLabel?f?f(v,g.matched):[]:g.matched,k=g.score+(v.boost||0);if(a(new ane(v,d.source,j,k)),typeof v.section=="object"&&v.section.rank==="dynamic"){let{name:w}=v.section;i||(i=Object.create(null)),i[w]=Math.max(k,i[w]||-1e9)}}}}if(r){let d=Object.create(null),f=0,h=(g,b)=>(g.rank==="dynamic"&&b.rank==="dynamic"?i[b.name]-i[g.name]:0)||(typeof g.rank=="number"?g.rank:1e9)-(typeof b.rank=="number"?b.rank:1e9)||(g.name<b.name?-1:1);for(let g of r.sort(h))f-=1e5,d[g.name]=f;for(let g of n){let{section:b}=g.completion;b&&(g.score+=d[typeof b=="string"?b:b.name])}}let l=[],c=null,u=o.compareCompletions;for(let d of n.sort((f,h)=>h.score-f.score||u(f.completion,h.completion))){let f=d.completion;!c||c.label!=f.label||c.detail!=f.detail||c.type!=null&&f.type!=null&&c.type!=f.type||c.apply!=f.apply||c.boost!=f.boost?l.push(d):cne(d.completion)>cne(c)&&(l[l.length-1]=d),c=d.completion}return l}class u3{constructor(t,n,r,i,a,o){this.options=t,this.attrs=n,this.tooltip=r,this.timestamp=i,this.selected=a,this.disabled=o}setSelected(t,n){return t==this.selected||t>=this.options.length?this:new u3(this.options,une(n,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,n,r,i,a,o){if(i&&!o&&t.some(u=>u.isPending))return i.setDisabled();let l=Kct(t,n);if(!l.length)return i&&t.some(u=>u.isPending)?i.setDisabled():null;let c=n.facet(ao).selectOnOpen?0:-1;if(i&&i.selected!=c&&i.selected!=-1){let u=i.options[i.selected].completion;for(let d=0;d<l.length;d++)if(l[d].completion==u){c=d;break}}return new u3(l,une(r,c),{pos:t.reduce((u,d)=>d.hasResult()?Math.min(u,d.from):u,1e8),create:Qct,above:a.aboveCursor},i?i.timestamp:Date.now(),c,!1)}map(t){return new u3(this.options,this.attrs,{...this.tooltip,pos:t.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new u3(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class QN{constructor(t,n,r){this.active=t,this.id=n,this.open=r}static start(){return new QN(Zct,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(t){let{state:n}=t,r=n.facet(ao),a=(r.override||n.languageDataAt("autocomplete",E2(n)).map(Dct)).map(c=>(this.active.find(d=>d.source==c)||new ku(c,this.active.some(d=>d.state!=0)?1:0)).update(t,r));a.length==this.active.length&&a.every((c,u)=>c==this.active[u])&&(a=this.active);let o=this.open,l=t.effects.some(c=>c.is(Yq));o&&t.docChanged&&(o=o.map(t.changes)),t.selection||a.some(c=>c.hasResult()&&t.changes.touchesRange(c.from,c.to))||!Hct(a,this.active)||l?o=u3.build(a,n,this.id,o,r,l):o&&o.disabled&&!a.some(c=>c.isPending)&&(o=null),!o&&a.every(c=>!c.isPending)&&a.some(c=>c.hasResult())&&(a=a.map(c=>c.hasResult()?new ku(c.source,0):c));for(let c of t.effects)c.is(Qq)&&(o=o&&o.setSelected(c.value,this.id));return a==this.active&&o==this.open?this:new QN(a,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Vct:Wct}}function Hct(e,t){if(e==t)return!0;for(let n=0,r=0;;){for(;n<e.length&&!e[n].hasResult();)n++;for(;r<t.length&&!t[r].hasResult();)r++;let i=n==e.length,a=r==t.length;if(i||a)return i==a;if(e[n++].result!=t[r++].result)return!1}}const Vct={"aria-autocomplete":"list"},Wct={};function une(e,t){let n={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":e};return t>-1&&(n["aria-activedescendant"]=e+"-"+t),n}const Zct=[];function s4e(e,t){if(e.isUserEvent("input.complete")){let r=e.annotation(Gq);if(r&&t.activateOnCompletion(r))return 12}let n=e.isUserEvent("input.type");return n&&t.activateOnTyping?5:n?1:e.isUserEvent("delete.backward")?2:e.selection?8:e.docChanged?16:0}class ku{constructor(t,n,r=!1){this.source=t,this.state=n,this.explicit=r}hasResult(){return!1}get isPending(){return this.state==1}update(t,n){let r=s4e(t,n),i=this;(r&8||r&16&&this.touches(t))&&(i=new ku(i.source,0)),r&4&&i.state==0&&(i=new ku(this.source,1)),i=i.updateFor(t,r);for(let a of t.effects)if(a.is(GN))i=new ku(i.source,1,a.value);else if(a.is(P6))i=new ku(i.source,0);else if(a.is(Yq))for(let o of a.value)o.source==i.source&&(i=o);return i}updateFor(t,n){return this.map(t.changes)}map(t){return this}touches(t){return t.changes.touchesRange(E2(t.state))}}class E3 extends ku{constructor(t,n,r,i,a,o){super(t,3,n),this.limit=r,this.result=i,this.from=a,this.to=o}hasResult(){return!0}updateFor(t,n){var r;if(!(n&3))return this.map(t.changes);let i=this.result;i.map&&!t.changes.empty&&(i=i.map(i,t.changes));let a=t.changes.mapPos(this.from),o=t.changes.mapPos(this.to,1),l=E2(t.state);if(l>o||!i||n&2&&(E2(t.startState)==this.from||l<this.limit))return new ku(this.source,n&4?1:0);let c=t.changes.mapPos(this.limit);return Gct(i.validFor,t.state,a,o)?new E3(this.source,this.explicit,c,i,a,o):i.update&&(i=i.update(i,a,o,new n4e(t.state,l,!1)))?new E3(this.source,this.explicit,c,i,i.from,(r=i.to)!==null&&r!==void 0?r:E2(t.state)):new ku(this.source,1,this.explicit)}map(t){return t.empty?this:(this.result.map?this.result.map(this.result,t):this.result)?new E3(this.source,this.explicit,t.mapPos(this.limit),this.result,t.mapPos(this.from),t.mapPos(this.to,1)):new ku(this.source,0)}touches(t){return t.changes.touchesRange(this.from,this.to)}}function Gct(e,t,n,r){if(!e)return!1;let i=t.sliceDoc(n,r);return typeof e=="function"?e(i,n,r,t):r4e(e,!0).test(i)}const Yq=ir.define({map(e,t){return e.map(n=>n.map(t))}}),ec=qo.define({create(){return QN.start()},update(e,t){return e.update(t)},provide:e=>[$q.from(e,t=>t.tooltip),Yt.contentAttributes.from(e,t=>t.attrs)]});function Jq(e,t){const n=t.completion.apply||t.completion.label;let r=e.state.field(ec).active.find(i=>i.source==t.source);return r instanceof E3?(typeof n=="string"?e.dispatch({...Pct(e.state,n,r.from,r.to),annotations:Gq.of(t.completion)}):n(e,t.completion,r.from,r.to),!0):!1}const Qct=Uct(ec,Jq);function T9(e,t="option"){return n=>{let r=n.state.field(ec,!1);if(!r||!r.open||r.open.disabled||Date.now()-r.open.timestamp<n.state.facet(ao).interactionDelay)return!1;let i=1,a;t=="page"&&(a=v5e(n,r.open.tooltip))&&(i=Math.max(2,Math.floor(a.dom.offsetHeight/a.dom.querySelector("li").offsetHeight)-1));let{length:o}=r.open.options,l=r.open.selected>-1?r.open.selected+i*(e?1:-1):e?0:o-1;return l<0?l=t=="page"?0:o-1:l>=o&&(l=t=="page"?o-1:0),n.dispatch({effects:Qq.of(l)}),!0}}const Yct=e=>{let t=e.state.field(ec,!1);return e.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<e.state.facet(ao).interactionDelay?!1:Jq(e,t.open.options[t.open.selected])},DM=e=>e.state.field(ec,!1)?(e.dispatch({effects:GN.of(!0)}),!0):!1,Jct=e=>{let t=e.state.field(ec,!1);return!t||!t.active.some(n=>n.state!=0)?!1:(e.dispatch({effects:P6.of(null)}),!0)};class Xct{constructor(t,n){this.active=t,this.context=n,this.time=Date.now(),this.updates=[],this.done=void 0}}const eut=50,tut=1e3,nut=ia.fromClass(class{constructor(e){this.view=e,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of e.state.field(ec).active)t.isPending&&this.startQuery(t)}update(e){let t=e.state.field(ec),n=e.state.facet(ao);if(!e.selectionSet&&!e.docChanged&&e.startState.field(ec)==t)return;let r=e.transactions.some(a=>{let o=s4e(a,n);return o&8||(a.selection||a.docChanged)&&!(o&3)});for(let a=0;a<this.running.length;a++){let o=this.running[a];if(r||o.context.abortOnDocChange&&e.docChanged||o.updates.length+e.transactions.length>eut&&Date.now()-o.time>tut){for(let l of o.context.abortListeners)try{l()}catch(c){rc(this.view.state,c)}o.context.abortListeners=null,this.running.splice(a--,1)}else o.updates.push(...e.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),e.transactions.some(a=>a.effects.some(o=>o.is(GN)))&&(this.pendingStart=!0);let i=this.pendingStart?50:n.activateOnTypingDelay;if(this.debounceUpdate=t.active.some(a=>a.isPending&&!this.running.some(o=>o.active.source==a.source))?setTimeout(()=>this.startUpdate(),i):-1,this.composing!=0)for(let a of e.transactions)a.isUserEvent("input.type")?this.composing=2:this.composing==2&&a.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:e}=this.view,t=e.field(ec);for(let n of t.active)n.isPending&&!this.running.some(r=>r.active.source==n.source)&&this.startQuery(n);this.running.length&&t.open&&t.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ao).updateSyncTime))}startQuery(e){let{state:t}=this.view,n=E2(t),r=new n4e(t,n,e.explicit,this.view),i=new Xct(e,r);this.running.push(i),Promise.resolve(e.source(r)).then(a=>{i.context.aborted||(i.done=a||null,this.scheduleAccept())},a=>{this.view.dispatch({effects:P6.of(null)}),rc(this.view.state,a)})}scheduleAccept(){this.running.every(e=>e.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ao).updateSyncTime))}accept(){var e;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let t=[],n=this.view.state.facet(ao),r=this.view.state.field(ec);for(let i=0;i<this.running.length;i++){let a=this.running[i];if(a.done===void 0)continue;if(this.running.splice(i--,1),a.done){let l=E2(a.updates.length?a.updates[0].startState:this.view.state),c=Math.min(l,a.done.from+(a.active.explicit?0:1)),u=new E3(a.active.source,a.active.explicit,c,a.done,a.done.from,(e=a.done.to)!==null&&e!==void 0?e:l);for(let d of a.updates)u=u.update(d,n);if(u.hasResult()){t.push(u);continue}}let o=r.active.find(l=>l.source==a.active.source);if(o&&o.isPending)if(a.done==null){let l=new ku(a.active.source,0);for(let c of a.updates)l=l.update(c,n);l.isPending||t.push(l)}else this.startQuery(o)}(t.length||r.open&&r.open.disabled)&&this.view.dispatch({effects:Yq.of(t)})}},{eventHandlers:{blur(e){let t=this.view.state.field(ec,!1);if(t&&t.tooltip&&this.view.state.facet(ao).closeOnBlur){let n=t.open&&v5e(this.view,t.open.tooltip);(!n||!n.dom.contains(e.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:P6.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:GN.of(!1)}),20),this.composing=0}}}),rut=typeof navigator=="object"&&/Win/.test(navigator.platform),sut=lg.highest(Yt.domEventHandlers({keydown(e,t){let n=t.state.field(ec,!1);if(!n||!n.open||n.open.disabled||n.open.selected<0||e.key.length>1||e.ctrlKey&&!(rut&&e.altKey)||e.metaKey)return!1;let r=n.open.options[n.open.selected],i=n.active.find(o=>o.source==r.source),a=r.completion.commitCharacters||i.result.commitCharacters;return a&&a.indexOf(e.key)>-1&&Jq(t,r),!1}})),i4e=Yt.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class iut{constructor(t,n,r,i){this.field=t,this.line=n,this.from=r,this.to=i}}class Xq{constructor(t,n,r){this.field=t,this.from=n,this.to=r}map(t){let n=t.mapPos(this.from,-1,To.TrackDel),r=t.mapPos(this.to,1,To.TrackDel);return n==null||r==null?null:new Xq(this.field,n,r)}}class eK{constructor(t,n){this.lines=t,this.fieldPositions=n}instantiate(t,n){let r=[],i=[n],a=t.doc.lineAt(n),o=/^\s*/.exec(a.text)[0];for(let c of this.lines){if(r.length){let u=o,d=/^\t*/.exec(c)[0].length;for(let f=0;f<d;f++)u+=t.facet(Q_);i.push(n+u.length-d),c=u+c.slice(d)}r.push(c),n+=c.length+1}let l=this.fieldPositions.map(c=>new Xq(c.field,i[c.line]+c.from,i[c.line]+c.to));return{text:r,ranges:l}}static parse(t){let n=[],r=[],i=[],a;for(let o of t.split(/\r\n?|\n/)){for(;a=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let l=a[1]?+a[1]:null,c=a[2]||a[3]||"",u=-1,d=c.replace(/\\[{}]/g,f=>f[1]);for(let f=0;f<n.length;f++)(l!=null?n[f].seq==l:d&&n[f].name==d)&&(u=f);if(u<0){let f=0;for(;f<n.length&&(l==null||n[f].seq!=null&&n[f].seq<l);)f++;n.splice(f,0,{seq:l,name:d}),u=f;for(let h of i)h.field>=u&&h.field++}for(let f of i)if(f.line==r.length&&f.from>a.index){let h=a[2]?3+(a[1]||"").length:2;f.from-=h,f.to-=h}i.push(new iut(u,r.length,a.index,a.index+d.length)),o=o.slice(0,a.index)+c+o.slice(a.index+a[0].length)}o=o.replace(/\\([{}])/g,(l,c,u)=>{for(let d of i)d.line==r.length&&d.from>u&&(d.from--,d.to--);return c}),r.push(o)}return new eK(r,i)}}let aut=$n.widget({widget:new class extends am{toDOM(){let e=document.createElement("span");return e.className="cm-snippetFieldPosition",e}ignoreEvent(){return!1}}}),out=$n.mark({class:"cm-snippetField"});class M4{constructor(t,n){this.ranges=t,this.active=n,this.deco=$n.set(t.map(r=>(r.from==r.to?aut:out).range(r.from,r.to)),!0)}map(t){let n=[];for(let r of this.ranges){let i=r.map(t);if(!i)return null;n.push(i)}return new M4(n,this.active)}selectionInsideField(t){return t.ranges.every(n=>this.ranges.some(r=>r.field==this.active&&r.from<=n.from&&r.to>=n.to))}}const Z7=ir.define({map(e,t){return e&&e.map(t)}}),lut=ir.define(),D6=qo.define({create(){return null},update(e,t){for(let n of t.effects){if(n.is(Z7))return n.value;if(n.is(lut)&&e)return new M4(e.ranges,n.value)}return e&&t.docChanged&&(e=e.map(t.changes)),e&&t.selection&&!e.selectionInsideField(t.selection)&&(e=null),e},provide:e=>Yt.decorations.from(e,t=>t?t.deco:$n.none)});function tK(e,t){return bt.create(e.filter(n=>n.field==t).map(n=>bt.range(n.from,n.to)))}function cut(e){let t=eK.parse(e);return(n,r,i,a)=>{let{text:o,ranges:l}=t.instantiate(n.state,i),{main:c}=n.state.selection,u={changes:{from:i,to:a==c.from?c.to:a,insert:ls.of(o)},scrollIntoView:!0,annotations:r?[Gq.of(r),ja.userEvent.of("input.complete")]:void 0};if(l.length&&(u.selection=tK(l,0)),l.some(d=>d.field>0)){let d=new M4(l,0),f=u.effects=[Z7.of(d)];n.state.field(D6,!1)===void 0&&f.push(ir.appendConfig.of([D6,hut,put,i4e]))}n.dispatch(n.state.update(u))}}function a4e(e){return({state:t,dispatch:n})=>{let r=t.field(D6,!1);if(!r||e<0&&r.active==0)return!1;let i=r.active+e,a=e>0&&!r.ranges.some(o=>o.field==i+e);return n(t.update({selection:tK(r.ranges,i),effects:Z7.of(a?null:new M4(r.ranges,i)),scrollIntoView:!0})),!0}}const uut=({state:e,dispatch:t})=>e.field(D6,!1)?(t(e.update({effects:Z7.of(null)})),!0):!1,dut=a4e(1),fut=a4e(-1),mut=[{key:"Tab",run:dut,shift:fut},{key:"Escape",run:uut}],dne=Jt.define({combine(e){return e.length?e[0]:mut}}),hut=lg.highest(H7.compute([dne],e=>e.facet(dne)));function gAt(e,t){return{...t,apply:cut(e)}}const put=Yt.domEventHandlers({mousedown(e,t){let n=t.state.field(D6,!1),r;if(!n||(r=t.posAtCoords({x:e.clientX,y:e.clientY}))==null)return!1;let i=n.ranges.find(a=>a.from<=r&&a.to>=r);return!i||i.field==n.active?!1:(t.dispatch({selection:tK(n.ranges,i.field),effects:Z7.of(n.ranges.some(a=>a.field>i.field)?new M4(n.ranges,i.field):null),scrollIntoView:!0}),!0)}}),L6={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},o2=ir.define({map(e,t){let n=t.mapPos(e,-1,To.TrackAfter);return n??void 0}}),nK=new class extends zp{};nK.startSide=1;nK.endSide=-1;const o4e=qo.define({create(){return Lr.empty},update(e,t){if(e=e.map(t.changes),t.selection){let n=t.state.doc.lineAt(t.selection.main.head);e=e.update({filter:r=>r>=n.from&&r<=n.to})}for(let n of t.effects)n.is(o2)&&(e=e.update({add:[nK.range(n.value,n.value+1)]}));return e}});function gut(){return[but,o4e]}const LM="()[]{}<>«»»«[]{}";function l4e(e){for(let t=0;t<LM.length;t+=2)if(LM.charCodeAt(t)==e)return LM.charAt(t+1);return wq(e<128?e:e+1)}function c4e(e,t){return e.languageDataAt("closeBrackets",t)[0]||L6}const xut=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),but=Yt.inputHandler.of((e,t,n,r)=>{if((xut?e.composing:e.compositionStarted)||e.state.readOnly)return!1;let i=e.state.selection.main;if(r.length>2||r.length==2&&wf(Xl(r,0))==1||t!=i.from||n!=i.to)return!1;let a=wut(e.state,r);return a?(e.dispatch(a),!0):!1}),yut=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=c4e(e,e.selection.main.head).brackets||L6.brackets,i=null,a=e.changeByRange(o=>{if(o.empty){let l=kut(e.doc,o.head);for(let c of r)if(c==l&&X_(e.doc,o.head)==l4e(Xl(c,0)))return{changes:{from:o.head-c.length,to:o.head+c.length},range:bt.cursor(o.head-c.length)}}return{range:i=o}});return i||t(e.update(a,{scrollIntoView:!0,userEvent:"delete.backward"})),!i},vut=[{key:"Backspace",run:yut}];function wut(e,t){let n=c4e(e,e.selection.main.head),r=n.brackets||L6.brackets;for(let i of r){let a=l4e(Xl(i,0));if(t==i)return a==i?Cut(e,i,r.indexOf(i+i+i)>-1,n):jut(e,i,a,n.before||L6.before);if(t==a&&u4e(e,e.selection.main.from))return Nut(e,i,a)}return null}function u4e(e,t){let n=!1;return e.field(o4e).between(0,e.doc.length,r=>{r==t&&(n=!0)}),n}function X_(e,t){let n=e.sliceString(t,t+2);return n.slice(0,wf(Xl(n,0)))}function kut(e,t){let n=e.sliceString(t-2,t);return wf(Xl(n,0))==n.length?n:n.slice(1)}function jut(e,t,n,r){let i=null,a=e.changeByRange(o=>{if(!o.empty)return{changes:[{insert:t,from:o.from},{insert:n,from:o.to}],effects:o2.of(o.to+t.length),range:bt.range(o.anchor+t.length,o.head+t.length)};let l=X_(e.doc,o.head);return!l||/\s/.test(l)||r.indexOf(l)>-1?{changes:{insert:t+n,from:o.head},effects:o2.of(o.head+t.length),range:bt.cursor(o.head+t.length)}:{range:i=o}});return i?null:e.update(a,{scrollIntoView:!0,userEvent:"input.type"})}function Nut(e,t,n){let r=null,i=e.changeByRange(a=>a.empty&&X_(e.doc,a.head)==n?{changes:{from:a.head,to:a.head+n.length,insert:n},range:bt.cursor(a.head+n.length)}:r={range:a});return r?null:e.update(i,{scrollIntoView:!0,userEvent:"input.type"})}function Cut(e,t,n,r){let i=r.stringPrefixes||L6.stringPrefixes,a=null,o=e.changeByRange(l=>{if(!l.empty)return{changes:[{insert:t,from:l.from},{insert:t,from:l.to}],effects:o2.of(l.to+t.length),range:bt.range(l.anchor+t.length,l.head+t.length)};let c=l.head,u=X_(e.doc,c),d;if(u==t){if(fne(e,c))return{changes:{insert:t+t,from:c},effects:o2.of(c+t.length),range:bt.cursor(c+t.length)};if(u4e(e,c)){let h=n&&e.sliceDoc(c,c+t.length*3)==t+t+t?t+t+t:t;return{changes:{from:c,to:c+h.length,insert:h},range:bt.cursor(c+h.length)}}}else{if(n&&e.sliceDoc(c-2*t.length,c)==t+t&&(d=mne(e,c-2*t.length,i))>-1&&fne(e,d))return{changes:{insert:t+t+t+t,from:c},effects:o2.of(c+t.length),range:bt.cursor(c+t.length)};if(e.charCategorizer(c)(u)!=yi.Word&&mne(e,c,i)>-1&&!Sut(e,c,t,i))return{changes:{insert:t+t,from:c},effects:o2.of(c+t.length),range:bt.cursor(c+t.length)}}return{range:a=l}});return a?null:e.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function fne(e,t){let n=Bo(e).resolveInner(t+1);return n.parent&&n.from==t}function Sut(e,t,n,r){let i=Bo(e).resolveInner(t,-1),a=r.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=e.sliceDoc(i.from,Math.min(i.to,i.from+n.length+a)),c=l.indexOf(n);if(!c||c>-1&&r.indexOf(l.slice(0,c))>-1){let d=i.firstChild;for(;d&&d.from==i.from&&d.to-d.from>n.length+c;){if(e.sliceDoc(d.to-n.length,d.to)==n)return!1;d=d.firstChild}return!0}let u=i.to==t&&i.parent;if(!u)break;i=u}return!1}function mne(e,t,n){let r=e.charCategorizer(t);if(r(e.sliceDoc(t-1,t))!=yi.Word)return t;for(let i of n){let a=t-i.length;if(e.sliceDoc(a,t)==i&&r(e.sliceDoc(a-1,a))!=yi.Word)return a}return-1}function _ut(e={}){return[sut,ec,ao.of(e),nut,Aut,i4e]}const d4e=[{key:"Ctrl-Space",run:DM},{mac:"Alt-`",run:DM},{mac:"Alt-i",run:DM},{key:"Escape",run:Jct},{key:"ArrowDown",run:T9(!0)},{key:"ArrowUp",run:T9(!1)},{key:"PageDown",run:T9(!0,"page")},{key:"PageUp",run:T9(!1,"page")},{key:"Enter",run:Yct}],Aut=lg.highest(H7.computeN([ao],e=>e.facet(ao).defaultKeymap?[d4e]:[])),Eut=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=sK(e.state,n.from);return r.line?Tut(e):r.block?Mut(e):!1};function rK(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}const Tut=rK(Put,0),Iut=rK(f4e,0),Mut=rK((e,t)=>f4e(e,t,Out(t)),0);function sK(e,t){let n=e.languageDataAt("commentTokens",t,1);return n.length?n[0]:{}}const oy=50;function Rut(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-oy,r),o=e.sliceDoc(i,i+oy),l=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,u=a.length-l;if(a.slice(u-t.length,u)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-l,margin:l&&1},close:{pos:i+c,margin:c&&1}};let d,f;i-r<=2*oy?d=f=e.sliceDoc(r,i):(d=e.sliceDoc(r,r+oy),f=e.sliceDoc(i-oy,i));let h=/^\s*/.exec(d)[0].length,g=/\s*$/.exec(f)[0].length,b=f.length-g-n.length;return d.slice(h,h+t.length)==t&&f.slice(b,b+n.length)==n?{open:{pos:r+h+t.length,margin:/\s/.test(d.charAt(h+t.length))?1:0},close:{pos:i-g-n.length,margin:/\s/.test(f.charAt(b-1))?1:0}}:null}function Out(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function f4e(e,t,n=t.selection.ranges){let r=n.map(a=>sK(t,a.from).block);if(!r.every(a=>a))return null;let i=n.map((a,o)=>Rut(t,r[o],a.from,a.to));if(e!=2&&!i.every(a=>a))return{changes:t.changes(n.map((a,o)=>i[o]?[]:[{from:a.from,insert:r[o].open+" "},{from:a.to,insert:" "+r[o].close}]))};if(e!=1&&i.some(a=>a)){let a=[];for(let o=0,l;o<i.length;o++)if(l=i[o]){let c=r[o],{open:u,close:d}=l;a.push({from:u.pos-c.open.length,to:u.pos+u.margin},{from:d.pos-d.margin,to:d.pos+c.close.length})}return{changes:a}}return null}function Put(e,t,n=t.selection.ranges){let r=[],i=-1;e:for(let{from:a,to:o}of n){let l=r.length,c=1e9,u;for(let d=a;d<=o;){let f=t.doc.lineAt(d);if(u==null&&(u=sK(t,f.from).line,!u))continue e;if(f.from>i&&(a==o||o>f.from)){i=f.from;let h=/^\s*/.exec(f.text)[0].length,g=h==f.length,b=f.text.slice(h,h+u.length)==u?h:-1;h<f.text.length&&h<c&&(c=h),r.push({line:f,comment:b,token:u,indent:h,empty:g,single:!1})}d=f.to+1}if(c<1e9)for(let d=l;d<r.length;d++)r[d].indent<r[d].line.text.length&&(r[d].indent=c);r.length==l+1&&(r[l].single=!0)}if(e!=2&&r.some(a=>a.comment<0&&(!a.empty||a.single))){let a=[];for(let{line:l,token:c,indent:u,empty:d,single:f}of r)(f||!d)&&a.push({from:l.from+u,insert:c+" "});let o=t.changes(a);return{changes:o,selection:t.selection.map(o,1)}}else if(e!=1&&r.some(a=>a.comment>=0)){let a=[];for(let{line:o,comment:l,token:c}of r)if(l>=0){let u=o.from+l,d=u+c.length;o.text[d-o.from]==" "&&d++,a.push({from:u,to:d})}return{changes:a}}return null}const qL=q1.define(),Dut=q1.define(),Lut=Jt.define(),m4e=Jt.define({combine(e){return im(e,{minDepth:100,newGroupDelay:500,joinToEvent:(t,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,n)=>(r,i)=>t(r,i)||n(r,i)})}}),h4e=qo.define({create(){return If.empty},update(e,t){let n=t.state.facet(m4e),r=t.annotation(qL);if(r){let c=sc.fromTransaction(t,r.selection),u=r.side,d=u==0?e.undone:e.done;return c?d=YN(d,d.length,n.minDepth,c):d=x4e(d,t.startState.selection),new If(u==0?r.rest:d,u==0?d:r.rest)}let i=t.annotation(Dut);if((i=="full"||i=="before")&&(e=e.isolate()),t.annotation(ja.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=sc.fromTransaction(t),o=t.annotation(ja.time),l=t.annotation(ja.userEvent);return a?e=e.addChanges(a,o,l,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,l,n.newGroupDelay)),(i=="full"||i=="after")&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(t=>t.toJSON()),undone:e.undone.map(t=>t.toJSON())}},fromJSON(e){return new If(e.done.map(sc.fromJSON),e.undone.map(sc.fromJSON))}});function $ut(e={}){return[h4e,m4e.of(e),Yt.domEventHandlers({beforeinput(t,n){let r=t.inputType=="historyUndo"?p4e:t.inputType=="historyRedo"?KL:null;return r?(t.preventDefault(),r(n)):!1}})]}function eA(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(h4e,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}const p4e=eA(0,!1),KL=eA(1,!1),Fut=eA(0,!0),zut=eA(1,!0);class sc{constructor(t,n,r,i,a){this.changes=t,this.effects=n,this.mapped=r,this.startSelection=i,this.selectionsAfter=a}setSelAfter(t){return new sc(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,n,r;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(i=>i.toJSON())}}static fromJSON(t){return new sc(t.changes&&Oa.fromJSON(t.changes),[],t.mapped&&Ff.fromJSON(t.mapped),t.startSelection&&bt.fromJSON(t.startSelection),t.selectionsAfter.map(bt.fromJSON))}static fromTransaction(t,n){let r=ju;for(let i of t.startState.facet(Lut)){let a=i(t);a.length&&(r=r.concat(a))}return!r.length&&t.changes.empty?null:new sc(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,ju)}static selection(t){return new sc(void 0,ju,void 0,void 0,t)}}function YN(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function But(e,t){let n=[],r=!1;return e.iterChangedRanges((i,a)=>n.push(i,a)),t.iterChangedRanges((i,a,o,l)=>{for(let c=0;c<n.length;){let u=n[c++],d=n[c++];l>=u&&o<=d&&(r=!0)}}),r}function Uut(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((n,r)=>n.empty!=t.ranges[r].empty).length===0}function g4e(e,t){return e.length?t.length?e.concat(t):e:t}const ju=[],qut=200;function x4e(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-qut));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),YN(e,e.length-1,1e9,n.setSelAfter(r)))}else return[sc.selection([t])]}function Kut(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function $M(e,t){if(!e.length)return e;let n=e.length,r=ju;for(;n;){let i=Hut(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let a=e.slice(0,n);return a[n-1]=i,a}else t=i.mapped,n--,r=i.selectionsAfter}return r.length?[sc.selection(r)]:ju}function Hut(e,t,n){let r=g4e(e.selectionsAfter.length?e.selectionsAfter.map(l=>l.map(t)):ju,n);if(!e.changes)return sc.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new sc(i,ir.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}const Vut=/^(input\.type|delete)($|\.)/;class If{constructor(t,n,r=0,i=void 0){this.done=t,this.undone=n,this.prevTime=r,this.prevUserEvent=i}isolate(){return this.prevTime?new If(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&t.changes&&(!r||Vut.test(r))&&(!l.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,But(l.changes,t.changes))||r=="input.type.compose")?o=YN(o,o.length-1,i.minDepth,new sc(t.changes.compose(l.changes),g4e(ir.mapEffects(t.effects,l.changes),l.effects),l.mapped,l.startSelection,ju)):o=YN(o,o.length,i.minDepth,t),new If(o,ju,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:ju;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&Uut(a[a.length-1],t)?this:new If(x4e(this.done,t),this.undone,n,r)}addMapping(t){return new If($M(this.done,t),$M(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,n,r){let i=t==0?this.done:this.undone;if(i.length==0)return null;let a=i[i.length-1],o=a.selectionsAfter[0]||(a.startSelection?a.startSelection.map(a.changes.invertedDesc,1):n.selection);if(r&&a.selectionsAfter.length)return n.update({selection:a.selectionsAfter[a.selectionsAfter.length-1],annotations:qL.of({side:t,rest:Kut(i),selection:o}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(a.changes){let l=i.length==1?ju:i.slice(0,i.length-1);return a.mapped&&(l=$M(l,a.mapped)),n.update({changes:a.changes,selection:a.startSelection,effects:a.effects,annotations:qL.of({side:t,rest:l,selection:o}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}If.empty=new If(ju,ju);const Wut=[{key:"Mod-z",run:p4e,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:KL,preventDefault:!0},{linux:"Ctrl-Shift-z",run:KL,preventDefault:!0},{key:"Mod-u",run:Fut,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:zut,preventDefault:!0}];function R4(e,t){return bt.create(e.ranges.map(t),e.mainIndex)}function Ud(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function qd({state:e,dispatch:t},n){let r=R4(e.selection,n);return r.eq(e.selection,!0)?!1:(t(Ud(e,r)),!0)}function tA(e,t){return bt.cursor(t?e.to:e.from)}function b4e(e,t){return qd(e,n=>n.empty?e.moveByChar(n,t):tA(n,t))}function dl(e){return e.textDirectionAt(e.state.selection.main.head)==Hs.LTR}const y4e=e=>b4e(e,!dl(e)),v4e=e=>b4e(e,dl(e));function w4e(e,t){return qd(e,n=>n.empty?e.moveByGroup(n,t):tA(n,t))}const Zut=e=>w4e(e,!dl(e)),Gut=e=>w4e(e,dl(e));function Qut(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function nA(e,t,n){let r=Bo(e).resolveInner(t.head),i=n?Or.closedBy:Or.openedBy;for(let c=t.head;;){let u=n?r.childAfter(c):r.childBefore(c);if(!u)break;Qut(e,u,i)?r=u:c=n?u.to:u.from}let a=r.type.prop(i),o,l;return a&&(o=n?Tf(e,r.from,1):Tf(e,r.to,-1))&&o.matched?l=n?o.end.to:o.end.from:l=n?r.to:r.from,bt.cursor(l,n?-1:1)}const Yut=e=>qd(e,t=>nA(e.state,t,!dl(e))),Jut=e=>qd(e,t=>nA(e.state,t,dl(e)));function k4e(e,t){return qd(e,n=>{if(!n.empty)return tA(n,t);let r=e.moveVertically(n,t);return r.head!=n.head?r:e.moveToLineBoundary(n,t)})}const j4e=e=>k4e(e,!1),N4e=e=>k4e(e,!0);function C4e(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let a of e.state.facet(Yt.scrollMargins)){let o=a(e);o!=null&&o.top&&(n=Math.max(o==null?void 0:o.top,n)),o!=null&&o.bottom&&(r=Math.max(o==null?void 0:o.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function S4e(e,t){let n=C4e(e),{state:r}=e,i=R4(r.selection,o=>o.empty?e.moveVertically(o,t,n.height):tA(o,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let o=e.coordsAtPos(r.selection.main.head),l=e.scrollDOM.getBoundingClientRect(),c=l.top+n.marginTop,u=l.bottom-n.marginBottom;o&&o.top>c&&o.bottom<u&&(a=Yt.scrollIntoView(i.main.head,{y:"start",yMargin:o.top-c}))}return e.dispatch(Ud(r,i),{effects:a}),!0}const hne=e=>S4e(e,!1),HL=e=>S4e(e,!0);function cg(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let a=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;a&&t.head!=r.from+a&&(i=bt.cursor(r.from+a))}return i}const Xut=e=>qd(e,t=>cg(e,t,!0)),edt=e=>qd(e,t=>cg(e,t,!1)),tdt=e=>qd(e,t=>cg(e,t,!dl(e))),ndt=e=>qd(e,t=>cg(e,t,dl(e))),rdt=e=>qd(e,t=>bt.cursor(e.lineBlockAt(t.head).from,1)),sdt=e=>qd(e,t=>bt.cursor(e.lineBlockAt(t.head).to,-1));function idt(e,t,n){let r=!1,i=R4(e.selection,a=>{let o=Tf(e,a.head,-1)||Tf(e,a.head,1)||a.head>0&&Tf(e,a.head-1,1)||a.head<e.doc.length&&Tf(e,a.head+1,-1);if(!o||!o.end)return a;r=!0;let l=o.start.from==a.head?o.end.to:o.end.from;return bt.cursor(l)});return r?(t(Ud(e,i)),!0):!1}const adt=({state:e,dispatch:t})=>idt(e,t);function Fu(e,t){let n=R4(e.state.selection,r=>{let i=t(r);return bt.range(r.anchor,i.head,i.goalColumn,i.bidiLevel||void 0,i.assoc)});return n.eq(e.state.selection)?!1:(e.dispatch(Ud(e.state,n)),!0)}function _4e(e,t){return Fu(e,n=>e.moveByChar(n,t))}const A4e=e=>_4e(e,!dl(e)),E4e=e=>_4e(e,dl(e));function T4e(e,t){return Fu(e,n=>e.moveByGroup(n,t))}const odt=e=>T4e(e,!dl(e)),ldt=e=>T4e(e,dl(e)),cdt=e=>Fu(e,t=>nA(e.state,t,!dl(e))),udt=e=>Fu(e,t=>nA(e.state,t,dl(e)));function I4e(e,t){return Fu(e,n=>e.moveVertically(n,t))}const M4e=e=>I4e(e,!1),R4e=e=>I4e(e,!0);function O4e(e,t){return Fu(e,n=>e.moveVertically(n,t,C4e(e).height))}const pne=e=>O4e(e,!1),gne=e=>O4e(e,!0),ddt=e=>Fu(e,t=>cg(e,t,!0)),fdt=e=>Fu(e,t=>cg(e,t,!1)),mdt=e=>Fu(e,t=>cg(e,t,!dl(e))),hdt=e=>Fu(e,t=>cg(e,t,dl(e))),pdt=e=>Fu(e,t=>bt.cursor(e.lineBlockAt(t.head).from)),gdt=e=>Fu(e,t=>bt.cursor(e.lineBlockAt(t.head).to)),xne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:0})),!0),bne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:e.doc.length})),!0),yne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:e.selection.main.anchor,head:0})),!0),vne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),xdt=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),bdt=({state:e,dispatch:t})=>{let n=rA(e).map(({from:r,to:i})=>bt.range(r,Math.min(i+1,e.doc.length)));return t(e.update({selection:bt.create(n),userEvent:"select"})),!0},ydt=({state:e,dispatch:t})=>{let n=R4(e.selection,r=>{let i=Bo(e),a=i.resolveStack(r.from,1);if(r.empty){let o=i.resolveStack(r.from,-1);o.node.from>=a.node.from&&o.node.to<=a.node.to&&(a=o)}for(let o=a;o;o=o.next){let{node:l}=o;if((l.from<r.from&&l.to>=r.to||l.to>r.to&&l.from<=r.from)&&o.next)return bt.range(l.to,l.from)}return r});return n.eq(e.selection)?!1:(t(Ud(e,n)),!0)};function P4e(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let a of n.selection.ranges){let o=n.doc.lineAt(a.head);if(t?o.to<e.state.doc.length:o.from>0)for(let l=a;;){let c=e.moveVertically(l,t);if(c.head<o.from||c.head>o.to){i.some(u=>u.head==c.head)||i.push(c);break}else{if(c.head==l.head)break;l=c}}}return i.length==r.ranges.length?!1:(e.dispatch(Ud(n,bt.create(i,i.length-1))),!0)}const vdt=e=>P4e(e,!1),wdt=e=>P4e(e,!0),kdt=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=bt.create([n.main]):n.main.empty||(r=bt.create([bt.cursor(n.main.head)])),r?(t(Ud(e,r)),!0):!1};function G7(e,t){if(e.state.readOnly)return!1;let n="delete.selection",{state:r}=e,i=r.changeByRange(a=>{let{from:o,to:l}=a;if(o==l){let c=t(a);c<o?(n="delete.backward",c=I9(e,c,!1)):c>o&&(n="delete.forward",c=I9(e,c,!0)),o=Math.min(o,c),l=Math.max(l,c)}else o=I9(e,o,!1),l=I9(e,l,!0);return o==l?{range:a}:{changes:{from:o,to:l},range:bt.cursor(o,o<a.head?-1:1)}});return i.changes.empty?!1:(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?Yt.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function I9(e,t,n){if(e instanceof Yt)for(let r of e.state.facet(Yt.atomicRanges).map(i=>i(e)))r.between(t,t,(i,a)=>{i<t&&a>t&&(t=n?a:i)});return t}const D4e=(e,t,n)=>G7(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),l,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,i-o.from))){if(l[l.length-1]==" ")return i-1;let u=I4(l,a.tabSize),d=u%h0(a)||h0(a);for(let f=0;f<d&&l[l.length-1-f]==" ";f++)i--;c=i}else c=lo(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=lo(o.text,c-o.from,!1,!1)+o.from);return c}),VL=e=>D4e(e,!1,!0),L4e=e=>D4e(e,!0,!1),$4e=(e,t)=>G7(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let l=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let c=lo(a.text,r-a.from,t)+a.from,u=a.text.slice(Math.min(r,c)-a.from,Math.max(r,c)-a.from),d=o(u);if(l!=null&&d!=l)break;(u!=" "||r!=n.head)&&(l=d),r=c}return r}),F4e=e=>$4e(e,!1),jdt=e=>$4e(e,!0),Ndt=e=>G7(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Cdt=e=>G7(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),Sdt=e=>G7(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),_dt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:ls.of(["",""])},range:bt.cursor(r.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},Adt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>{if(!r.empty||r.from==0||r.from==e.doc.length)return{range:r};let i=r.from,a=e.doc.lineAt(i),o=i==a.from?i-1:lo(a.text,i-a.from,!1)+a.from,l=i==a.to?i+1:lo(a.text,i-a.from,!0)+a.from;return{changes:{from:o,to:l,insert:e.doc.slice(i,l).append(e.doc.slice(o,i))},range:bt.cursor(l)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function rA(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let o=t[t.length-1];o.to=a.to,o.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function z4e(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let a of rA(e)){if(n?a.to==e.doc.length:a.from==0)continue;let o=e.doc.lineAt(n?a.to+1:a.from-1),l=o.length+1;if(n){r.push({from:a.to,to:o.to},{from:a.from,insert:o.text+e.lineBreak});for(let c of a.ranges)i.push(bt.range(Math.min(e.doc.length,c.anchor+l),Math.min(e.doc.length,c.head+l)))}else{r.push({from:o.from,to:a.from},{from:a.to,insert:e.lineBreak+o.text});for(let c of a.ranges)i.push(bt.range(c.anchor-l,c.head-l))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:bt.create(i,e.selection.mainIndex),userEvent:"move.line"})),!0):!1}const Edt=({state:e,dispatch:t})=>z4e(e,t,!1),Tdt=({state:e,dispatch:t})=>z4e(e,t,!0);function B4e(e,t,n){if(e.readOnly)return!1;let r=[];for(let a of rA(e))n?r.push({from:a.from,insert:e.doc.slice(a.from,a.to)+e.lineBreak}):r.push({from:a.to,insert:e.lineBreak+e.doc.slice(a.from,a.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Idt=({state:e,dispatch:t})=>B4e(e,t,!1),Mdt=({state:e,dispatch:t})=>B4e(e,t,!0),Rdt=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(rA(t).map(({from:i,to:a})=>(i>0?i--:a<t.doc.length&&a++,{from:i,to:a}))),r=R4(t.selection,i=>{let a;if(e.lineWrapping){let o=e.lineBlockAt(i.head),l=e.coordsAtPos(i.head,i.assoc||1);l&&(a=o.bottom+e.documentTop-l.bottom+e.defaultLineHeight/2)}return e.moveVertically(i,!0,a)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Odt(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=Bo(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(Or.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}const wne=U4e(!1),Pdt=U4e(!0);function U4e(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(i=>{let{from:a,to:o}=i,l=t.doc.lineAt(a),c=!e&&a==o&&Odt(t,a);e&&(a=o=(o<=l.to?l:t.doc.lineAt(o)).to);let u=new Y_(t,{simulateBreak:a,simulateDoubleBreak:!!c}),d=Kq(u,a);for(d==null&&(d=I4(/^\s*/.exec(t.doc.lineAt(a).text)[0],t.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;c?{from:a,to:o}=c:a>l.from&&a<l.from+100&&!/\S/.test(l.text.slice(0,a))&&(a=l.from);let f=["",R6(t,d)];return c&&f.push(R6(t,u.lineIndent(l.from,-1))),{changes:{from:a,to:o,insert:ls.of(f)},range:bt.cursor(a+1+f[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function iK(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let o=r.from;o<=r.to;){let l=e.doc.lineAt(o);l.number>n&&(r.empty||r.to>l.from)&&(t(l,i,r),n=l.number),o=l.to+1}let a=e.changes(i);return{changes:i,range:bt.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}const Ddt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new Y_(e,{overrideIndentation:a=>{let o=n[a];return o??-1}}),i=iK(e,(a,o,l)=>{let c=Kq(r,a.from);if(c==null)return;/\S/.test(a.text)||(c=0);let u=/^\s*/.exec(a.text)[0],d=R6(e,c);(u!=d||l.from<a.from+u.length)&&(n[a.from]=c,o.push({from:a.from,to:a.from+u.length,insert:d}))});return i.changes.empty||t(e.update(i,{userEvent:"indent"})),!0},q4e=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(iK(e,(n,r)=>{r.push({from:n.from,insert:e.facet(Q_)})}),{userEvent:"input.indent"})),!0),K4e=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(iK(e,(n,r)=>{let i=/^\s*/.exec(n.text)[0];if(!i)return;let a=I4(i,e.tabSize),o=0,l=R6(e,Math.max(0,a-h0(e)));for(;o<i.length&&o<l.length&&i.charCodeAt(o)==l.charCodeAt(o);)o++;r.push({from:n.from+o,to:n.from+i.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Ldt=e=>(e.setTabFocusMode(),!0),$dt=[{key:"Ctrl-b",run:y4e,shift:A4e,preventDefault:!0},{key:"Ctrl-f",run:v4e,shift:E4e},{key:"Ctrl-p",run:j4e,shift:M4e},{key:"Ctrl-n",run:N4e,shift:R4e},{key:"Ctrl-a",run:rdt,shift:pdt},{key:"Ctrl-e",run:sdt,shift:gdt},{key:"Ctrl-d",run:L4e},{key:"Ctrl-h",run:VL},{key:"Ctrl-k",run:Ndt},{key:"Ctrl-Alt-h",run:F4e},{key:"Ctrl-o",run:_dt},{key:"Ctrl-t",run:Adt},{key:"Ctrl-v",run:HL}],Fdt=[{key:"ArrowLeft",run:y4e,shift:A4e,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Zut,shift:odt,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:tdt,shift:mdt,preventDefault:!0},{key:"ArrowRight",run:v4e,shift:E4e,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Gut,shift:ldt,preventDefault:!0},{mac:"Cmd-ArrowRight",run:ndt,shift:hdt,preventDefault:!0},{key:"ArrowUp",run:j4e,shift:M4e,preventDefault:!0},{mac:"Cmd-ArrowUp",run:xne,shift:yne},{mac:"Ctrl-ArrowUp",run:hne,shift:pne},{key:"ArrowDown",run:N4e,shift:R4e,preventDefault:!0},{mac:"Cmd-ArrowDown",run:bne,shift:vne},{mac:"Ctrl-ArrowDown",run:HL,shift:gne},{key:"PageUp",run:hne,shift:pne},{key:"PageDown",run:HL,shift:gne},{key:"Home",run:edt,shift:fdt,preventDefault:!0},{key:"Mod-Home",run:xne,shift:yne},{key:"End",run:Xut,shift:ddt,preventDefault:!0},{key:"Mod-End",run:bne,shift:vne},{key:"Enter",run:wne,shift:wne},{key:"Mod-a",run:xdt},{key:"Backspace",run:VL,shift:VL,preventDefault:!0},{key:"Delete",run:L4e,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:F4e,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:jdt,preventDefault:!0},{mac:"Mod-Backspace",run:Cdt,preventDefault:!0},{mac:"Mod-Delete",run:Sdt,preventDefault:!0}].concat($dt.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),zdt=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Yut,shift:cdt},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Jut,shift:udt},{key:"Alt-ArrowUp",run:Edt},{key:"Shift-Alt-ArrowUp",run:Idt},{key:"Alt-ArrowDown",run:Tdt},{key:"Shift-Alt-ArrowDown",run:Mdt},{key:"Mod-Alt-ArrowUp",run:vdt},{key:"Mod-Alt-ArrowDown",run:wdt},{key:"Escape",run:kdt},{key:"Mod-Enter",run:Pdt},{key:"Alt-l",mac:"Ctrl-l",run:bdt},{key:"Mod-i",run:ydt,preventDefault:!0},{key:"Mod-[",run:K4e},{key:"Mod-]",run:q4e},{key:"Mod-Alt-\\",run:Ddt},{key:"Shift-Mod-k",run:Rdt},{key:"Shift-Mod-\\",run:adt},{key:"Mod-/",run:Eut},{key:"Alt-A",run:Iut},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Ldt}].concat(Fdt),Bdt={key:"Tab",run:q4e,shift:K4e};function Udt(e,t,n,r){const i=Wf(bi),a=Mc(C0e),o=se.useRef(null),{lexicalNode:l}=eL(),c=se.useRef(!1),u=se.useRef(!1),d=se.useCallback(()=>{a({editorType:t,rootNode:l,editorRef:o.current})},[t,l,a]),f=se.useCallback(h=>{var g,b,v,j,k,w;if(h.key==="ArrowDown"){const N=(b=(g=o.current)==null?void 0:g.getCodemirror())==null?void 0:b.state;if(N){const C=N.doc.length,A=N.selection.ranges[0].to;C===A&&(c.current?(i==null||i.update(()=>{var _,E;const T=$f(e);T.getNextSibling()?((E=(_=o.current)==null?void 0:_.getCodemirror())==null||E.contentDOM.blur(),T.selectNext()):T.insertAfter(Zs())}),c.current=!1):c.current=!0)}}else if(h.key==="ArrowUp"){const N=(j=(v=o.current)==null?void 0:v.getCodemirror())==null?void 0:j.state;N&&N.selection.ranges[0].from===0&&(u.current?(i==null||i.update(()=>{var A,_;const E=$f(e);E.getPreviousSibling()&&((_=(A=o.current)==null?void 0:A.getCodemirror())==null||_.contentDOM.blur(),E.selectPrevious())}),u.current=!1):u.current=!0)}else if(h.key==="Enter")h.stopPropagation();else if(h.key==="Backspace"||h.key==="Delete"){const N=(w=(k=o.current)==null?void 0:k.getCodemirror())==null?void 0:w.state;(N==null?void 0:N.doc.length)===0&&(i==null||i.update(()=>{$f(e).remove()}))}},[i,e]);return se.useEffect(()=>{const h=o.current;return setTimeout(()=>{var g,b;(g=h==null?void 0:h.getCodemirror())==null||g.contentDOM.addEventListener("focus",d),(b=h==null?void 0:h.getCodemirror())==null||b.contentDOM.addEventListener("keydown",f)},300),()=>{var g,b;(g=h==null?void 0:h.getCodemirror())==null||g.contentDOM.removeEventListener("focus",d),(b=h==null?void 0:h.getCodemirror())==null||b.contentDOM.removeEventListener("keydown",f)}},[o,d,f,n]),se.useEffect(()=>{r.subscribe(()=>{var h,g;(g=(h=o.current)==null?void 0:h.getCodemirror())==null||g.focus(),d()})},[r,o,e,d]),o}function Ct(e){return new Ult(Vq.define(e))}function wh(e){return mt(()=>import("./index-Dy1tUMNo.js"),__vite__mapDeps([0,1])).then(t=>t.sql({dialect:t[e]}))}const qdt=[ot.of({name:"C",extensions:["c","h","ino"],load(){return mt(()=>import("./index-MQzptRcp.js"),__vite__mapDeps([2,1])).then(e=>e.cpp())}}),ot.of({name:"C++",alias:["cpp"],extensions:["cpp","c++","cc","cxx","hpp","h++","hh","hxx"],load(){return mt(()=>import("./index-MQzptRcp.js"),__vite__mapDeps([2,1])).then(e=>e.cpp())}}),ot.of({name:"CQL",alias:["cassandra"],extensions:["cql"],load(){return wh("Cassandra")}}),ot.of({name:"CSS",extensions:["css"],load(){return mt(()=>import("./index-BfplXq-F.js"),__vite__mapDeps([3,1])).then(e=>e.css())}}),ot.of({name:"Go",extensions:["go"],load(){return mt(()=>import("./index-BZEL7Egt.js"),__vite__mapDeps([4,1])).then(e=>e.go())}}),ot.of({name:"HTML",alias:["xhtml"],extensions:["html","htm","handlebars","hbs"],load(){return mt(()=>import("./index-BxRgZJLt.js"),__vite__mapDeps([5,1,3,6])).then(e=>e.html())}}),ot.of({name:"Java",extensions:["java"],load(){return mt(()=>import("./index-DFW_78Yw.js"),__vite__mapDeps([7,1])).then(e=>e.java())}}),ot.of({name:"JavaScript",alias:["ecmascript","js","node"],extensions:["js","mjs","cjs"],load(){return mt(()=>import("./index-CG72w6I6.js"),__vite__mapDeps([6,1])).then(e=>e.javascript())}}),ot.of({name:"Jinja",extensions:["j2","jinja","jinja2"],load(){return mt(()=>import("./index-BltRQQBc.js"),__vite__mapDeps([8,5,1,3,6])).then(e=>e.jinja())}}),ot.of({name:"JSON",alias:["json5"],extensions:["json","map"],load(){return mt(()=>import("./index-yRsrqfY8.js"),__vite__mapDeps([9,1])).then(e=>e.json())}}),ot.of({name:"JSX",extensions:["jsx"],load(){return mt(()=>import("./index-CG72w6I6.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({jsx:!0}))}}),ot.of({name:"LESS",extensions:["less"],load(){return mt(()=>import("./index-nbjx7VzW.js"),__vite__mapDeps([10,3,1])).then(e=>e.less())}}),ot.of({name:"Liquid",extensions:["liquid"],load(){return mt(()=>import("./index-DUkFTf41.js"),__vite__mapDeps([11,5,1,3,6])).then(e=>e.liquid())}}),ot.of({name:"MariaDB SQL",load(){return wh("MariaSQL")}}),ot.of({name:"Markdown",extensions:["md","markdown","mkd"],load(){return mt(()=>import("./index-gUYia7os.js"),__vite__mapDeps([12,5,1,3,6])).then(e=>e.markdown())}}),ot.of({name:"MS SQL",load(){return wh("MSSQL")}}),ot.of({name:"MySQL",load(){return wh("MySQL")}}),ot.of({name:"PHP",extensions:["php","php3","php4","php5","php7","phtml"],load(){return mt(()=>import("./index-CRpHAVOZ.js"),__vite__mapDeps([13,1,5,3,6])).then(e=>e.php())}}),ot.of({name:"PLSQL",extensions:["pls"],load(){return wh("PLSQL")}}),ot.of({name:"PostgreSQL",load(){return wh("PostgreSQL")}}),ot.of({name:"Python",extensions:["BUILD","bzl","py","pyw"],filename:/^(BUCK|BUILD)$/,load(){return mt(()=>import("./index-kgevp2HG.js"),__vite__mapDeps([14,1])).then(e=>e.python())}}),ot.of({name:"Rust",extensions:["rs"],load(){return mt(()=>import("./index-BmsLGvk8.js"),__vite__mapDeps([15,1])).then(e=>e.rust())}}),ot.of({name:"Sass",extensions:["sass"],load(){return mt(()=>import("./index-CFbFr4ex.js"),__vite__mapDeps([16,1,3])).then(e=>e.sass({indented:!0}))}}),ot.of({name:"SCSS",extensions:["scss"],load(){return mt(()=>import("./index-CFbFr4ex.js"),__vite__mapDeps([16,1,3])).then(e=>e.sass())}}),ot.of({name:"SQL",extensions:["sql"],load(){return wh("StandardSQL")}}),ot.of({name:"SQLite",load(){return wh("SQLite")}}),ot.of({name:"TSX",extensions:["tsx"],load(){return mt(()=>import("./index-CG72w6I6.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({jsx:!0,typescript:!0}))}}),ot.of({name:"TypeScript",alias:["ts"],extensions:["ts","mts","cts"],load(){return mt(()=>import("./index-CG72w6I6.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({typescript:!0}))}}),ot.of({name:"WebAssembly",extensions:["wat","wast"],load(){return mt(()=>import("./index-C1tHyH8k.js"),__vite__mapDeps([17,1])).then(e=>e.wast())}}),ot.of({name:"XML",alias:["rss","wsdl","xsd"],extensions:["xml","xsl","xsd","svg"],load(){return mt(()=>import("./index-B8gsfmlA.js"),__vite__mapDeps([18,1])).then(e=>e.xml())}}),ot.of({name:"YAML",alias:["yml"],extensions:["yaml","yml"],load(){return mt(()=>import("./index-DCtxYhhT.js"),__vite__mapDeps([19,1])).then(e=>e.yaml())}}),ot.of({name:"APL",extensions:["dyalog","apl"],load(){return mt(()=>import("./apl-B4CMkyY2.js"),[]).then(e=>Ct(e.apl))}}),ot.of({name:"PGP",alias:["asciiarmor"],extensions:["asc","pgp","sig"],load(){return mt(()=>import("./asciiarmor-Df11BRmG.js"),[]).then(e=>Ct(e.asciiArmor))}}),ot.of({name:"ASN.1",extensions:["asn","asn1"],load(){return mt(()=>import("./asn1-EdZsLKOL.js"),[]).then(e=>Ct(e.asn1({})))}}),ot.of({name:"Asterisk",filename:/^extensions\.conf$/i,load(){return mt(()=>import("./asterisk-B-8jnY81.js"),[]).then(e=>Ct(e.asterisk))}}),ot.of({name:"Brainfuck",extensions:["b","bf"],load(){return mt(()=>import("./brainfuck-C4LP7Hcl.js"),[]).then(e=>Ct(e.brainfuck))}}),ot.of({name:"Cobol",extensions:["cob","cpy"],load(){return mt(()=>import("./cobol-CWcv1MsR.js"),[]).then(e=>Ct(e.cobol))}}),ot.of({name:"C#",alias:["csharp","cs"],extensions:["cs"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.csharp))}}),ot.of({name:"Clojure",extensions:["clj","cljc","cljx"],load(){return mt(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>Ct(e.clojure))}}),ot.of({name:"ClojureScript",extensions:["cljs"],load(){return mt(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>Ct(e.clojure))}}),ot.of({name:"Closure Stylesheets (GSS)",extensions:["gss"],load(){return mt(()=>import("./css-BnMrqG3P.js"),[]).then(e=>Ct(e.gss))}}),ot.of({name:"CMake",extensions:["cmake","cmake.in"],filename:/^CMakeLists\.txt$/,load(){return mt(()=>import("./cmake-BQqOBYOt.js"),[]).then(e=>Ct(e.cmake))}}),ot.of({name:"CoffeeScript",alias:["coffee","coffee-script"],extensions:["coffee"],load(){return mt(()=>import("./coffeescript-S37ZYGWr.js"),[]).then(e=>Ct(e.coffeeScript))}}),ot.of({name:"Common Lisp",alias:["lisp"],extensions:["cl","lisp","el"],load(){return mt(()=>import("./commonlisp-DBKNyK5s.js"),[]).then(e=>Ct(e.commonLisp))}}),ot.of({name:"Cypher",extensions:["cyp","cypher"],load(){return mt(()=>import("./cypher-C_CwsFkJ.js"),[]).then(e=>Ct(e.cypher))}}),ot.of({name:"Cython",extensions:["pyx","pxd","pxi"],load(){return mt(()=>import("./python-BuPzkPfP.js"),[]).then(e=>Ct(e.cython))}}),ot.of({name:"Crystal",extensions:["cr"],load(){return mt(()=>import("./crystal-SjHAIU92.js"),[]).then(e=>Ct(e.crystal))}}),ot.of({name:"D",extensions:["d"],load(){return mt(()=>import("./d-pRatUO7H.js"),[]).then(e=>Ct(e.d))}}),ot.of({name:"Dart",extensions:["dart"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.dart))}}),ot.of({name:"diff",extensions:["diff","patch"],load(){return mt(()=>import("./diff-DbItnlRl.js"),[]).then(e=>Ct(e.diff))}}),ot.of({name:"Dockerfile",filename:/^Dockerfile$/,load(){return mt(()=>import("./dockerfile-BKs6k2Af.js"),__vite__mapDeps([20,21])).then(e=>Ct(e.dockerFile))}}),ot.of({name:"DTD",extensions:["dtd"],load(){return mt(()=>import("./dtd-DF_7sFjM.js"),[]).then(e=>Ct(e.dtd))}}),ot.of({name:"Dylan",extensions:["dylan","dyl","intr"],load(){return mt(()=>import("./dylan-DwRh75JA.js"),[]).then(e=>Ct(e.dylan))}}),ot.of({name:"EBNF",load(){return mt(()=>import("./ebnf-CDyGwa7X.js"),[]).then(e=>Ct(e.ebnf))}}),ot.of({name:"ECL",extensions:["ecl"],load(){return mt(()=>import("./ecl-Cabwm37j.js"),[]).then(e=>Ct(e.ecl))}}),ot.of({name:"edn",extensions:["edn"],load(){return mt(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>Ct(e.clojure))}}),ot.of({name:"Eiffel",extensions:["e"],load(){return mt(()=>import("./eiffel-CnydiIhH.js"),[]).then(e=>Ct(e.eiffel))}}),ot.of({name:"Elm",extensions:["elm"],load(){return mt(()=>import("./elm-vLlmbW-K.js"),[]).then(e=>Ct(e.elm))}}),ot.of({name:"Erlang",extensions:["erl"],load(){return mt(()=>import("./erlang-BNw1qcRV.js"),[]).then(e=>Ct(e.erlang))}}),ot.of({name:"Esper",load(){return mt(()=>import("./sql-D0XecflT.js"),[]).then(e=>Ct(e.esper))}}),ot.of({name:"Factor",extensions:["factor"],load(){return mt(()=>import("./factor-kuTfRLto.js"),__vite__mapDeps([22,21])).then(e=>Ct(e.factor))}}),ot.of({name:"FCL",load(){return mt(()=>import("./fcl-Kvtd6kyn.js"),[]).then(e=>Ct(e.fcl))}}),ot.of({name:"Forth",extensions:["forth","fth","4th"],load(){return mt(()=>import("./forth-Ffai-XNe.js"),[]).then(e=>Ct(e.forth))}}),ot.of({name:"Fortran",extensions:["f","for","f77","f90","f95"],load(){return mt(()=>import("./fortran-DYz_wnZ1.js"),[]).then(e=>Ct(e.fortran))}}),ot.of({name:"F#",alias:["fsharp"],extensions:["fs"],load(){return mt(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>Ct(e.fSharp))}}),ot.of({name:"Gas",extensions:["s"],load(){return mt(()=>import("./gas-Bneqetm1.js"),[]).then(e=>Ct(e.gas))}}),ot.of({name:"Gherkin",extensions:["feature"],load(){return mt(()=>import("./gherkin-heZmZLOM.js"),[]).then(e=>Ct(e.gherkin))}}),ot.of({name:"Groovy",extensions:["groovy","gradle"],filename:/^Jenkinsfile$/,load(){return mt(()=>import("./groovy-D9Dt4D0W.js"),[]).then(e=>Ct(e.groovy))}}),ot.of({name:"Haskell",extensions:["hs"],load(){return mt(()=>import("./haskell-Cw1EW3IL.js"),[]).then(e=>Ct(e.haskell))}}),ot.of({name:"Haxe",extensions:["hx"],load(){return mt(()=>import("./haxe-H-WmDvRZ.js"),[]).then(e=>Ct(e.haxe))}}),ot.of({name:"HXML",extensions:["hxml"],load(){return mt(()=>import("./haxe-H-WmDvRZ.js"),[]).then(e=>Ct(e.hxml))}}),ot.of({name:"HTTP",load(){return mt(()=>import("./http-DBlCnlav.js"),[]).then(e=>Ct(e.http))}}),ot.of({name:"IDL",extensions:["pro"],load(){return mt(()=>import("./idl-BEugSyMb.js"),[]).then(e=>Ct(e.idl))}}),ot.of({name:"JSON-LD",alias:["jsonld"],extensions:["jsonld"],load(){return mt(()=>import("./javascript-iXu5QeM3.js"),[]).then(e=>Ct(e.jsonld))}}),ot.of({name:"Julia",extensions:["jl"],load(){return mt(()=>import("./julia-DuME0IfC.js"),[]).then(e=>Ct(e.julia))}}),ot.of({name:"Kotlin",extensions:["kt","kts"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.kotlin))}}),ot.of({name:"LiveScript",alias:["ls"],extensions:["ls"],load(){return mt(()=>import("./livescript-BwQOo05w.js"),[]).then(e=>Ct(e.liveScript))}}),ot.of({name:"Lua",extensions:["lua"],load(){return mt(()=>import("./lua-BgMRiT3U.js"),[]).then(e=>Ct(e.lua))}}),ot.of({name:"mIRC",extensions:["mrc"],load(){return mt(()=>import("./mirc-CjQqDB4T.js"),[]).then(e=>Ct(e.mirc))}}),ot.of({name:"Mathematica",extensions:["m","nb","wl","wls"],load(){return mt(()=>import("./mathematica-DTrFuWx2.js"),[]).then(e=>Ct(e.mathematica))}}),ot.of({name:"Modelica",extensions:["mo"],load(){return mt(()=>import("./modelica-Dc1JOy9r.js"),[]).then(e=>Ct(e.modelica))}}),ot.of({name:"MUMPS",extensions:["mps"],load(){return mt(()=>import("./mumps-BT43cFF4.js"),[]).then(e=>Ct(e.mumps))}}),ot.of({name:"Mbox",extensions:["mbox"],load(){return mt(()=>import("./mbox-CNhZ1qSd.js"),[]).then(e=>Ct(e.mbox))}}),ot.of({name:"Nginx",filename:/nginx.*\.conf$/i,load(){return mt(()=>import("./nginx-DdIZxoE0.js"),[]).then(e=>Ct(e.nginx))}}),ot.of({name:"NSIS",extensions:["nsh","nsi"],load(){return mt(()=>import("./nsis-LdVXkNf5.js"),__vite__mapDeps([23,21])).then(e=>Ct(e.nsis))}}),ot.of({name:"NTriples",extensions:["nt","nq"],load(){return mt(()=>import("./ntriples-BfvgReVJ.js"),[]).then(e=>Ct(e.ntriples))}}),ot.of({name:"Objective-C",alias:["objective-c","objc"],extensions:["m"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.objectiveC))}}),ot.of({name:"Objective-C++",alias:["objective-c++","objc++"],extensions:["mm"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.objectiveCpp))}}),ot.of({name:"OCaml",extensions:["ml","mli","mll","mly"],load(){return mt(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>Ct(e.oCaml))}}),ot.of({name:"Octave",extensions:["m"],load(){return mt(()=>import("./octave-Ck1zUtKM.js"),[]).then(e=>Ct(e.octave))}}),ot.of({name:"Oz",extensions:["oz"],load(){return mt(()=>import("./oz-BzwKVEFT.js"),[]).then(e=>Ct(e.oz))}}),ot.of({name:"Pascal",extensions:["p","pas"],load(){return mt(()=>import("./pascal--L3eBynH.js"),[]).then(e=>Ct(e.pascal))}}),ot.of({name:"Perl",extensions:["pl","pm"],load(){return mt(()=>import("./perl-CdXCOZ3F.js"),[]).then(e=>Ct(e.perl))}}),ot.of({name:"Pig",extensions:["pig"],load(){return mt(()=>import("./pig-CevX1Tat.js"),[]).then(e=>Ct(e.pig))}}),ot.of({name:"PowerShell",extensions:["ps1","psd1","psm1"],load(){return mt(()=>import("./powershell-CFHJl5sT.js"),[]).then(e=>Ct(e.powerShell))}}),ot.of({name:"Properties files",alias:["ini","properties"],extensions:["properties","ini","in"],load(){return mt(()=>import("./properties-C78fOPTZ.js"),[]).then(e=>Ct(e.properties))}}),ot.of({name:"ProtoBuf",extensions:["proto"],load(){return mt(()=>import("./protobuf-ChK-085T.js"),[]).then(e=>Ct(e.protobuf))}}),ot.of({name:"Pug",alias:["jade"],extensions:["pug","jade"],load(){return mt(()=>import("./pug-DeIclll2.js"),__vite__mapDeps([24,25])).then(e=>Ct(e.pug))}}),ot.of({name:"Puppet",extensions:["pp"],load(){return mt(()=>import("./puppet-DMA9R1ak.js"),[]).then(e=>Ct(e.puppet))}}),ot.of({name:"Q",extensions:["q"],load(){return mt(()=>import("./q-pXgVlZs6.js"),[]).then(e=>Ct(e.q))}}),ot.of({name:"R",alias:["rscript"],extensions:["r","R"],load(){return mt(()=>import("./r-B6wPVr8A.js"),[]).then(e=>Ct(e.r))}}),ot.of({name:"RPM Changes",load(){return mt(()=>import("./rpm-CTu-6PCP.js"),[]).then(e=>Ct(e.rpmChanges))}}),ot.of({name:"RPM Spec",extensions:["spec"],load(){return mt(()=>import("./rpm-CTu-6PCP.js"),[]).then(e=>Ct(e.rpmSpec))}}),ot.of({name:"Ruby",alias:["jruby","macruby","rake","rb","rbx"],extensions:["rb"],filename:/^(Gemfile|Rakefile)$/,load(){return mt(()=>import("./ruby-B2Rjki9n.js"),[]).then(e=>Ct(e.ruby))}}),ot.of({name:"SAS",extensions:["sas"],load(){return mt(()=>import("./sas-B4kiWyti.js"),[]).then(e=>Ct(e.sas))}}),ot.of({name:"Scala",extensions:["scala"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.scala))}}),ot.of({name:"Scheme",extensions:["scm","ss"],load(){return mt(()=>import("./scheme-C41bIUwD.js"),[]).then(e=>Ct(e.scheme))}}),ot.of({name:"Shell",alias:["bash","sh","zsh"],extensions:["sh","ksh","bash"],filename:/^PKGBUILD$/,load(){return mt(()=>import("./shell-CjFT_Tl9.js"),[]).then(e=>Ct(e.shell))}}),ot.of({name:"Sieve",extensions:["siv","sieve"],load(){return mt(()=>import("./sieve-C3Gn_uJK.js"),[]).then(e=>Ct(e.sieve))}}),ot.of({name:"Smalltalk",extensions:["st"],load(){return mt(()=>import("./smalltalk-CnHTOXQT.js"),[]).then(e=>Ct(e.smalltalk))}}),ot.of({name:"Solr",load(){return mt(()=>import("./solr-DehyRSwq.js"),[]).then(e=>Ct(e.solr))}}),ot.of({name:"SML",extensions:["sml","sig","fun","smackspec"],load(){return mt(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>Ct(e.sml))}}),ot.of({name:"SPARQL",alias:["sparul"],extensions:["rq","sparql"],load(){return mt(()=>import("./sparql-DkYu6x3z.js"),[]).then(e=>Ct(e.sparql))}}),ot.of({name:"Spreadsheet",alias:["excel","formula"],load(){return mt(()=>import("./spreadsheet-BCZA_wO0.js"),[]).then(e=>Ct(e.spreadsheet))}}),ot.of({name:"Squirrel",extensions:["nut"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.squirrel))}}),ot.of({name:"Stylus",extensions:["styl"],load(){return mt(()=>import("./stylus-B533Al4x.js"),[]).then(e=>Ct(e.stylus))}}),ot.of({name:"Swift",extensions:["swift"],load(){return mt(()=>import("./swift-BzpIVaGY.js"),[]).then(e=>Ct(e.swift))}}),ot.of({name:"sTeX",load(){return mt(()=>import("./stex-C3f8Ysf7.js"),[]).then(e=>Ct(e.stex))}}),ot.of({name:"LaTeX",alias:["tex"],extensions:["text","ltx","tex"],load(){return mt(()=>import("./stex-C3f8Ysf7.js"),[]).then(e=>Ct(e.stex))}}),ot.of({name:"SystemVerilog",extensions:["v","sv","svh"],load(){return mt(()=>import("./verilog-C6RDOZhf.js"),[]).then(e=>Ct(e.verilog))}}),ot.of({name:"Tcl",extensions:["tcl"],load(){return mt(()=>import("./tcl-DVfN8rqt.js"),[]).then(e=>Ct(e.tcl))}}),ot.of({name:"Textile",extensions:["textile"],load(){return mt(()=>import("./textile-CnDTJFAw.js"),[]).then(e=>Ct(e.textile))}}),ot.of({name:"TiddlyWiki",load(){return mt(()=>import("./tiddlywiki-DO-Gjzrf.js"),[]).then(e=>Ct(e.tiddlyWiki))}}),ot.of({name:"Tiki wiki",load(){return mt(()=>import("./tiki-DGYXhP31.js"),[]).then(e=>Ct(e.tiki))}}),ot.of({name:"TOML",extensions:["toml"],load(){return mt(()=>import("./toml-Bm5Em-hy.js"),[]).then(e=>Ct(e.toml))}}),ot.of({name:"Troff",extensions:["1","2","3","4","5","6","7","8","9"],load(){return mt(()=>import("./troff-wAsdV37c.js"),[]).then(e=>Ct(e.troff))}}),ot.of({name:"TTCN",extensions:["ttcn","ttcn3","ttcnpp"],load(){return mt(()=>import("./ttcn-CfJYG6tj.js"),[]).then(e=>Ct(e.ttcn))}}),ot.of({name:"TTCN_CFG",extensions:["cfg"],load(){return mt(()=>import("./ttcn-cfg-B9xdYoR4.js"),[]).then(e=>Ct(e.ttcnCfg))}}),ot.of({name:"Turtle",extensions:["ttl"],load(){return mt(()=>import("./turtle-B1tBg_DP.js"),[]).then(e=>Ct(e.turtle))}}),ot.of({name:"Web IDL",extensions:["webidl"],load(){return mt(()=>import("./webidl-ZXfAyPTL.js"),[]).then(e=>Ct(e.webIDL))}}),ot.of({name:"VB.NET",extensions:["vb"],load(){return mt(()=>import("./vb-CmGdzxic.js"),[]).then(e=>Ct(e.vb))}}),ot.of({name:"VBScript",extensions:["vbs"],load(){return mt(()=>import("./vbscript-BuJXcnF6.js"),[]).then(e=>Ct(e.vbScript))}}),ot.of({name:"Velocity",extensions:["vtl"],load(){return mt(()=>import("./velocity-D8B20fx6.js"),[]).then(e=>Ct(e.velocity))}}),ot.of({name:"Verilog",extensions:["v"],load(){return mt(()=>import("./verilog-C6RDOZhf.js"),[]).then(e=>Ct(e.verilog))}}),ot.of({name:"VHDL",extensions:["vhd","vhdl"],load(){return mt(()=>import("./vhdl-lSbBsy5d.js"),[]).then(e=>Ct(e.vhdl))}}),ot.of({name:"XQuery",extensions:["xy","xquery","xq","xqm","xqy"],load(){return mt(()=>import("./xquery-DzFWVndE.js"),[]).then(e=>Ct(e.xQuery))}}),ot.of({name:"Yacas",extensions:["ys"],load(){return mt(()=>import("./yacas-BJ4BC0dw.js"),[]).then(e=>Ct(e.yacas))}}),ot.of({name:"Z80",extensions:["z80"],load(){return mt(()=>import("./z80-Hz9HOZM7.js"),[]).then(e=>Ct(e.z80))}}),ot.of({name:"MscGen",extensions:["mscgen","mscin","msc"],load(){return mt(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>Ct(e.mscgen))}}),ot.of({name:"Xù",extensions:["xu"],load(){return mt(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>Ct(e.xu))}}),ot.of({name:"MsGenny",extensions:["msgenny"],load(){return mt(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>Ct(e.msgenny))}}),ot.of({name:"Vue",extensions:["vue"],load(){return mt(()=>import("./index-Cmtp6C3D.js"),__vite__mapDeps([26,5,1,3,6])).then(e=>e.vue())}}),ot.of({name:"Angular Template",load(){return mt(()=>import("./index-Csahsk0b.js"),__vite__mapDeps([27,5,1,3,6])).then(e=>e.angular())}})],kne="#2e3440",aK="#3b4252",jne="#434c5e",M9="#4c566a",Nne="#e5e9f0",WL="#eceff4",FM="#8fbcbb",Cne="#88c0d0",Kdt="#81a1c1",Gu="#5e81ac",Hdt="#bf616a",Rx="#d08770",zM="#ebcb8b",Sne="#a3be8c",Vdt="#b48ead",_ne="#d30102",oK=WL,BM=oK,Wdt="#ffffff",UM=aK,Zdt=oK,Ane=aK,Gdt=Yt.theme({"&":{color:kne,backgroundColor:Wdt},".cm-content":{caretColor:Ane},".cm-cursor, .cm-dropCursor":{borderLeftColor:Ane},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:Zdt},".cm-panels":{backgroundColor:oK,color:M9},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:`1px solid ${M9}`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:Nne},".cm-activeLine":{backgroundColor:BM},".cm-selectionMatch":{backgroundColor:Nne},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{outline:`1px solid ${M9}`},"&.cm-focused .cm-matchingBracket":{backgroundColor:WL},".cm-gutters":{backgroundColor:WL,color:kne,border:"none"},".cm-activeLineGutter":{backgroundColor:BM},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:UM},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:UM,borderBottomColor:UM},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:BM,color:M9}}},{dark:!1}),Qdt=W7.define([{tag:dt.keyword,color:Gu},{tag:[dt.name,dt.deleted,dt.character,dt.propertyName,dt.macroName],color:Rx},{tag:[dt.variableName],color:Rx},{tag:[dt.function(dt.variableName)],color:Gu},{tag:[dt.labelName],color:Kdt},{tag:[dt.color,dt.constant(dt.name),dt.standard(dt.name)],color:Gu},{tag:[dt.definition(dt.name),dt.separator],color:Sne},{tag:[dt.brace],color:FM},{tag:[dt.annotation],color:_ne},{tag:[dt.number,dt.changed,dt.annotation,dt.modifier,dt.self,dt.namespace],color:Cne},{tag:[dt.typeName,dt.className],color:zM},{tag:[dt.operator,dt.operatorKeyword],color:Sne},{tag:[dt.tagName],color:Vdt},{tag:[dt.squareBracket],color:Hdt},{tag:[dt.angleBracket],color:Rx},{tag:[dt.attributeName],color:zM},{tag:[dt.regexp],color:Gu},{tag:[dt.quote],color:aK},{tag:[dt.string],color:Rx},{tag:dt.link,color:FM,textDecoration:"underline",textUnderlinePosition:"under"},{tag:[dt.url,dt.escape,dt.special(dt.string)],color:Rx},{tag:[dt.meta],color:Cne},{tag:[dt.comment],color:jne,fontStyle:"italic"},{tag:dt.strong,fontWeight:"bold",color:Gu},{tag:dt.emphasis,fontStyle:"italic",color:Gu},{tag:dt.strikethrough,textDecoration:"line-through"},{tag:dt.heading,fontWeight:"bold",color:Gu},{tag:dt.special(dt.heading1),fontWeight:"bold",color:Gu},{tag:dt.heading1,fontWeight:"bold",color:Gu},{tag:[dt.heading2,dt.heading3,dt.heading4],fontWeight:"bold",color:Gu},{tag:[dt.heading5,dt.heading6],color:Gu},{tag:[dt.atom,dt.bool,dt.special(dt.variableName)],color:Rx},{tag:[dt.processingInstruction,dt.inserted],color:FM},{tag:[dt.contentSeparator],color:zM},{tag:dt.invalid,color:jne,borderBottom:`1px dotted ${_ne}`}]),Ydt=[Gdt,V5e(Qdt)],Ene=typeof String.prototype.normalize=="function"?e=>e.normalize("NFKD"):e=>e;class M5{constructor(t,n,r=0,i=t.length,a,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(r,i),this.bufferStart=r,this.normalize=a?l=>a(Ene(l)):Ene,this.query=this.normalize(n)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return Xl(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let n=wq(t),r=this.bufferStart+this.bufferPos;this.bufferPos+=wf(t);let i=this.normalize(n);if(i.length)for(let a=0,o=r;;a++){let l=i.charCodeAt(a),c=this.match(l,o,this.bufferPos+this.bufferStart);if(a==i.length-1){if(c)return this.value=c,this;break}o==r&&a<n.length&&n.charCodeAt(a)==l&&o++}}}match(t,n,r){let i=null;for(let a=0;a<this.matches.length;a+=2){let o=this.matches[a],l=!1;this.query.charCodeAt(o)==t&&(o==this.query.length-1?i={from:this.matches[a+1],to:r}:(this.matches[a]++,l=!0)),l||(this.matches.splice(a,2),a-=2)}return this.query.charCodeAt(0)==t&&(this.query.length==1?i={from:n,to:r}:this.matches.push(1,n)),i&&this.test&&!this.test(i.from,i.to,this.buffer,this.bufferStart)&&(i=null),i}}typeof Symbol<"u"&&(M5.prototype[Symbol.iterator]=function(){return this});const H4e={from:-1,to:-1,match:/.*/.exec("")},lK="gm"+(/x/.unicode==null?"":"u");class V4e{constructor(t,n,r,i=0,a=t.length){if(this.text=t,this.to=a,this.curLine="",this.done=!1,this.value=H4e,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new W4e(t,n,r,i,a);this.re=new RegExp(n,lK+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.iter=t.iter();let o=t.lineAt(i);this.curLineStart=o.from,this.matchPos=JN(t,i),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let n=this.matchPos<=this.to&&this.re.exec(this.curLine);if(n){let r=this.curLineStart+n.index,i=r+n[0].length;if(this.matchPos=JN(this.text,i+(r==i?1:0)),r==this.curLineStart+this.curLine.length&&this.nextLine(),(r<i||r>this.value.to)&&(!this.test||this.test(r,i,n)))return this.value={from:r,to:i,match:n},this;t=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),t=0;else return this.done=!0,this}}}const qM=new WeakMap;class T3{constructor(t,n){this.from=t,this.text=n}get to(){return this.from+this.text.length}static get(t,n,r){let i=qM.get(t);if(!i||i.from>=r||i.to<=n){let l=new T3(n,t.sliceString(n,r));return qM.set(t,l),l}if(i.from==n&&i.to==r)return i;let{text:a,from:o}=i;return o>n&&(a=t.sliceString(n,o)+a,o=n),i.to<r&&(a+=t.sliceString(i.to,r)),qM.set(t,new T3(o,a)),new T3(n,a.slice(n-o,r-o))}}class W4e{constructor(t,n,r,i,a){this.text=t,this.to=a,this.done=!1,this.value=H4e,this.matchPos=JN(t,i),this.re=new RegExp(n,lK+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.flat=T3.get(t,i,this.chunkEnd(i+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,n=this.re.exec(this.flat.text);if(n&&!n[0]&&n.index==t&&(this.re.lastIndex=t+1,n=this.re.exec(this.flat.text)),n){let r=this.flat.from+n.index,i=r+n[0].length;if((this.flat.to>=this.to||n.index+n[0].length<=this.flat.text.length-10)&&(!this.test||this.test(r,i,n)))return this.value={from:r,to:i,match:n},this.matchPos=JN(this.text,i+(r==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=T3.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(V4e.prototype[Symbol.iterator]=W4e.prototype[Symbol.iterator]=function(){return this});function Jdt(e){try{return new RegExp(e,lK),!0}catch{return!1}}function JN(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}const Xdt=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=nlt(e,{label:t.phrase("Go to line"),input:{type:"text",name:"line",value:n},focus:!0,submitLabel:t.phrase("go")});return i.then(a=>{let o=a&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(a.elements.line.value);if(!o){e.dispatch({effects:r});return}let l=t.doc.lineAt(t.selection.main.head),[,c,u,d,f]=o,h=d?+d.slice(1):0,g=u?+u:l.number;if(u&&f){let j=g/100;c&&(j=j*(c=="-"?-1:1)+l.number/t.doc.lines),g=Math.round(t.doc.lines*j)}else u&&c&&(g=g*(c=="-"?-1:1)+l.number);let b=t.doc.line(Math.max(1,Math.min(t.doc.lines,g))),v=bt.cursor(b.from+Math.max(0,Math.min(h,b.length)));e.dispatch({effects:[r,Yt.scrollIntoView(v.from,{y:"center"})],selection:v})}),!0},eft={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},tft=Jt.define({combine(e){return im(e,eft,{highlightWordAroundCursor:(t,n)=>t||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function nft(e){return[oft,aft]}const rft=$n.mark({class:"cm-selectionMatch"}),sft=$n.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Tne(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=yi.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=yi.Word)}function ift(e,t,n,r){return e(t.sliceDoc(n,n+1))==yi.Word&&e(t.sliceDoc(r-1,r))==yi.Word}const aft=ia.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(tft),{state:n}=e,r=n.selection;if(r.ranges.length>1)return $n.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return $n.none;let c=n.wordAt(i.head);if(!c)return $n.none;o=n.charCategorizer(i.head),a=n.sliceDoc(c.from,c.to)}else{let c=i.to-i.from;if(c<t.minSelectionLength||c>200)return $n.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(Tne(o,n,i.from,i.to)&&ift(o,n,i.from,i.to)))return $n.none}else if(a=n.sliceDoc(i.from,i.to),!a)return $n.none}let l=[];for(let c of e.visibleRanges){let u=new M5(n.doc,a,c.from,c.to);for(;!u.next().done;){let{from:d,to:f}=u.value;if((!o||Tne(o,n,d,f))&&(i.empty&&d<=i.from&&f>=i.to?l.push(sft.range(d,f)):(d>=i.to||f<=i.from)&&l.push(rft.range(d,f)),l.length>t.maxMatches))return $n.none}}return $n.set(l)}},{decorations:e=>e.decorations}),oft=Yt.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),lft=({state:e,dispatch:t})=>{let{selection:n}=e,r=bt.create(n.ranges.map(i=>e.wordAt(i.head)||bt.cursor(i.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function cft(e,t){let{main:n,ranges:r}=e.selection,i=e.wordAt(n.head),a=i&&i.from==n.from&&i.to==n.to;for(let o=!1,l=new M5(e.doc,t,r[r.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new M5(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),o=!0}else{if(o&&r.some(c=>c.from==l.value.from))continue;if(a){let c=e.wordAt(l.value.from);if(!c||c.from!=l.value.from||c.to!=l.value.to)continue}return l.value}}const uft=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(a=>a.from===a.to))return lft({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(a=>e.sliceDoc(a.from,a.to)!=r))return!1;let i=cft(e,r);return i?(t(e.update({selection:e.selection.addRange(bt.range(i.from,i.to),!1),effects:Yt.scrollIntoView(i.to)})),!0):!1},O4=Jt.define({combine(e){return im(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new Nft(t),scrollToMatch:t=>Yt.scrollIntoView(t)})}});class Z4e{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||Jdt(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord,this.test=t.test}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(n,r)=>r=="n"?`
1297
+ `);r>-1&&(n=n.slice(0,r))}return t+n.length<=this.to?n:n.slice(0,this.to-t)}nextLine(){let t=this.parsedPos,n=this.lineAfter(t),r=t+n.length;for(let i=this.rangeIndex;;){let a=this.ranges[i].to;if(a>=r||(n=n.slice(0,a-(r-n.length)),i++,i==this.ranges.length))break;let o=this.ranges[i].from,l=this.lineAfter(o);n+=l,r=o+l.length}return{line:n,end:r}}skipGapsTo(t,n,r){for(;;){let i=this.ranges[this.rangeIndex].to,a=t+n;if(r>0?i>a:i>=a)break;let o=this.ranges[++this.rangeIndex].from;n+=o-i}return n}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(t,n,r,i){let a=4;if(this.ranges.length>1){i=this.skipGapsTo(n,i,1),n+=i;let l=this.chunk.length;i=this.skipGapsTo(r,i,-1),r+=i,a+=this.chunk.length-l}let o=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&a==4&&o>=0&&this.chunk[o]==t&&this.chunk[o+2]==n?this.chunk[o+2]=r:this.chunk.push(t,n,r,a),i}parseLine(t){let{line:n,end:r}=this.nextLine(),i=0,{streamParser:a}=this.lang,o=new Q5e(n,t?t.state.tabSize:4,t?h0(t.state):2);if(o.eol())a.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=J5e(a.token,o,this.state);if(l&&(i=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,i)),o.start>1e4)break}this.parsedPos=r,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let t=Vs.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:Tct,topID:0,maxBufferLength:512,reused:this.chunkReused});t=new Vs(t.type,t.children,t.positions,t.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(t),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new Vs(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function J5e(e,t,n){t.start=t.pos;for(let r=0;r<10;r++){let i=e(t,n);if(t.pos>t.start)return i}throw new Error("Stream parser failed to advance stream.")}const Zq=Object.create(null),O6=[Ll.none],Tct=new zq(O6),rne=[],sne=Object.create(null),X5e=Object.create(null);for(let[e,t]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])X5e[e]=t4e(Zq,t);class e4e{constructor(t){this.extra=t,this.table=Object.assign(Object.create(null),X5e)}resolve(t){return t?this.table[t]||(this.table[t]=t4e(this.extra,t)):0}}const Ict=new e4e(Zq);function OM(e,t){rne.indexOf(e)>-1||(rne.push(e),console.warn(t))}function t4e(e,t){let n=[];for(let l of t.split(" ")){let c=[];for(let u of l.split(".")){let d=e[u]||dt[u];d?typeof d=="function"?c.length?c=c.map(d):OM(u,`Modifier ${u} used at start of tag`):c.length?OM(u,`Tag ${u} used as modifier`):c=Array.isArray(d)?d:[d]:OM(u,`Unknown highlighting tag ${u}`)}for(let u of c)n.push(u)}if(!n.length)return 0;let r=t.replace(/ /g,"_"),i=r+" "+n.map(l=>l.id),a=sne[i];if(a)return a.id;let o=sne[i]=Ll.define({id:O6.length,name:r,props:[Olt({[r]:n})]});return O6.push(o),o.id}function Mct(e,t){let n=Ll.define({id:O6.length,name:"Document",props:[a2.add(()=>e),P5e.add(()=>r=>t.getIndent(r))],top:!0});return O6.push(n),n}Hs.RTL,Hs.LTR;class n4e{constructor(t,n,r,i){this.state=t,this.pos=n,this.explicit=r,this.view=i,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(t){let n=Bo(this.state).resolveInner(this.pos,-1);for(;n&&t.indexOf(n.name)<0;)n=n.parent;return n?{from:n.from,to:this.pos,text:this.state.sliceDoc(n.from,this.pos),type:n.type}:null}matchBefore(t){let n=this.state.doc.lineAt(this.pos),r=Math.max(n.from,this.pos-250),i=n.text.slice(r-n.from,this.pos-n.from),a=i.search(r4e(t,!1));return a<0?null:{from:r+a,to:this.pos,text:i.slice(a)}}get aborted(){return this.abortListeners==null}addEventListener(t,n,r){t=="abort"&&this.abortListeners&&(this.abortListeners.push(n),r&&r.onDocChange&&(this.abortOnDocChange=!0))}}function ine(e){let t=Object.keys(e).join(""),n=/\w/.test(t);return n&&(t=t.replace(/\w/g,"")),`[${n?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}function Rct(e){let t=Object.create(null),n=Object.create(null);for(let{label:i}of e){t[i[0]]=!0;for(let a=1;a<i.length;a++)n[i[a]]=!0}let r=ine(t)+ine(n)+"*$";return[new RegExp("^"+r),new RegExp(r)]}function Oct(e){let t=e.map(i=>typeof i=="string"?{label:i}:i),[n,r]=t.every(i=>/^\w+$/.test(i.label))?[/\w*$/,/\w+$/]:Rct(t);return i=>{let a=i.matchBefore(r);return a||i.explicit?{from:a?a.from:i.pos,options:t,validFor:n}:null}}function pAt(e,t){return n=>{for(let r=Bo(n.state).resolveInner(n.pos,-1);r;r=r.parent){if(e.indexOf(r.name)>-1)return null;if(r.type.isTop)break}return t(n)}}class ane{constructor(t,n,r,i){this.completion=t,this.source=n,this.match=r,this.score=i}}function E2(e){return e.selection.main.from}function r4e(e,t){var n;let{source:r}=e,i=t&&r[0]!="^",a=r[r.length-1]!="$";return!i&&!a?e:new RegExp(`${i?"^":""}(?:${r})${a?"$":""}`,(n=e.flags)!==null&&n!==void 0?n:e.ignoreCase?"i":"")}const Gq=q1.define();function Pct(e,t,n,r){let{main:i}=e.selection,a=n-i.from,o=r-i.from;return{...e.changeByRange(l=>{if(l!=i&&n!=r&&e.sliceDoc(l.from+a,l.from+o)!=e.sliceDoc(n,r))return{range:l};let c=e.toText(t);return{changes:{from:l.from+a,to:r==i.from?l.to:l.from+o,insert:c},range:bt.cursor(l.from+a+c.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const one=new WeakMap;function Dct(e){if(!Array.isArray(e))return e;let t=one.get(e);return t||one.set(e,t=Oct(e)),t}const GN=ir.define(),P6=ir.define();class Lct{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let n=0;n<t.length;){let r=Xl(t,n),i=wf(r);this.chars.push(r);let a=t.slice(n,n+i),o=a.toUpperCase();this.folded.push(Xl(o==a?a.toLowerCase():o,0)),n+=i}this.astral=t.length!=this.chars.length}ret(t,n){return this.score=t,this.matched=n,this}match(t){if(this.pattern.length==0)return this.ret(-100,[]);if(t.length<this.pattern.length)return null;let{chars:n,folded:r,any:i,precise:a,byWord:o}=this;if(n.length==1){let w=Xl(t,0),N=wf(w),C=N==t.length?0:-100;if(w!=n[0])if(w==r[0])C+=-200;else return null;return this.ret(C,[0,N])}let l=t.indexOf(this.pattern);if(l==0)return this.ret(t.length==this.pattern.length?0:-100,[0,this.pattern.length]);let c=n.length,u=0;if(l<0){for(let w=0,N=Math.min(t.length,200);w<N&&u<c;){let C=Xl(t,w);(C==n[u]||C==r[u])&&(i[u++]=w),w+=wf(C)}if(u<c)return null}let d=0,f=0,h=!1,g=0,b=-1,v=-1,j=/[a-z]/.test(t),k=!0;for(let w=0,N=Math.min(t.length,200),C=0;w<N&&f<c;){let A=Xl(t,w);l<0&&(d<c&&A==n[d]&&(a[d++]=w),g<c&&(A==n[g]||A==r[g]?(g==0&&(b=w),v=w+1,g++):g=0));let _,E=A<255?A>=48&&A<=57||A>=97&&A<=122?2:A>=65&&A<=90?1:0:(_=wq(A))!=_.toLowerCase()?1:_!=_.toUpperCase()?2:0;(!w||E==1&&j||C==0&&E!=0)&&(n[f]==A||r[f]==A&&(h=!0)?o[f++]=w:o.length&&(k=!1)),C=E,w+=wf(A)}return f==c&&o[0]==0&&k?this.result(-100+(h?-200:0),o,t):g==c&&b==0?this.ret(-200-t.length+(v==t.length?0:-100),[0,v]):l>-1?this.ret(-700-t.length,[l,l+this.pattern.length]):g==c?this.ret(-900-t.length,[b,v]):f==c?this.result(-100+(h?-200:0)+-700+(k?0:-1100),o,t):n.length==2?null:this.result((i[0]?-700:0)+-200+-1100,i,t)}result(t,n,r){let i=[],a=0;for(let o of n){let l=o+(this.astral?wf(Xl(r,o)):1);a&&i[a-1]==o?i[a-1]=l:(i[a++]=o,i[a++]=l)}return this.ret(t-r.length,i)}}class $ct{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.length<this.pattern.length)return null;let n=t.slice(0,this.pattern.length),r=n==this.pattern?0:n.toLowerCase()==this.folded?-200:null;return r==null?null:(this.matched=[0,n.length],this.score=r+(t.length==this.pattern.length?0:-100),this)}}const ao=Jt.define({combine(e){return im(e,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Fct,filterStrict:!1,compareCompletions:(t,n)=>(t.sortText||t.label).localeCompare(n.sortText||n.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,n)=>t&&n,closeOnBlur:(t,n)=>t&&n,icons:(t,n)=>t&&n,tooltipClass:(t,n)=>r=>lne(t(r),n(r)),optionClass:(t,n)=>r=>lne(t(r),n(r)),addToOptions:(t,n)=>t.concat(n),filterStrict:(t,n)=>t||n})}});function lne(e,t){return e?t?e+" "+t:e:t}function Fct(e,t,n,r,i,a){let o=e.textDirection==Hs.RTL,l=o,c=!1,u="top",d,f,h=t.left-i.left,g=i.right-t.right,b=r.right-r.left,v=r.bottom-r.top;if(l&&h<Math.min(b,g)?l=!1:!l&&g<Math.min(b,h)&&(l=!0),b<=(l?h:g))d=Math.max(i.top,Math.min(n.top,i.bottom-v))-t.top,f=Math.min(400,l?h:g);else{c=!0,f=Math.min(400,(o?t.right:i.right-t.left)-30);let w=i.bottom-t.bottom;w>=v||w>t.top?d=n.bottom-t.top:(u="bottom",d=t.bottom-n.top)}let j=(t.bottom-t.top)/a.offsetHeight,k=(t.right-t.left)/a.offsetWidth;return{style:`${u}: ${d/j}px; max-width: ${f/k}px`,class:"cm-completionInfo-"+(c?o?"left-narrow":"right-narrow":l?"left":"right")}}const Qq=ir.define();function zct(e){let t=e.addToOptions.slice();return e.icons&&t.push({render(n){let r=document.createElement("div");return r.classList.add("cm-completionIcon"),n.type&&r.classList.add(...n.type.split(/\s+/g).map(i=>"cm-completionIcon-"+i)),r.setAttribute("aria-hidden","true"),r},position:20}),t.push({render(n,r,i,a){let o=document.createElement("span");o.className="cm-completionLabel";let l=n.displayLabel||n.label,c=0;for(let u=0;u<a.length;){let d=a[u++],f=a[u++];d>c&&o.appendChild(document.createTextNode(l.slice(c,d)));let h=o.appendChild(document.createElement("span"));h.appendChild(document.createTextNode(l.slice(d,f))),h.className="cm-completionMatchedText",c=f}return c<l.length&&o.appendChild(document.createTextNode(l.slice(c))),o},position:50},{render(n){if(!n.detail)return null;let r=document.createElement("span");return r.className="cm-completionDetail",r.textContent=n.detail,r},position:80}),t.sort((n,r)=>n.position-r.position).map(n=>n.render)}function PM(e,t,n){if(e<=n)return{from:0,to:e};if(t<0&&(t=0),t<=e>>1){let i=Math.floor(t/n);return{from:i*n,to:(i+1)*n}}let r=Math.floor((e-t)/n);return{from:e-(r+1)*n,to:e-r*n}}class Bct{constructor(t,n,r){this.view=t,this.stateField=n,this.applyCompletion=r,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:c=>this.placeInfo(c),key:this},this.space=null,this.currentClass="";let i=t.state.field(n),{options:a,selected:o}=i.open,l=t.state.facet(ao);this.optionContent=zct(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=PM(a.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",c=>{let{options:u}=t.state.field(n).open;for(let d=c.target,f;d&&d!=this.dom;d=d.parentNode)if(d.nodeName=="LI"&&(f=/-(\d+)$/.exec(d.id))&&+f[1]<u.length){this.applyCompletion(t,u[+f[1]]),c.preventDefault();return}if(c.target==this.list){let d=this.list.classList.contains("cm-completionListIncompleteTop")&&c.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&c.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;d!=null&&(t.dispatch({effects:Qq.of(d)}),c.preventDefault())}}),this.dom.addEventListener("focusout",c=>{let u=t.state.field(this.stateField,!1);u&&u.tooltip&&t.state.facet(ao).closeOnBlur&&c.relatedTarget!=t.contentDOM&&t.dispatch({effects:P6.of(null)})}),this.showOptions(a,i.id)}mount(){this.updateSel()}showOptions(t,n){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,n,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var n;let r=t.state.field(this.stateField),i=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),r!=i){let{options:a,selected:o,disabled:l}=r.open;(!i.open||i.open.options!=a)&&(this.range=PM(a.length,o,t.state.facet(ao).maxRenderedOptions),this.showOptions(a,r.id)),this.updateSel(),l!=((n=i.open)===null||n===void 0?void 0:n.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(t){let n=this.tooltipClass(t);if(n!=this.currentClass){for(let r of this.currentClass.split(" "))r&&this.dom.classList.remove(r);for(let r of n.split(" "))r&&this.dom.classList.add(r);this.currentClass=n}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),n=t.open;(n.selected>-1&&n.selected<this.range.from||n.selected>=this.range.to)&&(this.range=PM(n.options.length,n.selected,this.view.state.facet(ao).maxRenderedOptions),this.showOptions(n.options,t.id));let r=this.updateSelectedOption(n.selected);if(r){this.destroyInfo();let{completion:i}=n.options[n.selected],{info:a}=i;if(!a)return;let o=typeof a=="string"?document.createTextNode(a):a(i);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(l,i)}).catch(l=>rc(this.view.state,l,"completion info")):(this.addInfoPane(o,i),r.setAttribute("aria-describedby",this.info.id))}}addInfoPane(t,n){this.destroyInfo();let r=this.info=document.createElement("div");if(r.className="cm-tooltip cm-completionInfo",r.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),t.nodeType!=null)r.appendChild(t),this.infoDestroy=null;else{let{dom:i,destroy:a}=t;r.appendChild(i),this.infoDestroy=a||null}this.dom.appendChild(r),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let n=null;for(let r=this.list.firstChild,i=this.range.from;r;r=r.nextSibling,i++)r.nodeName!="LI"||!r.id?i--:i==t?r.hasAttribute("aria-selected")||(r.setAttribute("aria-selected","true"),n=r):r.hasAttribute("aria-selected")&&(r.removeAttribute("aria-selected"),r.removeAttribute("aria-describedby"));return n&&qct(this.list,n),n}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let n=this.dom.getBoundingClientRect(),r=this.info.getBoundingClientRect(),i=t.getBoundingClientRect(),a=this.space;if(!a){let o=this.dom.ownerDocument.documentElement;a={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return i.top>Math.min(a.bottom,n.bottom)-10||i.bottom<Math.max(a.top,n.top)+10?null:this.view.state.facet(ao).positionInfo(this.view,n,i,r,a,this.dom)}placeInfo(t){this.info&&(t?(t.style&&(this.info.style.cssText=t.style),this.info.className="cm-tooltip cm-completionInfo "+(t.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(t,n,r){const i=document.createElement("ul");i.id=n,i.setAttribute("role","listbox"),i.setAttribute("aria-expanded","true"),i.setAttribute("aria-label",this.view.state.phrase("Completions")),i.addEventListener("mousedown",o=>{o.target==i&&o.preventDefault()});let a=null;for(let o=r.from;o<r.to;o++){let{completion:l,match:c}=t[o],{section:u}=l;if(u){let h=typeof u=="string"?u:u.name;if(h!=a&&(o>r.from||r.from==0))if(a=h,typeof u!="string"&&u.header)i.appendChild(u.header(u));else{let g=i.appendChild(document.createElement("completion-section"));g.textContent=h}}const d=i.appendChild(document.createElement("li"));d.id=n+"-"+o,d.setAttribute("role","option");let f=this.optionClass(l);f&&(d.className=f);for(let h of this.optionContent){let g=h(l,this.view.state,this.view,c);g&&d.appendChild(g)}}return r.from&&i.classList.add("cm-completionListIncompleteTop"),r.to<t.length&&i.classList.add("cm-completionListIncompleteBottom"),i}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function Uct(e,t){return n=>new Bct(n,e,t)}function qct(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.height/e.offsetHeight;r.top<n.top?e.scrollTop-=(n.top-r.top)/i:r.bottom>n.bottom&&(e.scrollTop+=(r.bottom-n.bottom)/i)}function cne(e){return(e.boost||0)*100+(e.apply?10:0)+(e.info?5:0)+(e.type?1:0)}function Kct(e,t){let n=[],r=null,i=null,a=d=>{n.push(d);let{section:f}=d.completion;if(f){r||(r=[]);let h=typeof f=="string"?f:f.name;r.some(g=>g.name==h)||r.push(typeof f=="string"?{name:h}:f)}},o=t.facet(ao);for(let d of e)if(d.hasResult()){let f=d.result.getMatch;if(d.result.filter===!1)for(let h of d.result.options)a(new ane(h,d.source,f?f(h):[],1e9-n.length));else{let h=t.sliceDoc(d.from,d.to),g,b=o.filterStrict?new $ct(h):new Lct(h);for(let v of d.result.options)if(g=b.match(v.label)){let j=v.displayLabel?f?f(v,g.matched):[]:g.matched,k=g.score+(v.boost||0);if(a(new ane(v,d.source,j,k)),typeof v.section=="object"&&v.section.rank==="dynamic"){let{name:w}=v.section;i||(i=Object.create(null)),i[w]=Math.max(k,i[w]||-1e9)}}}}if(r){let d=Object.create(null),f=0,h=(g,b)=>(g.rank==="dynamic"&&b.rank==="dynamic"?i[b.name]-i[g.name]:0)||(typeof g.rank=="number"?g.rank:1e9)-(typeof b.rank=="number"?b.rank:1e9)||(g.name<b.name?-1:1);for(let g of r.sort(h))f-=1e5,d[g.name]=f;for(let g of n){let{section:b}=g.completion;b&&(g.score+=d[typeof b=="string"?b:b.name])}}let l=[],c=null,u=o.compareCompletions;for(let d of n.sort((f,h)=>h.score-f.score||u(f.completion,h.completion))){let f=d.completion;!c||c.label!=f.label||c.detail!=f.detail||c.type!=null&&f.type!=null&&c.type!=f.type||c.apply!=f.apply||c.boost!=f.boost?l.push(d):cne(d.completion)>cne(c)&&(l[l.length-1]=d),c=d.completion}return l}class u3{constructor(t,n,r,i,a,o){this.options=t,this.attrs=n,this.tooltip=r,this.timestamp=i,this.selected=a,this.disabled=o}setSelected(t,n){return t==this.selected||t>=this.options.length?this:new u3(this.options,une(n,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,n,r,i,a,o){if(i&&!o&&t.some(u=>u.isPending))return i.setDisabled();let l=Kct(t,n);if(!l.length)return i&&t.some(u=>u.isPending)?i.setDisabled():null;let c=n.facet(ao).selectOnOpen?0:-1;if(i&&i.selected!=c&&i.selected!=-1){let u=i.options[i.selected].completion;for(let d=0;d<l.length;d++)if(l[d].completion==u){c=d;break}}return new u3(l,une(r,c),{pos:t.reduce((u,d)=>d.hasResult()?Math.min(u,d.from):u,1e8),create:Qct,above:a.aboveCursor},i?i.timestamp:Date.now(),c,!1)}map(t){return new u3(this.options,this.attrs,{...this.tooltip,pos:t.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new u3(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class QN{constructor(t,n,r){this.active=t,this.id=n,this.open=r}static start(){return new QN(Zct,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(t){let{state:n}=t,r=n.facet(ao),a=(r.override||n.languageDataAt("autocomplete",E2(n)).map(Dct)).map(c=>(this.active.find(d=>d.source==c)||new ku(c,this.active.some(d=>d.state!=0)?1:0)).update(t,r));a.length==this.active.length&&a.every((c,u)=>c==this.active[u])&&(a=this.active);let o=this.open,l=t.effects.some(c=>c.is(Yq));o&&t.docChanged&&(o=o.map(t.changes)),t.selection||a.some(c=>c.hasResult()&&t.changes.touchesRange(c.from,c.to))||!Hct(a,this.active)||l?o=u3.build(a,n,this.id,o,r,l):o&&o.disabled&&!a.some(c=>c.isPending)&&(o=null),!o&&a.every(c=>!c.isPending)&&a.some(c=>c.hasResult())&&(a=a.map(c=>c.hasResult()?new ku(c.source,0):c));for(let c of t.effects)c.is(Qq)&&(o=o&&o.setSelected(c.value,this.id));return a==this.active&&o==this.open?this:new QN(a,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Vct:Wct}}function Hct(e,t){if(e==t)return!0;for(let n=0,r=0;;){for(;n<e.length&&!e[n].hasResult();)n++;for(;r<t.length&&!t[r].hasResult();)r++;let i=n==e.length,a=r==t.length;if(i||a)return i==a;if(e[n++].result!=t[r++].result)return!1}}const Vct={"aria-autocomplete":"list"},Wct={};function une(e,t){let n={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":e};return t>-1&&(n["aria-activedescendant"]=e+"-"+t),n}const Zct=[];function s4e(e,t){if(e.isUserEvent("input.complete")){let r=e.annotation(Gq);if(r&&t.activateOnCompletion(r))return 12}let n=e.isUserEvent("input.type");return n&&t.activateOnTyping?5:n?1:e.isUserEvent("delete.backward")?2:e.selection?8:e.docChanged?16:0}class ku{constructor(t,n,r=!1){this.source=t,this.state=n,this.explicit=r}hasResult(){return!1}get isPending(){return this.state==1}update(t,n){let r=s4e(t,n),i=this;(r&8||r&16&&this.touches(t))&&(i=new ku(i.source,0)),r&4&&i.state==0&&(i=new ku(this.source,1)),i=i.updateFor(t,r);for(let a of t.effects)if(a.is(GN))i=new ku(i.source,1,a.value);else if(a.is(P6))i=new ku(i.source,0);else if(a.is(Yq))for(let o of a.value)o.source==i.source&&(i=o);return i}updateFor(t,n){return this.map(t.changes)}map(t){return this}touches(t){return t.changes.touchesRange(E2(t.state))}}class E3 extends ku{constructor(t,n,r,i,a,o){super(t,3,n),this.limit=r,this.result=i,this.from=a,this.to=o}hasResult(){return!0}updateFor(t,n){var r;if(!(n&3))return this.map(t.changes);let i=this.result;i.map&&!t.changes.empty&&(i=i.map(i,t.changes));let a=t.changes.mapPos(this.from),o=t.changes.mapPos(this.to,1),l=E2(t.state);if(l>o||!i||n&2&&(E2(t.startState)==this.from||l<this.limit))return new ku(this.source,n&4?1:0);let c=t.changes.mapPos(this.limit);return Gct(i.validFor,t.state,a,o)?new E3(this.source,this.explicit,c,i,a,o):i.update&&(i=i.update(i,a,o,new n4e(t.state,l,!1)))?new E3(this.source,this.explicit,c,i,i.from,(r=i.to)!==null&&r!==void 0?r:E2(t.state)):new ku(this.source,1,this.explicit)}map(t){return t.empty?this:(this.result.map?this.result.map(this.result,t):this.result)?new E3(this.source,this.explicit,t.mapPos(this.limit),this.result,t.mapPos(this.from),t.mapPos(this.to,1)):new ku(this.source,0)}touches(t){return t.changes.touchesRange(this.from,this.to)}}function Gct(e,t,n,r){if(!e)return!1;let i=t.sliceDoc(n,r);return typeof e=="function"?e(i,n,r,t):r4e(e,!0).test(i)}const Yq=ir.define({map(e,t){return e.map(n=>n.map(t))}}),ec=qo.define({create(){return QN.start()},update(e,t){return e.update(t)},provide:e=>[$q.from(e,t=>t.tooltip),Yt.contentAttributes.from(e,t=>t.attrs)]});function Jq(e,t){const n=t.completion.apply||t.completion.label;let r=e.state.field(ec).active.find(i=>i.source==t.source);return r instanceof E3?(typeof n=="string"?e.dispatch({...Pct(e.state,n,r.from,r.to),annotations:Gq.of(t.completion)}):n(e,t.completion,r.from,r.to),!0):!1}const Qct=Uct(ec,Jq);function T9(e,t="option"){return n=>{let r=n.state.field(ec,!1);if(!r||!r.open||r.open.disabled||Date.now()-r.open.timestamp<n.state.facet(ao).interactionDelay)return!1;let i=1,a;t=="page"&&(a=v5e(n,r.open.tooltip))&&(i=Math.max(2,Math.floor(a.dom.offsetHeight/a.dom.querySelector("li").offsetHeight)-1));let{length:o}=r.open.options,l=r.open.selected>-1?r.open.selected+i*(e?1:-1):e?0:o-1;return l<0?l=t=="page"?0:o-1:l>=o&&(l=t=="page"?o-1:0),n.dispatch({effects:Qq.of(l)}),!0}}const Yct=e=>{let t=e.state.field(ec,!1);return e.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<e.state.facet(ao).interactionDelay?!1:Jq(e,t.open.options[t.open.selected])},DM=e=>e.state.field(ec,!1)?(e.dispatch({effects:GN.of(!0)}),!0):!1,Jct=e=>{let t=e.state.field(ec,!1);return!t||!t.active.some(n=>n.state!=0)?!1:(e.dispatch({effects:P6.of(null)}),!0)};class Xct{constructor(t,n){this.active=t,this.context=n,this.time=Date.now(),this.updates=[],this.done=void 0}}const eut=50,tut=1e3,nut=ia.fromClass(class{constructor(e){this.view=e,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of e.state.field(ec).active)t.isPending&&this.startQuery(t)}update(e){let t=e.state.field(ec),n=e.state.facet(ao);if(!e.selectionSet&&!e.docChanged&&e.startState.field(ec)==t)return;let r=e.transactions.some(a=>{let o=s4e(a,n);return o&8||(a.selection||a.docChanged)&&!(o&3)});for(let a=0;a<this.running.length;a++){let o=this.running[a];if(r||o.context.abortOnDocChange&&e.docChanged||o.updates.length+e.transactions.length>eut&&Date.now()-o.time>tut){for(let l of o.context.abortListeners)try{l()}catch(c){rc(this.view.state,c)}o.context.abortListeners=null,this.running.splice(a--,1)}else o.updates.push(...e.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),e.transactions.some(a=>a.effects.some(o=>o.is(GN)))&&(this.pendingStart=!0);let i=this.pendingStart?50:n.activateOnTypingDelay;if(this.debounceUpdate=t.active.some(a=>a.isPending&&!this.running.some(o=>o.active.source==a.source))?setTimeout(()=>this.startUpdate(),i):-1,this.composing!=0)for(let a of e.transactions)a.isUserEvent("input.type")?this.composing=2:this.composing==2&&a.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:e}=this.view,t=e.field(ec);for(let n of t.active)n.isPending&&!this.running.some(r=>r.active.source==n.source)&&this.startQuery(n);this.running.length&&t.open&&t.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ao).updateSyncTime))}startQuery(e){let{state:t}=this.view,n=E2(t),r=new n4e(t,n,e.explicit,this.view),i=new Xct(e,r);this.running.push(i),Promise.resolve(e.source(r)).then(a=>{i.context.aborted||(i.done=a||null,this.scheduleAccept())},a=>{this.view.dispatch({effects:P6.of(null)}),rc(this.view.state,a)})}scheduleAccept(){this.running.every(e=>e.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ao).updateSyncTime))}accept(){var e;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let t=[],n=this.view.state.facet(ao),r=this.view.state.field(ec);for(let i=0;i<this.running.length;i++){let a=this.running[i];if(a.done===void 0)continue;if(this.running.splice(i--,1),a.done){let l=E2(a.updates.length?a.updates[0].startState:this.view.state),c=Math.min(l,a.done.from+(a.active.explicit?0:1)),u=new E3(a.active.source,a.active.explicit,c,a.done,a.done.from,(e=a.done.to)!==null&&e!==void 0?e:l);for(let d of a.updates)u=u.update(d,n);if(u.hasResult()){t.push(u);continue}}let o=r.active.find(l=>l.source==a.active.source);if(o&&o.isPending)if(a.done==null){let l=new ku(a.active.source,0);for(let c of a.updates)l=l.update(c,n);l.isPending||t.push(l)}else this.startQuery(o)}(t.length||r.open&&r.open.disabled)&&this.view.dispatch({effects:Yq.of(t)})}},{eventHandlers:{blur(e){let t=this.view.state.field(ec,!1);if(t&&t.tooltip&&this.view.state.facet(ao).closeOnBlur){let n=t.open&&v5e(this.view,t.open.tooltip);(!n||!n.dom.contains(e.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:P6.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:GN.of(!1)}),20),this.composing=0}}}),rut=typeof navigator=="object"&&/Win/.test(navigator.platform),sut=lg.highest(Yt.domEventHandlers({keydown(e,t){let n=t.state.field(ec,!1);if(!n||!n.open||n.open.disabled||n.open.selected<0||e.key.length>1||e.ctrlKey&&!(rut&&e.altKey)||e.metaKey)return!1;let r=n.open.options[n.open.selected],i=n.active.find(o=>o.source==r.source),a=r.completion.commitCharacters||i.result.commitCharacters;return a&&a.indexOf(e.key)>-1&&Jq(t,r),!1}})),i4e=Yt.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class iut{constructor(t,n,r,i){this.field=t,this.line=n,this.from=r,this.to=i}}class Xq{constructor(t,n,r){this.field=t,this.from=n,this.to=r}map(t){let n=t.mapPos(this.from,-1,To.TrackDel),r=t.mapPos(this.to,1,To.TrackDel);return n==null||r==null?null:new Xq(this.field,n,r)}}class eK{constructor(t,n){this.lines=t,this.fieldPositions=n}instantiate(t,n){let r=[],i=[n],a=t.doc.lineAt(n),o=/^\s*/.exec(a.text)[0];for(let c of this.lines){if(r.length){let u=o,d=/^\t*/.exec(c)[0].length;for(let f=0;f<d;f++)u+=t.facet(Q_);i.push(n+u.length-d),c=u+c.slice(d)}r.push(c),n+=c.length+1}let l=this.fieldPositions.map(c=>new Xq(c.field,i[c.line]+c.from,i[c.line]+c.to));return{text:r,ranges:l}}static parse(t){let n=[],r=[],i=[],a;for(let o of t.split(/\r\n?|\n/)){for(;a=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let l=a[1]?+a[1]:null,c=a[2]||a[3]||"",u=-1,d=c.replace(/\\[{}]/g,f=>f[1]);for(let f=0;f<n.length;f++)(l!=null?n[f].seq==l:d&&n[f].name==d)&&(u=f);if(u<0){let f=0;for(;f<n.length&&(l==null||n[f].seq!=null&&n[f].seq<l);)f++;n.splice(f,0,{seq:l,name:d}),u=f;for(let h of i)h.field>=u&&h.field++}for(let f of i)if(f.line==r.length&&f.from>a.index){let h=a[2]?3+(a[1]||"").length:2;f.from-=h,f.to-=h}i.push(new iut(u,r.length,a.index,a.index+d.length)),o=o.slice(0,a.index)+c+o.slice(a.index+a[0].length)}o=o.replace(/\\([{}])/g,(l,c,u)=>{for(let d of i)d.line==r.length&&d.from>u&&(d.from--,d.to--);return c}),r.push(o)}return new eK(r,i)}}let aut=$n.widget({widget:new class extends am{toDOM(){let e=document.createElement("span");return e.className="cm-snippetFieldPosition",e}ignoreEvent(){return!1}}}),out=$n.mark({class:"cm-snippetField"});class M4{constructor(t,n){this.ranges=t,this.active=n,this.deco=$n.set(t.map(r=>(r.from==r.to?aut:out).range(r.from,r.to)),!0)}map(t){let n=[];for(let r of this.ranges){let i=r.map(t);if(!i)return null;n.push(i)}return new M4(n,this.active)}selectionInsideField(t){return t.ranges.every(n=>this.ranges.some(r=>r.field==this.active&&r.from<=n.from&&r.to>=n.to))}}const Z7=ir.define({map(e,t){return e&&e.map(t)}}),lut=ir.define(),D6=qo.define({create(){return null},update(e,t){for(let n of t.effects){if(n.is(Z7))return n.value;if(n.is(lut)&&e)return new M4(e.ranges,n.value)}return e&&t.docChanged&&(e=e.map(t.changes)),e&&t.selection&&!e.selectionInsideField(t.selection)&&(e=null),e},provide:e=>Yt.decorations.from(e,t=>t?t.deco:$n.none)});function tK(e,t){return bt.create(e.filter(n=>n.field==t).map(n=>bt.range(n.from,n.to)))}function cut(e){let t=eK.parse(e);return(n,r,i,a)=>{let{text:o,ranges:l}=t.instantiate(n.state,i),{main:c}=n.state.selection,u={changes:{from:i,to:a==c.from?c.to:a,insert:ls.of(o)},scrollIntoView:!0,annotations:r?[Gq.of(r),ja.userEvent.of("input.complete")]:void 0};if(l.length&&(u.selection=tK(l,0)),l.some(d=>d.field>0)){let d=new M4(l,0),f=u.effects=[Z7.of(d)];n.state.field(D6,!1)===void 0&&f.push(ir.appendConfig.of([D6,hut,put,i4e]))}n.dispatch(n.state.update(u))}}function a4e(e){return({state:t,dispatch:n})=>{let r=t.field(D6,!1);if(!r||e<0&&r.active==0)return!1;let i=r.active+e,a=e>0&&!r.ranges.some(o=>o.field==i+e);return n(t.update({selection:tK(r.ranges,i),effects:Z7.of(a?null:new M4(r.ranges,i)),scrollIntoView:!0})),!0}}const uut=({state:e,dispatch:t})=>e.field(D6,!1)?(t(e.update({effects:Z7.of(null)})),!0):!1,dut=a4e(1),fut=a4e(-1),mut=[{key:"Tab",run:dut,shift:fut},{key:"Escape",run:uut}],dne=Jt.define({combine(e){return e.length?e[0]:mut}}),hut=lg.highest(H7.compute([dne],e=>e.facet(dne)));function gAt(e,t){return{...t,apply:cut(e)}}const put=Yt.domEventHandlers({mousedown(e,t){let n=t.state.field(D6,!1),r;if(!n||(r=t.posAtCoords({x:e.clientX,y:e.clientY}))==null)return!1;let i=n.ranges.find(a=>a.from<=r&&a.to>=r);return!i||i.field==n.active?!1:(t.dispatch({selection:tK(n.ranges,i.field),effects:Z7.of(n.ranges.some(a=>a.field>i.field)?new M4(n.ranges,i.field):null),scrollIntoView:!0}),!0)}}),L6={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},o2=ir.define({map(e,t){let n=t.mapPos(e,-1,To.TrackAfter);return n??void 0}}),nK=new class extends zp{};nK.startSide=1;nK.endSide=-1;const o4e=qo.define({create(){return Lr.empty},update(e,t){if(e=e.map(t.changes),t.selection){let n=t.state.doc.lineAt(t.selection.main.head);e=e.update({filter:r=>r>=n.from&&r<=n.to})}for(let n of t.effects)n.is(o2)&&(e=e.update({add:[nK.range(n.value,n.value+1)]}));return e}});function gut(){return[but,o4e]}const LM="()[]{}<>«»»«[]{}";function l4e(e){for(let t=0;t<LM.length;t+=2)if(LM.charCodeAt(t)==e)return LM.charAt(t+1);return wq(e<128?e:e+1)}function c4e(e,t){return e.languageDataAt("closeBrackets",t)[0]||L6}const xut=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),but=Yt.inputHandler.of((e,t,n,r)=>{if((xut?e.composing:e.compositionStarted)||e.state.readOnly)return!1;let i=e.state.selection.main;if(r.length>2||r.length==2&&wf(Xl(r,0))==1||t!=i.from||n!=i.to)return!1;let a=wut(e.state,r);return a?(e.dispatch(a),!0):!1}),yut=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=c4e(e,e.selection.main.head).brackets||L6.brackets,i=null,a=e.changeByRange(o=>{if(o.empty){let l=kut(e.doc,o.head);for(let c of r)if(c==l&&X_(e.doc,o.head)==l4e(Xl(c,0)))return{changes:{from:o.head-c.length,to:o.head+c.length},range:bt.cursor(o.head-c.length)}}return{range:i=o}});return i||t(e.update(a,{scrollIntoView:!0,userEvent:"delete.backward"})),!i},vut=[{key:"Backspace",run:yut}];function wut(e,t){let n=c4e(e,e.selection.main.head),r=n.brackets||L6.brackets;for(let i of r){let a=l4e(Xl(i,0));if(t==i)return a==i?Cut(e,i,r.indexOf(i+i+i)>-1,n):jut(e,i,a,n.before||L6.before);if(t==a&&u4e(e,e.selection.main.from))return Nut(e,i,a)}return null}function u4e(e,t){let n=!1;return e.field(o4e).between(0,e.doc.length,r=>{r==t&&(n=!0)}),n}function X_(e,t){let n=e.sliceString(t,t+2);return n.slice(0,wf(Xl(n,0)))}function kut(e,t){let n=e.sliceString(t-2,t);return wf(Xl(n,0))==n.length?n:n.slice(1)}function jut(e,t,n,r){let i=null,a=e.changeByRange(o=>{if(!o.empty)return{changes:[{insert:t,from:o.from},{insert:n,from:o.to}],effects:o2.of(o.to+t.length),range:bt.range(o.anchor+t.length,o.head+t.length)};let l=X_(e.doc,o.head);return!l||/\s/.test(l)||r.indexOf(l)>-1?{changes:{insert:t+n,from:o.head},effects:o2.of(o.head+t.length),range:bt.cursor(o.head+t.length)}:{range:i=o}});return i?null:e.update(a,{scrollIntoView:!0,userEvent:"input.type"})}function Nut(e,t,n){let r=null,i=e.changeByRange(a=>a.empty&&X_(e.doc,a.head)==n?{changes:{from:a.head,to:a.head+n.length,insert:n},range:bt.cursor(a.head+n.length)}:r={range:a});return r?null:e.update(i,{scrollIntoView:!0,userEvent:"input.type"})}function Cut(e,t,n,r){let i=r.stringPrefixes||L6.stringPrefixes,a=null,o=e.changeByRange(l=>{if(!l.empty)return{changes:[{insert:t,from:l.from},{insert:t,from:l.to}],effects:o2.of(l.to+t.length),range:bt.range(l.anchor+t.length,l.head+t.length)};let c=l.head,u=X_(e.doc,c),d;if(u==t){if(fne(e,c))return{changes:{insert:t+t,from:c},effects:o2.of(c+t.length),range:bt.cursor(c+t.length)};if(u4e(e,c)){let h=n&&e.sliceDoc(c,c+t.length*3)==t+t+t?t+t+t:t;return{changes:{from:c,to:c+h.length,insert:h},range:bt.cursor(c+h.length)}}}else{if(n&&e.sliceDoc(c-2*t.length,c)==t+t&&(d=mne(e,c-2*t.length,i))>-1&&fne(e,d))return{changes:{insert:t+t+t+t,from:c},effects:o2.of(c+t.length),range:bt.cursor(c+t.length)};if(e.charCategorizer(c)(u)!=yi.Word&&mne(e,c,i)>-1&&!Sut(e,c,t,i))return{changes:{insert:t+t,from:c},effects:o2.of(c+t.length),range:bt.cursor(c+t.length)}}return{range:a=l}});return a?null:e.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function fne(e,t){let n=Bo(e).resolveInner(t+1);return n.parent&&n.from==t}function Sut(e,t,n,r){let i=Bo(e).resolveInner(t,-1),a=r.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=e.sliceDoc(i.from,Math.min(i.to,i.from+n.length+a)),c=l.indexOf(n);if(!c||c>-1&&r.indexOf(l.slice(0,c))>-1){let d=i.firstChild;for(;d&&d.from==i.from&&d.to-d.from>n.length+c;){if(e.sliceDoc(d.to-n.length,d.to)==n)return!1;d=d.firstChild}return!0}let u=i.to==t&&i.parent;if(!u)break;i=u}return!1}function mne(e,t,n){let r=e.charCategorizer(t);if(r(e.sliceDoc(t-1,t))!=yi.Word)return t;for(let i of n){let a=t-i.length;if(e.sliceDoc(a,t)==i&&r(e.sliceDoc(a-1,a))!=yi.Word)return a}return-1}function _ut(e={}){return[sut,ec,ao.of(e),nut,Aut,i4e]}const d4e=[{key:"Ctrl-Space",run:DM},{mac:"Alt-`",run:DM},{mac:"Alt-i",run:DM},{key:"Escape",run:Jct},{key:"ArrowDown",run:T9(!0)},{key:"ArrowUp",run:T9(!1)},{key:"PageDown",run:T9(!0,"page")},{key:"PageUp",run:T9(!1,"page")},{key:"Enter",run:Yct}],Aut=lg.highest(H7.computeN([ao],e=>e.facet(ao).defaultKeymap?[d4e]:[])),Eut=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=sK(e.state,n.from);return r.line?Tut(e):r.block?Mut(e):!1};function rK(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}const Tut=rK(Put,0),Iut=rK(f4e,0),Mut=rK((e,t)=>f4e(e,t,Out(t)),0);function sK(e,t){let n=e.languageDataAt("commentTokens",t,1);return n.length?n[0]:{}}const oy=50;function Rut(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-oy,r),o=e.sliceDoc(i,i+oy),l=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,u=a.length-l;if(a.slice(u-t.length,u)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-l,margin:l&&1},close:{pos:i+c,margin:c&&1}};let d,f;i-r<=2*oy?d=f=e.sliceDoc(r,i):(d=e.sliceDoc(r,r+oy),f=e.sliceDoc(i-oy,i));let h=/^\s*/.exec(d)[0].length,g=/\s*$/.exec(f)[0].length,b=f.length-g-n.length;return d.slice(h,h+t.length)==t&&f.slice(b,b+n.length)==n?{open:{pos:r+h+t.length,margin:/\s/.test(d.charAt(h+t.length))?1:0},close:{pos:i-g-n.length,margin:/\s/.test(f.charAt(b-1))?1:0}}:null}function Out(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function f4e(e,t,n=t.selection.ranges){let r=n.map(a=>sK(t,a.from).block);if(!r.every(a=>a))return null;let i=n.map((a,o)=>Rut(t,r[o],a.from,a.to));if(e!=2&&!i.every(a=>a))return{changes:t.changes(n.map((a,o)=>i[o]?[]:[{from:a.from,insert:r[o].open+" "},{from:a.to,insert:" "+r[o].close}]))};if(e!=1&&i.some(a=>a)){let a=[];for(let o=0,l;o<i.length;o++)if(l=i[o]){let c=r[o],{open:u,close:d}=l;a.push({from:u.pos-c.open.length,to:u.pos+u.margin},{from:d.pos-d.margin,to:d.pos+c.close.length})}return{changes:a}}return null}function Put(e,t,n=t.selection.ranges){let r=[],i=-1;e:for(let{from:a,to:o}of n){let l=r.length,c=1e9,u;for(let d=a;d<=o;){let f=t.doc.lineAt(d);if(u==null&&(u=sK(t,f.from).line,!u))continue e;if(f.from>i&&(a==o||o>f.from)){i=f.from;let h=/^\s*/.exec(f.text)[0].length,g=h==f.length,b=f.text.slice(h,h+u.length)==u?h:-1;h<f.text.length&&h<c&&(c=h),r.push({line:f,comment:b,token:u,indent:h,empty:g,single:!1})}d=f.to+1}if(c<1e9)for(let d=l;d<r.length;d++)r[d].indent<r[d].line.text.length&&(r[d].indent=c);r.length==l+1&&(r[l].single=!0)}if(e!=2&&r.some(a=>a.comment<0&&(!a.empty||a.single))){let a=[];for(let{line:l,token:c,indent:u,empty:d,single:f}of r)(f||!d)&&a.push({from:l.from+u,insert:c+" "});let o=t.changes(a);return{changes:o,selection:t.selection.map(o,1)}}else if(e!=1&&r.some(a=>a.comment>=0)){let a=[];for(let{line:o,comment:l,token:c}of r)if(l>=0){let u=o.from+l,d=u+c.length;o.text[d-o.from]==" "&&d++,a.push({from:u,to:d})}return{changes:a}}return null}const qL=q1.define(),Dut=q1.define(),Lut=Jt.define(),m4e=Jt.define({combine(e){return im(e,{minDepth:100,newGroupDelay:500,joinToEvent:(t,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,n)=>(r,i)=>t(r,i)||n(r,i)})}}),h4e=qo.define({create(){return If.empty},update(e,t){let n=t.state.facet(m4e),r=t.annotation(qL);if(r){let c=sc.fromTransaction(t,r.selection),u=r.side,d=u==0?e.undone:e.done;return c?d=YN(d,d.length,n.minDepth,c):d=x4e(d,t.startState.selection),new If(u==0?r.rest:d,u==0?d:r.rest)}let i=t.annotation(Dut);if((i=="full"||i=="before")&&(e=e.isolate()),t.annotation(ja.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=sc.fromTransaction(t),o=t.annotation(ja.time),l=t.annotation(ja.userEvent);return a?e=e.addChanges(a,o,l,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,l,n.newGroupDelay)),(i=="full"||i=="after")&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(t=>t.toJSON()),undone:e.undone.map(t=>t.toJSON())}},fromJSON(e){return new If(e.done.map(sc.fromJSON),e.undone.map(sc.fromJSON))}});function $ut(e={}){return[h4e,m4e.of(e),Yt.domEventHandlers({beforeinput(t,n){let r=t.inputType=="historyUndo"?p4e:t.inputType=="historyRedo"?KL:null;return r?(t.preventDefault(),r(n)):!1}})]}function eA(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(h4e,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}const p4e=eA(0,!1),KL=eA(1,!1),Fut=eA(0,!0),zut=eA(1,!0);class sc{constructor(t,n,r,i,a){this.changes=t,this.effects=n,this.mapped=r,this.startSelection=i,this.selectionsAfter=a}setSelAfter(t){return new sc(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,n,r;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(i=>i.toJSON())}}static fromJSON(t){return new sc(t.changes&&Oa.fromJSON(t.changes),[],t.mapped&&Ff.fromJSON(t.mapped),t.startSelection&&bt.fromJSON(t.startSelection),t.selectionsAfter.map(bt.fromJSON))}static fromTransaction(t,n){let r=ju;for(let i of t.startState.facet(Lut)){let a=i(t);a.length&&(r=r.concat(a))}return!r.length&&t.changes.empty?null:new sc(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,ju)}static selection(t){return new sc(void 0,ju,void 0,void 0,t)}}function YN(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function But(e,t){let n=[],r=!1;return e.iterChangedRanges((i,a)=>n.push(i,a)),t.iterChangedRanges((i,a,o,l)=>{for(let c=0;c<n.length;){let u=n[c++],d=n[c++];l>=u&&o<=d&&(r=!0)}}),r}function Uut(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((n,r)=>n.empty!=t.ranges[r].empty).length===0}function g4e(e,t){return e.length?t.length?e.concat(t):e:t}const ju=[],qut=200;function x4e(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-qut));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),YN(e,e.length-1,1e9,n.setSelAfter(r)))}else return[sc.selection([t])]}function Kut(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function $M(e,t){if(!e.length)return e;let n=e.length,r=ju;for(;n;){let i=Hut(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let a=e.slice(0,n);return a[n-1]=i,a}else t=i.mapped,n--,r=i.selectionsAfter}return r.length?[sc.selection(r)]:ju}function Hut(e,t,n){let r=g4e(e.selectionsAfter.length?e.selectionsAfter.map(l=>l.map(t)):ju,n);if(!e.changes)return sc.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new sc(i,ir.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}const Vut=/^(input\.type|delete)($|\.)/;class If{constructor(t,n,r=0,i=void 0){this.done=t,this.undone=n,this.prevTime=r,this.prevUserEvent=i}isolate(){return this.prevTime?new If(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&t.changes&&(!r||Vut.test(r))&&(!l.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,But(l.changes,t.changes))||r=="input.type.compose")?o=YN(o,o.length-1,i.minDepth,new sc(t.changes.compose(l.changes),g4e(ir.mapEffects(t.effects,l.changes),l.effects),l.mapped,l.startSelection,ju)):o=YN(o,o.length,i.minDepth,t),new If(o,ju,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:ju;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&Uut(a[a.length-1],t)?this:new If(x4e(this.done,t),this.undone,n,r)}addMapping(t){return new If($M(this.done,t),$M(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,n,r){let i=t==0?this.done:this.undone;if(i.length==0)return null;let a=i[i.length-1],o=a.selectionsAfter[0]||(a.startSelection?a.startSelection.map(a.changes.invertedDesc,1):n.selection);if(r&&a.selectionsAfter.length)return n.update({selection:a.selectionsAfter[a.selectionsAfter.length-1],annotations:qL.of({side:t,rest:Kut(i),selection:o}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(a.changes){let l=i.length==1?ju:i.slice(0,i.length-1);return a.mapped&&(l=$M(l,a.mapped)),n.update({changes:a.changes,selection:a.startSelection,effects:a.effects,annotations:qL.of({side:t,rest:l,selection:o}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}If.empty=new If(ju,ju);const Wut=[{key:"Mod-z",run:p4e,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:KL,preventDefault:!0},{linux:"Ctrl-Shift-z",run:KL,preventDefault:!0},{key:"Mod-u",run:Fut,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:zut,preventDefault:!0}];function R4(e,t){return bt.create(e.ranges.map(t),e.mainIndex)}function Ud(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function qd({state:e,dispatch:t},n){let r=R4(e.selection,n);return r.eq(e.selection,!0)?!1:(t(Ud(e,r)),!0)}function tA(e,t){return bt.cursor(t?e.to:e.from)}function b4e(e,t){return qd(e,n=>n.empty?e.moveByChar(n,t):tA(n,t))}function dl(e){return e.textDirectionAt(e.state.selection.main.head)==Hs.LTR}const y4e=e=>b4e(e,!dl(e)),v4e=e=>b4e(e,dl(e));function w4e(e,t){return qd(e,n=>n.empty?e.moveByGroup(n,t):tA(n,t))}const Zut=e=>w4e(e,!dl(e)),Gut=e=>w4e(e,dl(e));function Qut(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function nA(e,t,n){let r=Bo(e).resolveInner(t.head),i=n?Or.closedBy:Or.openedBy;for(let c=t.head;;){let u=n?r.childAfter(c):r.childBefore(c);if(!u)break;Qut(e,u,i)?r=u:c=n?u.to:u.from}let a=r.type.prop(i),o,l;return a&&(o=n?Tf(e,r.from,1):Tf(e,r.to,-1))&&o.matched?l=n?o.end.to:o.end.from:l=n?r.to:r.from,bt.cursor(l,n?-1:1)}const Yut=e=>qd(e,t=>nA(e.state,t,!dl(e))),Jut=e=>qd(e,t=>nA(e.state,t,dl(e)));function k4e(e,t){return qd(e,n=>{if(!n.empty)return tA(n,t);let r=e.moveVertically(n,t);return r.head!=n.head?r:e.moveToLineBoundary(n,t)})}const j4e=e=>k4e(e,!1),N4e=e=>k4e(e,!0);function C4e(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let a of e.state.facet(Yt.scrollMargins)){let o=a(e);o!=null&&o.top&&(n=Math.max(o==null?void 0:o.top,n)),o!=null&&o.bottom&&(r=Math.max(o==null?void 0:o.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function S4e(e,t){let n=C4e(e),{state:r}=e,i=R4(r.selection,o=>o.empty?e.moveVertically(o,t,n.height):tA(o,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let o=e.coordsAtPos(r.selection.main.head),l=e.scrollDOM.getBoundingClientRect(),c=l.top+n.marginTop,u=l.bottom-n.marginBottom;o&&o.top>c&&o.bottom<u&&(a=Yt.scrollIntoView(i.main.head,{y:"start",yMargin:o.top-c}))}return e.dispatch(Ud(r,i),{effects:a}),!0}const hne=e=>S4e(e,!1),HL=e=>S4e(e,!0);function cg(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let a=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;a&&t.head!=r.from+a&&(i=bt.cursor(r.from+a))}return i}const Xut=e=>qd(e,t=>cg(e,t,!0)),edt=e=>qd(e,t=>cg(e,t,!1)),tdt=e=>qd(e,t=>cg(e,t,!dl(e))),ndt=e=>qd(e,t=>cg(e,t,dl(e))),rdt=e=>qd(e,t=>bt.cursor(e.lineBlockAt(t.head).from,1)),sdt=e=>qd(e,t=>bt.cursor(e.lineBlockAt(t.head).to,-1));function idt(e,t,n){let r=!1,i=R4(e.selection,a=>{let o=Tf(e,a.head,-1)||Tf(e,a.head,1)||a.head>0&&Tf(e,a.head-1,1)||a.head<e.doc.length&&Tf(e,a.head+1,-1);if(!o||!o.end)return a;r=!0;let l=o.start.from==a.head?o.end.to:o.end.from;return bt.cursor(l)});return r?(t(Ud(e,i)),!0):!1}const adt=({state:e,dispatch:t})=>idt(e,t);function Fu(e,t){let n=R4(e.state.selection,r=>{let i=t(r);return bt.range(r.anchor,i.head,i.goalColumn,i.bidiLevel||void 0,i.assoc)});return n.eq(e.state.selection)?!1:(e.dispatch(Ud(e.state,n)),!0)}function _4e(e,t){return Fu(e,n=>e.moveByChar(n,t))}const A4e=e=>_4e(e,!dl(e)),E4e=e=>_4e(e,dl(e));function T4e(e,t){return Fu(e,n=>e.moveByGroup(n,t))}const odt=e=>T4e(e,!dl(e)),ldt=e=>T4e(e,dl(e)),cdt=e=>Fu(e,t=>nA(e.state,t,!dl(e))),udt=e=>Fu(e,t=>nA(e.state,t,dl(e)));function I4e(e,t){return Fu(e,n=>e.moveVertically(n,t))}const M4e=e=>I4e(e,!1),R4e=e=>I4e(e,!0);function O4e(e,t){return Fu(e,n=>e.moveVertically(n,t,C4e(e).height))}const pne=e=>O4e(e,!1),gne=e=>O4e(e,!0),ddt=e=>Fu(e,t=>cg(e,t,!0)),fdt=e=>Fu(e,t=>cg(e,t,!1)),mdt=e=>Fu(e,t=>cg(e,t,!dl(e))),hdt=e=>Fu(e,t=>cg(e,t,dl(e))),pdt=e=>Fu(e,t=>bt.cursor(e.lineBlockAt(t.head).from)),gdt=e=>Fu(e,t=>bt.cursor(e.lineBlockAt(t.head).to)),xne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:0})),!0),bne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:e.doc.length})),!0),yne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:e.selection.main.anchor,head:0})),!0),vne=({state:e,dispatch:t})=>(t(Ud(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),xdt=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),bdt=({state:e,dispatch:t})=>{let n=rA(e).map(({from:r,to:i})=>bt.range(r,Math.min(i+1,e.doc.length)));return t(e.update({selection:bt.create(n),userEvent:"select"})),!0},ydt=({state:e,dispatch:t})=>{let n=R4(e.selection,r=>{let i=Bo(e),a=i.resolveStack(r.from,1);if(r.empty){let o=i.resolveStack(r.from,-1);o.node.from>=a.node.from&&o.node.to<=a.node.to&&(a=o)}for(let o=a;o;o=o.next){let{node:l}=o;if((l.from<r.from&&l.to>=r.to||l.to>r.to&&l.from<=r.from)&&o.next)return bt.range(l.to,l.from)}return r});return n.eq(e.selection)?!1:(t(Ud(e,n)),!0)};function P4e(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let a of n.selection.ranges){let o=n.doc.lineAt(a.head);if(t?o.to<e.state.doc.length:o.from>0)for(let l=a;;){let c=e.moveVertically(l,t);if(c.head<o.from||c.head>o.to){i.some(u=>u.head==c.head)||i.push(c);break}else{if(c.head==l.head)break;l=c}}}return i.length==r.ranges.length?!1:(e.dispatch(Ud(n,bt.create(i,i.length-1))),!0)}const vdt=e=>P4e(e,!1),wdt=e=>P4e(e,!0),kdt=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=bt.create([n.main]):n.main.empty||(r=bt.create([bt.cursor(n.main.head)])),r?(t(Ud(e,r)),!0):!1};function G7(e,t){if(e.state.readOnly)return!1;let n="delete.selection",{state:r}=e,i=r.changeByRange(a=>{let{from:o,to:l}=a;if(o==l){let c=t(a);c<o?(n="delete.backward",c=I9(e,c,!1)):c>o&&(n="delete.forward",c=I9(e,c,!0)),o=Math.min(o,c),l=Math.max(l,c)}else o=I9(e,o,!1),l=I9(e,l,!0);return o==l?{range:a}:{changes:{from:o,to:l},range:bt.cursor(o,o<a.head?-1:1)}});return i.changes.empty?!1:(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?Yt.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function I9(e,t,n){if(e instanceof Yt)for(let r of e.state.facet(Yt.atomicRanges).map(i=>i(e)))r.between(t,t,(i,a)=>{i<t&&a>t&&(t=n?a:i)});return t}const D4e=(e,t,n)=>G7(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),l,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,i-o.from))){if(l[l.length-1]==" ")return i-1;let u=I4(l,a.tabSize),d=u%h0(a)||h0(a);for(let f=0;f<d&&l[l.length-1-f]==" ";f++)i--;c=i}else c=lo(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=lo(o.text,c-o.from,!1,!1)+o.from);return c}),VL=e=>D4e(e,!1,!0),L4e=e=>D4e(e,!0,!1),$4e=(e,t)=>G7(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let l=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let c=lo(a.text,r-a.from,t)+a.from,u=a.text.slice(Math.min(r,c)-a.from,Math.max(r,c)-a.from),d=o(u);if(l!=null&&d!=l)break;(u!=" "||r!=n.head)&&(l=d),r=c}return r}),F4e=e=>$4e(e,!1),jdt=e=>$4e(e,!0),Ndt=e=>G7(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Cdt=e=>G7(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),Sdt=e=>G7(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),_dt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:ls.of(["",""])},range:bt.cursor(r.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},Adt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>{if(!r.empty||r.from==0||r.from==e.doc.length)return{range:r};let i=r.from,a=e.doc.lineAt(i),o=i==a.from?i-1:lo(a.text,i-a.from,!1)+a.from,l=i==a.to?i+1:lo(a.text,i-a.from,!0)+a.from;return{changes:{from:o,to:l,insert:e.doc.slice(i,l).append(e.doc.slice(o,i))},range:bt.cursor(l)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function rA(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let o=t[t.length-1];o.to=a.to,o.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function z4e(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let a of rA(e)){if(n?a.to==e.doc.length:a.from==0)continue;let o=e.doc.lineAt(n?a.to+1:a.from-1),l=o.length+1;if(n){r.push({from:a.to,to:o.to},{from:a.from,insert:o.text+e.lineBreak});for(let c of a.ranges)i.push(bt.range(Math.min(e.doc.length,c.anchor+l),Math.min(e.doc.length,c.head+l)))}else{r.push({from:o.from,to:a.from},{from:a.to,insert:e.lineBreak+o.text});for(let c of a.ranges)i.push(bt.range(c.anchor-l,c.head-l))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:bt.create(i,e.selection.mainIndex),userEvent:"move.line"})),!0):!1}const Edt=({state:e,dispatch:t})=>z4e(e,t,!1),Tdt=({state:e,dispatch:t})=>z4e(e,t,!0);function B4e(e,t,n){if(e.readOnly)return!1;let r=[];for(let a of rA(e))n?r.push({from:a.from,insert:e.doc.slice(a.from,a.to)+e.lineBreak}):r.push({from:a.to,insert:e.lineBreak+e.doc.slice(a.from,a.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Idt=({state:e,dispatch:t})=>B4e(e,t,!1),Mdt=({state:e,dispatch:t})=>B4e(e,t,!0),Rdt=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(rA(t).map(({from:i,to:a})=>(i>0?i--:a<t.doc.length&&a++,{from:i,to:a}))),r=R4(t.selection,i=>{let a;if(e.lineWrapping){let o=e.lineBlockAt(i.head),l=e.coordsAtPos(i.head,i.assoc||1);l&&(a=o.bottom+e.documentTop-l.bottom+e.defaultLineHeight/2)}return e.moveVertically(i,!0,a)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Odt(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=Bo(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(Or.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}const wne=U4e(!1),Pdt=U4e(!0);function U4e(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(i=>{let{from:a,to:o}=i,l=t.doc.lineAt(a),c=!e&&a==o&&Odt(t,a);e&&(a=o=(o<=l.to?l:t.doc.lineAt(o)).to);let u=new Y_(t,{simulateBreak:a,simulateDoubleBreak:!!c}),d=Kq(u,a);for(d==null&&(d=I4(/^\s*/.exec(t.doc.lineAt(a).text)[0],t.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;c?{from:a,to:o}=c:a>l.from&&a<l.from+100&&!/\S/.test(l.text.slice(0,a))&&(a=l.from);let f=["",R6(t,d)];return c&&f.push(R6(t,u.lineIndent(l.from,-1))),{changes:{from:a,to:o,insert:ls.of(f)},range:bt.cursor(a+1+f[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function iK(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let o=r.from;o<=r.to;){let l=e.doc.lineAt(o);l.number>n&&(r.empty||r.to>l.from)&&(t(l,i,r),n=l.number),o=l.to+1}let a=e.changes(i);return{changes:i,range:bt.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}const Ddt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new Y_(e,{overrideIndentation:a=>{let o=n[a];return o??-1}}),i=iK(e,(a,o,l)=>{let c=Kq(r,a.from);if(c==null)return;/\S/.test(a.text)||(c=0);let u=/^\s*/.exec(a.text)[0],d=R6(e,c);(u!=d||l.from<a.from+u.length)&&(n[a.from]=c,o.push({from:a.from,to:a.from+u.length,insert:d}))});return i.changes.empty||t(e.update(i,{userEvent:"indent"})),!0},q4e=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(iK(e,(n,r)=>{r.push({from:n.from,insert:e.facet(Q_)})}),{userEvent:"input.indent"})),!0),K4e=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(iK(e,(n,r)=>{let i=/^\s*/.exec(n.text)[0];if(!i)return;let a=I4(i,e.tabSize),o=0,l=R6(e,Math.max(0,a-h0(e)));for(;o<i.length&&o<l.length&&i.charCodeAt(o)==l.charCodeAt(o);)o++;r.push({from:n.from+o,to:n.from+i.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Ldt=e=>(e.setTabFocusMode(),!0),$dt=[{key:"Ctrl-b",run:y4e,shift:A4e,preventDefault:!0},{key:"Ctrl-f",run:v4e,shift:E4e},{key:"Ctrl-p",run:j4e,shift:M4e},{key:"Ctrl-n",run:N4e,shift:R4e},{key:"Ctrl-a",run:rdt,shift:pdt},{key:"Ctrl-e",run:sdt,shift:gdt},{key:"Ctrl-d",run:L4e},{key:"Ctrl-h",run:VL},{key:"Ctrl-k",run:Ndt},{key:"Ctrl-Alt-h",run:F4e},{key:"Ctrl-o",run:_dt},{key:"Ctrl-t",run:Adt},{key:"Ctrl-v",run:HL}],Fdt=[{key:"ArrowLeft",run:y4e,shift:A4e,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Zut,shift:odt,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:tdt,shift:mdt,preventDefault:!0},{key:"ArrowRight",run:v4e,shift:E4e,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Gut,shift:ldt,preventDefault:!0},{mac:"Cmd-ArrowRight",run:ndt,shift:hdt,preventDefault:!0},{key:"ArrowUp",run:j4e,shift:M4e,preventDefault:!0},{mac:"Cmd-ArrowUp",run:xne,shift:yne},{mac:"Ctrl-ArrowUp",run:hne,shift:pne},{key:"ArrowDown",run:N4e,shift:R4e,preventDefault:!0},{mac:"Cmd-ArrowDown",run:bne,shift:vne},{mac:"Ctrl-ArrowDown",run:HL,shift:gne},{key:"PageUp",run:hne,shift:pne},{key:"PageDown",run:HL,shift:gne},{key:"Home",run:edt,shift:fdt,preventDefault:!0},{key:"Mod-Home",run:xne,shift:yne},{key:"End",run:Xut,shift:ddt,preventDefault:!0},{key:"Mod-End",run:bne,shift:vne},{key:"Enter",run:wne,shift:wne},{key:"Mod-a",run:xdt},{key:"Backspace",run:VL,shift:VL,preventDefault:!0},{key:"Delete",run:L4e,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:F4e,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:jdt,preventDefault:!0},{mac:"Mod-Backspace",run:Cdt,preventDefault:!0},{mac:"Mod-Delete",run:Sdt,preventDefault:!0}].concat($dt.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),zdt=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Yut,shift:cdt},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Jut,shift:udt},{key:"Alt-ArrowUp",run:Edt},{key:"Shift-Alt-ArrowUp",run:Idt},{key:"Alt-ArrowDown",run:Tdt},{key:"Shift-Alt-ArrowDown",run:Mdt},{key:"Mod-Alt-ArrowUp",run:vdt},{key:"Mod-Alt-ArrowDown",run:wdt},{key:"Escape",run:kdt},{key:"Mod-Enter",run:Pdt},{key:"Alt-l",mac:"Ctrl-l",run:bdt},{key:"Mod-i",run:ydt,preventDefault:!0},{key:"Mod-[",run:K4e},{key:"Mod-]",run:q4e},{key:"Mod-Alt-\\",run:Ddt},{key:"Shift-Mod-k",run:Rdt},{key:"Shift-Mod-\\",run:adt},{key:"Mod-/",run:Eut},{key:"Alt-A",run:Iut},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Ldt}].concat(Fdt),Bdt={key:"Tab",run:q4e,shift:K4e};function Udt(e,t,n,r){const i=Wf(bi),a=Mc(C0e),o=se.useRef(null),{lexicalNode:l}=eL(),c=se.useRef(!1),u=se.useRef(!1),d=se.useCallback(()=>{a({editorType:t,rootNode:l,editorRef:o.current})},[t,l,a]),f=se.useCallback(h=>{var g,b,v,j,k,w;if(h.key==="ArrowDown"){const N=(b=(g=o.current)==null?void 0:g.getCodemirror())==null?void 0:b.state;if(N){const C=N.doc.length,A=N.selection.ranges[0].to;C===A&&(c.current?(i==null||i.update(()=>{var _,E;const T=$f(e);T.getNextSibling()?((E=(_=o.current)==null?void 0:_.getCodemirror())==null||E.contentDOM.blur(),T.selectNext()):T.insertAfter(Zs())}),c.current=!1):c.current=!0)}}else if(h.key==="ArrowUp"){const N=(j=(v=o.current)==null?void 0:v.getCodemirror())==null?void 0:j.state;N&&N.selection.ranges[0].from===0&&(u.current?(i==null||i.update(()=>{var A,_;const E=$f(e);E.getPreviousSibling()&&((_=(A=o.current)==null?void 0:A.getCodemirror())==null||_.contentDOM.blur(),E.selectPrevious())}),u.current=!1):u.current=!0)}else if(h.key==="Enter")h.stopPropagation();else if(h.key==="Backspace"||h.key==="Delete"){const N=(w=(k=o.current)==null?void 0:k.getCodemirror())==null?void 0:w.state;(N==null?void 0:N.doc.length)===0&&(i==null||i.update(()=>{$f(e).remove()}))}},[i,e]);return se.useEffect(()=>{const h=o.current;return setTimeout(()=>{var g,b;(g=h==null?void 0:h.getCodemirror())==null||g.contentDOM.addEventListener("focus",d),(b=h==null?void 0:h.getCodemirror())==null||b.contentDOM.addEventListener("keydown",f)},300),()=>{var g,b;(g=h==null?void 0:h.getCodemirror())==null||g.contentDOM.removeEventListener("focus",d),(b=h==null?void 0:h.getCodemirror())==null||b.contentDOM.removeEventListener("keydown",f)}},[o,d,f,n]),se.useEffect(()=>{r.subscribe(()=>{var h,g;(g=(h=o.current)==null?void 0:h.getCodemirror())==null||g.focus(),d()})},[r,o,e,d]),o}function Ct(e){return new Ult(Vq.define(e))}function wh(e){return mt(()=>import("./index-HtPOAsph.js"),__vite__mapDeps([0,1])).then(t=>t.sql({dialect:t[e]}))}const qdt=[ot.of({name:"C",extensions:["c","h","ino"],load(){return mt(()=>import("./index-IQg-mKY2.js"),__vite__mapDeps([2,1])).then(e=>e.cpp())}}),ot.of({name:"C++",alias:["cpp"],extensions:["cpp","c++","cc","cxx","hpp","h++","hh","hxx"],load(){return mt(()=>import("./index-IQg-mKY2.js"),__vite__mapDeps([2,1])).then(e=>e.cpp())}}),ot.of({name:"CQL",alias:["cassandra"],extensions:["cql"],load(){return wh("Cassandra")}}),ot.of({name:"CSS",extensions:["css"],load(){return mt(()=>import("./index-Br5zwB0Z.js"),__vite__mapDeps([3,1])).then(e=>e.css())}}),ot.of({name:"Go",extensions:["go"],load(){return mt(()=>import("./index-DyAGGhVR.js"),__vite__mapDeps([4,1])).then(e=>e.go())}}),ot.of({name:"HTML",alias:["xhtml"],extensions:["html","htm","handlebars","hbs"],load(){return mt(()=>import("./index-CUmK5YNa.js"),__vite__mapDeps([5,1,3,6])).then(e=>e.html())}}),ot.of({name:"Java",extensions:["java"],load(){return mt(()=>import("./index-D_H502gP.js"),__vite__mapDeps([7,1])).then(e=>e.java())}}),ot.of({name:"JavaScript",alias:["ecmascript","js","node"],extensions:["js","mjs","cjs"],load(){return mt(()=>import("./index-BF94W45f.js"),__vite__mapDeps([6,1])).then(e=>e.javascript())}}),ot.of({name:"Jinja",extensions:["j2","jinja","jinja2"],load(){return mt(()=>import("./index-RDOFpY3r.js"),__vite__mapDeps([8,5,1,3,6])).then(e=>e.jinja())}}),ot.of({name:"JSON",alias:["json5"],extensions:["json","map"],load(){return mt(()=>import("./index-D7g9B35Q.js"),__vite__mapDeps([9,1])).then(e=>e.json())}}),ot.of({name:"JSX",extensions:["jsx"],load(){return mt(()=>import("./index-BF94W45f.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({jsx:!0}))}}),ot.of({name:"LESS",extensions:["less"],load(){return mt(()=>import("./index-BNFWBcMX.js"),__vite__mapDeps([10,3,1])).then(e=>e.less())}}),ot.of({name:"Liquid",extensions:["liquid"],load(){return mt(()=>import("./index-RV97u8HI.js"),__vite__mapDeps([11,5,1,3,6])).then(e=>e.liquid())}}),ot.of({name:"MariaDB SQL",load(){return wh("MariaSQL")}}),ot.of({name:"Markdown",extensions:["md","markdown","mkd"],load(){return mt(()=>import("./index-CBJ1GRlx.js"),__vite__mapDeps([12,5,1,3,6])).then(e=>e.markdown())}}),ot.of({name:"MS SQL",load(){return wh("MSSQL")}}),ot.of({name:"MySQL",load(){return wh("MySQL")}}),ot.of({name:"PHP",extensions:["php","php3","php4","php5","php7","phtml"],load(){return mt(()=>import("./index-Cnn7Ze7A.js"),__vite__mapDeps([13,1,5,3,6])).then(e=>e.php())}}),ot.of({name:"PLSQL",extensions:["pls"],load(){return wh("PLSQL")}}),ot.of({name:"PostgreSQL",load(){return wh("PostgreSQL")}}),ot.of({name:"Python",extensions:["BUILD","bzl","py","pyw"],filename:/^(BUCK|BUILD)$/,load(){return mt(()=>import("./index-BjDcoM23.js"),__vite__mapDeps([14,1])).then(e=>e.python())}}),ot.of({name:"Rust",extensions:["rs"],load(){return mt(()=>import("./index-DQIgDJJD.js"),__vite__mapDeps([15,1])).then(e=>e.rust())}}),ot.of({name:"Sass",extensions:["sass"],load(){return mt(()=>import("./index-CxutLWF3.js"),__vite__mapDeps([16,1,3])).then(e=>e.sass({indented:!0}))}}),ot.of({name:"SCSS",extensions:["scss"],load(){return mt(()=>import("./index-CxutLWF3.js"),__vite__mapDeps([16,1,3])).then(e=>e.sass())}}),ot.of({name:"SQL",extensions:["sql"],load(){return wh("StandardSQL")}}),ot.of({name:"SQLite",load(){return wh("SQLite")}}),ot.of({name:"TSX",extensions:["tsx"],load(){return mt(()=>import("./index-BF94W45f.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({jsx:!0,typescript:!0}))}}),ot.of({name:"TypeScript",alias:["ts"],extensions:["ts","mts","cts"],load(){return mt(()=>import("./index-BF94W45f.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({typescript:!0}))}}),ot.of({name:"WebAssembly",extensions:["wat","wast"],load(){return mt(()=>import("./index-DRi3oX80.js"),__vite__mapDeps([17,1])).then(e=>e.wast())}}),ot.of({name:"XML",alias:["rss","wsdl","xsd"],extensions:["xml","xsl","xsd","svg"],load(){return mt(()=>import("./index-PghKETw5.js"),__vite__mapDeps([18,1])).then(e=>e.xml())}}),ot.of({name:"YAML",alias:["yml"],extensions:["yaml","yml"],load(){return mt(()=>import("./index-BwOeluhm.js"),__vite__mapDeps([19,1])).then(e=>e.yaml())}}),ot.of({name:"APL",extensions:["dyalog","apl"],load(){return mt(()=>import("./apl-B4CMkyY2.js"),[]).then(e=>Ct(e.apl))}}),ot.of({name:"PGP",alias:["asciiarmor"],extensions:["asc","pgp","sig"],load(){return mt(()=>import("./asciiarmor-Df11BRmG.js"),[]).then(e=>Ct(e.asciiArmor))}}),ot.of({name:"ASN.1",extensions:["asn","asn1"],load(){return mt(()=>import("./asn1-EdZsLKOL.js"),[]).then(e=>Ct(e.asn1({})))}}),ot.of({name:"Asterisk",filename:/^extensions\.conf$/i,load(){return mt(()=>import("./asterisk-B-8jnY81.js"),[]).then(e=>Ct(e.asterisk))}}),ot.of({name:"Brainfuck",extensions:["b","bf"],load(){return mt(()=>import("./brainfuck-C4LP7Hcl.js"),[]).then(e=>Ct(e.brainfuck))}}),ot.of({name:"Cobol",extensions:["cob","cpy"],load(){return mt(()=>import("./cobol-CWcv1MsR.js"),[]).then(e=>Ct(e.cobol))}}),ot.of({name:"C#",alias:["csharp","cs"],extensions:["cs"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.csharp))}}),ot.of({name:"Clojure",extensions:["clj","cljc","cljx"],load(){return mt(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>Ct(e.clojure))}}),ot.of({name:"ClojureScript",extensions:["cljs"],load(){return mt(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>Ct(e.clojure))}}),ot.of({name:"Closure Stylesheets (GSS)",extensions:["gss"],load(){return mt(()=>import("./css-BnMrqG3P.js"),[]).then(e=>Ct(e.gss))}}),ot.of({name:"CMake",extensions:["cmake","cmake.in"],filename:/^CMakeLists\.txt$/,load(){return mt(()=>import("./cmake-BQqOBYOt.js"),[]).then(e=>Ct(e.cmake))}}),ot.of({name:"CoffeeScript",alias:["coffee","coffee-script"],extensions:["coffee"],load(){return mt(()=>import("./coffeescript-S37ZYGWr.js"),[]).then(e=>Ct(e.coffeeScript))}}),ot.of({name:"Common Lisp",alias:["lisp"],extensions:["cl","lisp","el"],load(){return mt(()=>import("./commonlisp-DBKNyK5s.js"),[]).then(e=>Ct(e.commonLisp))}}),ot.of({name:"Cypher",extensions:["cyp","cypher"],load(){return mt(()=>import("./cypher-C_CwsFkJ.js"),[]).then(e=>Ct(e.cypher))}}),ot.of({name:"Cython",extensions:["pyx","pxd","pxi"],load(){return mt(()=>import("./python-BuPzkPfP.js"),[]).then(e=>Ct(e.cython))}}),ot.of({name:"Crystal",extensions:["cr"],load(){return mt(()=>import("./crystal-SjHAIU92.js"),[]).then(e=>Ct(e.crystal))}}),ot.of({name:"D",extensions:["d"],load(){return mt(()=>import("./d-pRatUO7H.js"),[]).then(e=>Ct(e.d))}}),ot.of({name:"Dart",extensions:["dart"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.dart))}}),ot.of({name:"diff",extensions:["diff","patch"],load(){return mt(()=>import("./diff-DbItnlRl.js"),[]).then(e=>Ct(e.diff))}}),ot.of({name:"Dockerfile",filename:/^Dockerfile$/,load(){return mt(()=>import("./dockerfile-BKs6k2Af.js"),__vite__mapDeps([20,21])).then(e=>Ct(e.dockerFile))}}),ot.of({name:"DTD",extensions:["dtd"],load(){return mt(()=>import("./dtd-DF_7sFjM.js"),[]).then(e=>Ct(e.dtd))}}),ot.of({name:"Dylan",extensions:["dylan","dyl","intr"],load(){return mt(()=>import("./dylan-DwRh75JA.js"),[]).then(e=>Ct(e.dylan))}}),ot.of({name:"EBNF",load(){return mt(()=>import("./ebnf-CDyGwa7X.js"),[]).then(e=>Ct(e.ebnf))}}),ot.of({name:"ECL",extensions:["ecl"],load(){return mt(()=>import("./ecl-Cabwm37j.js"),[]).then(e=>Ct(e.ecl))}}),ot.of({name:"edn",extensions:["edn"],load(){return mt(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>Ct(e.clojure))}}),ot.of({name:"Eiffel",extensions:["e"],load(){return mt(()=>import("./eiffel-CnydiIhH.js"),[]).then(e=>Ct(e.eiffel))}}),ot.of({name:"Elm",extensions:["elm"],load(){return mt(()=>import("./elm-vLlmbW-K.js"),[]).then(e=>Ct(e.elm))}}),ot.of({name:"Erlang",extensions:["erl"],load(){return mt(()=>import("./erlang-BNw1qcRV.js"),[]).then(e=>Ct(e.erlang))}}),ot.of({name:"Esper",load(){return mt(()=>import("./sql-D0XecflT.js"),[]).then(e=>Ct(e.esper))}}),ot.of({name:"Factor",extensions:["factor"],load(){return mt(()=>import("./factor-kuTfRLto.js"),__vite__mapDeps([22,21])).then(e=>Ct(e.factor))}}),ot.of({name:"FCL",load(){return mt(()=>import("./fcl-Kvtd6kyn.js"),[]).then(e=>Ct(e.fcl))}}),ot.of({name:"Forth",extensions:["forth","fth","4th"],load(){return mt(()=>import("./forth-Ffai-XNe.js"),[]).then(e=>Ct(e.forth))}}),ot.of({name:"Fortran",extensions:["f","for","f77","f90","f95"],load(){return mt(()=>import("./fortran-DYz_wnZ1.js"),[]).then(e=>Ct(e.fortran))}}),ot.of({name:"F#",alias:["fsharp"],extensions:["fs"],load(){return mt(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>Ct(e.fSharp))}}),ot.of({name:"Gas",extensions:["s"],load(){return mt(()=>import("./gas-Bneqetm1.js"),[]).then(e=>Ct(e.gas))}}),ot.of({name:"Gherkin",extensions:["feature"],load(){return mt(()=>import("./gherkin-heZmZLOM.js"),[]).then(e=>Ct(e.gherkin))}}),ot.of({name:"Groovy",extensions:["groovy","gradle"],filename:/^Jenkinsfile$/,load(){return mt(()=>import("./groovy-D9Dt4D0W.js"),[]).then(e=>Ct(e.groovy))}}),ot.of({name:"Haskell",extensions:["hs"],load(){return mt(()=>import("./haskell-Cw1EW3IL.js"),[]).then(e=>Ct(e.haskell))}}),ot.of({name:"Haxe",extensions:["hx"],load(){return mt(()=>import("./haxe-H-WmDvRZ.js"),[]).then(e=>Ct(e.haxe))}}),ot.of({name:"HXML",extensions:["hxml"],load(){return mt(()=>import("./haxe-H-WmDvRZ.js"),[]).then(e=>Ct(e.hxml))}}),ot.of({name:"HTTP",load(){return mt(()=>import("./http-DBlCnlav.js"),[]).then(e=>Ct(e.http))}}),ot.of({name:"IDL",extensions:["pro"],load(){return mt(()=>import("./idl-BEugSyMb.js"),[]).then(e=>Ct(e.idl))}}),ot.of({name:"JSON-LD",alias:["jsonld"],extensions:["jsonld"],load(){return mt(()=>import("./javascript-iXu5QeM3.js"),[]).then(e=>Ct(e.jsonld))}}),ot.of({name:"Julia",extensions:["jl"],load(){return mt(()=>import("./julia-DuME0IfC.js"),[]).then(e=>Ct(e.julia))}}),ot.of({name:"Kotlin",extensions:["kt","kts"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.kotlin))}}),ot.of({name:"LiveScript",alias:["ls"],extensions:["ls"],load(){return mt(()=>import("./livescript-BwQOo05w.js"),[]).then(e=>Ct(e.liveScript))}}),ot.of({name:"Lua",extensions:["lua"],load(){return mt(()=>import("./lua-BgMRiT3U.js"),[]).then(e=>Ct(e.lua))}}),ot.of({name:"mIRC",extensions:["mrc"],load(){return mt(()=>import("./mirc-CjQqDB4T.js"),[]).then(e=>Ct(e.mirc))}}),ot.of({name:"Mathematica",extensions:["m","nb","wl","wls"],load(){return mt(()=>import("./mathematica-DTrFuWx2.js"),[]).then(e=>Ct(e.mathematica))}}),ot.of({name:"Modelica",extensions:["mo"],load(){return mt(()=>import("./modelica-Dc1JOy9r.js"),[]).then(e=>Ct(e.modelica))}}),ot.of({name:"MUMPS",extensions:["mps"],load(){return mt(()=>import("./mumps-BT43cFF4.js"),[]).then(e=>Ct(e.mumps))}}),ot.of({name:"Mbox",extensions:["mbox"],load(){return mt(()=>import("./mbox-CNhZ1qSd.js"),[]).then(e=>Ct(e.mbox))}}),ot.of({name:"Nginx",filename:/nginx.*\.conf$/i,load(){return mt(()=>import("./nginx-DdIZxoE0.js"),[]).then(e=>Ct(e.nginx))}}),ot.of({name:"NSIS",extensions:["nsh","nsi"],load(){return mt(()=>import("./nsis-LdVXkNf5.js"),__vite__mapDeps([23,21])).then(e=>Ct(e.nsis))}}),ot.of({name:"NTriples",extensions:["nt","nq"],load(){return mt(()=>import("./ntriples-BfvgReVJ.js"),[]).then(e=>Ct(e.ntriples))}}),ot.of({name:"Objective-C",alias:["objective-c","objc"],extensions:["m"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.objectiveC))}}),ot.of({name:"Objective-C++",alias:["objective-c++","objc++"],extensions:["mm"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.objectiveCpp))}}),ot.of({name:"OCaml",extensions:["ml","mli","mll","mly"],load(){return mt(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>Ct(e.oCaml))}}),ot.of({name:"Octave",extensions:["m"],load(){return mt(()=>import("./octave-Ck1zUtKM.js"),[]).then(e=>Ct(e.octave))}}),ot.of({name:"Oz",extensions:["oz"],load(){return mt(()=>import("./oz-BzwKVEFT.js"),[]).then(e=>Ct(e.oz))}}),ot.of({name:"Pascal",extensions:["p","pas"],load(){return mt(()=>import("./pascal--L3eBynH.js"),[]).then(e=>Ct(e.pascal))}}),ot.of({name:"Perl",extensions:["pl","pm"],load(){return mt(()=>import("./perl-CdXCOZ3F.js"),[]).then(e=>Ct(e.perl))}}),ot.of({name:"Pig",extensions:["pig"],load(){return mt(()=>import("./pig-CevX1Tat.js"),[]).then(e=>Ct(e.pig))}}),ot.of({name:"PowerShell",extensions:["ps1","psd1","psm1"],load(){return mt(()=>import("./powershell-CFHJl5sT.js"),[]).then(e=>Ct(e.powerShell))}}),ot.of({name:"Properties files",alias:["ini","properties"],extensions:["properties","ini","in"],load(){return mt(()=>import("./properties-C78fOPTZ.js"),[]).then(e=>Ct(e.properties))}}),ot.of({name:"ProtoBuf",extensions:["proto"],load(){return mt(()=>import("./protobuf-ChK-085T.js"),[]).then(e=>Ct(e.protobuf))}}),ot.of({name:"Pug",alias:["jade"],extensions:["pug","jade"],load(){return mt(()=>import("./pug-DeIclll2.js"),__vite__mapDeps([24,25])).then(e=>Ct(e.pug))}}),ot.of({name:"Puppet",extensions:["pp"],load(){return mt(()=>import("./puppet-DMA9R1ak.js"),[]).then(e=>Ct(e.puppet))}}),ot.of({name:"Q",extensions:["q"],load(){return mt(()=>import("./q-pXgVlZs6.js"),[]).then(e=>Ct(e.q))}}),ot.of({name:"R",alias:["rscript"],extensions:["r","R"],load(){return mt(()=>import("./r-B6wPVr8A.js"),[]).then(e=>Ct(e.r))}}),ot.of({name:"RPM Changes",load(){return mt(()=>import("./rpm-CTu-6PCP.js"),[]).then(e=>Ct(e.rpmChanges))}}),ot.of({name:"RPM Spec",extensions:["spec"],load(){return mt(()=>import("./rpm-CTu-6PCP.js"),[]).then(e=>Ct(e.rpmSpec))}}),ot.of({name:"Ruby",alias:["jruby","macruby","rake","rb","rbx"],extensions:["rb"],filename:/^(Gemfile|Rakefile)$/,load(){return mt(()=>import("./ruby-B2Rjki9n.js"),[]).then(e=>Ct(e.ruby))}}),ot.of({name:"SAS",extensions:["sas"],load(){return mt(()=>import("./sas-B4kiWyti.js"),[]).then(e=>Ct(e.sas))}}),ot.of({name:"Scala",extensions:["scala"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.scala))}}),ot.of({name:"Scheme",extensions:["scm","ss"],load(){return mt(()=>import("./scheme-C41bIUwD.js"),[]).then(e=>Ct(e.scheme))}}),ot.of({name:"Shell",alias:["bash","sh","zsh"],extensions:["sh","ksh","bash"],filename:/^PKGBUILD$/,load(){return mt(()=>import("./shell-CjFT_Tl9.js"),[]).then(e=>Ct(e.shell))}}),ot.of({name:"Sieve",extensions:["siv","sieve"],load(){return mt(()=>import("./sieve-C3Gn_uJK.js"),[]).then(e=>Ct(e.sieve))}}),ot.of({name:"Smalltalk",extensions:["st"],load(){return mt(()=>import("./smalltalk-CnHTOXQT.js"),[]).then(e=>Ct(e.smalltalk))}}),ot.of({name:"Solr",load(){return mt(()=>import("./solr-DehyRSwq.js"),[]).then(e=>Ct(e.solr))}}),ot.of({name:"SML",extensions:["sml","sig","fun","smackspec"],load(){return mt(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>Ct(e.sml))}}),ot.of({name:"SPARQL",alias:["sparul"],extensions:["rq","sparql"],load(){return mt(()=>import("./sparql-DkYu6x3z.js"),[]).then(e=>Ct(e.sparql))}}),ot.of({name:"Spreadsheet",alias:["excel","formula"],load(){return mt(()=>import("./spreadsheet-BCZA_wO0.js"),[]).then(e=>Ct(e.spreadsheet))}}),ot.of({name:"Squirrel",extensions:["nut"],load(){return mt(()=>import("./clike-B9uivgTg.js"),[]).then(e=>Ct(e.squirrel))}}),ot.of({name:"Stylus",extensions:["styl"],load(){return mt(()=>import("./stylus-B533Al4x.js"),[]).then(e=>Ct(e.stylus))}}),ot.of({name:"Swift",extensions:["swift"],load(){return mt(()=>import("./swift-BzpIVaGY.js"),[]).then(e=>Ct(e.swift))}}),ot.of({name:"sTeX",load(){return mt(()=>import("./stex-C3f8Ysf7.js"),[]).then(e=>Ct(e.stex))}}),ot.of({name:"LaTeX",alias:["tex"],extensions:["text","ltx","tex"],load(){return mt(()=>import("./stex-C3f8Ysf7.js"),[]).then(e=>Ct(e.stex))}}),ot.of({name:"SystemVerilog",extensions:["v","sv","svh"],load(){return mt(()=>import("./verilog-C6RDOZhf.js"),[]).then(e=>Ct(e.verilog))}}),ot.of({name:"Tcl",extensions:["tcl"],load(){return mt(()=>import("./tcl-DVfN8rqt.js"),[]).then(e=>Ct(e.tcl))}}),ot.of({name:"Textile",extensions:["textile"],load(){return mt(()=>import("./textile-CnDTJFAw.js"),[]).then(e=>Ct(e.textile))}}),ot.of({name:"TiddlyWiki",load(){return mt(()=>import("./tiddlywiki-DO-Gjzrf.js"),[]).then(e=>Ct(e.tiddlyWiki))}}),ot.of({name:"Tiki wiki",load(){return mt(()=>import("./tiki-DGYXhP31.js"),[]).then(e=>Ct(e.tiki))}}),ot.of({name:"TOML",extensions:["toml"],load(){return mt(()=>import("./toml-Bm5Em-hy.js"),[]).then(e=>Ct(e.toml))}}),ot.of({name:"Troff",extensions:["1","2","3","4","5","6","7","8","9"],load(){return mt(()=>import("./troff-wAsdV37c.js"),[]).then(e=>Ct(e.troff))}}),ot.of({name:"TTCN",extensions:["ttcn","ttcn3","ttcnpp"],load(){return mt(()=>import("./ttcn-CfJYG6tj.js"),[]).then(e=>Ct(e.ttcn))}}),ot.of({name:"TTCN_CFG",extensions:["cfg"],load(){return mt(()=>import("./ttcn-cfg-B9xdYoR4.js"),[]).then(e=>Ct(e.ttcnCfg))}}),ot.of({name:"Turtle",extensions:["ttl"],load(){return mt(()=>import("./turtle-B1tBg_DP.js"),[]).then(e=>Ct(e.turtle))}}),ot.of({name:"Web IDL",extensions:["webidl"],load(){return mt(()=>import("./webidl-ZXfAyPTL.js"),[]).then(e=>Ct(e.webIDL))}}),ot.of({name:"VB.NET",extensions:["vb"],load(){return mt(()=>import("./vb-CmGdzxic.js"),[]).then(e=>Ct(e.vb))}}),ot.of({name:"VBScript",extensions:["vbs"],load(){return mt(()=>import("./vbscript-BuJXcnF6.js"),[]).then(e=>Ct(e.vbScript))}}),ot.of({name:"Velocity",extensions:["vtl"],load(){return mt(()=>import("./velocity-D8B20fx6.js"),[]).then(e=>Ct(e.velocity))}}),ot.of({name:"Verilog",extensions:["v"],load(){return mt(()=>import("./verilog-C6RDOZhf.js"),[]).then(e=>Ct(e.verilog))}}),ot.of({name:"VHDL",extensions:["vhd","vhdl"],load(){return mt(()=>import("./vhdl-lSbBsy5d.js"),[]).then(e=>Ct(e.vhdl))}}),ot.of({name:"XQuery",extensions:["xy","xquery","xq","xqm","xqy"],load(){return mt(()=>import("./xquery-DzFWVndE.js"),[]).then(e=>Ct(e.xQuery))}}),ot.of({name:"Yacas",extensions:["ys"],load(){return mt(()=>import("./yacas-BJ4BC0dw.js"),[]).then(e=>Ct(e.yacas))}}),ot.of({name:"Z80",extensions:["z80"],load(){return mt(()=>import("./z80-Hz9HOZM7.js"),[]).then(e=>Ct(e.z80))}}),ot.of({name:"MscGen",extensions:["mscgen","mscin","msc"],load(){return mt(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>Ct(e.mscgen))}}),ot.of({name:"Xù",extensions:["xu"],load(){return mt(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>Ct(e.xu))}}),ot.of({name:"MsGenny",extensions:["msgenny"],load(){return mt(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>Ct(e.msgenny))}}),ot.of({name:"Vue",extensions:["vue"],load(){return mt(()=>import("./index-DooRYrN2.js"),__vite__mapDeps([26,5,1,3,6])).then(e=>e.vue())}}),ot.of({name:"Angular Template",load(){return mt(()=>import("./index-DtA8NpRC.js"),__vite__mapDeps([27,5,1,3,6])).then(e=>e.angular())}})],kne="#2e3440",aK="#3b4252",jne="#434c5e",M9="#4c566a",Nne="#e5e9f0",WL="#eceff4",FM="#8fbcbb",Cne="#88c0d0",Kdt="#81a1c1",Gu="#5e81ac",Hdt="#bf616a",Rx="#d08770",zM="#ebcb8b",Sne="#a3be8c",Vdt="#b48ead",_ne="#d30102",oK=WL,BM=oK,Wdt="#ffffff",UM=aK,Zdt=oK,Ane=aK,Gdt=Yt.theme({"&":{color:kne,backgroundColor:Wdt},".cm-content":{caretColor:Ane},".cm-cursor, .cm-dropCursor":{borderLeftColor:Ane},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:Zdt},".cm-panels":{backgroundColor:oK,color:M9},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:`1px solid ${M9}`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:Nne},".cm-activeLine":{backgroundColor:BM},".cm-selectionMatch":{backgroundColor:Nne},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{outline:`1px solid ${M9}`},"&.cm-focused .cm-matchingBracket":{backgroundColor:WL},".cm-gutters":{backgroundColor:WL,color:kne,border:"none"},".cm-activeLineGutter":{backgroundColor:BM},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:UM},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:UM,borderBottomColor:UM},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:BM,color:M9}}},{dark:!1}),Qdt=W7.define([{tag:dt.keyword,color:Gu},{tag:[dt.name,dt.deleted,dt.character,dt.propertyName,dt.macroName],color:Rx},{tag:[dt.variableName],color:Rx},{tag:[dt.function(dt.variableName)],color:Gu},{tag:[dt.labelName],color:Kdt},{tag:[dt.color,dt.constant(dt.name),dt.standard(dt.name)],color:Gu},{tag:[dt.definition(dt.name),dt.separator],color:Sne},{tag:[dt.brace],color:FM},{tag:[dt.annotation],color:_ne},{tag:[dt.number,dt.changed,dt.annotation,dt.modifier,dt.self,dt.namespace],color:Cne},{tag:[dt.typeName,dt.className],color:zM},{tag:[dt.operator,dt.operatorKeyword],color:Sne},{tag:[dt.tagName],color:Vdt},{tag:[dt.squareBracket],color:Hdt},{tag:[dt.angleBracket],color:Rx},{tag:[dt.attributeName],color:zM},{tag:[dt.regexp],color:Gu},{tag:[dt.quote],color:aK},{tag:[dt.string],color:Rx},{tag:dt.link,color:FM,textDecoration:"underline",textUnderlinePosition:"under"},{tag:[dt.url,dt.escape,dt.special(dt.string)],color:Rx},{tag:[dt.meta],color:Cne},{tag:[dt.comment],color:jne,fontStyle:"italic"},{tag:dt.strong,fontWeight:"bold",color:Gu},{tag:dt.emphasis,fontStyle:"italic",color:Gu},{tag:dt.strikethrough,textDecoration:"line-through"},{tag:dt.heading,fontWeight:"bold",color:Gu},{tag:dt.special(dt.heading1),fontWeight:"bold",color:Gu},{tag:dt.heading1,fontWeight:"bold",color:Gu},{tag:[dt.heading2,dt.heading3,dt.heading4],fontWeight:"bold",color:Gu},{tag:[dt.heading5,dt.heading6],color:Gu},{tag:[dt.atom,dt.bool,dt.special(dt.variableName)],color:Rx},{tag:[dt.processingInstruction,dt.inserted],color:FM},{tag:[dt.contentSeparator],color:zM},{tag:dt.invalid,color:jne,borderBottom:`1px dotted ${_ne}`}]),Ydt=[Gdt,V5e(Qdt)],Ene=typeof String.prototype.normalize=="function"?e=>e.normalize("NFKD"):e=>e;class M5{constructor(t,n,r=0,i=t.length,a,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(r,i),this.bufferStart=r,this.normalize=a?l=>a(Ene(l)):Ene,this.query=this.normalize(n)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return Xl(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let n=wq(t),r=this.bufferStart+this.bufferPos;this.bufferPos+=wf(t);let i=this.normalize(n);if(i.length)for(let a=0,o=r;;a++){let l=i.charCodeAt(a),c=this.match(l,o,this.bufferPos+this.bufferStart);if(a==i.length-1){if(c)return this.value=c,this;break}o==r&&a<n.length&&n.charCodeAt(a)==l&&o++}}}match(t,n,r){let i=null;for(let a=0;a<this.matches.length;a+=2){let o=this.matches[a],l=!1;this.query.charCodeAt(o)==t&&(o==this.query.length-1?i={from:this.matches[a+1],to:r}:(this.matches[a]++,l=!0)),l||(this.matches.splice(a,2),a-=2)}return this.query.charCodeAt(0)==t&&(this.query.length==1?i={from:n,to:r}:this.matches.push(1,n)),i&&this.test&&!this.test(i.from,i.to,this.buffer,this.bufferStart)&&(i=null),i}}typeof Symbol<"u"&&(M5.prototype[Symbol.iterator]=function(){return this});const H4e={from:-1,to:-1,match:/.*/.exec("")},lK="gm"+(/x/.unicode==null?"":"u");class V4e{constructor(t,n,r,i=0,a=t.length){if(this.text=t,this.to=a,this.curLine="",this.done=!1,this.value=H4e,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new W4e(t,n,r,i,a);this.re=new RegExp(n,lK+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.iter=t.iter();let o=t.lineAt(i);this.curLineStart=o.from,this.matchPos=JN(t,i),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let n=this.matchPos<=this.to&&this.re.exec(this.curLine);if(n){let r=this.curLineStart+n.index,i=r+n[0].length;if(this.matchPos=JN(this.text,i+(r==i?1:0)),r==this.curLineStart+this.curLine.length&&this.nextLine(),(r<i||r>this.value.to)&&(!this.test||this.test(r,i,n)))return this.value={from:r,to:i,match:n},this;t=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),t=0;else return this.done=!0,this}}}const qM=new WeakMap;class T3{constructor(t,n){this.from=t,this.text=n}get to(){return this.from+this.text.length}static get(t,n,r){let i=qM.get(t);if(!i||i.from>=r||i.to<=n){let l=new T3(n,t.sliceString(n,r));return qM.set(t,l),l}if(i.from==n&&i.to==r)return i;let{text:a,from:o}=i;return o>n&&(a=t.sliceString(n,o)+a,o=n),i.to<r&&(a+=t.sliceString(i.to,r)),qM.set(t,new T3(o,a)),new T3(n,a.slice(n-o,r-o))}}class W4e{constructor(t,n,r,i,a){this.text=t,this.to=a,this.done=!1,this.value=H4e,this.matchPos=JN(t,i),this.re=new RegExp(n,lK+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.flat=T3.get(t,i,this.chunkEnd(i+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,n=this.re.exec(this.flat.text);if(n&&!n[0]&&n.index==t&&(this.re.lastIndex=t+1,n=this.re.exec(this.flat.text)),n){let r=this.flat.from+n.index,i=r+n[0].length;if((this.flat.to>=this.to||n.index+n[0].length<=this.flat.text.length-10)&&(!this.test||this.test(r,i,n)))return this.value={from:r,to:i,match:n},this.matchPos=JN(this.text,i+(r==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=T3.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(V4e.prototype[Symbol.iterator]=W4e.prototype[Symbol.iterator]=function(){return this});function Jdt(e){try{return new RegExp(e,lK),!0}catch{return!1}}function JN(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}const Xdt=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=nlt(e,{label:t.phrase("Go to line"),input:{type:"text",name:"line",value:n},focus:!0,submitLabel:t.phrase("go")});return i.then(a=>{let o=a&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(a.elements.line.value);if(!o){e.dispatch({effects:r});return}let l=t.doc.lineAt(t.selection.main.head),[,c,u,d,f]=o,h=d?+d.slice(1):0,g=u?+u:l.number;if(u&&f){let j=g/100;c&&(j=j*(c=="-"?-1:1)+l.number/t.doc.lines),g=Math.round(t.doc.lines*j)}else u&&c&&(g=g*(c=="-"?-1:1)+l.number);let b=t.doc.line(Math.max(1,Math.min(t.doc.lines,g))),v=bt.cursor(b.from+Math.max(0,Math.min(h,b.length)));e.dispatch({effects:[r,Yt.scrollIntoView(v.from,{y:"center"})],selection:v})}),!0},eft={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},tft=Jt.define({combine(e){return im(e,eft,{highlightWordAroundCursor:(t,n)=>t||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function nft(e){return[oft,aft]}const rft=$n.mark({class:"cm-selectionMatch"}),sft=$n.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Tne(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=yi.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=yi.Word)}function ift(e,t,n,r){return e(t.sliceDoc(n,n+1))==yi.Word&&e(t.sliceDoc(r-1,r))==yi.Word}const aft=ia.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(tft),{state:n}=e,r=n.selection;if(r.ranges.length>1)return $n.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return $n.none;let c=n.wordAt(i.head);if(!c)return $n.none;o=n.charCategorizer(i.head),a=n.sliceDoc(c.from,c.to)}else{let c=i.to-i.from;if(c<t.minSelectionLength||c>200)return $n.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(Tne(o,n,i.from,i.to)&&ift(o,n,i.from,i.to)))return $n.none}else if(a=n.sliceDoc(i.from,i.to),!a)return $n.none}let l=[];for(let c of e.visibleRanges){let u=new M5(n.doc,a,c.from,c.to);for(;!u.next().done;){let{from:d,to:f}=u.value;if((!o||Tne(o,n,d,f))&&(i.empty&&d<=i.from&&f>=i.to?l.push(sft.range(d,f)):(d>=i.to||f<=i.from)&&l.push(rft.range(d,f)),l.length>t.maxMatches))return $n.none}}return $n.set(l)}},{decorations:e=>e.decorations}),oft=Yt.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),lft=({state:e,dispatch:t})=>{let{selection:n}=e,r=bt.create(n.ranges.map(i=>e.wordAt(i.head)||bt.cursor(i.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function cft(e,t){let{main:n,ranges:r}=e.selection,i=e.wordAt(n.head),a=i&&i.from==n.from&&i.to==n.to;for(let o=!1,l=new M5(e.doc,t,r[r.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new M5(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),o=!0}else{if(o&&r.some(c=>c.from==l.value.from))continue;if(a){let c=e.wordAt(l.value.from);if(!c||c.from!=l.value.from||c.to!=l.value.to)continue}return l.value}}const uft=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(a=>a.from===a.to))return lft({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(a=>e.sliceDoc(a.from,a.to)!=r))return!1;let i=cft(e,r);return i?(t(e.update({selection:e.selection.addRange(bt.range(i.from,i.to),!1),effects:Yt.scrollIntoView(i.to)})),!0):!1},O4=Jt.define({combine(e){return im(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new Nft(t),scrollToMatch:t=>Yt.scrollIntoView(t)})}});class Z4e{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||Jdt(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord,this.test=t.test}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(n,r)=>r=="n"?`
1298
1298
  `:r=="r"?"\r":r=="t"?" ":"\\")}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord&&this.test==t.test}create(){return this.regexp?new gft(this):new mft(this)}getCursor(t,n=0,r){let i=t.doc?t:Yr.create({doc:t});return r==null&&(r=i.doc.length),this.regexp?t3(this,i,n,r):e3(this,i,n,r)}}class G4e{constructor(t){this.spec=t}}function dft(e,t,n){return(r,i,a,o)=>{if(n&&!n(r,i,a,o))return!1;let l=r>=o&&i<=o+a.length?a.slice(r-o,i-o):t.doc.sliceString(r,i);return e(l,t,r,i)}}function e3(e,t,n,r){let i;return e.wholeWord&&(i=fft(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(i=dft(e.test,t,i)),new M5(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:a=>a.toLowerCase(),i)}function fft(e,t){return(n,r,i,a)=>((a>n||a+i.length<r)&&(a=Math.max(0,n-2),i=e.sliceString(a,Math.min(e.length,r+2))),(t(XN(i,n-a))!=yi.Word||t(eC(i,n-a))!=yi.Word)&&(t(eC(i,r-a))!=yi.Word||t(XN(i,r-a))!=yi.Word))}class mft extends G4e{constructor(t){super(t)}nextMatch(t,n,r){let i=e3(this.spec,t,r,t.doc.length).nextOverlapping();if(i.done){let a=Math.min(t.doc.length,n+this.spec.unquoted.length);i=e3(this.spec,t,0,a).nextOverlapping()}return i.done||i.value.from==n&&i.value.to==r?null:i.value}prevMatchInRange(t,n,r){for(let i=r;;){let a=Math.max(n,i-1e4-this.spec.unquoted.length),o=e3(this.spec,t,a,i),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(a==n)return null;i-=1e4}}prevMatch(t,n,r){let i=this.prevMatchInRange(t,0,n);return i||(i=this.prevMatchInRange(t,Math.max(0,r-this.spec.unquoted.length),t.doc.length)),i&&(i.from!=n||i.to!=r)?i:null}getReplacement(t){return this.spec.unquote(this.spec.replace)}matchAll(t,n){let r=e3(this.spec,t,0,t.doc.length),i=[];for(;!r.next().done;){if(i.length>=n)return null;i.push(r.value)}return i}highlight(t,n,r,i){let a=e3(this.spec,t,Math.max(0,n-this.spec.unquoted.length),Math.min(r+this.spec.unquoted.length,t.doc.length));for(;!a.next().done;)i(a.value.from,a.value.to)}}function hft(e,t,n){return(r,i,a)=>(!n||n(r,i,a))&&e(a[0],t,r,i)}function t3(e,t,n,r){let i;return e.wholeWord&&(i=pft(t.charCategorizer(t.selection.main.head))),e.test&&(i=hft(e.test,t,i)),new V4e(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:i},n,r)}function XN(e,t){return e.slice(lo(e,t,!1),t)}function eC(e,t){return e.slice(t,lo(e,t))}function pft(e){return(t,n,r)=>!r[0].length||(e(XN(r.input,r.index))!=yi.Word||e(eC(r.input,r.index))!=yi.Word)&&(e(eC(r.input,r.index+r[0].length))!=yi.Word||e(XN(r.input,r.index+r[0].length))!=yi.Word)}class gft extends G4e{nextMatch(t,n,r){let i=t3(this.spec,t,r,t.doc.length).next();return i.done&&(i=t3(this.spec,t,0,n).next()),i.done?null:i.value}prevMatchInRange(t,n,r){for(let i=1;;i++){let a=Math.max(n,r-i*1e4),o=t3(this.spec,t,a,r),l=null;for(;!o.next().done;)l=o.value;if(l&&(a==n||l.from>a+10))return l;if(a==n)return null}}prevMatch(t,n,r){return this.prevMatchInRange(t,0,n)||this.prevMatchInRange(t,r,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(n,r)=>{if(r=="&")return t.match[0];if(r=="$")return"$";for(let i=r.length;i>0;i--){let a=+r.slice(0,i);if(a>0&&a<t.match.length)return t.match[a]+r.slice(i)}return n})}matchAll(t,n){let r=t3(this.spec,t,0,t.doc.length),i=[];for(;!r.next().done;){if(i.length>=n)return null;i.push(r.value)}return i}highlight(t,n,r,i){let a=t3(this.spec,t,Math.max(0,n-250),Math.min(r+250,t.doc.length));for(;!a.next().done;)i(a.value.from,a.value.to)}}const $6=ir.define(),cK=ir.define(),xp=qo.define({create(e){return new KM(ZL(e).create(),null)},update(e,t){for(let n of t.effects)n.is($6)?e=new KM(n.value.create(),e.panel):n.is(cK)&&(e=new KM(e.query,n.value?uK:null));return e},provide:e=>T6.from(e,t=>t.panel)});class KM{constructor(t,n){this.query=t,this.panel=n}}const xft=$n.mark({class:"cm-searchMatch"}),bft=$n.mark({class:"cm-searchMatch cm-searchMatch-selected"}),yft=ia.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(xp))}update(e){let t=e.state.field(xp);(t!=e.startState.field(xp)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return $n.none;let{view:n}=this,r=new S1;for(let i=0,a=n.visibleRanges,o=a.length;i<o;i++){let{from:l,to:c}=a[i];for(;i<o-1&&c>a[i+1].from-500;)c=a[++i].to;e.highlight(n.state,l,c,(u,d)=>{let f=n.state.selection.ranges.some(h=>h.from==u&&h.to==d);r.add(u,d,f?bft:xft)})}return r.finish()}},{decorations:e=>e.decorations});function Q7(e){return t=>{let n=t.state.field(xp,!1);return n&&n.query.spec.valid?e(t,n):J4e(t)}}const tC=Q7((e,{query:t})=>{let{to:n}=e.state.selection.main,r=t.nextMatch(e.state,n,n);if(!r)return!1;let i=bt.single(r.from,r.to),a=e.state.facet(O4);return e.dispatch({selection:i,effects:[dK(e,r),a.scrollToMatch(i.main,e)],userEvent:"select.search"}),Y4e(e),!0}),nC=Q7((e,{query:t})=>{let{state:n}=e,{from:r}=n.selection.main,i=t.prevMatch(n,r,r);if(!i)return!1;let a=bt.single(i.from,i.to),o=e.state.facet(O4);return e.dispatch({selection:a,effects:[dK(e,i),o.scrollToMatch(a.main,e)],userEvent:"select.search"}),Y4e(e),!0}),vft=Q7((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:bt.create(n.map(r=>bt.range(r.from,r.to))),userEvent:"select.search.matches"}),!0)}),wft=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:i}=n.main,a=[],o=0;for(let l=new M5(e.doc,e.sliceDoc(r,i));!l.next().done;){if(a.length>1e3)return!1;l.value.from==r&&(o=a.length),a.push(bt.range(l.value.from,l.value.to))}return t(e.update({selection:bt.create(a,o),userEvent:"select.search.matches"})),!0},Ine=Q7((e,{query:t})=>{let{state:n}=e,{from:r,to:i}=n.selection.main;if(n.readOnly)return!1;let a=t.nextMatch(n,r,r);if(!a)return!1;let o=a,l=[],c,u,d=[];o.from==r&&o.to==i&&(u=n.toText(t.getReplacement(o)),l.push({from:o.from,to:o.to,insert:u}),o=t.nextMatch(n,o.from,o.to),d.push(Yt.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(r).number)+".")));let f=e.state.changes(l);return o&&(c=bt.single(o.from,o.to).map(f),d.push(dK(e,o)),d.push(n.facet(O4).scrollToMatch(c.main,e))),e.dispatch({changes:f,selection:c,effects:d,userEvent:"input.replace"}),!0}),kft=Q7((e,{query:t})=>{if(e.state.readOnly)return!1;let n=t.matchAll(e.state,1e9).map(i=>{let{from:a,to:o}=i;return{from:a,to:o,insert:t.getReplacement(i)}});if(!n.length)return!1;let r=e.state.phrase("replaced $ matches",n.length)+".";return e.dispatch({changes:n,effects:Yt.announce.of(r),userEvent:"input.replace.all"}),!0});function uK(e){return e.state.facet(O4).createPanel(e)}function ZL(e,t){var n,r,i,a,o;let l=e.selection.main,c=l.empty||l.to>l.from+100?"":e.sliceDoc(l.from,l.to);if(t&&!c)return t;let u=e.facet(O4);return new Z4e({search:((n=t==null?void 0:t.literal)!==null&&n!==void 0?n:u.literal)?c:c.replace(/\n/g,"\\n"),caseSensitive:(r=t==null?void 0:t.caseSensitive)!==null&&r!==void 0?r:u.caseSensitive,literal:(i=t==null?void 0:t.literal)!==null&&i!==void 0?i:u.literal,regexp:(a=t==null?void 0:t.regexp)!==null&&a!==void 0?a:u.regexp,wholeWord:(o=t==null?void 0:t.wholeWord)!==null&&o!==void 0?o:u.wholeWord})}function Q4e(e){let t=Fq(e,uK);return t&&t.dom.querySelector("[main-field]")}function Y4e(e){let t=Q4e(e);t&&t==e.root.activeElement&&t.select()}const J4e=e=>{let t=e.state.field(xp,!1);if(t&&t.panel){let n=Q4e(e);if(n&&n!=e.root.activeElement){let r=ZL(e.state,t.query.spec);r.valid&&e.dispatch({effects:$6.of(r)}),n.focus(),n.select()}}else e.dispatch({effects:[cK.of(!0),t?$6.of(ZL(e.state,t.query.spec)):ir.appendConfig.of(Sft)]});return!0},X4e=e=>{let t=e.state.field(xp,!1);if(!t||!t.panel)return!1;let n=Fq(e,uK);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:cK.of(!1)}),!0},jft=[{key:"Mod-f",run:J4e,scope:"editor search-panel"},{key:"F3",run:tC,shift:nC,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:tC,shift:nC,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:X4e,scope:"editor search-panel"},{key:"Mod-Shift-l",run:wft},{key:"Mod-Alt-g",run:Xdt},{key:"Mod-d",run:uft,preventDefault:!0}];class Nft{constructor(t){this.view=t;let n=this.query=t.state.field(xp).query.spec;this.commit=this.commit.bind(this),this.searchField=Ps("input",{value:n.search,placeholder:kc(t,"Find"),"aria-label":kc(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Ps("input",{value:n.replace,placeholder:kc(t,"Replace"),"aria-label":kc(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=Ps("input",{type:"checkbox",name:"case",form:"",checked:n.caseSensitive,onchange:this.commit}),this.reField=Ps("input",{type:"checkbox",name:"re",form:"",checked:n.regexp,onchange:this.commit}),this.wordField=Ps("input",{type:"checkbox",name:"word",form:"",checked:n.wholeWord,onchange:this.commit});function r(i,a,o){return Ps("button",{class:"cm-button",name:i,onclick:a,type:"button"},o)}this.dom=Ps("div",{onkeydown:i=>this.keydown(i),class:"cm-search"},[this.searchField,r("next",()=>tC(t),[kc(t,"next")]),r("prev",()=>nC(t),[kc(t,"previous")]),r("select",()=>vft(t),[kc(t,"all")]),Ps("label",null,[this.caseField,kc(t,"match case")]),Ps("label",null,[this.reField,kc(t,"regexp")]),Ps("label",null,[this.wordField,kc(t,"by word")]),...t.state.readOnly?[]:[Ps("br"),this.replaceField,r("replace",()=>Ine(t),[kc(t,"replace")]),r("replaceAll",()=>kft(t),[kc(t,"replace all")])],Ps("button",{name:"close",onclick:()=>X4e(t),"aria-label":kc(t,"close"),type:"button"},["×"])])}commit(){let t=new Z4e({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:$6.of(t)}))}keydown(t){hot(this.view,t,"search-panel")?t.preventDefault():t.keyCode==13&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?nC:tC)(this.view)):t.keyCode==13&&t.target==this.replaceField&&(t.preventDefault(),Ine(this.view))}update(t){for(let n of t.transactions)for(let r of n.effects)r.is($6)&&!r.value.eq(this.query)&&this.setQuery(r.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(O4).top}}function kc(e,t){return e.state.phrase(t)}const R9=30,O9=/[\s\.,:;?!]/;function dK(e,{from:t,to:n}){let r=e.state.doc.lineAt(t),i=e.state.doc.lineAt(n).to,a=Math.max(r.from,t-R9),o=Math.min(i,n+R9),l=e.state.sliceDoc(a,o);if(a!=r.from){for(let c=0;c<R9;c++)if(!O9.test(l[c+1])&&O9.test(l[c])){l=l.slice(c);break}}if(o!=i){for(let c=l.length-1;c>l.length-R9;c--)if(!O9.test(l[c-1])&&O9.test(l[c])){l=l.slice(0,c);break}}return Yt.announce.of(`${e.state.phrase("current match")}. ${l} ${e.state.phrase("on line")} ${r.number}.`)}const Cft=Yt.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),Sft=[xp,lg.low(yft),Cft];class Mne{constructor(t,n,r){this.from=t,this.to=n,this.diagnostic=r}}class Qg{constructor(t,n,r){this.diagnostics=t,this.panel=n,this.selected=r}static init(t,n,r){let i=r.facet(F6).markerFilter;i&&(t=i(t,r));let a=t.slice().sort((g,b)=>g.from-b.from||g.to-b.to),o=new S1,l=[],c=0,u=r.doc.iter(),d=0,f=r.doc.length;for(let g=0;;){let b=g==a.length?null:a[g];if(!b&&!l.length)break;let v,j;if(l.length)v=c,j=l.reduce((N,C)=>Math.min(N,C.to),b&&b.from>v?b.from:1e8);else{if(v=b.from,v>f)break;j=b.to,l.push(b),g++}for(;g<a.length;){let N=a[g];if(N.from==v&&(N.to>N.from||N.to==v))l.push(N),g++,j=Math.min(N.to,j);else{j=Math.min(N.from,j);break}}j=Math.min(j,f);let k=!1;if(l.some(N=>N.from==v&&(N.to==j||j==f))&&(k=v==j,!k&&j-v<10)){let N=v-(d+u.value.length);N>0&&(u.next(N),d=v);for(let C=v;;){if(C>=j){k=!0;break}if(!u.lineBreak&&d+u.value.length>C)break;C=d+u.value.length,d+=u.value.length,u.next()}}let w=Fft(l);if(k)o.add(v,v,$n.widget({widget:new Pft(w),diagnostics:l.slice()}));else{let N=l.reduce((C,A)=>A.markClass?C+" "+A.markClass:C,"");o.add(v,j,$n.mark({class:"cm-lintRange cm-lintRange-"+w+N,diagnostics:l.slice(),inclusiveEnd:l.some(C=>C.to>j)}))}if(c=j,c==f)break;for(let N=0;N<l.length;N++)l[N].to<=c&&l.splice(N--,1)}let h=o.finish();return new Qg(h,n,Vp(h))}}function Vp(e,t=null,n=0){let r=null;return e.between(n,1e9,(i,a,{spec:o})=>{if(!(t&&o.diagnostics.indexOf(t)<0))if(!r)r=new Mne(i,a,t||o.diagnostics[0]);else{if(o.diagnostics.indexOf(r.diagnostic)<0)return!1;r=new Mne(r.from,a,r.diagnostic)}}),r}function _ft(e,t){let n=t.pos,r=t.end||n,i=e.state.facet(F6).hideOn(e,n,r);if(i!=null)return i;let a=e.startState.doc.lineAt(t.pos);return!!(e.effects.some(o=>o.is(ebe))||e.changes.touchesRange(a.from,Math.max(a.to,r)))}function Aft(e,t){return e.field(Oc,!1)?t:t.concat(ir.appendConfig.of(zft))}const ebe=ir.define(),fK=ir.define(),tbe=ir.define(),Oc=qo.define({create(){return new Qg($n.none,null,null)},update(e,t){if(t.docChanged&&e.diagnostics.size){let n=e.diagnostics.map(t.changes),r=null,i=e.panel;if(e.selected){let a=t.changes.mapPos(e.selected.from,1);r=Vp(n,e.selected.diagnostic,a)||Vp(n,null,a)}!n.size&&i&&t.state.facet(F6).autoPanel&&(i=null),e=new Qg(n,i,r)}for(let n of t.effects)if(n.is(ebe)){let r=t.state.facet(F6).autoPanel?n.value.length?z6.open:null:e.panel;e=Qg.init(n.value,r,t.state)}else n.is(fK)?e=new Qg(e.diagnostics,n.value?z6.open:null,e.selected):n.is(tbe)&&(e=new Qg(e.diagnostics,e.panel,n.value));return e},provide:e=>[T6.from(e,t=>t.panel),Yt.decorations.from(e,t=>t.diagnostics)]}),Eft=$n.mark({class:"cm-lintRange cm-lintRange-active"});function Tft(e,t,n){let{diagnostics:r}=e.state.field(Oc),i,a=-1,o=-1;r.between(t-(n<0?1:0),t+(n>0?1:0),(c,u,{spec:d})=>{if(t>=c&&t<=u&&(c==u||(t>c||n>0)&&(t<u||n<0)))return i=d.diagnostics,a=c,o=u,!1});let l=e.state.facet(F6).tooltipFilter;return i&&l&&(i=l(i,e.state)),i?{pos:a,end:o,above:e.state.doc.lineAt(a).to<o,create(){return{dom:Ift(e,i)}}}:null}function Ift(e,t){return Ps("ul",{class:"cm-tooltip-lint"},t.map(n=>rbe(e,n,!1)))}const Mft=e=>{let t=e.state.field(Oc,!1);(!t||!t.panel)&&e.dispatch({effects:Aft(e.state,[fK.of(!0)])});let n=Fq(e,z6.open);return n&&n.dom.querySelector(".cm-panel-lint ul").focus(),!0},Rne=e=>{let t=e.state.field(Oc,!1);return!t||!t.panel?!1:(e.dispatch({effects:fK.of(!1)}),!0)},Rft=e=>{let t=e.state.field(Oc,!1);if(!t)return!1;let n=e.state.selection.main,r=Vp(t.diagnostics,null,n.to+1);return!r&&(r=Vp(t.diagnostics,null,0),!r||r.from==n.from&&r.to==n.to)?!1:(e.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),!0)},Oft=[{key:"Mod-Shift-m",run:Mft,preventDefault:!0},{key:"F8",run:Rft}],F6=Jt.define({combine(e){return{sources:e.map(t=>t.source).filter(t=>t!=null),...im(e.map(t=>t.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:One,tooltipFilter:One,needsRefresh:(t,n)=>t?n?r=>t(r)||n(r):t:n,hideOn:(t,n)=>t?n?(r,i,a)=>t(r,i,a)||n(r,i,a):t:n,autoPanel:(t,n)=>t||n})}}});function One(e,t){return e?t?(n,r)=>t(e(n,r),r):e:t}function nbe(e){let t=[];if(e)e:for(let{name:n}of e){for(let r=0;r<n.length;r++){let i=n[r];if(/[a-zA-Z]/.test(i)&&!t.some(a=>a.toLowerCase()==i.toLowerCase())){t.push(i);continue e}}t.push("")}return t}function rbe(e,t,n){var r;let i=n?nbe(t.actions):[];return Ps("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},Ps("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(e):t.message),(r=t.actions)===null||r===void 0?void 0:r.map((a,o)=>{let l=!1,c=g=>{if(g.preventDefault(),l)return;l=!0;let b=Vp(e.state.field(Oc).diagnostics,t);b&&a.apply(e,b.from,b.to)},{name:u}=a,d=i[o]?u.indexOf(i[o]):-1,f=d<0?u:[u.slice(0,d),Ps("u",u.slice(d,d+1)),u.slice(d+1)],h=a.markClass?" "+a.markClass:"";return Ps("button",{type:"button",class:"cm-diagnosticAction"+h,onclick:c,onmousedown:c,"aria-label":` Action: ${u}${d<0?"":` (access key "${i[o]})"`}.`},f)}),t.source&&Ps("div",{class:"cm-diagnosticSource"},t.source))}class Pft extends am{constructor(t){super(),this.sev=t}eq(t){return t.sev==this.sev}toDOM(){return Ps("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class Pne{constructor(t,n){this.diagnostic=n,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=rbe(t,n,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class z6{constructor(t){this.view=t,this.items=[];let n=i=>{if(!(i.ctrlKey||i.altKey||i.metaKey)){if(i.keyCode==27)Rne(this.view),this.view.focus();else if(i.keyCode==38||i.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(i.keyCode==40||i.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(i.keyCode==36)this.moveSelection(0);else if(i.keyCode==35)this.moveSelection(this.items.length-1);else if(i.keyCode==13)this.view.focus();else if(i.keyCode>=65&&i.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:a}=this.items[this.selectedIndex],o=nbe(a.actions);for(let l=0;l<o.length;l++)if(o[l].toUpperCase().charCodeAt(0)==i.keyCode){let c=Vp(this.view.state.field(Oc).diagnostics,a);c&&a.actions[l].apply(t,c.from,c.to)}}else return;i.preventDefault()}},r=i=>{for(let a=0;a<this.items.length;a++)this.items[a].dom.contains(i.target)&&this.moveSelection(a)};this.list=Ps("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:n,onclick:r}),this.dom=Ps("div",{class:"cm-panel-lint"},this.list,Ps("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>Rne(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(Oc).selected;if(!t)return-1;for(let n=0;n<this.items.length;n++)if(this.items[n].diagnostic==t.diagnostic)return n;return-1}update(){let{diagnostics:t,selected:n}=this.view.state.field(Oc),r=0,i=!1,a=null,o=new Set;for(t.between(0,this.view.state.doc.length,(l,c,{spec:u})=>{for(let d of u.diagnostics){if(o.has(d))continue;o.add(d);let f=-1,h;for(let g=r;g<this.items.length;g++)if(this.items[g].diagnostic==d){f=g;break}f<0?(h=new Pne(this.view,d),this.items.splice(r,0,h),i=!0):(h=this.items[f],f>r&&(this.items.splice(r,f-r),i=!0)),n&&h.diagnostic==n.diagnostic?h.dom.hasAttribute("aria-selected")||(h.dom.setAttribute("aria-selected","true"),a=h):h.dom.hasAttribute("aria-selected")&&h.dom.removeAttribute("aria-selected"),r++}});r<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)i=!0,this.items.pop();this.items.length==0&&(this.items.push(new Pne(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),i=!0),a?(this.list.setAttribute("aria-activedescendant",a.id),this.view.requestMeasure({key:this,read:()=>({sel:a.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:l,panel:c})=>{let u=c.height/this.list.offsetHeight;l.top<c.top?this.list.scrollTop-=(c.top-l.top)/u:l.bottom>c.bottom&&(this.list.scrollTop+=(l.bottom-c.bottom)/u)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),i&&this.sync()}sync(){let t=this.list.firstChild;function n(){let r=t;t=r.nextSibling,r.remove()}for(let r of this.items)if(r.dom.parentNode==this.list){for(;t!=r.dom;)n();t=r.dom.nextSibling}else this.list.insertBefore(r.dom,t);for(;t;)n()}moveSelection(t){if(this.selectedIndex<0)return;let n=this.view.state.field(Oc),r=Vp(n.diagnostics,this.items[t].diagnostic);r&&this.view.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0,effects:tbe.of(r)})}static open(t){return new z6(t)}}function Dft(e,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}function P9(e){return Dft(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const Lft=Yt.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:P9("#d11")},".cm-lintRange-warning":{backgroundImage:P9("orange")},".cm-lintRange-info":{backgroundImage:P9("#999")},".cm-lintRange-hint":{backgroundImage:P9("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function $ft(e){return e=="error"?4:e=="warning"?3:e=="info"?2:1}function Fft(e){let t="hint",n=1;for(let r of e){let i=$ft(r.severity);i>n&&(n=i,t=r.severity)}return t}const zft=[Oc,Yt.decorations.compute([Oc],e=>{let{selected:t,panel:n}=e.field(Oc);return!t||!n||t.from==t.to?$n.none:$n.set([Eft.range(t.from,t.to)])}),elt(Tft,{hideOn:_ft}),Lft],Bft=[S5e(),plt(),Iot(),$ut(),dct(),vot(),Cot(),Yr.allowMultipleSelections.of(!0),Ylt(),V5e(pct,{fallback:!0}),kct(),gut(),_ut(),qot(),Vot(),Lot(),nft(),H7.of([...vut,...zdt,...jft,...Wut,...oct,...d4e,...Oft])],Uft=se.forwardRef(({title:e,children:t},n)=>{const r=Wf(O0);return se.createElement(cz,{delayDuration:100},se.createElement(uz,null,se.createElement(dz,{ref:n,asChild:!0},se.createElement("span",{className:Rt.tooltipTrigger},t)),se.createElement(fz,{container:r==null?void 0:r.current},se.createElement(mz,{className:Ds(Rt.tooltipContent),sideOffset:10},e))))}),qft=se.forwardRef(({children:e,className:t,...n},r)=>se.createElement(vde,{...n,ref:r,className:Ds(t,Rt.selectItem)},se.createElement(wde,null,e))),Kft=({title:e,placeholder:t,className:n})=>{const[r,i]=Ld(Id,F1);return se.createElement(Uft,{title:e},se.createElement(hde,{"aria-label":t,className:Ds(Rt.selectTrigger,n),"data-toolbar-item":!0,disabled:r},se.createElement(pde,{placeholder:t}),se.createElement(gde,{className:Rt.selectDropdownArrow},i("arrow_drop_down"))))},Hft=({children:e,className:t=Rt.selectContainer})=>{const n=Wf(O0);return se.createElement(xde,{container:n==null?void 0:n.current},se.createElement(bde,{className:Ds(t,"mdxeditor-select-content"),onCloseAutoFocus:r=>{r.preventDefault()},position:"popper"},se.createElement(yde,{"data-editor-dropdown":!0,style:{maxHeight:"var(--radix-select-content-available-height)"}},e)))},Vft=e=>se.createElement(mde,{value:e.value||"",onValueChange:e.onChange,disabled:e.disabled},se.createElement(Kft,{title:e.triggerTitle,placeholder:e.placeholder}),se.createElement(Hft,null,e.items.map((t,n)=>t==="separator"?se.createElement(QEe,{key:n}):se.createElement(qft,{key:n,value:t.value},t.label)))),sbe=({language:e,nodeKey:t,code:n,focusEmitter:r})=>{const i=z1(),{parentEditor:a,lexicalNode:o}=eL(),[l,c,u,d,f]=Ld(Id,JL,XL,F1,YL),h=Udt(t,"codeblock",e,r),{setCode:g}=eL(),b=se.useRef(null),v=se.useRef(null),j=se.useRef(g);return j.current=g,h.current={getCodemirror:()=>b.current},se.useEffect(()=>{const k=v.current;return(async()=>{const w=[...c,Bft,Ydt,S5e(),H7.of([Bdt]),Yt.lineWrapping,Yt.updateListener.of(({state:N})=>{j.current(N.doc.toString())}),Yt.domEventHandlers({focus:()=>{a.update(()=>{$u(null)})}})];if(l&&w.push(Yr.readOnly.of(!0)),e!==""&&u){const N=qdt.find(C=>C.name===e||C.alias.includes(e)||C.extensions.includes(e));if(N)try{const C=await N.load();w.push(C.extension)}catch{console.warn("failed to load language support for",e)}}k.innerHTML="",b.current=new Yt({parent:k,state:Yr.create({doc:n,extensions:w})}),k.addEventListener("keydown",Dne)})(),()=>{var w;(w=b.current)==null||w.destroy(),b.current=null,k.removeEventListener("keydown",Dne)}},[l,e,...c]),se.createElement("div",{className:Rt.codeMirrorWrapper},se.createElement("div",{className:Rt.codeMirrorToolbar},se.createElement(Vft,{disabled:l,value:f.keyMap[e]??e,onChange:k=>{a.update(()=>{o.setLanguage(k===GL?"":k),setTimeout(()=>{a.update(()=>{o.getLatest().select()})})})},triggerTitle:i("codeBlock.selectLanguage","Select code block language"),placeholder:i("codeBlock.inlineLanguage","Language"),items:f.items}),se.createElement("button",{className:Rt.iconButton,type:"button",disabled:l,title:i("codeblock.delete","Delete code block"),onClick:k=>{k.preventDefault(),a.update(()=>{o.remove()})}},d("delete_small"))),se.createElement("div",{ref:v}))};function Dne(e){e.stopPropagation()}const GL="__EMPTY_VALUE__";function QL(e){var t;const n=[],r={};if(Array.isArray(e))for(const i of e){const a=((t=i.alias)==null?void 0:t[0])??i.name.toLowerCase();if(n.push({value:a,label:i.name}),r[a]=a,i.alias)for(const o of i.alias)r[o]=a;if(i.extensions)for(const o of i.extensions)r[o]=a;r[i.name.toLowerCase()]=a}else{const i={};for(const[a,o]of Object.entries(e))o in i||(i[o]=a,n.push({value:a||GL,label:o})),r[a]=i[o]||GL}return{items:n,keyMap:r}}const YL=en(QL({js:"JavaScript",ts:"TypeScript",tsx:"TypeScript (React)",jsx:"JavaScript (React)",css:"CSS"})),Wft=oa(e=>{e.link(e.pipe(Wft,Mp(({language:t,code:n})=>({code:n,language:t,meta:""}))),e3e)}),JL=en([]),XL=en(!0),Zft=Uo({update(e,t){e.pubIn({[YL]:QL((t==null?void 0:t.codeBlockLanguages)??{}),[JL]:(t==null?void 0:t.codeMirrorExtensions)??[],[XL]:(t==null?void 0:t.autoLoadLanguageSupport)??!0})},init(e,t){const n=QL((t==null?void 0:t.codeBlockLanguages)??{});e.pubIn({[YL]:n,[JL]:(t==null?void 0:t.codeMirrorExtensions)??[],[sit]:Gft(n),[XL]:(t==null?void 0:t.autoLoadLanguageSupport)??!0})}});function Gft(e){return{match(t,n){return Object.hasOwn(e.keyMap,t??"")&&!n},priority:1,Editor:sbe}}function Qft({url:e,title:t,text:n,onSubmit:r,onCancel:i,linkAutocompleteSuggestions:a,showLinkTitleField:o,showAnchorTextField:l}){const{register:c,handleSubmit:u,control:d,setValue:f,reset:h}=Exe({values:{url:e,title:t,text:n}}),g=z1();return se.createElement("form",{onSubmit:b=>{u(r)(b),b.stopPropagation(),b.preventDefault()},onReset:b=>{b.stopPropagation(),i()},onKeyDown:b=>{b.key==="Escape"&&(b.stopPropagation(),i())},className:Ds(Rt.multiFieldForm,Rt.linkDialogEditForm)},se.createElement("div",{className:Rt.formField},se.createElement("label",{htmlFor:"link-url"},g("createLink.url","URL")),se.createElement(Wxe,{register:c,initialInputValue:e,inputName:"url",suggestions:a,setValue:f,control:d,placeholder:g("createLink.urlPlaceholder","Select or paste an URL"),autofocus:!0})),l?se.createElement("div",{className:Rt.formField},se.createElement("label",{htmlFor:"link-text",title:g("createLink.textTooltip","The text to be displayed for the link")},g("createLink.text","Anchor text")),se.createElement("input",{id:"link-text",className:Rt.textInput,size:40,...c("text")})):null,o?se.createElement("div",{className:Rt.formField},se.createElement("label",{htmlFor:"link-title",title:g("createLink.titleTooltip","The link's title attribute, shown on hover")},g("createLink.title","Link title")),se.createElement("input",{id:"link-title",className:Rt.textInput,size:40,...c("title")})):null,se.createElement("div",{style:{display:"flex",justifyContent:"flex-end",gap:"var(--spacing-2)"}},se.createElement("button",{type:"submit",title:g("createLink.saveTooltip","Set URL"),"aria-label":g("createLink.saveTooltip","Set URL"),className:Ds(Rt.primaryButton)},g("dialogControls.save","Save")),se.createElement("button",{type:"reset",title:g("createLink.cancelTooltip","Cancel change"),"aria-label":g("createLink.cancelTooltip","Cancel change"),className:Ds(Rt.secondaryButton)},g("dialogControls.cancel","Cancel"))))}const Yft=()=>{const[e,t,n,r,i,a,o]=Ld(O0,bi,F1,Zl,dbe,fbe,hbe),l=Mc(ibe),c=Mc(abe),u=Mc(obe),d=Mc(lbe),f=Mc(cbe);se.useEffect(()=>{const k=()=>{t==null||t.getEditorState().read(()=>{l(!0)})};return window.addEventListener("resize",k),window.addEventListener("scroll",k),()=>{window.removeEventListener("resize",k),window.removeEventListener("scroll",k)}},[t,l]);const[h,g]=se.useState(!1),b=z1();if(r.type==="inactive")return null;const v=r.rectangle,j=r.type==="preview"&&r.url.startsWith("http");return se.createElement(OS,{open:!0},se.createElement(Cue,{"data-visible":r.type==="edit",className:Rt.linkDialogAnchor,style:{top:`${v.top}px`,left:`${v.left}px`,width:`${v.width}px`,height:`${v.height}px`}}),se.createElement(PS,{container:e==null?void 0:e.current},se.createElement(Sue,{className:Ds(Rt.linkDialogPopoverContent),sideOffset:5,onOpenAutoFocus:k=>{k.preventDefault()},key:r.linkNodeKey},r.type==="edit"&&se.createElement(Qft,{url:r.url,title:r.title,text:r.text,onSubmit:c,onCancel:u.bind(null),linkAutocompleteSuggestions:i,showLinkTitleField:o,showAnchorTextField:r.withAnchorText}),r.type==="preview"&&se.createElement(se.Fragment,null,se.createElement("a",{className:Rt.linkDialogPreviewAnchor,href:r.url,...j?{target:"_blank",rel:"noreferrer"}:{},onClick:k=>{a!==null&&(k.preventDefault(),a(r.url))},title:j?b("linkPreview.open","Open {{url}} in new window",{url:r.url}):r.url},se.createElement("span",null,r.url),j&&n("open_in_new")),se.createElement(HM,{onClick:()=>{d()},title:b("linkPreview.edit","Edit link URL"),"aria-label":b("linkPreview.edit","Edit link URL")},n("edit")),se.createElement(cz,null,se.createElement(uz,{open:h},se.createElement(dz,{asChild:!0},se.createElement(HM,{title:b("linkPreview.copyToClipboard","Copy to clipboard"),"aria-label":b("linkPreview.copyToClipboard","Copy to clipboard"),onClick:()=>{window.navigator.clipboard.writeText(r.url).then(()=>{g(!0),setTimeout(()=>{g(!1)},1e3)})}},n(h?"check":"content_copy"))),se.createElement(fz,{container:e==null?void 0:e.current},se.createElement(mz,{className:Ds(Rt.tooltipContent),sideOffset:5},b("linkPreview.copied","Copied!"),se.createElement(ofe,null))))),se.createElement(HM,{title:b("linkPreview.remove","Remove link"),"aria-label":b("linkPreview.remove","Remove link"),onClick:()=>{f()}},n("link_off"))),se.createElement(YF,{className:Rt.popoverArrow}))))},HM=se.forwardRef(({className:e,...t},n)=>se.createElement("button",{className:Ds(Rt.actionButton,e),ref:n,...t}));function e$(e){if(!e)return null;const t=Itt(e);if(t===null)return null;const n=t.getParent();return kl(n)?n:kl(t)?t:null}const ibe=oa(),Zl=en({type:"inactive"},e=>{e.pub(b6,t=>t.registerCommand(A_,()=>e.getValue(Zl).type==="preview"?(e.pub(Zl,{type:"inactive"}),!0):!1,ri)),e.sub(e.pipe(y6),t=>{t!=="rich-text"&&e.pub(Zl,{type:"inactive"})}),e.pub(b6,t=>t.registerCommand(Bge,n=>{if(n.key==="k"&&(J0e?n.metaKey:n.ctrlKey)&&!e.getValue(Id)){const r=an();return hn(r)?(e.pub(ube),n.stopPropagation(),n.preventDefault(),!0):!1}return!1},m6)),e.sub(e.pipe(lbe,Pi(Zl,bi)),([,t,n])=>{if(t.type==="preview")setTimeout(()=>{n==null||n.getEditorState().read(()=>{const r=$f(t.linkNodeKey),i=kl(r)?r.getTextContent().length>0&&r.getChildrenSize()<=1:!1,a=i&&r?r.getTextContent():"";e.pub(Zl,{type:"edit",initialUrl:t.url,url:t.url,title:t.title,text:a,withAnchorText:i,linkNodeKey:t.linkNodeKey,rectangle:t.rectangle})})});else throw new Error("Cannot switch to edit mode when not in preview mode")}),e.sub(e.pipe(abe,Pi(bi,Zl,k5)),([t,n,r,i])=>{var a,o,l;const c=((a=t.text)==null?void 0:a.trim())??"",u=((o=t.url)==null?void 0:o.trim())??"",d=((l=t.title)==null?void 0:l.trim())??"";if(u!==""){if(i!=null&&i.isCollapsed()){const f=c||d||u;n==null||n.update(()=>{const h=e$(i);if(h)if(sd(h)){const g=C1(u,{title:d});g.append(Ru(c)),h.replace(g),g.select()}else h.setURL(u),h.setTitle(d),Lne(h.getFirstChild(),c);else{const g=C1(u,{title:d});g.append(Ru(f)),j4([g]),g.select()}},{discrete:!0})}else n==null||n.update(()=>{Lne(i==null?void 0:i.anchor.getNode(),c)}),n==null||n.dispatchCommand(j5,{url:u,title:d});e.pub(Zl,{type:"preview",linkNodeKey:r.linkNodeKey,rectangle:r.rectangle,title:d,url:u})}else r.type==="edit"&&r.initialUrl!==""&&(n==null||n.dispatchCommand(j5,null)),e.pub(Zl,{type:"inactive"})}),e.link(e.pipe(obe,Pi(Zl,bi),Mp(([,t,n])=>{if(t.type==="edit")return n==null||n.focus(),t.initialUrl===""?{type:"inactive"}:{type:"preview",url:t.initialUrl,linkNodeKey:t.linkNodeKey,rectangle:t.rectangle};throw new Error("Cannot cancel edit when not in edit mode")})),Zl),e.link(e.pipe(e.combine(k5,ibe),Pi(bi,Zl,Id),Mp(([[t],n,r,i])=>{if(hn(t)&&n&&!i){const a=e$(t);if(!t.isCollapsed())return{type:"inactive"};if(a){const o=G0e(n);return o?{type:"preview",url:a.getURL(),linkNodeKey:a.getKey(),title:a.getTitle(),rectangle:o}:{type:"inactive"}}else return{type:"inactive"}}else return{type:"inactive"}})),Zl)}),abe=oa(),obe=rg();rg();const lbe=rg(),cbe=rg(e=>{e.sub(e.pipe(cbe,Pi(bi)),([,t])=>{t==null||t.dispatchCommand(j5,null)})}),ube=rg(e=>{e.sub(e.pipe(ube,Pi(k5,bi),S7(([,t])=>hn(t))),([,t,n])=>{n==null||n.focus(()=>{setTimeout(()=>{n.getEditorState().read(()=>{const r=e$(t),i=G0e(n),a=(r==null?void 0:r.getURL())??"",o=(r==null?void 0:r.getURL())??"",l=(r==null?void 0:r.getTitle())??"",c=(r==null?void 0:r.getKey())??"",u=r?r.getTextContent().length>0&&r.getChildrenSize()<=1:!!(t!=null&&t.isCollapsed()),d=u&&r?r.getTextContent():"";e.pub(Zl,{type:"edit",initialUrl:a,url:o,title:l,text:d,withAnchorText:u,linkNodeKey:c,rectangle:i})})})})})}),dbe=en([]),fbe=en(null),mbe=en(null,e=>{e.pub(b6,t=>{function n(r){const[i,a]=e.getValues([Id,mbe]);!i||a===null||t.update(()=>{const o=l0(r.target);if(o!==null){const l=gd(o,c=>c instanceof Bd);l!==null&&a(r,l,l.getURL())}})}return t.registerRootListener((r,i)=>{r&&r.addEventListener("click",n),i&&i.removeEventListener("click",n)})})});function Lne(e,t){cs(e)&&t&&(e.setTextContent(t),e.selectStart())}const hbe=en(!0),Jft=Uo({init(e,t){e.pub(P0,(t==null?void 0:t.LinkDialog)??Yft),e.pub(fbe,(t==null?void 0:t.onClickLinkCallback)??null),e.pub(mbe,(t==null?void 0:t.onReadOnlyClickLinkCallback)??null),e.pub(hbe,(t==null?void 0:t.showLinkTitleField)??!0)},update(e,t={}){e.pub(dbe,t.linkAutocompleteSuggestions??[])}});var VM={exports:{}},$ne;function Xft(){return $ne||($ne=1,(function(e){var t=typeof window<"u"?window:typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?self:{};/**
1299
1299
  * Prism: Lightweight, robust, elegant syntax highlighting
1300
1300
  *
@@ -1380,7 +1380,7 @@ ${u}`,c.ts=l.ts):r.push({type:"stdout",ts:l.ts,text:u})}if(!t)for(const l of r)(
1380
1380
  `}),n.push(e[r]);return t&&e.length>0&&n.push({type:"text",value:`
1381
1381
  `}),n}function mse(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function hse(e,t){const n=K4t(e,t),r=n.one(e,void 0),i=U4t(n),a=Array.isArray(r)?{type:"root",children:r}:r||{type:"root",children:[]};return i&&a.children.push({type:"text",value:`
1382
1382
  `},i),a}function G4t(e,t){return e&&"run"in e?async function(n,r){const i=hse(n,{file:r,...t});await e.run(i,r)}:function(n,r){return hse(n,{file:r,...e||t})}}function pse(e){if(e)throw e}var bR,gse;function Q4t(){if(gse)return bR;gse=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=function(u){return typeof Array.isArray=="function"?Array.isArray(u):t.call(u)==="[object Array]"},a=function(u){if(!u||t.call(u)!=="[object Object]")return!1;var d=e.call(u,"constructor"),f=u.constructor&&u.constructor.prototype&&e.call(u.constructor.prototype,"isPrototypeOf");if(u.constructor&&!d&&!f)return!1;var h;for(h in u);return typeof h>"u"||e.call(u,h)},o=function(u,d){n&&d.name==="__proto__"?n(u,d.name,{enumerable:!0,configurable:!0,value:d.newValue,writable:!0}):u[d.name]=d.newValue},l=function(u,d){if(d==="__proto__")if(e.call(u,d)){if(r)return r(u,d).value}else return;return u[d]};return bR=function c(){var u,d,f,h,g,b,v=arguments[0],j=1,k=arguments.length,w=!1;for(typeof v=="boolean"&&(w=v,v=arguments[1]||{},j=2),(v==null||typeof v!="object"&&typeof v!="function")&&(v={});j<k;++j)if(u=arguments[j],u!=null)for(d in u)f=l(v,d),h=l(u,d),v!==h&&(w&&h&&(a(h)||(g=i(h)))?(g?(g=!1,b=f&&i(f)?f:[]):b=f&&a(f)?f:{},o(v,{name:d,newValue:c(w,b,h)})):typeof h<"u"&&o(v,{name:d,newValue:h}));return v},bR}var Y4t=Q4t();const yR=U5(Y4t);function S$(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function J4t(){const e=[],t={run:n,use:r};return t;function n(...i){let a=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);l(null,...i);function l(c,...u){const d=e[++a];let f=-1;if(c){o(c);return}for(;++f<i.length;)(u[f]===null||u[f]===void 0)&&(u[f]=i[f]);i=u,d?X4t(d,l)(...u):o(null,...u)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),t}}function X4t(e,t){let n;return r;function r(...o){const l=e.length>o.length;let c;l&&o.push(i);try{c=e.apply(this,o)}catch(u){const d=u;if(l&&n)throw d;return i(d)}l||(c&&c.then&&typeof c.then=="function"?c.then(a,i):c instanceof Error?i(c):a(c))}function i(o,...l){n||(n=!0,t(o,...l))}function a(o){i(null,o)}}const df={basename:ebt,dirname:tbt,extname:nbt,join:rbt,sep:"/"};function ebt(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');c8(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let o=-1,l=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),l>-1&&(e.codePointAt(i)===t.codePointAt(l--)?l<0&&(r=i):(l=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function tbt(e){if(c8(e),e.length===0)return".";let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||(r=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function nbt(e){c8(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){const l=e.codePointAt(t);if(l===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),l===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?"":e.slice(i,n)}function rbt(...e){let t=-1,n;for(;++t<e.length;)c8(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":sbt(n)}function sbt(e){c8(e);const t=e.codePointAt(0)===47;let n=ibt(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function ibt(e,t){let n="",r=0,i=-1,a=0,o=-1,l,c;for(;++o<=e.length;){if(o<e.length)l=e.codePointAt(o);else{if(l===47)break;l=47}if(l===47){if(!(i===o-1||a===1))if(i!==o-1&&a===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(c=n.lastIndexOf("/"),c!==n.length-1){c<0?(n="",r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf("/")),i=o,a=0;continue}}else if(n.length>0){n="",r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else l===46&&a>-1?a++:a=-1}return n}function c8(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const abt={cwd:obt};function obt(){return"/"}function _$(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function lbt(e){if(typeof e=="string")e=new URL(e);else if(!_$(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return cbt(e)}function cbt(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const r=t.codePointAt(n+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(t)}const vR=["history","path","basename","stem","extname","dirname"];class y6e{constructor(t){let n;t?_$(t)?n={path:t}:typeof t=="string"||ubt(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":abt.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<vR.length;){const a=vR[r];a in n&&n[a]!==void 0&&n[a]!==null&&(this[a]=a==="history"?[...n[a]]:n[a])}let i;for(i in n)vR.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?df.basename(this.path):void 0}set basename(t){kR(t,"basename"),wR(t,"basename"),this.path=df.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?df.dirname(this.path):void 0}set dirname(t){xse(this.basename,"dirname"),this.path=df.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?df.extname(this.path):void 0}set extname(t){if(wR(t,"extname"),xse(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=df.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){_$(t)&&(t=lbt(t)),kR(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?df.basename(this.path,this.extname):void 0}set stem(t){kR(t,"stem"),wR(t,"stem"),this.path=df.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const i=this.message(t,n,r);throw i.fatal=!0,i}info(t,n,r){const i=this.message(t,n,r);return i.fatal=void 0,i}message(t,n,r){const i=new ps(t,n,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function wR(e,t){if(e&&e.includes(df.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+df.sep+"`")}function kR(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function xse(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function ubt(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const dbt=(function(e){const r=this.constructor.prototype,i=r[e],a=function(){return i.apply(a,arguments)};return Object.setPrototypeOf(a,r),a}),fbt={}.hasOwnProperty;class nH extends dbt{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=J4t()}copy(){const t=new nH;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(yR(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(CR("data",this.frozen),this.namespace[t]=n,this):fbt.call(this.namespace,t)&&this.namespace[t]||void 0:t?(CR("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const i=n.call(t,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=Q9(t),r=this.parser||this.Parser;return jR("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),jR("process",this.parser||this.Parser),NR("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(a,o){const l=Q9(t),c=r.parse(l);r.run(c,l,function(d,f,h){if(d||!f||!h)return u(d);const g=f,b=r.stringify(g,h);pbt(b)?h.value=b:h.result=b,u(d,h)});function u(d,f){d||!f?o(d):a?a(f):n(void 0,f)}}}processSync(t){let n=!1,r;return this.freeze(),jR("processSync",this.parser||this.Parser),NR("processSync",this.compiler||this.Compiler),this.process(t,i),yse("processSync","process",n),r;function i(a,o){n=!0,pse(a),r=o}}run(t,n,r){bse(t),this.freeze();const i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?a(void 0,r):new Promise(a);function a(o,l){const c=Q9(n);i.run(t,c,u);function u(d,f,h){const g=f||t;d?l(d):o?o(g):r(void 0,g,h)}}}runSync(t,n){let r=!1,i;return this.run(t,n,a),yse("runSync","run",r),i;function a(o,l){pse(o),i=l,r=!0}}stringify(t,n){this.freeze();const r=Q9(n),i=this.compiler||this.Compiler;return NR("stringify",i),bse(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(CR("use",this.frozen),t!=null)if(typeof t=="function")c(t,n);else if(typeof t=="object")Array.isArray(t)?l(t):o(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function a(u){if(typeof u=="function")c(u,[]);else if(typeof u=="object")if(Array.isArray(u)){const[d,...f]=u;c(d,f)}else o(u);else throw new TypeError("Expected usable value, not `"+u+"`")}function o(u){if(!("plugins"in u)&&!("settings"in u))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");l(u.plugins),u.settings&&(i.settings=yR(!0,i.settings,u.settings))}function l(u){let d=-1;if(u!=null)if(Array.isArray(u))for(;++d<u.length;){const f=u[d];a(f)}else throw new TypeError("Expected a list of plugins, not `"+u+"`")}function c(u,d){let f=-1,h=-1;for(;++f<r.length;)if(r[f][0]===u){h=f;break}if(h===-1)r.push([u,...d]);else if(d.length>0){let[g,...b]=d;const v=r[h][1];S$(v)&&S$(g)&&(g=yR(!0,v,g)),r[h]=[u,g,...b]}}}}const mbt=new nH().freeze();function jR(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function NR(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function CR(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function bse(e){if(!S$(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function yse(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function Q9(e){return hbt(e)?e:new y6e(e)}function hbt(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function pbt(e){return typeof e=="string"||gbt(e)}function gbt(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const xbt="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",vse=[],wse={allowDangerousHtml:!0},bbt=/^(https?|ircs?|mailto|xmpp)$/i,ybt=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function vbt(e){const t=wbt(e),n=kbt(e);return jbt(t.runSync(t.parse(n),n),e)}function wbt(e){const t=e.rehypePlugins||vse,n=e.remarkPlugins||vse,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...wse}:wse;return mbt().use(c4t).use(n).use(G4t,r).use(t)}function kbt(e){const t=e.children||"",n=new y6e;return typeof t=="string"&&(n.value=t),n}function jbt(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,l=t.unwrapDisallowed,c=t.urlTransform||Nbt;for(const d of ybt)Object.hasOwn(t,d.from)&&(""+d.from+(d.to?"use `"+d.to+"` instead":"remove it")+xbt+d.id,void 0);return MU(e,u),W5t(e,{Fragment:s.Fragment,components:i,ignoreInvalidStyle:!0,jsx:s.jsx,jsxs:s.jsxs,passKeys:!0,passNode:!0});function u(d,f,h){if(d.type==="raw"&&h&&typeof f=="number")return o?h.children.splice(f,1):h.children[f]={type:"text",value:d.value},f;if(d.type==="element"){let g;for(g in xR)if(Object.hasOwn(xR,g)&&Object.hasOwn(d.properties,g)){const b=d.properties[g],v=xR[g];(v===null||v.includes(d.tagName))&&(d.properties[g]=c(String(b||""),g,d))}}if(d.type==="element"){let g=n?!n.includes(d.tagName):a?a.includes(d.tagName):!1;if(!g&&r&&typeof f=="number"&&(g=!r(d,f,h)),g&&h&&typeof f=="number")return l&&d.children?h.children.splice(f,1,...d.children):h.children.splice(f,1),f}}}function Nbt(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),i=e.indexOf("/");return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||bbt.test(e.slice(0,t))?e:""}function Cbt(e,t,n){const i=O_((n||{}).ignore||[]),a=Sbt(t);let o=-1;for(;++o<a.length;)D2e(e,"text",l);function l(u,d){let f=-1,h;for(;++f<d.length;){const g=d[f],b=h?h.children:void 0;if(i(g,b?b.indexOf(g):void 0,h))return;h=g}if(h)return c(u,d)}function c(u,d){const f=d[d.length-1],h=a[o][0],g=a[o][1];let b=0;const j=f.children.indexOf(u);let k=!1,w=[];h.lastIndex=0;let N=h.exec(u.value);for(;N;){const C=N.index,A={index:N.index,input:N.input,stack:[...d,u]};let _=g(...N,A);if(typeof _=="string"&&(_=_.length>0?{type:"text",value:_}:void 0),_===!1?h.lastIndex=C+1:(b!==C&&w.push({type:"text",value:u.value.slice(b,C)}),Array.isArray(_)?w.push(..._):_&&w.push(_),b=C+N[0].length,k=!0),!h.global)break;N=h.exec(u.value)}return k?(b<u.value.length&&w.push({type:"text",value:u.value.slice(b)}),f.children.splice(j,1,...w)):w=[u],j+w.length}}function Sbt(e){const t=[];if(!Array.isArray(e))throw new TypeError("Expected find and replace tuple or list of tuples");const n=!e[0]||Array.isArray(e[0])?e:[e];let r=-1;for(;++r<n.length;){const i=n[r];t.push([_bt(i[0]),Abt(i[1])])}return t}function _bt(e){return typeof e=="string"?new RegExp(Vst(e),"g"):e}function Abt(e){return typeof e=="function"?e:function(){return e}}const SR="phrasing",_R=["autolink","link","image","label"];function Ebt(){return{transforms:[Dbt],enter:{literalAutolink:Ibt,literalAutolinkEmail:AR,literalAutolinkHttp:AR,literalAutolinkWww:AR},exit:{literalAutolink:Pbt,literalAutolinkEmail:Obt,literalAutolinkHttp:Mbt,literalAutolinkWww:Rbt}}}function Tbt(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:SR,notInConstruct:_R},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:SR,notInConstruct:_R},{character:":",before:"[ps]",after:"\\/",inConstruct:SR,notInConstruct:_R}]}}function Ibt(e){this.enter({type:"link",title:null,url:"",children:[]},e)}function AR(e){this.config.enter.autolinkProtocol.call(this,e)}function Mbt(e){this.config.exit.autolinkProtocol.call(this,e)}function Rbt(e){this.config.exit.data.call(this,e);const t=this.stack[this.stack.length-1];t.type,t.url="http://"+this.sliceSerialize(e)}function Obt(e){this.config.exit.autolinkEmail.call(this,e)}function Pbt(e){this.exit(e)}function Dbt(e){Cbt(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,Lbt],[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)","gu"),$bt]],{ignore:["link","linkReference"]})}function Lbt(e,t,n,r,i){let a="";if(!v6e(i)||(/^w/i.test(t)&&(n=t+n,t="",a="http://"),!Fbt(n)))return!1;const o=zbt(n+r);if(!o[0])return!1;const l={type:"link",title:null,url:a+t+o[0],children:[{type:"text",value:t+o[0]}]};return o[1]?[l,{type:"text",value:o[1]}]:l}function $bt(e,t,n,r){return!v6e(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+t+"@"+n,children:[{type:"text",value:t+"@"+n}]}}function Fbt(e){const t=e.split(".");return!(t.length<2||t[t.length-1]&&(/_/.test(t[t.length-1])||!/[a-zA-Z\d]/.test(t[t.length-1]))||t[t.length-2]&&(/_/.test(t[t.length-2])||!/[a-zA-Z\d]/.test(t[t.length-2])))}function zbt(e){const t=/[!"&'),.:;<>?\]}]+$/.exec(e);if(!t)return[e,void 0];e=e.slice(0,t.index);let n=t[0],r=n.indexOf(")");const i=bN(e,"(");let a=bN(e,")");for(;r!==-1&&i>a;)e+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),a++;return[e,n]}function v6e(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||yl(n)||R_(n))&&(!t||n!==47)}w6e.peek=Gbt;function Bbt(){this.buffer()}function Ubt(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function qbt(){this.buffer()}function Kbt(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function Hbt(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=xd(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Vbt(e){this.exit(e)}function Wbt(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=xd(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Zbt(e){this.exit(e)}function Gbt(){return"["}function w6e(e,t,n,r){const i=n.createTracker(r);let a=i.move("[^");const o=n.enter("footnoteReference"),l=n.enter("reference");return a+=i.move(n.safe(n.associationId(e),{after:"]",before:a})),l(),o(),a+=i.move("]"),a}function Qbt(){return{enter:{gfmFootnoteCallString:Bbt,gfmFootnoteCall:Ubt,gfmFootnoteDefinitionLabelString:qbt,gfmFootnoteDefinition:Kbt},exit:{gfmFootnoteCallString:Hbt,gfmFootnoteCall:Vbt,gfmFootnoteDefinitionLabelString:Wbt,gfmFootnoteDefinition:Zbt}}}function Ybt(e){let t=!1;return e&&e.firstLineBlank&&(t=!0),{handlers:{footnoteDefinition:n,footnoteReference:w6e},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,i,a,o){const l=a.createTracker(o);let c=l.move("[^");const u=a.enter("footnoteDefinition"),d=a.enter("label");return c+=l.move(a.safe(a.associationId(r),{before:c,after:"]"})),d(),c+=l.move("]:"),r.children&&r.children.length>0&&(l.shift(4),c+=l.move((t?`
1383
- `:" ")+a.indentLines(a.containerFlow(r,l.current()),t?k6e:Jbt))),u(),c}}function Jbt(e,t,n){return t===0?e:k6e(e,t,n)}function k6e(e,t,n){return(n?"":" ")+e}function Xbt(){return[Ebt(),Qbt(),g2e(),axe(),sxe()]}function eyt(e){return{extensions:[Tbt(),Ybt(e),x2e(),oxe(e),ixe()]}}const tyt={tokenize:oyt,partial:!0},j6e={tokenize:lyt,partial:!0},N6e={tokenize:cyt,partial:!0},C6e={tokenize:uyt,partial:!0},nyt={tokenize:dyt,partial:!0},S6e={name:"wwwAutolink",tokenize:iyt,previous:A6e},_6e={name:"protocolAutolink",tokenize:ayt,previous:E6e},K1={name:"emailAutolink",tokenize:syt,previous:T6e},om={};function ryt(){return{text:om}}let Lg=48;for(;Lg<123;)om[Lg]=K1,Lg++,Lg===58?Lg=65:Lg===91&&(Lg=97);om[43]=K1;om[45]=K1;om[46]=K1;om[95]=K1;om[72]=[K1,_6e];om[104]=[K1,_6e];om[87]=[K1,S6e];om[119]=[K1,S6e];function syt(e,t,n){const r=this;let i,a;return o;function o(f){return!A$(f)||!T6e.call(r,r.previous)||rH(r.events)?n(f):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),l(f))}function l(f){return A$(f)?(e.consume(f),l):f===64?(e.consume(f),c):n(f)}function c(f){return f===46?e.check(nyt,d,u)(f):f===45||f===95||tl(f)?(a=!0,e.consume(f),c):d(f)}function u(f){return e.consume(f),i=!0,c}function d(f){return a&&i&&Cl(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(f)):n(f)}}function iyt(e,t,n){const r=this;return i;function i(o){return o!==87&&o!==119||!A6e.call(r,r.previous)||rH(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(tyt,e.attempt(j6e,e.attempt(N6e,a),n),n)(o))}function a(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function ayt(e,t,n){const r=this;let i="",a=!1;return o;function o(f){return(f===72||f===104)&&E6e.call(r,r.previous)&&!rH(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(f),e.consume(f),l):n(f)}function l(f){if(Cl(f)&&i.length<5)return i+=String.fromCodePoint(f),e.consume(f),l;if(f===58){const h=i.toLowerCase();if(h==="http"||h==="https")return e.consume(f),c}return n(f)}function c(f){return f===47?(e.consume(f),a?u:(a=!0,c)):n(f)}function u(f){return f===null||xN(f)||Jr(f)||yl(f)||R_(f)?n(f):e.attempt(j6e,e.attempt(N6e,d),n)(f)}function d(f){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(f)}}function oyt(e,t,n){let r=0;return i;function i(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),i):o===46&&r===3?(e.consume(o),a):n(o)}function a(o){return o===null?n(o):t(o)}}function lyt(e,t,n){let r,i,a;return o;function o(u){return u===46||u===95?e.check(C6e,c,l)(u):u===null||Jr(u)||yl(u)||u!==45&&R_(u)?c(u):(a=!0,e.consume(u),o)}function l(u){return u===95?r=!0:(i=r,r=void 0),e.consume(u),o}function c(u){return i||r||!a?n(u):t(u)}}function cyt(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?a(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(C6e,t,a)(o):o===null||Jr(o)||yl(o)?t(o):(e.consume(o),i)}function a(o){return o===41&&r++,e.consume(o),i}}function uyt(e,t,n){return r;function r(l){return l===33||l===34||l===39||l===41||l===42||l===44||l===46||l===58||l===59||l===63||l===95||l===126?(e.consume(l),r):l===38?(e.consume(l),a):l===93?(e.consume(l),i):l===60||l===null||Jr(l)||yl(l)?t(l):n(l)}function i(l){return l===null||l===40||l===91||Jr(l)||yl(l)?t(l):r(l)}function a(l){return Cl(l)?o(l):n(l)}function o(l){return l===59?(e.consume(l),r):Cl(l)?(e.consume(l),o):n(l)}}function dyt(e,t,n){return r;function r(a){return e.consume(a),i}function i(a){return tl(a)?n(a):t(a)}}function A6e(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||Jr(e)}function E6e(e){return!Cl(e)}function T6e(e){return!(e===47||A$(e))}function A$(e){return e===43||e===45||e===46||e===95||tl(e)}function rH(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const fyt={tokenize:vyt,partial:!0};function myt(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:xyt,continuation:{tokenize:byt},exit:yyt}},text:{91:{name:"gfmFootnoteCall",tokenize:gyt},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:hyt,resolveTo:pyt}}}}function hyt(e,t,n){const r=this;let i=r.events.length;const a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;i--;){const c=r.events[i][1];if(c.type==="labelImage"){o=c;break}if(c.type==="gfmFootnoteCall"||c.type==="labelLink"||c.type==="label"||c.type==="image"||c.type==="link")break}return l;function l(c){if(!o||!o._balanced)return n(c);const u=xd(r.sliceSerialize({start:o.end,end:r.now()}));return u.codePointAt(0)!==94||!a.includes(u.slice(1))?n(c):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(c),e.exit("gfmFootnoteCallLabelMarker"),t(c))}}function pyt(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const a={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},a.start),end:Object.assign({},a.end)},l=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",a,t],["enter",o,t],["exit",o,t],["exit",a,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...l),e}function gyt(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a=0,o;return l;function l(f){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),c}function c(f){return f!==94?n(f):(e.enter("gfmFootnoteCallMarker"),e.consume(f),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",u)}function u(f){if(a>999||f===93&&!o||f===null||f===91||Jr(f))return n(f);if(f===93){e.exit("chunkString");const h=e.exit("gfmFootnoteCallString");return i.includes(xd(r.sliceSerialize(h)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(f)}return Jr(f)||(o=!0),a++,e.consume(f),f===92?d:u}function d(f){return f===91||f===92||f===93?(e.consume(f),a++,u):u(f)}}function xyt(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a,o=0,l;return c;function c(b){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),u}function u(b){return b===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",d):n(b)}function d(b){if(o>999||b===93&&!l||b===null||b===91||Jr(b))return n(b);if(b===93){e.exit("chunkString");const v=e.exit("gfmFootnoteDefinitionLabelString");return a=xd(r.sliceSerialize(v)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),h}return Jr(b)||(l=!0),o++,e.consume(b),b===92?f:d}function f(b){return b===91||b===92||b===93?(e.consume(b),o++,d):d(b)}function h(b){return b===58?(e.enter("definitionMarker"),e.consume(b),e.exit("definitionMarker"),i.includes(a)||i.push(a),$r(e,g,"gfmFootnoteDefinitionWhitespace")):n(b)}function g(b){return t(b)}}function byt(e,t,n){return e.check(P7,t,e.attempt(fyt,t,n))}function yyt(e){e.exit("gfmFootnoteDefinition")}function vyt(e,t,n){const r=this;return $r(e,i,"gfmFootnoteDefinitionIndent",5);function i(a){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(a):n(a)}}function wyt(e){return t0e([ryt(),myt(),p2e(e),lxe(),rxe()])}const kyt={};function jyt(e){const t=this,n=e||kyt,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),a=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(wyt(n)),a.push(Xbt()),o.push(eyt(n))}const I6e="rudder.theme",kse="#1f1f1d",jse="#f1f0ef",M6e=x.createContext(void 0);function Nyt(){return typeof window>"u"?null:window.desktopShell??null}function R6e(){return typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Nse(){if(typeof window>"u")return"system";try{const e=window.localStorage.getItem(I6e);if(e==="light"||e==="dark"||e==="system")return e}catch{}return"system"}function tj(e){return e==="system"?R6e():e}function Cse(e){var a,o;if(typeof document>"u")return;const n=tj(e)==="dark",r=document.documentElement;r.classList.toggle("dark",n),r.style.colorScheme=n?"dark":"light",r.style.backgroundColor=r.classList.contains("desktop-shell-macos")?"transparent":n?kse:jse;const i=document.querySelector('meta[name="theme-color"]');i instanceof HTMLMetaElement&&i.setAttribute("content",n?kse:jse),(o=(a=Nyt())==null?void 0:a.setAppearance)==null||o.call(a,e)}function Cyt({children:e}){const[t,n]=x.useState(()=>Nse()),[r,i]=x.useState(()=>tj(Nse())),a=x.useCallback(c=>{n(c)},[]),o=x.useCallback(()=>{n(c=>tj(c)==="dark"?"light":"dark")},[]);x.useEffect(()=>{Cse(t),i(tj(t));try{localStorage.setItem(I6e,t)}catch{}},[t]),x.useEffect(()=>{if(typeof window>"u")return;const c=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{if(t!=="system")return;const d=R6e();i(d),Cse("system")};return c.addEventListener("change",u),()=>{c.removeEventListener("change",u)}},[t]);const l=x.useMemo(()=>({theme:t,resolvedTheme:r,setTheme:a,toggleTheme:o}),[t,r,a,o]);return s.jsx(M6e.Provider,{value:l,children:e})}function O6e(){const e=x.useContext(M6e);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}const Syt=190,_yt=178;function Ayt(e,t){return typeof window>"u"?{left:e,top:t}:{left:Math.min(e,Math.max(8,window.innerWidth-Syt)),top:Math.min(t,Math.max(8,window.innerHeight-_yt))}}function Eyt(e){return e instanceof Error?e.message:String(e)}function Tyt(){try{return _r()}catch{return null}}function Iyt({alt:e,className:t,name:n,onInspect:r,src:i,...a}){const o=Tyt(),l=x.useRef(null),c=x.useRef(null),[u,d]=x.useState(null),f=wK();x.useEffect(()=>{if(!u)return;const v=k=>{var w;(w=l.current)!=null&&w.contains(k.target)||d(null)},j=k=>{k.key==="Escape"&&d(null)};return document.addEventListener("pointerdown",v),document.addEventListener("keydown",j),()=>{document.removeEventListener("pointerdown",v),document.removeEventListener("keydown",j)}},[u]);const h=()=>{const v=c.current;!v||!r||r(v)},g=v=>{v.preventDefault(),v.stopPropagation(),d(Ayt(v.clientX,v.clientY))},b=async(v,j,k)=>{d(null);try{await j(),k&&(o==null||o.pushToast({title:k,tone:"success"}))}catch(w){o==null||o.pushToast({title:v,body:Eyt(w),tone:"error"})}};return s.jsxs("span",{className:"rudder-inspectable-image",children:[s.jsxs("button",{type:"button",className:"rudder-inspectable-image-trigger","aria-label":`Open image preview: ${n}`,title:"Open image preview",onClick:h,onDoubleClick:h,onContextMenu:g,children:[s.jsx("img",{...a,ref:c,src:i,alt:e??"",className:t,onContextMenu:g}),s.jsx("span",{className:"rudder-inspectable-image-overlay","aria-hidden":"true",children:s.jsx(x1,{className:"size-3.5"})})]}),u&&typeof document<"u"?oo.createPortal(s.jsxs("div",{ref:l,"data-testid":"markdown-image-context-menu",role:"menu",className:"motion-chat-composer-menu-pop surface-overlay fixed z-50 min-w-[190px] rounded-[var(--radius-lg)] border p-1.5 text-foreground shadow-[var(--shadow-lg)]",style:u,children:[s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Open Image failed",()=>$mt(i)),children:[s.jsx(Bc,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Open Image"})]}),s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Copy Image failed",()=>yK(i,n),"Image copied"),children:[s.jsx(Ni,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Copy Image"})]}),s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Download Image failed",()=>Lbe(i,n)),children:[s.jsx(Kf,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Download Image"})]}),f?s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Open in Finder failed",()=>vK(i,n)),children:[s.jsx(dc,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Open in Finder"})]}):null]}),document.body):null]})}function P6e({label:e,preview:t}){var c,u,d,f,h;const n=((c=t==null?void 0:t.displayName)==null?void 0:c.trim())||e,r=((u=t==null?void 0:t.description)==null?void 0:u.trim())||null,i=((d=t==null?void 0:t.categoryLabel)==null?void 0:d.trim())||null,a=((f=t==null?void 0:t.locationLabel)==null?void 0:f.trim())||null,o=((h=t==null?void 0:t.detailsHref)==null?void 0:h.trim())||null,l=!!(r||i||a||o);return s.jsxs("span",{className:G("rudder-skill-token-wrap",l&&"rudder-skill-token-wrap--preview"),children:[s.jsx("span",{className:"rudder-skill-token","data-skill-token":"true",tabIndex:l?0:void 0,"aria-label":l?`${n} skill`:void 0,children:e}),l?s.jsxs("span",{className:"rudder-skill-hover-card",role:"tooltip",children:[s.jsxs("span",{className:"flex items-start gap-3",children:[s.jsx("span",{className:"mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-[var(--radius-md)] bg-[#2f80ed]/10 text-[#2f80ed]",children:s.jsx(zc,{className:"h-4 w-4","aria-hidden":!0})}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"block truncate text-sm font-medium text-foreground",children:n}),i||a?s.jsxs("span",{className:"mt-1.5 flex min-w-0 flex-wrap items-center gap-1.5",children:[i?s.jsx("span",{className:"inline-flex items-center rounded-[var(--radius-sm)] border border-border/70 bg-muted/50 px-1.5 py-0.5 text-[11px] font-medium leading-none text-muted-foreground",children:i}):null,a?s.jsx("span",{className:"min-w-0 truncate text-[11px] leading-none text-muted-foreground",children:a}):null]}):null,r?s.jsx("span",{className:"mt-1 block text-xs leading-5 text-muted-foreground",children:r}):null]})]}),o?s.jsxs("a",{className:"rudder-skill-hover-card-action",href:o,children:[s.jsx("span",{children:"View details"}),s.jsx(p1,{className:"h-3.5 w-3.5","aria-hidden":!0})]}):null]}):null]})}let ER=null;function Myt(){return ER||(ER=mt(()=>import("./mermaid.core-DzTz01fK.js").then(e=>e.bF),[]).then(e=>e.default)),ER}function Tv(e){return e==null?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(t=>Tv(t)).join(""):""}function Y9(e){return(e==null?void 0:e.trim().replace(/\/+$/u,"").toLowerCase())??""}function Ryt(e){const t=(e==null?void 0:e.trim())??"";if(!t)return!1;if(t.startsWith("//"))return!0;if(!/^[a-z][a-z\d+.-]*:/iu.test(t))return!1;try{const n=new URL(t);return n.protocol==="http:"||n.protocol==="https:"||n.protocol==="mailto:"}catch{return!1}}function Oyt(e){const t=e.trim();return/^(?:https?:\/\/|www\.|\/\/)/iu.test(t)}function Pyt(e){if(!x.isValidElement(e))return null;const t=e.props;return typeof t.className!="string"||!/\blanguage-mermaid\b/i.test(t.className)?null:Tv(t.children).replace(/\n$/,"")}function Dyt(e){const t=e.alt.trim();if(t)return t;const n=e.currentSrc||e.src;try{const i=new URL(n,window.location.href).pathname.split("/").filter(Boolean).at(-1);return i?decodeURIComponent(i):"Image preview"}catch{return"Image preview"}}function Lyt(e){var o,l;if(!e.includes("\\n"))return e;const t=((o=e.match(/\\n/g))==null?void 0:o.length)??0;if(t===0)return e;const n=((l=e.match(/\n/g))==null?void 0:l.length)??0,r=e.includes("\\n\\n"),i=/\\n\s*(?:[-*+]\s|\d+\.\s)/.test(e),a=n===0&&t>=3;return!r&&!i&&!a?e:e.replace(/\\r\\n/g,`
1383
+ `:" ")+a.indentLines(a.containerFlow(r,l.current()),t?k6e:Jbt))),u(),c}}function Jbt(e,t,n){return t===0?e:k6e(e,t,n)}function k6e(e,t,n){return(n?"":" ")+e}function Xbt(){return[Ebt(),Qbt(),g2e(),axe(),sxe()]}function eyt(e){return{extensions:[Tbt(),Ybt(e),x2e(),oxe(e),ixe()]}}const tyt={tokenize:oyt,partial:!0},j6e={tokenize:lyt,partial:!0},N6e={tokenize:cyt,partial:!0},C6e={tokenize:uyt,partial:!0},nyt={tokenize:dyt,partial:!0},S6e={name:"wwwAutolink",tokenize:iyt,previous:A6e},_6e={name:"protocolAutolink",tokenize:ayt,previous:E6e},K1={name:"emailAutolink",tokenize:syt,previous:T6e},om={};function ryt(){return{text:om}}let Lg=48;for(;Lg<123;)om[Lg]=K1,Lg++,Lg===58?Lg=65:Lg===91&&(Lg=97);om[43]=K1;om[45]=K1;om[46]=K1;om[95]=K1;om[72]=[K1,_6e];om[104]=[K1,_6e];om[87]=[K1,S6e];om[119]=[K1,S6e];function syt(e,t,n){const r=this;let i,a;return o;function o(f){return!A$(f)||!T6e.call(r,r.previous)||rH(r.events)?n(f):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),l(f))}function l(f){return A$(f)?(e.consume(f),l):f===64?(e.consume(f),c):n(f)}function c(f){return f===46?e.check(nyt,d,u)(f):f===45||f===95||tl(f)?(a=!0,e.consume(f),c):d(f)}function u(f){return e.consume(f),i=!0,c}function d(f){return a&&i&&Cl(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(f)):n(f)}}function iyt(e,t,n){const r=this;return i;function i(o){return o!==87&&o!==119||!A6e.call(r,r.previous)||rH(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(tyt,e.attempt(j6e,e.attempt(N6e,a),n),n)(o))}function a(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function ayt(e,t,n){const r=this;let i="",a=!1;return o;function o(f){return(f===72||f===104)&&E6e.call(r,r.previous)&&!rH(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(f),e.consume(f),l):n(f)}function l(f){if(Cl(f)&&i.length<5)return i+=String.fromCodePoint(f),e.consume(f),l;if(f===58){const h=i.toLowerCase();if(h==="http"||h==="https")return e.consume(f),c}return n(f)}function c(f){return f===47?(e.consume(f),a?u:(a=!0,c)):n(f)}function u(f){return f===null||xN(f)||Jr(f)||yl(f)||R_(f)?n(f):e.attempt(j6e,e.attempt(N6e,d),n)(f)}function d(f){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(f)}}function oyt(e,t,n){let r=0;return i;function i(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),i):o===46&&r===3?(e.consume(o),a):n(o)}function a(o){return o===null?n(o):t(o)}}function lyt(e,t,n){let r,i,a;return o;function o(u){return u===46||u===95?e.check(C6e,c,l)(u):u===null||Jr(u)||yl(u)||u!==45&&R_(u)?c(u):(a=!0,e.consume(u),o)}function l(u){return u===95?r=!0:(i=r,r=void 0),e.consume(u),o}function c(u){return i||r||!a?n(u):t(u)}}function cyt(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?a(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(C6e,t,a)(o):o===null||Jr(o)||yl(o)?t(o):(e.consume(o),i)}function a(o){return o===41&&r++,e.consume(o),i}}function uyt(e,t,n){return r;function r(l){return l===33||l===34||l===39||l===41||l===42||l===44||l===46||l===58||l===59||l===63||l===95||l===126?(e.consume(l),r):l===38?(e.consume(l),a):l===93?(e.consume(l),i):l===60||l===null||Jr(l)||yl(l)?t(l):n(l)}function i(l){return l===null||l===40||l===91||Jr(l)||yl(l)?t(l):r(l)}function a(l){return Cl(l)?o(l):n(l)}function o(l){return l===59?(e.consume(l),r):Cl(l)?(e.consume(l),o):n(l)}}function dyt(e,t,n){return r;function r(a){return e.consume(a),i}function i(a){return tl(a)?n(a):t(a)}}function A6e(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||Jr(e)}function E6e(e){return!Cl(e)}function T6e(e){return!(e===47||A$(e))}function A$(e){return e===43||e===45||e===46||e===95||tl(e)}function rH(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const fyt={tokenize:vyt,partial:!0};function myt(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:xyt,continuation:{tokenize:byt},exit:yyt}},text:{91:{name:"gfmFootnoteCall",tokenize:gyt},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:hyt,resolveTo:pyt}}}}function hyt(e,t,n){const r=this;let i=r.events.length;const a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;i--;){const c=r.events[i][1];if(c.type==="labelImage"){o=c;break}if(c.type==="gfmFootnoteCall"||c.type==="labelLink"||c.type==="label"||c.type==="image"||c.type==="link")break}return l;function l(c){if(!o||!o._balanced)return n(c);const u=xd(r.sliceSerialize({start:o.end,end:r.now()}));return u.codePointAt(0)!==94||!a.includes(u.slice(1))?n(c):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(c),e.exit("gfmFootnoteCallLabelMarker"),t(c))}}function pyt(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const a={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},a.start),end:Object.assign({},a.end)},l=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",a,t],["enter",o,t],["exit",o,t],["exit",a,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...l),e}function gyt(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a=0,o;return l;function l(f){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),c}function c(f){return f!==94?n(f):(e.enter("gfmFootnoteCallMarker"),e.consume(f),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",u)}function u(f){if(a>999||f===93&&!o||f===null||f===91||Jr(f))return n(f);if(f===93){e.exit("chunkString");const h=e.exit("gfmFootnoteCallString");return i.includes(xd(r.sliceSerialize(h)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(f)}return Jr(f)||(o=!0),a++,e.consume(f),f===92?d:u}function d(f){return f===91||f===92||f===93?(e.consume(f),a++,u):u(f)}}function xyt(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a,o=0,l;return c;function c(b){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),u}function u(b){return b===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",d):n(b)}function d(b){if(o>999||b===93&&!l||b===null||b===91||Jr(b))return n(b);if(b===93){e.exit("chunkString");const v=e.exit("gfmFootnoteDefinitionLabelString");return a=xd(r.sliceSerialize(v)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),h}return Jr(b)||(l=!0),o++,e.consume(b),b===92?f:d}function f(b){return b===91||b===92||b===93?(e.consume(b),o++,d):d(b)}function h(b){return b===58?(e.enter("definitionMarker"),e.consume(b),e.exit("definitionMarker"),i.includes(a)||i.push(a),$r(e,g,"gfmFootnoteDefinitionWhitespace")):n(b)}function g(b){return t(b)}}function byt(e,t,n){return e.check(P7,t,e.attempt(fyt,t,n))}function yyt(e){e.exit("gfmFootnoteDefinition")}function vyt(e,t,n){const r=this;return $r(e,i,"gfmFootnoteDefinitionIndent",5);function i(a){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(a):n(a)}}function wyt(e){return t0e([ryt(),myt(),p2e(e),lxe(),rxe()])}const kyt={};function jyt(e){const t=this,n=e||kyt,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),a=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(wyt(n)),a.push(Xbt()),o.push(eyt(n))}const I6e="rudder.theme",kse="#1f1f1d",jse="#f1f0ef",M6e=x.createContext(void 0);function Nyt(){return typeof window>"u"?null:window.desktopShell??null}function R6e(){return typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Nse(){if(typeof window>"u")return"system";try{const e=window.localStorage.getItem(I6e);if(e==="light"||e==="dark"||e==="system")return e}catch{}return"system"}function tj(e){return e==="system"?R6e():e}function Cse(e){var a,o;if(typeof document>"u")return;const n=tj(e)==="dark",r=document.documentElement;r.classList.toggle("dark",n),r.style.colorScheme=n?"dark":"light",r.style.backgroundColor=r.classList.contains("desktop-shell-macos")?"transparent":n?kse:jse;const i=document.querySelector('meta[name="theme-color"]');i instanceof HTMLMetaElement&&i.setAttribute("content",n?kse:jse),(o=(a=Nyt())==null?void 0:a.setAppearance)==null||o.call(a,e)}function Cyt({children:e}){const[t,n]=x.useState(()=>Nse()),[r,i]=x.useState(()=>tj(Nse())),a=x.useCallback(c=>{n(c)},[]),o=x.useCallback(()=>{n(c=>tj(c)==="dark"?"light":"dark")},[]);x.useEffect(()=>{Cse(t),i(tj(t));try{localStorage.setItem(I6e,t)}catch{}},[t]),x.useEffect(()=>{if(typeof window>"u")return;const c=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{if(t!=="system")return;const d=R6e();i(d),Cse("system")};return c.addEventListener("change",u),()=>{c.removeEventListener("change",u)}},[t]);const l=x.useMemo(()=>({theme:t,resolvedTheme:r,setTheme:a,toggleTheme:o}),[t,r,a,o]);return s.jsx(M6e.Provider,{value:l,children:e})}function O6e(){const e=x.useContext(M6e);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}const Syt=190,_yt=178;function Ayt(e,t){return typeof window>"u"?{left:e,top:t}:{left:Math.min(e,Math.max(8,window.innerWidth-Syt)),top:Math.min(t,Math.max(8,window.innerHeight-_yt))}}function Eyt(e){return e instanceof Error?e.message:String(e)}function Tyt(){try{return _r()}catch{return null}}function Iyt({alt:e,className:t,name:n,onInspect:r,src:i,...a}){const o=Tyt(),l=x.useRef(null),c=x.useRef(null),[u,d]=x.useState(null),f=wK();x.useEffect(()=>{if(!u)return;const v=k=>{var w;(w=l.current)!=null&&w.contains(k.target)||d(null)},j=k=>{k.key==="Escape"&&d(null)};return document.addEventListener("pointerdown",v),document.addEventListener("keydown",j),()=>{document.removeEventListener("pointerdown",v),document.removeEventListener("keydown",j)}},[u]);const h=()=>{const v=c.current;!v||!r||r(v)},g=v=>{v.preventDefault(),v.stopPropagation(),d(Ayt(v.clientX,v.clientY))},b=async(v,j,k)=>{d(null);try{await j(),k&&(o==null||o.pushToast({title:k,tone:"success"}))}catch(w){o==null||o.pushToast({title:v,body:Eyt(w),tone:"error"})}};return s.jsxs("span",{className:"rudder-inspectable-image",children:[s.jsxs("button",{type:"button",className:"rudder-inspectable-image-trigger","aria-label":`Open image preview: ${n}`,title:"Open image preview",onClick:h,onDoubleClick:h,onContextMenu:g,children:[s.jsx("img",{...a,ref:c,src:i,alt:e??"",className:t,onContextMenu:g}),s.jsx("span",{className:"rudder-inspectable-image-overlay","aria-hidden":"true",children:s.jsx(x1,{className:"size-3.5"})})]}),u&&typeof document<"u"?oo.createPortal(s.jsxs("div",{ref:l,"data-testid":"markdown-image-context-menu",role:"menu",className:"motion-chat-composer-menu-pop surface-overlay fixed z-50 min-w-[190px] rounded-[var(--radius-lg)] border p-1.5 text-foreground shadow-[var(--shadow-lg)]",style:u,children:[s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Open Image failed",()=>$mt(i)),children:[s.jsx(Bc,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Open Image"})]}),s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Copy Image failed",()=>yK(i,n),"Image copied"),children:[s.jsx(Ni,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Copy Image"})]}),s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Download Image failed",()=>Lbe(i,n)),children:[s.jsx(Kf,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Download Image"})]}),f?s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Open in Finder failed",()=>vK(i,n)),children:[s.jsx(dc,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Open in Finder"})]}):null]}),document.body):null]})}function P6e({label:e,preview:t}){var c,u,d,f,h;const n=((c=t==null?void 0:t.displayName)==null?void 0:c.trim())||e,r=((u=t==null?void 0:t.description)==null?void 0:u.trim())||null,i=((d=t==null?void 0:t.categoryLabel)==null?void 0:d.trim())||null,a=((f=t==null?void 0:t.locationLabel)==null?void 0:f.trim())||null,o=((h=t==null?void 0:t.detailsHref)==null?void 0:h.trim())||null,l=!!(r||i||a||o);return s.jsxs("span",{className:G("rudder-skill-token-wrap",l&&"rudder-skill-token-wrap--preview"),children:[s.jsx("span",{className:"rudder-skill-token","data-skill-token":"true",tabIndex:l?0:void 0,"aria-label":l?`${n} skill`:void 0,children:e}),l?s.jsxs("span",{className:"rudder-skill-hover-card",role:"tooltip",children:[s.jsxs("span",{className:"flex items-start gap-3",children:[s.jsx("span",{className:"mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-[var(--radius-md)] bg-[#2f80ed]/10 text-[#2f80ed]",children:s.jsx(zc,{className:"h-4 w-4","aria-hidden":!0})}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"block truncate text-sm font-medium text-foreground",children:n}),i||a?s.jsxs("span",{className:"mt-1.5 flex min-w-0 flex-wrap items-center gap-1.5",children:[i?s.jsx("span",{className:"inline-flex items-center rounded-[var(--radius-sm)] border border-border/70 bg-muted/50 px-1.5 py-0.5 text-[11px] font-medium leading-none text-muted-foreground",children:i}):null,a?s.jsx("span",{className:"min-w-0 truncate text-[11px] leading-none text-muted-foreground",children:a}):null]}):null,r?s.jsx("span",{className:"mt-1 block text-xs leading-5 text-muted-foreground",children:r}):null]})]}),o?s.jsxs("a",{className:"rudder-skill-hover-card-action",href:o,children:[s.jsx("span",{children:"View details"}),s.jsx(p1,{className:"h-3.5 w-3.5","aria-hidden":!0})]}):null]}):null]})}let ER=null;function Myt(){return ER||(ER=mt(()=>import("./mermaid.core-D3HFVWWP.js").then(e=>e.bF),[]).then(e=>e.default)),ER}function Tv(e){return e==null?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(t=>Tv(t)).join(""):""}function Y9(e){return(e==null?void 0:e.trim().replace(/\/+$/u,"").toLowerCase())??""}function Ryt(e){const t=(e==null?void 0:e.trim())??"";if(!t)return!1;if(t.startsWith("//"))return!0;if(!/^[a-z][a-z\d+.-]*:/iu.test(t))return!1;try{const n=new URL(t);return n.protocol==="http:"||n.protocol==="https:"||n.protocol==="mailto:"}catch{return!1}}function Oyt(e){const t=e.trim();return/^(?:https?:\/\/|www\.|\/\/)/iu.test(t)}function Pyt(e){if(!x.isValidElement(e))return null;const t=e.props;return typeof t.className!="string"||!/\blanguage-mermaid\b/i.test(t.className)?null:Tv(t.children).replace(/\n$/,"")}function Dyt(e){const t=e.alt.trim();if(t)return t;const n=e.currentSrc||e.src;try{const i=new URL(n,window.location.href).pathname.split("/").filter(Boolean).at(-1);return i?decodeURIComponent(i):"Image preview"}catch{return"Image preview"}}function Lyt(e){var o,l;if(!e.includes("\\n"))return e;const t=((o=e.match(/\\n/g))==null?void 0:o.length)??0;if(t===0)return e;const n=((l=e.match(/\n/g))==null?void 0:l.length)??0,r=e.includes("\\n\\n"),i=/\\n\s*(?:[-*+]\s|\d+\.\s)/.test(e),a=n===0&&t>=3;return!r&&!i&&!a?e:e.replace(/\\r\\n/g,`
1384
1384
  `).replace(/\\n/g,`
1385
1385
  `)}function $yt({source:e,darkMode:t}){const n=x.useId().replace(/[^a-zA-Z0-9_-]/g,""),[r,i]=x.useState(null),[a,o]=x.useState(null);return x.useEffect(()=>{let l=!0;return i(null),o(null),Myt().then(async c=>{c.initialize({startOnLoad:!1,securityLevel:"strict",theme:t?"dark":"default",fontFamily:"inherit",suppressErrorRendering:!0});const u=await c.render(`rudder-mermaid-${n}`,e);l&&i(u.svg)}).catch(c=>{if(!l)return;const u=c instanceof Error&&c.message?c.message:"Failed to render Mermaid diagram.";o(u)}),()=>{l=!1}},[t,n,e]),s.jsx("div",{className:"rudder-mermaid",children:r?s.jsx("div",{dangerouslySetInnerHTML:{__html:r}}):s.jsxs(s.Fragment,{children:[s.jsx("p",{className:G("rudder-mermaid-status",a&&"rudder-mermaid-status-error"),children:a?`Unable to render Mermaid diagram: ${a}`:"Rendering Mermaid diagram..."}),s.jsx("pre",{className:"rudder-mermaid-source",children:s.jsx("code",{className:"language-mermaid",children:e})})]})})}function Aa({children:e,className:t,resolveImageSrc:n,onLinkClick:r,skillReferences:i,enableImagePreview:a=!0}){const{resolvedTheme:o}=O6e(),[l,c]=x.useState(null),u=new Map((i??[]).map(b=>[Y9(b.href),b]).filter(([b])=>b.length>0)),d=new Map((i??[]).map(b=>[Y9(b.label),b]).filter(([b])=>b.length>0)),f=Lyt(e),h=b=>{if(!a)return;const v=b.currentSrc||b.src;v&&c({alt:b.alt,name:Dyt(b),src:v,naturalSize:b.naturalWidth>0&&b.naturalHeight>0?{width:b.naturalWidth,height:b.naturalHeight}:null})},g={pre:({node:b,children:v,...j})=>{const k=Pyt(v);return k?s.jsx($yt,{source:k,darkMode:o==="dark"}):s.jsx("pre",{...j,children:v})},a:({href:b,children:v})=>{const j=b?ug(b):null;if(j){const A=J7(Tv(v)),_=j.kind==="project"?`/projects/${j.projectId}`:j.kind==="issue"?`/issues/${j.ref??j.issueId}`:`/agents/${j.agentId}`;return s.jsx("a",{href:_,className:G("rudder-mention-chip",`rudder-mention-chip--${j.kind}`,j.kind==="project"&&"rudder-project-mention-chip"),"data-mention-kind":j.kind,style:$be(j),children:A})}const k=m4(b,Tv(v));if(k){const A=u.get(Y9(k.href))??d.get(Y9(k.label))??null;return s.jsx(P6e,{label:k.label,preview:A})}const w=Tv(v),N=Ryt(b),C=N&&Oyt(w);return s.jsx("a",{href:b,target:N?"_blank":void 0,rel:N?"noreferrer noopener":"noreferrer",title:C?b:void 0,onClick:A=>{!b||!r||r({event:A,href:b,label:w})},children:v})}};return g.img=({node:b,src:v,alt:j,...k})=>{const N=(v&&n?n(v):null)??v??"";return a&&N?s.jsx(Iyt,{...k,src:N,alt:j??"",name:(j==null?void 0:j.trim())||"Markdown image",onInspect:h}):s.jsx("img",{...k,src:N,alt:j??""})},s.jsxs(s.Fragment,{children:[s.jsx("div",{className:G("rudder-markdown prose prose-sm max-w-none break-words overflow-hidden",o==="dark"&&"prose-invert",t),children:s.jsx(vbt,{remarkPlugins:[jyt],components:g,urlTransform:b=>b,children:f})}),a?s.jsx(kK,{preview:l,onOpenChange:b=>{b||c(null)},testId:"markdown-body-image-preview-dialog",titleFallback:"Image preview"}):null]})}function D6e({block:e,density:t,presentation:n="default",className:r,collapsibleSummary:i=!1,onMarkdownLinkClick:a}){const o=t==="compact",l=e.role==="user",c=l&&n!=="detail",[u,d]=x.useState(!0),f=s.jsx(Aa,{className:G("[&>*:first-child]:mt-0 [&>*:last-child]:mb-0",o?"text-xs leading-5 text-foreground/85":n==="detail"?"text-sm leading-7":"text-sm",r),onLinkClick:a,children:e.text});return!l||!i?s.jsxs("div",{title:uc(e.ts),children:[c&&s.jsxs("div",{className:"mb-1.5 flex items-center gap-2 text-[11px] font-semibold tracking-[0.06em] text-muted-foreground",children:[s.jsx(Hf,{className:o?"h-3.5 w-3.5":"h-4 w-4"}),s.jsx("span",{children:"User"})]}),f]}):s.jsxs("div",{className:"rounded-lg border border-border/30 bg-muted/10",title:uc(e.ts),children:[s.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-2.5 py-2 text-left",onClick:()=>d(h=>!h),"aria-expanded":u,"aria-label":u?"Collapse user message":"Expand user message",children:[s.jsx(Pd,{open:u,className:"h-4 w-4 shrink-0 text-muted-foreground"}),s.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold tracking-[0.06em] text-muted-foreground",children:[s.jsx(Hf,{className:o?"h-3.5 w-3.5":"h-4 w-4"}),s.jsx("span",{children:"User"})]})]}),u&&s.jsx("div",{className:"motion-disclosure-enter border-t border-border/20 px-2.5 pb-2.5 pt-2",children:f})]})}function L6e({block:e,density:t,className:n,collapsibleSummary:r=!1,onMarkdownLinkClick:i}){const[a,o]=x.useState(()=>!!e.streaming);x.useEffect(()=>{e.streaming&&o(!0)},[e.streaming]);const l=ji(e.text),c=bu(l,t==="compact"?100:160),u=s.jsx(Aa,{className:G("italic text-foreground/75 [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",t==="compact"?"text-[11px] leading-5":"text-sm leading-6",n),onLinkClick:i,children:e.text});return r?s.jsxs("div",{className:"rounded-lg border border-border/30 bg-muted/10",title:uc(e.ts),children:[s.jsxs("button",{type:"button",className:"flex w-full items-start gap-2 px-2.5 py-2 text-left",onClick:()=>o(d=>!d),"aria-expanded":a,"aria-label":a?"Collapse thinking":"Expand thinking",children:[e.streaming?s.jsx(yr,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground","aria-hidden":!0}):s.jsx(Pd,{open:a,className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"text-[11px] font-medium tracking-wide text-muted-foreground",children:"Thinking"}),!a&&!e.streaming?s.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] leading-5 text-foreground/55",children:c||"…"}):null]})]}),(a||e.streaming)&&s.jsx("div",{className:"motion-disclosure-enter border-t border-border/20 px-2.5 pb-2.5 pt-2",children:u})]}):u}function sH({block:e,index:t,density:n,presentation:r,collapseStdout:i,thinkingClassName:a,onMarkdownLinkClick:o}){return s.jsxs("div",{className:G(t===-1&&"hidden"),children:[e.type==="message"&&s.jsx(D6e,{block:e,density:n,presentation:r,collapsibleSummary:r==="chat",onMarkdownLinkClick:o}),e.type==="thinking"&&s.jsx(L6e,{block:e,density:n,className:a,onMarkdownLinkClick:o}),e.type==="tool"&&s.jsx(iH,{block:e,density:n,presentation:r}),e.type==="command_group"&&s.jsx(zyt,{block:e,density:n}),e.type==="todo_list"&&s.jsx(U6e,{block:e,density:n,presentation:r}),e.type==="stdout"&&s.jsx(K6e,{block:e,density:n,collapseByDefault:i,presentation:r}),e.type==="memory_update"&&s.jsx(Byt,{block:e,density:n}),e.type==="activity"&&s.jsx(B6e,{block:e,density:n}),e.type==="event"&&s.jsx(q6e,{block:e,density:n,presentation:r})]},`${e.type}-${e.ts}-${t}`)}function $6e({command:e,output:t,status:n,className:r}){return s.jsxs("div",{"data-testid":"command-terminal-detail",className:G("overflow-hidden rounded-xl border border-neutral-800 bg-[#0a0a0a] text-neutral-100 shadow-[0_18px_45px_-28px_rgb(0_0_0/0.75)]",r),children:[s.jsxs("div",{className:"flex h-8 items-center gap-1.5 border-b border-white/10 bg-[#171717] px-3",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full bg-[#ff5f57]"}),s.jsx("span",{className:"h-2.5 w-2.5 rounded-full bg-[#febc2e]"}),s.jsx("span",{className:"h-2.5 w-2.5 rounded-full bg-[#28c840]"})]}),s.jsxs("div",{className:"p-4 font-mono text-[11px] leading-5",children:[s.jsxs("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-neutral-100",children:[s.jsx("span",{className:"select-none text-emerald-400",children:"$ "}),e]}),t?s.jsx("pre",{className:G("mt-3 overflow-x-auto whitespace-pre-wrap break-words",n==="error"?"text-red-300":"text-neutral-200"),children:t}):null]})]})}function Fyt(e){if(typeof e.input=="string"&&dg(e.name,e.input))return bd(e.input);const t=Ei(e.input);if(t){if(typeof t.command=="string")return bd(t.command);if(typeof t.cmd=="string")return bd(t.cmd)}return null}function iH({block:e,density:t,presentation:n="default"}){const[r,i]=x.useState(n!=="detail"&&e.status==="error"),a=t==="compact",o=n==="detail",l=Wp(e.name,e.input),c=dg(e.name,e.input),u=e.status==="running"?"Running":e.status==="error"?"Errored":c?null:"Completed",d=e.status==="running"?"text-cyan-700 dark:text-cyan-300":e.status==="error"?"text-red-700 dark:text-red-300":"text-emerald-700 dark:text-emerald-300",f=Rve(e.ts,e.endTs),h=Fyt(e),g=h??($5(e.input)||"<empty>"),b=h?Gve(e.result):e.result?$5(e.result):"Waiting for result...",v=G("space-y-3",e.status==="error"&&"rounded-xl border border-red-500/20 bg-red-500/[0.06] p-3",o&&"rounded-xl border border-border/40 bg-background/60 p-3"),j=l.summary,k=G(o&&"rounded-xl border border-border/60 bg-background/80 p-3 shadow-sm",e.status==="error"&&"rounded-xl border border-red-500/20 bg-red-500/[0.04] p-3");return s.jsxs("div",{className:k,title:uc(e.ts),children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(V6,{category:l.category,status:e.status}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:"text-[11px] font-semibold tracking-[0.06em] text-muted-foreground",children:l.label}),u?s.jsx("span",{className:G("text-[10px] font-semibold tracking-[0.05em]",d),children:u}):null,f&&s.jsx("span",{className:"text-[10px] font-medium tracking-[0.04em] text-muted-foreground",children:f})]}),s.jsx("div",{className:G("mt-1 break-words text-foreground/80",a?"text-xs":"text-sm"),children:j})]}),s.jsx("button",{type:"button",className:"mt-0.5 inline-flex h-5 w-5 items-center justify-center text-muted-foreground transition-colors hover:text-foreground",onClick:()=>i(w=>!w),"aria-expanded":r,"aria-label":r?`Collapse ${c?"command":"tool"} details`:`Expand ${c?"command":"tool"} details`,children:s.jsx(Pd,{open:r,className:"h-4 w-4"})})]}),r&&s.jsx("div",{className:"motion-disclosure-enter mt-3",children:h?s.jsx($6e,{command:g,output:b,status:e.status}):s.jsx("div",{className:v,children:s.jsxs("div",{className:G("grid gap-3",a?"grid-cols-1":"lg:grid-cols-2"),children:[s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-[10px] font-semibold tracking-[0.06em] text-muted-foreground",children:"Request"}),s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words font-mono text-[11px] text-foreground/80",children:g})]}),s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-[10px] font-semibold tracking-[0.06em] text-muted-foreground",children:"Response"}),s.jsx("pre",{className:G("overflow-x-auto whitespace-pre-wrap break-words font-mono text-[11px]",e.status==="error"?"text-red-700 dark:text-red-300":"text-foreground/80"),children:b??"No response"})]})]})})})]})}function F6e(){var e;return typeof window>"u"?!1:(((e=window.getSelection())==null?void 0:e.toString().length)??0)>0}function Pd({open:e,className:t}){return s.jsx(Ls,{"data-state":e?"open":"closed",className:G("motion-disclosure-icon",t),"aria-hidden":!0})}function z6e(e){return e.length>0&&e.every(t=>t.status==="error")}function E$(e){return e.split(/[_\s-]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function zyt({block:e,density:t}){const n=t==="compact",r=[...e.items].reverse().find(h=>h.status==="running"),i=z6e(e.items),[a,o]=x.useState(i),l=!!r,c=a&&i,u=e.items.map(h=>Wp(h.name,h.input)),d=Qve(u,0,{preferDirectSummary:!0}),f=e.items.slice(0,3).map((h,g)=>({category:(u[g]??Wp(h.name,h.input)).category,status:h.status==="error"?"error":h.status==="running"?"running":"completed"}));return s.jsxs("div",{className:G(c&&"rounded-xl border border-red-500/20 bg-red-500/[0.04] p-3"),title:uc(e.ts),children:[s.jsxs("div",{role:"button",tabIndex:0,className:"flex cursor-pointer items-start gap-2",onClick:()=>{F6e()||o(h=>!h)},onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),o(g=>!g))},children:[s.jsx(Mve,{icons:f,highlightError:c}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"text-[11px] font-semibold leading-none tracking-[0.05em] text-muted-foreground/70",children:"Command activity"}),s.jsx("div",{className:G("mt-1 break-words text-foreground/85",n?"text-xs":"text-sm"),children:d||(l?"Working with commands":"Command details")})]}),s.jsx("button",{type:"button",className:"mt-0.5 inline-flex h-5 w-5 items-center justify-center text-muted-foreground transition-colors hover:text-foreground",onClick:h=>{h.stopPropagation(),o(g=>!g)},"aria-label":a?"Collapse command details":"Expand command details",children:s.jsx(Pd,{open:a,className:"h-4 w-4"})})]}),a&&s.jsx("div",{className:G("motion-disclosure-enter mt-3 space-y-3",i&&"rounded-xl border border-red-500/20 bg-red-500/[0.06] p-3"),children:e.items.map((h,g)=>s.jsx(iH,{block:h,density:t,presentation:"chat"},`${h.ts}-${g}`))})]})}function B6e({block:e,density:t}){return s.jsxs("div",{className:"flex items-start gap-2",title:uc(e.ts),children:[e.status==="completed"?s.jsx(gs,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-emerald-600 dark:text-emerald-300"}):s.jsxs("span",{className:"relative mt-1 flex h-2.5 w-2.5 shrink-0",children:[s.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-cyan-400 opacity-70"}),s.jsx("span",{className:"relative inline-flex h-2.5 w-2.5 rounded-full bg-cyan-500"})]}),s.jsx("div",{className:G("break-words text-foreground/80",t==="compact"?"text-xs leading-5":"text-sm leading-6"),children:e.name})]})}function U6e({block:e,density:t,presentation:n="default"}){const r=t==="compact",i=Yve(e.items),a=e.items.some(c=>c.status==="in_progress"),o=e.items.length>0&&i===e.items.length,l=n==="detail";return s.jsxs("div",{className:G("rounded-xl border border-border/45 bg-muted/10",l?"p-3":r?"p-2.5":"p-3"),title:uc(e.ts),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[a?s.jsx(yr,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-cyan-600 dark:text-cyan-300"}):o?s.jsx(gs,{className:"h-3.5 w-3.5 shrink-0 text-emerald-600 dark:text-emerald-300"}):s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("div",{className:"min-w-0 flex-1 text-[11px] font-semibold tracking-[0.06em] text-muted-foreground",children:"Todo List"}),s.jsxs("div",{className:"text-[10px] font-medium tabular-nums text-muted-foreground",children:[i,"/",e.items.length]})]}),s.jsx("ul",{className:G("mt-2 space-y-1.5",r?"text-xs leading-5":"text-sm leading-6"),children:e.items.map((c,u)=>s.jsxs("li",{className:"flex items-start gap-2 text-foreground/82",children:[s.jsx("span",{className:G("mt-[0.35em] inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-full border",c.status==="completed"?"border-emerald-500/40 bg-emerald-500/[0.10] text-emerald-700 dark:text-emerald-300":c.status==="in_progress"?"border-cyan-500/40 bg-cyan-500/[0.10] text-cyan-700 dark:text-cyan-300":"border-border bg-background text-transparent"),children:c.status==="completed"?s.jsx(gs,{className:"h-2.5 w-2.5"}):c.status==="in_progress"?s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current"}):s.jsx("span",{className:"h-1.5 w-1.5 rounded-full"})}),s.jsx("span",{className:G("min-w-0 break-words",c.status==="completed"&&"text-muted-foreground line-through decoration-muted-foreground/40"),children:c.text})]},`${c.status}-${u}-${c.text}`))})]})}function Byt({block:e,density:t}){const[n,r]=x.useState(e.status==="error"&&!!e.failureReason),i=t==="compact",a=e.status==="error",o=a?"Memory update failed":"Agent memory updated",l=$3t(e.scope),c=e.agentName??"Agent",d=`${o}, ${c}, ${l}, ${n?"expanded":"collapsed"}`,f=e.changes.map(g=>g.path),h=[c,l,e.effect];return s.jsxs("div",{"data-transcript-memory-update":"true",className:G("rounded-lg border px-2.5 py-2",a?"border-red-500/20 bg-red-500/[0.04]":"border-border/45 bg-muted/10"),title:uc(e.ts),children:[s.jsxs("div",{role:"button",tabIndex:0,className:"flex cursor-pointer items-start gap-2 text-left",onClick:()=>{F6e()||r(g=>!g)},onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),r(b=>!b))},"aria-expanded":n,"aria-label":d,children:[s.jsx(V6,{category:"memory",status:a?"error":"completed"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:G("font-semibold tracking-[0.05em]",i?"text-[11px]":"text-xs",a?"text-red-700 dark:text-red-300":"text-foreground/80"),children:o}),s.jsx("span",{className:"hidden text-[10px] font-medium tabular-nums text-muted-foreground sm:inline",children:Tve(e.ts)})]}),s.jsx("div",{className:G("mt-1 break-words text-foreground/82",i?"text-xs leading-5":"text-sm leading-6"),children:a&&e.failureReason?e.failureReason:e.summary}),s.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:h.map(g=>s.jsx("span",{className:"inline-flex max-w-full items-center rounded-md border border-border/55 bg-background/65 px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground",children:s.jsx("span",{className:"truncate",children:g})},g))})]}),s.jsx("button",{type:"button",className:"mt-0.5 inline-flex h-5 w-5 items-center justify-center text-muted-foreground transition-colors hover:text-foreground",onClick:g=>{g.stopPropagation(),r(b=>!b)},"aria-expanded":n,"aria-label":n?"Collapse memory update details":"Expand memory update details",children:s.jsx(Pd,{open:n,className:"h-4 w-4"})})]}),n?s.jsxs("div",{className:"motion-disclosure-enter mt-2 space-y-2 border-t border-border/30 pt-2",children:[a&&e.failureReason?s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-[10px] font-semibold text-muted-foreground",children:"Failure"}),s.jsx("div",{className:"whitespace-pre-wrap break-words text-xs text-red-700 dark:text-red-300",children:e.failureReason})]}):null,s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-[10px] font-semibold text-muted-foreground",children:"Paths"}),s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words font-mono text-[11px] text-foreground/80",children:f.join(`
1386
1386
  `)})]}),s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-[10px] font-semibold text-muted-foreground",children:"Raw event"}),s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words font-mono text-[11px] text-foreground/80",children:e.rawText})]})]}):null]})}function q6e({block:e,density:t,presentation:n="default"}){const[r,i]=x.useState(!e.collapseByDefault),a=t==="compact",o=n==="detail",l=e.collapseByDefault===!0,c=bu(ji(e.text),a?96:140),u=e.tone==="error"?"rounded-xl border border-red-500/20 bg-red-500/[0.06] p-3 text-red-700 dark:text-red-300":e.tone==="warn"?"text-amber-700 dark:text-amber-300":e.tone==="info"?"text-sky-700 dark:text-sky-300":"text-foreground/75";return s.jsx("div",{className:u,title:uc(e.ts),children:s.jsxs("div",{className:"flex items-start gap-2",children:[e.tone==="error"?s.jsx(g1,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}):e.tone==="warn"?s.jsx(Jz,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}):s.jsx("span",{className:"mt-[7px] h-1.5 w-1.5 shrink-0 rounded-full bg-current/50"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[l&&s.jsxs("button",{type:"button",className:G("mb-1 inline-flex max-w-full items-center gap-1 rounded-md text-left font-medium transition-colors hover:text-red-800 dark:hover:text-red-100",a?"text-[11px]":"text-xs"),onClick:()=>i(d=>!d),"aria-expanded":r,"aria-label":r?"Collapse stderr details":"Expand stderr details",children:[s.jsx(Pd,{open:r,className:"h-3.5 w-3.5 shrink-0"}),s.jsxs("span",{className:"min-w-0 truncate",children:[E$(e.label),": ",c||"Details"]})]}),e.label==="result"&&e.tone!=="error"?s.jsx("div",{className:G("whitespace-pre-wrap break-words text-sky-700 dark:text-sky-300",a?"text-[11px]":"text-xs"),children:e.text}):l&&!r?null:o?s.jsx("div",{className:G(l&&r&&"motion-disclosure-enter","whitespace-pre-wrap break-words",a?"text-[11px]":"text-xs"),children:e.text}):s.jsxs("div",{className:G(l&&r&&"motion-disclosure-enter","whitespace-pre-wrap break-words",a?"text-[11px]":"text-xs"),children:[s.jsx("span",{className:"text-[10px] font-semibold tracking-[0.05em] text-muted-foreground/70",children:E$(e.label)}),e.text?s.jsx("span",{className:"ml-2",children:e.text}):null]}),e.detail&&(!l||r)&&s.jsx("pre",{className:G(e.collapseByDefault&&r&&"motion-disclosure-enter","mt-2 overflow-x-auto whitespace-pre-wrap break-words font-mono text-[11px] text-foreground/75"),children:e.detail})]})]})})}function K6e({block:e,density:t,collapseByDefault:n,presentation:r="default"}){const[i,a]=x.useState(!n),o=r==="detail";return s.jsxs("div",{title:uc(e.ts),children:[o?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("button",{type:"button",className:"inline-flex h-5 w-5 items-center justify-center text-muted-foreground transition-colors hover:text-foreground",onClick:()=>a(l=>!l),"aria-label":i?"Collapse stdout details":"Expand stdout details",children:s.jsx(Pd,{open:i,className:"h-4 w-4"})}),s.jsx("span",{className:"text-[10px] font-semibold tracking-[0.06em] text-muted-foreground",children:"details"})]}):s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-[10px] font-semibold tracking-[0.06em] text-muted-foreground",children:"Stdout"}),s.jsx("button",{type:"button",className:"inline-flex h-5 w-5 items-center justify-center text-muted-foreground transition-colors hover:text-foreground",onClick:()=>a(l=>!l),"aria-label":i?"Collapse stdout":"Expand stdout",children:s.jsx(Pd,{open:i,className:"h-4 w-4"})})]}),i&&s.jsx("pre",{className:G("motion-disclosure-enter",o?"overflow-x-auto whitespace-pre-wrap break-words font-mono text-foreground/80":"mt-2 overflow-x-auto whitespace-pre-wrap break-words font-mono text-foreground/80",t==="compact"?"text-[11px]":"text-xs"),children:e.text})]})}function Uyt(e){const t=[];for(const n of e){if(n.type==="command_group"){n.items.forEach((r,i)=>{t.push({key:`tool-${r.ts}-${i}`,type:"tool",entry:r})});continue}if(n.type==="tool"){t.push({key:`tool-${n.ts}-${n.toolUseId??n.name}`,type:"tool",entry:{ts:n.ts,endTs:n.endTs,name:n.name,input:n.input,result:n.result,isError:n.isError,status:n.status}});continue}n.type==="stdout"&&t.push({key:`stdout-${n.ts}`,type:"stdout",entry:n})}return t}function qyt(e){if(typeof e.input=="string"&&dg(e.name,e.input))return bd(e.input);const t=Ei(e.input);if(t){if(typeof t.command=="string")return bd(t.command);if(typeof t.cmd=="string")return bd(t.cmd)}return null}function Kyt(e){return e.category==="read"||e.category==="skill"}function Hyt({block:e,density:t,inline:n=!1}){const[r,i]=x.useState(n),a=bu(ji(e.text),t==="compact"?80:120)||"Output";return n?s.jsx("div",{className:"py-1.5",title:uc(e.ts),children:s.jsxs("div",{className:"flex w-full items-start gap-2 text-left",children:[s.jsx(V6,{category:"stdout",status:"completed"}),s.jsx("pre",{className:G("min-w-0 flex-1 whitespace-pre-wrap break-words font-mono text-foreground/80",t==="compact"?"text-[11px] leading-5":"text-xs leading-6"),children:e.text})]})}):s.jsxs("div",{className:"py-1.5",title:uc(e.ts),children:[s.jsxs("button",{type:"button",className:"flex w-full items-start gap-2 text-left",onClick:()=>i(o=>!o),"aria-expanded":r,"aria-label":r?"Collapse output details":"Expand output details",children:[s.jsx(V6,{category:"stdout",status:"completed"}),s.jsx("span",{className:G("min-w-0 flex-1 break-words text-foreground/82",t==="compact"?"text-xs leading-5":"text-sm leading-6"),children:a}),s.jsx("span",{className:"mt-0.5 inline-flex h-5 w-5 items-center justify-center text-muted-foreground",children:s.jsx(Pd,{open:r,className:"h-4 w-4"})})]}),r?s.jsx("pre",{className:G("motion-disclosure-enter","mt-2 overflow-x-auto whitespace-pre-wrap break-words rounded-lg border border-border/35 bg-muted/10 p-2.5 font-mono text-foreground/80",t==="compact"?"text-[11px]":"text-xs"),children:e.text}):null]})}function Vyt({block:e,density:t,inline:n=!1,defaultOpenOnError:r=!0,highlightError:i=!0}){const a=Wp(e.name,e.input),o=dg(e.name,e.input),l=qyt(e),c=l??($5(e.input)||"<empty>"),u=Kyt(a)?null:l?Gve(e.result):e.result?$5(e.result):e.status==="running"?"Waiting for result...":null,d=!!(l||u||!o&&c!=="<empty>"),[f,h]=x.useState(n||r&&e.status==="error"),g=Rve(e.ts,e.endTs),b=e.status==="error"?"Failed":e.status==="running"?"Running":null,v=e.status==="error"?"text-red-700 dark:text-red-300":e.status==="running"?"text-cyan-700 dark:text-cyan-300":"text-muted-foreground",j=e.status==="error"?"error":e.status==="running"?"running":"completed";return s.jsxs("div",{className:G("py-1.5",i&&e.status==="error"&&"rounded-lg bg-red-500/[0.04] px-2"),title:uc(e.ts),children:[s.jsxs("button",{type:"button",className:"flex w-full items-start gap-2 text-left",onClick:()=>{n||d&&h(k=>!k)},"aria-expanded":d&&!n?f:void 0,"aria-label":d&&!n?f?`Collapse ${o?"command":"tool"} details`:`Expand ${o?"command":"tool"} details`:void 0,children:[s.jsx(V6,{category:a.category,status:j}),s.jsx("span",{className:G("min-w-0 flex-1 break-words text-foreground/84",t==="compact"?"text-xs leading-5":"text-sm leading-6"),children:a.summary}),g?s.jsx("span",{className:"pt-0.5 text-[10px] font-medium tabular-nums text-muted-foreground",children:g}):null,b?s.jsx("span",{className:G("pt-0.5 text-[10px] font-medium",v),children:b}):null,d&&!n?s.jsx("span",{className:"mt-0.5 inline-flex h-5 w-5 items-center justify-center text-muted-foreground",children:s.jsx(Pd,{open:f,className:"h-4 w-4"})}):null]}),d&&f?l?s.jsx($6e,{command:c,output:u,status:e.status,className:"motion-disclosure-enter ml-5 mt-2"}):s.jsxs("div",{className:"motion-disclosure-enter ml-5 mt-2 space-y-2 rounded-lg border border-border/35 bg-muted/10 p-2.5",children:[s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-[10px] font-semibold text-muted-foreground",children:"Input"}),s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words font-mono text-[11px] text-foreground/80",children:c})]}),u?s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 text-[10px] font-semibold text-muted-foreground",children:"Response"}),s.jsx("pre",{className:G("overflow-x-auto whitespace-pre-wrap break-words font-mono text-[11px]",e.status==="error"?"text-red-700 dark:text-red-300":"text-foreground/80"),children:u})]}):null]}):null]})}function TR({action:e,density:t,inline:n=!1,defaultOpenOnError:r=!0,highlightError:i=!0}){return e.type==="stdout"?s.jsx(Hyt,{block:e.entry,density:t,inline:n}):s.jsx(Vyt,{block:e.entry,density:t,inline:n,defaultOpenOnError:r,highlightError:i})}function Wyt(e){return e.type==="tool"||e.type==="command_group"||e.type==="stdout"}function Zyt(e){const t=[];let n=[];const r=()=>{var a;if(n.length===0)return;const i=Uyt(n);i.length>0&&t.push({type:"actions",key:`actions-${((a=n[0])==null?void 0:a.ts)??t.length}-${t.length}`,actions:i}),n=[]};return e.forEach((i,a)=>{if(Wyt(i)){n.push(i);return}r(),t.push({type:"block",key:`${i.type}-${i.ts}-${a}`,block:i})}),r(),t}function Gyt(e){const t=e.filter(r=>r.type==="tool").map(r=>Wp(r.entry.name,r.entry.input)),n=e.filter(r=>r.type==="stdout").length;return Qve(t,n,{preferDirectSummary:!0})}function Qyt(e){return e.type==="stdout"?{category:"stdout",status:"completed"}:{category:Wp(e.entry.name,e.entry.input).category,status:e.entry.status==="error"?"error":e.entry.status==="running"?"running":"completed"}}function Yyt({actions:e,density:t,detailVariant:n,groupIndex:r,groupCount:i}){const a=t==="compact",o=e[0],l=e.length===1,c=e.filter(N=>N.type==="tool").map(N=>N.entry),u=z6e(c),d=l&&(o==null?void 0:o.type)==="stdout",f=l&&(o==null?void 0:o.type)==="tool",h=Gyt(e),g=u&&!n,[b,v]=x.useState(()=>n?!1:u),j=e.slice(0,3).map(Qyt);if(x.useEffect(()=>{!n&&u&&v(!0)},[n,u]),d)return s.jsx("div",{className:"divide-y divide-border/30",children:s.jsx(TR,{action:o,density:t,inline:!0})});if(f)return s.jsx("div",{className:"divide-y divide-border/30",children:s.jsx(TR,{action:o,density:t,defaultOpenOnError:!n,highlightError:!n})});const k=i>1?` group ${r+1}`:"",w=b?`Collapse tool activity${k}`:`Expand tool activity${k}`;return s.jsxs("div",{children:[s.jsxs("button",{type:"button",className:G("-mx-2 flex w-[calc(100%+1rem)] items-start gap-2 rounded-lg px-2 py-1.5 text-left transition-colors",g?"hover:bg-red-500/[0.05]":"hover:bg-muted/10"),onClick:()=>v(N=>!N),"aria-expanded":b,"aria-label":w,children:[s.jsx(Mve,{icons:j,highlightError:g}),s.jsx("span",{className:"min-w-0 flex-1",children:s.jsx("span",{className:G("block break-words text-foreground/82",a?"text-xs":"text-sm"),children:h||"Tool details"})}),s.jsx("span",{className:"mt-0.5 inline-flex h-5 w-5 items-center justify-center text-muted-foreground",children:s.jsx(Pd,{open:b,className:"h-4 w-4"})})]}),b?s.jsx("div",{className:"motion-disclosure-enter mt-2 divide-y divide-border/30 border-l border-border/35 pl-3",children:e.map(N=>s.jsx(TR,{action:N,density:t},N.key))}):null]})}function H6e({turn:e,density:t,thinkingClassName:n,variant:r="chat",onMarkdownLinkClick:i}){const a=r==="detail",o=Zyt(e.blocks),l=o.filter(u=>u.type==="actions").length;return o.length>0?s.jsx("div",{className:"space-y-3",title:uc(e.ts),children:o.map((u,d)=>u.type==="block"?sH({block:u.block,index:d,density:t,presentation:a?"detail":"chat",collapseStdout:!0,thinkingClassName:n,onMarkdownLinkClick:i}):s.jsx(Yyt,{actions:u.actions,density:t,detailVariant:a,groupIndex:o.slice(0,d).filter(f=>f.type==="actions").length,groupCount:l},u.key))}):null}function xy(e){return e.replace(/\s+$/g,"")}function Jyt(e,t){let n=xy(t??"");if(!n)return e;const r=[];for(let i=e.length-1;i>=0;i-=1){const a=e[i];if(a.kind!=="assistant"||!n){r.push(a);continue}const o=xy(a.text);if(n=xy(n),!o){r.push(a);continue}if(n.endsWith(o)){n=xy(n.slice(0,n.length-o.length));continue}if(o.endsWith(n)){const l=xy(o.slice(0,o.length-n.length));n="",l&&r.push({...a,text:l});continue}r.push(a)}return n?e:r.reverse()}function Xyt(e,t){return t.hideAssistantMessages?e.filter(n=>n.kind!=="assistant"):Jyt(e,t.hiddenAssistantMessageText)}function evt({entries:e,density:t,streaming:n,collapseStdout:r,thinkingClassName:i,hideAssistantMessages:a,hiddenAssistantMessageText:o,showDeveloperDiagnostics:l,onMarkdownLinkClick:c}){const u=x.useMemo(()=>Xyt(e,{hideAssistantMessages:a,hiddenAssistantMessageText:o}),[e,a,o]),{preludeBlocks:d,turns:f}=x.useMemo(()=>e6e(u,n,{showDeveloperDiagnostics:l}),[u,n,l]);return s.jsxs("div",{className:"space-y-3",children:[d.map((h,g)=>sH({block:h,index:g,density:t,presentation:"chat",collapseStdout:r,thinkingClassName:i,onMarkdownLinkClick:c})),f.map(h=>s.jsx(H6e,{turn:h,density:t,thinkingClassName:i,onMarkdownLinkClick:c},h.key))]})}function tvt(e){const t=[];for(const n of e){if(n.type==="command_group"){n.items.forEach((r,i)=>{t.push({key:`${n.ts}-command-${i}-${r.ts}`,block:{type:"tool",ts:r.ts,endTs:r.endTs,name:r.name,input:r.input,result:r.result,isError:r.isError,status:r.status}})});continue}if(n.type==="message"){t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n});continue}if(n.type==="thinking"){t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n});continue}if(n.type==="tool"){t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n});continue}if(n.type==="todo_list"){t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n});continue}if(n.type==="activity"){t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n});continue}if(n.type==="memory_update"){t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n});continue}if(n.type==="event"){t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n});continue}t.push({key:`${n.type}-${n.ts}-${t.length}`,block:n})}return t}function nvt({entries:e,density:t,streaming:n,thinkingClassName:r,showDeveloperDiagnostics:i,onMarkdownLinkClick:a}){const{preludeBlocks:o,turns:l}=x.useMemo(()=>e6e(e,n,{showDeveloperDiagnostics:i}),[e,n,i]),c=tvt(o);return s.jsxs("div",{className:"space-y-3",children:[c.map(u=>s.jsxs(x.Fragment,{children:[u.block.type==="message"&&s.jsx(D6e,{block:u.block,density:t,presentation:"detail",className:"text-sm leading-7",collapsibleSummary:u.block.role==="user",onMarkdownLinkClick:a}),u.block.type==="thinking"&&s.jsx(L6e,{block:u.block,density:t,className:r,collapsibleSummary:!0,onMarkdownLinkClick:a}),u.block.type==="tool"&&s.jsx(iH,{block:u.block,density:t,presentation:"detail"}),u.block.type==="todo_list"&&s.jsx(U6e,{block:u.block,density:t,presentation:"detail"}),u.block.type==="activity"&&s.jsx(B6e,{block:u.block,density:t}),u.block.type==="event"&&s.jsx(q6e,{block:u.block,density:t,presentation:"detail"}),u.block.type==="stdout"&&s.jsx(K6e,{block:u.block,density:t,collapseByDefault:!0,presentation:"detail"})]},u.key)),l.map((u,d)=>s.jsx("div",{className:G(d===l.length-1&&n&&"animate-in fade-in slide-in-from-bottom-1 duration-300"),children:s.jsx(H6e,{turn:u,density:t,thinkingClassName:r,variant:"detail",onMarkdownLinkClick:a})},u.key))]})}function rvt({entries:e,density:t}){const n=t==="compact";return s.jsx("div",{className:G("font-mono",n?"space-y-1 text-[11px]":"space-y-1.5 text-xs"),children:e.map((r,i)=>s.jsxs("div",{className:G("grid gap-x-3","grid-cols-[auto_1fr]"),children:[s.jsx("span",{className:"text-[10px] tracking-[0.06em] text-muted-foreground",children:svt(r)}),s.jsx("pre",{className:"min-w-0 whitespace-pre-wrap break-words text-foreground/80",children:r.kind==="tool_call"?`${r.name}
@@ -1395,7 +1395,7 @@ ${rr(r.inputTokens)} / ${rr(r.outputTokens)} / $${r.costUsd.toFixed(6)}`:r.kind=
1395
1395
 
1396
1396
  ${Ce}`:Ce)}else u&&await u(X)}finally{O(!1),ee.current&&(ee.current.value="")}}}const xe=!E&&!!w.trim();return s.jsxs("div",{className:"space-y-4",children:[!v&&(b??s.jsxs("h3",{className:"text-sm font-semibold",children:["Comments & Runs (",$.length,")"]})),s.jsx(u8t,{timeline:$,agentMap:l,orgId:r,projectId:i,highlightCommentId:P,runTranscriptById:V,runHasOutput:H,operatorDisplayName:g,skillReferences:le,emptyMessage:j}),f,s.jsxs("div",{ref:Q,className:"chat-composer rounded-[var(--radius-lg)] p-3","data-issue-detail-escape-back":k?w.trim()?"dirty":"empty":void 0,children:[s.jsx(ol,{ref:L,value:w,onChange:N,placeholder:"Leave a comment...",mentions:ae,mentionMenuAnchorRef:Q,mentionMenuPlacement:"container",onSubmit:fe,imageUploadHandler:c,className:"rounded-[var(--radius-md)] bg-transparent",contentClassName:"min-h-[64px] bg-transparent text-sm leading-6 text-foreground",bordered:!1}),s.jsxs("div",{className:"mt-3 flex items-center justify-end gap-3",children:[(c||u)&&s.jsxs("div",{className:"mr-auto flex items-center gap-3",children:[s.jsx("input",{ref:ee,type:"file",accept:n8t,className:"hidden",onChange:U}),s.jsx(ce,{variant:"ghost",size:"icon-sm",onClick:()=>{var re;return(re=ee.current)==null?void 0:re.click()},disabled:M,title:"Attach file",children:s.jsx(b1,{className:"h-4 w-4"})})]}),C?s.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-muted-foreground cursor-pointer select-none",children:[s.jsx("input",{type:"checkbox",checked:A,onChange:re=>_(re.target.checked),className:"rounded border-border"}),"Re-open"]}):null,s.jsx(ce,{size:"sm",disabled:!xe,onClick:fe,children:E?"Posting...":"Comment"})]})]})]})}function f8t(e){return e.replace(/`([^`]+)`/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/<[^>]+>/g,"").replace(/[*_~]/g,"").trim()}function m8t(e){return e.trim().toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"")}function h8t(e){var a;const t=[],n=new Map,r=e.replace(/\r\n?/g,`
1397
1397
  `).split(`
1398
- `);let i=null;for(let o=0;o<r.length;o+=1){const l=r[o]??"",c=l.match(/^ {0,3}(`{3,}|~{3,})/);if(c){const b=c[1]??"",v=b.charAt(0);if(!i){i={marker:v,length:b.length};continue}i.marker===v&&b.length>=i.length&&(i=null);continue}if(i)continue;const u=l.match(/^ {0,3}(#{1,6})(?:[ \t]+|$)(.*)$/);if(!u)continue;const d=(u[2]??"").replace(/[ \t]+#+[ \t]*$/g,""),f=f8t(d);if(!f)continue;const h=m8t(f)||`section-${o+1}`,g=n.get(h)??0;n.set(h,g+1),t.push({id:g===0?h:`${h}-${g+1}`,level:((a=u[1])==null?void 0:a.length)??1,title:f,line:o+1,headingIndex:t.length})}return t}const E7e=900,T7e=e=>`rudder:issue-document-folds:${e}`;function die(e){if(typeof window>"u")return[];try{const t=window.localStorage.getItem(T7e(e));if(!t)return[];const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>typeof r=="string"):[]}catch{return[]}}function fie(e,t){typeof window>"u"||window.localStorage.setItem(T7e(e),JSON.stringify(t))}function mie(e,t){return s.jsx(Aa,{className:t,children:e})}function e1(e){return e.trim().toLowerCase()==="plan"}function I7e(e){return e.split(/[-_ ]+/g).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function p8t(e){return e.replace(/^#{1,6}\s+/,"").replace(/^[-*+]\s+/,"").replace(/^\d+\.\s+/,"").replace(/^\>\s+/,"").replace(/`+/g,"").replace(/\[(.*?)\]\(.*?\)/g,"$1").replace(/[*_~]/g,"").trim()}function F5(e,t,n){const r=e==null?void 0:e.trim();if(r)return r;const i=t.split(/\r?\n/).map(p8t).find(a=>a.length>0);return i?i.slice(0,80):n&&!e1(n)?I7e(n):"Untitled document"}function g8t(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"note"}function M7e(e,t,n){const r=new Set(n),i=g8t(F5(e,t)),a=i==="plan"?"note":i;let o=a,l=2;for(;r.has(o);)o=`${a}-${l}`,l+=1;return o}function hie(e){return e1(e.key)?"Plan":F5(e.title,e.body,e.key)}function R7e(e){return e instanceof Ml&&e.status===409}function x8t(e,t){const n=new Blob([t],{type:"text/markdown;charset=utf-8"}),r=URL.createObjectURL(n),i=document.createElement("a");i.href=r,i.download=`${e}.md`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}function b8t({issue:e,canDeleteDocuments:t,mentions:n,imageUploadHandler:r,extraActions:i,onFocusDocument:a,onFocusNewDocument:o}){const l=vn(),c=Mn(),[u,d]=x.useState(null),[f,h]=x.useState(null),[g,b]=x.useState(null),[v,j]=x.useState(null),[k,w]=x.useState(()=>die(e.id)),[N,C]=x.useState(null),[A,_]=x.useState(null),[E,T]=x.useState(null),M=x.useRef(null),O=x.useRef(null),P=x.useRef(!1),{state:z,markDirty:L,reset:Q,runSave:ee}=bH(),{data:B}=Ne({queryKey:q.issues.documents(e.id),queryFn:()=>ln.listDocuments(e.id)}),F=()=>{l.invalidateQueries({queryKey:q.issues.detail(e.id)}),l.invalidateQueries({queryKey:q.issues.documents(e.id)})},Z=nt({mutationFn:async Pe=>ln.upsertDocument(e.id,Pe.key,{title:e1(Pe.key)?null:Pe.title.trim()||null,format:"markdown",body:Pe.body,baseRevisionId:Pe.baseRevisionId})}),W=nt({mutationFn:Pe=>ln.deleteDocument(e.id,Pe),onSuccess:()=>{h(null),d(null),F()},onError:Pe=>{h(Pe instanceof Error?Pe.message:"Failed to delete document")}}),$=x.useMemo(()=>[...B??[]].sort((Pe,Ae)=>Pe.key==="plan"&&Ae.key!=="plan"?-1:Pe.key!=="plan"&&Ae.key==="plan"?1:new Date(Ae.updatedAt).getTime()-new Date(Pe.updatedAt).getTime()),[B]),Y=$.some(Pe=>Pe.key==="plan"),V=$.length===0&&!e.legacyPlanDocument,H=x.useCallback(()=>{C(null),Q()},[Q]),ae=x.useCallback(Pe=>{C(Pe),L()},[L]),le=()=>{if(o){o();return}H(),j(null),b({key:"",title:"",body:"",baseRevisionId:null,isNew:!0}),h(null)},fe=Pe=>{const Ae=$.find(D=>D.key===Pe);if(!Ae)return;const oe=(v==null?void 0:v.key)===Pe?v.localDraft:null;w(D=>D.filter(J=>J!==Pe)),H(),j(D=>(D==null?void 0:D.key)===Pe?D:null),b({key:(oe==null?void 0:oe.key)??Ae.key,title:(oe==null?void 0:oe.title)??Ae.title??"",body:(oe==null?void 0:oe.body)??Ae.body,baseRevisionId:(oe==null?void 0:oe.baseRevisionId)??Ae.latestRevisionId,isNew:!1}),h(null)},U=()=>{M.current&&clearTimeout(M.current),H(),j(null),b(null),h(null)},xe=x.useCallback(async(Pe,Ae)=>{if(!Pe||Z.isPending)return!1;const oe=Pe.body.trim(),D=Pe.isNew?M7e(Pe.title,Pe.body,$.map(K=>K.key)):Pe.key.trim().toLowerCase(),J=F5(Pe.title,Pe.body,Pe.isNew?void 0:D),de=(v==null?void 0:v.key)===D?v:null;if(de&&!(Ae!=null&&Ae.overrideConflict))return Ae!=null&&Ae.trackAutosave&&H(),!1;if(!oe)return Pe.isNew?h("Add some content before creating the document"):h("Document body cannot be empty"),Ae!=null&&Ae.trackAutosave&&H(),!1;const ue=$.find(K=>K.key===D);if(!Pe.isNew&&ue&&ue.body===Pe.body&&(ue.title??"")===Pe.title)return Ae!=null&&Ae.clearAfterSave&&b(K=>(K==null?void 0:K.key)===D?null:K),Ae!=null&&Ae.trackAutosave&&H(),!0;const me=async()=>{const K=await Z.mutateAsync({...Pe,key:D,title:e1(D)?"":J,body:Pe.body,baseRevisionId:Ae!=null&&Ae.overrideConflict?(de==null?void 0:de.serverDocument.latestRevisionId)??Pe.baseRevisionId:Pe.baseRevisionId});h(null),j(je=>(je==null?void 0:je.key)===D?null:je),b(je=>!je||!(Pe.isNew?je.isNew&&je.key===Pe.key:je.key===D)?je:Ae!=null&&Ae.clearAfterSave?null:{key:K.key,title:K.title??J,body:K.body,baseRevisionId:K.latestRevisionId,isNew:!1}),F()};try{return Ae!=null&&Ae.trackAutosave?(C(D),await ee(me)):await me(),!0}catch(K){if(R7e(K))try{const je=await ln.getDocument(e.id,D);return j({key:D,serverDocument:je,localDraft:{key:D,title:e1(D)?"":J,body:Pe.body,baseRevisionId:Pe.baseRevisionId,isNew:!1},showRemote:!0}),w(Be=>Be.filter(Ve=>Ve!==D)),h(null),H(),!1}catch{return h("Document changed remotely and the latest version could not be loaded"),!1}return h(K instanceof Error?K.message:"Failed to save document"),!1}},[v,F,e.id,H,ee,$,Z]),re=x.useCallback(Pe=>{if((v==null?void 0:v.key)!==Pe)return;const Ae=v.serverDocument;b({key:Ae.key,title:Ae.title??"",body:Ae.body,baseRevisionId:Ae.latestRevisionId,isNew:!1}),j(null),H(),h(null)},[v,H]),X=x.useCallback(async Pe=>{if((v==null?void 0:v.key)!==Pe)return;const Ae=g&&g.key===Pe&&!g.isNew?g:v.localDraft;await xe({...Ae,baseRevisionId:v.serverDocument.latestRevisionId},{clearAfterSave:!1,trackAutosave:!0,overrideConflict:!0})},[xe,v,g]),ie=x.useCallback(Pe=>{(v==null?void 0:v.key)===Pe&&(b(v.localDraft),j(Ae=>(Ae==null?void 0:Ae.key)===Pe?{...Ae,showRemote:!1}:Ae),h(null))},[v]),pe=x.useCallback(async(Pe,Ae)=>{try{await navigator.clipboard.writeText(Ae),_(Pe),O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{_(oe=>oe===Pe?null:oe)},1400)}catch{h("Could not copy document")}},[]),ke=async Pe=>{Pe.currentTarget.contains(Pe.relatedTarget)||(M.current&&clearTimeout(M.current),await xe(g,{clearAfterSave:!0,trackAutosave:!0}))},Ce=async Pe=>{if(Pe.key==="Escape"){Pe.preventDefault(),U();return}(Pe.metaKey||Pe.ctrlKey)&&Pe.key==="Enter"&&(Pe.preventDefault(),M.current&&clearTimeout(M.current),await xe(g,{clearAfterSave:!1,trackAutosave:!0}))},$e=x.useCallback(async Pe=>{await xe(g,{clearAfterSave:!0,trackAutosave:(Pe==null?void 0:Pe.trackAutosave)??!1})&&H()},[xe,g]);x.useEffect(()=>{w(die(e.id))},[e.id]),x.useEffect(()=>{P.current=!1},[e.id,c.hash]),x.useEffect(()=>{const Pe=new Set($.map(Ae=>Ae.key));w(Ae=>{const oe=Ae.filter(D=>Pe.has(D));return oe.length!==Ae.length&&fie(e.id,oe),oe})},[e.id,$]),x.useEffect(()=>{fie(e.id,k)},[k,e.id]),x.useEffect(()=>{if(!v)return;const Pe=$.find(Ae=>Ae.key===v.key);!Pe||Pe.latestRevisionId===v.serverDocument.latestRevisionId||j(Ae=>(Ae==null?void 0:Ae.key)===Pe.key?{...Ae,serverDocument:Pe}:Ae)},[v,$]),x.useEffect(()=>{const Pe=c.hash;if(!Pe.startsWith("#document-"))return;const Ae=decodeURIComponent(Pe.slice(10));if(!($.some(de=>de.key===Ae)||Ae==="plan"&&!!e.legacyPlanDocument)||P.current)return;w(de=>de.filter(ue=>ue!==Ae));const D=document.getElementById(`document-${Ae}`);if(!D)return;P.current=!0,T(Ae),D.scrollIntoView({behavior:"smooth",block:"center"});const J=setTimeout(()=>T(de=>de===Ae?null:de),3e3);return()=>clearTimeout(J)},[e.legacyPlanDocument,c.hash,$]),x.useEffect(()=>()=>{M.current&&clearTimeout(M.current),O.current&&clearTimeout(O.current)},[]),x.useEffect(()=>{if(!g||g.isNew||(v==null?void 0:v.key)===g.key)return;const Pe=$.find(oe=>oe.key===g.key);if(!Pe)return;if(!(Pe.body!==g.body||(Pe.title??"")!==g.title)){z!=="saved"&&H();return}return ae(g.key),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{xe(g,{clearAfterSave:!1,trackAutosave:!0})},E7e),()=>{M.current&&clearTimeout(M.current)}},[z,xe,v,g,ae,H,$]);const Ue="mt-3 overflow-hidden rounded-md",he="",We="rudder-edit-in-place-content min-h-[220px] text-[15px] leading-7",ct=Pe=>{w(Ae=>Ae.includes(Pe)?Ae.filter(oe=>oe!==Pe):[...Ae,Pe])};return s.jsxs("div",{className:"space-y-3",children:[V&&!(g!=null&&g.isNew)?s.jsxs("div",{className:"flex items-center justify-end gap-2 min-w-0",children:[i,s.jsxs(ce,{variant:"quiet",size:"xs",onClick:le,className:"shrink-0",children:[s.jsx(tr,{className:"mr-1.5 h-3.5 w-3.5"}),s.jsx("span",{className:"hidden sm:inline",children:"New document"}),s.jsx("span",{className:"sm:hidden",children:"New"})]})]}):s.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[s.jsx("h3",{className:"text-sm font-medium text-muted-foreground shrink-0",children:"Documents"}),s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[i,s.jsxs(ce,{variant:"quiet",size:"xs",onClick:le,className:"shrink-0",children:[s.jsx(tr,{className:"mr-1.5 h-3.5 w-3.5"}),s.jsx("span",{className:"hidden sm:inline",children:"New document"}),s.jsx("span",{className:"sm:hidden",children:"New"})]})]})]}),f&&s.jsx("p",{className:"text-xs text-destructive",children:f}),(g==null?void 0:g.isNew)&&s.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-accent/10 p-3",onBlurCapture:ke,onKeyDown:Ce,children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(In,{autoFocus:!0,value:g.title,onChange:Pe=>b(Ae=>Ae&&{...Ae,title:Pe.target.value}),placeholder:"Document title"}),s.jsx(ce,{type:"button",variant:"ghost",size:"icon-sm",className:"shrink-0 text-muted-foreground",title:"Expand editor","aria-label":"Expand editor",onMouseDown:Pe=>Pe.preventDefault(),onClick:()=>o==null?void 0:o(),children:s.jsx(c5,{className:"h-4 w-4"})})]}),s.jsx(ol,{value:g.body,onChange:Pe=>b(Ae=>Ae&&{...Ae,body:Pe}),placeholder:"Write the document...",bordered:!1,className:"bg-transparent",contentClassName:"min-h-[220px] text-[15px] leading-7",mentions:n,imageUploadHandler:r,onSubmit:()=>void $e()}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(ce,{variant:"outline",size:"sm",onClick:U,children:[s.jsx(Gs,{className:"mr-1.5 h-3.5 w-3.5"}),"Cancel"]}),s.jsx(ce,{size:"sm",onClick:()=>void $e(),disabled:Z.isPending,children:Z.isPending?"Saving...":"Create"})]})]}),!Y&&e.legacyPlanDocument?s.jsxs("div",{id:"document-plan",className:G("rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 transition-colors duration-1000",E==="plan"&&"border-primary/50 bg-primary/5"),children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx(Nd,{className:"h-4 w-4 text-amber-600"}),s.jsx("span",{className:"rounded-full border border-amber-500/30 px-2 py-0.5 font-mono text-[10px] uppercase tracking-[0.16em] text-amber-700 dark:text-amber-300",children:"PLAN"})]}),s.jsx("div",{className:he,children:mie(e.legacyPlanDocument.body,We)})]}):null,s.jsx("div",{className:"space-y-3",children:$.map(Pe=>{const Ae=(g==null?void 0:g.key)===Pe.key&&!g.isNew?g:null,oe=(v==null?void 0:v.key)===Pe.key?v:null,D=k.includes(Pe.key),J=Ae?F5(Ae.title,Ae.body,Pe.key):hie(Pe);return s.jsxs("div",{id:`document-${Pe.key}`,className:G("rounded-lg border border-border p-3 transition-colors duration-1000",E===Pe.key&&"border-primary/50 bg-primary/5"),children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("button",{type:"button",className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground",onClick:()=>ct(Pe.key),"aria-label":D?`Expand ${J}`:`Collapse ${J}`,"aria-expanded":!D,children:D?s.jsx(Ls,{className:"h-3.5 w-3.5"}):s.jsx(fr,{className:"h-3.5 w-3.5"})}),s.jsx(Nd,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),s.jsx("p",{className:"truncate text-sm font-medium",children:J})]}),s.jsx("div",{className:"mt-1 flex items-center gap-2 pl-7",children:s.jsxs("a",{href:`#document-${encodeURIComponent(Pe.key)}`,className:"truncate text-[11px] text-muted-foreground transition-colors hover:text-foreground hover:underline",children:["rev ",Pe.latestRevisionNumber," • updated ",js(Pe.updatedAt)]})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(ce,{type:"button",variant:"ghost",size:"icon-xs",className:"text-muted-foreground",title:"Expand editor","aria-label":"Expand editor",onMouseDown:de=>de.preventDefault(),onClick:()=>{a==null||a(Pe.key)},children:s.jsx(c5,{className:"h-3.5 w-3.5"})}),s.jsx(ce,{variant:"ghost",size:"icon-xs",className:G("text-muted-foreground transition-colors",A===Pe.key&&"text-foreground"),title:A===Pe.key?"Copied":"Copy document",onClick:()=>void pe(Pe.key,(Ae==null?void 0:Ae.body)??Pe.body),children:A===Pe.key?s.jsx(gs,{className:"h-3.5 w-3.5"}):s.jsx(Ni,{className:"h-3.5 w-3.5"})}),s.jsxs($o,{children:[s.jsx(Fo,{asChild:!0,children:s.jsx(ce,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground",title:"Document actions",children:s.jsx(Iu,{className:"h-3.5 w-3.5"})})}),s.jsxs(zo,{align:"end",children:[s.jsxs(Hn,{onClick:()=>x8t(Pe.key,(Ae==null?void 0:Ae.body)??Pe.body),children:[s.jsx(Kf,{className:"h-3.5 w-3.5"}),"Download document"]}),t?s.jsx(fd,{}):null,t?s.jsxs(Hn,{variant:"destructive",onClick:()=>d(Pe.key),children:[s.jsx(Sa,{className:"h-3.5 w-3.5"}),"Delete document"]}):null]})]})]})]}),D?null:s.jsxs("div",{className:"mt-3 space-y-3",onFocusCapture:()=>{Ae||fe(Pe.key)},onBlurCapture:async de=>{Ae&&await ke(de)},onKeyDown:async de=>{Ae&&await Ce(de)},children:[oe&&s.jsxs("div",{className:G("rounded-md border px-3 py-3",xA.warn),children:[s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:G("text-sm font-medium",c2.warn),children:"Out of date"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"This document changed while you were editing. Your local draft is preserved and autosave is paused."})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(ce,{variant:"outline",size:"sm",onClick:()=>j(de=>(de==null?void 0:de.key)===Pe.key?{...de,showRemote:!de.showRemote}:de),children:oe.showRemote?"Hide remote":"Review remote"}),s.jsx(ce,{variant:"outline",size:"sm",onClick:()=>ie(Pe.key),children:"Keep my draft"}),s.jsx(ce,{variant:"outline",size:"sm",onClick:()=>re(Pe.key),children:"Reload remote"}),s.jsx(ce,{size:"sm",onClick:()=>void X(Pe.key),disabled:Z.isPending,children:Z.isPending?"Saving...":"Overwrite remote"})]})]}),oe.showRemote&&s.jsxs("div",{className:"mt-3 rounded-md border border-border/70 bg-background/60 p-3",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2 text-[11px] text-muted-foreground",children:[s.jsxs("span",{children:["Remote revision ",oe.serverDocument.latestRevisionNumber]}),s.jsx("span",{children:"•"}),s.jsxs("span",{children:["updated ",js(oe.serverDocument.updatedAt)]})]}),s.jsx("p",{className:"mb-2 text-sm font-medium",children:hie(oe.serverDocument)}),mie(oe.serverDocument.body,"text-[14px] leading-7")]})]}),Ae&&!e1(Pe.key)&&s.jsx(In,{value:Ae.title,onChange:de=>{ae(Pe.key),b(ue=>ue&&{...ue,title:de.target.value})},placeholder:"Document title"}),s.jsx("div",{className:`${Ue} ${he} ${Ae?"":"hover:bg-accent/10"}`,children:s.jsx(ol,{value:(Ae==null?void 0:Ae.body)??Pe.body,onChange:de=>{ae(Pe.key),b(ue=>ue&&ue.key===Pe.key&&!ue.isNew?{...ue,body:de}:{key:Pe.key,title:Pe.title??J,body:de,baseRevisionId:Pe.latestRevisionId,isNew:!1})},placeholder:"Write the document...",bordered:!1,className:"bg-transparent",contentClassName:We,mentions:n,imageUploadHandler:r,onSubmit:()=>void xe(Ae??g,{clearAfterSave:!1,trackAutosave:!0})})}),s.jsx("div",{className:"flex min-h-4 items-center justify-end px-1",children:s.jsx("span",{className:`text-[11px] transition-opacity duration-150 ${oe?"text-amber-300":z==="error"?"text-destructive":"text-muted-foreground"} ${Ae?"opacity-100":"opacity-0"}`,children:Ae?oe?"Out of date":N===Pe.key?z==="saving"?"Autosaving...":z==="saved"?"Saved":z==="error"?"Could not save":"":"":""})})]}),u===Pe.key&&s.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 rounded-md border border-destructive/20 bg-destructive/5 px-4 py-3",children:[s.jsx("p",{className:"text-sm text-destructive font-medium",children:"Delete this document? This cannot be undone."}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsx(ce,{variant:"ghost",size:"sm",onClick:()=>d(null),disabled:W.isPending,children:"Cancel"}),s.jsx(ce,{variant:"destructive",size:"sm",onClick:()=>W.mutate(Pe.key),disabled:W.isPending,children:W.isPending?"Deleting...":"Delete"})]})]})]},Pe.id)})})]})}function y8t({issue:e,target:t,motionState:n="open",mentions:r,imageUploadHandler:i,onClose:a,onDocumentCreated:o}){const l=vn(),c=x.useRef(null),u=x.useRef(null),[d,f]=x.useState(null),[h,g]=x.useState(null),[b,v]=x.useState(null),j=x.useRef(null),{state:k,markDirty:w,reset:N,runSave:C}=bH(),{data:A}=Ne({queryKey:q.issues.documents(e.id),queryFn:()=>ln.listDocuments(e.id)}),_=x.useMemo(()=>[...A??[]].sort((Z,W)=>Z.key==="plan"&&W.key!=="plan"?-1:Z.key!=="plan"&&W.key==="plan"?1:new Date(W.updatedAt).getTime()-new Date(Z.updatedAt).getTime()),[A]),E=t.kind==="existing"?_.find(Z=>Z.key===t.key):null,T=nt({mutationFn:async Z=>ln.upsertDocument(e.id,Z.key,{title:e1(Z.key)?null:Z.title.trim()||null,format:"markdown",body:Z.body,baseRevisionId:Z.baseRevisionId})}),M=x.useCallback(()=>{v(null),N()},[N]),O=x.useCallback(()=>{l.invalidateQueries({queryKey:q.issues.detail(e.id)}),l.invalidateQueries({queryKey:q.issues.documents(e.id)})},[e.id,l]);x.useEffect(()=>{if(M(),g(null),t.kind==="new"){f({key:"",title:"",body:"",baseRevisionId:null,isNew:!0});return}E&&f({key:E.key,title:E.title??"",body:E.body,baseRevisionId:E.latestRevisionId,isNew:!1})},[E,M,t.kind]),x.useEffect(()=>{d&&d.title.trim()&&window.requestAnimationFrame(()=>{var Z;return(Z=c.current)==null?void 0:Z.focus()})},[d==null?void 0:d.key]),x.useEffect(()=>()=>{j.current&&clearTimeout(j.current)},[]);const P=x.useCallback(async(Z,W)=>{if(!Z||T.isPending)return!1;const $=Z.body.trim(),Y=Z.isNew?M7e(Z.title,Z.body,_.map(le=>le.key)):Z.key.trim().toLowerCase(),V=F5(Z.title,Z.body,Z.isNew?void 0:Y);if(!$)return Z.isNew||g("Document body cannot be empty"),W!=null&&W.trackAutosave&&M(),!1;const H=_.find(le=>le.key===Y);if(!Z.isNew&&H&&H.body===Z.body&&(H.title??"")===Z.title)return W!=null&&W.trackAutosave&&M(),!0;const ae=async()=>{const le=await T.mutateAsync({...Z,key:Y,title:e1(Y)?"":V,body:Z.body});g(null),f({key:le.key,title:le.title??V,body:le.body,baseRevisionId:le.latestRevisionId,isNew:!1}),O(),Z.isNew&&(o==null||o(le.key))};try{return W!=null&&W.trackAutosave?(v(Y),await C(ae)):await ae(),!0}catch(le){return R7e(le)?(g("Document changed remotely. Return to the issue and reopen it to refresh."),M(),!1):(g(le instanceof Error?le.message:"Failed to save document"),!1)}},[O,o,M,C,_,T]);x.useEffect(()=>{if(!d)return;const Z=d.isNew?null:_.find($=>$.key===d.key);if(!(d.isNew?d.body.trim().length>0:!!Z&&(Z.body!==d.body||(Z.title??"")!==d.title))){k!=="saved"&&M();return}return g(null),v(d.key),w(),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>{P(d,{trackAutosave:!0})},E7e),()=>{j.current&&clearTimeout(j.current)}},[k,P,d,w,M,_]);const z=d?F5(d.title,d.body,d.isNew?void 0:d.key):t.kind==="existing"?I7e(t.key):"Untitled document",L=x.useMemo(()=>h8t((d==null?void 0:d.body)??""),[d==null?void 0:d.body]),Q=!!(d!=null&&d.body.trim()),ee=!!b||!!(d!=null&&d.isNew&&Q),B=h?"Could not save":k==="saving"&&ee?"Saving...":k==="error"&&ee?"Could not save":k==="saved"||d&&!d.isNew?"Saved":"",F=x.useCallback(Z=>{var Y,V;const $=Array.from(((Y=u.current)==null?void 0:Y.querySelectorAll("h1,h2,h3,h4,h5,h6"))??[])[Z.headingIndex];if($ instanceof HTMLElement){$.scrollIntoView({block:"center",behavior:"smooth"});return}(V=c.current)==null||V.focus()},[]);return s.jsxs("section",{"aria-label":"Focused document editor",className:G("min-h-[calc(100dvh-7rem)]",n==="closing"?"animate-out fade-out-0 slide-out-to-right-2 duration-200":"animate-in fade-in-0 slide-in-from-right-2 duration-200"),children:[s.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3 border-b border-border/60 pb-3",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx(ce,{type:"button",variant:"ghost",size:"icon-sm",className:"shrink-0 text-muted-foreground",onClick:a,"aria-label":"Back to issue",title:"Back to issue",children:s.jsx(O1,{className:"h-4 w-4"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-xs text-muted-foreground",children:[s.jsx("span",{className:"truncate",children:e.identifier??e.id}),s.jsx("span",{children:"/"}),s.jsx("span",{className:"truncate",children:"Document"})]}),s.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:z})]})]}),s.jsx("div",{className:G("shrink-0 text-xs",h?"text-destructive":"text-muted-foreground"),children:B})]}),h?s.jsx("p",{className:"mb-3 text-xs text-destructive",children:h}):null,s.jsxs("div",{className:"grid min-h-[calc(100dvh-13rem)] w-full grid-cols-1 gap-6 pt-3 xl:grid-cols-[minmax(0,1fr)_220px]",children:[s.jsx("div",{className:"flex min-h-[calc(100dvh-13rem)] w-full max-w-[980px] min-w-0 flex-col pl-10 pr-4",children:d?s.jsxs(s.Fragment,{children:[e1(d.key)?s.jsx("h2",{className:"text-[28px] font-semibold leading-tight text-foreground",children:"Plan"}):s.jsx("input",{value:d.title,onChange:Z=>{f(W=>W&&{...W,title:Z.target.value})},placeholder:"Untitled document",className:"w-full bg-transparent text-[28px] font-semibold leading-tight text-foreground outline-none placeholder:text-muted-foreground/45",autoFocus:!0}),s.jsx("div",{className:"mt-4 border-t border-border/60"}),s.jsx("div",{ref:u,className:"min-h-0 flex-1",children:s.jsx(ol,{ref:c,value:d.body,onChange:Z=>{f(W=>W&&{...W,body:Z})},placeholder:"Write the document...",bordered:!1,className:"mt-4 min-h-0 flex-1 bg-transparent",contentClassName:"min-h-[calc(100dvh-20rem)] cursor-text text-[16px] leading-7",mentions:r,imageUploadHandler:i,onSubmit:()=>void P(d,{trackAutosave:!0})})})]}):s.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading document..."})}),s.jsx("aside",{"aria-label":"Document sections",className:"hidden min-w-0 xl:block",children:s.jsxs("div",{className:"sticky top-4 border-l border-border/60 py-1 pl-4",children:[s.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Sections"}),L.length>0?s.jsx("nav",{className:"space-y-0.5",children:L.map(Z=>s.jsx("button",{type:"button",className:"block w-full truncate rounded px-2 py-1 text-left text-xs leading-5 text-muted-foreground hover:bg-accent/50 hover:text-foreground focus:outline-none focus:ring-1 focus:ring-ring",style:{paddingLeft:`${8+Math.max(0,Z.level-1)*10}px`},title:Z.title,onClick:()=>F(Z),children:Z.title},Z.id))}):s.jsx("p",{className:"max-w-[180px] text-xs leading-5 text-muted-foreground/75",children:"Add Markdown headings to show sections."})]})})]})]})}const v8t="mark[data-issue-find-highlight='true']",w8t=["[data-issue-find-ui]","input","textarea","select","script","style","noscript","[aria-hidden='true']"].join(","),O7e="color-mix(in oklab, #f4c430 62%, transparent)",k8t="color-mix(in oklab, var(--accent-base) 58%, #f4c430)",j8t="0 0 0 1px color-mix(in oklab, var(--accent-strong) 62%, transparent)";function N8t(e){e.style.borderRadius="2px",e.style.background=O7e,e.style.color="inherit",e.style.padding="0 1px"}function ZR(e,t){var n;return((n=e.ownerDocument.defaultView)==null?void 0:n.NodeFilter[t])??(t==="FILTER_ACCEPT"?1:t==="FILTER_REJECT"?2:4)}function C8t(e){const t=e instanceof HTMLElement?e:null;return t?t.isContentEditable?!0:!!t.closest("input, textarea, select, [contenteditable='true']"):!1}function S8t(e){return e.defaultPrevented||e.key.toLowerCase()!=="f"||!e.metaKey&&!e.ctrlKey?!1:!e.altKey&&!e.shiftKey}function nj(e){const t=Array.from(e.querySelectorAll(v8t));for(const n of t){const r=n.parentNode;if(r){for(;n.firstChild;)r.insertBefore(n.firstChild,n);r.removeChild(n),r.normalize()}}}function _8t(e,t){var a;const n=e.parentElement;if(!n||n.closest(w8t)||t!=null&&t.contains(n))return!1;const r=n.ownerDocument.activeElement,i=n.closest("[contenteditable='true']");return i&&r instanceof Node&&i.contains(r)?!1:!!((a=e.nodeValue)!=null&&a.trim())}function A8t(e,t,n={}){nj(e);const r=t.trim();if(!r)return[];const i=e.ownerDocument,a=[],o=i.createTreeWalker(e,ZR(e,"SHOW_TEXT"),{acceptNode:f=>_8t(f,n.skipElement)?ZR(e,"FILTER_ACCEPT"):ZR(e,"FILTER_REJECT")});let l=o.nextNode();for(;l;)a.push(l),l=o.nextNode();const c=[],u=r.toLocaleLowerCase(),d=r.length;for(const f of a){const h=f.nodeValue??"",g=h.toLocaleLowerCase();let b=0,v=g.indexOf(u,b);if(v===-1)continue;const j=i.createDocumentFragment();for(;v!==-1;){v>b&&j.append(i.createTextNode(h.slice(b,v)));const k=i.createElement("mark");k.dataset.issueFindHighlight="true",k.className="issue-find-highlight",N8t(k),k.textContent=h.slice(v,v+d),j.append(k),c.push(k),b=v+d,v=g.indexOf(u,b)}b<h.length&&j.append(i.createTextNode(h.slice(b))),f.replaceWith(j)}return c}function pie(e,t){let n=null;for(let r=0;r<e.length;r+=1){const i=e[r],a=r===t;i.dataset.issueFindActive=a?"true":"false",i.classList.toggle("issue-find-highlight--active",a),i.style.background=a?k8t:O7e,i.style.boxShadow=a?j8t:"",a&&(n=i)}return n}function E8t(){return typeof document>"u"?!1:!!(document.querySelector("[role='dialog']")||document.querySelector("[data-radix-popper-content-wrapper]"))}function T8t(e){return e.key==="Escape"&&!e.defaultPrevented&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.shiftKey}function I8t({rootRef:e,disabled:t=!1,refreshKey:n}){const[r,i]=x.useState(!1),[a,o]=x.useState(""),[l,c]=x.useState(0),[u,d]=x.useState(0),f=x.useRef(null),h=x.useRef([]),g=x.useRef(0),b=x.useRef(""),v=x.useRef(null),j=x.useCallback(()=>{requestAnimationFrame(()=>{var C,A;(C=f.current)==null||C.focus(),(A=f.current)==null||A.select()})},[]),k=x.useCallback(()=>{const C=e.current;C&&nj(C),h.current=[],g.current=0,b.current="",v.current=null,i(!1),o(""),c(0),d(0)},[e]),w=x.useCallback(C=>{var T;const A=h.current;if(A.length===0){g.current=0,d(0);return}const _=(g.current+C+A.length)%A.length;g.current=_,d(_);const E=pie(A,_);(T=E==null?void 0:E.scrollIntoView)==null||T.call(E,{block:"center",inline:"nearest",behavior:"smooth"})},[]);if(x.useEffect(()=>{t&&r&&k()},[k,t,r]),x.useEffect(()=>{const C=A=>{if(t)return;if(S8t(A)){if(E8t())return;const T=A.target instanceof HTMLElement?A.target:null;v.current=(T==null?void 0:T.closest("input, textarea, select, [contenteditable='true']"))??null,A.preventDefault(),i(!0),j();return}if(!r||!T8t(A))return;const _=A.target instanceof HTMLElement?A.target:null;!(_!=null&&_.closest("[data-issue-find-ui]"))&&C8t(A.target)||(A.preventDefault(),k())};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[k,t,j,r]),x.useLayoutEffect(()=>{var O;const C=e.current;if(!C||!r)return;const A=A8t(C,a,{skipElement:v.current});h.current=A,c(A.length);const _=a.trim(),E=b.current!==_;b.current=_;const T=A.length===0||E?0:Math.min(g.current,A.length-1);g.current=T,d(T);const M=pie(A,T);return _&&M&&((O=M.scrollIntoView)==null||O.call(M,{block:"center",inline:"nearest",behavior:"smooth"})),()=>{nj(C),h.current=[]}},[r,a,n,e]),x.useEffect(()=>()=>{const C=e.current;C&&nj(C)},[e]),!r)return null;const N=l===0?"0 of 0":`${u+1} of ${l}`;return s.jsxs("div",{"data-issue-find-ui":!0,role:"search","aria-label":"Find in issue",className:"fixed right-4 top-4 z-50 flex w-[min(420px,calc(100vw-2rem))] items-center gap-1 rounded-md border border-border bg-popover p-1.5 text-popover-foreground shadow-md",children:[s.jsx(na,{className:"ml-1 h-4 w-4 shrink-0 text-muted-foreground"}),s.jsx(In,{ref:f,value:a,onChange:C=>o(C.target.value),onKeyDown:C=>{if(C.key==="Enter"){C.preventDefault(),w(C.shiftKey?-1:1);return}if(C.key==="ArrowDown"){C.preventDefault(),w(1);return}if(C.key==="ArrowUp"){C.preventDefault(),w(-1);return}C.key==="Escape"&&(C.preventDefault(),k())},className:"h-7 min-w-0 flex-1 border-0 bg-transparent px-1 text-sm shadow-none focus-visible:ring-0",placeholder:"Find","aria-label":"Find in issue"}),s.jsx("span",{className:"min-w-14 shrink-0 text-right text-xs tabular-nums text-muted-foreground",children:N}),s.jsx(ce,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"Previous match",disabled:l===0,onClick:()=>w(-1),children:s.jsx(yme,{className:"h-3.5 w-3.5"})}),s.jsx(ce,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"Next match",disabled:l===0,onClick:()=>w(1),children:s.jsx(bme,{className:"h-3.5 w-3.5"})}),s.jsx(ce,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"Close find",onClick:k,children:s.jsx(Gs,{className:"h-3.5 w-3.5"})})]})}function M8t(e){var t,n,r,i,a,o,l,c;return e?((t=e.codebase)==null?void 0:t.scope)==="organization"||((n=e.codebase)==null?void 0:n.scope)==="none"?((r=e.executionWorkspacePolicy)==null?void 0:r.defaultProjectWorkspaceId)??null:((i=e.executionWorkspacePolicy)==null?void 0:i.defaultProjectWorkspaceId)??((o=(a=e.workspaces)==null?void 0:a.find(u=>u.isPrimary))==null?void 0:o.id)??((c=(l=e.workspaces)==null?void 0:l[0])==null?void 0:c.id)??null:null}function ff({label:e,children:t,align:n="center"}){return s.jsxs("div",{"data-slot":"issue-property-row","data-align":n,className:G("flex gap-3 py-1.5",n==="start"?"items-start":"items-center"),children:[s.jsx("span",{className:"text-xs text-muted-foreground shrink-0 w-20",children:e}),s.jsx("div",{className:"flex items-center gap-1.5 min-w-0 flex-1",children:t})]})}function Cy({inline:e,label:t,open:n,onOpenChange:r,triggerContent:i,triggerClassName:a,popoverClassName:o,popoverAlign:l="end",rowAlign:c="center",extra:u,children:d}){const f=G("inline-flex min-w-0 max-w-full items-center gap-1.5 cursor-pointer hover:bg-accent/50 rounded px-1 -mx-1 py-0.5 transition-colors",a);return e?s.jsxs("div",{children:[s.jsxs(ff,{label:t,align:c,children:[s.jsx("button",{className:f,onClick:()=>r(!n),children:i}),u]}),n&&s.jsx("div",{className:G("rounded-md border border-border bg-popover p-1 mb-2",o),children:d})]}):s.jsxs(ff,{label:t,align:c,children:[s.jsxs(qn,{open:n,onOpenChange:r,children:[s.jsx(Wn,{asChild:!0,children:s.jsx("button",{className:f,children:i})}),s.jsx(Kn,{className:G("p-1",o),align:l,collisionPadding:16,children:d})]}),u]})}function gie({issue:e,onUpdate:t,inline:n,childIssues:r}){var st,kt,$t,Nn,_n,Ee;const{selectedOrganizationId:i}=wn(),{openNewIssue:a}=Wr(),{pushToast:o}=_r(),l=vn(),c=e.orgId??i,[u,d]=x.useState(!1),[f,h]=x.useState(""),[g,b]=x.useState(!1),[v,j]=x.useState(""),[k,w]=x.useState(!1),[N,C]=x.useState(""),[A,_]=x.useState(!1),[E,T]=x.useState(""),[M,O]=x.useState(!1),[P,z]=x.useState(!1),[L,Q]=x.useState(""),[ee,B]=x.useState(!1),[F,Z]=x.useState(""),W=ns(),$=ns(),{data:Y}=Ne({queryKey:q.auth.session,queryFn:()=>Di.getSession()}),V=((st=Y==null?void 0:Y.user)==null?void 0:st.id)??((kt=Y==null?void 0:Y.session)==null?void 0:kt.userId),{data:H}=Ne({queryKey:q.agents.list(c),queryFn:()=>Bt.list(c),enabled:!!c}),{data:ae}=Ne({queryKey:q.projects.list(c),queryFn:()=>ws.list(c),enabled:!!c}),le=x.useMemo(()=>(ae??[]).filter(we=>!we.archivedAt||we.id===e.projectId),[ae,e.projectId]),{orderedProjects:fe}=j7({projects:le,orgId:c,userId:V}),{data:U}=Ne({queryKey:q.issues.labels(c),queryFn:()=>ln.listLabels(c),enabled:!!c}),{data:xe}=Ne({queryKey:q.issues.list(c),queryFn:()=>ln.list(c),enabled:!!c}),re=nt({mutationFn:we=>ln.createLabel(c,we),onSuccess:async we=>{await l.invalidateQueries({queryKey:q.issues.labels(c)}),t({labelIds:[...e.labelIds??[],we.id]}),Z("")}}),X=we=>{const Ze=e.labelIds??[],Ot=Ze.includes(we)?Ze.filter(un=>un!==we):[...Ze,we];t({labelIds:Ot})},ie=we=>{if(!we||!H)return null;const Ze=H.find(Ot=>Ot.id===we);return(Ze==null?void 0:Ze.name)??we.slice(0,8)},pe=x.useMemo(()=>new Map((H??[]).map(we=>[we.id,we])),[H]),ke=we=>{if(!we)return(we==null?void 0:we.slice(0,8))??"None";const Ze=fe.find(Ot=>Ot.id===we);return(Ze==null?void 0:Ze.name)??we.slice(0,8)},Ce=x.useMemo(()=>new Map((xe??[]).map(we=>[we.id,we])),[xe]),$e=x.useCallback(we=>{var Ze;return((Ze=we.project)==null?void 0:Ze.name)??(we.projectId?ke(we.projectId):null)},[fe]),Ue=we=>we.identifier??we.id.slice(0,8),he=x.useCallback((we,Ze)=>{const Ot=Ze.trim().toLowerCase();return Ot?`${we.identifier??""} ${we.title}`.toLowerCase().includes(Ot):!0},[]),We=x.useCallback((we,Ze)=>{var Jn;let Ot=we.parentId;const un=new Set;for(;Ot;){if(Ot===Ze)return!0;if(un.has(Ot))return!1;un.add(Ot),Ot=((Jn=Ce.get(Ot))==null?void 0:Jn.parentId)??null}return!1},[Ce]),ct=e.parentId?(($t=e.ancestors)==null?void 0:$t[0])??Ce.get(e.parentId)??null:null,Pe=x.useMemo(()=>(r??[]).slice(0,5),[r]),Ae=()=>{O(!1),z(!1),a({parentId:e.id,parentIssue:{id:e.id,identifier:e.identifier,title:e.title},...e.projectId?{projectId:e.projectId}:{}})},oe=nt({mutationFn:we=>ln.update(we.id,{parentId:e.id}),onSuccess:async(we,Ze)=>{z(!1),Q(""),await l.invalidateQueries({queryKey:q.issues.detail(e.id)}),await l.invalidateQueries({queryKey:q.issues.detail(we.id)}),we.identifier&&await l.invalidateQueries({queryKey:q.issues.detail(we.identifier)}),c&&(await l.invalidateQueries({queryKey:q.issues.list(c)}),await l.invalidateQueries({queryKey:q.issues.children(c,e.id)}),Ze.parentId&&await l.invalidateQueries({queryKey:q.issues.children(c,Ze.parentId)}))},onError:we=>{o({title:we instanceof Error?we.message:"Failed to add existing issue",tone:"error"})}}),D=x.useMemo(()=>(xe??[]).filter(we=>we.id!==e.id).filter(we=>!We(we,e.id)).filter(we=>he(we,E)).slice(0,12),[xe,e.id,he,We,E]),J=x.useMemo(()=>(xe??[]).filter(we=>we.id!==e.id).filter(we=>we.parentId!==e.id).filter(we=>!(e.ancestors??[]).some(Ze=>Ze.id===we.id)).filter(we=>he(we,L)).slice(0,12),[xe,L,e.ancestors,e.id,he]),de=we=>{if(!we)return null;const Ze=(ae==null?void 0:ae.find(Ot=>Ot.id===we))??null;return Ze?Kv(Ze):`/projects/${we}`},ue=x.useMemo(()=>C7(),[u]),me=x.useMemo(()=>n6((H??[]).filter(we=>we.status!=="terminated"),ue),[H,ue]),K=e.assigneeAgentId?H==null?void 0:H.find(we=>we.id===e.assigneeAgentId):null,je=e.reviewerAgentId?H==null?void 0:H.find(we=>we.id===e.reviewerAgentId):null,Be=we=>Ol(we,V),Ve=Be(e.assigneeUserId),Me=Be(e.reviewerUserId),ht=Be(e.createdByUserId),ve=!!(e.reviewerAgentId&&e.reviewerAgentId===e.assigneeAgentId||e.reviewerUserId&&e.reviewerUserId===e.assigneeUserId),Le=(e.labels??[]).length>0?s.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[(e.labels??[]).slice(0,3).map(we=>s.jsx(T2,{label:we,size:"sm"},we.id)),(e.labels??[]).length>3&&s.jsxs("span",{className:"text-xs text-muted-foreground",children:["+",(e.labels??[]).length-3]})]}):s.jsxs(s.Fragment,{children:[s.jsx(wP,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-sm text-muted-foreground",children:"No labels"})]}),Ie=mp(F),at=x.useMemo(()=>(U??[]).filter(we=>Ie?we.name.toLowerCase().includes(Ie.toLowerCase()):!0),[U,Ie]),Je=x.useMemo(()=>Che(U??[],Ie),[U,Ie]),St=Ie.length>0&&at.length===0&&!Je,Pt=TB(Ie),_t=x.useCallback(()=>{!St||re.isPending||re.mutate({name:Ie,color:Pt})},[re,Pt,Ie,St]),Lt=s.jsxs(s.Fragment,{children:[s.jsx("input",{className:"w-full px-2 py-1.5 text-xs bg-transparent outline-none border-b border-border mb-1 placeholder:text-muted-foreground/50",placeholder:"Search labels...",value:F,onChange:we=>Z(we.target.value),onKeyDown:we=>{we.key!=="Enter"||!St||(we.preventDefault(),_t())},autoFocus:!n}),s.jsxs("div",{className:"max-h-44 overflow-y-auto overscroll-contain space-y-0.5",children:[at.map(we=>{const Ze=(e.labelIds??[]).includes(we.id);return s.jsxs("button",{className:G("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-left",Ze&&"bg-accent"),onClick:()=>X(we.id),children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{backgroundColor:we.color}}),s.jsx("span",{className:"truncate",children:we.name})]},we.id)}),St&&s.jsxs(s.Fragment,{children:[at.length>0?s.jsx("div",{className:"my-1 border-t border-border"}):null,s.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-left",disabled:re.isPending,onClick:_t,children:[s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-sm border border-border/70 text-muted-foreground",children:s.jsx(tr,{className:"h-2.5 w-2.5"})}),s.jsx("span",{className:"truncate",children:re.isPending?"Creating…":`Create label "${Ie}"`}),s.jsx("span",{className:"ml-auto h-2.5 w-2.5 shrink-0 rounded-full",style:{backgroundColor:Pt},"aria-hidden":"true"})]})]})]})]}),It=K?s.jsx(Ki,{kind:"agent",label:K.name,badgeLabel:Q2(K),agentIcon:K.icon,agentRole:K.role,layout:"stacked"}):Ve?s.jsx(Ki,{kind:"user",label:Ve}):s.jsx(Ki,{kind:"unassigned",label:"Unassigned",muted:!0}),Vt=s.jsxs(s.Fragment,{children:[s.jsx("input",{className:"w-full px-2 py-1.5 text-xs bg-transparent outline-none border-b border-border mb-1 placeholder:text-muted-foreground/50",placeholder:"Search assignees...",value:f,onChange:we=>h(we.target.value),autoFocus:!n}),s.jsxs("div",{ref:W,"data-testid":"issue-properties-assignee-scroll",className:"scrollbar-auto-hide max-h-60 overflow-y-auto overscroll-contain",children:[s.jsx("button",{className:G("flex min-w-0 items-center gap-2 w-full px-2 py-1.5 text-left text-xs rounded hover:bg-accent/50",!e.assigneeAgentId&&!e.assigneeUserId&&"bg-accent"),onClick:()=>{t({assigneeAgentId:null,assigneeUserId:null}),d(!1)},children:s.jsx(Ki,{kind:"unassigned",label:"No assignee"})}),V&&s.jsx("button",{className:G("flex min-w-0 items-center gap-2 w-full px-2 py-2 text-left text-xs rounded hover:bg-accent/50",e.assigneeUserId===V&&"bg-accent"),onClick:()=>{t({assigneeAgentId:null,assigneeUserId:V}),d(!1)},children:s.jsx(o$,{})}),e.createdByUserId&&e.createdByUserId!==V&&s.jsx("button",{className:G("flex min-w-0 items-center gap-2 w-full px-2 py-1.5 text-left text-xs rounded hover:bg-accent/50",e.assigneeUserId===e.createdByUserId&&"bg-accent"),onClick:()=>{t({assigneeAgentId:null,assigneeUserId:e.createdByUserId}),d(!1)},children:s.jsx(Ki,{kind:"user",label:ht?`Assign to ${ht}`:"Assign to requester"})}),me.filter(we=>{if(!f.trim())return!0;const Ze=f.toLowerCase();return`${rl(we)} ${we.name} ${we.role} ${we.title??""}`.toLowerCase().includes(Ze)}).map(we=>s.jsx("button",{className:G("flex min-w-0 items-center gap-2 w-full px-2 py-2 text-left text-xs rounded hover:bg-accent/50",we.id===e.assigneeAgentId&&"bg-accent"),onClick:()=>{h5(we.id),t({assigneeAgentId:we.id,assigneeUserId:null}),d(!1)},children:s.jsx(ip,{agent:we})},we.id))]})]}),Sn=je?s.jsx(Ki,{kind:"agent",label:je.name,badgeLabel:Q2(je),agentIcon:je.icon,agentRole:je.role,layout:"stacked"}):Me?s.jsx(Ki,{kind:"user",label:Me}):s.jsx(Ki,{kind:"unassigned",label:"No reviewer",muted:!0}),rt=s.jsxs(s.Fragment,{children:[s.jsx("input",{className:"w-full px-2 py-1.5 text-xs bg-transparent outline-none border-b border-border mb-1 placeholder:text-muted-foreground/50",placeholder:"Search reviewers...",value:v,onChange:we=>j(we.target.value),autoFocus:!n}),s.jsxs("div",{ref:$,"data-testid":"issue-properties-reviewer-scroll",className:"scrollbar-auto-hide max-h-60 overflow-y-auto overscroll-contain",children:[s.jsx("button",{className:G("flex min-w-0 items-center gap-2 w-full px-2 py-1.5 text-left text-xs rounded hover:bg-accent/50",!e.reviewerAgentId&&!e.reviewerUserId&&"bg-accent"),onClick:()=>{t({reviewerAgentId:null,reviewerUserId:null}),b(!1)},children:s.jsx(Ki,{kind:"unassigned",label:"No reviewer"})}),V&&s.jsx("button",{className:G("flex min-w-0 items-center gap-2 w-full px-2 py-2 text-left text-xs rounded hover:bg-accent/50",e.reviewerUserId===V&&"bg-accent"),onClick:()=>{t({reviewerAgentId:null,reviewerUserId:V}),b(!1)},children:s.jsx(o$,{})}),me.filter(we=>{if(!v.trim())return!0;const Ze=v.toLowerCase();return`${rl(we)} ${we.name} ${we.role} ${we.title??""}`.toLowerCase().includes(Ze)}).map(we=>s.jsx("button",{className:G("flex min-w-0 items-center gap-2 w-full px-2 py-2 text-left text-xs rounded hover:bg-accent/50",we.id===e.reviewerAgentId&&"bg-accent"),onClick:()=>{h5(we.id),t({reviewerAgentId:we.id,reviewerUserId:null}),b(!1)},children:s.jsx(ip,{agent:we})},we.id))]})]}),sn=e.projectId?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"shrink-0 h-3 w-3 rounded-sm",style:ic((Nn=fe.find(we=>we.id===e.projectId))==null?void 0:Nn.color)}),s.jsx("span",{className:"text-sm truncate",children:ke(e.projectId)})]}):s.jsxs(s.Fragment,{children:[s.jsx(Ep,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-sm text-muted-foreground",children:"No project"})]}),tn=s.jsxs(s.Fragment,{children:[s.jsx("input",{className:"w-full px-2 py-1.5 text-xs bg-transparent outline-none border-b border-border mb-1 placeholder:text-muted-foreground/50",placeholder:"Search projects...",value:N,onChange:we=>C(we.target.value),autoFocus:!n}),s.jsxs("div",{className:"max-h-48 overflow-y-auto overscroll-contain",children:[s.jsx("button",{className:G("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 whitespace-nowrap",!e.projectId&&"bg-accent"),onClick:()=>{t({projectId:null,projectWorkspaceId:null}),w(!1)},children:"No project"}),fe.filter(we=>{if(!N.trim())return!0;const Ze=N.toLowerCase();return we.name.toLowerCase().includes(Ze)}).map(we=>s.jsxs("button",{className:G("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 whitespace-nowrap",we.id===e.projectId&&"bg-accent"),onClick:()=>{t({projectId:we.id,projectWorkspaceId:M8t(we)}),w(!1)},children:[s.jsx("span",{className:"shrink-0 h-3 w-3 rounded-sm",style:ic(we.color)}),we.name]},we.id))]})]}),xn=ct?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"shrink-0 font-mono text-[11px] text-muted-foreground",children:Ue(ct)}),s.jsx("span",{className:"min-w-0 truncate text-sm",children:ct.title})]}):s.jsxs(s.Fragment,{children:[s.jsx(b3,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-sm text-muted-foreground",children:"No parent"})]}),Se=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border px-2 py-1.5",children:[s.jsx(na,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),s.jsx("input",{className:"min-w-0 flex-1 bg-transparent text-xs outline-none placeholder:text-muted-foreground/50",placeholder:"Search issues...",value:E,onChange:we=>T(we.target.value),autoFocus:!n})]}),s.jsxs("div",{className:"max-h-60 overflow-y-auto overscroll-contain p-1",children:[s.jsxs("button",{type:"button",className:G("flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",!e.parentId&&"bg-accent"),onClick:()=>{t({parentId:null}),_(!1),T("")},children:[s.jsx(b3,{className:"h-3.5 w-3.5 text-muted-foreground"}),"No parent"]}),D.length>0?D.map(we=>{const Ze=$e(we);return s.jsxs("button",{type:"button",className:G("grid w-full grid-cols-[auto_minmax(0,1fr)] items-center gap-x-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",we.id===e.parentId&&"bg-accent"),onClick:()=>{t({parentId:we.id}),_(!1),T("")},children:[s.jsx("span",{className:"font-mono text-[11px] text-muted-foreground",children:Ue(we)}),s.jsx("span",{className:"min-w-0 truncate",children:we.title}),Ze&&we.projectId!==e.projectId?s.jsx("span",{className:"col-start-2 min-w-0 truncate text-[11px] text-muted-foreground",children:Ze}):null]},we.id)}):s.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:"No matching issues."})]})]}),ye=P?s.jsxs("div",{className:G("shrink-0 rounded-md border border-border bg-popover p-1",n?"w-full":void 0),style:n?void 0:{width:"480px",maxWidth:"calc(100vw - 2rem)"},children:[s.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border px-2 py-1.5",children:[s.jsx(na,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),s.jsx("input",{className:"min-w-0 flex-1 bg-transparent text-xs outline-none placeholder:text-muted-foreground/50",placeholder:"Search existing issues...",value:L,onChange:we=>Q(we.target.value),autoFocus:!n})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto overscroll-contain py-1",children:J.length>0?J.map(we=>{const Ze=$e(we),Ot=we.parentId?Ce.get(we.parentId)??null:null;return s.jsxs("button",{type:"button",className:"grid w-full grid-cols-[auto_minmax(0,1fr)] items-center gap-x-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50 disabled:cursor-wait disabled:opacity-60",onClick:()=>oe.mutate(we),disabled:oe.isPending,children:[s.jsx("span",{className:"font-mono text-[11px] text-muted-foreground",children:Ue(we)}),s.jsx("span",{className:"min-w-0 truncate",children:we.title}),s.jsx("span",{className:"col-start-2 min-w-0 truncate text-[11px] text-muted-foreground",children:Ot?`Move from ${Ue(Ot)}`:Ze&&we.projectId!==e.projectId?Ze:"No parent"})]},we.id)}):s.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:"No matching issues."})})]}):null;return s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx(ff,{label:"Status",children:s.jsx(os,{status:e.status,onChange:we=>t({status:we}),showLabel:!0})}),s.jsx(ff,{label:"Priority",children:s.jsx(ya,{priority:e.priority,onChange:we=>t({priority:we}),showLabel:!0})}),s.jsx(Cy,{inline:n,label:"Labels",open:ee,onOpenChange:we=>{B(we),we||Z("")},triggerContent:Le,triggerClassName:"min-w-0 max-w-full",popoverClassName:"w-64",children:Lt}),s.jsx(Cy,{inline:n,label:"Assignee",open:u,onOpenChange:we=>{d(we),we||h("")},triggerContent:It,triggerClassName:"min-w-0 w-full max-w-full justify-start",popoverClassName:"w-[19rem]",popoverAlign:"start",rowAlign:"start",children:Vt}),s.jsx(Cy,{inline:n,label:"Reviewer",open:g,onOpenChange:we=>{b(we),we||j("")},triggerContent:Sn,triggerClassName:"min-w-0 w-full max-w-full justify-start",popoverClassName:"w-[19rem]",popoverAlign:"start",rowAlign:"start",extra:ve?s.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-muted-foreground",children:[s.jsx(Ad,{className:"h-3 w-3"}),"Same as assignee"]}):void 0,children:rt}),s.jsx(Cy,{inline:n,label:"Project",open:k,onOpenChange:we=>{w(we),we||C("")},triggerContent:sn,triggerClassName:"min-w-0 max-w-full",popoverClassName:"w-fit min-w-[11rem]",extra:e.projectId?s.jsx(yt,{to:de(e.projectId),className:"inline-flex items-center justify-center h-5 w-5 rounded hover:bg-accent/50 transition-colors text-muted-foreground hover:text-foreground",onClick:we=>we.stopPropagation(),children:s.jsx(p1,{className:"h-3 w-3"})}):void 0,children:tn}),s.jsx(Cy,{inline:n,label:"Parent issue",open:A,onOpenChange:we=>{_(we),we||T("")},triggerContent:xn,triggerClassName:"min-w-0 max-w-full",popoverClassName:"w-72",extra:ct?s.jsx(yt,{to:`/issues/${Ue(ct)}`,"aria-label":"Open parent issue",className:"inline-flex h-5 w-5 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",onClick:we=>we.stopPropagation(),children:s.jsx(p1,{className:"h-3 w-3"})}):void 0,children:Se}),r?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"w-20 shrink-0 text-xs text-muted-foreground",children:"Sub-issues"}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[s.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-1.5 rounded px-1 py-0.5 text-left transition-colors hover:bg-accent/50 disabled:pointer-events-none",onClick:()=>z(we=>!we),"aria-label":"Show sub-issue picker",children:[s.jsx(b3,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),s.jsx("span",{className:"rounded-sm border border-border px-1.5 py-0.5 text-[11px] leading-none text-muted-foreground",children:r.length})]}),s.jsxs(qn,{open:M,onOpenChange:O,children:[s.jsx(Wn,{asChild:!0,children:s.jsxs("button",{type:"button",className:"ml-auto inline-flex h-6 items-center gap-1 rounded border border-border px-1.5 text-[11px] text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",children:[s.jsx(tr,{className:"h-3 w-3"}),"Add"]})}),s.jsxs(Kn,{className:"w-44 p-1",align:"end",collisionPadding:16,children:[s.jsx("button",{type:"button",className:"w-full rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",onClick:Ae,children:"Create new sub-issue"}),s.jsx("button",{type:"button",className:"w-full rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",onClick:()=>{O(!1),z(!0)},children:"Add existing issue"})]})]})]})]}),s.jsxs("div",{className:"mt-1.5 min-w-0 space-y-1",children:[ye?s.jsx("div",{className:G(n?void 0:"flex justify-end"),children:ye}):null,s.jsxs("div",{className:G("min-w-0 space-y-1",n?"ml-0":"ml-[5.75rem]"),children:[Pe.length===0?s.jsx("button",{type:"button",className:"w-full rounded px-1 py-1 text-left text-xs text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",onClick:Ae,children:"No sub-issues."}):Pe.map(we=>{const Ze=we.identifier??we.id,Ot=we.identifier??we.id.slice(0,8);return s.jsxs(yt,{to:`/issues/${Ze}`,className:"grid max-w-full min-w-0 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-1.5 overflow-hidden rounded px-1 py-1 text-xs transition-colors hover:bg-accent/50",title:we.title,children:[s.jsx(os,{status:we.status}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:we.title}),s.jsx("span",{className:"min-w-0 max-w-[5.5rem] truncate font-mono text-[11px] text-muted-foreground",children:Ot})]},we.id)}),r.length>Pe.length?s.jsxs("p",{className:"px-1 text-[11px] text-muted-foreground",children:["+",r.length-Pe.length," more"]}):null]})]})]}):null,e.requestDepth>0&&s.jsx(ff,{label:"Depth",children:s.jsx("span",{className:"text-sm font-mono",children:e.requestDepth})})]}),s.jsx(Lc,{}),s.jsxs("div",{className:"space-y-1",children:[(e.createdByAgentId||e.createdByUserId)&&s.jsx(ff,{label:"Created by",children:e.createdByAgentId?s.jsx(yt,{to:`/agents/${e.createdByAgentId}`,className:"hover:underline",children:s.jsx(Za,{name:ie(e.createdByAgentId)??e.createdByAgentId.slice(0,8),icon:e.createdByAgentId?(_n=pe.get(e.createdByAgentId))==null?void 0:_n.icon:null,role:e.createdByAgentId?(Ee=pe.get(e.createdByAgentId))==null?void 0:Ee.role:null,size:"sm"})}):s.jsxs(s.Fragment,{children:[s.jsx(Hf,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-sm",children:ht??"User"})]})}),e.startedAt&&s.jsx(ff,{label:"Started",children:s.jsx("span",{className:"text-sm",children:Ha(e.startedAt)})}),e.completedAt&&s.jsx(ff,{label:"Completed",children:s.jsx("span",{className:"text-sm",children:Ha(e.completedAt)})}),s.jsx(ff,{label:"Created",children:s.jsx("span",{className:"text-sm",children:wi(e.createdAt)})}),s.jsx(ff,{label:"Updated",children:s.jsx("span",{className:"text-sm",children:I1(e.updatedAt)})})]})]})}function GR(e){return e?typeof e=="string"?e:e.toISOString():null}function R8t(e){return e==="queued"||e==="running"}function P7e({issueId:e,orgId:t}){const n=vn(),[r,i]=x.useState(new Set),{data:a}=Ne({queryKey:q.issues.liveRuns(e),queryFn:()=>xs.liveRunsForIssue(e),enabled:!!e,refetchInterval:3e3}),{data:o}=Ne({queryKey:q.issues.activeRun(e),queryFn:()=>xs.activeRunForIssue(e),enabled:!!e,refetchInterval:3e3}),l=x.useMemo(()=>{const g=new Map;for(const b of a??[])g.set(b.id,b);return o&&g.set(o.id,{id:o.id,status:o.status,invocationSource:o.invocationSource,triggerDetail:o.triggerDetail,startedAt:GR(o.startedAt),finishedAt:GR(o.finishedAt),createdAt:GR(o.createdAt)??new Date().toISOString(),agentId:o.agentId,agentName:o.agentName,agentRuntimeType:o.agentRuntimeType,issueId:e}),[...g.values()].sort((b,v)=>new Date(v.createdAt).getTime()-new Date(b.createdAt).getTime())},[o,e,a]),{transcriptByRun:c,hasOutputForRun:u}=o8({runs:l,orgId:t}),{data:d}=Ne({queryKey:q.agents.list(t??"__none__"),queryFn:()=>Bt.list(t),enabled:!!t&&l.length>0}),f=x.useMemo(()=>new Map((d??[]).map(g=>[g.id,g])),[d]),h=async g=>{i(b=>new Set(b).add(g));try{await xs.cancel(g),n.invalidateQueries({queryKey:q.issues.liveRuns(e)}),n.invalidateQueries({queryKey:q.issues.activeRun(e)})}finally{i(b=>{const v=new Set(b);return v.delete(g),v})}};return l.length===0?null:s.jsxs("div",{className:"overflow-hidden rounded-xl border border-cyan-500/25 bg-background/80 shadow-[0_18px_50px_rgba(6,182,212,0.08)]",children:[s.jsxs("div",{className:"border-b border-border/60 bg-cyan-500/[0.04] px-4 py-3",children:[s.jsx("div",{className:"text-xs font-semibold uppercase tracking-[0.18em] text-cyan-700 dark:text-cyan-300",children:"Live Runs"}),s.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"Streamed with the same transcript UI used on the full run detail page."})]}),s.jsx("div",{className:"divide-y divide-border/60",children:l.map(g=>{const b=R8t(g.status),v=c.get(g.id)??[],j=f.get(g.agentId)??null,k=WS(g.startedAt??g.createdAt,b?null:g.finishedAt);return s.jsxs("section",{className:"px-4 py-4",children:[s.jsxs("div",{className:"mb-3 flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx(yt,{to:`/agents/${g.agentId}`,className:"inline-flex hover:underline",children:j?s.jsx(Za,{name:j.name,icon:j.icon,role:j.role,size:"sm"}):s.jsx(Da,{name:g.agentName,size:"sm"})}),s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[s.jsx(yt,{to:`/agents/${g.agentId}/runs/${g.id}`,className:"inline-flex items-center rounded-full border border-border/70 bg-background/70 px-2 py-1 font-mono hover:border-cyan-500/30 hover:text-foreground",children:g.id.slice(0,8)}),s.jsx(er,{status:g.status}),s.jsx("span",{children:wi(g.startedAt??g.createdAt)}),k?s.jsx("span",{children:b?`Live for ${k}`:`Ran for ${k}`}):null]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[b&&s.jsxs("button",{onClick:()=>h(g.id),disabled:r.has(g.id),className:"inline-flex items-center gap-1 rounded-full border border-red-500/20 bg-red-500/[0.06] px-2.5 py-1 text-[11px] font-medium text-red-700 transition-colors hover:bg-red-500/[0.12] dark:text-red-300 disabled:opacity-50",children:[s.jsx(Xz,{className:"h-2.5 w-2.5",fill:"currentColor"}),r.has(g.id)?"Stopping…":"Stop"]}),s.jsxs(yt,{to:`/agents/${g.agentId}/runs/${g.id}`,className:"inline-flex items-center gap-1 rounded-full border border-border/70 bg-background/70 px-2.5 py-1 text-[11px] font-medium text-cyan-700 transition-colors hover:border-cyan-500/30 hover:text-cyan-600 dark:text-cyan-300",children:["Open run",s.jsx(Bc,{className:"h-3 w-3"})]})]})]}),s.jsx("div",{className:"max-h-[320px] overflow-y-auto pr-1",children:s.jsx(Qf,{entries:v,density:"compact",limit:8,streaming:b,collapseStdout:!0,presentation:"chat",emptyMessage:u(g.id)?"Waiting for transcript parsing...":"Waiting for run output..."})})]},g.id)})})]})}function PC({...e}){return s.jsx(pS,{"data-slot":"sheet",...e})}function O8t({...e}){return s.jsx(zle,{"data-slot":"sheet-trigger",...e})}function P8t({...e}){return s.jsx(gS,{"data-slot":"sheet-portal",...e})}function D8t({className:e,...t}){return s.jsx(xS,{"data-slot":"sheet-overlay",className:G("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...t})}function DC({className:e,children:t,side:n="right",showCloseButton:r=!0,...i}){return s.jsxs(P8t,{children:[s.jsx(D8t,{}),s.jsxs(bS,{"data-slot":"sheet-content",className:G("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500",n==="right"&&"data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm",n==="left"&&"data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm",n==="top"&&"data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b",n==="bottom"&&"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t",e),...i,children:[t,r&&s.jsxs(J5,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none",children:[s.jsx(Gs,{className:"size-4"}),s.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function LC({className:e,...t}){return s.jsx("div",{"data-slot":"sheet-header",className:G("flex flex-col gap-1.5 p-4",e),...t})}function L8t({className:e,...t}){return s.jsx("div",{"data-slot":"sheet-footer",className:G("mt-auto flex flex-col gap-2 p-4",e),...t})}function $C({className:e,...t}){return s.jsx(MF,{"data-slot":"sheet-title",className:G("text-foreground font-semibold",e),...t})}function $8t({className:e,...t}){return s.jsx(Ble,{"data-slot":"sheet-description",className:G("text-muted-foreground text-sm",e),...t})}function kH({className:e,children:t,...n}){return s.jsxs(kEe,{"data-slot":"scroll-area",className:G("relative flex flex-col overflow-hidden",e),...n,children:[s.jsx(jEe,{"data-slot":"scroll-area-viewport",className:"flex-1 min-h-0 w-full focus-visible:ring-ring/50 rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1",children:t}),s.jsx(F8t,{}),s.jsx(NEe,{})]})}function F8t({className:e,orientation:t="vertical",...n}){return s.jsx(Iue,{"data-slot":"scroll-area-scrollbar",orientation:t,className:G("flex touch-none p-px transition-colors select-none",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent",e),...n,children:s.jsx(Pue,{"data-slot":"scroll-area-thumb",className:"bg-border relative flex-1 rounded-full"})})}function z8t(e){const t=new URLSearchParams({issueId:e.id});return e.projectId&&t.set("projectId",e.projectId),e.assigneeAgentId&&t.set("agentId",e.assigneeAgentId),`/messenger/chat?${t.toString()}`}const B8t=new Set(["identifier","issueIdentifier","_previous","source","reopened","reopenedFrom","normalizedFromStatus","normalizedReason"]),xie={"issue.created":"created the issue","issue.updated":"updated the issue","issue.checked_out":"checked out the issue","issue.released":"released the issue","issue.code_committed":"committed code","issue.passive_followup_queued":"queued passive follow-up","issue.closure_needs_operator_review":"needs operator review for close-out","issue.review_decision_recorded":"recorded a reviewer decision","issue.human_intervention_required":"requested human intervention","issue.attachment_added":"added an attachment","issue.attachment_removed":"removed an attachment","issue.approval_linked":"linked an approval","issue.approval_unlinked":"unlinked an approval","issue.document_created":"created a document","issue.document_updated":"updated a document","issue.document_deleted":"deleted a document","issue.deleted":"deleted the issue","agent.created":"created an agent","agent.updated":"updated the agent","agent.paused":"paused the agent","agent.resumed":"resumed the agent","agent.terminated":"terminated the agent","heartbeat.invoked":"invoked a heartbeat","heartbeat.cancelled":"cancelled a heartbeat","approval.created":"requested approval","approval.approved":"approved","approval.rejected":"rejected"};function Bg(e){return typeof e!="string"?String(e??"none"):e.replace(/_/g," ")}function U8t(e,t){return Ol(e,t)??e.slice(0,8)}function ak(e,t,n){var r;return e?typeof e.agentId=="string"&&e.agentId?((r=t.get(e.agentId))==null?void 0:r.name)??e.agentId.slice(0,8):typeof e.userId=="string"&&e.userId?U8t(e.userId,n):null:null}function bie(e){return e.toLabel?e.fromLabel?`${e.changedVerb} from ${e.fromLabel} to ${e.toLabel}`:`${e.assignedVerb} to ${e.toLabel}`:e.fromLabel?`${e.clearedVerb} ${e.fromLabel}`:e.unassignedVerb}function x0(e){return typeof e!="object"||e===null||Array.isArray(e)?null:e}function q8t(e){return e?Object.keys(e).filter(t=>!B8t.has(t)):[]}function K8t(e){if(e.action!=="issue.updated")return!1;const t=q8t(x0(e.details));return t.length===1&&t[0]==="description"}function H8t(e){return!(e.action==="issue.comment_added"||e.action==="issue.document_updated"||K8t(e))}function Sy(e,...t){if(!e)return 0;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return 0}function yie(e,...t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r.trim()}return null}const V8t=["backlog","todo","in_progress","in_review","done","cancelled","blocked"],W8t="image/*,application/pdf,text/plain,text/markdown,application/json,text/csv,text/html,.md,.markdown",D7e="rudder.linear",Z8t="linear-issue-tab",vie="issue-link";function G8t(e){return e.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function wie(e){return e.pluginKey===D7e&&e.id===Z8t}function kie(e){const t=e.name.toLowerCase();return t.endsWith(".md")||t.endsWith(".markdown")||e.type==="text/markdown"}function Q8t(e){return e.replace(/\.[^.]+$/,"")}function Y8t(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"document"}function J8t(e){return e.split(/[-_ ]+/g).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function X8t(e){var t;return((t=e.displayLabel)==null?void 0:t.trim())||e.name}function ewt(e){const t=e.split("/").filter(Boolean);return t.pop(),t.join("/")}function twt({orgId:e,open:t,onOpenChange:n,onAttach:r,attaching:i,error:a}){var g;const[o,l]=x.useState(""),[c,u]=x.useState(null);x.useEffect(()=>{t&&(l(""),u(null))},[t,e]);const d=Ne({queryKey:q.organizations.workspaceFiles(e??"__none__",o),queryFn:()=>Xn.listWorkspaceFiles(e,o),enabled:t&&!!e,refetchOnWindowFocus:!1}),f=((g=d.data)==null?void 0:g.entries)??[],h=o.length>0;return s.jsx(Ws,{open:t,onOpenChange:n,children:s.jsxs(ii,{className:"sm:max-w-xl",children:[s.jsxs(_a,{children:[s.jsx(Wi,{className:"text-base",children:"Attach from Workspaces"}),s.jsx(Va,{children:"Choose a file to copy into this issue's attachments."})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex min-h-8 items-center gap-2 rounded-md border border-border bg-muted/20 px-2 text-xs text-muted-foreground",children:[s.jsx("span",{className:"font-medium text-foreground",children:"/"}),s.jsx("span",{className:"truncate",children:o||"workspace"})]}),s.jsx("div",{className:"h-[320px] overflow-hidden rounded-md border border-border",children:d.isLoading?s.jsxs("div",{className:"flex h-full items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(yr,{className:"h-4 w-4 animate-spin"}),"Loading files..."]}):d.error?s.jsx("div",{className:"p-3 text-sm text-destructive",children:d.error instanceof Error?d.error.message:"Could not load workspace files"}):f.length===0&&!h?s.jsx("div",{className:"p-3 text-sm text-muted-foreground",children:"No workspace files available."}):s.jsx(kH,{className:"h-full",children:s.jsxs("div",{className:"space-y-0.5 p-1.5",children:[h?s.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",onClick:()=>{l(ewt(o)),u(null)},children:[s.jsx(Ls,{className:"h-3.5 w-3.5 rotate-180"}),"Parent folder"]}):null,f.map(b=>{const v=X8t(b),j=c===b.path;return b.isDirectory?s.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-foreground transition-colors hover:bg-accent/60",onClick:()=>{l(b.path),u(null)},children:[s.jsx(dc,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),s.jsx("span",{className:"truncate font-medium",children:v})]},b.path):s.jsxs("button",{type:"button",className:G("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",j?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),onClick:()=>u(b.path),onDoubleClick:()=>void r(b.path),children:[s.jsx(QS,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:v})]},b.path)})]})})}),c?s.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:["Selected: ",c]}):null,a?s.jsx("p",{className:"text-xs text-destructive",children:a}):null]}),s.jsxs(nl,{children:[s.jsx(ce,{type:"button",variant:"ghost",onClick:()=>n(!1),disabled:i,children:"Cancel"}),s.jsxs(ce,{type:"button",onClick:()=>c?void r(c):void 0,disabled:!c||i,children:[i?s.jsx(yr,{className:"h-3.5 w-3.5 animate-spin"}):s.jsx(b1,{className:"h-3.5 w-3.5"}),"Attach"]})]})]})})}function nwt(e,t,n,r){if(e==="issue.code_committed"&&t){const i=typeof t.shortSha=="string"?t.shortSha:null,a=typeof t.subject=="string"?t.subject:null;if(i&&a)return`committed ${i}: ${a}`;if(i)return`committed ${i}`}if(e==="issue.updated"&&t){const i=t._previous??{},a=[];if(t.status!==void 0){const o=i.status;a.push(o?`changed the status from ${Bg(o)} to ${Bg(t.status)}`:`changed the status to ${Bg(t.status)}`)}if(t.priority!==void 0){const o=i.priority;a.push(o?`changed the priority from ${Lo(Bg(o))} to ${Lo(Bg(t.priority))}`:`changed the priority to ${Lo(Bg(t.priority))}`)}if(t.assigneeAgentId!==void 0||t.assigneeUserId!==void 0){const o=x0(i.assignee),l=ak(o??{agentId:i.assigneeAgentId,userId:i.assigneeUserId},n,r),c=ak({agentId:t.assigneeAgentId,userId:t.assigneeUserId},n,r);a.push(bie({toLabel:c,fromLabel:l,assignedVerb:"assigned the issue",changedVerb:"reassigned the issue",clearedVerb:"unassigned the issue from",unassignedVerb:"unassigned the issue"}))}if(t.reviewerAgentId!==void 0||t.reviewerUserId!==void 0){const o=x0(i.reviewer),l=ak(o??{agentId:i.reviewerAgentId,userId:i.reviewerUserId},n,r),c=ak({agentId:t.reviewerAgentId,userId:t.reviewerUserId},n,r);a.push(bie({toLabel:c,fromLabel:l,assignedVerb:"set the reviewer",changedVerb:"changed the reviewer",clearedVerb:"cleared the reviewer from",unassignedVerb:"cleared the reviewer"}))}if(t.title!==void 0&&a.push("updated the title"),t.description!==void 0&&a.push("updated the description"),a.length>0)return a.join(", ")}if((e==="issue.document_created"||e==="issue.document_updated"||e==="issue.document_deleted")&&t){const i=typeof t.key=="string"?t.key:"document",a=typeof t.title=="string"&&t.title?` (${t.title})`:"";return`${xie[e]??e} ${i}${a}`}if(e==="issue.passive_followup_queued"&&t){const i=typeof t.attempt=="number"?t.attempt:null,a=typeof t.maxAttempts=="number"?t.maxAttempts:null,o=typeof t.followupRunId=="string"?t.followupRunId:null;return`queued passive follow-up${i&&a?` (${i}/${a})`:""}${o?` as run ${o.slice(0,8)}`:""}`}if(e==="issue.closure_needs_operator_review"&&t){const i=typeof t.attempts=="number"?t.attempts:null;return i?`stopped passive follow-up after ${i} attempts; operator review needed`:"stopped passive follow-up; operator review needed"}if(e==="issue.review_decision_recorded"&&t){const i=typeof t.decision=="string"?Bg(t.decision):"unknown";return t.outcome==="human_handoff"||t.operatorActionRequired===!0?"confirmed blocker; operator handoff needed":`recorded reviewer decision: ${i}`}return xie[e]??e.replace(/[._]/g," ")}function rwt(e){const t=x0(e.details);return(typeof(t==null?void 0:t.conversationTitle)=="string"?t.conversationTitle.trim():"")||`Chat ${e.entityId.slice(0,8)}`}function swt(e,t,n){const r=x0(e.details);if(e.entityType==="chat"){const i=`/chat/${e.entityId}`,a=rwt(e),o=s.jsx(yt,{to:i,className:"underline underline-offset-4 hover:text-foreground",children:a});if(e.action==="chat.issue_converted")return s.jsxs(s.Fragment,{children:["created this issue from ",o]});if(e.action==="chat.context_linked")return s.jsxs(s.Fragment,{children:["linked this issue in ",o]});if(e.action==="chat.created")return s.jsxs(s.Fragment,{children:["started ",o," with this issue linked"]})}if(e.action==="issue.approval_linked"||e.action==="issue.approval_unlinked"){const i=typeof(r==null?void 0:r.approvalId)=="string"?r.approvalId:null;if(i){const a=e.action==="issue.approval_linked"?"linked":"unlinked";return s.jsxs(s.Fragment,{children:[a," ",s.jsx(yt,{to:`/messenger/approvals/${i}`,className:"underline underline-offset-4 hover:text-foreground",children:"an approval"})]})}}return nwt(e.action,r,t,n)}function iwt(e){if(e.key!=="Escape"||e.defaultPrevented||e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)return!1;const t=e.target instanceof HTMLElement?e.target:null;if(t){const n=t.closest("input, textarea, select, [contenteditable='true'], [contenteditable='plaintext-only']");if(t.isContentEditable||n){const r=t.closest("[data-issue-detail-escape-back='empty']"),i=t.isContentEditable||!!t.closest("[contenteditable='true'], [contenteditable='plaintext-only']");if(!r||!i)return!1}}return!(typeof document<"u"&&(document.querySelector("[data-issue-find-ui]")||document.querySelector("[role='dialog']")||document.querySelector("[data-radix-popper-content-wrapper]")))}function awt(e){return!(e.key!=="Escape"||e.defaultPrevented||e.metaKey||e.ctrlKey||e.altKey||e.shiftKey||typeof document<"u"&&(document.querySelector("[role='dialog']")||document.querySelector("[data-radix-popper-content-wrapper]")))}function owt(){var t;if(typeof window>"u")return!1;const e=(t=window.history.state)==null?void 0:t.idx;return typeof e=="number"&&e>0}function lwt({evt:e,agentMap:t,currentBoardUserId:n,operatorDisplayName:r}){const i=e.actorId;if(e.actorType==="agent"){const a=t.get(i);return s.jsx(Za,{name:(a==null?void 0:a.name)??i.slice(0,8),icon:a==null?void 0:a.icon,role:a==null?void 0:a.role,size:"sm"})}return s.jsx(Da,{name:a8(e.actorType,i,n,r),size:"sm"})}function cwt({evt:e,agentMap:t,currentBoardUserId:n,operatorDisplayName:r}){return s.jsxs("div",{className:"flex items-center gap-1.5 rounded-sm px-1 py-0.5 text-xs text-muted-foreground",children:[s.jsx(lwt,{evt:e,agentMap:t,currentBoardUserId:n,operatorDisplayName:r}),s.jsx("span",{className:"min-w-0",children:swt(e,t,n)}),s.jsx("span",{className:"ml-auto shrink-0",children:js(e.createdAt)})]})}function uwt({data:e}){var h,g,b;const t=e.latestIssue,n=e.link,r=(t==null?void 0:t.identifier)??n.linearIdentifier,i=(t==null?void 0:t.title)??n.linearTitle,a=(t==null?void 0:t.url)??n.linearUrl,o=((h=t==null?void 0:t.description)==null?void 0:h.trim())??"",l=(t==null?void 0:t.team.name)??n.teamName,c=(t==null?void 0:t.state.name)??n.stateName,u=((g=t==null?void 0:t.project)==null?void 0:g.name)??n.projectName,d=((b=t==null?void 0:t.assignee)==null?void 0:b.name)??null,f=(t==null?void 0:t.updatedAt)??n.updatedAt;return s.jsxs("section",{className:"rounded-lg border border-border bg-card/70 p-3 text-sm","data-testid":"issue-activity-linear-link",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Linked Linear issue"}),s.jsx("span",{className:"rounded-full border border-border bg-muted/40 px-2 py-0.5 font-mono text-[11px] text-muted-foreground",children:r})]}),s.jsx("div",{className:"font-medium text-foreground",children:i}),s.jsxs("div",{className:"flex flex-wrap gap-1.5 text-[11px] text-muted-foreground",children:[s.jsx("span",{className:"rounded-full border border-border bg-background/70 px-2 py-0.5",children:l}),s.jsx("span",{className:"rounded-full border border-border bg-background/70 px-2 py-0.5",children:c}),u?s.jsx("span",{className:"rounded-full border border-border bg-background/70 px-2 py-0.5",children:u}):null,d?s.jsx("span",{className:"rounded-full border border-border bg-background/70 px-2 py-0.5",children:d}):null,s.jsxs("span",{className:"rounded-full border border-border bg-background/70 px-2 py-0.5",children:["Updated ",js(f)]}),s.jsxs("span",{className:"rounded-full border border-border bg-background/70 px-2 py-0.5",children:["Imported ",js(n.importedAt)]})]})]}),s.jsxs("a",{href:a,target:"_blank",rel:"noreferrer",className:"inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",children:["Open in Linear",s.jsx(Bc,{className:"h-3 w-3"})]})]}),e.staleReason?s.jsx("div",{className:"mt-3 rounded-md border border-amber-500/30 bg-amber-500/10 px-2 py-1.5 text-xs text-amber-700 dark:text-amber-200",children:e.staleReason}):null,o?s.jsx("p",{className:"mt-3 line-clamp-4 whitespace-pre-wrap text-xs leading-5 text-muted-foreground",children:o}):null]})}function jie({summary:e}){return!e.hasCost&&!e.hasTokens?null:s.jsxs("section",{className:"rounded-lg border border-border bg-background/80 p-3",children:[s.jsx("div",{className:"mb-2 text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Cost"}),s.jsxs("div",{className:"space-y-1.5 text-xs text-muted-foreground tabular-nums",children:[e.hasCost?s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{children:"Spend"}),s.jsxs("span",{className:"font-medium text-foreground",children:["$",e.cost.toFixed(4)]})]}):null,e.hasTokens?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{children:"Total tokens"}),s.jsx("span",{className:"font-medium text-foreground",children:rr(e.totalTokens)})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{children:"Input"}),s.jsx("span",{children:rr(e.input)})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{children:"Output"}),s.jsx("span",{children:rr(e.output)})]}),e.cached>0?s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{children:"Cached"}),s.jsx("span",{children:rr(e.cached)})]}):null]}):null]})]})}function dwt(){var fl,mo,$i,Kc;const{issueId:e}=ci(),{organizations:t,selectedOrganizationId:n,selectedOrganization:r}=wn(),{setBreadcrumbs:i}=zr(),a=vn(),o=Ir(),l=Mn(),c=Eht(),{pushToast:u}=_r(),d=i8(),[f,h]=x.useState(!1),[g,b]=x.useState(!1),[v,j]=x.useState(!1),[k,w]=x.useState(!1),[N,C]=x.useState(!1),[A,_]=x.useState(""),[E,T]=x.useState(!1),[M,O]=x.useState(""),[P,z]=x.useState(null),[L,Q]=x.useState(null),[ee,B]=x.useState(null),[F,Z]=x.useState(!1),[W,$]=x.useState(!1),[Y,V]=x.useState(null),H=x.useRef(null),ae=x.useRef(null),le=x.useRef(null),fe=x.useRef(null),{data:U,isLoading:xe,error:re}=Ne({queryKey:q.issues.detail(e),queryFn:()=>ln.get(e),enabled:!!e}),X=(U==null?void 0:U.orgId)??n;x.useEffect(()=>{V(null),le.current&&(clearTimeout(le.current),le.current=null)},[e]),x.useEffect(()=>()=>{le.current&&clearTimeout(le.current)},[]);const ie=x.useCallback(Te=>{le.current&&(clearTimeout(le.current),le.current=null),V({target:Te,phase:"open"})},[]),pe=x.useCallback(()=>{V(Te=>!Te||Te.phase==="closing"?Te:{...Te,phase:"closing"}),le.current&&clearTimeout(le.current),le.current=setTimeout(()=>{V(null),le.current=null},200)},[]);x.useEffect(()=>{!(U!=null&&U.orgId)||!U.id||cB(U.orgId,U.id,s3(U.orgId))},[U==null?void 0:U.id,U==null?void 0:U.orgId]);const{data:ke}=Ne({queryKey:q.issues.comments(e),queryFn:()=>ln.listComments(e),enabled:!!e}),{data:Ce}=Ne({queryKey:q.issues.activity(e),queryFn:()=>l1.forIssue(e),enabled:!!e}),{data:$e}=Ne({queryKey:q.issues.runs(e),queryFn:()=>l1.runsForIssue(e),enabled:!!e,refetchInterval:5e3}),{data:Ue}=Ne({queryKey:q.issues.attachments(e),queryFn:()=>ln.listAttachments(e),enabled:!!e}),{data:he}=Ne({queryKey:q.issues.liveRuns(e),queryFn:()=>xs.liveRunsForIssue(e),enabled:!!e,refetchInterval:3e3}),{data:We}=Ne({queryKey:q.issues.activeRun(e),queryFn:()=>xs.activeRunForIssue(e),enabled:!!e,refetchInterval:3e3}),ct=(he??[]).length>0||!!We,Pe=x.useMemo(()=>EHe(l.state)??{label:"Issues",href:"/issues"},[l.state]),Ae=(U==null?void 0:U.ancestors)??[],oe=x.useMemo(()=>{const Te=(U==null?void 0:U.title)??e??"Issue";return[Pe,...[...Ae].reverse().map(De=>({label:De.title,href:`/issues/${De.identifier??De.id}`})),{label:Te,href:null}]},[Ae,U==null?void 0:U.title,e,Pe]),D=x.useMemo(()=>{const Te=new Set;for(const De of he??[])Te.add(De.id);return We&&Te.add(We.id),Te.size===0?$e??[]:($e??[]).filter(De=>!Te.has(De.runId))},[$e,he,We]),{data:J}=Ne({queryKey:q.issues.list(X??"__none__"),queryFn:()=>ln.list(X),enabled:!!X}),{data:de=[]}=Ne({queryKey:q.issues.children(X??"__none__",(U==null?void 0:U.id)??"__none__"),queryFn:()=>ln.list(X,{parentId:U.id}),enabled:!!X&&!!(U!=null&&U.id)}),{data:ue}=Ne({queryKey:q.agents.list(X??"__none__"),queryFn:()=>Bt.list(X),enabled:!!X}),{data:me}=Ne({queryKey:q.organizationSkills.list(X??"__none__"),queryFn:()=>Co.list(X),enabled:!!X&&!!(U!=null&&U.assigneeAgentId)}),{data:K}=Ne({queryKey:q.agents.skills((U==null?void 0:U.assigneeAgentId)??"__none__"),queryFn:()=>Bt.skills(U.assigneeAgentId,X),enabled:!!X&&!!(U!=null&&U.assigneeAgentId)}),{data:je}=Ne({queryKey:q.auth.session,queryFn:()=>Di.getSession()}),{data:Be}=Ne({queryKey:q.projects.list(X??"__none__"),queryFn:()=>ws.list(X),enabled:!!X}),{data:Ve}=Ne({queryKey:q.access.currentBoardAccess,queryFn:()=>Vi.getCurrentBoardAccess(),enabled:!!e}),Me=((fl=je==null?void 0:je.user)==null?void 0:fl.id)??((mo=je==null?void 0:je.session)==null?void 0:mo.userId)??null,ht=(($i=Ve==null?void 0:Ve.user)==null?void 0:$i.id)??(Ve==null?void 0:Ve.userId)??Me,ve=t.find(Te=>Te.id===X)??r,{orderedProjects:Le}=j7({projects:Be??[],orgId:X,userId:Me}),{slots:Ie}=d4({slotTypes:["detailTab"],entityType:"issue",enabled:!!X}),at=x.useMemo(()=>Ie.filter(Te=>!wie(Te)).map(Te=>({value:`plugin:${Te.pluginKey}:${Te.id}`,label:Te.displayName,slot:Te})),[Ie]),Je=Ie.find(Te=>wie(Te))??null,{data:St}=Ne({queryKey:["plugins",D7e,vie,X??"__none__",(U==null?void 0:U.id)??e??"__none__",(Je==null?void 0:Je.pluginId)??"__none__"],queryFn:async()=>(await _s.bridgeGetData(Je.pluginId,vie,{orgId:X,issueId:U.id},X)).data,enabled:!!(X&&(U!=null&&U.id)&&(Je!=null&&Je.pluginId))}),Pt=x.useMemo(()=>{const Te=new Map;for(const De of ue??[])Te.set(De.id,De);return Te},[ue]),_t=x.useMemo(()=>new Map((Be??[]).map(Te=>[Te.id,Te])),[Be]),Lt=U!=null&&U.assigneeAgentId?Pt.get(U.assigneeAgentId)??null:null,It=x.useMemo(()=>N7({agent:Lt,orgUrlKey:(ve==null?void 0:ve.urlKey)??"organization",organizationSkills:me,skillSnapshot:K}),[me,K,Lt,ve==null?void 0:ve.urlKey]),Vt=x.useMemo(()=>{const Te=[],De=[...ue??[]].filter(vt=>vt.status!=="terminated").sort((vt,Cn)=>vt.name.localeCompare(Cn.name));for(const vt of De)Te.push({id:`agent:${vt.id}`,name:rl(vt),kind:"agent",agentId:vt.id,agentIcon:vt.icon,agentRole:vt.role});for(const vt of Le)Te.push({id:`project:${vt.id}`,name:vt.name,kind:"project",projectId:vt.id,projectColor:vt.color});for(const vt of J??[]){if(vt.id===(U==null?void 0:U.id))continue;const Cn=vt.projectId?_t.get(vt.projectId)??vt.project??null:vt.project??null,mr=vt.assigneeAgentId?Pt.get(vt.assigneeAgentId)??null:null,Yi=vt.assigneeAgentId?(mr==null?void 0:mr.name)??vt.assigneeAgentId.slice(0,8):Ol(vt.assigneeUserId,Me);Te.push({id:`issue:${vt.id}`,name:vt.identifier?`${vt.identifier} ${vt.title}`:vt.title,kind:"issue",searchText:[vt.identifier,vt.title,vt.status,Cn==null?void 0:Cn.name,Yi].filter(Boolean).join(" "),issueId:vt.id,issueIdentifier:vt.identifier,issueStatus:vt.status,issueProjectName:(Cn==null?void 0:Cn.name)??null,issueProjectColor:(Cn==null?void 0:Cn.color)??null,issueAssigneeName:Yi,issueAssigneeIcon:(mr==null?void 0:mr.icon)??null,issueAssigneeRole:(mr==null?void 0:mr.role)??null})}return Te.push(...It),Te},[Pt,ue,J,Me,U==null?void 0:U.id,Le,_t,It]),Sn=x.useMemo(()=>[...de].sort((Te,De)=>new Date(Te.createdAt).getTime()-new Date(De.createdAt).getTime()),[de]),rt=x.useMemo(()=>new Map((J??[]).map(Te=>[Te.id,Te])),[J]),sn=x.useMemo(()=>{if(!U)return[];const Te=M.trim().toLowerCase();return(J??[]).filter(De=>De.id!==U.id).filter(De=>De.parentId!==U.id).filter(De=>!(U.ancestors??[]).some(vt=>vt.id===De.id)).filter(De=>Te?`${De.identifier??""} ${De.title}`.toLowerCase().includes(Te):!0).slice(0,12)},[J,M,U]),tn=x.useMemo(()=>{const Te=new Map,De=new Map;for(const vt of $e??[])De.set(vt.runId,vt.agentId);for(const vt of Ce??[]){if(vt.action!=="issue.comment_added"||!vt.runId)continue;const Cn=vt.details??{},mr=typeof Cn.commentId=="string"?Cn.commentId:null;!mr||Te.has(mr)||Te.set(mr,{runId:vt.runId,runAgentId:vt.agentId??De.get(vt.runId)??null})}return(ke??[]).map(vt=>{const Cn=Te.get(vt.id);return Cn?{...vt,...Cn}:vt})},[Ce,ke,$e]),xn=x.useMemo(()=>{let Te=0,De=0,vt=0,Cn=0,mr=!1,Yi=!1;for(const ho of $e??[]){const Ye=x0(ho.usageJson),Nt=x0(ho.resultJson),nn=Sy(Ye,"inputTokens","input_tokens"),cr=Sy(Ye,"outputTokens","output_tokens"),ai=Sy(Ye,"cachedInputTokens","cached_input_tokens")+Sy(Ye,"cache_read_input_tokens")+Sy(Ye,"cache_creation_input_tokens"),Hc=Nl({provider:yie(Ye,"provider")??yie(Nt,"provider"),inputTokens:nn,cachedInputTokens:ai,outputTokens:cr}),Vc=hme(Ye,Nt);Vc>0&&(mr=!0),nn+cr+ai>0&&(Yi=!0),Te+=Hc.promptTokens,De+=cr,vt+=ai,Cn+=Vc}return{input:Te,output:De,cached:vt,cost:Cn,totalTokens:Te+De,hasCost:mr,hasTokens:Yi}},[$e]),Se=x.useMemo(()=>{var De;const Te=[];St!=null&&St.linked&&Te.push({id:"linear-linked-issue",createdAt:((De=St.latestIssue)==null?void 0:De.updatedAt)??St.link.updatedAt??St.link.importedAt,node:s.jsx(uwt,{data:St})});for(const vt of Ce??[])H8t(vt)&&Te.push({id:vt.id,createdAt:vt.createdAt,node:s.jsx(cwt,{evt:vt,agentMap:Pt,currentBoardUserId:ht,operatorDisplayName:d})});return Te},[Ce,Pt,ht,St,d]),ye=()=>{const Te=(U==null?void 0:U.orgId)??X??n;a.invalidateQueries({queryKey:q.issues.detail(e)}),a.invalidateQueries({queryKey:q.issues.activity(e)}),a.invalidateQueries({queryKey:q.issues.runs(e)}),a.invalidateQueries({queryKey:q.issues.approvals(e)}),a.invalidateQueries({queryKey:q.issues.attachments(e)}),a.invalidateQueries({queryKey:q.issues.documents(e)}),a.invalidateQueries({queryKey:q.issues.liveRuns(e)}),a.invalidateQueries({queryKey:q.issues.activeRun(e)}),U!=null&&U.id&&Te&&a.invalidateQueries({queryKey:q.issues.children(Te,U.id)}),Te&&(a.invalidateQueries({queryKey:q.issues.list(Te)}),a.invalidateQueries({queryKey:q.issues.listTouchedByMe(Te)}),a.invalidateQueries({queryKey:q.issues.listUnreadTouchedByMe(Te)}),a.invalidateQueries({queryKey:q.sidebarBadges(Te)}))},st=nt({mutationFn:Te=>ln.markRead(Te),onSuccess:()=>{const Te=(U==null?void 0:U.orgId)??X??n;Te&&(a.invalidateQueries({queryKey:q.issues.listTouchedByMe(Te)}),a.invalidateQueries({queryKey:q.issues.listUnreadTouchedByMe(Te)}),a.invalidateQueries({queryKey:q.sidebarBadges(Te)}))}}),kt=nt({mutationFn:Te=>ln.update(e,Te),onSuccess:()=>{ye()}}),$t=nt({mutationFn:({childIssueId:Te,status:De})=>ln.update(Te,{status:De}),onMutate:({childIssueId:Te})=>{Q(Te)},onSuccess:Te=>{X&&(U!=null&&U.id)&&a.setQueryData(q.issues.children(X,U.id),De=>(De==null?void 0:De.map(vt=>vt.id===Te.id?{...vt,...Te}:vt))??De),a.setQueryData(q.issues.detail(Te.id),Te),Te.identifier&&a.setQueryData(q.issues.detail(Te.identifier),Te),X&&(a.invalidateQueries({queryKey:q.issues.list(X)}),a.invalidateQueries({queryKey:q.issues.listTouchedByMe(X)}),a.invalidateQueries({queryKey:q.issues.listUnreadTouchedByMe(X)}),a.invalidateQueries({queryKey:q.sidebarBadges(X)}))},onError:Te=>{u({title:"Failed to update sub-issue status",body:Te instanceof Error?Te.message:"Try again.",tone:"error"})},onSettled:(Te,De,vt)=>{z(Cn=>Cn===vt.childIssueId?null:Cn),Q(Cn=>Cn===vt.childIssueId?null:Cn)}}),Nn=nt({mutationFn:({body:Te,reopen:De})=>ln.addComment(e,Te,De),onSuccess:()=>{ye(),a.invalidateQueries({queryKey:q.issues.comments(e)})}}),_n=nt({mutationFn:async({file:Te,usage:De="issue"})=>{const vt=(U==null?void 0:U.orgId)??X??n;if(!vt)throw new Error("No organization selected");return ln.uploadAttachment(vt,e,Te,{usage:De})},onSuccess:(Te,De)=>{B(null),(De.usage===void 0||De.usage==="issue")&&a.invalidateQueries({queryKey:q.issues.attachments(e)}),ye()},onError:Te=>{B(Te instanceof Error?Te.message:"Upload failed")}}),Ee=nt({mutationFn:async Te=>{const De=(U==null?void 0:U.orgId)??X??n;if(!De)throw new Error("No organization selected");return ln.attachWorkspaceFile(De,e,Te)},onSuccess:()=>{B(null),$(!1),a.invalidateQueries({queryKey:q.issues.attachments(e)}),ye()},onError:Te=>{B(Te instanceof Error?Te.message:"Workspace attach failed")}}),we=nt({mutationFn:async Te=>{const De=Q8t(Te.name),vt=Y8t(De),Cn=((U==null?void 0:U.documentSummaries)??[]).find(Ye=>Ye.key===vt)??null,mr=await Te.text(),Yi=J8t(De),ho=(Cn==null?void 0:Cn.title)??Yi??null;return ln.upsertDocument(e,vt,{title:vt==="plan"?null:ho,format:"markdown",body:mr,baseRevisionId:(Cn==null?void 0:Cn.latestRevisionId)??null})},onSuccess:()=>{B(null),ye()},onError:Te=>{B(Te instanceof Error?Te.message:"Document import failed")}}),Ze=nt({mutationFn:Te=>ln.deleteAttachment(Te),onSuccess:()=>{B(null),a.invalidateQueries({queryKey:q.issues.attachments(e)}),ye()},onError:Te=>{B(Te instanceof Error?Te.message:"Delete failed")}}),Ot=x.useCallback(()=>{if(!U){u({title:"Issue is not ready",tone:"error"});return}o(z8t(U))},[U,o,u]),un=nt({mutationFn:async Te=>{if(!U)throw new Error("Issue is not ready");return ln.create(U.orgId,{title:Te,parentId:U.id})},onSuccess:()=>{_(""),C(!1),ye()},onError:Te=>{u({title:Te instanceof Error?Te.message:"Failed to create sub-issue",tone:"error"})}}),Jn=nt({mutationFn:async Te=>{if(!U)throw new Error("Issue is not ready");return ln.update(Te.id,{parentId:U.id})},onSuccess:(Te,De)=>{T(!1),O(""),ye(),a.invalidateQueries({queryKey:q.issues.detail(Te.id)}),Te.identifier&&a.invalidateQueries({queryKey:q.issues.detail(Te.identifier)}),U!=null&&U.orgId&&De.parentId&&a.invalidateQueries({queryKey:q.issues.children(U.orgId,De.parentId)})},onError:Te=>{u({title:Te instanceof Error?Te.message:"Failed to add existing issue",tone:"error"})}});x.useEffect(()=>{const Te=(U==null?void 0:U.title)??e??"Issue";i([Pe,{label:ct?`🔵 ${Te}`:Te}])},[i,Pe,U,e,ct]),x.useEffect(()=>{U!=null&&U.identifier&&e!==U.identifier&&o(`/issues/${U.identifier}`,{replace:!0,state:l.state})},[U,e,o,l.state]),x.useLayoutEffect(()=>{const Te=De=>{if(Y){if(!awt(De))return;De.preventDefault(),pe();return}if(iwt(De)&&(De.preventDefault(),!(c!=null&&c()))){if(owt()){o(-1);return}o(Pe.href)}};return document.addEventListener("keydown",Te),()=>document.removeEventListener("keydown",Te)},[pe,Y,o,c,Pe.href]),x.useEffect(()=>{U!=null&&U.id&&fe.current!==U.id&&(fe.current=U.id,st.mutate(U.id))},[U==null?void 0:U.id]);const $s=async()=>{U&&(await navigator.clipboard.writeText(U.identifier??U.id),j(!0),u({title:"Copied issue ID",tone:"success"}),setTimeout(()=>j(!1),1500))},Ci=async()=>{const Te=A.trim();!Te||un.isPending||await un.mutateAsync(Te)};if(xe)return s.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading..."});if(re)return s.jsx("p",{className:"text-sm text-destructive",children:re.message});if(!U)return null;const ar=async Te=>{const De=Te.target.files;if(!(!De||De.length===0)){for(const vt of Array.from(De))kie(vt)?await we.mutateAsync(vt):await _n.mutateAsync({file:vt,usage:"issue"});ae.current&&(ae.current.value="")}},Ts=async Te=>{Te.preventDefault(),Z(!1);const De=Te.dataTransfer.files;if(!(!De||De.length===0))for(const vt of Array.from(De))kie(vt)?await we.mutateAsync(vt):await _n.mutateAsync({file:vt,usage:"issue"})},Gi=Te=>Te.contentType.startsWith("image/"),qe=Ue??[],At=qe.length>0,Ft=`${Sn.length}`,Pn=(Y==null?void 0:Y.target)??null,En=_n.isPending||we.isPending||Ee.isPending,la=s.jsxs(s.Fragment,{children:[s.jsx("input",{ref:ae,type:"file",accept:W8t,className:"hidden",onChange:ar,multiple:!0}),s.jsxs($o,{children:[s.jsx(Fo,{asChild:!0,children:s.jsxs(ce,{type:"button",variant:"quiet",size:"xs",disabled:En,className:G("shadow-none",F&&"border-primary bg-primary/5"),title:En?"Attaching":"Attach file",children:[En?s.jsx(yr,{className:"h-3.5 w-3.5 animate-spin"}):s.jsx(b1,{className:"h-3.5 w-3.5"}),En?"Attaching...":s.jsx("span",{className:"hidden sm:inline",children:"Attach"})]})}),s.jsxs(zo,{align:"end",className:"w-52",children:[s.jsxs(Hn,{onSelect:()=>{var Te;(Te=ae.current)==null||Te.click()},children:[s.jsx(d5,{className:"h-4 w-4"}),"Upload from computer"]}),s.jsx(fd,{}),s.jsxs(Hn,{onSelect:()=>{$(!0)},children:[s.jsx(dc,{className:"h-4 w-4"}),"Attach from Workspaces"]})]})]})]}),ca=U.identifier??U.id.slice(0,8),Qi=[U.id,U.updatedAt,tn.length,Se.length,Sn.length,qe.length].join(":"),Qa=({moreOpen:Te,onMoreOpenChange:De,grouped:vt=!1})=>s.jsxs("div",{className:G("flex items-center gap-1 shrink-0",vt&&"rounded-full border border-border bg-background/80 p-1"),children:[s.jsxs(ce,{variant:"ghost",size:"sm",className:G("h-7 px-2 text-xs",vt&&"rounded-full"),onClick:$s,title:`Copy ${ca}`,children:[v?s.jsx(gs,{className:"mr-1.5 h-3.5 w-3.5"}):s.jsx(Ni,{className:"mr-1.5 h-3.5 w-3.5"}),v?"Copied":"Copy ID"]}),s.jsxs(ce,{variant:"ghost",size:"sm",className:G("h-7 px-2 text-xs",vt&&"rounded-full"),onClick:Ot,children:[s.jsx(fo,{className:"mr-1.5 h-3.5 w-3.5"}),"Chat"]}),s.jsxs(qn,{open:Te,onOpenChange:De,children:[s.jsx(Wn,{asChild:!0,children:s.jsx(ce,{variant:"ghost",size:"sm",className:G("h-7 w-7 px-0 shrink-0",vt&&"rounded-full"),"aria-label":"More issue actions",children:s.jsx(Iu,{className:"h-4 w-4"})})}),s.jsx(Kn,{className:"w-44 p-1",align:"end",children:s.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-destructive",onClick:()=>{kt.mutate({hiddenAt:new Date().toISOString()},{onSuccess:()=>o("/issues/all")}),De(!1)},children:[s.jsx(Ap,{className:"h-3 w-3"}),"Hide this Issue"]})})]})]});return s.jsxs("div",{ref:H,className:G("mx-auto max-w-6xl",!Pn&&"xl:grid xl:grid-cols-[minmax(0,1fr)_280px] xl:items-start xl:gap-6"),children:[Pn?null:s.jsx(I8t,{rootRef:H,refreshKey:Qi}),Pn?s.jsx(y8t,{issue:U,target:Pn,motionState:(Y==null?void 0:Y.phase)??"open",mentions:Vt,imageUploadHandler:async Te=>(await _n.mutateAsync({file:Te,usage:"document_inline"})).contentPath,onClose:pe,onDocumentCreated:Te=>{V(De=>De&&{...De,target:{kind:"existing",key:Te}})}}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"min-w-0 space-y-6",children:[s.jsx("nav",{"aria-label":"Issue navigation","data-testid":"issue-detail-breadcrumb",children:s.jsx(kB,{children:s.jsx(jB,{className:"flex-wrap gap-y-1",children:oe.map((Te,De)=>{const vt=De===oe.length-1;return s.jsxs(iv,{className:vt?"min-w-0":"max-w-[220px]",children:[De>0?s.jsx(Vj,{}):null,vt||!Te.href?s.jsx(NB,{className:"truncate",title:Te.label,children:Te.label}):s.jsx(Hj,{asChild:!0,children:s.jsx(yt,{to:Te.href,state:Te.href.startsWith("/issues/")?l.state:void 0,className:"truncate",title:Te.label,children:Te.label})})]},`${Te.label}-${De}`)})})})}),U.hiddenAt&&s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:[s.jsx(Ap,{className:"h-4 w-4 shrink-0"}),"This issue is hidden"]}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-wrap",children:[ct&&s.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-cyan-500/10 border border-cyan-500/30 px-2 py-0.5 text-[10px] font-medium text-cyan-600 dark:text-cyan-400 shrink-0",children:[s.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[s.jsx("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-cyan-400 opacity-75"}),s.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-cyan-400"})]}),"Live"]}),U.originKind==="automation_execution"&&U.originId&&s.jsxs(yt,{to:`/automations/${U.originId}`,className:"inline-flex items-center gap-1 rounded-full bg-violet-500/10 border border-violet-500/30 px-2 py-0.5 text-[10px] font-medium text-violet-600 dark:text-violet-400 shrink-0 hover:bg-violet-500/20 transition-colors",children:[s.jsx(b7,{className:"h-3 w-3"}),"Automation"]})]}),s.jsxs("div",{className:"flex items-center gap-0.5 md:hidden shrink-0",children:[s.jsx(ce,{variant:"ghost",size:"icon-xs",onClick:$s,title:"Copy issue ID",children:v?s.jsx(gs,{className:"h-4 w-4"}):s.jsx(Ni,{className:"h-4 w-4"})}),s.jsx(ce,{variant:"ghost",size:"icon-xs",onClick:Ot,title:"Open in chat",children:s.jsx(fo,{className:"h-4 w-4"})}),s.jsx(ce,{variant:"ghost",size:"icon-xs",onClick:()=>w(!0),title:"Properties",children:s.jsx(o4,{className:"h-4 w-4"})})]}),s.jsx("div",{className:"hidden md:flex xl:hidden items-center shrink-0",children:Qa({moreOpen:f,onMoreOpenChange:h})})]}),s.jsx(zf,{value:U.title,onSave:Te=>kt.mutateAsync({title:Te}),as:"h2",className:"text-xl font-bold"}),s.jsx(zf,{value:U.description??"",onSave:Te=>kt.mutateAsync({description:Te}),as:"p",className:"text-[15px] leading-7 text-foreground",placeholder:"Add a description...",multiline:!0,mentions:Vt,imageUploadHandler:async Te=>(await _n.mutateAsync({file:Te,usage:"description_inline"})).contentPath})]}),s.jsx(y1,{slotTypes:["toolbarButton","contextMenuItem"],entityType:"issue",context:{orgId:U.orgId,projectId:U.projectId??null,entityId:U.id,entityType:"issue"},className:"flex flex-wrap gap-2",itemClassName:"inline-flex",missingBehavior:"placeholder"}),s.jsx(_B,{placementZones:["toolbarButton"],entityType:"issue",context:{orgId:U.orgId,projectId:U.projectId??null,entityId:U.id,entityType:"issue"},className:"flex flex-wrap gap-2",itemClassName:"inline-flex"}),s.jsx(y1,{slotTypes:["taskDetailView"],entityType:"issue",context:{orgId:U.orgId,projectId:U.projectId??null,entityId:U.id,entityType:"issue"},className:"space-y-3",itemClassName:"rounded-lg border border-border p-3",missingBehavior:"placeholder"}),s.jsxs("section",{"aria-label":"Sub-issues",className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsxs("div",{className:"flex items-center gap-1.5 font-medium text-foreground",children:[s.jsx(b3,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{children:"Sub-issues"})]}),s.jsx("span",{className:"rounded-sm border border-border px-1.5 py-0.5 text-[11px] text-muted-foreground",children:Ft})]}),s.jsxs($o,{children:[s.jsx(Fo,{asChild:!0,children:s.jsxs(ce,{variant:"outline",size:"sm",className:"h-8 gap-1.5 px-2.5 text-xs",disabled:un.isPending||Jn.isPending,children:[s.jsx(tr,{className:"h-3.5 w-3.5"}),"Add sub-issue"]})}),s.jsxs(zo,{align:"end",children:[s.jsx(Hn,{onSelect:()=>{T(!1),C(!0),_("")},children:"Create new sub-issue"}),s.jsx(Hn,{onSelect:()=>{C(!1),_(""),T(!0)},children:"Add existing issue"})]})]})]}),N?s.jsxs("div",{className:"rounded-lg border border-border bg-background/80 p-2.5",children:[s.jsxs("form",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",onSubmit:Te=>{Te.preventDefault(),Ci()},children:[s.jsx(In,{value:A,onChange:Te=>_(Te.target.value),onKeyDown:Te=>{Te.key==="Escape"&&(Te.preventDefault(),C(!1),_(""))},placeholder:"Add sub-issue title",autoFocus:!0,disabled:un.isPending,className:"h-9 text-sm"}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsx(ce,{type:"submit",size:"sm",className:"h-8 px-3 text-xs",disabled:!A.trim()||un.isPending,children:"Create"}),s.jsx(ce,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2.5 text-xs",onClick:()=>{C(!1),_("")},disabled:un.isPending,children:"Cancel"})]})]}),un.error instanceof Error?s.jsx("p",{className:"mt-2 text-xs text-destructive",children:un.error.message}):null]}):null,E?s.jsxs("div",{className:"rounded-lg border border-border bg-background/80 p-2.5",children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/70 pb-2",children:[s.jsx(In,{value:M,onChange:Te=>O(Te.target.value),placeholder:"Search existing issues",autoFocus:!0,disabled:Jn.isPending,className:"h-8 text-sm"}),s.jsx(ce,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2.5 text-xs",onClick:()=>{T(!1),O("")},disabled:Jn.isPending,children:"Cancel"})]}),s.jsx("div",{className:"max-h-64 overflow-y-auto pt-2",children:sn.length===0?s.jsx("p",{className:"px-1 py-2 text-xs text-muted-foreground",children:"No matching issues."}):sn.map(Te=>{const De=Te.identifier??Te.id.slice(0,8),vt=Te.parentId?rt.get(Te.parentId)??null:null,Cn=Te.projectId?_t.get(Te.projectId)??Te.project??null:Te.project??null,mr=vt?`Move from ${vt.identifier??vt.id.slice(0,8)}`:Cn&&Te.projectId!==U.projectId?Cn.name:"No parent";return s.jsxs("button",{type:"button",className:"grid w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-2 rounded-md px-2 py-2 text-left text-sm transition-colors hover:bg-accent/40 disabled:cursor-wait disabled:opacity-60",onClick:()=>Jn.mutate(Te),disabled:Jn.isPending,children:[s.jsx(os,{status:Te.status}),s.jsx("span",{className:"min-w-0 truncate",children:Te.title}),s.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:De}),s.jsx("span",{className:"col-start-2 min-w-0 truncate text-xs text-muted-foreground",children:mr})]},Te.id)})})]}):null,Sn.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:"No sub-issues."}):s.jsx("div",{className:"overflow-hidden rounded-lg border border-border",children:Sn.map(Te=>{var mr,Yi,ho,Ye;const De=Te.identifier??Te.id,vt=P===Te.id,Cn=L===Te.id;return s.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2 text-sm transition-colors hover:bg-accent/20 last:border-b-0",children:[s.jsxs(qn,{open:vt,onOpenChange:Nt=>{z(Nt?Te.id:null)},children:[s.jsx(Wn,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":`Change status for ${Te.title}`,className:"inline-flex shrink-0 items-center gap-2 rounded-md p-1 text-left transition-colors hover:bg-accent/50 disabled:cursor-wait disabled:opacity-60",disabled:Cn,children:[s.jsx(os,{status:Te.status}),s.jsx(ya,{priority:Te.priority})]})}),s.jsx(Kn,{className:"w-40 p-1",align:"start",children:V8t.map(Nt=>s.jsxs(ce,{variant:"ghost",size:"sm",className:G("w-full justify-start gap-2 text-xs",Nt===Te.status&&"bg-accent"),onClick:()=>{$t.mutate({childIssueId:Te.id,status:Nt})},children:[s.jsx(os,{status:Nt}),G8t(Nt)]},Nt))})]}),s.jsxs(yt,{to:`/issues/${De}`,state:l.state,className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:De}),s.jsx("span",{className:"truncate",children:Te.title})]}),s.jsx("div",{className:"shrink-0",children:Te.assigneeAgentId?(mr=Pt.get(Te.assigneeAgentId))!=null&&mr.name?s.jsx(Za,{name:((Yi=Pt.get(Te.assigneeAgentId))==null?void 0:Yi.name)??Te.assigneeAgentId.slice(0,8),icon:(ho=Pt.get(Te.assigneeAgentId))==null?void 0:ho.icon,role:(Ye=Pt.get(Te.assigneeAgentId))==null?void 0:Ye.role,size:"sm"}):s.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:Te.assigneeAgentId.slice(0,8)}):Te.assigneeUserId?s.jsx(Da,{name:a8("user",Te.assigneeUserId,ht,d),size:"sm"}):null})]})]},Te.id)})})]}),s.jsx(b8t,{issue:U,canDeleteDocuments:!!((Kc=je==null?void 0:je.user)!=null&&Kc.id),mentions:Vt,imageUploadHandler:async Te=>(await _n.mutateAsync({file:Te,usage:"document_inline"})).contentPath,extraActions:At?void 0:la,onFocusNewDocument:()=>ie({kind:"new"}),onFocusDocument:Te=>ie({kind:"existing",key:Te})}),At?s.jsxs("div",{className:G("space-y-3 rounded-lg transition-colors"),onDragEnter:Te=>{Te.preventDefault(),Z(!0)},onDragOver:Te=>{Te.preventDefault(),Z(!0)},onDragLeave:Te=>{Te.currentTarget.contains(Te.relatedTarget)||Z(!1)},onDrop:Te=>void Ts(Te),children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:"Attachments"}),la]}),ee&&s.jsx("p",{className:"text-xs text-destructive",children:ee}),s.jsx("div",{className:"space-y-2",children:qe.map(Te=>s.jsxs("div",{className:"border border-border rounded-md p-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("a",{href:Te.contentPath,target:"_blank",rel:"noreferrer",className:"text-xs hover:underline truncate",title:Te.originalFilename??Te.id,children:Te.originalFilename??Te.id}),s.jsx("button",{type:"button",className:"text-muted-foreground hover:text-destructive",onClick:()=>Ze.mutate(Te.id),disabled:Ze.isPending,title:"Delete attachment",children:s.jsx(Sa,{className:"h-3.5 w-3.5"})})]}),s.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[Te.contentType," · ",(Te.byteSize/1024).toFixed(1)," KB"]}),Gi(Te)&&s.jsx("a",{href:Te.contentPath,target:"_blank",rel:"noreferrer",children:s.jsx("img",{src:Te.contentPath,alt:Te.originalFilename??"attachment",className:"mt-2 max-h-56 rounded border border-border object-contain bg-accent/10",loading:"lazy"})})]},Te.id))})]}):null,s.jsx(Lc,{}),s.jsxs("section",{"aria-label":"Activity",className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold",children:[s.jsx(Dz,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{children:"Activity"})]}),s.jsx(d8t,{comments:tn,linkedRuns:D,activityItems:Se,orgId:U.orgId,projectId:U.projectId,issueStatus:U.status,agentMap:Pt,draftKey:`rudder:issue-comment-draft:${U.id}`,mentions:Vt,operatorDisplayName:d,hideHeading:!0,emptyMessage:"No activity yet.",escapeBackWhenEmpty:!0,onAdd:async(Te,De)=>{await Nn.mutateAsync({body:Te,reopen:De})},imageUploadHandler:async Te=>(await _n.mutateAsync({file:Te,usage:"comment_inline"})).contentPath,onAttachImage:async Te=>{await _n.mutateAsync({file:Te,usage:"comment_attachment"})},liveRunSlot:s.jsx(P7e,{issueId:e,orgId:U.orgId})})]}),at.length>0?s.jsx("div",{className:"space-y-3",children:at.map(Te=>s.jsxs("section",{className:"space-y-2",children:[s.jsx("h3",{className:"text-sm font-semibold",children:Te.label}),s.jsx(f4,{slot:Te.slot,context:{orgId:U.orgId,orgPrefix:(ve==null?void 0:ve.issuePrefix)??null,projectId:U.projectId??null,entityId:U.id,entityType:"issue"},missingBehavior:"placeholder"})]},Te.value))}):null,s.jsx(PC,{open:k,onOpenChange:w,children:s.jsxs(DC,{side:"bottom",className:"max-h-[85dvh] pb-[env(safe-area-inset-bottom)]",children:[s.jsx(LC,{children:s.jsx($C,{className:"text-sm",children:"Properties"})}),s.jsx(kH,{className:"flex-1 overflow-y-auto",children:s.jsxs("div",{className:"space-y-3 px-4 pb-4",children:[s.jsx(gie,{issue:U,onUpdate:Te=>kt.mutate(Te),inline:!0,childIssues:Sn}),s.jsx(jie,{summary:xn})]})})]})}),s.jsx(c7e,{})]}),s.jsx("aside",{className:"mt-6 xl:mt-0",children:s.jsxs("div",{className:"space-y-3 xl:sticky xl:top-4",children:[s.jsx("div",{className:"hidden xl:flex justify-end",children:Qa({moreOpen:g,onMoreOpenChange:b,grouped:!0})}),s.jsxs("section",{"aria-label":"Issue properties",className:"rounded-lg border border-border bg-background/80 p-3",children:[s.jsx("div",{className:"mb-3 flex items-center justify-between gap-2",children:s.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Properties"})}),s.jsx(gie,{issue:U,onUpdate:Te=>kt.mutate(Te),childIssues:Sn})]}),s.jsx(jie,{summary:xn})]})})]}),s.jsx(twt,{orgId:U.orgId??X??n,open:W,onOpenChange:$,onAttach:Te=>Ee.mutateAsync(Te).then(()=>{}).catch(()=>{}),attaching:Ee.isPending,error:ee})]})}const L7e="rudder:chat-drafts",fwt="__new__";function $7e(){try{return globalThis.localStorage??null}catch{return null}}function jH(e){return((e==null?void 0:e.trim())??"")||fwt}function F7e(){var e;try{const t=(e=$7e())==null?void 0:e.getItem(L7e);if(!t)return{};const n=JSON.parse(t);return n&&typeof n=="object"?n:{}}catch{return{}}}function Nie(e){var t;(t=$7e())==null||t.setItem(L7e,JSON.stringify(e))}function Cie(e,t){const n=F7e()[e];if(!n||typeof n!="object")return"";const r=n[jH(t)];return typeof r=="string"?r:""}function Sie(e,t,n){const r=F7e(),i=jH(t),a={...r[e]??{}};if(n.length>0){a[i]=n,r[e]=a,Nie(r);return}i in a&&(delete a[i],Object.keys(a).length===0?delete r[e]:r[e]=a,Nie(r))}let R$={};function _ie(e,t){return`${e}:${jH(t)}`}function z7e(e,t){return e[t]??[]}function mwt(e,t,n){const r=z7e(e,t),i=n(r);if(i.length===0){if(!(t in e))return e;const a={...e};return delete a[t],a}return i===r?e:{...e,[t]:i}}function hwt(e){return z7e(R$,e)}function Aie(e,t){R$=mwt(R$,e,t)}const Ph="__none__",O$="rudder.chatLastAgentByOrg";function B7e(){try{return globalThis.localStorage??null}catch{return null}}function NH(e){return(e??[]).filter(t=>t.status!=="terminated")}function pwt(e){var t;try{const n=(t=B7e())==null?void 0:t.getItem(O$);if(!n)return;const r=JSON.parse(n);if(!r||typeof r!="object")return;const i=r[e];return typeof i=="string"&&i.trim().length>0?i:void 0}catch{return}}function _y(e,t){if(!(!t||t===Ph))try{const n=B7e();if(!n)return;const r=n.getItem(O$),i=r?JSON.parse(r):{},a=i&&typeof i=="object"?i:{};a[e]=t,n.setItem(O$,JSON.stringify(a))}catch{return}}function QR(e,t){return!!(e&&NH(t).some(n=>n.id===e))}function gwt(e,t){const n=NH(t);if(n.length===0)return Ph;const r=e?pwt(e):void 0;return r&&n.some(i=>i.id===r)?r:n[0].id}function xwt(e,t){const n=(e==null?void 0:e.trim())??"";if(!n)return null;const r=t.find(i=>i.id===n);return!r||r.status==="terminated"?null:r.id}function bwt(e){return N7(e)}function ywt(e,t){const n=t.trim().toLowerCase();return n?e.filter(r=>r.searchText.includes(n)):e}function Jy(e){if(!e)return null;const t=e instanceof Date?e.getTime():Date.parse(e);return Number.isFinite(t)?t:null}function vwt(e){if(!Number.isFinite(e)||e<0)return"0s";if(e<1e3)return"under 1s";const t=Math.floor(e/1e3);if(t<60)return`${t}s`;const n=Math.floor(t/60),r=t%60;return r>0?`${n}m ${r}s`:`${n}m`}function U7e(e){let t=0;for(const n of e){const r=Date.parse(n.ts);Number.isFinite(r)&&r>t&&(t=r)}return t>0?t:Date.now()}function wwt(e,t){for(const n of e){const r=Date.parse(n.ts);if(Number.isFinite(r))return new Date(r)}return t}function kwt(e,t,n){const r=Jy(t.createdAt),a=(t.chatTurnId?e.filter(l=>{if(l.role!=="user"||l.chatTurnId!==t.chatTurnId||(l.turnVariant??0)!==(t.turnVariant??0))return!1;const c=Jy(l.createdAt);return c!==null&&(r===null||c<=r)}):[]).reduce((l,c)=>{const u=Jy(c.createdAt);return u===null?l:l===null||u>l?u:l},null);if(a!==null)return new Date(a);const o=e.reduce((l,c)=>{if(c.role!=="user")return l;const u=Jy(c.createdAt);return u===null||r!==null&&u>r?l:l===null||u>l?u:l},null);return o!==null?new Date(o):wwt(n,new Date(t.createdAt))}function jwt(e,t){const n=t.length>0?U7e(t):0,r=Jy(e.createdAt)??0,i=Math.max(n,r);return new Date(i>0?i:Date.now())}const Nwt=["/Users/","/home/","/Volumes/","/tmp/","/var/","/opt/","/mnt/","/private/"];function Cwt(e){try{const t=new URL(e);if(t.protocol!=="file:")return null;const n=decodeURIComponent(t.pathname);return/^\/[A-Za-z]:\//.test(n)?n.slice(1):n}catch{return null}}function q7e(e){const t=e==null?void 0:e.trim();if(!t)return null;const n=/^file:/i.test(t)?Cwt(t):null;return n||(/^[A-Za-z]:[\\/]/.test(t)||/^\\\\[^\\]+\\[^\\]+/.test(t)?t:/^[a-z][a-z0-9+.-]*:/i.test(t)||t.startsWith("//")?null:Nwt.some(r=>t.startsWith(r))?t:null)}function CH({src:e,name:t,onOpen:n,onRemove:r,testId:i}){const{pushToast:a}=_r(),o=x.useRef(null),[l,c]=x.useState(null),u=wK();x.useEffect(()=>{if(!l)return;const g=v=>{var j;(j=o.current)!=null&&j.contains(v.target)||c(null)},b=v=>{v.key==="Escape"&&c(null)};return document.addEventListener("pointerdown",g),document.addEventListener("keydown",b),()=>{document.removeEventListener("pointerdown",g),document.removeEventListener("keydown",b)}},[l]);const d=g=>{g.preventDefault(),g.stopPropagation(),c(Gwt(g.clientX,g.clientY))},f=async()=>{c(null);try{await yK(e,t),a({title:"Image copied",tone:"success"})}catch(g){a({title:"Copy Image failed",body:g instanceof Error?g.message:String(g),tone:"error"})}},h=async()=>{if(c(null),!u){a({title:"Open in Finder unavailable",body:"Open in Finder is available in the desktop app.",tone:"error"});return}try{await vK(e,t)}catch(g){a({title:"Open in Finder failed",body:g instanceof Error?g.message:String(g),tone:"error"})}};return s.jsxs("div",{"data-testid":i,className:"relative inline-flex max-w-full",children:[s.jsx("button",{type:"button","aria-label":`Open image preview: ${t}`,className:"flex h-12 w-12 min-w-0 items-center justify-center overflow-hidden rounded-[calc(var(--radius-sm)+4px)] border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-active)_42%,transparent)] text-left transition-[border-color,box-shadow] hover:border-[color:var(--border-strong)] focus-visible:border-ring focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",onClick:n,onContextMenu:d,children:s.jsx("img",{src:e,alt:t,className:"h-full w-full shrink-0 object-cover",onContextMenu:d})}),r?s.jsx("button",{type:"button",className:"absolute -right-1.5 -top-1.5 inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full border border-[color:var(--border-soft)] bg-[color:var(--surface-elevated)] text-muted-foreground shadow-[var(--shadow-sm)] transition-colors hover:text-foreground focus-visible:border-ring focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50","aria-label":`Remove ${t}`,onClick:r,children:s.jsx(Gs,{className:"h-3.5 w-3.5"})}):null,l&&typeof document<"u"?oo.createPortal(s.jsxs("div",{ref:o,"data-testid":"chat-image-context-menu",role:"menu",className:"motion-chat-composer-menu-pop surface-overlay fixed z-50 min-w-[172px] rounded-[var(--radius-lg)] border p-1.5 text-foreground shadow-[var(--shadow-lg)]",style:l,children:[s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full disabled:cursor-not-allowed disabled:opacity-50",disabled:!u,onClick:h,children:[s.jsx(dc,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Open in Finder"})]}),s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:f,children:[s.jsx(Ni,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Copy Image"})]})]}),document.body):null]})}function SH({name:e,href:t,onRemove:n,onOpenFile:r}){const i=s.jsxs(s.Fragment,{children:[s.jsx(b1,{className:"h-3 w-3 shrink-0"}),s.jsx("span",{className:"truncate",children:e})]});if(t){const a=q7e(t);return a&&r?s.jsx("button",{type:"button",className:"chat-chip inline-flex max-w-full items-center gap-2 rounded-[calc(var(--radius-sm)+2px)] px-3 py-1.5 text-xs transition-colors hover:bg-[color:var(--surface-active)] hover:text-foreground",onClick:()=>r(a),children:i}):s.jsx("a",{href:t,target:"_blank",rel:"noreferrer",className:"chat-chip inline-flex max-w-full items-center gap-2 rounded-[calc(var(--radius-sm)+2px)] px-3 py-1.5 text-xs transition-colors hover:bg-[color:var(--surface-active)] hover:text-foreground",children:i})}return s.jsxs("span",{className:"chat-chip inline-flex max-w-full items-center gap-2 rounded-[calc(var(--radius-sm)+2px)] px-3 py-1.5 text-xs",children:[i,n?s.jsx("button",{type:"button",className:"inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:text-foreground","aria-label":`Remove ${e}`,onClick:n,children:s.jsx(Gs,{className:"h-3 w-3"})}):null]})}function G6({file:e,onOpenImage:t,onRemove:n}){const[r,i]=x.useState(null),a=xK(e.type),o=t8e(e);return x.useEffect(()=>{if(!a){i(null);return}const l=URL.createObjectURL(e);return i(l),()=>URL.revokeObjectURL(l)},[e,a]),a&&r?s.jsx(CH,{src:r,name:o,onOpen:()=>t({src:r,name:o}),onRemove:n,testId:"chat-pending-image-attachment"}):s.jsx(SH,{name:o,onRemove:n})}function rj({attachments:e,onOpenImage:t,onOpenFile:n}){return e.length===0?null:s.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:e.map(r=>{const i=t8e(r);return xK(r.contentType)?s.jsx(CH,{src:r.contentPath,name:i,onOpen:()=>t({src:r.contentPath,name:i}),testId:"chat-image-attachment"},r.id):s.jsx(SH,{name:i,href:r.contentPath,onOpenFile:n},r.id)})})}function K7e({preview:e,onOpenChange:t}){return s.jsx(kK,{preview:e?{src:e.src,name:e.name,alt:e.name}:null,onOpenChange:t,testId:"chat-image-preview-dialog",titleFallback:"Attachment preview"})}function H7e({message:e}){const t=x.useMemo(()=>cRe(e.structuredPayload).filter(n=>n.display==="card"),[e.structuredPayload]);return t.length===0?null:s.jsx("div",{className:"mt-3 flex max-w-[72ch] flex-col gap-2","data-testid":"chat-rich-references",children:t.map((n,r)=>s.jsx(Swt,{reference:n},`${n.type}:${n.issueId??n.identifier??"issue"}:${n.type==="issue_comment"?n.commentId:r}`))})}function Swt({reference:e}){return e.type==="issue"?s.jsx(_wt,{reference:e}):s.jsx(Awt,{reference:e})}function _wt({reference:e}){const t=V7e(e),n=Ne({queryKey:q.issues.detail(t),queryFn:()=>ln.get(t),retry:!1,enabled:!!t});return n.isLoading?s.jsx(D2,{icon:"issue",title:"Loading issue",detail:t,tone:"loading"}):n.isError?s.jsx(P$,{error:n.error,kind:"issue"}):n.data?s.jsx(Ewt,{issue:n.data}):s.jsx(D2,{icon:"issue",title:"Issue unavailable",detail:"The issue could not be loaded.",tone:"muted"})}function Awt({reference:e}){const t=V7e(e),n=Ne({queryKey:q.issues.detail(t),queryFn:()=>ln.get(t),retry:!1,enabled:!!t}),r=Ne({queryKey:q.issues.comment(t,e.commentId),queryFn:()=>ln.getComment(t,e.commentId),retry:!1,enabled:!!t});return n.isLoading||r.isLoading?s.jsx(D2,{icon:"comment",title:"Loading comment",detail:t,tone:"loading"}):n.isError?s.jsx(P$,{error:n.error,kind:"issue"}):r.isError?s.jsx(P$,{error:r.error,kind:"comment"}):!n.data||!r.data?s.jsx(D2,{icon:"comment",title:"Comment unavailable",detail:"The comment could not be loaded.",tone:"muted"}):s.jsx(Twt,{issue:n.data,comment:r.data})}function Ewt({issue:e}){const t=e.identifier??e.id.slice(0,8),n=e.assigneeAgentId?e.assigneeAgentId.slice(0,8):e.assigneeUserId?Ol(e.assigneeUserId,null)??e.assigneeUserId.slice(0,8):"Unassigned";return s.jsx(yt,{to:`/issues/${e.identifier??e.id}`,className:"group block rounded-lg border border-border bg-card px-3 py-2.5 text-left shadow-[var(--shadow-sm)] transition-colors hover:border-[color:var(--accent-strong)]/40 hover:bg-[color:var(--surface-active)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":`Open issue ${t}`,children:s.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[s.jsx("div",{className:"mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-border bg-background text-muted-foreground",children:s.jsx(Nd,{className:"h-4 w-4","aria-hidden":!0})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[s.jsx("span",{className:"font-mono text-[11px] font-medium text-foreground",children:t}),s.jsx(er,{status:e.status}),s.jsx("span",{children:Lo(e.priority)})]}),s.jsx("div",{className:"mt-1 truncate text-sm font-medium leading-5 text-foreground",children:e.title}),s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",children:[s.jsx("span",{children:n}),s.jsxs("span",{children:["Updated ",js(e.updatedAt)]})]})]})]})})}function Twt({issue:e,comment:t}){const n=e.identifier??e.id.slice(0,8),r=t.authorAgentId?t.authorAgentId.slice(0,8):t.authorUserId?Ol(t.authorUserId,null)??t.authorUserId.slice(0,8):"System",i=Iwt(t.body);return s.jsx(yt,{to:`/issues/${e.identifier??e.id}#comment-${t.id}`,className:"group block rounded-lg border border-border bg-card px-3 py-2.5 text-left shadow-[var(--shadow-sm)] transition-colors hover:border-[color:var(--accent-strong)]/40 hover:bg-[color:var(--surface-active)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":`Open comment on issue ${n}`,children:s.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[s.jsx("div",{className:"mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-border bg-background text-muted-foreground",children:s.jsx(Tme,{className:"h-4 w-4","aria-hidden":!0})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[s.jsx("span",{className:"font-mono text-[11px] font-medium text-foreground",children:n}),s.jsx("span",{children:r}),s.jsx("span",{children:js(t.createdAt)})]}),s.jsx("div",{className:"mt-1 truncate text-sm font-medium leading-5 text-foreground",children:e.title}),s.jsx("p",{className:"mt-1 max-h-[3.75rem] overflow-hidden text-sm leading-5 text-muted-foreground",children:i})]})]})})}function P$({error:e,kind:t}){if(e instanceof Ml){if(e.status===403)return s.jsx(D2,{icon:t,title:"Permission denied",detail:"You do not have access to this reference.",tone:"warning"});if(e.status===404)return s.jsx(D2,{icon:t,title:t==="issue"?"Issue not found":"Comment not found",detail:"The reference may have been deleted or moved.",tone:"muted"})}return s.jsx(D2,{icon:t,title:"Reference unavailable",detail:"The reference could not be loaded.",tone:"warning"})}function D2({icon:e,title:t,detail:n,tone:r}){const i=e==="issue"?Nd:g1;return s.jsx("div",{className:G("rounded-lg border border-dashed px-3 py-2.5 text-sm",r==="warning"?"border-amber-500/35 bg-amber-500/5 text-amber-800 dark:text-amber-200":"border-border bg-card text-muted-foreground"),children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-current/15 bg-background/70",children:s.jsx(i,{className:"h-4 w-4","aria-hidden":!0})}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"font-medium text-foreground",children:t}),s.jsx("div",{className:"mt-0.5 break-words text-xs",children:n})]})]})})}function V7e(e){return e.issueId??e.identifier??""}function Iwt(e){return e.replace(/!\[[^\]]*]\([^)]*\)/g,"").replace(/\[([^\]]+)]\([^)]*\)/g,"$1").replace(/[`*_>#~-]+/g,"").replace(/\s+/g," ").trim()||"No comment body."}function W7e({text:e,className:t,...n}){return s.jsxs("span",{role:"status","aria-label":`${e}...`,className:G("rudder-text-dots inline-flex items-baseline whitespace-nowrap align-baseline",t),...n,children:[s.jsx("span",{children:e}),s.jsx("span",{className:"rudder-text-dots__dots","aria-hidden":"true",children:[0,1,2].map(r=>s.jsx("span",{className:"rudder-text-dots__dot",style:{"--rudder-text-dot-index":r},children:"."},r))})]})}function h8({replyingAgentId:e,conversation:t,agents:n}){var l;const r=e?n==null?void 0:n.find(c=>c.id===e):null,i=e?((l=t.chatRuntime)==null?void 0:l.sourceLabel)??"Unknown agent":"Assistant",a=(r==null?void 0:r.name)??i,o=s.jsxs(s.Fragment,{children:[r||e?s.jsx(ki,{icon:r==null?void 0:r.icon,role:r==null?void 0:r.role,fallbackSeed:(r==null?void 0:r.id)??e,className:"h-8 w-8 shrink-0"}):s.jsx("span",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-border/70 bg-muted/90 text-foreground shadow-sm",children:s.jsx(Sd,{className:"h-4 w-4 text-muted-foreground"})}),s.jsx("span",{className:"text-sm font-semibold tracking-tight text-foreground",children:a})]});return s.jsx("div",{className:"mb-2 flex items-center gap-2.5",children:r?s.jsx(yt,{to:co(r),className:"inline-flex items-center gap-2.5 rounded-[calc(var(--radius-sm)-1px)] pr-1 outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/45","aria-label":`Open ${a} agent detail`,children:o}):o})}const _H={assignee:{agent:"assigneeAgentId",user:"assigneeUserId"},reviewer:{agent:"reviewerAgentId",user:"reviewerUserId"}};function Mwt(e,t){const n=_H[t],r=e[n.agent],i=typeof r=="string"?r.trim():"";if(i)return Jh({assigneeAgentId:i});const a=e[n.user],o=typeof a=="string"?a.trim():"";return o?Jh({assigneeUserId:o}):""}function Rwt(e,t,n){const r=_H[t],i=cu(n);return{...e,[r.agent]:i.assigneeAgentId,[r.user]:i.assigneeUserId}}function Owt(e,t){const n=e.proposedIssue&&typeof e.proposedIssue=="object"&&!Array.isArray(e.proposedIssue)?e.proposedIssue:{};return{...e,proposedIssue:{...n,...t}}}function Eie(e,t,n,r){const i=_H[t],a=e[i.agent],o=typeof a=="string"?a.trim():"";if(o){const u=(n==null?void 0:n.find(d=>d.id===o))??null;return{kind:"agent",label:(u==null?void 0:u.name)??(t==="assignee"?"Unknown agent":"Unknown reviewer"),agent:u}}const l=e[i.user],c=typeof l=="string"?l.trim():"";return c?{kind:"user",label:Ol(c,r)??(t==="assignee"?"Human assignee":"Human reviewer")}:null}function YR(e,t,n,r){const i=cu(e.id);if(i.assigneeAgentId){const a=(n==null?void 0:n.find(o=>o.id===i.assigneeAgentId))??null;return{kind:"agent",label:(a==null?void 0:a.name)??e.label,agent:a}}return i.assigneeUserId?{kind:"user",label:Ol(i.assigneeUserId,r)??e.label}:t==="assignee"?{kind:"user",label:"No owner"}:{kind:"user",label:"No reviewer"}}function JR({label:e,children:t}){return s.jsxs("div",{className:"grid min-h-9 grid-cols-[minmax(5rem,0.8fr)_minmax(0,1.2fr)] items-center gap-4 border-b border-[color:var(--border-soft)] py-2 last:border-b-0",children:[s.jsx("div",{className:"text-sm text-muted-foreground",children:e}),s.jsx("div",{className:"flex min-w-0 justify-end text-sm font-medium text-foreground",children:t})]})}function FC({principal:e}){var t,n;return e?e.kind==="agent"?s.jsx(Ki,{kind:"agent",label:e.label,badgeLabel:e.agent?Q2(e.agent):null,agentIcon:((t=e.agent)==null?void 0:t.icon)??null,agentRole:((n=e.agent)==null?void 0:n.role)??null}):s.jsx(Ki,{kind:"user",label:e.label}):s.jsx("span",{className:"text-muted-foreground",children:"None"})}function Tie({proposal:e,role:t,agents:n,currentUserId:r,onChange:i}){const a=Mwt(e,t),o=x.useMemo(()=>zP(r),[r]),l=x.useMemo(()=>{const u=(n??[]).filter(f=>f.status!=="terminated").map(f=>({id:Jh({assigneeAgentId:f.id}),label:f.name,searchText:`${f.name} ${f.role} ${f.title??""}`})),d=[...o,...u];if(a&&!d.some(f=>f.id===a)){const f=YR({id:a,label:t==="assignee"?"Current owner":"Current reviewer"},t,n,r);d.unshift({id:a,label:(f==null?void 0:f.label)??(t==="assignee"?"Current owner":"Current reviewer")})}return d},[n,r,o,t,a]),c=t==="assignee"?"No owner":"No reviewer";return s.jsx(Mf,{value:a,options:l,placeholder:c,noneLabel:c,searchPlaceholder:t==="assignee"?"Search owners...":"Search reviewers...",emptyMessage:t==="assignee"?"No owners found.":"No reviewers found.",ariaLabel:t==="assignee"?"Edit owner":"Edit reviewer",className:"max-w-full justify-end rounded-[var(--radius-sm)] border-transparent bg-transparent px-1.5 py-1 hover:border-border hover:bg-accent/50",contentClassName:"min-w-64",onChange:u=>i(Rwt(e,t,u)),renderTriggerValue:u=>u?s.jsx(FC,{principal:YR(u,t,n,r)}):s.jsx(Ki,{kind:"unassigned",label:c,muted:!0}),renderOption:u=>{if(!u.id)return s.jsx(Ki,{kind:"unassigned",label:u.label,muted:!0});const d=cu(u.id),f=d.assigneeAgentId?(n??[]).find(h=>h.id===d.assigneeAgentId)??null:null;return f?s.jsx(ip,{agent:f}):s.jsx(FC,{principal:YR(u,t,n,r)})}})}function Pwt({conversation:e,message:t,agents:n,currentUserId:r,issueProposalOverride:i,onIssueProposalChange:a,decisionNote:o,onDecisionNoteChange:l,onApprovalAction:c,onResolveOperationProposal:u,onConvertToIssue:d,actionPending:f,skillReferences:h,onMarkdownLinkClick:g}){var xe,re;const b=t.kind==="issue_proposal"?z$(t):null,v=b?i??b:null,j=t.kind==="issue_proposal"?c9t(t):null,k=t.kind==="operation_proposal"?B$(t):null,w=t.kind==="operation_proposal"?EH(t):null,N=n8e(t.approval),C=t.kind==="operation_proposal"&&!t.approval&&w==="pending",A=t.kind==="issue_proposal"&&!t.approval&&!e.primaryIssue,_=d9t(t),E=f9t(_),T=N||C,M=((xe=t.approval)==null?void 0:xe.status)==="pending",O=`proposal-review-note-${t.id}`,P=`proposal-details-${t.id}`,z=((re=t.approval)==null?void 0:re.decisionNote)??u9t(t),L=T||A||!!z,Q=_==="revision_requested"?"Requested changes":"Decision note",ee=v?Die(v,"assignee",n):null,B=v?Die(v,"reviewer",n):null,F=v?Eie(v,"assignee",n,r):null,Z=v?Eie(v,"reviewer",n,r):null,W=v?String(v.description):"",$=!!(v&&(N||A)&&a),[Y,V]=x.useState(!1),[H,ae]=x.useState(!1),le=x.useRef(null),fe=v?"issue":k?"operation":j?"plan":"default",U=v?"Issue proposal":k?"Operation proposal":j?"Plan proposal":"Proposal";return x.useEffect(()=>{V(!1)},[t.id,W]),x.useEffect(()=>{const X=le.current;if(!X||!v){ae(!1);return}const ie=()=>{const ke=window.getComputedStyle(X),Ce=Number.parseFloat(ke.lineHeight),$e=Number.isFinite(Ce)?Ce*10:240;ae(X.scrollHeight>$e+1)};if(ie(),typeof ResizeObserver>"u")return;const pe=new ResizeObserver(ie);return pe.observe(X),()=>pe.disconnect()},[v,W,Y]),s.jsxs("div",{className:"text-foreground",children:[s.jsx(h8,{replyingAgentId:t.replyingAgentId??null,conversation:e,agents:n}),t.body.trim().length>0?s.jsx(b0,{body:t.body,skillReferences:h,onMarkdownLinkClick:g,className:"mt-4 max-w-[72ch] text-[15px] leading-7 text-foreground"}):null,s.jsxs("div",{"data-testid":"proposal-review-block","data-status":_??"default","data-kind":fe,className:"chat-review-block mt-4 max-w-[860px] rounded-[var(--radius-lg)] text-foreground transition-all duration-200",children:[s.jsxs("div",{className:G("chat-review-docket-header grid border-b border-[color:var(--border-soft)]",_?"grid-cols-1 sm:grid-cols-[1fr_minmax(9rem,13rem)]":"grid-cols-1"),children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-5 py-4",children:[s.jsx("span",{className:"h-6 w-1 rounded-full bg-[color:var(--accent-strong)]","aria-hidden":"true"}),s.jsx("span",{className:"truncate text-sm font-semibold leading-5 text-foreground",children:U})]}),_?s.jsx("div",{"data-testid":"proposal-review-status",className:"relative z-[6] flex min-w-0 items-center justify-start border-t border-[color:var(--border-soft)] px-5 py-4 sm:justify-end sm:border-t-0 sm:pr-10",children:s.jsx(er,{status:_})}):null]}),s.jsx("div",{className:"px-5 py-5",children:s.jsxs("div",{className:"min-w-0",children:[v?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"grid gap-5 md:grid-cols-[minmax(0,1fr)_minmax(15rem,22rem)]",children:[s.jsx("div",{className:"flex min-w-0 items-center border-b border-[color:var(--border-soft)] pb-5 md:border-b-0 md:pb-0",children:s.jsx("div",{className:"text-[26px] font-semibold leading-tight text-foreground",children:String(v.title)})}),s.jsxs("div",{className:"chat-review-fact-ledger",children:[s.jsx(JR,{label:"Priority",children:s.jsx(ya,{priority:String(v.priority??"medium"),showLabel:!0})}),s.jsx(JR,{label:"Owner",children:$?s.jsx(Tie,{proposal:v,role:"assignee",agents:n,currentUserId:r,onChange:X=>a==null?void 0:a(t.id,X)}):s.jsx(FC,{principal:F})}),s.jsx(JR,{label:"Reviewer",children:$?s.jsx(Tie,{proposal:v,role:"reviewer",agents:n,currentUserId:r,onChange:X=>a==null?void 0:a(t.id,X)}):s.jsx(FC,{principal:Z})})]})]}),ee||B?s.jsxs("div",{className:"sr-only",children:[ee?s.jsxs("span",{children:["Assignee · ",ee]}):null,B?s.jsxs("span",{children:["Reviewer · ",B]}):null]}):null]}):k?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"text-base font-medium text-foreground",children:String(k.summary)}),s.jsxs("div",{className:"mt-1 text-xs font-medium text-muted-foreground",children:["Target · ",String(k.targetType),":",String(k.targetId)]})]}):j?s.jsx("div",{className:"text-base font-medium text-foreground",children:j.title}):null,E&&(!v||_!=="pending")?s.jsx("p",{className:"mt-3 text-sm leading-6 text-muted-foreground",children:E}):null]})}),v?s.jsxs("section",{className:"chat-review-details-section px-5 pb-4 pt-7",children:[s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[s.jsx("div",{className:"text-sm font-semibold text-foreground",children:"Proposal details"}),H?s.jsxs("button",{type:"button","aria-controls":P,"aria-expanded":Y,className:"inline-flex items-center gap-1 rounded-[var(--radius-sm)] px-1.5 py-1 text-xs font-medium text-[color:var(--accent-strong)] transition-colors hover:bg-[color:color-mix(in_oklab,var(--surface-proposal)_55%,transparent)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--ring)]",onClick:()=>V(X=>!X),children:[Y?"Show less":"Show full proposal",s.jsx(fr,{className:G("h-3.5 w-3.5 transition-transform duration-200",Y&&"rotate-180"),"aria-hidden":"true"})]}):null]}),s.jsx("div",{id:P,ref:le,className:G("chat-review-details-body text-sm leading-6 text-muted-foreground",!Y&&"chat-review-details-body--collapsed",H&&!Y&&"chat-review-details-body--can-expand"),children:s.jsx(Aa,{skillReferences:h,onLinkClick:g,children:W})})]}):null,j?s.jsxs("div",{className:"border-t border-[color:var(--border-soft)] px-5 py-4",children:[v?s.jsx("div",{className:"text-[11px] font-medium text-muted-foreground",children:j.title}):null,s.jsx("div",{className:"mt-3 text-sm leading-6 text-foreground",children:s.jsx(Aa,{skillReferences:h,onLinkClick:g,children:j.body})})]}):null,k!=null&&k.patch&&typeof k.patch=="object"?s.jsx("div",{className:"border-t border-[color:var(--border-soft)] px-5 py-4",children:s.jsx("pre",{className:"overflow-x-auto rounded-[var(--radius-lg)] border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-shell)_88%,transparent)] p-3 text-xs text-muted-foreground",children:JSON.stringify(k.patch,null,2)})}):null,L?s.jsxs("div",{className:"border-t border-[color:var(--border-soft)] px-5 py-5",children:[T?s.jsxs("label",{className:"block space-y-2",children:[s.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:M||C?"Feedback for agent":"Decision note"}),s.jsx(Na,{id:O,"data-testid":"proposal-review-note",value:o,onChange:X=>l(X.target.value),placeholder:M||C?"Tell the agent what must change before approval.":"Optional note for approval or rejection.",className:"chat-field min-h-[88px] rounded-[var(--radius-lg)]"})]}):null,!T&&z?s.jsxs("div",{className:"chat-review-note mt-1 rounded-[var(--radius-lg)] px-4 py-3",children:[s.jsx("div",{className:"text-[11px] font-medium text-muted-foreground",children:Q}),s.jsx("p",{className:"mt-2 text-sm leading-6 text-foreground/90",children:z})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[N&&t.approval?s.jsxs(s.Fragment,{children:[s.jsx(ce,{size:"sm",className:"bg-green-700 text-white hover:bg-green-600 dark:bg-green-600 dark:hover:bg-green-500",disabled:f,onClick:()=>c(t.approval.id,"approve",t.id),children:"Approve"}),M?s.jsx(ce,{size:"sm",variant:"outline",className:"text-foreground",disabled:f,onClick:()=>c(t.approval.id,"requestRevision",t.id),children:"Request changes"}):null,s.jsx(ce,{size:"sm",variant:"outline",className:"border-destructive/30 text-destructive hover:bg-destructive/10",disabled:f,onClick:()=>c(t.approval.id,"reject",t.id),children:"Reject"})]}):null,C?s.jsxs(s.Fragment,{children:[s.jsx(ce,{size:"sm",className:"bg-green-700 text-white hover:bg-green-600 dark:bg-green-600 dark:hover:bg-green-500",disabled:f,onClick:()=>u(t.id,"approve",o),children:"Approve"}),s.jsx(ce,{size:"sm",variant:"outline",className:"text-foreground",disabled:f,onClick:()=>u(t.id,"requestRevision",o),children:"Request changes"}),s.jsx(ce,{size:"sm",variant:"outline",className:"border-destructive/30 text-destructive hover:bg-destructive/10",disabled:f,onClick:()=>u(t.id,"reject",o),children:"Reject"})]}):null,A?s.jsx(ce,{size:"sm",variant:"outline",className:"text-foreground",disabled:f,onClick:()=>d(t),children:"Create issue"}):null]})]}):null]})]})}const zC="opacity-0 pointer-events-none transition-opacity duration-150 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100";function b0({body:e,skillReferences:t,onMarkdownLinkClick:n,className:r}){return s.jsx("div",{className:G("min-w-0",r),children:s.jsx("div",{"data-testid":"chat-long-message-body",className:"min-w-0",children:s.jsx(Aa,{skillReferences:t,onLinkClick:n,children:e})})})}function BC(e,t){const n=e==null?void 0:e[t];return typeof n=="string"&&n.trim().length>0?n.trim():null}function Dwt(e){const t=e.structuredPayload;if(!t||t.eventType!=="issue_created")return null;const n=BC(t,"issueId"),i=BC(t,"issueIdentifier")??n;if(!i)return null;const a=e.body.indexOf(i);return a<0?null:{issueRef:i,prefix:e.body.slice(0,a),suffix:e.body.slice(a+i.length)}}function Lwt(e){const t=e.structuredPayload;if(!t||t.eventType!=="automation_source"&&t.eventType!=="automation_created")return null;const n=BC(t,"automationId"),r=BC(t,"automationTitle")??"automation";return n?{automationId:n,automationTitle:r}:null}function Z7e({message:e,skillReferences:t,onMarkdownLinkClick:n}){var a;const r=Dwt(e),i=Lwt(e);return i?((a=e.structuredPayload)==null?void 0:a.eventType)==="automation_created"?s.jsxs("span",{className:"min-w-0 flex-1 leading-5",children:["Created automation"," ",s.jsx(yt,{to:`/automations/${i.automationId}`,className:"chat-system-issue-link","aria-label":`Open automation ${i.automationTitle}`,children:i.automationTitle})," ","from this chat conversation."]}):s.jsxs("span",{className:"min-w-0 flex-1 leading-5",children:["From automation"," ",s.jsx(yt,{to:`/automations/${i.automationId}`,className:"chat-system-issue-link","aria-label":`Open automation ${i.automationTitle}`,children:i.automationTitle}),"."]}):r?s.jsxs("span",{className:"min-w-0 flex-1 leading-5",children:[r.prefix,s.jsx(yt,{to:`/issues/${r.issueRef}`,className:"chat-system-issue-link","aria-label":`Open issue ${r.issueRef}`,children:r.issueRef}),r.suffix]}):s.jsx(Aa,{skillReferences:t,onLinkClick:n,children:e.body})}function G7e({message:e,request:t,answered:n,conversation:r,agents:i,skillReferences:a,onMarkdownLinkClick:o}){return s.jsx("div",{"data-testid":"chat-ask-user-history",className:"flex justify-start transition-all duration-200",children:s.jsxs("div",{className:"group w-full max-w-3xl px-1 py-1",children:[s.jsx(h8,{replyingAgentId:e.replyingAgentId??null,conversation:r,agents:i}),e.body.trim().length>0?s.jsx(b0,{body:e.body,skillReferences:a,onMarkdownLinkClick:o,className:"max-w-[72ch] text-[15px] leading-7 text-foreground"}):null,s.jsxs("div",{className:"mt-3 max-w-[72ch] rounded-lg border border-border bg-card px-3 py-2.5 text-sm shadow-[var(--shadow-sm)]",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"font-medium text-foreground",children:n?"Input requested":"Input needed"}),s.jsx("span",{className:"rounded-full bg-muted px-2 py-0.5 text-[11px] text-muted-foreground",children:n?"Answered":"Waiting"})]}),s.jsx("div",{className:"mt-1.5 space-y-1 text-muted-foreground",children:t.questions.map(l=>s.jsx("div",{className:"truncate",children:z5(l)},l.id))})]})]})})}function AH({answer:e}){return s.jsxs("div",{"data-testid":"chat-ask-user-answer",className:"chat-message-user w-fit max-w-[min(100%,72ch)] rounded-[var(--radius-xl)] px-4 py-3 shadow-[var(--shadow-sm)]","aria-label":"Answered requested input",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-foreground",children:[s.jsx(Mo,{className:"h-4 w-4 text-[color:var(--accent-strong)]","aria-hidden":!0}),s.jsx("span",{children:"Answered"})]}),s.jsx("div",{className:"mt-2 space-y-2",children:e.map(t=>s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:t.title}),s.jsx("div",{className:"mt-0.5 whitespace-pre-wrap text-[15px] leading-6 text-foreground",children:t.answer})]},t.questionId))})]})}function Q7e({message:e,request:t,disabled:n,pendingFiles:r,onAddAttachment:i,onRemovePendingFile:a,onOpenAttachmentPreview:o,onSubmit:l}){const[c,u]=x.useState({}),[d,f]=x.useState({}),[h,g]=x.useState(0),[b,v]=x.useState(!1);x.useEffect(()=>{u({}),f({}),g(0),v(!1)},[e.id]);const j=x.useMemo(()=>{var Q,ee;const L={};for(const B of t.questions){const F=c[B.id]??[],Z=B.selectionMode==="multiple";if(!Z&&F[0]==="__other"){const $=((Q=d[B.id])==null?void 0:Q.trim())??"";$&&(L[B.id]={kind:"freeform",text:$});continue}const W=F.filter($=>$!=="__other").map($=>{var Y;return(Y=B.options.find(V=>V.id===$))==null?void 0:Y.label}).filter($=>!!$);if(F.includes("__other")){const $=((ee=d[B.id])==null?void 0:ee.trim())??"";$&&W.push(`Other: ${$}`)}W.length>0&&(L[B.id]=Z?{kind:"options",labels:W}:{kind:"option",label:W[0]??""})}return L},[d,t.questions,c]),k=t.questions.length,w=k>1,N=Math.min(h,Math.max(k-1,0)),C=t.questions[N]??null,A=r.length>0,_=r.length===1?"See attached file.":"See attached files.",E=x.useMemo(()=>{if(!A)return j;const L={...j};for(const Q of t.questions){if(L[Q.id])continue;(c[Q.id]??[]).includes("__other")&&(L[Q.id]=Q.selectionMode==="multiple"?{kind:"options",labels:[`Other: ${_}`]}:{kind:"freeform",text:_})}return L},[_,j,A,t.questions,c]),T=C?E[C.id]:null,M=t.questions.every(L=>!!E[L.id]),O=L=>{if(w){if(L<k-1){g(L+1),v(!1);return}v(!0)}},P=L=>(L==null?void 0:L.kind)==="freeform"?L.text:(L==null?void 0:L.kind)==="options"?L.labels.join(", "):(L==null?void 0:L.label)??"Not answered",z=(L,Q,ee)=>{const B=L.selectionMode==="multiple";u(F=>{const Z=F[L.id]??[];if(!B)return{...F,[L.id]:[ee]};const W=Z.includes(ee)?Z.filter($=>$!==ee):[...Z,ee];return{...F,[L.id]:W}}),!B&&ee!=="__other"&&O(Q)};return s.jsxs("div",{"data-testid":"chat-ask-user-panel",className:"rounded-[var(--radius-lg)] border border-[color:color-mix(in_oklab,var(--accent-base)_35%,var(--border))] bg-[color:color-mix(in_oklab,var(--accent-soft)_28%,var(--surface-elevated))] p-3 shadow-[var(--shadow-sm)]",children:[w?s.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3 text-xs text-muted-foreground",children:[s.jsx("span",{children:b?"Review answers":`Question ${N+1} of ${k}`}),s.jsxs("span",{children:[Object.keys(E).length,"/",k," answered"]})]}):null,b?s.jsxs("section",{className:"rounded-[var(--radius-md)] border border-border bg-card/85 p-3",children:[s.jsx("div",{className:"text-sm font-medium text-foreground",children:"Review answers"}),s.jsx("div",{className:"mt-2 space-y-2",children:t.questions.map((L,Q)=>{const ee=E[L.id];return s.jsxs("button",{type:"button",className:"flex w-full min-w-0 items-start justify-between gap-3 rounded-[var(--radius-md)] px-2 py-1.5 text-left text-sm hover:bg-[color:var(--surface-active)]",onClick:()=>{g(Q),v(!1)},children:[s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"block truncate font-medium text-foreground",children:z5(L)}),s.jsx("span",{className:"mt-0.5 block whitespace-pre-wrap break-words text-muted-foreground",children:P(ee)})]}),s.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:"Edit"})]},L.id)})})]}):C?s.jsxs("section",{className:"rounded-[var(--radius-md)] border border-border bg-card/85 p-3",children:[s.jsx("div",{className:"text-sm font-medium text-foreground",children:z5(C)}),C.header&&C.header!==C.question?s.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:C.question}):null,s.jsxs("div",{className:"mt-2 grid gap-1.5",children:[C.options.map(L=>{const Q=c[C.id]??[],ee=C.selectionMode==="multiple",B=Q.includes(L.id);return s.jsxs("button",{type:"button",className:G("flex w-full items-start gap-2 rounded-[var(--radius-md)] border px-3 py-2 text-left text-sm transition-colors",B?"border-[color:var(--accent-base)] bg-[color:color-mix(in_oklab,var(--accent-soft)_62%,transparent)] text-foreground":"border-border bg-background/70 text-foreground hover:bg-[color:var(--surface-active)]"),"aria-pressed":B,onClick:()=>z(C,N,L.id),children:[s.jsx("span",{className:G("mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center border",ee?"rounded-[4px]":"rounded-full",B?"border-[color:var(--accent-base)] bg-[color:var(--accent-base)] text-primary-foreground":"border-border"),"aria-hidden":!0,children:B?s.jsx(Mo,{className:"h-3 w-3"}):null}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsxs("span",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[s.jsx("span",{className:"font-medium",children:L.label}),L.recommended?s.jsx("span",{className:"rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground",children:"Recommended"}):null]}),L.description?s.jsx("span",{className:"mt-0.5 block text-xs leading-5 text-muted-foreground",children:L.description}):null]})]},L.id)}),C.allowFreeform!==!1?s.jsxs("button",{type:"button",className:G("flex w-full items-center gap-2 rounded-[var(--radius-md)] border px-3 py-2 text-left text-sm transition-colors",(c[C.id]??[]).includes("__other")?"border-[color:var(--accent-base)] bg-[color:color-mix(in_oklab,var(--accent-soft)_62%,transparent)]":"border-border bg-background/70 hover:bg-[color:var(--surface-active)]"),"aria-pressed":(c[C.id]??[]).includes("__other"),onClick:()=>z(C,N,"__other"),children:[s.jsx("span",{className:G("flex h-4 w-4 shrink-0 items-center justify-center border",C.selectionMode==="multiple"?"rounded-[4px]":"rounded-full",(c[C.id]??[]).includes("__other")?"border-[color:var(--accent-base)] bg-[color:var(--accent-base)] text-primary-foreground":"border-border"),"aria-hidden":!0,children:(c[C.id]??[]).includes("__other")?s.jsx(Mo,{className:"h-3 w-3"}):null}),s.jsx("span",{className:"font-medium text-foreground",children:"Other"})]}):null]}),(c[C.id]??[]).includes("__other")?s.jsxs("div",{className:"mt-2 space-y-2",children:[s.jsx(Na,{value:d[C.id]??"",onChange:L=>f(Q=>({...Q,[C.id]:L.target.value})),placeholder:"Type your answer...",className:"min-h-20 resize-y rounded-[var(--radius-md)] bg-background text-sm"}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(ce,{type:"button",variant:"outline",size:"sm",disabled:n,onClick:i,className:"h-8 gap-1.5 px-2.5 text-xs",children:[s.jsx(b1,{className:"h-3.5 w-3.5"}),"Attach"]}),A?s.jsx("div",{"data-testid":"chat-ask-user-pending-attachments",className:"flex min-w-0 flex-wrap gap-2",children:r.map(L=>{const Q=UC(L);return s.jsx("div",{"data-testid":"chat-ask-user-pending-attachment",className:"max-w-full",children:s.jsx(G6,{file:L,onOpenImage:o,onRemove:()=>a(Q)})},Q)})}):null]})]}):null]},C.id):null,!(c[(C==null?void 0:C.id)??""]??[]).includes("__other")&&A?s.jsx("div",{"data-testid":"chat-ask-user-pending-attachments",className:"mt-3 flex min-w-0 flex-wrap gap-2",children:r.map(L=>{const Q=UC(L);return s.jsx("div",{"data-testid":"chat-ask-user-pending-attachment",className:"max-w-full",children:s.jsx(G6,{file:L,onOpenImage:o,onRemove:()=>a(Q)})},Q)})}):null,s.jsxs("div",{className:"mt-3 flex items-center justify-between gap-2",children:[w?s.jsx(ce,{type:"button",variant:"ghost",size:"sm",disabled:n||!b&&N===0,onClick:()=>{if(b){g(k-1),v(!1);return}g(L=>Math.max(L-1,0))},children:"Back"}):s.jsx("span",{"aria-hidden":!0}),w&&!b?s.jsx(ce,{type:"button",size:"sm",disabled:n||!T,onClick:()=>O(N),children:N===k-1?"Review answers":"Next"}):s.jsx(ce,{type:"button",size:"sm",disabled:n||!M,onClick:()=>l(g9t(t,E)),children:"Submit answer"})]})]})}function sj({conversation:e,message:t,agents:n,currentUserId:r,issueProposalOverride:i,decisionNote:a,onDecisionNoteChange:o,onApprovalAction:l,onIssueProposalChange:c,onResolveOperationProposal:u,onConvertToIssue:d,actionPending:f,onCopyMessageText:h,onEditUserMessage:g,onContinueInterruptedMessage:b,onRetryFailedMessage:v,onOpenImage:j,onOpenFile:k,onMarkdownLinkClick:w,turnBranchControls:N,skillReferences:C,answered:A,askUserAnswer:_}){if(t.kind==="issue_proposal"||t.kind==="operation_proposal")return s.jsx(Pwt,{conversation:e,message:t,agents:n,currentUserId:r,issueProposalOverride:i,onIssueProposalChange:c,decisionNote:a,onDecisionNoteChange:o,onApprovalAction:l,onResolveOperationProposal:u,onConvertToIssue:d,actionPending:f,skillReferences:C,onMarkdownLinkClick:w});const E=CA(t);if(E)return s.jsx(G7e,{message:t,request:E,answered:A??!1,conversation:e,agents:n,skillReferences:C,onMarkdownLinkClick:w});if(t.role==="system")return s.jsx("div",{className:"chat-system-pill rounded-[calc(var(--radius-sm)+2px)] px-4 py-2 text-sm transition-all duration-200",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Mo,{className:"h-4 w-4 text-[color:var(--accent-strong)]"}),s.jsx(Z7e,{message:t,skillReferences:C,onMarkdownLinkClick:w})]})});const T=t.role==="user",M=T?null:i8e(t.status),O=v9t(t),P=w9t(t);return T?s.jsx("div",{className:"flex justify-end transition-all duration-200",children:s.jsxs("div",{className:"group flex max-w-[82%] flex-col items-end text-left",children:[_?s.jsx(AH,{answer:_}):s.jsxs("div",{"data-testid":"chat-user-message-bubble",className:"chat-message-user w-fit max-w-[min(100%,72ch)] rounded-[var(--radius-xl)] px-4 py-3 shadow-[var(--shadow-sm)]",children:[s.jsx(b0,{body:t.body,skillReferences:C,onMarkdownLinkClick:w,className:"text-[15px] leading-7"}),s.jsx(rj,{attachments:t.attachments,onOpenImage:j,onOpenFile:k})]}),_&&t.attachments.length>0?s.jsx(rj,{attachments:t.attachments,onOpenImage:j,onOpenFile:k}):null,s.jsxs("div",{"data-testid":"chat-user-message-toolbar",className:G("mt-1 flex h-7 items-center justify-end gap-1 text-muted-foreground",zC),children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground","aria-label":"Copy message",onClick:()=>void h(t.body),children:s.jsx(Ni,{className:"h-4 w-4"})}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground","aria-label":"Edit message in composer",onClick:()=>g(t),children:s.jsx(s4,{className:"h-4 w-4"})}),N?s.jsxs("span",{className:"inline-flex items-center gap-0.5 rounded-md px-0.5 text-[11px] tabular-nums text-muted-foreground",children:[s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground disabled:pointer-events-none disabled:opacity-30","aria-label":"Previous branch",disabled:!N.canPrev,onClick:N.onPrev,children:s.jsx(Lz,{className:"h-4 w-4"})}),s.jsxs("span",{className:"min-w-[2.25rem] text-center",children:[N.current,"/",N.total]}),s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground disabled:pointer-events-none disabled:opacity-30","aria-label":"Next branch",disabled:!N.canNext,onClick:N.onNext,children:s.jsx(Ls,{className:"h-4 w-4"})})]}):null,s.jsx(m5,{date:t.createdAt,label:js(t.createdAt),className:"px-1 text-[11px] tracking-normal"})]})]})}):s.jsx("div",{"data-testid":"chat-assistant-message",className:"flex justify-start transition-all duration-200",children:s.jsxs("div",{className:"group w-full max-w-3xl px-1 py-1",children:[s.jsx(h8,{replyingAgentId:t.replyingAgentId??null,conversation:e,agents:n}),M?s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx("span",{className:G("rounded-full px-2 py-0.5 text-[10px]",a8e(t.status)),children:M}),O?s.jsx("button",{type:"button",className:"inline-flex h-7 items-center rounded-md border border-amber-500/30 bg-amber-500/10 px-2 text-xs font-medium text-amber-700 transition-[background-color,border-color,color,box-shadow] hover:border-amber-500/70 hover:bg-amber-500/25 hover:text-amber-950 hover:shadow-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500/35 dark:text-amber-300 dark:hover:text-amber-100",onClick:()=>b(t),children:"Continue"}):null,P?s.jsxs("button",{type:"button",className:"inline-flex h-7 items-center gap-1.5 rounded-md border border-destructive/30 bg-destructive/10 px-2 text-xs font-medium text-destructive transition-colors hover:bg-destructive/15",onClick:()=>v(t),children:[s.jsx(Qv,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Retry"]}):null]}):null,s.jsx(b0,{body:t.body,skillReferences:C,onMarkdownLinkClick:w,className:"max-w-[72ch] text-[15px] leading-7 text-foreground"}),s.jsx(H7e,{message:t}),s.jsx(rj,{attachments:t.attachments,onOpenImage:j,onOpenFile:k}),s.jsxs("div",{className:G("mt-2 flex h-7 items-center gap-1 text-muted-foreground",zC),children:[s.jsx(m5,{date:t.createdAt,label:js(t.createdAt),className:"text-[11px] tracking-normal"}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground","aria-label":"Copy message",onClick:()=>void h(t.body),children:s.jsx(Ni,{className:"h-4 w-4"})})]})]})})}function Y7e({body:e,createdAt:t,onCopyMessageText:n,onEditDraftOnly:r,skillReferences:i,onMarkdownLinkClick:a,askUserAnswer:o}){return s.jsx("div",{className:"flex justify-end transition-all duration-200",children:s.jsxs("div",{className:"group flex max-w-[82%] flex-col items-end text-left",children:[o?s.jsx(AH,{answer:o}):s.jsx("div",{className:"chat-message-user w-fit max-w-[min(100%,72ch)] rounded-[var(--radius-xl)] px-4 py-3 shadow-[var(--shadow-sm)]",children:s.jsx(b0,{body:e,skillReferences:i,onMarkdownLinkClick:a,className:"text-[15px] leading-7"})}),s.jsxs("div",{className:G("mt-1 flex h-7 items-center justify-end gap-1 text-muted-foreground",zC),children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground","aria-label":"Copy message",onClick:()=>void n(e),children:s.jsx(Ni,{className:"h-4 w-4"})}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground","aria-label":"Edit message in composer",onClick:()=>r(e),children:s.jsx(s4,{className:"h-4 w-4"})}),s.jsx(m5,{date:t,label:js(t),className:"px-1 text-[11px] tracking-normal"})]})]})})}function J7e(){return s.jsxs("div",{className:"flex flex-col gap-5 pb-2",children:[s.jsx("div",{className:"flex justify-end",children:s.jsx("div",{className:"chat-message-user w-fit max-w-[min(100%,72ch)] rounded-[var(--radius-xl)] px-4 py-3 shadow-[var(--shadow-sm)]",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx(Et,{className:"ml-auto h-4 w-[18rem]"}),s.jsx(Et,{className:"ml-auto h-4 w-[13rem]"})]})})}),s.jsx("div",{className:"flex justify-start",children:s.jsx("div",{className:"w-full max-w-3xl rounded-[var(--radius-xl)] px-1 py-4",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx(Et,{className:"h-4 w-[92%]"}),s.jsx(Et,{className:"h-4 w-[84%]"}),s.jsx(Et,{className:"h-4 w-[76%]"})]})})})]})}function D$({entries:e,state:t,streamStartedAt:n,streamEndedAt:r,assistantMessageBody:i,showDeveloperDiagnostics:a,defaultOpen:o=!1,onOpenChange:l}){const c=t==="streaming"||t==="finalizing",[u,d]=x.useState(()=>c||o),[f,h]=x.useState(0);x.useEffect(()=>{if(!c)return;const j=window.setInterval(()=>h(k=>k+1),500);return()=>clearInterval(j)},[c]),x.useEffect(()=>{o&&d(!0)},[o]);const g=x.useMemo(()=>{const j=n.getTime(),k=(r==null?void 0:r.getTime())??0,w=c?Date.now():Math.max(U7e(e),k);return Math.max(0,w-j)},[n,r,c,e,f]);if(e.length===0)return null;const b=t==="failed"?"Stopped with errors":t==="stopped"?"Stopped":"",v=u||c;return s.jsx("div",{"data-testid":"chat-transcript-item",className:"flex justify-start transition-all duration-200",children:s.jsxs("div",{className:"w-full max-w-3xl px-1 py-1",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"h-px min-w-[1rem] flex-1 bg-border/45","aria-hidden":!0}),s.jsxs("button",{type:"button",className:G("flex max-w-[min(100%,90%)] shrink-0 items-center gap-1.5 text-[12px] text-muted-foreground transition-colors",c?"cursor-default":"hover:text-foreground"),disabled:c,onClick:()=>{c||d(j=>{const k=!j;return l==null||l(k),k})},"aria-expanded":v,children:[c?s.jsx(yr,{className:"h-3.5 w-3.5 shrink-0 animate-spin","aria-hidden":!0}):null,s.jsxs("span",{className:"whitespace-nowrap",children:[c?"Working":"Worked"," for ",vwt(g)]}),b?s.jsxs("span",{className:"truncate text-amber-700/90 dark:text-amber-400/85",children:["· ",b]}):null,c?s.jsx(fr,{className:"h-4 w-4 shrink-0 opacity-60","aria-hidden":!0}):v?s.jsx(fr,{className:"h-4 w-4 shrink-0 opacity-60","aria-hidden":!0}):s.jsx(Ls,{className:"h-4 w-4 shrink-0 opacity-60","aria-hidden":!0})]}),s.jsx("div",{className:"h-px min-w-[1rem] flex-1 bg-border/45","aria-hidden":!0})]}),v?s.jsx("div",{className:"mt-3",children:s.jsx(Qf,{entries:e,mode:"nice",density:"compact",streaming:c,collapseStdout:!0,presentation:"chat",showDeveloperDiagnostics:a,hiddenAssistantMessageText:i})}):null]})})}function X7e({body:e,createdAt:t,state:n,replyingAgentId:r,conversation:i,agents:a,onCopyMessageText:o,skillReferences:l,onMarkdownLinkClick:c}){const u=n==="streaming"||n==="finalizing",d=u?null:i8e(n);return!e.trim()&&!u?null:s.jsx("div",{className:"flex justify-start transition-all duration-200",children:s.jsxs("div",{className:"group w-full max-w-3xl px-1 py-1",children:[s.jsx(h8,{replyingAgentId:r,conversation:i,agents:a}),d?s.jsx("div",{className:"mb-2 flex flex-wrap items-center gap-2 text-[11px] text-muted-foreground",children:s.jsx("span",{className:G("rounded-full px-2 py-0.5 text-[10px]",a8e(n)),children:d})}):null,s.jsx("div",{className:"max-w-[72ch] text-[15px] leading-7 text-foreground",children:e.trim()?s.jsx(b0,{body:e,skillReferences:l,onMarkdownLinkClick:c}):s.jsx(W7e,{text:"Thinking",className:"text-muted-foreground"})}),e.trim()?s.jsxs("div",{className:G("mt-2 flex h-7 items-center gap-1 text-muted-foreground",zC),children:[s.jsx(m5,{date:t,label:js(t),className:"text-[11px] tracking-normal"}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground","aria-label":"Copy message",onClick:()=>void o(e),children:s.jsx(Ni,{className:"h-4 w-4"})})]}):null]})})}const $wt="List my open tasks by priority",L$=[{label:"Scope a new feature",examples:["Plan an approval queue for budget overrides","Scope a weekly CEO status digest","Design an organization plugin install flow"]},{label:"Clarify a vague request",examples:["Turn rough notes into an implementation plan","Figure out what 'make Messenger less noisy' should mean","Translate a founder ask into acceptance criteria"]},{label:"Turn a chat into an issue",examples:[$wt,"Extract the next shippable task from this discussion","Split this conversation into scope, owner, and done criteria","Draft an issue from a decision we already made"]},{label:"Review a blocker",examples:["Diagnose why a packaged desktop build is failing","Review a confusing approval flow before more coding","Decide whether to patch the design or write a standard first"]}],jc="__none__",$$="rudder.chatLastProjectByOrg";function e8e({group:e,optionsId:t,entered:n,originX:r,onExampleSelect:i}){return s.jsxs("div",{id:t,"data-testid":"chat-empty-state-prompt-options","data-entered":n?"true":"false",role:"region","aria-label":`${e.label} examples`,style:{"--chat-options-origin-x":r},className:"motion-chat-options-pop mt-3 w-full max-w-3xl rounded-[var(--radius-lg)] border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-panel)_86%,transparent)] px-3 py-3 shadow-[var(--shadow-sm)]",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3",children:[s.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Example use cases"}),s.jsx("p",{className:"text-sm text-foreground",children:e.label})]}),s.jsx("div",{className:"flex flex-wrap gap-2",children:e.examples.map(a=>s.jsx("button",{type:"button","data-chat-option":!0,onClick:()=>i(a),className:"rounded-[calc(var(--radius-sm)+2px)] border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_72%,transparent)] px-3 py-2 text-left text-sm text-muted-foreground transition-colors hover:border-[color:var(--border-strong)] hover:bg-[color:var(--surface-active)] hover:text-foreground",children:a},a))})]},e.label)}function Fwt(e){if(!(typeof window>"u"))try{const t=window.localStorage.getItem($$);if(!t)return;const n=JSON.parse(t);if(!n||typeof n!="object")return;const r=n[e];return typeof r=="string"?r:r===null?null:void 0}catch{return}}function ok(e,t){if(!(typeof window>"u"))try{const n=window.localStorage.getItem($$),r=n?JSON.parse(n):{},i=r&&typeof r=="object"?r:{};i[e]=t,window.localStorage.setItem($$,JSON.stringify(i))}catch{}}function XR(e){var t;return((t=e==null?void 0:e.contextLinks.find(n=>n.entityType==="project"))==null?void 0:t.entityId)??null}function zwt(e,t){const n=t==null?void 0:t.trim();return n?(e??[]).find(r=>r.id===n||r.identifier===n)??null:null}function Bwt(e){var t;return e&&(((t=e.identifier)==null?void 0:t.trim())||e.title.trim())||"this issue"}function Uwt(e,t){const n=[];return t&&n.push({entityType:"issue",entityId:t}),e&&n.push({entityType:"project",entityId:e}),n}function qwt(e,t){var n;return e.assigneeAgentId?((n=t.get(e.assigneeAgentId))==null?void 0:n.name)??e.assigneeAgentId.slice(0,8):e.assigneeUserId?Ol(e.assigneeUserId,null)??e.assigneeUserId.slice(0,8):null}function eO(e){var t;return((t=e==null?void 0:e.name)==null?void 0:t.trim())||"Unknown project"}function Kwt({activeProjectName:e,userNickname:t,t:n}){const r=(e==null?void 0:e.trim())??"";if(r)return n("chat.emptyState.headingProject",{project:r});const i=(t==null?void 0:t.trim())??"";return i?n("chat.emptyState.headingNamed",{name:i}):n("chat.emptyState.heading")}function Hwt(e){return kBe(e)}const Ay=12,lk=10,Iie=128,Vwt=360,Mie=320;function Rie(e){const t=e.getBoundingClientRect(),n=window.innerWidth,r=window.innerHeight,i=Math.max(Mie,n-Ay*2),a=Math.min(Math.max(t.width,Mie),i),o=Math.min(Math.max(t.left,Ay),n-Ay-a),l=Math.max(0,t.top-Ay-lk),c=Math.max(0,r-t.bottom-Ay-lk),u=l>=Iie||l>=c,d=Math.max(Iie,Math.min(Vwt,u?l:c));return u?{left:o,width:a,bottom:r-t.top+lk,maxHeight:d}:{left:o,width:a,top:t.bottom+lk,maxHeight:d}}function Wwt(e){var r,i;const t=e.trim().toLowerCase();if(!t)return"bin";if(t==="text/plain")return"txt";if(t==="text/markdown")return"md";if(t==="application/json")return"json";if(t==="text/csv")return"csv";if(t==="text/html")return"html";if(t==="application/pdf")return"pdf";const n=(i=(r=t.split("/")[1])==null?void 0:r.split(";")[0])==null?void 0:i.trim();return n&&n.length>0?n:"bin"}async function Zwt(e,t){const n=await e.arrayBuffer(),r=e.name.trim()||`pasted-attachment-${t+1}.${Wwt(e.type)}`;return new File([n],r,{type:e.type,lastModified:e.lastModified||Date.now()})}function UC(e){return`${e.name}-${e.size}-${e.lastModified}`}function t8e(e){return e.originalFilename??e.name??e.assetId??"attachment"}function Gwt(e,t){return typeof window>"u"?{left:e,top:t}:{left:Math.min(e,Math.max(8,window.innerWidth-190)),top:Math.min(t,Math.max(8,window.innerHeight-96))}}function Qwt(e){return e.button===0&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey}const Ywt="No agents available",Oie="Read-only planning. The agent should investigate, produce a plan, and create an issue with that plan attached.";function Jwt(e,t){const n=new Map;for(const r of e)n.set(r.id,r);for(const r of t){const i=n.get(r.id);n.set(r.id,{...i??r,...r,replyingAgentId:r.replyingAgentId??(i==null?void 0:i.replyingAgentId)??null,chatTurnId:r.chatTurnId??(i==null?void 0:i.chatTurnId)??null,turnVariant:r.turnVariant??(i==null?void 0:i.turnVariant)??0,supersededAt:r.supersededAt??(i==null?void 0:i.supersededAt)??null})}return Array.from(n.values()).map(r=>({...r,replyingAgentId:r.replyingAgentId??null,chatTurnId:r.chatTurnId??null,turnVariant:r.turnVariant??0,supersededAt:r.supersededAt??null})).sort((r,i)=>new Date(r.createdAt).getTime()-new Date(i.createdAt).getTime())}function Xwt(e){e.scrollTo({top:e.scrollHeight,behavior:"auto"})}function e9t(e,t){const n=[...e].sort((c,u)=>new Date(c.createdAt).getTime()-new Date(u.createdAt).getTime());if(!t)return n.filter(c=>!c.supersededAt);const{chatTurnId:r,turnVariant:i}=t,a=n.filter(c=>c.chatTurnId===r&&c.turnVariant===i);if(a.length===0)return n.filter(c=>!c.supersededAt);const o=n.filter(c=>!c.supersededAt&&c.chatTurnId!==r),l=[...a].sort((c,u)=>new Date(c.createdAt).getTime()-new Date(u.createdAt).getTime());return[...o,...l].sort((c,u)=>new Date(c.createdAt).getTime()-new Date(u.createdAt).getTime())}function t9t(e,t,n){const r=e.filter(i=>i.id!==t.id);return n!=="all"&&t.status!==n?r:[t,...r]}function n9t(e,t){return fp(t)||fp(e.latestReplyPreview)||fp(e.summary)||"Start the conversation"}function F$(e){return e6(e)}function r9t(e,t){const n=n9t(e,t==null?void 0:t.preview);return{threadKey:`chat:${e.id}`,kind:"chat",title:F$(e),subtitle:n,preview:n,latestActivityAt:(t==null?void 0:t.latestActivityAt)??e.lastMessageAt??e.updatedAt,lastReadAt:e.lastReadAt,unreadCount:e.unreadCount,needsAttention:e.needsAttention,isPinned:e.isPinned,href:`/messenger/chat/${e.id}`}}function s9t(e,t){const n=e.filter(r=>r.threadKey!==t.threadKey);return[t,...n].sort((r,i)=>{const a=r.latestActivityAt?new Date(r.latestActivityAt).getTime():Number.NEGATIVE_INFINITY,o=i.latestActivityAt?new Date(i.latestActivityAt).getTime():Number.NEGATIVE_INFINITY;return a!==o?o-a:r.title.localeCompare(i.title)})}function i9t(e,t,n){const r=t.trim();return r?{...e,title:gBe(e.title,r),summary:e.summary??r,lastMessageAt:n,updatedAt:n}:e}function a9t(e,t){return e.planMode===t?e:{...e,planMode:t,updatedAt:new Date}}function o9t({hasConversation:e,preferredAgentId:t,hasLastMessageAt:n,hasMessages:r,hasActiveStream:i,hasActiveSendInFlight:a}){return!!(e&&(i||a||t&&(n||r)))}function l9t({hasConversation:e,hasLastMessageAt:t,hasMessages:n,hasActiveStream:r,hasActiveSendInFlight:i}){return!!(e&&(r||i||t||n))}function n8e(e){return(e==null?void 0:e.status)==="pending"}function Pie(e){var n;const t=(n=e.proposalTitle)==null?void 0:n.trim();return[t?`Please revise the proposal "${t}" based on the feedback below.`:"Please revise the current proposal based on the feedback below.","","Return a new proposal for review. Do not create the issue or apply the change yet.","","Requested changes:",e.feedback.trim()].join(`
1398
+ `);let i=null;for(let o=0;o<r.length;o+=1){const l=r[o]??"",c=l.match(/^ {0,3}(`{3,}|~{3,})/);if(c){const b=c[1]??"",v=b.charAt(0);if(!i){i={marker:v,length:b.length};continue}i.marker===v&&b.length>=i.length&&(i=null);continue}if(i)continue;const u=l.match(/^ {0,3}(#{1,6})(?:[ \t]+|$)(.*)$/);if(!u)continue;const d=(u[2]??"").replace(/[ \t]+#+[ \t]*$/g,""),f=f8t(d);if(!f)continue;const h=m8t(f)||`section-${o+1}`,g=n.get(h)??0;n.set(h,g+1),t.push({id:g===0?h:`${h}-${g+1}`,level:((a=u[1])==null?void 0:a.length)??1,title:f,line:o+1,headingIndex:t.length})}return t}const E7e=900,T7e=e=>`rudder:issue-document-folds:${e}`;function die(e){if(typeof window>"u")return[];try{const t=window.localStorage.getItem(T7e(e));if(!t)return[];const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>typeof r=="string"):[]}catch{return[]}}function fie(e,t){typeof window>"u"||window.localStorage.setItem(T7e(e),JSON.stringify(t))}function mie(e,t){return s.jsx(Aa,{className:t,children:e})}function e1(e){return e.trim().toLowerCase()==="plan"}function I7e(e){return e.split(/[-_ ]+/g).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function p8t(e){return e.replace(/^#{1,6}\s+/,"").replace(/^[-*+]\s+/,"").replace(/^\d+\.\s+/,"").replace(/^\>\s+/,"").replace(/`+/g,"").replace(/\[(.*?)\]\(.*?\)/g,"$1").replace(/[*_~]/g,"").trim()}function F5(e,t,n){const r=e==null?void 0:e.trim();if(r)return r;const i=t.split(/\r?\n/).map(p8t).find(a=>a.length>0);return i?i.slice(0,80):n&&!e1(n)?I7e(n):"Untitled document"}function g8t(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"note"}function M7e(e,t,n){const r=new Set(n),i=g8t(F5(e,t)),a=i==="plan"?"note":i;let o=a,l=2;for(;r.has(o);)o=`${a}-${l}`,l+=1;return o}function hie(e){return e1(e.key)?"Plan":F5(e.title,e.body,e.key)}function R7e(e){return e instanceof Ml&&e.status===409}function x8t(e,t){const n=new Blob([t],{type:"text/markdown;charset=utf-8"}),r=URL.createObjectURL(n),i=document.createElement("a");i.href=r,i.download=`${e}.md`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}function b8t({issue:e,canDeleteDocuments:t,mentions:n,imageUploadHandler:r,extraActions:i,onFocusDocument:a,onFocusNewDocument:o}){const l=vn(),c=Mn(),[u,d]=x.useState(null),[f,h]=x.useState(null),[g,b]=x.useState(null),[v,j]=x.useState(null),[k,w]=x.useState(()=>die(e.id)),[N,C]=x.useState(null),[A,_]=x.useState(null),[E,T]=x.useState(null),M=x.useRef(null),O=x.useRef(null),P=x.useRef(!1),{state:z,markDirty:L,reset:Q,runSave:ee}=bH(),{data:B}=Ne({queryKey:q.issues.documents(e.id),queryFn:()=>ln.listDocuments(e.id)}),F=()=>{l.invalidateQueries({queryKey:q.issues.detail(e.id)}),l.invalidateQueries({queryKey:q.issues.documents(e.id)})},Z=nt({mutationFn:async Pe=>ln.upsertDocument(e.id,Pe.key,{title:e1(Pe.key)?null:Pe.title.trim()||null,format:"markdown",body:Pe.body,baseRevisionId:Pe.baseRevisionId})}),W=nt({mutationFn:Pe=>ln.deleteDocument(e.id,Pe),onSuccess:()=>{h(null),d(null),F()},onError:Pe=>{h(Pe instanceof Error?Pe.message:"Failed to delete document")}}),$=x.useMemo(()=>[...B??[]].sort((Pe,Ae)=>Pe.key==="plan"&&Ae.key!=="plan"?-1:Pe.key!=="plan"&&Ae.key==="plan"?1:new Date(Ae.updatedAt).getTime()-new Date(Pe.updatedAt).getTime()),[B]),Y=$.some(Pe=>Pe.key==="plan"),V=$.length===0&&!e.legacyPlanDocument,H=x.useCallback(()=>{C(null),Q()},[Q]),ae=x.useCallback(Pe=>{C(Pe),L()},[L]),le=()=>{if(o){o();return}H(),j(null),b({key:"",title:"",body:"",baseRevisionId:null,isNew:!0}),h(null)},fe=Pe=>{const Ae=$.find(D=>D.key===Pe);if(!Ae)return;const oe=(v==null?void 0:v.key)===Pe?v.localDraft:null;w(D=>D.filter(J=>J!==Pe)),H(),j(D=>(D==null?void 0:D.key)===Pe?D:null),b({key:(oe==null?void 0:oe.key)??Ae.key,title:(oe==null?void 0:oe.title)??Ae.title??"",body:(oe==null?void 0:oe.body)??Ae.body,baseRevisionId:(oe==null?void 0:oe.baseRevisionId)??Ae.latestRevisionId,isNew:!1}),h(null)},U=()=>{M.current&&clearTimeout(M.current),H(),j(null),b(null),h(null)},xe=x.useCallback(async(Pe,Ae)=>{if(!Pe||Z.isPending)return!1;const oe=Pe.body.trim(),D=Pe.isNew?M7e(Pe.title,Pe.body,$.map(K=>K.key)):Pe.key.trim().toLowerCase(),J=F5(Pe.title,Pe.body,Pe.isNew?void 0:D),de=(v==null?void 0:v.key)===D?v:null;if(de&&!(Ae!=null&&Ae.overrideConflict))return Ae!=null&&Ae.trackAutosave&&H(),!1;if(!oe)return Pe.isNew?h("Add some content before creating the document"):h("Document body cannot be empty"),Ae!=null&&Ae.trackAutosave&&H(),!1;const ue=$.find(K=>K.key===D);if(!Pe.isNew&&ue&&ue.body===Pe.body&&(ue.title??"")===Pe.title)return Ae!=null&&Ae.clearAfterSave&&b(K=>(K==null?void 0:K.key)===D?null:K),Ae!=null&&Ae.trackAutosave&&H(),!0;const me=async()=>{const K=await Z.mutateAsync({...Pe,key:D,title:e1(D)?"":J,body:Pe.body,baseRevisionId:Ae!=null&&Ae.overrideConflict?(de==null?void 0:de.serverDocument.latestRevisionId)??Pe.baseRevisionId:Pe.baseRevisionId});h(null),j(je=>(je==null?void 0:je.key)===D?null:je),b(je=>!je||!(Pe.isNew?je.isNew&&je.key===Pe.key:je.key===D)?je:Ae!=null&&Ae.clearAfterSave?null:{key:K.key,title:K.title??J,body:K.body,baseRevisionId:K.latestRevisionId,isNew:!1}),F()};try{return Ae!=null&&Ae.trackAutosave?(C(D),await ee(me)):await me(),!0}catch(K){if(R7e(K))try{const je=await ln.getDocument(e.id,D);return j({key:D,serverDocument:je,localDraft:{key:D,title:e1(D)?"":J,body:Pe.body,baseRevisionId:Pe.baseRevisionId,isNew:!1},showRemote:!0}),w(Be=>Be.filter(Ve=>Ve!==D)),h(null),H(),!1}catch{return h("Document changed remotely and the latest version could not be loaded"),!1}return h(K instanceof Error?K.message:"Failed to save document"),!1}},[v,F,e.id,H,ee,$,Z]),re=x.useCallback(Pe=>{if((v==null?void 0:v.key)!==Pe)return;const Ae=v.serverDocument;b({key:Ae.key,title:Ae.title??"",body:Ae.body,baseRevisionId:Ae.latestRevisionId,isNew:!1}),j(null),H(),h(null)},[v,H]),X=x.useCallback(async Pe=>{if((v==null?void 0:v.key)!==Pe)return;const Ae=g&&g.key===Pe&&!g.isNew?g:v.localDraft;await xe({...Ae,baseRevisionId:v.serverDocument.latestRevisionId},{clearAfterSave:!1,trackAutosave:!0,overrideConflict:!0})},[xe,v,g]),ie=x.useCallback(Pe=>{(v==null?void 0:v.key)===Pe&&(b(v.localDraft),j(Ae=>(Ae==null?void 0:Ae.key)===Pe?{...Ae,showRemote:!1}:Ae),h(null))},[v]),pe=x.useCallback(async(Pe,Ae)=>{try{await navigator.clipboard.writeText(Ae),_(Pe),O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{_(oe=>oe===Pe?null:oe)},1400)}catch{h("Could not copy document")}},[]),ke=async Pe=>{Pe.currentTarget.contains(Pe.relatedTarget)||(M.current&&clearTimeout(M.current),await xe(g,{clearAfterSave:!0,trackAutosave:!0}))},Ce=async Pe=>{if(Pe.key==="Escape"){Pe.preventDefault(),U();return}(Pe.metaKey||Pe.ctrlKey)&&Pe.key==="Enter"&&(Pe.preventDefault(),M.current&&clearTimeout(M.current),await xe(g,{clearAfterSave:!1,trackAutosave:!0}))},$e=x.useCallback(async Pe=>{await xe(g,{clearAfterSave:!0,trackAutosave:(Pe==null?void 0:Pe.trackAutosave)??!1})&&H()},[xe,g]);x.useEffect(()=>{w(die(e.id))},[e.id]),x.useEffect(()=>{P.current=!1},[e.id,c.hash]),x.useEffect(()=>{const Pe=new Set($.map(Ae=>Ae.key));w(Ae=>{const oe=Ae.filter(D=>Pe.has(D));return oe.length!==Ae.length&&fie(e.id,oe),oe})},[e.id,$]),x.useEffect(()=>{fie(e.id,k)},[k,e.id]),x.useEffect(()=>{if(!v)return;const Pe=$.find(Ae=>Ae.key===v.key);!Pe||Pe.latestRevisionId===v.serverDocument.latestRevisionId||j(Ae=>(Ae==null?void 0:Ae.key)===Pe.key?{...Ae,serverDocument:Pe}:Ae)},[v,$]),x.useEffect(()=>{const Pe=c.hash;if(!Pe.startsWith("#document-"))return;const Ae=decodeURIComponent(Pe.slice(10));if(!($.some(de=>de.key===Ae)||Ae==="plan"&&!!e.legacyPlanDocument)||P.current)return;w(de=>de.filter(ue=>ue!==Ae));const D=document.getElementById(`document-${Ae}`);if(!D)return;P.current=!0,T(Ae),D.scrollIntoView({behavior:"smooth",block:"center"});const J=setTimeout(()=>T(de=>de===Ae?null:de),3e3);return()=>clearTimeout(J)},[e.legacyPlanDocument,c.hash,$]),x.useEffect(()=>()=>{M.current&&clearTimeout(M.current),O.current&&clearTimeout(O.current)},[]),x.useEffect(()=>{if(!g||g.isNew||(v==null?void 0:v.key)===g.key)return;const Pe=$.find(oe=>oe.key===g.key);if(!Pe)return;if(!(Pe.body!==g.body||(Pe.title??"")!==g.title)){z!=="saved"&&H();return}return ae(g.key),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{xe(g,{clearAfterSave:!1,trackAutosave:!0})},E7e),()=>{M.current&&clearTimeout(M.current)}},[z,xe,v,g,ae,H,$]);const Ue="mt-3 overflow-hidden rounded-md",he="",We="rudder-edit-in-place-content min-h-[220px] text-[15px] leading-7",ct=Pe=>{w(Ae=>Ae.includes(Pe)?Ae.filter(oe=>oe!==Pe):[...Ae,Pe])};return s.jsxs("div",{className:"space-y-3",children:[V&&!(g!=null&&g.isNew)?s.jsxs("div",{className:"flex items-center justify-end gap-2 min-w-0",children:[i,s.jsxs(ce,{variant:"quiet",size:"xs",onClick:le,className:"shrink-0",children:[s.jsx(tr,{className:"mr-1.5 h-3.5 w-3.5"}),s.jsx("span",{className:"hidden sm:inline",children:"New document"}),s.jsx("span",{className:"sm:hidden",children:"New"})]})]}):s.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[s.jsx("h3",{className:"text-sm font-medium text-muted-foreground shrink-0",children:"Documents"}),s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[i,s.jsxs(ce,{variant:"quiet",size:"xs",onClick:le,className:"shrink-0",children:[s.jsx(tr,{className:"mr-1.5 h-3.5 w-3.5"}),s.jsx("span",{className:"hidden sm:inline",children:"New document"}),s.jsx("span",{className:"sm:hidden",children:"New"})]})]})]}),f&&s.jsx("p",{className:"text-xs text-destructive",children:f}),(g==null?void 0:g.isNew)&&s.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-accent/10 p-3",onBlurCapture:ke,onKeyDown:Ce,children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(In,{autoFocus:!0,value:g.title,onChange:Pe=>b(Ae=>Ae&&{...Ae,title:Pe.target.value}),placeholder:"Document title"}),s.jsx(ce,{type:"button",variant:"ghost",size:"icon-sm",className:"shrink-0 text-muted-foreground",title:"Expand editor","aria-label":"Expand editor",onMouseDown:Pe=>Pe.preventDefault(),onClick:()=>o==null?void 0:o(),children:s.jsx(c5,{className:"h-4 w-4"})})]}),s.jsx(ol,{value:g.body,onChange:Pe=>b(Ae=>Ae&&{...Ae,body:Pe}),placeholder:"Write the document...",bordered:!1,className:"bg-transparent",contentClassName:"min-h-[220px] text-[15px] leading-7",mentions:n,imageUploadHandler:r,onSubmit:()=>void $e()}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(ce,{variant:"outline",size:"sm",onClick:U,children:[s.jsx(Gs,{className:"mr-1.5 h-3.5 w-3.5"}),"Cancel"]}),s.jsx(ce,{size:"sm",onClick:()=>void $e(),disabled:Z.isPending,children:Z.isPending?"Saving...":"Create"})]})]}),!Y&&e.legacyPlanDocument?s.jsxs("div",{id:"document-plan",className:G("rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 transition-colors duration-1000",E==="plan"&&"border-primary/50 bg-primary/5"),children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx(Nd,{className:"h-4 w-4 text-amber-600"}),s.jsx("span",{className:"rounded-full border border-amber-500/30 px-2 py-0.5 font-mono text-[10px] uppercase tracking-[0.16em] text-amber-700 dark:text-amber-300",children:"PLAN"})]}),s.jsx("div",{className:he,children:mie(e.legacyPlanDocument.body,We)})]}):null,s.jsx("div",{className:"space-y-3",children:$.map(Pe=>{const Ae=(g==null?void 0:g.key)===Pe.key&&!g.isNew?g:null,oe=(v==null?void 0:v.key)===Pe.key?v:null,D=k.includes(Pe.key),J=Ae?F5(Ae.title,Ae.body,Pe.key):hie(Pe);return s.jsxs("div",{id:`document-${Pe.key}`,className:G("rounded-lg border border-border p-3 transition-colors duration-1000",E===Pe.key&&"border-primary/50 bg-primary/5"),children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("button",{type:"button",className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground",onClick:()=>ct(Pe.key),"aria-label":D?`Expand ${J}`:`Collapse ${J}`,"aria-expanded":!D,children:D?s.jsx(Ls,{className:"h-3.5 w-3.5"}):s.jsx(fr,{className:"h-3.5 w-3.5"})}),s.jsx(Nd,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),s.jsx("p",{className:"truncate text-sm font-medium",children:J})]}),s.jsx("div",{className:"mt-1 flex items-center gap-2 pl-7",children:s.jsxs("a",{href:`#document-${encodeURIComponent(Pe.key)}`,className:"truncate text-[11px] text-muted-foreground transition-colors hover:text-foreground hover:underline",children:["rev ",Pe.latestRevisionNumber," • updated ",js(Pe.updatedAt)]})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(ce,{type:"button",variant:"ghost",size:"icon-xs",className:"text-muted-foreground",title:"Expand editor","aria-label":"Expand editor",onMouseDown:de=>de.preventDefault(),onClick:()=>{a==null||a(Pe.key)},children:s.jsx(c5,{className:"h-3.5 w-3.5"})}),s.jsx(ce,{variant:"ghost",size:"icon-xs",className:G("text-muted-foreground transition-colors",A===Pe.key&&"text-foreground"),title:A===Pe.key?"Copied":"Copy document",onClick:()=>void pe(Pe.key,(Ae==null?void 0:Ae.body)??Pe.body),children:A===Pe.key?s.jsx(gs,{className:"h-3.5 w-3.5"}):s.jsx(Ni,{className:"h-3.5 w-3.5"})}),s.jsxs($o,{children:[s.jsx(Fo,{asChild:!0,children:s.jsx(ce,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground",title:"Document actions",children:s.jsx(Iu,{className:"h-3.5 w-3.5"})})}),s.jsxs(zo,{align:"end",children:[s.jsxs(Hn,{onClick:()=>x8t(Pe.key,(Ae==null?void 0:Ae.body)??Pe.body),children:[s.jsx(Kf,{className:"h-3.5 w-3.5"}),"Download document"]}),t?s.jsx(fd,{}):null,t?s.jsxs(Hn,{variant:"destructive",onClick:()=>d(Pe.key),children:[s.jsx(Sa,{className:"h-3.5 w-3.5"}),"Delete document"]}):null]})]})]})]}),D?null:s.jsxs("div",{className:"mt-3 space-y-3",onFocusCapture:()=>{Ae||fe(Pe.key)},onBlurCapture:async de=>{Ae&&await ke(de)},onKeyDown:async de=>{Ae&&await Ce(de)},children:[oe&&s.jsxs("div",{className:G("rounded-md border px-3 py-3",xA.warn),children:[s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:G("text-sm font-medium",c2.warn),children:"Out of date"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"This document changed while you were editing. Your local draft is preserved and autosave is paused."})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(ce,{variant:"outline",size:"sm",onClick:()=>j(de=>(de==null?void 0:de.key)===Pe.key?{...de,showRemote:!de.showRemote}:de),children:oe.showRemote?"Hide remote":"Review remote"}),s.jsx(ce,{variant:"outline",size:"sm",onClick:()=>ie(Pe.key),children:"Keep my draft"}),s.jsx(ce,{variant:"outline",size:"sm",onClick:()=>re(Pe.key),children:"Reload remote"}),s.jsx(ce,{size:"sm",onClick:()=>void X(Pe.key),disabled:Z.isPending,children:Z.isPending?"Saving...":"Overwrite remote"})]})]}),oe.showRemote&&s.jsxs("div",{className:"mt-3 rounded-md border border-border/70 bg-background/60 p-3",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2 text-[11px] text-muted-foreground",children:[s.jsxs("span",{children:["Remote revision ",oe.serverDocument.latestRevisionNumber]}),s.jsx("span",{children:"•"}),s.jsxs("span",{children:["updated ",js(oe.serverDocument.updatedAt)]})]}),s.jsx("p",{className:"mb-2 text-sm font-medium",children:hie(oe.serverDocument)}),mie(oe.serverDocument.body,"text-[14px] leading-7")]})]}),Ae&&!e1(Pe.key)&&s.jsx(In,{value:Ae.title,onChange:de=>{ae(Pe.key),b(ue=>ue&&{...ue,title:de.target.value})},placeholder:"Document title"}),s.jsx("div",{className:`${Ue} ${he} ${Ae?"":"hover:bg-accent/10"}`,children:s.jsx(ol,{value:(Ae==null?void 0:Ae.body)??Pe.body,onChange:de=>{ae(Pe.key),b(ue=>ue&&ue.key===Pe.key&&!ue.isNew?{...ue,body:de}:{key:Pe.key,title:Pe.title??J,body:de,baseRevisionId:Pe.latestRevisionId,isNew:!1})},placeholder:"Write the document...",bordered:!1,className:"bg-transparent",contentClassName:We,mentions:n,imageUploadHandler:r,onSubmit:()=>void xe(Ae??g,{clearAfterSave:!1,trackAutosave:!0})})}),s.jsx("div",{className:"flex min-h-4 items-center justify-end px-1",children:s.jsx("span",{className:`text-[11px] transition-opacity duration-150 ${oe?"text-amber-300":z==="error"?"text-destructive":"text-muted-foreground"} ${Ae?"opacity-100":"opacity-0"}`,children:Ae?oe?"Out of date":N===Pe.key?z==="saving"?"Autosaving...":z==="saved"?"Saved":z==="error"?"Could not save":"":"":""})})]}),u===Pe.key&&s.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 rounded-md border border-destructive/20 bg-destructive/5 px-4 py-3",children:[s.jsx("p",{className:"text-sm text-destructive font-medium",children:"Delete this document? This cannot be undone."}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsx(ce,{variant:"ghost",size:"sm",onClick:()=>d(null),disabled:W.isPending,children:"Cancel"}),s.jsx(ce,{variant:"destructive",size:"sm",onClick:()=>W.mutate(Pe.key),disabled:W.isPending,children:W.isPending?"Deleting...":"Delete"})]})]})]},Pe.id)})})]})}function y8t({issue:e,target:t,motionState:n="open",mentions:r,imageUploadHandler:i,onClose:a,onDocumentCreated:o}){const l=vn(),c=x.useRef(null),u=x.useRef(null),[d,f]=x.useState(null),[h,g]=x.useState(null),[b,v]=x.useState(null),j=x.useRef(null),{state:k,markDirty:w,reset:N,runSave:C}=bH(),{data:A}=Ne({queryKey:q.issues.documents(e.id),queryFn:()=>ln.listDocuments(e.id)}),_=x.useMemo(()=>[...A??[]].sort((Z,W)=>Z.key==="plan"&&W.key!=="plan"?-1:Z.key!=="plan"&&W.key==="plan"?1:new Date(W.updatedAt).getTime()-new Date(Z.updatedAt).getTime()),[A]),E=t.kind==="existing"?_.find(Z=>Z.key===t.key):null,T=nt({mutationFn:async Z=>ln.upsertDocument(e.id,Z.key,{title:e1(Z.key)?null:Z.title.trim()||null,format:"markdown",body:Z.body,baseRevisionId:Z.baseRevisionId})}),M=x.useCallback(()=>{v(null),N()},[N]),O=x.useCallback(()=>{l.invalidateQueries({queryKey:q.issues.detail(e.id)}),l.invalidateQueries({queryKey:q.issues.documents(e.id)})},[e.id,l]);x.useEffect(()=>{if(M(),g(null),t.kind==="new"){f({key:"",title:"",body:"",baseRevisionId:null,isNew:!0});return}E&&f({key:E.key,title:E.title??"",body:E.body,baseRevisionId:E.latestRevisionId,isNew:!1})},[E,M,t.kind]),x.useEffect(()=>{d&&d.title.trim()&&window.requestAnimationFrame(()=>{var Z;return(Z=c.current)==null?void 0:Z.focus()})},[d==null?void 0:d.key]),x.useEffect(()=>()=>{j.current&&clearTimeout(j.current)},[]);const P=x.useCallback(async(Z,W)=>{if(!Z||T.isPending)return!1;const $=Z.body.trim(),Y=Z.isNew?M7e(Z.title,Z.body,_.map(le=>le.key)):Z.key.trim().toLowerCase(),V=F5(Z.title,Z.body,Z.isNew?void 0:Y);if(!$)return Z.isNew||g("Document body cannot be empty"),W!=null&&W.trackAutosave&&M(),!1;const H=_.find(le=>le.key===Y);if(!Z.isNew&&H&&H.body===Z.body&&(H.title??"")===Z.title)return W!=null&&W.trackAutosave&&M(),!0;const ae=async()=>{const le=await T.mutateAsync({...Z,key:Y,title:e1(Y)?"":V,body:Z.body});g(null),f({key:le.key,title:le.title??V,body:le.body,baseRevisionId:le.latestRevisionId,isNew:!1}),O(),Z.isNew&&(o==null||o(le.key))};try{return W!=null&&W.trackAutosave?(v(Y),await C(ae)):await ae(),!0}catch(le){return R7e(le)?(g("Document changed remotely. Return to the issue and reopen it to refresh."),M(),!1):(g(le instanceof Error?le.message:"Failed to save document"),!1)}},[O,o,M,C,_,T]);x.useEffect(()=>{if(!d)return;const Z=d.isNew?null:_.find($=>$.key===d.key);if(!(d.isNew?d.body.trim().length>0:!!Z&&(Z.body!==d.body||(Z.title??"")!==d.title))){k!=="saved"&&M();return}return g(null),v(d.key),w(),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>{P(d,{trackAutosave:!0})},E7e),()=>{j.current&&clearTimeout(j.current)}},[k,P,d,w,M,_]);const z=d?F5(d.title,d.body,d.isNew?void 0:d.key):t.kind==="existing"?I7e(t.key):"Untitled document",L=x.useMemo(()=>h8t((d==null?void 0:d.body)??""),[d==null?void 0:d.body]),Q=!!(d!=null&&d.body.trim()),ee=!!b||!!(d!=null&&d.isNew&&Q),B=h?"Could not save":k==="saving"&&ee?"Saving...":k==="error"&&ee?"Could not save":k==="saved"||d&&!d.isNew?"Saved":"",F=x.useCallback(Z=>{var Y,V;const $=Array.from(((Y=u.current)==null?void 0:Y.querySelectorAll("h1,h2,h3,h4,h5,h6"))??[])[Z.headingIndex];if($ instanceof HTMLElement){$.scrollIntoView({block:"center",behavior:"smooth"});return}(V=c.current)==null||V.focus()},[]);return s.jsxs("section",{"aria-label":"Focused document editor",className:G("min-h-[calc(100dvh-7rem)]",n==="closing"?"animate-out fade-out-0 slide-out-to-right-2 duration-200":"animate-in fade-in-0 slide-in-from-right-2 duration-200"),children:[s.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3 border-b border-border/60 pb-3",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx(ce,{type:"button",variant:"ghost",size:"icon-sm",className:"shrink-0 text-muted-foreground",onClick:a,"aria-label":"Back to issue",title:"Back to issue",children:s.jsx(O1,{className:"h-4 w-4"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-xs text-muted-foreground",children:[s.jsx("span",{className:"truncate",children:e.identifier??e.id}),s.jsx("span",{children:"/"}),s.jsx("span",{className:"truncate",children:"Document"})]}),s.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:z})]})]}),s.jsx("div",{className:G("shrink-0 text-xs",h?"text-destructive":"text-muted-foreground"),children:B})]}),h?s.jsx("p",{className:"mb-3 text-xs text-destructive",children:h}):null,s.jsxs("div",{className:"grid min-h-[calc(100dvh-13rem)] w-full grid-cols-1 gap-6 pt-3 xl:grid-cols-[minmax(0,1fr)_220px]",children:[s.jsx("div",{className:"flex min-h-[calc(100dvh-13rem)] w-full max-w-[980px] min-w-0 flex-col pl-10 pr-4",children:d?s.jsxs(s.Fragment,{children:[e1(d.key)?s.jsx("h2",{className:"text-[28px] font-semibold leading-tight text-foreground",children:"Plan"}):s.jsx("input",{value:d.title,onChange:Z=>{f(W=>W&&{...W,title:Z.target.value})},placeholder:"Untitled document",className:"w-full bg-transparent text-[28px] font-semibold leading-tight text-foreground outline-none placeholder:text-muted-foreground/45",autoFocus:!0}),s.jsx("div",{className:"mt-4 border-t border-border/60"}),s.jsx("div",{ref:u,className:"min-h-0 flex-1",children:s.jsx(ol,{ref:c,value:d.body,onChange:Z=>{f(W=>W&&{...W,body:Z})},placeholder:"Write the document...",bordered:!1,className:"mt-4 min-h-0 flex-1 bg-transparent",contentClassName:"min-h-[calc(100dvh-20rem)] cursor-text text-[16px] leading-7",mentions:r,imageUploadHandler:i,onSubmit:()=>void P(d,{trackAutosave:!0})})})]}):s.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading document..."})}),s.jsx("aside",{"aria-label":"Document sections",className:"hidden min-w-0 xl:block",children:s.jsxs("div",{className:"sticky top-4 border-l border-border/60 py-1 pl-4",children:[s.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Sections"}),L.length>0?s.jsx("nav",{className:"space-y-0.5",children:L.map(Z=>s.jsx("button",{type:"button",className:"block w-full truncate rounded px-2 py-1 text-left text-xs leading-5 text-muted-foreground hover:bg-accent/50 hover:text-foreground focus:outline-none focus:ring-1 focus:ring-ring",style:{paddingLeft:`${8+Math.max(0,Z.level-1)*10}px`},title:Z.title,onClick:()=>F(Z),children:Z.title},Z.id))}):s.jsx("p",{className:"max-w-[180px] text-xs leading-5 text-muted-foreground/75",children:"Add Markdown headings to show sections."})]})})]})]})}const v8t="mark[data-issue-find-highlight='true']",w8t=["[data-issue-find-ui]","input","textarea","select","script","style","noscript","[aria-hidden='true']"].join(","),O7e="color-mix(in oklab, #f4c430 62%, transparent)",k8t="color-mix(in oklab, var(--accent-base) 58%, #f4c430)",j8t="0 0 0 1px color-mix(in oklab, var(--accent-strong) 62%, transparent)";function N8t(e){e.style.borderRadius="2px",e.style.background=O7e,e.style.color="inherit",e.style.padding="0 1px"}function ZR(e,t){var n;return((n=e.ownerDocument.defaultView)==null?void 0:n.NodeFilter[t])??(t==="FILTER_ACCEPT"?1:t==="FILTER_REJECT"?2:4)}function C8t(e){const t=e instanceof HTMLElement?e:null;return t?t.isContentEditable?!0:!!t.closest("input, textarea, select, [contenteditable='true']"):!1}function S8t(e){return e.defaultPrevented||e.key.toLowerCase()!=="f"||!e.metaKey&&!e.ctrlKey?!1:!e.altKey&&!e.shiftKey}function nj(e){const t=Array.from(e.querySelectorAll(v8t));for(const n of t){const r=n.parentNode;if(r){for(;n.firstChild;)r.insertBefore(n.firstChild,n);r.removeChild(n),r.normalize()}}}function _8t(e,t){var a;const n=e.parentElement;if(!n||n.closest(w8t)||t!=null&&t.contains(n))return!1;const r=n.ownerDocument.activeElement,i=n.closest("[contenteditable='true']");return i&&r instanceof Node&&i.contains(r)?!1:!!((a=e.nodeValue)!=null&&a.trim())}function A8t(e,t,n={}){nj(e);const r=t.trim();if(!r)return[];const i=e.ownerDocument,a=[],o=i.createTreeWalker(e,ZR(e,"SHOW_TEXT"),{acceptNode:f=>_8t(f,n.skipElement)?ZR(e,"FILTER_ACCEPT"):ZR(e,"FILTER_REJECT")});let l=o.nextNode();for(;l;)a.push(l),l=o.nextNode();const c=[],u=r.toLocaleLowerCase(),d=r.length;for(const f of a){const h=f.nodeValue??"",g=h.toLocaleLowerCase();let b=0,v=g.indexOf(u,b);if(v===-1)continue;const j=i.createDocumentFragment();for(;v!==-1;){v>b&&j.append(i.createTextNode(h.slice(b,v)));const k=i.createElement("mark");k.dataset.issueFindHighlight="true",k.className="issue-find-highlight",N8t(k),k.textContent=h.slice(v,v+d),j.append(k),c.push(k),b=v+d,v=g.indexOf(u,b)}b<h.length&&j.append(i.createTextNode(h.slice(b))),f.replaceWith(j)}return c}function pie(e,t){let n=null;for(let r=0;r<e.length;r+=1){const i=e[r],a=r===t;i.dataset.issueFindActive=a?"true":"false",i.classList.toggle("issue-find-highlight--active",a),i.style.background=a?k8t:O7e,i.style.boxShadow=a?j8t:"",a&&(n=i)}return n}function E8t(){return typeof document>"u"?!1:!!(document.querySelector("[role='dialog']")||document.querySelector("[data-radix-popper-content-wrapper]"))}function T8t(e){return e.key==="Escape"&&!e.defaultPrevented&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.shiftKey}function I8t({rootRef:e,disabled:t=!1,refreshKey:n}){const[r,i]=x.useState(!1),[a,o]=x.useState(""),[l,c]=x.useState(0),[u,d]=x.useState(0),f=x.useRef(null),h=x.useRef([]),g=x.useRef(0),b=x.useRef(""),v=x.useRef(null),j=x.useCallback(()=>{requestAnimationFrame(()=>{var C,A;(C=f.current)==null||C.focus(),(A=f.current)==null||A.select()})},[]),k=x.useCallback(()=>{const C=e.current;C&&nj(C),h.current=[],g.current=0,b.current="",v.current=null,i(!1),o(""),c(0),d(0)},[e]),w=x.useCallback(C=>{var T;const A=h.current;if(A.length===0){g.current=0,d(0);return}const _=(g.current+C+A.length)%A.length;g.current=_,d(_);const E=pie(A,_);(T=E==null?void 0:E.scrollIntoView)==null||T.call(E,{block:"center",inline:"nearest",behavior:"smooth"})},[]);if(x.useEffect(()=>{t&&r&&k()},[k,t,r]),x.useEffect(()=>{const C=A=>{if(t)return;if(S8t(A)){if(E8t())return;const T=A.target instanceof HTMLElement?A.target:null;v.current=(T==null?void 0:T.closest("input, textarea, select, [contenteditable='true']"))??null,A.preventDefault(),i(!0),j();return}if(!r||!T8t(A))return;const _=A.target instanceof HTMLElement?A.target:null;!(_!=null&&_.closest("[data-issue-find-ui]"))&&C8t(A.target)||(A.preventDefault(),k())};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[k,t,j,r]),x.useLayoutEffect(()=>{var O;const C=e.current;if(!C||!r)return;const A=A8t(C,a,{skipElement:v.current});h.current=A,c(A.length);const _=a.trim(),E=b.current!==_;b.current=_;const T=A.length===0||E?0:Math.min(g.current,A.length-1);g.current=T,d(T);const M=pie(A,T);return _&&M&&((O=M.scrollIntoView)==null||O.call(M,{block:"center",inline:"nearest",behavior:"smooth"})),()=>{nj(C),h.current=[]}},[r,a,n,e]),x.useEffect(()=>()=>{const C=e.current;C&&nj(C)},[e]),!r)return null;const N=l===0?"0 of 0":`${u+1} of ${l}`;return s.jsxs("div",{"data-issue-find-ui":!0,role:"search","aria-label":"Find in issue",className:"fixed right-4 top-4 z-50 flex w-[min(420px,calc(100vw-2rem))] items-center gap-1 rounded-md border border-border bg-popover p-1.5 text-popover-foreground shadow-md",children:[s.jsx(na,{className:"ml-1 h-4 w-4 shrink-0 text-muted-foreground"}),s.jsx(In,{ref:f,value:a,onChange:C=>o(C.target.value),onKeyDown:C=>{if(C.key==="Enter"){C.preventDefault(),w(C.shiftKey?-1:1);return}if(C.key==="ArrowDown"){C.preventDefault(),w(1);return}if(C.key==="ArrowUp"){C.preventDefault(),w(-1);return}C.key==="Escape"&&(C.preventDefault(),k())},className:"h-7 min-w-0 flex-1 border-0 bg-transparent px-1 text-sm shadow-none focus-visible:ring-0",placeholder:"Find","aria-label":"Find in issue"}),s.jsx("span",{className:"min-w-14 shrink-0 text-right text-xs tabular-nums text-muted-foreground",children:N}),s.jsx(ce,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"Previous match",disabled:l===0,onClick:()=>w(-1),children:s.jsx(yme,{className:"h-3.5 w-3.5"})}),s.jsx(ce,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"Next match",disabled:l===0,onClick:()=>w(1),children:s.jsx(bme,{className:"h-3.5 w-3.5"})}),s.jsx(ce,{type:"button",variant:"ghost",size:"icon-xs","aria-label":"Close find",onClick:k,children:s.jsx(Gs,{className:"h-3.5 w-3.5"})})]})}function M8t(e){var t,n,r,i,a,o,l,c;return e?((t=e.codebase)==null?void 0:t.scope)==="organization"||((n=e.codebase)==null?void 0:n.scope)==="none"?((r=e.executionWorkspacePolicy)==null?void 0:r.defaultProjectWorkspaceId)??null:((i=e.executionWorkspacePolicy)==null?void 0:i.defaultProjectWorkspaceId)??((o=(a=e.workspaces)==null?void 0:a.find(u=>u.isPrimary))==null?void 0:o.id)??((c=(l=e.workspaces)==null?void 0:l[0])==null?void 0:c.id)??null:null}function ff({label:e,children:t,align:n="center"}){return s.jsxs("div",{"data-slot":"issue-property-row","data-align":n,className:G("flex gap-3 py-1.5",n==="start"?"items-start":"items-center"),children:[s.jsx("span",{className:"text-xs text-muted-foreground shrink-0 w-20",children:e}),s.jsx("div",{className:"flex items-center gap-1.5 min-w-0 flex-1",children:t})]})}function Cy({inline:e,label:t,open:n,onOpenChange:r,triggerContent:i,triggerClassName:a,popoverClassName:o,popoverAlign:l="end",rowAlign:c="center",extra:u,children:d}){const f=G("inline-flex min-w-0 max-w-full items-center gap-1.5 cursor-pointer hover:bg-accent/50 rounded px-1 -mx-1 py-0.5 transition-colors",a);return e?s.jsxs("div",{children:[s.jsxs(ff,{label:t,align:c,children:[s.jsx("button",{className:f,onClick:()=>r(!n),children:i}),u]}),n&&s.jsx("div",{className:G("rounded-md border border-border bg-popover p-1 mb-2",o),children:d})]}):s.jsxs(ff,{label:t,align:c,children:[s.jsxs(qn,{open:n,onOpenChange:r,children:[s.jsx(Wn,{asChild:!0,children:s.jsx("button",{className:f,children:i})}),s.jsx(Kn,{className:G("p-1",o),align:l,collisionPadding:16,children:d})]}),u]})}function gie({issue:e,onUpdate:t,inline:n,childIssues:r}){var st,kt,$t,Nn,_n,Ee;const{selectedOrganizationId:i}=wn(),{openNewIssue:a}=Wr(),{pushToast:o}=_r(),l=vn(),c=e.orgId??i,[u,d]=x.useState(!1),[f,h]=x.useState(""),[g,b]=x.useState(!1),[v,j]=x.useState(""),[k,w]=x.useState(!1),[N,C]=x.useState(""),[A,_]=x.useState(!1),[E,T]=x.useState(""),[M,O]=x.useState(!1),[P,z]=x.useState(!1),[L,Q]=x.useState(""),[ee,B]=x.useState(!1),[F,Z]=x.useState(""),W=ns(),$=ns(),{data:Y}=Ne({queryKey:q.auth.session,queryFn:()=>Di.getSession()}),V=((st=Y==null?void 0:Y.user)==null?void 0:st.id)??((kt=Y==null?void 0:Y.session)==null?void 0:kt.userId),{data:H}=Ne({queryKey:q.agents.list(c),queryFn:()=>Bt.list(c),enabled:!!c}),{data:ae}=Ne({queryKey:q.projects.list(c),queryFn:()=>ws.list(c),enabled:!!c}),le=x.useMemo(()=>(ae??[]).filter(we=>!we.archivedAt||we.id===e.projectId),[ae,e.projectId]),{orderedProjects:fe}=j7({projects:le,orgId:c,userId:V}),{data:U}=Ne({queryKey:q.issues.labels(c),queryFn:()=>ln.listLabels(c),enabled:!!c}),{data:xe}=Ne({queryKey:q.issues.list(c),queryFn:()=>ln.list(c),enabled:!!c}),re=nt({mutationFn:we=>ln.createLabel(c,we),onSuccess:async we=>{await l.invalidateQueries({queryKey:q.issues.labels(c)}),t({labelIds:[...e.labelIds??[],we.id]}),Z("")}}),X=we=>{const Ze=e.labelIds??[],Ot=Ze.includes(we)?Ze.filter(un=>un!==we):[...Ze,we];t({labelIds:Ot})},ie=we=>{if(!we||!H)return null;const Ze=H.find(Ot=>Ot.id===we);return(Ze==null?void 0:Ze.name)??we.slice(0,8)},pe=x.useMemo(()=>new Map((H??[]).map(we=>[we.id,we])),[H]),ke=we=>{if(!we)return(we==null?void 0:we.slice(0,8))??"None";const Ze=fe.find(Ot=>Ot.id===we);return(Ze==null?void 0:Ze.name)??we.slice(0,8)},Ce=x.useMemo(()=>new Map((xe??[]).map(we=>[we.id,we])),[xe]),$e=x.useCallback(we=>{var Ze;return((Ze=we.project)==null?void 0:Ze.name)??(we.projectId?ke(we.projectId):null)},[fe]),Ue=we=>we.identifier??we.id.slice(0,8),he=x.useCallback((we,Ze)=>{const Ot=Ze.trim().toLowerCase();return Ot?`${we.identifier??""} ${we.title}`.toLowerCase().includes(Ot):!0},[]),We=x.useCallback((we,Ze)=>{var Jn;let Ot=we.parentId;const un=new Set;for(;Ot;){if(Ot===Ze)return!0;if(un.has(Ot))return!1;un.add(Ot),Ot=((Jn=Ce.get(Ot))==null?void 0:Jn.parentId)??null}return!1},[Ce]),ct=e.parentId?(($t=e.ancestors)==null?void 0:$t[0])??Ce.get(e.parentId)??null:null,Pe=x.useMemo(()=>(r??[]).slice(0,5),[r]),Ae=()=>{O(!1),z(!1),a({parentId:e.id,parentIssue:{id:e.id,identifier:e.identifier,title:e.title},...e.projectId?{projectId:e.projectId}:{}})},oe=nt({mutationFn:we=>ln.update(we.id,{parentId:e.id}),onSuccess:async(we,Ze)=>{z(!1),Q(""),await l.invalidateQueries({queryKey:q.issues.detail(e.id)}),await l.invalidateQueries({queryKey:q.issues.detail(we.id)}),we.identifier&&await l.invalidateQueries({queryKey:q.issues.detail(we.identifier)}),c&&(await l.invalidateQueries({queryKey:q.issues.list(c)}),await l.invalidateQueries({queryKey:q.issues.children(c,e.id)}),Ze.parentId&&await l.invalidateQueries({queryKey:q.issues.children(c,Ze.parentId)}))},onError:we=>{o({title:we instanceof Error?we.message:"Failed to add existing issue",tone:"error"})}}),D=x.useMemo(()=>(xe??[]).filter(we=>we.id!==e.id).filter(we=>!We(we,e.id)).filter(we=>he(we,E)).slice(0,12),[xe,e.id,he,We,E]),J=x.useMemo(()=>(xe??[]).filter(we=>we.id!==e.id).filter(we=>we.parentId!==e.id).filter(we=>!(e.ancestors??[]).some(Ze=>Ze.id===we.id)).filter(we=>he(we,L)).slice(0,12),[xe,L,e.ancestors,e.id,he]),de=we=>{if(!we)return null;const Ze=(ae==null?void 0:ae.find(Ot=>Ot.id===we))??null;return Ze?Kv(Ze):`/projects/${we}`},ue=x.useMemo(()=>C7(),[u]),me=x.useMemo(()=>n6((H??[]).filter(we=>we.status!=="terminated"),ue),[H,ue]),K=e.assigneeAgentId?H==null?void 0:H.find(we=>we.id===e.assigneeAgentId):null,je=e.reviewerAgentId?H==null?void 0:H.find(we=>we.id===e.reviewerAgentId):null,Be=we=>Ol(we,V),Ve=Be(e.assigneeUserId),Me=Be(e.reviewerUserId),ht=Be(e.createdByUserId),ve=!!(e.reviewerAgentId&&e.reviewerAgentId===e.assigneeAgentId||e.reviewerUserId&&e.reviewerUserId===e.assigneeUserId),Le=(e.labels??[]).length>0?s.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[(e.labels??[]).slice(0,3).map(we=>s.jsx(T2,{label:we,size:"sm"},we.id)),(e.labels??[]).length>3&&s.jsxs("span",{className:"text-xs text-muted-foreground",children:["+",(e.labels??[]).length-3]})]}):s.jsxs(s.Fragment,{children:[s.jsx(wP,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-sm text-muted-foreground",children:"No labels"})]}),Ie=mp(F),at=x.useMemo(()=>(U??[]).filter(we=>Ie?we.name.toLowerCase().includes(Ie.toLowerCase()):!0),[U,Ie]),Je=x.useMemo(()=>Che(U??[],Ie),[U,Ie]),St=Ie.length>0&&at.length===0&&!Je,Pt=TB(Ie),_t=x.useCallback(()=>{!St||re.isPending||re.mutate({name:Ie,color:Pt})},[re,Pt,Ie,St]),Lt=s.jsxs(s.Fragment,{children:[s.jsx("input",{className:"w-full px-2 py-1.5 text-xs bg-transparent outline-none border-b border-border mb-1 placeholder:text-muted-foreground/50",placeholder:"Search labels...",value:F,onChange:we=>Z(we.target.value),onKeyDown:we=>{we.key!=="Enter"||!St||(we.preventDefault(),_t())},autoFocus:!n}),s.jsxs("div",{className:"max-h-44 overflow-y-auto overscroll-contain space-y-0.5",children:[at.map(we=>{const Ze=(e.labelIds??[]).includes(we.id);return s.jsxs("button",{className:G("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-left",Ze&&"bg-accent"),onClick:()=>X(we.id),children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{backgroundColor:we.color}}),s.jsx("span",{className:"truncate",children:we.name})]},we.id)}),St&&s.jsxs(s.Fragment,{children:[at.length>0?s.jsx("div",{className:"my-1 border-t border-border"}):null,s.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-left",disabled:re.isPending,onClick:_t,children:[s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-sm border border-border/70 text-muted-foreground",children:s.jsx(tr,{className:"h-2.5 w-2.5"})}),s.jsx("span",{className:"truncate",children:re.isPending?"Creating…":`Create label "${Ie}"`}),s.jsx("span",{className:"ml-auto h-2.5 w-2.5 shrink-0 rounded-full",style:{backgroundColor:Pt},"aria-hidden":"true"})]})]})]})]}),It=K?s.jsx(Ki,{kind:"agent",label:K.name,badgeLabel:Q2(K),agentIcon:K.icon,agentRole:K.role,layout:"stacked"}):Ve?s.jsx(Ki,{kind:"user",label:Ve}):s.jsx(Ki,{kind:"unassigned",label:"Unassigned",muted:!0}),Vt=s.jsxs(s.Fragment,{children:[s.jsx("input",{className:"w-full px-2 py-1.5 text-xs bg-transparent outline-none border-b border-border mb-1 placeholder:text-muted-foreground/50",placeholder:"Search assignees...",value:f,onChange:we=>h(we.target.value),autoFocus:!n}),s.jsxs("div",{ref:W,"data-testid":"issue-properties-assignee-scroll",className:"scrollbar-auto-hide max-h-60 overflow-y-auto overscroll-contain",children:[s.jsx("button",{className:G("flex min-w-0 items-center gap-2 w-full px-2 py-1.5 text-left text-xs rounded hover:bg-accent/50",!e.assigneeAgentId&&!e.assigneeUserId&&"bg-accent"),onClick:()=>{t({assigneeAgentId:null,assigneeUserId:null}),d(!1)},children:s.jsx(Ki,{kind:"unassigned",label:"No assignee"})}),V&&s.jsx("button",{className:G("flex min-w-0 items-center gap-2 w-full px-2 py-2 text-left text-xs rounded hover:bg-accent/50",e.assigneeUserId===V&&"bg-accent"),onClick:()=>{t({assigneeAgentId:null,assigneeUserId:V}),d(!1)},children:s.jsx(o$,{})}),e.createdByUserId&&e.createdByUserId!==V&&s.jsx("button",{className:G("flex min-w-0 items-center gap-2 w-full px-2 py-1.5 text-left text-xs rounded hover:bg-accent/50",e.assigneeUserId===e.createdByUserId&&"bg-accent"),onClick:()=>{t({assigneeAgentId:null,assigneeUserId:e.createdByUserId}),d(!1)},children:s.jsx(Ki,{kind:"user",label:ht?`Assign to ${ht}`:"Assign to requester"})}),me.filter(we=>{if(!f.trim())return!0;const Ze=f.toLowerCase();return`${rl(we)} ${we.name} ${we.role} ${we.title??""}`.toLowerCase().includes(Ze)}).map(we=>s.jsx("button",{className:G("flex min-w-0 items-center gap-2 w-full px-2 py-2 text-left text-xs rounded hover:bg-accent/50",we.id===e.assigneeAgentId&&"bg-accent"),onClick:()=>{h5(we.id),t({assigneeAgentId:we.id,assigneeUserId:null}),d(!1)},children:s.jsx(ip,{agent:we})},we.id))]})]}),Sn=je?s.jsx(Ki,{kind:"agent",label:je.name,badgeLabel:Q2(je),agentIcon:je.icon,agentRole:je.role,layout:"stacked"}):Me?s.jsx(Ki,{kind:"user",label:Me}):s.jsx(Ki,{kind:"unassigned",label:"No reviewer",muted:!0}),rt=s.jsxs(s.Fragment,{children:[s.jsx("input",{className:"w-full px-2 py-1.5 text-xs bg-transparent outline-none border-b border-border mb-1 placeholder:text-muted-foreground/50",placeholder:"Search reviewers...",value:v,onChange:we=>j(we.target.value),autoFocus:!n}),s.jsxs("div",{ref:$,"data-testid":"issue-properties-reviewer-scroll",className:"scrollbar-auto-hide max-h-60 overflow-y-auto overscroll-contain",children:[s.jsx("button",{className:G("flex min-w-0 items-center gap-2 w-full px-2 py-1.5 text-left text-xs rounded hover:bg-accent/50",!e.reviewerAgentId&&!e.reviewerUserId&&"bg-accent"),onClick:()=>{t({reviewerAgentId:null,reviewerUserId:null}),b(!1)},children:s.jsx(Ki,{kind:"unassigned",label:"No reviewer"})}),V&&s.jsx("button",{className:G("flex min-w-0 items-center gap-2 w-full px-2 py-2 text-left text-xs rounded hover:bg-accent/50",e.reviewerUserId===V&&"bg-accent"),onClick:()=>{t({reviewerAgentId:null,reviewerUserId:V}),b(!1)},children:s.jsx(o$,{})}),me.filter(we=>{if(!v.trim())return!0;const Ze=v.toLowerCase();return`${rl(we)} ${we.name} ${we.role} ${we.title??""}`.toLowerCase().includes(Ze)}).map(we=>s.jsx("button",{className:G("flex min-w-0 items-center gap-2 w-full px-2 py-2 text-left text-xs rounded hover:bg-accent/50",we.id===e.reviewerAgentId&&"bg-accent"),onClick:()=>{h5(we.id),t({reviewerAgentId:we.id,reviewerUserId:null}),b(!1)},children:s.jsx(ip,{agent:we})},we.id))]})]}),sn=e.projectId?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"shrink-0 h-3 w-3 rounded-sm",style:ic((Nn=fe.find(we=>we.id===e.projectId))==null?void 0:Nn.color)}),s.jsx("span",{className:"text-sm truncate",children:ke(e.projectId)})]}):s.jsxs(s.Fragment,{children:[s.jsx(Ep,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-sm text-muted-foreground",children:"No project"})]}),tn=s.jsxs(s.Fragment,{children:[s.jsx("input",{className:"w-full px-2 py-1.5 text-xs bg-transparent outline-none border-b border-border mb-1 placeholder:text-muted-foreground/50",placeholder:"Search projects...",value:N,onChange:we=>C(we.target.value),autoFocus:!n}),s.jsxs("div",{className:"max-h-48 overflow-y-auto overscroll-contain",children:[s.jsx("button",{className:G("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 whitespace-nowrap",!e.projectId&&"bg-accent"),onClick:()=>{t({projectId:null,projectWorkspaceId:null}),w(!1)},children:"No project"}),fe.filter(we=>{if(!N.trim())return!0;const Ze=N.toLowerCase();return we.name.toLowerCase().includes(Ze)}).map(we=>s.jsxs("button",{className:G("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 whitespace-nowrap",we.id===e.projectId&&"bg-accent"),onClick:()=>{t({projectId:we.id,projectWorkspaceId:M8t(we)}),w(!1)},children:[s.jsx("span",{className:"shrink-0 h-3 w-3 rounded-sm",style:ic(we.color)}),we.name]},we.id))]})]}),xn=ct?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"shrink-0 font-mono text-[11px] text-muted-foreground",children:Ue(ct)}),s.jsx("span",{className:"min-w-0 truncate text-sm",children:ct.title})]}):s.jsxs(s.Fragment,{children:[s.jsx(b3,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-sm text-muted-foreground",children:"No parent"})]}),Se=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border px-2 py-1.5",children:[s.jsx(na,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),s.jsx("input",{className:"min-w-0 flex-1 bg-transparent text-xs outline-none placeholder:text-muted-foreground/50",placeholder:"Search issues...",value:E,onChange:we=>T(we.target.value),autoFocus:!n})]}),s.jsxs("div",{className:"max-h-60 overflow-y-auto overscroll-contain p-1",children:[s.jsxs("button",{type:"button",className:G("flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",!e.parentId&&"bg-accent"),onClick:()=>{t({parentId:null}),_(!1),T("")},children:[s.jsx(b3,{className:"h-3.5 w-3.5 text-muted-foreground"}),"No parent"]}),D.length>0?D.map(we=>{const Ze=$e(we);return s.jsxs("button",{type:"button",className:G("grid w-full grid-cols-[auto_minmax(0,1fr)] items-center gap-x-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",we.id===e.parentId&&"bg-accent"),onClick:()=>{t({parentId:we.id}),_(!1),T("")},children:[s.jsx("span",{className:"font-mono text-[11px] text-muted-foreground",children:Ue(we)}),s.jsx("span",{className:"min-w-0 truncate",children:we.title}),Ze&&we.projectId!==e.projectId?s.jsx("span",{className:"col-start-2 min-w-0 truncate text-[11px] text-muted-foreground",children:Ze}):null]},we.id)}):s.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:"No matching issues."})]})]}),ye=P?s.jsxs("div",{className:G("shrink-0 rounded-md border border-border bg-popover p-1",n?"w-full":void 0),style:n?void 0:{width:"480px",maxWidth:"calc(100vw - 2rem)"},children:[s.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border px-2 py-1.5",children:[s.jsx(na,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),s.jsx("input",{className:"min-w-0 flex-1 bg-transparent text-xs outline-none placeholder:text-muted-foreground/50",placeholder:"Search existing issues...",value:L,onChange:we=>Q(we.target.value),autoFocus:!n})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto overscroll-contain py-1",children:J.length>0?J.map(we=>{const Ze=$e(we),Ot=we.parentId?Ce.get(we.parentId)??null:null;return s.jsxs("button",{type:"button",className:"grid w-full grid-cols-[auto_minmax(0,1fr)] items-center gap-x-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50 disabled:cursor-wait disabled:opacity-60",onClick:()=>oe.mutate(we),disabled:oe.isPending,children:[s.jsx("span",{className:"font-mono text-[11px] text-muted-foreground",children:Ue(we)}),s.jsx("span",{className:"min-w-0 truncate",children:we.title}),s.jsx("span",{className:"col-start-2 min-w-0 truncate text-[11px] text-muted-foreground",children:Ot?`Move from ${Ue(Ot)}`:Ze&&we.projectId!==e.projectId?Ze:"No parent"})]},we.id)}):s.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:"No matching issues."})})]}):null;return s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx(ff,{label:"Status",children:s.jsx(os,{status:e.status,onChange:we=>t({status:we}),showLabel:!0})}),s.jsx(ff,{label:"Priority",children:s.jsx(ya,{priority:e.priority,onChange:we=>t({priority:we}),showLabel:!0})}),s.jsx(Cy,{inline:n,label:"Labels",open:ee,onOpenChange:we=>{B(we),we||Z("")},triggerContent:Le,triggerClassName:"min-w-0 max-w-full",popoverClassName:"w-64",children:Lt}),s.jsx(Cy,{inline:n,label:"Assignee",open:u,onOpenChange:we=>{d(we),we||h("")},triggerContent:It,triggerClassName:"min-w-0 w-full max-w-full justify-start",popoverClassName:"w-[19rem]",popoverAlign:"start",rowAlign:"start",children:Vt}),s.jsx(Cy,{inline:n,label:"Reviewer",open:g,onOpenChange:we=>{b(we),we||j("")},triggerContent:Sn,triggerClassName:"min-w-0 w-full max-w-full justify-start",popoverClassName:"w-[19rem]",popoverAlign:"start",rowAlign:"start",extra:ve?s.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-muted-foreground",children:[s.jsx(Ad,{className:"h-3 w-3"}),"Same as assignee"]}):void 0,children:rt}),s.jsx(Cy,{inline:n,label:"Project",open:k,onOpenChange:we=>{w(we),we||C("")},triggerContent:sn,triggerClassName:"min-w-0 max-w-full",popoverClassName:"w-fit min-w-[11rem]",extra:e.projectId?s.jsx(yt,{to:de(e.projectId),className:"inline-flex items-center justify-center h-5 w-5 rounded hover:bg-accent/50 transition-colors text-muted-foreground hover:text-foreground",onClick:we=>we.stopPropagation(),children:s.jsx(p1,{className:"h-3 w-3"})}):void 0,children:tn}),s.jsx(Cy,{inline:n,label:"Parent issue",open:A,onOpenChange:we=>{_(we),we||T("")},triggerContent:xn,triggerClassName:"min-w-0 max-w-full",popoverClassName:"w-72",extra:ct?s.jsx(yt,{to:`/issues/${Ue(ct)}`,"aria-label":"Open parent issue",className:"inline-flex h-5 w-5 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",onClick:we=>we.stopPropagation(),children:s.jsx(p1,{className:"h-3 w-3"})}):void 0,children:Se}),r?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"w-20 shrink-0 text-xs text-muted-foreground",children:"Sub-issues"}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[s.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-1.5 rounded px-1 py-0.5 text-left transition-colors hover:bg-accent/50 disabled:pointer-events-none",onClick:()=>z(we=>!we),"aria-label":"Show sub-issue picker",children:[s.jsx(b3,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),s.jsx("span",{className:"rounded-sm border border-border px-1.5 py-0.5 text-[11px] leading-none text-muted-foreground",children:r.length})]}),s.jsxs(qn,{open:M,onOpenChange:O,children:[s.jsx(Wn,{asChild:!0,children:s.jsxs("button",{type:"button",className:"ml-auto inline-flex h-6 items-center gap-1 rounded border border-border px-1.5 text-[11px] text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",children:[s.jsx(tr,{className:"h-3 w-3"}),"Add"]})}),s.jsxs(Kn,{className:"w-44 p-1",align:"end",collisionPadding:16,children:[s.jsx("button",{type:"button",className:"w-full rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",onClick:Ae,children:"Create new sub-issue"}),s.jsx("button",{type:"button",className:"w-full rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",onClick:()=>{O(!1),z(!0)},children:"Add existing issue"})]})]})]})]}),s.jsxs("div",{className:"mt-1.5 min-w-0 space-y-1",children:[ye?s.jsx("div",{className:G(n?void 0:"flex justify-end"),children:ye}):null,s.jsxs("div",{className:G("min-w-0 space-y-1",n?"ml-0":"ml-[5.75rem]"),children:[Pe.length===0?s.jsx("button",{type:"button",className:"w-full rounded px-1 py-1 text-left text-xs text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",onClick:Ae,children:"No sub-issues."}):Pe.map(we=>{const Ze=we.identifier??we.id,Ot=we.identifier??we.id.slice(0,8);return s.jsxs(yt,{to:`/issues/${Ze}`,className:"grid max-w-full min-w-0 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-1.5 overflow-hidden rounded px-1 py-1 text-xs transition-colors hover:bg-accent/50",title:we.title,children:[s.jsx(os,{status:we.status}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:we.title}),s.jsx("span",{className:"min-w-0 max-w-[5.5rem] truncate font-mono text-[11px] text-muted-foreground",children:Ot})]},we.id)}),r.length>Pe.length?s.jsxs("p",{className:"px-1 text-[11px] text-muted-foreground",children:["+",r.length-Pe.length," more"]}):null]})]})]}):null,e.requestDepth>0&&s.jsx(ff,{label:"Depth",children:s.jsx("span",{className:"text-sm font-mono",children:e.requestDepth})})]}),s.jsx(Lc,{}),s.jsxs("div",{className:"space-y-1",children:[(e.createdByAgentId||e.createdByUserId)&&s.jsx(ff,{label:"Created by",children:e.createdByAgentId?s.jsx(yt,{to:`/agents/${e.createdByAgentId}`,className:"hover:underline",children:s.jsx(Za,{name:ie(e.createdByAgentId)??e.createdByAgentId.slice(0,8),icon:e.createdByAgentId?(_n=pe.get(e.createdByAgentId))==null?void 0:_n.icon:null,role:e.createdByAgentId?(Ee=pe.get(e.createdByAgentId))==null?void 0:Ee.role:null,size:"sm"})}):s.jsxs(s.Fragment,{children:[s.jsx(Hf,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-sm",children:ht??"User"})]})}),e.startedAt&&s.jsx(ff,{label:"Started",children:s.jsx("span",{className:"text-sm",children:Ha(e.startedAt)})}),e.completedAt&&s.jsx(ff,{label:"Completed",children:s.jsx("span",{className:"text-sm",children:Ha(e.completedAt)})}),s.jsx(ff,{label:"Created",children:s.jsx("span",{className:"text-sm",children:wi(e.createdAt)})}),s.jsx(ff,{label:"Updated",children:s.jsx("span",{className:"text-sm",children:I1(e.updatedAt)})})]})]})}function GR(e){return e?typeof e=="string"?e:e.toISOString():null}function R8t(e){return e==="queued"||e==="running"}function P7e({issueId:e,orgId:t}){const n=vn(),[r,i]=x.useState(new Set),{data:a}=Ne({queryKey:q.issues.liveRuns(e),queryFn:()=>xs.liveRunsForIssue(e),enabled:!!e,refetchInterval:3e3}),{data:o}=Ne({queryKey:q.issues.activeRun(e),queryFn:()=>xs.activeRunForIssue(e),enabled:!!e,refetchInterval:3e3}),l=x.useMemo(()=>{const g=new Map;for(const b of a??[])g.set(b.id,b);return o&&g.set(o.id,{id:o.id,status:o.status,invocationSource:o.invocationSource,triggerDetail:o.triggerDetail,startedAt:GR(o.startedAt),finishedAt:GR(o.finishedAt),createdAt:GR(o.createdAt)??new Date().toISOString(),agentId:o.agentId,agentName:o.agentName,agentRuntimeType:o.agentRuntimeType,issueId:e}),[...g.values()].sort((b,v)=>new Date(v.createdAt).getTime()-new Date(b.createdAt).getTime())},[o,e,a]),{transcriptByRun:c,hasOutputForRun:u}=o8({runs:l,orgId:t}),{data:d}=Ne({queryKey:q.agents.list(t??"__none__"),queryFn:()=>Bt.list(t),enabled:!!t&&l.length>0}),f=x.useMemo(()=>new Map((d??[]).map(g=>[g.id,g])),[d]),h=async g=>{i(b=>new Set(b).add(g));try{await xs.cancel(g),n.invalidateQueries({queryKey:q.issues.liveRuns(e)}),n.invalidateQueries({queryKey:q.issues.activeRun(e)})}finally{i(b=>{const v=new Set(b);return v.delete(g),v})}};return l.length===0?null:s.jsxs("div",{className:"overflow-hidden rounded-xl border border-cyan-500/25 bg-background/80 shadow-[0_18px_50px_rgba(6,182,212,0.08)]",children:[s.jsxs("div",{className:"border-b border-border/60 bg-cyan-500/[0.04] px-4 py-3",children:[s.jsx("div",{className:"text-xs font-semibold uppercase tracking-[0.18em] text-cyan-700 dark:text-cyan-300",children:"Live Runs"}),s.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"Streamed with the same transcript UI used on the full run detail page."})]}),s.jsx("div",{className:"divide-y divide-border/60",children:l.map(g=>{const b=R8t(g.status),v=c.get(g.id)??[],j=f.get(g.agentId)??null,k=WS(g.startedAt??g.createdAt,b?null:g.finishedAt);return s.jsxs("section",{className:"px-4 py-4",children:[s.jsxs("div",{className:"mb-3 flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx(yt,{to:`/agents/${g.agentId}`,className:"inline-flex hover:underline",children:j?s.jsx(Za,{name:j.name,icon:j.icon,role:j.role,size:"sm"}):s.jsx(Da,{name:g.agentName,size:"sm"})}),s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[s.jsx(yt,{to:`/agents/${g.agentId}/runs/${g.id}`,className:"inline-flex items-center rounded-full border border-border/70 bg-background/70 px-2 py-1 font-mono hover:border-cyan-500/30 hover:text-foreground",children:g.id.slice(0,8)}),s.jsx(er,{status:g.status}),s.jsx("span",{children:wi(g.startedAt??g.createdAt)}),k?s.jsx("span",{children:b?`Live for ${k}`:`Ran for ${k}`}):null]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[b&&s.jsxs("button",{onClick:()=>h(g.id),disabled:r.has(g.id),className:"inline-flex items-center gap-1 rounded-full border border-red-500/20 bg-red-500/[0.06] px-2.5 py-1 text-[11px] font-medium text-red-700 transition-colors hover:bg-red-500/[0.12] dark:text-red-300 disabled:opacity-50",children:[s.jsx(Xz,{className:"h-2.5 w-2.5",fill:"currentColor"}),r.has(g.id)?"Stopping…":"Stop"]}),s.jsxs(yt,{to:`/agents/${g.agentId}/runs/${g.id}`,className:"inline-flex items-center gap-1 rounded-full border border-border/70 bg-background/70 px-2.5 py-1 text-[11px] font-medium text-cyan-700 transition-colors hover:border-cyan-500/30 hover:text-cyan-600 dark:text-cyan-300",children:["Open run",s.jsx(Bc,{className:"h-3 w-3"})]})]})]}),s.jsx("div",{className:"max-h-[320px] overflow-y-auto pr-1",children:s.jsx(Qf,{entries:v,density:"compact",limit:8,streaming:b,collapseStdout:!0,presentation:"chat",emptyMessage:u(g.id)?"Waiting for transcript parsing...":"Waiting for run output..."})})]},g.id)})})]})}function PC({...e}){return s.jsx(pS,{"data-slot":"sheet",...e})}function O8t({...e}){return s.jsx(zle,{"data-slot":"sheet-trigger",...e})}function P8t({...e}){return s.jsx(gS,{"data-slot":"sheet-portal",...e})}function D8t({className:e,...t}){return s.jsx(xS,{"data-slot":"sheet-overlay",className:G("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...t})}function DC({className:e,children:t,side:n="right",showCloseButton:r=!0,...i}){return s.jsxs(P8t,{children:[s.jsx(D8t,{}),s.jsxs(bS,{"data-slot":"sheet-content",className:G("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500",n==="right"&&"data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm",n==="left"&&"data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm",n==="top"&&"data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b",n==="bottom"&&"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t",e),...i,children:[t,r&&s.jsxs(J5,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none",children:[s.jsx(Gs,{className:"size-4"}),s.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function LC({className:e,...t}){return s.jsx("div",{"data-slot":"sheet-header",className:G("flex flex-col gap-1.5 p-4",e),...t})}function L8t({className:e,...t}){return s.jsx("div",{"data-slot":"sheet-footer",className:G("mt-auto flex flex-col gap-2 p-4",e),...t})}function $C({className:e,...t}){return s.jsx(MF,{"data-slot":"sheet-title",className:G("text-foreground font-semibold",e),...t})}function $8t({className:e,...t}){return s.jsx(Ble,{"data-slot":"sheet-description",className:G("text-muted-foreground text-sm",e),...t})}function kH({className:e,children:t,...n}){return s.jsxs(kEe,{"data-slot":"scroll-area",className:G("relative flex flex-col overflow-hidden",e),...n,children:[s.jsx(jEe,{"data-slot":"scroll-area-viewport",className:"flex-1 min-h-0 w-full focus-visible:ring-ring/50 rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1",children:t}),s.jsx(F8t,{}),s.jsx(NEe,{})]})}function F8t({className:e,orientation:t="vertical",...n}){return s.jsx(Iue,{"data-slot":"scroll-area-scrollbar",orientation:t,className:G("flex touch-none p-px transition-colors select-none",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent",e),...n,children:s.jsx(Pue,{"data-slot":"scroll-area-thumb",className:"bg-border relative flex-1 rounded-full"})})}function z8t(e){const t=new URLSearchParams({issueId:e.id});return e.projectId&&t.set("projectId",e.projectId),e.assigneeAgentId&&t.set("agentId",e.assigneeAgentId),`/messenger/chat?${t.toString()}`}const B8t=new Set(["identifier","issueIdentifier","_previous","source","reopened","reopenedFrom","normalizedFromStatus","normalizedReason"]),xie={"issue.created":"created the issue","issue.updated":"updated the issue","issue.checked_out":"checked out the issue","issue.released":"released the issue","issue.code_committed":"committed code","issue.passive_followup_queued":"queued passive follow-up","issue.closure_needs_operator_review":"needs operator review for close-out","issue.review_decision_recorded":"recorded a reviewer decision","issue.human_intervention_required":"requested human intervention","issue.attachment_added":"added an attachment","issue.attachment_removed":"removed an attachment","issue.approval_linked":"linked an approval","issue.approval_unlinked":"unlinked an approval","issue.document_created":"created a document","issue.document_updated":"updated a document","issue.document_deleted":"deleted a document","issue.deleted":"deleted the issue","agent.created":"created an agent","agent.updated":"updated the agent","agent.paused":"paused the agent","agent.resumed":"resumed the agent","agent.terminated":"terminated the agent","heartbeat.invoked":"invoked a heartbeat","heartbeat.cancelled":"cancelled a heartbeat","approval.created":"requested approval","approval.approved":"approved","approval.rejected":"rejected"};function Bg(e){return typeof e!="string"?String(e??"none"):e.replace(/_/g," ")}function U8t(e,t){return Ol(e,t)??e.slice(0,8)}function ak(e,t,n){var r;return e?typeof e.agentId=="string"&&e.agentId?((r=t.get(e.agentId))==null?void 0:r.name)??e.agentId.slice(0,8):typeof e.userId=="string"&&e.userId?U8t(e.userId,n):null:null}function bie(e){return e.toLabel?e.fromLabel?`${e.changedVerb} from ${e.fromLabel} to ${e.toLabel}`:`${e.assignedVerb} to ${e.toLabel}`:e.fromLabel?`${e.clearedVerb} ${e.fromLabel}`:e.unassignedVerb}function x0(e){return typeof e!="object"||e===null||Array.isArray(e)?null:e}function q8t(e){return e?Object.keys(e).filter(t=>!B8t.has(t)):[]}function K8t(e){if(e.action!=="issue.updated")return!1;const t=q8t(x0(e.details));return t.length===1&&t[0]==="description"}function H8t(e){return!(e.action==="issue.comment_added"||e.action==="issue.document_updated"||K8t(e))}function Sy(e,...t){if(!e)return 0;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return 0}function yie(e,...t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r.trim()}return null}const V8t=["backlog","todo","in_progress","in_review","done","cancelled","blocked"],W8t="image/*,application/pdf,text/plain,text/markdown,application/json,text/csv,text/html,.md,.markdown",D7e="rudder.linear",Z8t="linear-issue-tab",vie="issue-link";function G8t(e){return e.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function wie(e){return e.pluginKey===D7e&&e.id===Z8t}function kie(e){const t=e.name.toLowerCase();return t.endsWith(".md")||t.endsWith(".markdown")||e.type==="text/markdown"}function Q8t(e){return e.replace(/\.[^.]+$/,"")}function Y8t(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"document"}function J8t(e){return e.split(/[-_ ]+/g).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function X8t(e){var t;return((t=e.displayLabel)==null?void 0:t.trim())||e.name}function ewt(e){const t=e.split("/").filter(Boolean);return t.pop(),t.join("/")}function twt({orgId:e,open:t,onOpenChange:n,onAttach:r,attaching:i,error:a}){var g;const[o,l]=x.useState(""),[c,u]=x.useState(null);x.useEffect(()=>{t&&(l(""),u(null))},[t,e]);const d=Ne({queryKey:q.organizations.workspaceFiles(e??"__none__",o),queryFn:()=>Xn.listWorkspaceFiles(e,o),enabled:t&&!!e,refetchOnWindowFocus:!1}),f=((g=d.data)==null?void 0:g.entries)??[],h=o.length>0;return s.jsx(Ws,{open:t,onOpenChange:n,children:s.jsxs(ii,{className:"sm:max-w-xl",children:[s.jsxs(_a,{children:[s.jsx(Wi,{className:"text-base",children:"Attach from Workspaces"}),s.jsx(Va,{children:"Choose a file to copy into this issue's attachments."})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex min-h-8 items-center gap-2 rounded-md border border-border bg-muted/20 px-2 text-xs text-muted-foreground",children:[s.jsx("span",{className:"font-medium text-foreground",children:"/"}),s.jsx("span",{className:"truncate",children:o||"workspace"})]}),s.jsx("div",{className:"h-[320px] overflow-hidden rounded-md border border-border",children:d.isLoading?s.jsxs("div",{className:"flex h-full items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(yr,{className:"h-4 w-4 animate-spin"}),"Loading files..."]}):d.error?s.jsx("div",{className:"p-3 text-sm text-destructive",children:d.error instanceof Error?d.error.message:"Could not load workspace files"}):f.length===0&&!h?s.jsx("div",{className:"p-3 text-sm text-muted-foreground",children:"No workspace files available."}):s.jsx(kH,{className:"h-full",children:s.jsxs("div",{className:"space-y-0.5 p-1.5",children:[h?s.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",onClick:()=>{l(ewt(o)),u(null)},children:[s.jsx(Ls,{className:"h-3.5 w-3.5 rotate-180"}),"Parent folder"]}):null,f.map(b=>{const v=X8t(b),j=c===b.path;return b.isDirectory?s.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-foreground transition-colors hover:bg-accent/60",onClick:()=>{l(b.path),u(null)},children:[s.jsx(dc,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),s.jsx("span",{className:"truncate font-medium",children:v})]},b.path):s.jsxs("button",{type:"button",className:G("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",j?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),onClick:()=>u(b.path),onDoubleClick:()=>void r(b.path),children:[s.jsx(QS,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:v})]},b.path)})]})})}),c?s.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:["Selected: ",c]}):null,a?s.jsx("p",{className:"text-xs text-destructive",children:a}):null]}),s.jsxs(nl,{children:[s.jsx(ce,{type:"button",variant:"ghost",onClick:()=>n(!1),disabled:i,children:"Cancel"}),s.jsxs(ce,{type:"button",onClick:()=>c?void r(c):void 0,disabled:!c||i,children:[i?s.jsx(yr,{className:"h-3.5 w-3.5 animate-spin"}):s.jsx(b1,{className:"h-3.5 w-3.5"}),"Attach"]})]})]})})}function nwt(e,t,n,r){if(e==="issue.code_committed"&&t){const i=typeof t.shortSha=="string"?t.shortSha:null,a=typeof t.subject=="string"?t.subject:null;if(i&&a)return`committed ${i}: ${a}`;if(i)return`committed ${i}`}if(e==="issue.updated"&&t){const i=t._previous??{},a=[];if(t.status!==void 0){const o=i.status;a.push(o?`changed the status from ${Bg(o)} to ${Bg(t.status)}`:`changed the status to ${Bg(t.status)}`)}if(t.priority!==void 0){const o=i.priority;a.push(o?`changed the priority from ${Lo(Bg(o))} to ${Lo(Bg(t.priority))}`:`changed the priority to ${Lo(Bg(t.priority))}`)}if(t.assigneeAgentId!==void 0||t.assigneeUserId!==void 0){const o=x0(i.assignee),l=ak(o??{agentId:i.assigneeAgentId,userId:i.assigneeUserId},n,r),c=ak({agentId:t.assigneeAgentId,userId:t.assigneeUserId},n,r);a.push(bie({toLabel:c,fromLabel:l,assignedVerb:"assigned the issue",changedVerb:"reassigned the issue",clearedVerb:"unassigned the issue from",unassignedVerb:"unassigned the issue"}))}if(t.reviewerAgentId!==void 0||t.reviewerUserId!==void 0){const o=x0(i.reviewer),l=ak(o??{agentId:i.reviewerAgentId,userId:i.reviewerUserId},n,r),c=ak({agentId:t.reviewerAgentId,userId:t.reviewerUserId},n,r);a.push(bie({toLabel:c,fromLabel:l,assignedVerb:"set the reviewer",changedVerb:"changed the reviewer",clearedVerb:"cleared the reviewer from",unassignedVerb:"cleared the reviewer"}))}if(t.title!==void 0&&a.push("updated the title"),t.description!==void 0&&a.push("updated the description"),a.length>0)return a.join(", ")}if((e==="issue.document_created"||e==="issue.document_updated"||e==="issue.document_deleted")&&t){const i=typeof t.key=="string"?t.key:"document",a=typeof t.title=="string"&&t.title?` (${t.title})`:"";return`${xie[e]??e} ${i}${a}`}if(e==="issue.passive_followup_queued"&&t){const i=typeof t.attempt=="number"?t.attempt:null,a=typeof t.maxAttempts=="number"?t.maxAttempts:null,o=typeof t.followupRunId=="string"?t.followupRunId:null;return`queued passive follow-up${i&&a?` (${i}/${a})`:""}${o?` as run ${o.slice(0,8)}`:""}`}if(e==="issue.closure_needs_operator_review"&&t){const i=typeof t.attempts=="number"?t.attempts:null;return i?`stopped passive follow-up after ${i} attempts; operator review needed`:"stopped passive follow-up; operator review needed"}if(e==="issue.review_decision_recorded"&&t){const i=typeof t.decision=="string"?Bg(t.decision):"unknown";return t.outcome==="human_handoff"||t.operatorActionRequired===!0?"confirmed blocker; operator handoff needed":`recorded reviewer decision: ${i}`}return xie[e]??e.replace(/[._]/g," ")}function rwt(e){const t=x0(e.details);return(typeof(t==null?void 0:t.conversationTitle)=="string"?t.conversationTitle.trim():"")||`Chat ${e.entityId.slice(0,8)}`}function swt(e,t,n){const r=x0(e.details);if(e.entityType==="chat"){const i=`/chat/${e.entityId}`,a=rwt(e),o=s.jsx(yt,{to:i,className:"underline underline-offset-4 hover:text-foreground",children:a});if(e.action==="chat.issue_converted")return s.jsxs(s.Fragment,{children:["created this issue from ",o]});if(e.action==="chat.context_linked")return s.jsxs(s.Fragment,{children:["linked this issue in ",o]});if(e.action==="chat.created")return s.jsxs(s.Fragment,{children:["started ",o," with this issue linked"]})}if(e.action==="issue.approval_linked"||e.action==="issue.approval_unlinked"){const i=typeof(r==null?void 0:r.approvalId)=="string"?r.approvalId:null;if(i){const a=e.action==="issue.approval_linked"?"linked":"unlinked";return s.jsxs(s.Fragment,{children:[a," ",s.jsx(yt,{to:`/messenger/approvals/${i}`,className:"underline underline-offset-4 hover:text-foreground",children:"an approval"})]})}}return nwt(e.action,r,t,n)}function iwt(e){if(e.key!=="Escape"||e.defaultPrevented||e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)return!1;const t=e.target instanceof HTMLElement?e.target:null;if(t){const n=t.closest("input, textarea, select, [contenteditable='true'], [contenteditable='plaintext-only']");if(t.isContentEditable||n){const r=t.closest("[data-issue-detail-escape-back='empty']"),i=t.isContentEditable||!!t.closest("[contenteditable='true'], [contenteditable='plaintext-only']");if(!r||!i)return!1}}return!(typeof document<"u"&&(document.querySelector("[data-issue-find-ui]")||document.querySelector("[role='dialog']")||document.querySelector("[data-radix-popper-content-wrapper]")))}function awt(e){return!(e.key!=="Escape"||e.defaultPrevented||e.metaKey||e.ctrlKey||e.altKey||e.shiftKey||typeof document<"u"&&(document.querySelector("[role='dialog']")||document.querySelector("[data-radix-popper-content-wrapper]")))}function owt(){var t;if(typeof window>"u")return!1;const e=(t=window.history.state)==null?void 0:t.idx;return typeof e=="number"&&e>0}function lwt({evt:e,agentMap:t,currentBoardUserId:n,operatorDisplayName:r}){const i=e.actorId;if(e.actorType==="agent"){const a=t.get(i);return s.jsx(Za,{name:(a==null?void 0:a.name)??i.slice(0,8),icon:a==null?void 0:a.icon,role:a==null?void 0:a.role,size:"sm"})}return s.jsx(Da,{name:a8(e.actorType,i,n,r),size:"sm"})}function cwt({evt:e,agentMap:t,currentBoardUserId:n,operatorDisplayName:r}){return s.jsxs("div",{className:"flex items-center gap-1.5 rounded-sm px-1 py-0.5 text-xs text-muted-foreground",children:[s.jsx(lwt,{evt:e,agentMap:t,currentBoardUserId:n,operatorDisplayName:r}),s.jsx("span",{className:"min-w-0",children:swt(e,t,n)}),s.jsx("span",{className:"ml-auto shrink-0",children:js(e.createdAt)})]})}function uwt({data:e}){var h,g,b;const t=e.latestIssue,n=e.link,r=(t==null?void 0:t.identifier)??n.linearIdentifier,i=(t==null?void 0:t.title)??n.linearTitle,a=(t==null?void 0:t.url)??n.linearUrl,o=((h=t==null?void 0:t.description)==null?void 0:h.trim())??"",l=(t==null?void 0:t.team.name)??n.teamName,c=(t==null?void 0:t.state.name)??n.stateName,u=((g=t==null?void 0:t.project)==null?void 0:g.name)??n.projectName,d=((b=t==null?void 0:t.assignee)==null?void 0:b.name)??null,f=(t==null?void 0:t.updatedAt)??n.updatedAt;return s.jsxs("section",{className:"rounded-lg border border-border bg-card/70 p-3 text-sm","data-testid":"issue-activity-linear-link",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Linked Linear issue"}),s.jsx("span",{className:"rounded-full border border-border bg-muted/40 px-2 py-0.5 font-mono text-[11px] text-muted-foreground",children:r})]}),s.jsx("div",{className:"font-medium text-foreground",children:i}),s.jsxs("div",{className:"flex flex-wrap gap-1.5 text-[11px] text-muted-foreground",children:[s.jsx("span",{className:"rounded-full border border-border bg-background/70 px-2 py-0.5",children:l}),s.jsx("span",{className:"rounded-full border border-border bg-background/70 px-2 py-0.5",children:c}),u?s.jsx("span",{className:"rounded-full border border-border bg-background/70 px-2 py-0.5",children:u}):null,d?s.jsx("span",{className:"rounded-full border border-border bg-background/70 px-2 py-0.5",children:d}):null,s.jsxs("span",{className:"rounded-full border border-border bg-background/70 px-2 py-0.5",children:["Updated ",js(f)]}),s.jsxs("span",{className:"rounded-full border border-border bg-background/70 px-2 py-0.5",children:["Imported ",js(n.importedAt)]})]})]}),s.jsxs("a",{href:a,target:"_blank",rel:"noreferrer",className:"inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",children:["Open in Linear",s.jsx(Bc,{className:"h-3 w-3"})]})]}),e.staleReason?s.jsx("div",{className:"mt-3 rounded-md border border-amber-500/30 bg-amber-500/10 px-2 py-1.5 text-xs text-amber-700 dark:text-amber-200",children:e.staleReason}):null,o?s.jsx("p",{className:"mt-3 line-clamp-4 whitespace-pre-wrap text-xs leading-5 text-muted-foreground",children:o}):null]})}function jie({summary:e}){return!e.hasCost&&!e.hasTokens?null:s.jsxs("section",{className:"rounded-lg border border-border bg-background/80 p-3",children:[s.jsx("div",{className:"mb-2 text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Cost"}),s.jsxs("div",{className:"space-y-1.5 text-xs text-muted-foreground tabular-nums",children:[e.hasCost?s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{children:"Spend"}),s.jsxs("span",{className:"font-medium text-foreground",children:["$",e.cost.toFixed(4)]})]}):null,e.hasTokens?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{children:"Total tokens"}),s.jsx("span",{className:"font-medium text-foreground",children:rr(e.totalTokens)})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{children:"Input"}),s.jsx("span",{children:rr(e.input)})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{children:"Output"}),s.jsx("span",{children:rr(e.output)})]}),e.cached>0?s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{children:"Cached"}),s.jsx("span",{children:rr(e.cached)})]}):null]}):null]})]})}function dwt(){var fl,mo,$i,Kc;const{issueId:e}=ci(),{organizations:t,selectedOrganizationId:n,selectedOrganization:r}=wn(),{setBreadcrumbs:i}=zr(),a=vn(),o=Ir(),l=Mn(),c=Eht(),{pushToast:u}=_r(),d=i8(),[f,h]=x.useState(!1),[g,b]=x.useState(!1),[v,j]=x.useState(!1),[k,w]=x.useState(!1),[N,C]=x.useState(!1),[A,_]=x.useState(""),[E,T]=x.useState(!1),[M,O]=x.useState(""),[P,z]=x.useState(null),[L,Q]=x.useState(null),[ee,B]=x.useState(null),[F,Z]=x.useState(!1),[W,$]=x.useState(!1),[Y,V]=x.useState(null),H=x.useRef(null),ae=x.useRef(null),le=x.useRef(null),fe=x.useRef(null),{data:U,isLoading:xe,error:re}=Ne({queryKey:q.issues.detail(e),queryFn:()=>ln.get(e),enabled:!!e}),X=(U==null?void 0:U.orgId)??n;x.useEffect(()=>{V(null),le.current&&(clearTimeout(le.current),le.current=null)},[e]),x.useEffect(()=>()=>{le.current&&clearTimeout(le.current)},[]);const ie=x.useCallback(Te=>{le.current&&(clearTimeout(le.current),le.current=null),V({target:Te,phase:"open"})},[]),pe=x.useCallback(()=>{V(Te=>!Te||Te.phase==="closing"?Te:{...Te,phase:"closing"}),le.current&&clearTimeout(le.current),le.current=setTimeout(()=>{V(null),le.current=null},200)},[]);x.useEffect(()=>{!(U!=null&&U.orgId)||!U.id||cB(U.orgId,U.id,s3(U.orgId))},[U==null?void 0:U.id,U==null?void 0:U.orgId]);const{data:ke}=Ne({queryKey:q.issues.comments(e),queryFn:()=>ln.listComments(e),enabled:!!e}),{data:Ce}=Ne({queryKey:q.issues.activity(e),queryFn:()=>l1.forIssue(e),enabled:!!e}),{data:$e}=Ne({queryKey:q.issues.runs(e),queryFn:()=>l1.runsForIssue(e),enabled:!!e,refetchInterval:5e3}),{data:Ue}=Ne({queryKey:q.issues.attachments(e),queryFn:()=>ln.listAttachments(e),enabled:!!e}),{data:he}=Ne({queryKey:q.issues.liveRuns(e),queryFn:()=>xs.liveRunsForIssue(e),enabled:!!e,refetchInterval:3e3}),{data:We}=Ne({queryKey:q.issues.activeRun(e),queryFn:()=>xs.activeRunForIssue(e),enabled:!!e,refetchInterval:3e3}),ct=(he??[]).length>0||!!We,Pe=x.useMemo(()=>EHe(l.state)??{label:"Issues",href:"/issues"},[l.state]),Ae=(U==null?void 0:U.ancestors)??[],oe=x.useMemo(()=>{const Te=(U==null?void 0:U.title)??e??"Issue";return[Pe,...[...Ae].reverse().map(De=>({label:De.title,href:`/issues/${De.identifier??De.id}`})),{label:Te,href:null}]},[Ae,U==null?void 0:U.title,e,Pe]),D=x.useMemo(()=>{const Te=new Set;for(const De of he??[])Te.add(De.id);return We&&Te.add(We.id),Te.size===0?$e??[]:($e??[]).filter(De=>!Te.has(De.runId))},[$e,he,We]),{data:J}=Ne({queryKey:q.issues.list(X??"__none__"),queryFn:()=>ln.list(X),enabled:!!X}),{data:de=[]}=Ne({queryKey:q.issues.children(X??"__none__",(U==null?void 0:U.id)??"__none__"),queryFn:()=>ln.list(X,{parentId:U.id}),enabled:!!X&&!!(U!=null&&U.id)}),{data:ue}=Ne({queryKey:q.agents.list(X??"__none__"),queryFn:()=>Bt.list(X),enabled:!!X}),{data:me}=Ne({queryKey:q.organizationSkills.list(X??"__none__"),queryFn:()=>Co.list(X),enabled:!!X&&!!(U!=null&&U.assigneeAgentId)}),{data:K}=Ne({queryKey:q.agents.skills((U==null?void 0:U.assigneeAgentId)??"__none__"),queryFn:()=>Bt.skills(U.assigneeAgentId,X),enabled:!!X&&!!(U!=null&&U.assigneeAgentId)}),{data:je}=Ne({queryKey:q.auth.session,queryFn:()=>Di.getSession()}),{data:Be}=Ne({queryKey:q.projects.list(X??"__none__"),queryFn:()=>ws.list(X),enabled:!!X}),{data:Ve}=Ne({queryKey:q.access.currentBoardAccess,queryFn:()=>Vi.getCurrentBoardAccess(),enabled:!!e}),Me=((fl=je==null?void 0:je.user)==null?void 0:fl.id)??((mo=je==null?void 0:je.session)==null?void 0:mo.userId)??null,ht=(($i=Ve==null?void 0:Ve.user)==null?void 0:$i.id)??(Ve==null?void 0:Ve.userId)??Me,ve=t.find(Te=>Te.id===X)??r,{orderedProjects:Le}=j7({projects:Be??[],orgId:X,userId:Me}),{slots:Ie}=d4({slotTypes:["detailTab"],entityType:"issue",enabled:!!X}),at=x.useMemo(()=>Ie.filter(Te=>!wie(Te)).map(Te=>({value:`plugin:${Te.pluginKey}:${Te.id}`,label:Te.displayName,slot:Te})),[Ie]),Je=Ie.find(Te=>wie(Te))??null,{data:St}=Ne({queryKey:["plugins",D7e,vie,X??"__none__",(U==null?void 0:U.id)??e??"__none__",(Je==null?void 0:Je.pluginId)??"__none__"],queryFn:async()=>(await _s.bridgeGetData(Je.pluginId,vie,{orgId:X,issueId:U.id},X)).data,enabled:!!(X&&(U!=null&&U.id)&&(Je!=null&&Je.pluginId))}),Pt=x.useMemo(()=>{const Te=new Map;for(const De of ue??[])Te.set(De.id,De);return Te},[ue]),_t=x.useMemo(()=>new Map((Be??[]).map(Te=>[Te.id,Te])),[Be]),Lt=U!=null&&U.assigneeAgentId?Pt.get(U.assigneeAgentId)??null:null,It=x.useMemo(()=>N7({agent:Lt,orgUrlKey:(ve==null?void 0:ve.urlKey)??"organization",organizationSkills:me,skillSnapshot:K}),[me,K,Lt,ve==null?void 0:ve.urlKey]),Vt=x.useMemo(()=>{const Te=[],De=[...ue??[]].filter(vt=>vt.status!=="terminated").sort((vt,Cn)=>vt.name.localeCompare(Cn.name));for(const vt of De)Te.push({id:`agent:${vt.id}`,name:rl(vt),kind:"agent",agentId:vt.id,agentIcon:vt.icon,agentRole:vt.role});for(const vt of Le)Te.push({id:`project:${vt.id}`,name:vt.name,kind:"project",projectId:vt.id,projectColor:vt.color});for(const vt of J??[]){if(vt.id===(U==null?void 0:U.id))continue;const Cn=vt.projectId?_t.get(vt.projectId)??vt.project??null:vt.project??null,mr=vt.assigneeAgentId?Pt.get(vt.assigneeAgentId)??null:null,Yi=vt.assigneeAgentId?(mr==null?void 0:mr.name)??vt.assigneeAgentId.slice(0,8):Ol(vt.assigneeUserId,Me);Te.push({id:`issue:${vt.id}`,name:vt.identifier?`${vt.identifier} ${vt.title}`:vt.title,kind:"issue",searchText:[vt.identifier,vt.title,vt.status,Cn==null?void 0:Cn.name,Yi].filter(Boolean).join(" "),issueId:vt.id,issueIdentifier:vt.identifier,issueStatus:vt.status,issueProjectName:(Cn==null?void 0:Cn.name)??null,issueProjectColor:(Cn==null?void 0:Cn.color)??null,issueAssigneeName:Yi,issueAssigneeIcon:(mr==null?void 0:mr.icon)??null,issueAssigneeRole:(mr==null?void 0:mr.role)??null})}return Te.push(...It),Te},[Pt,ue,J,Me,U==null?void 0:U.id,Le,_t,It]),Sn=x.useMemo(()=>[...de].sort((Te,De)=>new Date(Te.createdAt).getTime()-new Date(De.createdAt).getTime()),[de]),rt=x.useMemo(()=>new Map((J??[]).map(Te=>[Te.id,Te])),[J]),sn=x.useMemo(()=>{if(!U)return[];const Te=M.trim().toLowerCase();return(J??[]).filter(De=>De.id!==U.id).filter(De=>De.parentId!==U.id).filter(De=>!(U.ancestors??[]).some(vt=>vt.id===De.id)).filter(De=>Te?`${De.identifier??""} ${De.title}`.toLowerCase().includes(Te):!0).slice(0,12)},[J,M,U]),tn=x.useMemo(()=>{const Te=new Map,De=new Map;for(const vt of $e??[])De.set(vt.runId,vt.agentId);for(const vt of Ce??[]){if(vt.action!=="issue.comment_added"||!vt.runId)continue;const Cn=vt.details??{},mr=typeof Cn.commentId=="string"?Cn.commentId:null;!mr||Te.has(mr)||Te.set(mr,{runId:vt.runId,runAgentId:vt.agentId??De.get(vt.runId)??null})}return(ke??[]).map(vt=>{const Cn=Te.get(vt.id);return Cn?{...vt,...Cn}:vt})},[Ce,ke,$e]),xn=x.useMemo(()=>{let Te=0,De=0,vt=0,Cn=0,mr=!1,Yi=!1;for(const ho of $e??[]){const Ye=x0(ho.usageJson),Nt=x0(ho.resultJson),nn=Sy(Ye,"inputTokens","input_tokens"),cr=Sy(Ye,"outputTokens","output_tokens"),ai=Sy(Ye,"cachedInputTokens","cached_input_tokens")+Sy(Ye,"cache_read_input_tokens")+Sy(Ye,"cache_creation_input_tokens"),Hc=Nl({provider:yie(Ye,"provider")??yie(Nt,"provider"),inputTokens:nn,cachedInputTokens:ai,outputTokens:cr}),Vc=hme(Ye,Nt);Vc>0&&(mr=!0),nn+cr+ai>0&&(Yi=!0),Te+=Hc.promptTokens,De+=cr,vt+=ai,Cn+=Vc}return{input:Te,output:De,cached:vt,cost:Cn,totalTokens:Te+De,hasCost:mr,hasTokens:Yi}},[$e]),Se=x.useMemo(()=>{var De;const Te=[];St!=null&&St.linked&&Te.push({id:"linear-linked-issue",createdAt:((De=St.latestIssue)==null?void 0:De.updatedAt)??St.link.updatedAt??St.link.importedAt,node:s.jsx(uwt,{data:St})});for(const vt of Ce??[])H8t(vt)&&Te.push({id:vt.id,createdAt:vt.createdAt,node:s.jsx(cwt,{evt:vt,agentMap:Pt,currentBoardUserId:ht,operatorDisplayName:d})});return Te},[Ce,Pt,ht,St,d]),ye=()=>{const Te=(U==null?void 0:U.orgId)??X??n;a.invalidateQueries({queryKey:q.issues.detail(e)}),a.invalidateQueries({queryKey:q.issues.activity(e)}),a.invalidateQueries({queryKey:q.issues.runs(e)}),a.invalidateQueries({queryKey:q.issues.approvals(e)}),a.invalidateQueries({queryKey:q.issues.attachments(e)}),a.invalidateQueries({queryKey:q.issues.documents(e)}),a.invalidateQueries({queryKey:q.issues.liveRuns(e)}),a.invalidateQueries({queryKey:q.issues.activeRun(e)}),U!=null&&U.id&&Te&&a.invalidateQueries({queryKey:q.issues.children(Te,U.id)}),Te&&(a.invalidateQueries({queryKey:q.issues.list(Te)}),a.invalidateQueries({queryKey:q.issues.listTouchedByMe(Te)}),a.invalidateQueries({queryKey:q.issues.listUnreadTouchedByMe(Te)}),a.invalidateQueries({queryKey:q.sidebarBadges(Te)}))},st=nt({mutationFn:Te=>ln.markRead(Te),onSuccess:()=>{const Te=(U==null?void 0:U.orgId)??X??n;Te&&(a.invalidateQueries({queryKey:q.issues.listTouchedByMe(Te)}),a.invalidateQueries({queryKey:q.issues.listUnreadTouchedByMe(Te)}),a.invalidateQueries({queryKey:q.sidebarBadges(Te)}))}}),kt=nt({mutationFn:Te=>ln.update(e,Te),onSuccess:()=>{ye()}}),$t=nt({mutationFn:({childIssueId:Te,status:De})=>ln.update(Te,{status:De}),onMutate:({childIssueId:Te})=>{Q(Te)},onSuccess:Te=>{X&&(U!=null&&U.id)&&a.setQueryData(q.issues.children(X,U.id),De=>(De==null?void 0:De.map(vt=>vt.id===Te.id?{...vt,...Te}:vt))??De),a.setQueryData(q.issues.detail(Te.id),Te),Te.identifier&&a.setQueryData(q.issues.detail(Te.identifier),Te),X&&(a.invalidateQueries({queryKey:q.issues.list(X)}),a.invalidateQueries({queryKey:q.issues.listTouchedByMe(X)}),a.invalidateQueries({queryKey:q.issues.listUnreadTouchedByMe(X)}),a.invalidateQueries({queryKey:q.sidebarBadges(X)}))},onError:Te=>{u({title:"Failed to update sub-issue status",body:Te instanceof Error?Te.message:"Try again.",tone:"error"})},onSettled:(Te,De,vt)=>{z(Cn=>Cn===vt.childIssueId?null:Cn),Q(Cn=>Cn===vt.childIssueId?null:Cn)}}),Nn=nt({mutationFn:({body:Te,reopen:De})=>ln.addComment(e,Te,De),onSuccess:()=>{ye(),a.invalidateQueries({queryKey:q.issues.comments(e)})}}),_n=nt({mutationFn:async({file:Te,usage:De="issue"})=>{const vt=(U==null?void 0:U.orgId)??X??n;if(!vt)throw new Error("No organization selected");return ln.uploadAttachment(vt,e,Te,{usage:De})},onSuccess:(Te,De)=>{B(null),(De.usage===void 0||De.usage==="issue")&&a.invalidateQueries({queryKey:q.issues.attachments(e)}),ye()},onError:Te=>{B(Te instanceof Error?Te.message:"Upload failed")}}),Ee=nt({mutationFn:async Te=>{const De=(U==null?void 0:U.orgId)??X??n;if(!De)throw new Error("No organization selected");return ln.attachWorkspaceFile(De,e,Te)},onSuccess:()=>{B(null),$(!1),a.invalidateQueries({queryKey:q.issues.attachments(e)}),ye()},onError:Te=>{B(Te instanceof Error?Te.message:"Workspace attach failed")}}),we=nt({mutationFn:async Te=>{const De=Q8t(Te.name),vt=Y8t(De),Cn=((U==null?void 0:U.documentSummaries)??[]).find(Ye=>Ye.key===vt)??null,mr=await Te.text(),Yi=J8t(De),ho=(Cn==null?void 0:Cn.title)??Yi??null;return ln.upsertDocument(e,vt,{title:vt==="plan"?null:ho,format:"markdown",body:mr,baseRevisionId:(Cn==null?void 0:Cn.latestRevisionId)??null})},onSuccess:()=>{B(null),ye()},onError:Te=>{B(Te instanceof Error?Te.message:"Document import failed")}}),Ze=nt({mutationFn:Te=>ln.deleteAttachment(Te),onSuccess:()=>{B(null),a.invalidateQueries({queryKey:q.issues.attachments(e)}),ye()},onError:Te=>{B(Te instanceof Error?Te.message:"Delete failed")}}),Ot=x.useCallback(()=>{if(!U){u({title:"Issue is not ready",tone:"error"});return}o(z8t(U))},[U,o,u]),un=nt({mutationFn:async Te=>{if(!U)throw new Error("Issue is not ready");return ln.create(U.orgId,{title:Te,parentId:U.id})},onSuccess:()=>{_(""),C(!1),ye()},onError:Te=>{u({title:Te instanceof Error?Te.message:"Failed to create sub-issue",tone:"error"})}}),Jn=nt({mutationFn:async Te=>{if(!U)throw new Error("Issue is not ready");return ln.update(Te.id,{parentId:U.id})},onSuccess:(Te,De)=>{T(!1),O(""),ye(),a.invalidateQueries({queryKey:q.issues.detail(Te.id)}),Te.identifier&&a.invalidateQueries({queryKey:q.issues.detail(Te.identifier)}),U!=null&&U.orgId&&De.parentId&&a.invalidateQueries({queryKey:q.issues.children(U.orgId,De.parentId)})},onError:Te=>{u({title:Te instanceof Error?Te.message:"Failed to add existing issue",tone:"error"})}});x.useEffect(()=>{const Te=(U==null?void 0:U.title)??e??"Issue";i([Pe,{label:ct?`🔵 ${Te}`:Te}])},[i,Pe,U,e,ct]),x.useEffect(()=>{U!=null&&U.identifier&&e!==U.identifier&&o(`/issues/${U.identifier}`,{replace:!0,state:l.state})},[U,e,o,l.state]),x.useLayoutEffect(()=>{const Te=De=>{if(Y){if(!awt(De))return;De.preventDefault(),pe();return}if(iwt(De)&&(De.preventDefault(),!(c!=null&&c()))){if(owt()){o(-1);return}o(Pe.href)}};return document.addEventListener("keydown",Te),()=>document.removeEventListener("keydown",Te)},[pe,Y,o,c,Pe.href]),x.useEffect(()=>{U!=null&&U.id&&fe.current!==U.id&&(fe.current=U.id,st.mutate(U.id))},[U==null?void 0:U.id]);const $s=async()=>{U&&(await navigator.clipboard.writeText(U.identifier??U.id),j(!0),u({title:"Copied issue ID",tone:"success"}),setTimeout(()=>j(!1),1500))},Ci=async()=>{const Te=A.trim();!Te||un.isPending||await un.mutateAsync(Te)};if(xe)return s.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading..."});if(re)return s.jsx("p",{className:"text-sm text-destructive",children:re.message});if(!U)return null;const ar=async Te=>{const De=Te.target.files;if(!(!De||De.length===0)){for(const vt of Array.from(De))kie(vt)?await we.mutateAsync(vt):await _n.mutateAsync({file:vt,usage:"issue"});ae.current&&(ae.current.value="")}},Ts=async Te=>{Te.preventDefault(),Z(!1);const De=Te.dataTransfer.files;if(!(!De||De.length===0))for(const vt of Array.from(De))kie(vt)?await we.mutateAsync(vt):await _n.mutateAsync({file:vt,usage:"issue"})},Gi=Te=>Te.contentType.startsWith("image/"),qe=Ue??[],At=qe.length>0,Ft=`${Sn.length}`,Pn=(Y==null?void 0:Y.target)??null,En=_n.isPending||we.isPending||Ee.isPending,la=s.jsxs(s.Fragment,{children:[s.jsx("input",{ref:ae,type:"file",accept:W8t,className:"hidden",onChange:ar,multiple:!0}),s.jsxs($o,{children:[s.jsx(Fo,{asChild:!0,children:s.jsxs(ce,{type:"button",variant:"quiet",size:"xs",disabled:En,className:G("shadow-none",F&&"border-primary bg-primary/5"),title:En?"Attaching":"Attach file",children:[En?s.jsx(yr,{className:"h-3.5 w-3.5 animate-spin"}):s.jsx(b1,{className:"h-3.5 w-3.5"}),En?"Attaching...":s.jsx("span",{className:"hidden sm:inline",children:"Attach"})]})}),s.jsxs(zo,{align:"end",className:"w-52",children:[s.jsxs(Hn,{onSelect:()=>{var Te;(Te=ae.current)==null||Te.click()},children:[s.jsx(d5,{className:"h-4 w-4"}),"Upload from computer"]}),s.jsx(fd,{}),s.jsxs(Hn,{onSelect:()=>{$(!0)},children:[s.jsx(dc,{className:"h-4 w-4"}),"Attach from Workspaces"]})]})]})]}),ca=U.identifier??U.id.slice(0,8),Qi=[U.id,U.updatedAt,tn.length,Se.length,Sn.length,qe.length].join(":"),Qa=({moreOpen:Te,onMoreOpenChange:De,grouped:vt=!1})=>s.jsxs("div",{className:G("flex items-center gap-1 shrink-0",vt&&"rounded-full border border-border bg-background/80 p-1"),children:[s.jsxs(ce,{variant:"ghost",size:"sm",className:G("h-7 px-2 text-xs",vt&&"rounded-full"),onClick:$s,title:`Copy ${ca}`,children:[v?s.jsx(gs,{className:"mr-1.5 h-3.5 w-3.5"}):s.jsx(Ni,{className:"mr-1.5 h-3.5 w-3.5"}),v?"Copied":"Copy ID"]}),s.jsxs(ce,{variant:"ghost",size:"sm",className:G("h-7 px-2 text-xs",vt&&"rounded-full"),onClick:Ot,children:[s.jsx(fo,{className:"mr-1.5 h-3.5 w-3.5"}),"Chat"]}),s.jsxs(qn,{open:Te,onOpenChange:De,children:[s.jsx(Wn,{asChild:!0,children:s.jsx(ce,{variant:"ghost",size:"sm",className:G("h-7 w-7 px-0 shrink-0",vt&&"rounded-full"),"aria-label":"More issue actions",children:s.jsx(Iu,{className:"h-4 w-4"})})}),s.jsx(Kn,{className:"w-44 p-1",align:"end",children:s.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-destructive",onClick:()=>{kt.mutate({hiddenAt:new Date().toISOString()},{onSuccess:()=>o("/issues/all")}),De(!1)},children:[s.jsx(Ap,{className:"h-3 w-3"}),"Hide this Issue"]})})]})]});return s.jsxs("div",{ref:H,className:G("mx-auto max-w-6xl",!Pn&&"xl:grid xl:grid-cols-[minmax(0,1fr)_280px] xl:items-start xl:gap-6"),children:[Pn?null:s.jsx(I8t,{rootRef:H,refreshKey:Qi}),Pn?s.jsx(y8t,{issue:U,target:Pn,motionState:(Y==null?void 0:Y.phase)??"open",mentions:Vt,imageUploadHandler:async Te=>(await _n.mutateAsync({file:Te,usage:"document_inline"})).contentPath,onClose:pe,onDocumentCreated:Te=>{V(De=>De&&{...De,target:{kind:"existing",key:Te}})}}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"min-w-0 space-y-6",children:[s.jsx("nav",{"aria-label":"Issue navigation","data-testid":"issue-detail-breadcrumb",children:s.jsx(kB,{children:s.jsx(jB,{className:"flex-wrap gap-y-1",children:oe.map((Te,De)=>{const vt=De===oe.length-1;return s.jsxs(iv,{className:vt?"min-w-0":"max-w-[220px]",children:[De>0?s.jsx(Vj,{}):null,vt||!Te.href?s.jsx(NB,{className:"truncate",title:Te.label,children:Te.label}):s.jsx(Hj,{asChild:!0,children:s.jsx(yt,{to:Te.href,state:Te.href.startsWith("/issues/")?l.state:void 0,className:"truncate",title:Te.label,children:Te.label})})]},`${Te.label}-${De}`)})})})}),U.hiddenAt&&s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:[s.jsx(Ap,{className:"h-4 w-4 shrink-0"}),"This issue is hidden"]}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-wrap",children:[ct&&s.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-cyan-500/10 border border-cyan-500/30 px-2 py-0.5 text-[10px] font-medium text-cyan-600 dark:text-cyan-400 shrink-0",children:[s.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[s.jsx("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-cyan-400 opacity-75"}),s.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-cyan-400"})]}),"Live"]}),U.originKind==="automation_execution"&&U.originId&&s.jsxs(yt,{to:`/automations/${U.originId}`,className:"inline-flex items-center gap-1 rounded-full bg-violet-500/10 border border-violet-500/30 px-2 py-0.5 text-[10px] font-medium text-violet-600 dark:text-violet-400 shrink-0 hover:bg-violet-500/20 transition-colors",children:[s.jsx(b7,{className:"h-3 w-3"}),"Automation"]})]}),s.jsxs("div",{className:"flex items-center gap-0.5 md:hidden shrink-0",children:[s.jsx(ce,{variant:"ghost",size:"icon-xs",onClick:$s,title:"Copy issue ID",children:v?s.jsx(gs,{className:"h-4 w-4"}):s.jsx(Ni,{className:"h-4 w-4"})}),s.jsx(ce,{variant:"ghost",size:"icon-xs",onClick:Ot,title:"Open in chat",children:s.jsx(fo,{className:"h-4 w-4"})}),s.jsx(ce,{variant:"ghost",size:"icon-xs",onClick:()=>w(!0),title:"Properties",children:s.jsx(o4,{className:"h-4 w-4"})})]}),s.jsx("div",{className:"hidden md:flex xl:hidden items-center shrink-0",children:Qa({moreOpen:f,onMoreOpenChange:h})})]}),s.jsx(zf,{value:U.title,onSave:Te=>kt.mutateAsync({title:Te}),as:"h2",className:"text-xl font-bold"}),s.jsx(zf,{value:U.description??"",onSave:Te=>kt.mutateAsync({description:Te}),as:"p",className:"text-[15px] leading-7 text-foreground",placeholder:"Add a description...",multiline:!0,mentions:Vt,imageUploadHandler:async Te=>(await _n.mutateAsync({file:Te,usage:"description_inline"})).contentPath})]}),s.jsx(y1,{slotTypes:["toolbarButton","contextMenuItem"],entityType:"issue",context:{orgId:U.orgId,projectId:U.projectId??null,entityId:U.id,entityType:"issue"},className:"flex flex-wrap gap-2",itemClassName:"inline-flex",missingBehavior:"placeholder"}),s.jsx(_B,{placementZones:["toolbarButton"],entityType:"issue",context:{orgId:U.orgId,projectId:U.projectId??null,entityId:U.id,entityType:"issue"},className:"flex flex-wrap gap-2",itemClassName:"inline-flex"}),s.jsx(y1,{slotTypes:["taskDetailView"],entityType:"issue",context:{orgId:U.orgId,projectId:U.projectId??null,entityId:U.id,entityType:"issue"},className:"space-y-3",itemClassName:"rounded-lg border border-border p-3",missingBehavior:"placeholder"}),s.jsxs("section",{"aria-label":"Sub-issues",className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsxs("div",{className:"flex items-center gap-1.5 font-medium text-foreground",children:[s.jsx(b3,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{children:"Sub-issues"})]}),s.jsx("span",{className:"rounded-sm border border-border px-1.5 py-0.5 text-[11px] text-muted-foreground",children:Ft})]}),s.jsxs($o,{children:[s.jsx(Fo,{asChild:!0,children:s.jsxs(ce,{variant:"outline",size:"sm",className:"h-8 gap-1.5 px-2.5 text-xs",disabled:un.isPending||Jn.isPending,children:[s.jsx(tr,{className:"h-3.5 w-3.5"}),"Add sub-issue"]})}),s.jsxs(zo,{align:"end",children:[s.jsx(Hn,{onSelect:()=>{T(!1),C(!0),_("")},children:"Create new sub-issue"}),s.jsx(Hn,{onSelect:()=>{C(!1),_(""),T(!0)},children:"Add existing issue"})]})]})]}),N?s.jsxs("div",{className:"rounded-lg border border-border bg-background/80 p-2.5",children:[s.jsxs("form",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",onSubmit:Te=>{Te.preventDefault(),Ci()},children:[s.jsx(In,{value:A,onChange:Te=>_(Te.target.value),onKeyDown:Te=>{Te.key==="Escape"&&(Te.preventDefault(),C(!1),_(""))},placeholder:"Add sub-issue title",autoFocus:!0,disabled:un.isPending,className:"h-9 text-sm"}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsx(ce,{type:"submit",size:"sm",className:"h-8 px-3 text-xs",disabled:!A.trim()||un.isPending,children:"Create"}),s.jsx(ce,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2.5 text-xs",onClick:()=>{C(!1),_("")},disabled:un.isPending,children:"Cancel"})]})]}),un.error instanceof Error?s.jsx("p",{className:"mt-2 text-xs text-destructive",children:un.error.message}):null]}):null,E?s.jsxs("div",{className:"rounded-lg border border-border bg-background/80 p-2.5",children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/70 pb-2",children:[s.jsx(In,{value:M,onChange:Te=>O(Te.target.value),placeholder:"Search existing issues",autoFocus:!0,disabled:Jn.isPending,className:"h-8 text-sm"}),s.jsx(ce,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2.5 text-xs",onClick:()=>{T(!1),O("")},disabled:Jn.isPending,children:"Cancel"})]}),s.jsx("div",{className:"max-h-64 overflow-y-auto pt-2",children:sn.length===0?s.jsx("p",{className:"px-1 py-2 text-xs text-muted-foreground",children:"No matching issues."}):sn.map(Te=>{const De=Te.identifier??Te.id.slice(0,8),vt=Te.parentId?rt.get(Te.parentId)??null:null,Cn=Te.projectId?_t.get(Te.projectId)??Te.project??null:Te.project??null,mr=vt?`Move from ${vt.identifier??vt.id.slice(0,8)}`:Cn&&Te.projectId!==U.projectId?Cn.name:"No parent";return s.jsxs("button",{type:"button",className:"grid w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-2 rounded-md px-2 py-2 text-left text-sm transition-colors hover:bg-accent/40 disabled:cursor-wait disabled:opacity-60",onClick:()=>Jn.mutate(Te),disabled:Jn.isPending,children:[s.jsx(os,{status:Te.status}),s.jsx("span",{className:"min-w-0 truncate",children:Te.title}),s.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:De}),s.jsx("span",{className:"col-start-2 min-w-0 truncate text-xs text-muted-foreground",children:mr})]},Te.id)})})]}):null,Sn.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:"No sub-issues."}):s.jsx("div",{className:"overflow-hidden rounded-lg border border-border",children:Sn.map(Te=>{var mr,Yi,ho,Ye;const De=Te.identifier??Te.id,vt=P===Te.id,Cn=L===Te.id;return s.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2 text-sm transition-colors hover:bg-accent/20 last:border-b-0",children:[s.jsxs(qn,{open:vt,onOpenChange:Nt=>{z(Nt?Te.id:null)},children:[s.jsx(Wn,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":`Change status for ${Te.title}`,className:"inline-flex shrink-0 items-center gap-2 rounded-md p-1 text-left transition-colors hover:bg-accent/50 disabled:cursor-wait disabled:opacity-60",disabled:Cn,children:[s.jsx(os,{status:Te.status}),s.jsx(ya,{priority:Te.priority})]})}),s.jsx(Kn,{className:"w-40 p-1",align:"start",children:V8t.map(Nt=>s.jsxs(ce,{variant:"ghost",size:"sm",className:G("w-full justify-start gap-2 text-xs",Nt===Te.status&&"bg-accent"),onClick:()=>{$t.mutate({childIssueId:Te.id,status:Nt})},children:[s.jsx(os,{status:Nt}),G8t(Nt)]},Nt))})]}),s.jsxs(yt,{to:`/issues/${De}`,state:l.state,className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:De}),s.jsx("span",{className:"truncate",children:Te.title})]}),s.jsx("div",{className:"shrink-0",children:Te.assigneeAgentId?(mr=Pt.get(Te.assigneeAgentId))!=null&&mr.name?s.jsx(Za,{name:((Yi=Pt.get(Te.assigneeAgentId))==null?void 0:Yi.name)??Te.assigneeAgentId.slice(0,8),icon:(ho=Pt.get(Te.assigneeAgentId))==null?void 0:ho.icon,role:(Ye=Pt.get(Te.assigneeAgentId))==null?void 0:Ye.role,size:"sm"}):s.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:Te.assigneeAgentId.slice(0,8)}):Te.assigneeUserId?s.jsx(Da,{name:a8("user",Te.assigneeUserId,ht,d),size:"sm"}):null})]})]},Te.id)})})]}),s.jsx(b8t,{issue:U,canDeleteDocuments:!!((Kc=je==null?void 0:je.user)!=null&&Kc.id),mentions:Vt,imageUploadHandler:async Te=>(await _n.mutateAsync({file:Te,usage:"document_inline"})).contentPath,extraActions:At?void 0:la,onFocusNewDocument:()=>ie({kind:"new"}),onFocusDocument:Te=>ie({kind:"existing",key:Te})}),At?s.jsxs("div",{className:G("space-y-3 rounded-lg transition-colors"),onDragEnter:Te=>{Te.preventDefault(),Z(!0)},onDragOver:Te=>{Te.preventDefault(),Z(!0)},onDragLeave:Te=>{Te.currentTarget.contains(Te.relatedTarget)||Z(!1)},onDrop:Te=>void Ts(Te),children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:"Attachments"}),la]}),ee&&s.jsx("p",{className:"text-xs text-destructive",children:ee}),s.jsx("div",{className:"space-y-2",children:qe.map(Te=>s.jsxs("div",{className:"border border-border rounded-md p-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("a",{href:Te.contentPath,target:"_blank",rel:"noreferrer",className:"text-xs hover:underline truncate",title:Te.originalFilename??Te.id,children:Te.originalFilename??Te.id}),s.jsx("button",{type:"button",className:"text-muted-foreground hover:text-destructive",onClick:()=>Ze.mutate(Te.id),disabled:Ze.isPending,title:"Delete attachment",children:s.jsx(Sa,{className:"h-3.5 w-3.5"})})]}),s.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[Te.contentType," · ",(Te.byteSize/1024).toFixed(1)," KB"]}),Gi(Te)&&s.jsx("a",{href:Te.contentPath,target:"_blank",rel:"noreferrer",children:s.jsx("img",{src:Te.contentPath,alt:Te.originalFilename??"attachment",className:"mt-2 max-h-56 rounded border border-border object-contain bg-accent/10",loading:"lazy"})})]},Te.id))})]}):null,s.jsx(Lc,{}),s.jsxs("section",{"aria-label":"Activity",className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold",children:[s.jsx(Dz,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{children:"Activity"})]}),s.jsx(d8t,{comments:tn,linkedRuns:D,activityItems:Se,orgId:U.orgId,projectId:U.projectId,issueStatus:U.status,agentMap:Pt,draftKey:`rudder:issue-comment-draft:${U.id}`,mentions:Vt,operatorDisplayName:d,hideHeading:!0,emptyMessage:"No activity yet.",escapeBackWhenEmpty:!0,onAdd:async(Te,De)=>{await Nn.mutateAsync({body:Te,reopen:De})},imageUploadHandler:async Te=>(await _n.mutateAsync({file:Te,usage:"comment_inline"})).contentPath,onAttachImage:async Te=>{await _n.mutateAsync({file:Te,usage:"comment_attachment"})},liveRunSlot:s.jsx(P7e,{issueId:e,orgId:U.orgId})})]}),at.length>0?s.jsx("div",{className:"space-y-3",children:at.map(Te=>s.jsxs("section",{className:"space-y-2",children:[s.jsx("h3",{className:"text-sm font-semibold",children:Te.label}),s.jsx(f4,{slot:Te.slot,context:{orgId:U.orgId,orgPrefix:(ve==null?void 0:ve.issuePrefix)??null,projectId:U.projectId??null,entityId:U.id,entityType:"issue"},missingBehavior:"placeholder"})]},Te.value))}):null,s.jsx(PC,{open:k,onOpenChange:w,children:s.jsxs(DC,{side:"bottom",className:"max-h-[85dvh] pb-[env(safe-area-inset-bottom)]",children:[s.jsx(LC,{children:s.jsx($C,{className:"text-sm",children:"Properties"})}),s.jsx(kH,{className:"flex-1 overflow-y-auto",children:s.jsxs("div",{className:"space-y-3 px-4 pb-4",children:[s.jsx(gie,{issue:U,onUpdate:Te=>kt.mutate(Te),inline:!0,childIssues:Sn}),s.jsx(jie,{summary:xn})]})})]})}),s.jsx(c7e,{})]}),s.jsx("aside",{className:"mt-6 xl:mt-0",children:s.jsxs("div",{className:"space-y-3 xl:sticky xl:top-4",children:[s.jsx("div",{className:"hidden xl:flex justify-end",children:Qa({moreOpen:g,onMoreOpenChange:b,grouped:!0})}),s.jsxs("section",{"aria-label":"Issue properties",className:"rounded-lg border border-border bg-background/80 p-3",children:[s.jsx("div",{className:"mb-3 flex items-center justify-between gap-2",children:s.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Properties"})}),s.jsx(gie,{issue:U,onUpdate:Te=>kt.mutate(Te),childIssues:Sn})]}),s.jsx(jie,{summary:xn})]})})]}),s.jsx(twt,{orgId:U.orgId??X??n,open:W,onOpenChange:$,onAttach:Te=>Ee.mutateAsync(Te).then(()=>{}).catch(()=>{}),attaching:Ee.isPending,error:ee})]})}const L7e="rudder:chat-drafts",fwt="__new__";function $7e(){try{return globalThis.localStorage??null}catch{return null}}function jH(e){return((e==null?void 0:e.trim())??"")||fwt}function F7e(){var e;try{const t=(e=$7e())==null?void 0:e.getItem(L7e);if(!t)return{};const n=JSON.parse(t);return n&&typeof n=="object"?n:{}}catch{return{}}}function Nie(e){var t;(t=$7e())==null||t.setItem(L7e,JSON.stringify(e))}function Cie(e,t){const n=F7e()[e];if(!n||typeof n!="object")return"";const r=n[jH(t)];return typeof r=="string"?r:""}function Sie(e,t,n){const r=F7e(),i=jH(t),a={...r[e]??{}};if(n.length>0){a[i]=n,r[e]=a,Nie(r);return}i in a&&(delete a[i],Object.keys(a).length===0?delete r[e]:r[e]=a,Nie(r))}let R$={};function _ie(e,t){return`${e}:${jH(t)}`}function z7e(e,t){return e[t]??[]}function mwt(e,t,n){const r=z7e(e,t),i=n(r);if(i.length===0){if(!(t in e))return e;const a={...e};return delete a[t],a}return i===r?e:{...e,[t]:i}}function hwt(e){return z7e(R$,e)}function Aie(e,t){R$=mwt(R$,e,t)}const Ph="__none__",O$="rudder.chatLastAgentByOrg";function B7e(){try{return globalThis.localStorage??null}catch{return null}}function NH(e){return(e??[]).filter(t=>t.status!=="terminated")}function pwt(e){var t;try{const n=(t=B7e())==null?void 0:t.getItem(O$);if(!n)return;const r=JSON.parse(n);if(!r||typeof r!="object")return;const i=r[e];return typeof i=="string"&&i.trim().length>0?i:void 0}catch{return}}function _y(e,t){if(!(!t||t===Ph))try{const n=B7e();if(!n)return;const r=n.getItem(O$),i=r?JSON.parse(r):{},a=i&&typeof i=="object"?i:{};a[e]=t,n.setItem(O$,JSON.stringify(a))}catch{return}}function QR(e,t){return!!(e&&NH(t).some(n=>n.id===e))}function gwt(e,t){const n=NH(t);if(n.length===0)return Ph;const r=e?pwt(e):void 0;return r&&n.some(i=>i.id===r)?r:n[0].id}function xwt(e,t){const n=(e==null?void 0:e.trim())??"";if(!n)return null;const r=t.find(i=>i.id===n);return!r||r.status==="terminated"?null:r.id}function bwt(e){return N7(e)}function ywt(e,t){const n=t.trim().toLowerCase();return n?e.filter(r=>r.searchText.includes(n)):e}function Jy(e){if(!e)return null;const t=e instanceof Date?e.getTime():Date.parse(e);return Number.isFinite(t)?t:null}function vwt(e){if(!Number.isFinite(e)||e<0)return"0s";if(e<1e3)return"under 1s";const t=Math.floor(e/1e3);if(t<60)return`${t}s`;const n=Math.floor(t/60),r=t%60;return r>0?`${n}m ${r}s`:`${n}m`}function U7e(e){let t=0;for(const n of e){const r=Date.parse(n.ts);Number.isFinite(r)&&r>t&&(t=r)}return t>0?t:Date.now()}function wwt(e,t){for(const n of e){const r=Date.parse(n.ts);if(Number.isFinite(r))return new Date(r)}return t}function kwt(e,t,n){const r=Jy(t.createdAt),a=(t.chatTurnId?e.filter(l=>{if(l.role!=="user"||l.chatTurnId!==t.chatTurnId||(l.turnVariant??0)!==(t.turnVariant??0))return!1;const c=Jy(l.createdAt);return c!==null&&(r===null||c<=r)}):[]).reduce((l,c)=>{const u=Jy(c.createdAt);return u===null?l:l===null||u>l?u:l},null);if(a!==null)return new Date(a);const o=e.reduce((l,c)=>{if(c.role!=="user")return l;const u=Jy(c.createdAt);return u===null||r!==null&&u>r?l:l===null||u>l?u:l},null);return o!==null?new Date(o):wwt(n,new Date(t.createdAt))}function jwt(e,t){const n=t.length>0?U7e(t):0,r=Jy(e.createdAt)??0,i=Math.max(n,r);return new Date(i>0?i:Date.now())}const Nwt=["/Users/","/home/","/Volumes/","/tmp/","/var/","/opt/","/mnt/","/private/"];function Cwt(e){try{const t=new URL(e);if(t.protocol!=="file:")return null;const n=decodeURIComponent(t.pathname);return/^\/[A-Za-z]:\//.test(n)?n.slice(1):n}catch{return null}}function q7e(e){const t=e==null?void 0:e.trim();if(!t)return null;const n=/^file:/i.test(t)?Cwt(t):null;return n||(/^[A-Za-z]:[\\/]/.test(t)||/^\\\\[^\\]+\\[^\\]+/.test(t)?t:/^[a-z][a-z0-9+.-]*:/i.test(t)||t.startsWith("//")?null:Nwt.some(r=>t.startsWith(r))?t:null)}function CH({src:e,name:t,onOpen:n,onRemove:r,testId:i}){const{pushToast:a}=_r(),o=x.useRef(null),[l,c]=x.useState(null),u=wK();x.useEffect(()=>{if(!l)return;const g=v=>{var j;(j=o.current)!=null&&j.contains(v.target)||c(null)},b=v=>{v.key==="Escape"&&c(null)};return document.addEventListener("pointerdown",g),document.addEventListener("keydown",b),()=>{document.removeEventListener("pointerdown",g),document.removeEventListener("keydown",b)}},[l]);const d=g=>{g.preventDefault(),g.stopPropagation(),c(Gwt(g.clientX,g.clientY))},f=async()=>{c(null);try{await yK(e,t),a({title:"Image copied",tone:"success"})}catch(g){a({title:"Copy Image failed",body:g instanceof Error?g.message:String(g),tone:"error"})}},h=async()=>{if(c(null),!u){a({title:"Open in Finder unavailable",body:"Open in Finder is available in the desktop app.",tone:"error"});return}try{await vK(e,t)}catch(g){a({title:"Open in Finder failed",body:g instanceof Error?g.message:String(g),tone:"error"})}};return s.jsxs("div",{"data-testid":i,className:"relative inline-flex max-w-full",children:[s.jsx("button",{type:"button","aria-label":`Open image preview: ${t}`,className:"flex h-12 w-12 min-w-0 items-center justify-center overflow-hidden rounded-[calc(var(--radius-sm)+4px)] border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-active)_42%,transparent)] text-left transition-[border-color,box-shadow] hover:border-[color:var(--border-strong)] focus-visible:border-ring focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",onClick:n,onContextMenu:d,children:s.jsx("img",{src:e,alt:t,className:"h-full w-full shrink-0 object-cover",onContextMenu:d})}),r?s.jsx("button",{type:"button",className:"absolute -right-1.5 -top-1.5 inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full border border-[color:var(--border-soft)] bg-[color:var(--surface-elevated)] text-muted-foreground shadow-[var(--shadow-sm)] transition-colors hover:text-foreground focus-visible:border-ring focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50","aria-label":`Remove ${t}`,onClick:r,children:s.jsx(Gs,{className:"h-3.5 w-3.5"})}):null,l&&typeof document<"u"?oo.createPortal(s.jsxs("div",{ref:o,"data-testid":"chat-image-context-menu",role:"menu",className:"motion-chat-composer-menu-pop surface-overlay fixed z-50 min-w-[172px] rounded-[var(--radius-lg)] border p-1.5 text-foreground shadow-[var(--shadow-lg)]",style:l,children:[s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full disabled:cursor-not-allowed disabled:opacity-50",disabled:!u,onClick:h,children:[s.jsx(dc,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Open in Finder"})]}),s.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:f,children:[s.jsx(Ni,{className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Copy Image"})]})]}),document.body):null]})}function SH({name:e,href:t,onRemove:n,onOpenFile:r}){const i=s.jsxs(s.Fragment,{children:[s.jsx(b1,{className:"h-3 w-3 shrink-0"}),s.jsx("span",{className:"truncate",children:e})]});if(t){const a=q7e(t);return a&&r?s.jsx("button",{type:"button",className:"chat-chip inline-flex max-w-full items-center gap-2 rounded-[calc(var(--radius-sm)+2px)] px-3 py-1.5 text-xs transition-colors hover:bg-[color:var(--surface-active)] hover:text-foreground",onClick:()=>r(a),children:i}):s.jsx("a",{href:t,target:"_blank",rel:"noreferrer",className:"chat-chip inline-flex max-w-full items-center gap-2 rounded-[calc(var(--radius-sm)+2px)] px-3 py-1.5 text-xs transition-colors hover:bg-[color:var(--surface-active)] hover:text-foreground",children:i})}return s.jsxs("span",{className:"chat-chip inline-flex max-w-full items-center gap-2 rounded-[calc(var(--radius-sm)+2px)] px-3 py-1.5 text-xs",children:[i,n?s.jsx("button",{type:"button",className:"inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:text-foreground","aria-label":`Remove ${e}`,onClick:n,children:s.jsx(Gs,{className:"h-3 w-3"})}):null]})}function G6({file:e,onOpenImage:t,onRemove:n}){const[r,i]=x.useState(null),a=xK(e.type),o=t8e(e);return x.useEffect(()=>{if(!a){i(null);return}const l=URL.createObjectURL(e);return i(l),()=>URL.revokeObjectURL(l)},[e,a]),a&&r?s.jsx(CH,{src:r,name:o,onOpen:()=>t({src:r,name:o}),onRemove:n,testId:"chat-pending-image-attachment"}):s.jsx(SH,{name:o,onRemove:n})}function rj({attachments:e,onOpenImage:t,onOpenFile:n}){return e.length===0?null:s.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:e.map(r=>{const i=t8e(r);return xK(r.contentType)?s.jsx(CH,{src:r.contentPath,name:i,onOpen:()=>t({src:r.contentPath,name:i}),testId:"chat-image-attachment"},r.id):s.jsx(SH,{name:i,href:r.contentPath,onOpenFile:n},r.id)})})}function K7e({preview:e,onOpenChange:t}){return s.jsx(kK,{preview:e?{src:e.src,name:e.name,alt:e.name}:null,onOpenChange:t,testId:"chat-image-preview-dialog",titleFallback:"Attachment preview"})}function H7e({message:e}){const t=x.useMemo(()=>cRe(e.structuredPayload).filter(n=>n.display==="card"),[e.structuredPayload]);return t.length===0?null:s.jsx("div",{className:"mt-3 flex max-w-[72ch] flex-col gap-2","data-testid":"chat-rich-references",children:t.map((n,r)=>s.jsx(Swt,{reference:n},`${n.type}:${n.issueId??n.identifier??"issue"}:${n.type==="issue_comment"?n.commentId:r}`))})}function Swt({reference:e}){return e.type==="issue"?s.jsx(_wt,{reference:e}):s.jsx(Awt,{reference:e})}function _wt({reference:e}){const t=V7e(e),n=Ne({queryKey:q.issues.detail(t),queryFn:()=>ln.get(t),retry:!1,enabled:!!t});return n.isLoading?s.jsx(D2,{icon:"issue",title:"Loading issue",detail:t,tone:"loading"}):n.isError?s.jsx(P$,{error:n.error,kind:"issue"}):n.data?s.jsx(Ewt,{issue:n.data}):s.jsx(D2,{icon:"issue",title:"Issue unavailable",detail:"The issue could not be loaded.",tone:"muted"})}function Awt({reference:e}){const t=V7e(e),n=Ne({queryKey:q.issues.detail(t),queryFn:()=>ln.get(t),retry:!1,enabled:!!t}),r=Ne({queryKey:q.issues.comment(t,e.commentId),queryFn:()=>ln.getComment(t,e.commentId),retry:!1,enabled:!!t});return n.isLoading||r.isLoading?s.jsx(D2,{icon:"comment",title:"Loading comment",detail:t,tone:"loading"}):n.isError?s.jsx(P$,{error:n.error,kind:"issue"}):r.isError?s.jsx(P$,{error:r.error,kind:"comment"}):!n.data||!r.data?s.jsx(D2,{icon:"comment",title:"Comment unavailable",detail:"The comment could not be loaded.",tone:"muted"}):s.jsx(Twt,{issue:n.data,comment:r.data})}function Ewt({issue:e}){const t=e.identifier??e.id.slice(0,8),n=e.assigneeAgentId?e.assigneeAgentId.slice(0,8):e.assigneeUserId?Ol(e.assigneeUserId,null)??e.assigneeUserId.slice(0,8):"Unassigned";return s.jsx(yt,{to:`/issues/${e.identifier??e.id}`,className:"group block rounded-lg border border-border bg-card px-3 py-2.5 text-left shadow-[var(--shadow-sm)] transition-colors hover:border-[color:var(--accent-strong)]/40 hover:bg-[color:var(--surface-active)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":`Open issue ${t}`,children:s.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[s.jsx("div",{className:"mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-border bg-background text-muted-foreground",children:s.jsx(Nd,{className:"h-4 w-4","aria-hidden":!0})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[s.jsx("span",{className:"font-mono text-[11px] font-medium text-foreground",children:t}),s.jsx(er,{status:e.status}),s.jsx("span",{children:Lo(e.priority)})]}),s.jsx("div",{className:"mt-1 truncate text-sm font-medium leading-5 text-foreground",children:e.title}),s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",children:[s.jsx("span",{children:n}),s.jsxs("span",{children:["Updated ",js(e.updatedAt)]})]})]})]})})}function Twt({issue:e,comment:t}){const n=e.identifier??e.id.slice(0,8),r=t.authorAgentId?t.authorAgentId.slice(0,8):t.authorUserId?Ol(t.authorUserId,null)??t.authorUserId.slice(0,8):"System",i=Iwt(t.body);return s.jsx(yt,{to:`/issues/${e.identifier??e.id}#comment-${t.id}`,className:"group block rounded-lg border border-border bg-card px-3 py-2.5 text-left shadow-[var(--shadow-sm)] transition-colors hover:border-[color:var(--accent-strong)]/40 hover:bg-[color:var(--surface-active)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":`Open comment on issue ${n}`,children:s.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[s.jsx("div",{className:"mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-border bg-background text-muted-foreground",children:s.jsx(Tme,{className:"h-4 w-4","aria-hidden":!0})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[s.jsx("span",{className:"font-mono text-[11px] font-medium text-foreground",children:n}),s.jsx("span",{children:r}),s.jsx("span",{children:js(t.createdAt)})]}),s.jsx("div",{className:"mt-1 truncate text-sm font-medium leading-5 text-foreground",children:e.title}),s.jsx("p",{className:"mt-1 max-h-[3.75rem] overflow-hidden text-sm leading-5 text-muted-foreground",children:i})]})]})})}function P$({error:e,kind:t}){if(e instanceof Ml){if(e.status===403)return s.jsx(D2,{icon:t,title:"Permission denied",detail:"You do not have access to this reference.",tone:"warning"});if(e.status===404)return s.jsx(D2,{icon:t,title:t==="issue"?"Issue not found":"Comment not found",detail:"The reference may have been deleted or moved.",tone:"muted"})}return s.jsx(D2,{icon:t,title:"Reference unavailable",detail:"The reference could not be loaded.",tone:"warning"})}function D2({icon:e,title:t,detail:n,tone:r}){const i=e==="issue"?Nd:g1;return s.jsx("div",{className:G("rounded-lg border border-dashed px-3 py-2.5 text-sm",r==="warning"?"border-amber-500/35 bg-amber-500/5 text-amber-800 dark:text-amber-200":"border-border bg-card text-muted-foreground"),children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-current/15 bg-background/70",children:s.jsx(i,{className:"h-4 w-4","aria-hidden":!0})}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"font-medium text-foreground",children:t}),s.jsx("div",{className:"mt-0.5 break-words text-xs",children:n})]})]})})}function V7e(e){return e.issueId??e.identifier??""}function Iwt(e){return e.replace(/!\[[^\]]*]\([^)]*\)/g,"").replace(/\[([^\]]+)]\([^)]*\)/g,"$1").replace(/[`*_>#~-]+/g,"").replace(/\s+/g," ").trim()||"No comment body."}function W7e({text:e,className:t,...n}){return s.jsxs("span",{role:"status","aria-label":`${e}...`,className:G("rudder-text-dots inline-flex items-baseline whitespace-nowrap align-baseline",t),...n,children:[s.jsx("span",{children:e}),s.jsx("span",{className:"rudder-text-dots__dots","aria-hidden":"true",children:[0,1,2].map(r=>s.jsx("span",{className:"rudder-text-dots__dot",style:{"--rudder-text-dot-index":r},children:"."},r))})]})}function h8({replyingAgentId:e,conversation:t,agents:n}){var l;const r=e?n==null?void 0:n.find(c=>c.id===e):null,i=e?((l=t.chatRuntime)==null?void 0:l.sourceLabel)??"Unknown agent":"Assistant",a=(r==null?void 0:r.name)??i,o=s.jsxs(s.Fragment,{children:[r||e?s.jsx(ki,{icon:r==null?void 0:r.icon,role:r==null?void 0:r.role,fallbackSeed:(r==null?void 0:r.id)??e,className:"h-8 w-8 shrink-0"}):s.jsx("span",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-border/70 bg-muted/90 text-foreground shadow-sm",children:s.jsx(Sd,{className:"h-4 w-4 text-muted-foreground"})}),s.jsx("span",{className:"text-sm font-semibold tracking-tight text-foreground",children:a})]});return s.jsx("div",{className:"mb-2 flex items-center gap-2.5",children:r?s.jsx(yt,{to:co(r),className:"inline-flex items-center gap-2.5 rounded-[calc(var(--radius-sm)-1px)] pr-1 outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/45","aria-label":`Open ${a} agent detail`,children:o}):o})}const _H={assignee:{agent:"assigneeAgentId",user:"assigneeUserId"},reviewer:{agent:"reviewerAgentId",user:"reviewerUserId"}};function Mwt(e,t){const n=_H[t],r=e[n.agent],i=typeof r=="string"?r.trim():"";if(i)return Jh({assigneeAgentId:i});const a=e[n.user],o=typeof a=="string"?a.trim():"";return o?Jh({assigneeUserId:o}):""}function Rwt(e,t,n){const r=_H[t],i=cu(n);return{...e,[r.agent]:i.assigneeAgentId,[r.user]:i.assigneeUserId}}function Owt(e,t){const n=e.proposedIssue&&typeof e.proposedIssue=="object"&&!Array.isArray(e.proposedIssue)?e.proposedIssue:{};return{...e,proposedIssue:{...n,...t}}}function Eie(e,t,n,r){const i=_H[t],a=e[i.agent],o=typeof a=="string"?a.trim():"";if(o){const u=(n==null?void 0:n.find(d=>d.id===o))??null;return{kind:"agent",label:(u==null?void 0:u.name)??(t==="assignee"?"Unknown agent":"Unknown reviewer"),agent:u}}const l=e[i.user],c=typeof l=="string"?l.trim():"";return c?{kind:"user",label:Ol(c,r)??(t==="assignee"?"Human assignee":"Human reviewer")}:null}function YR(e,t,n,r){const i=cu(e.id);if(i.assigneeAgentId){const a=(n==null?void 0:n.find(o=>o.id===i.assigneeAgentId))??null;return{kind:"agent",label:(a==null?void 0:a.name)??e.label,agent:a}}return i.assigneeUserId?{kind:"user",label:Ol(i.assigneeUserId,r)??e.label}:t==="assignee"?{kind:"user",label:"No owner"}:{kind:"user",label:"No reviewer"}}function JR({label:e,children:t}){return s.jsxs("div",{className:"grid min-h-9 grid-cols-[minmax(5rem,0.8fr)_minmax(0,1.2fr)] items-center gap-4 border-b border-[color:var(--border-soft)] py-2 last:border-b-0",children:[s.jsx("div",{className:"text-sm text-muted-foreground",children:e}),s.jsx("div",{className:"flex min-w-0 justify-end text-sm font-medium text-foreground",children:t})]})}function FC({principal:e}){var t,n;return e?e.kind==="agent"?s.jsx(Ki,{kind:"agent",label:e.label,badgeLabel:e.agent?Q2(e.agent):null,agentIcon:((t=e.agent)==null?void 0:t.icon)??null,agentRole:((n=e.agent)==null?void 0:n.role)??null}):s.jsx(Ki,{kind:"user",label:e.label}):s.jsx("span",{className:"text-muted-foreground",children:"None"})}function Tie({proposal:e,role:t,agents:n,currentUserId:r,onChange:i}){const a=Mwt(e,t),o=x.useMemo(()=>zP(r),[r]),l=x.useMemo(()=>{const u=(n??[]).filter(f=>f.status!=="terminated").map(f=>({id:Jh({assigneeAgentId:f.id}),label:f.name,searchText:`${f.name} ${f.role} ${f.title??""}`})),d=[...o,...u];if(a&&!d.some(f=>f.id===a)){const f=YR({id:a,label:t==="assignee"?"Current owner":"Current reviewer"},t,n,r);d.unshift({id:a,label:(f==null?void 0:f.label)??(t==="assignee"?"Current owner":"Current reviewer")})}return d},[n,r,o,t,a]),c=t==="assignee"?"No owner":"No reviewer";return s.jsx(Mf,{value:a,options:l,placeholder:c,noneLabel:c,searchPlaceholder:t==="assignee"?"Search owners...":"Search reviewers...",emptyMessage:t==="assignee"?"No owners found.":"No reviewers found.",ariaLabel:t==="assignee"?"Edit owner":"Edit reviewer",className:"max-w-full justify-end rounded-[var(--radius-sm)] border-transparent bg-transparent px-1.5 py-1 hover:border-border hover:bg-accent/50",contentClassName:"min-w-64",onChange:u=>i(Rwt(e,t,u)),renderTriggerValue:u=>u?s.jsx(FC,{principal:YR(u,t,n,r)}):s.jsx(Ki,{kind:"unassigned",label:c,muted:!0}),renderOption:u=>{if(!u.id)return s.jsx(Ki,{kind:"unassigned",label:u.label,muted:!0});const d=cu(u.id),f=d.assigneeAgentId?(n??[]).find(h=>h.id===d.assigneeAgentId)??null:null;return f?s.jsx(ip,{agent:f}):s.jsx(FC,{principal:YR(u,t,n,r)})}})}function Pwt({conversation:e,message:t,agents:n,currentUserId:r,issueProposalOverride:i,onIssueProposalChange:a,decisionNote:o,onDecisionNoteChange:l,onApprovalAction:c,onResolveOperationProposal:u,onConvertToIssue:d,actionPending:f,skillReferences:h,onMarkdownLinkClick:g}){var xe,re;const b=t.kind==="issue_proposal"?z$(t):null,v=b?i??b:null,j=t.kind==="issue_proposal"?c9t(t):null,k=t.kind==="operation_proposal"?B$(t):null,w=t.kind==="operation_proposal"?EH(t):null,N=n8e(t.approval),C=t.kind==="operation_proposal"&&!t.approval&&w==="pending",A=t.kind==="issue_proposal"&&!t.approval&&!e.primaryIssue,_=d9t(t),E=f9t(_),T=N||C,M=((xe=t.approval)==null?void 0:xe.status)==="pending",O=`proposal-review-note-${t.id}`,P=`proposal-details-${t.id}`,z=((re=t.approval)==null?void 0:re.decisionNote)??u9t(t),L=T||A||!!z,Q=_==="revision_requested"?"Requested changes":"Decision note",ee=v?Die(v,"assignee",n):null,B=v?Die(v,"reviewer",n):null,F=v?Eie(v,"assignee",n,r):null,Z=v?Eie(v,"reviewer",n,r):null,W=v?String(v.description):"",$=!!(v&&(N||A)&&a),[Y,V]=x.useState(!1),[H,ae]=x.useState(!1),le=x.useRef(null),fe=v?"issue":k?"operation":j?"plan":"default",U=v?"Issue proposal":k?"Operation proposal":j?"Plan proposal":"Proposal";return x.useEffect(()=>{V(!1)},[t.id,W]),x.useEffect(()=>{const X=le.current;if(!X||!v){ae(!1);return}const ie=()=>{const ke=window.getComputedStyle(X),Ce=Number.parseFloat(ke.lineHeight),$e=Number.isFinite(Ce)?Ce*10:240;ae(X.scrollHeight>$e+1)};if(ie(),typeof ResizeObserver>"u")return;const pe=new ResizeObserver(ie);return pe.observe(X),()=>pe.disconnect()},[v,W,Y]),s.jsxs("div",{className:"text-foreground",children:[s.jsx(h8,{replyingAgentId:t.replyingAgentId??null,conversation:e,agents:n}),t.body.trim().length>0?s.jsx(b0,{body:t.body,skillReferences:h,onMarkdownLinkClick:g,className:"mt-4 max-w-[72ch] text-[15px] leading-7 text-foreground"}):null,s.jsxs("div",{"data-testid":"proposal-review-block","data-status":_??"default","data-kind":fe,className:"chat-review-block mt-4 max-w-[860px] rounded-[var(--radius-lg)] text-foreground transition-all duration-200",children:[s.jsxs("div",{className:G("chat-review-docket-header grid border-b border-[color:var(--border-soft)]",_?"grid-cols-1 sm:grid-cols-[1fr_minmax(9rem,13rem)]":"grid-cols-1"),children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-5 py-4",children:[s.jsx("span",{className:"h-6 w-1 rounded-full bg-[color:var(--accent-strong)]","aria-hidden":"true"}),s.jsx("span",{className:"truncate text-sm font-semibold leading-5 text-foreground",children:U})]}),_?s.jsx("div",{"data-testid":"proposal-review-status",className:"relative z-[6] flex min-w-0 items-center justify-start border-t border-[color:var(--border-soft)] px-5 py-4 sm:justify-end sm:border-t-0 sm:pr-10",children:s.jsx(er,{status:_})}):null]}),s.jsx("div",{className:"px-5 py-5",children:s.jsxs("div",{className:"min-w-0",children:[v?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"grid gap-5 md:grid-cols-[minmax(0,1fr)_minmax(15rem,22rem)]",children:[s.jsx("div",{className:"flex min-w-0 items-center border-b border-[color:var(--border-soft)] pb-5 md:border-b-0 md:pb-0",children:s.jsx("div",{className:"text-[26px] font-semibold leading-tight text-foreground",children:String(v.title)})}),s.jsxs("div",{className:"chat-review-fact-ledger",children:[s.jsx(JR,{label:"Priority",children:s.jsx(ya,{priority:String(v.priority??"medium"),showLabel:!0})}),s.jsx(JR,{label:"Owner",children:$?s.jsx(Tie,{proposal:v,role:"assignee",agents:n,currentUserId:r,onChange:X=>a==null?void 0:a(t.id,X)}):s.jsx(FC,{principal:F})}),s.jsx(JR,{label:"Reviewer",children:$?s.jsx(Tie,{proposal:v,role:"reviewer",agents:n,currentUserId:r,onChange:X=>a==null?void 0:a(t.id,X)}):s.jsx(FC,{principal:Z})})]})]}),ee||B?s.jsxs("div",{className:"sr-only",children:[ee?s.jsxs("span",{children:["Assignee · ",ee]}):null,B?s.jsxs("span",{children:["Reviewer · ",B]}):null]}):null]}):k?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"text-base font-medium text-foreground",children:String(k.summary)}),s.jsxs("div",{className:"mt-1 text-xs font-medium text-muted-foreground",children:["Target · ",String(k.targetType),":",String(k.targetId)]})]}):j?s.jsx("div",{className:"text-base font-medium text-foreground",children:j.title}):null,E&&(!v||_!=="pending")?s.jsx("p",{className:"mt-3 text-sm leading-6 text-muted-foreground",children:E}):null]})}),v?s.jsxs("section",{className:"border-t border-[color:var(--border-soft)] px-5 py-4",children:[s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[s.jsx("div",{className:"text-sm font-semibold text-foreground",children:"Proposal details"}),H?s.jsxs("button",{type:"button","aria-controls":P,"aria-expanded":Y,className:"inline-flex items-center gap-1 rounded-[var(--radius-sm)] px-1.5 py-1 text-xs font-medium text-[color:var(--accent-strong)] transition-colors hover:bg-[color:color-mix(in_oklab,var(--surface-proposal)_55%,transparent)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--ring)]",onClick:()=>V(X=>!X),children:[Y?"Show less":"Show full proposal",s.jsx(fr,{className:G("h-3.5 w-3.5 transition-transform duration-200",Y&&"rotate-180"),"aria-hidden":"true"})]}):null]}),s.jsx("div",{id:P,ref:le,className:G("chat-review-details-body text-sm leading-6 text-muted-foreground",!Y&&"chat-review-details-body--collapsed",H&&!Y&&"chat-review-details-body--can-expand"),children:s.jsx(Aa,{skillReferences:h,onLinkClick:g,children:W})})]}):null,j?s.jsxs("div",{className:"border-t border-[color:var(--border-soft)] px-5 py-4",children:[v?s.jsx("div",{className:"text-[11px] font-medium text-muted-foreground",children:j.title}):null,s.jsx("div",{className:"mt-3 text-sm leading-6 text-foreground",children:s.jsx(Aa,{skillReferences:h,onLinkClick:g,children:j.body})})]}):null,k!=null&&k.patch&&typeof k.patch=="object"?s.jsx("div",{className:"border-t border-[color:var(--border-soft)] px-5 py-4",children:s.jsx("pre",{className:"overflow-x-auto rounded-[var(--radius-lg)] border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-shell)_88%,transparent)] p-3 text-xs text-muted-foreground",children:JSON.stringify(k.patch,null,2)})}):null,L?s.jsxs("div",{className:"border-t border-[color:var(--border-soft)] px-5 py-5",children:[T?s.jsxs("label",{className:"block space-y-2",children:[s.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:M||C?"Feedback for agent":"Decision note"}),s.jsx(Na,{id:O,"data-testid":"proposal-review-note",value:o,onChange:X=>l(X.target.value),placeholder:M||C?"Tell the agent what must change before approval.":"Optional note for approval or rejection.",className:"chat-field min-h-[88px] rounded-[var(--radius-lg)]"})]}):null,!T&&z?s.jsxs("div",{className:"chat-review-note mt-1 rounded-[var(--radius-lg)] px-4 py-3",children:[s.jsx("div",{className:"chat-review-note-header text-[11px] font-medium text-muted-foreground",children:Q}),s.jsx("p",{className:"chat-review-note-body mt-2 text-sm leading-6 text-foreground/90",children:z})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[N&&t.approval?s.jsxs(s.Fragment,{children:[s.jsx(ce,{size:"sm",className:"bg-green-700 text-white hover:bg-green-600 dark:bg-green-600 dark:hover:bg-green-500",disabled:f,onClick:()=>c(t.approval.id,"approve",t.id),children:"Approve"}),M?s.jsx(ce,{size:"sm",variant:"outline",className:"text-foreground",disabled:f,onClick:()=>c(t.approval.id,"requestRevision",t.id),children:"Request changes"}):null,s.jsx(ce,{size:"sm",variant:"outline",className:"border-destructive/30 text-destructive hover:bg-destructive/10",disabled:f,onClick:()=>c(t.approval.id,"reject",t.id),children:"Reject"})]}):null,C?s.jsxs(s.Fragment,{children:[s.jsx(ce,{size:"sm",className:"bg-green-700 text-white hover:bg-green-600 dark:bg-green-600 dark:hover:bg-green-500",disabled:f,onClick:()=>u(t.id,"approve",o),children:"Approve"}),s.jsx(ce,{size:"sm",variant:"outline",className:"text-foreground",disabled:f,onClick:()=>u(t.id,"requestRevision",o),children:"Request changes"}),s.jsx(ce,{size:"sm",variant:"outline",className:"border-destructive/30 text-destructive hover:bg-destructive/10",disabled:f,onClick:()=>u(t.id,"reject",o),children:"Reject"})]}):null,A?s.jsx(ce,{size:"sm",variant:"outline",className:"text-foreground",disabled:f,onClick:()=>d(t),children:"Create issue"}):null]})]}):null]})]})}const zC="opacity-0 pointer-events-none transition-opacity duration-150 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100";function b0({body:e,skillReferences:t,onMarkdownLinkClick:n,className:r}){return s.jsx("div",{className:G("min-w-0",r),children:s.jsx("div",{"data-testid":"chat-long-message-body",className:"min-w-0",children:s.jsx(Aa,{skillReferences:t,onLinkClick:n,children:e})})})}function BC(e,t){const n=e==null?void 0:e[t];return typeof n=="string"&&n.trim().length>0?n.trim():null}function Dwt(e){const t=e.structuredPayload;if(!t||t.eventType!=="issue_created")return null;const n=BC(t,"issueId"),i=BC(t,"issueIdentifier")??n;if(!i)return null;const a=e.body.indexOf(i);return a<0?null:{issueRef:i,prefix:e.body.slice(0,a),suffix:e.body.slice(a+i.length)}}function Lwt(e){const t=e.structuredPayload;if(!t||t.eventType!=="automation_source"&&t.eventType!=="automation_created")return null;const n=BC(t,"automationId"),r=BC(t,"automationTitle")??"automation";return n?{automationId:n,automationTitle:r}:null}function Z7e({message:e,skillReferences:t,onMarkdownLinkClick:n}){var a;const r=Dwt(e),i=Lwt(e);return i?((a=e.structuredPayload)==null?void 0:a.eventType)==="automation_created"?s.jsxs("span",{className:"min-w-0 flex-1 leading-5",children:["Created automation"," ",s.jsx(yt,{to:`/automations/${i.automationId}`,className:"chat-system-issue-link","aria-label":`Open automation ${i.automationTitle}`,children:i.automationTitle})," ","from this chat conversation."]}):s.jsxs("span",{className:"min-w-0 flex-1 leading-5",children:["From automation"," ",s.jsx(yt,{to:`/automations/${i.automationId}`,className:"chat-system-issue-link","aria-label":`Open automation ${i.automationTitle}`,children:i.automationTitle}),"."]}):r?s.jsxs("span",{className:"min-w-0 flex-1 leading-5",children:[r.prefix,s.jsx(yt,{to:`/issues/${r.issueRef}`,className:"chat-system-issue-link","aria-label":`Open issue ${r.issueRef}`,children:r.issueRef}),r.suffix]}):s.jsx(Aa,{skillReferences:t,onLinkClick:n,children:e.body})}function G7e({message:e,request:t,answered:n,conversation:r,agents:i,skillReferences:a,onMarkdownLinkClick:o}){return s.jsx("div",{"data-testid":"chat-ask-user-history",className:"flex justify-start transition-all duration-200",children:s.jsxs("div",{className:"group w-full max-w-3xl px-1 py-1",children:[s.jsx(h8,{replyingAgentId:e.replyingAgentId??null,conversation:r,agents:i}),e.body.trim().length>0?s.jsx(b0,{body:e.body,skillReferences:a,onMarkdownLinkClick:o,className:"max-w-[72ch] text-[15px] leading-7 text-foreground"}):null,s.jsxs("div",{className:"mt-3 max-w-[72ch] rounded-lg border border-border bg-card px-3 py-2.5 text-sm shadow-[var(--shadow-sm)]",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"font-medium text-foreground",children:n?"Input requested":"Input needed"}),s.jsx("span",{className:"rounded-full bg-muted px-2 py-0.5 text-[11px] text-muted-foreground",children:n?"Answered":"Waiting"})]}),s.jsx("div",{className:"mt-1.5 space-y-1 text-muted-foreground",children:t.questions.map(l=>s.jsx("div",{className:"truncate",children:z5(l)},l.id))})]})]})})}function AH({answer:e}){return s.jsxs("div",{"data-testid":"chat-ask-user-answer",className:"chat-message-user w-fit max-w-[min(100%,72ch)] rounded-[var(--radius-xl)] px-4 py-3 shadow-[var(--shadow-sm)]","aria-label":"Answered requested input",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-foreground",children:[s.jsx(Mo,{className:"h-4 w-4 text-[color:var(--accent-strong)]","aria-hidden":!0}),s.jsx("span",{children:"Answered"})]}),s.jsx("div",{className:"mt-2 space-y-2",children:e.map(t=>s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:t.title}),s.jsx("div",{className:"mt-0.5 whitespace-pre-wrap text-[15px] leading-6 text-foreground",children:t.answer})]},t.questionId))})]})}function Q7e({message:e,request:t,disabled:n,pendingFiles:r,onAddAttachment:i,onRemovePendingFile:a,onOpenAttachmentPreview:o,onSubmit:l}){const[c,u]=x.useState({}),[d,f]=x.useState({}),[h,g]=x.useState(0),[b,v]=x.useState(!1);x.useEffect(()=>{u({}),f({}),g(0),v(!1)},[e.id]);const j=x.useMemo(()=>{var Q,ee;const L={};for(const B of t.questions){const F=c[B.id]??[],Z=B.selectionMode==="multiple";if(!Z&&F[0]==="__other"){const $=((Q=d[B.id])==null?void 0:Q.trim())??"";$&&(L[B.id]={kind:"freeform",text:$});continue}const W=F.filter($=>$!=="__other").map($=>{var Y;return(Y=B.options.find(V=>V.id===$))==null?void 0:Y.label}).filter($=>!!$);if(F.includes("__other")){const $=((ee=d[B.id])==null?void 0:ee.trim())??"";$&&W.push(`Other: ${$}`)}W.length>0&&(L[B.id]=Z?{kind:"options",labels:W}:{kind:"option",label:W[0]??""})}return L},[d,t.questions,c]),k=t.questions.length,w=k>1,N=Math.min(h,Math.max(k-1,0)),C=t.questions[N]??null,A=r.length>0,_=r.length===1?"See attached file.":"See attached files.",E=x.useMemo(()=>{if(!A)return j;const L={...j};for(const Q of t.questions){if(L[Q.id])continue;(c[Q.id]??[]).includes("__other")&&(L[Q.id]=Q.selectionMode==="multiple"?{kind:"options",labels:[`Other: ${_}`]}:{kind:"freeform",text:_})}return L},[_,j,A,t.questions,c]),T=C?E[C.id]:null,M=t.questions.every(L=>!!E[L.id]),O=L=>{if(w){if(L<k-1){g(L+1),v(!1);return}v(!0)}},P=L=>(L==null?void 0:L.kind)==="freeform"?L.text:(L==null?void 0:L.kind)==="options"?L.labels.join(", "):(L==null?void 0:L.label)??"Not answered",z=(L,Q,ee)=>{const B=L.selectionMode==="multiple";u(F=>{const Z=F[L.id]??[];if(!B)return{...F,[L.id]:[ee]};const W=Z.includes(ee)?Z.filter($=>$!==ee):[...Z,ee];return{...F,[L.id]:W}}),!B&&ee!=="__other"&&O(Q)};return s.jsxs("div",{"data-testid":"chat-ask-user-panel",className:"rounded-[var(--radius-lg)] border border-[color:color-mix(in_oklab,var(--accent-base)_35%,var(--border))] bg-[color:color-mix(in_oklab,var(--accent-soft)_28%,var(--surface-elevated))] p-3 shadow-[var(--shadow-sm)]",children:[w?s.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3 text-xs text-muted-foreground",children:[s.jsx("span",{children:b?"Review answers":`Question ${N+1} of ${k}`}),s.jsxs("span",{children:[Object.keys(E).length,"/",k," answered"]})]}):null,b?s.jsxs("section",{className:"rounded-[var(--radius-md)] border border-border bg-card/85 p-3",children:[s.jsx("div",{className:"text-sm font-medium text-foreground",children:"Review answers"}),s.jsx("div",{className:"mt-2 space-y-2",children:t.questions.map((L,Q)=>{const ee=E[L.id];return s.jsxs("button",{type:"button",className:"flex w-full min-w-0 items-start justify-between gap-3 rounded-[var(--radius-md)] px-2 py-1.5 text-left text-sm hover:bg-[color:var(--surface-active)]",onClick:()=>{g(Q),v(!1)},children:[s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"block truncate font-medium text-foreground",children:z5(L)}),s.jsx("span",{className:"mt-0.5 block whitespace-pre-wrap break-words text-muted-foreground",children:P(ee)})]}),s.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:"Edit"})]},L.id)})})]}):C?s.jsxs("section",{className:"rounded-[var(--radius-md)] border border-border bg-card/85 p-3",children:[s.jsx("div",{className:"text-sm font-medium text-foreground",children:z5(C)}),C.header&&C.header!==C.question?s.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:C.question}):null,s.jsxs("div",{className:"mt-2 grid gap-1.5",children:[C.options.map(L=>{const Q=c[C.id]??[],ee=C.selectionMode==="multiple",B=Q.includes(L.id);return s.jsxs("button",{type:"button",className:G("flex w-full items-start gap-2 rounded-[var(--radius-md)] border px-3 py-2 text-left text-sm transition-colors",B?"border-[color:var(--accent-base)] bg-[color:color-mix(in_oklab,var(--accent-soft)_62%,transparent)] text-foreground":"border-border bg-background/70 text-foreground hover:bg-[color:var(--surface-active)]"),"aria-pressed":B,onClick:()=>z(C,N,L.id),children:[s.jsx("span",{className:G("mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center border",ee?"rounded-[4px]":"rounded-full",B?"border-[color:var(--accent-base)] bg-[color:var(--accent-base)] text-primary-foreground":"border-border"),"aria-hidden":!0,children:B?s.jsx(Mo,{className:"h-3 w-3"}):null}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsxs("span",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[s.jsx("span",{className:"font-medium",children:L.label}),L.recommended?s.jsx("span",{className:"rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground",children:"Recommended"}):null]}),L.description?s.jsx("span",{className:"mt-0.5 block text-xs leading-5 text-muted-foreground",children:L.description}):null]})]},L.id)}),C.allowFreeform!==!1?s.jsxs("button",{type:"button",className:G("flex w-full items-center gap-2 rounded-[var(--radius-md)] border px-3 py-2 text-left text-sm transition-colors",(c[C.id]??[]).includes("__other")?"border-[color:var(--accent-base)] bg-[color:color-mix(in_oklab,var(--accent-soft)_62%,transparent)]":"border-border bg-background/70 hover:bg-[color:var(--surface-active)]"),"aria-pressed":(c[C.id]??[]).includes("__other"),onClick:()=>z(C,N,"__other"),children:[s.jsx("span",{className:G("flex h-4 w-4 shrink-0 items-center justify-center border",C.selectionMode==="multiple"?"rounded-[4px]":"rounded-full",(c[C.id]??[]).includes("__other")?"border-[color:var(--accent-base)] bg-[color:var(--accent-base)] text-primary-foreground":"border-border"),"aria-hidden":!0,children:(c[C.id]??[]).includes("__other")?s.jsx(Mo,{className:"h-3 w-3"}):null}),s.jsx("span",{className:"font-medium text-foreground",children:"Other"})]}):null]}),(c[C.id]??[]).includes("__other")?s.jsxs("div",{className:"mt-2 space-y-2",children:[s.jsx(Na,{value:d[C.id]??"",onChange:L=>f(Q=>({...Q,[C.id]:L.target.value})),placeholder:"Type your answer...",className:"min-h-20 resize-y rounded-[var(--radius-md)] bg-background text-sm"}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(ce,{type:"button",variant:"outline",size:"sm",disabled:n,onClick:i,className:"h-8 gap-1.5 px-2.5 text-xs",children:[s.jsx(b1,{className:"h-3.5 w-3.5"}),"Attach"]}),A?s.jsx("div",{"data-testid":"chat-ask-user-pending-attachments",className:"flex min-w-0 flex-wrap gap-2",children:r.map(L=>{const Q=UC(L);return s.jsx("div",{"data-testid":"chat-ask-user-pending-attachment",className:"max-w-full",children:s.jsx(G6,{file:L,onOpenImage:o,onRemove:()=>a(Q)})},Q)})}):null]})]}):null]},C.id):null,!(c[(C==null?void 0:C.id)??""]??[]).includes("__other")&&A?s.jsx("div",{"data-testid":"chat-ask-user-pending-attachments",className:"mt-3 flex min-w-0 flex-wrap gap-2",children:r.map(L=>{const Q=UC(L);return s.jsx("div",{"data-testid":"chat-ask-user-pending-attachment",className:"max-w-full",children:s.jsx(G6,{file:L,onOpenImage:o,onRemove:()=>a(Q)})},Q)})}):null,s.jsxs("div",{className:"mt-3 flex items-center justify-between gap-2",children:[w?s.jsx(ce,{type:"button",variant:"ghost",size:"sm",disabled:n||!b&&N===0,onClick:()=>{if(b){g(k-1),v(!1);return}g(L=>Math.max(L-1,0))},children:"Back"}):s.jsx("span",{"aria-hidden":!0}),w&&!b?s.jsx(ce,{type:"button",size:"sm",disabled:n||!T,onClick:()=>O(N),children:N===k-1?"Review answers":"Next"}):s.jsx(ce,{type:"button",size:"sm",disabled:n||!M,onClick:()=>l(g9t(t,E)),children:"Submit answer"})]})]})}function sj({conversation:e,message:t,agents:n,currentUserId:r,issueProposalOverride:i,decisionNote:a,onDecisionNoteChange:o,onApprovalAction:l,onIssueProposalChange:c,onResolveOperationProposal:u,onConvertToIssue:d,actionPending:f,onCopyMessageText:h,onEditUserMessage:g,onContinueInterruptedMessage:b,onRetryFailedMessage:v,onOpenImage:j,onOpenFile:k,onMarkdownLinkClick:w,turnBranchControls:N,skillReferences:C,answered:A,askUserAnswer:_}){if(t.kind==="issue_proposal"||t.kind==="operation_proposal")return s.jsx(Pwt,{conversation:e,message:t,agents:n,currentUserId:r,issueProposalOverride:i,onIssueProposalChange:c,decisionNote:a,onDecisionNoteChange:o,onApprovalAction:l,onResolveOperationProposal:u,onConvertToIssue:d,actionPending:f,skillReferences:C,onMarkdownLinkClick:w});const E=CA(t);if(E)return s.jsx(G7e,{message:t,request:E,answered:A??!1,conversation:e,agents:n,skillReferences:C,onMarkdownLinkClick:w});if(t.role==="system")return s.jsx("div",{className:"chat-system-pill rounded-[calc(var(--radius-sm)+2px)] px-4 py-2 text-sm transition-all duration-200",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Mo,{className:"h-4 w-4 text-[color:var(--accent-strong)]"}),s.jsx(Z7e,{message:t,skillReferences:C,onMarkdownLinkClick:w})]})});const T=t.role==="user",M=T?null:i8e(t.status),O=v9t(t),P=w9t(t);return T?s.jsx("div",{className:"flex justify-end transition-all duration-200",children:s.jsxs("div",{className:"group flex max-w-[82%] flex-col items-end text-left",children:[_?s.jsx(AH,{answer:_}):s.jsxs("div",{"data-testid":"chat-user-message-bubble",className:"chat-message-user w-fit max-w-[min(100%,72ch)] rounded-[var(--radius-xl)] px-4 py-3 shadow-[var(--shadow-sm)]",children:[s.jsx(b0,{body:t.body,skillReferences:C,onMarkdownLinkClick:w,className:"text-[15px] leading-7"}),s.jsx(rj,{attachments:t.attachments,onOpenImage:j,onOpenFile:k})]}),_&&t.attachments.length>0?s.jsx(rj,{attachments:t.attachments,onOpenImage:j,onOpenFile:k}):null,s.jsxs("div",{"data-testid":"chat-user-message-toolbar",className:G("mt-1 flex h-7 items-center justify-end gap-1 text-muted-foreground",zC),children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground","aria-label":"Copy message",onClick:()=>void h(t.body),children:s.jsx(Ni,{className:"h-4 w-4"})}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground","aria-label":"Edit message in composer",onClick:()=>g(t),children:s.jsx(s4,{className:"h-4 w-4"})}),N?s.jsxs("span",{className:"inline-flex items-center gap-0.5 rounded-md px-0.5 text-[11px] tabular-nums text-muted-foreground",children:[s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground disabled:pointer-events-none disabled:opacity-30","aria-label":"Previous branch",disabled:!N.canPrev,onClick:N.onPrev,children:s.jsx(Lz,{className:"h-4 w-4"})}),s.jsxs("span",{className:"min-w-[2.25rem] text-center",children:[N.current,"/",N.total]}),s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground disabled:pointer-events-none disabled:opacity-30","aria-label":"Next branch",disabled:!N.canNext,onClick:N.onNext,children:s.jsx(Ls,{className:"h-4 w-4"})})]}):null,s.jsx(m5,{date:t.createdAt,label:js(t.createdAt),className:"px-1 text-[11px] tracking-normal"})]})]})}):s.jsx("div",{"data-testid":"chat-assistant-message",className:"flex justify-start transition-all duration-200",children:s.jsxs("div",{className:"group w-full max-w-3xl px-1 py-1",children:[s.jsx(h8,{replyingAgentId:t.replyingAgentId??null,conversation:e,agents:n}),M?s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx("span",{className:G("rounded-full px-2 py-0.5 text-[10px]",a8e(t.status)),children:M}),O?s.jsx("button",{type:"button",className:"inline-flex h-7 items-center rounded-md border border-amber-500/30 bg-amber-500/10 px-2 text-xs font-medium text-amber-700 transition-[background-color,border-color,color,box-shadow] hover:border-amber-500/70 hover:bg-amber-500/25 hover:text-amber-950 hover:shadow-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500/35 dark:text-amber-300 dark:hover:text-amber-100",onClick:()=>b(t),children:"Continue"}):null,P?s.jsxs("button",{type:"button",className:"inline-flex h-7 items-center gap-1.5 rounded-md border border-destructive/30 bg-destructive/10 px-2 text-xs font-medium text-destructive transition-colors hover:bg-destructive/15",onClick:()=>v(t),children:[s.jsx(Qv,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Retry"]}):null]}):null,s.jsx(b0,{body:t.body,skillReferences:C,onMarkdownLinkClick:w,className:"max-w-[72ch] text-[15px] leading-7 text-foreground"}),s.jsx(H7e,{message:t}),s.jsx(rj,{attachments:t.attachments,onOpenImage:j,onOpenFile:k}),s.jsxs("div",{className:G("mt-2 flex h-7 items-center gap-1 text-muted-foreground",zC),children:[s.jsx(m5,{date:t.createdAt,label:js(t.createdAt),className:"text-[11px] tracking-normal"}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground","aria-label":"Copy message",onClick:()=>void h(t.body),children:s.jsx(Ni,{className:"h-4 w-4"})})]})]})})}function Y7e({body:e,createdAt:t,onCopyMessageText:n,onEditDraftOnly:r,skillReferences:i,onMarkdownLinkClick:a,askUserAnswer:o}){return s.jsx("div",{className:"flex justify-end transition-all duration-200",children:s.jsxs("div",{className:"group flex max-w-[82%] flex-col items-end text-left",children:[o?s.jsx(AH,{answer:o}):s.jsx("div",{className:"chat-message-user w-fit max-w-[min(100%,72ch)] rounded-[var(--radius-xl)] px-4 py-3 shadow-[var(--shadow-sm)]",children:s.jsx(b0,{body:e,skillReferences:i,onMarkdownLinkClick:a,className:"text-[15px] leading-7"})}),s.jsxs("div",{className:G("mt-1 flex h-7 items-center justify-end gap-1 text-muted-foreground",zC),children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground","aria-label":"Copy message",onClick:()=>void n(e),children:s.jsx(Ni,{className:"h-4 w-4"})}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground","aria-label":"Edit message in composer",onClick:()=>r(e),children:s.jsx(s4,{className:"h-4 w-4"})}),s.jsx(m5,{date:t,label:js(t),className:"px-1 text-[11px] tracking-normal"})]})]})})}function J7e(){return s.jsxs("div",{className:"flex flex-col gap-5 pb-2",children:[s.jsx("div",{className:"flex justify-end",children:s.jsx("div",{className:"chat-message-user w-fit max-w-[min(100%,72ch)] rounded-[var(--radius-xl)] px-4 py-3 shadow-[var(--shadow-sm)]",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx(Et,{className:"ml-auto h-4 w-[18rem]"}),s.jsx(Et,{className:"ml-auto h-4 w-[13rem]"})]})})}),s.jsx("div",{className:"flex justify-start",children:s.jsx("div",{className:"w-full max-w-3xl rounded-[var(--radius-xl)] px-1 py-4",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx(Et,{className:"h-4 w-[92%]"}),s.jsx(Et,{className:"h-4 w-[84%]"}),s.jsx(Et,{className:"h-4 w-[76%]"})]})})})]})}function D$({entries:e,state:t,streamStartedAt:n,streamEndedAt:r,assistantMessageBody:i,showDeveloperDiagnostics:a,defaultOpen:o=!1,onOpenChange:l}){const c=t==="streaming"||t==="finalizing",[u,d]=x.useState(()=>c||o),[f,h]=x.useState(0);x.useEffect(()=>{if(!c)return;const j=window.setInterval(()=>h(k=>k+1),500);return()=>clearInterval(j)},[c]),x.useEffect(()=>{o&&d(!0)},[o]);const g=x.useMemo(()=>{const j=n.getTime(),k=(r==null?void 0:r.getTime())??0,w=c?Date.now():Math.max(U7e(e),k);return Math.max(0,w-j)},[n,r,c,e,f]);if(e.length===0)return null;const b=t==="failed"?"Stopped with errors":t==="stopped"?"Stopped":"",v=u||c;return s.jsx("div",{"data-testid":"chat-transcript-item",className:"flex justify-start transition-all duration-200",children:s.jsxs("div",{className:"w-full max-w-3xl px-1 py-1",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"h-px min-w-[1rem] flex-1 bg-border/45","aria-hidden":!0}),s.jsxs("button",{type:"button",className:G("flex max-w-[min(100%,90%)] shrink-0 items-center gap-1.5 text-[12px] text-muted-foreground transition-colors",c?"cursor-default":"hover:text-foreground"),disabled:c,onClick:()=>{c||d(j=>{const k=!j;return l==null||l(k),k})},"aria-expanded":v,children:[c?s.jsx(yr,{className:"h-3.5 w-3.5 shrink-0 animate-spin","aria-hidden":!0}):null,s.jsxs("span",{className:"whitespace-nowrap",children:[c?"Working":"Worked"," for ",vwt(g)]}),b?s.jsxs("span",{className:"truncate text-amber-700/90 dark:text-amber-400/85",children:["· ",b]}):null,c?s.jsx(fr,{className:"h-4 w-4 shrink-0 opacity-60","aria-hidden":!0}):v?s.jsx(fr,{className:"h-4 w-4 shrink-0 opacity-60","aria-hidden":!0}):s.jsx(Ls,{className:"h-4 w-4 shrink-0 opacity-60","aria-hidden":!0})]}),s.jsx("div",{className:"h-px min-w-[1rem] flex-1 bg-border/45","aria-hidden":!0})]}),v?s.jsx("div",{className:"mt-3",children:s.jsx(Qf,{entries:e,mode:"nice",density:"compact",streaming:c,collapseStdout:!0,presentation:"chat",showDeveloperDiagnostics:a,hiddenAssistantMessageText:i})}):null]})})}function X7e({body:e,createdAt:t,state:n,replyingAgentId:r,conversation:i,agents:a,onCopyMessageText:o,skillReferences:l,onMarkdownLinkClick:c}){const u=n==="streaming"||n==="finalizing",d=u?null:i8e(n);return!e.trim()&&!u?null:s.jsx("div",{className:"flex justify-start transition-all duration-200",children:s.jsxs("div",{className:"group w-full max-w-3xl px-1 py-1",children:[s.jsx(h8,{replyingAgentId:r,conversation:i,agents:a}),d?s.jsx("div",{className:"mb-2 flex flex-wrap items-center gap-2 text-[11px] text-muted-foreground",children:s.jsx("span",{className:G("rounded-full px-2 py-0.5 text-[10px]",a8e(n)),children:d})}):null,s.jsx("div",{className:"max-w-[72ch] text-[15px] leading-7 text-foreground",children:e.trim()?s.jsx(b0,{body:e,skillReferences:l,onMarkdownLinkClick:c}):s.jsx(W7e,{text:"Thinking",className:"text-muted-foreground"})}),e.trim()?s.jsxs("div",{className:G("mt-2 flex h-7 items-center gap-1 text-muted-foreground",zC),children:[s.jsx(m5,{date:t,label:js(t),className:"text-[11px] tracking-normal"}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md hover:bg-[color:var(--surface-active)] hover:text-foreground","aria-label":"Copy message",onClick:()=>void o(e),children:s.jsx(Ni,{className:"h-4 w-4"})})]}):null]})})}const $wt="List my open tasks by priority",L$=[{label:"Scope a new feature",examples:["Plan an approval queue for budget overrides","Scope a weekly CEO status digest","Design an organization plugin install flow"]},{label:"Clarify a vague request",examples:["Turn rough notes into an implementation plan","Figure out what 'make Messenger less noisy' should mean","Translate a founder ask into acceptance criteria"]},{label:"Turn a chat into an issue",examples:[$wt,"Extract the next shippable task from this discussion","Split this conversation into scope, owner, and done criteria","Draft an issue from a decision we already made"]},{label:"Review a blocker",examples:["Diagnose why a packaged desktop build is failing","Review a confusing approval flow before more coding","Decide whether to patch the design or write a standard first"]}],jc="__none__",$$="rudder.chatLastProjectByOrg";function e8e({group:e,optionsId:t,entered:n,originX:r,onExampleSelect:i}){return s.jsxs("div",{id:t,"data-testid":"chat-empty-state-prompt-options","data-entered":n?"true":"false",role:"region","aria-label":`${e.label} examples`,style:{"--chat-options-origin-x":r},className:"motion-chat-options-pop mt-3 w-full max-w-3xl rounded-[var(--radius-lg)] border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-panel)_86%,transparent)] px-3 py-3 shadow-[var(--shadow-sm)]",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3",children:[s.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Example use cases"}),s.jsx("p",{className:"text-sm text-foreground",children:e.label})]}),s.jsx("div",{className:"flex flex-wrap gap-2",children:e.examples.map(a=>s.jsx("button",{type:"button","data-chat-option":!0,onClick:()=>i(a),className:"rounded-[calc(var(--radius-sm)+2px)] border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_72%,transparent)] px-3 py-2 text-left text-sm text-muted-foreground transition-colors hover:border-[color:var(--border-strong)] hover:bg-[color:var(--surface-active)] hover:text-foreground",children:a},a))})]},e.label)}function Fwt(e){if(!(typeof window>"u"))try{const t=window.localStorage.getItem($$);if(!t)return;const n=JSON.parse(t);if(!n||typeof n!="object")return;const r=n[e];return typeof r=="string"?r:r===null?null:void 0}catch{return}}function ok(e,t){if(!(typeof window>"u"))try{const n=window.localStorage.getItem($$),r=n?JSON.parse(n):{},i=r&&typeof r=="object"?r:{};i[e]=t,window.localStorage.setItem($$,JSON.stringify(i))}catch{}}function XR(e){var t;return((t=e==null?void 0:e.contextLinks.find(n=>n.entityType==="project"))==null?void 0:t.entityId)??null}function zwt(e,t){const n=t==null?void 0:t.trim();return n?(e??[]).find(r=>r.id===n||r.identifier===n)??null:null}function Bwt(e){var t;return e&&(((t=e.identifier)==null?void 0:t.trim())||e.title.trim())||"this issue"}function Uwt(e,t){const n=[];return t&&n.push({entityType:"issue",entityId:t}),e&&n.push({entityType:"project",entityId:e}),n}function qwt(e,t){var n;return e.assigneeAgentId?((n=t.get(e.assigneeAgentId))==null?void 0:n.name)??e.assigneeAgentId.slice(0,8):e.assigneeUserId?Ol(e.assigneeUserId,null)??e.assigneeUserId.slice(0,8):null}function eO(e){var t;return((t=e==null?void 0:e.name)==null?void 0:t.trim())||"Unknown project"}function Kwt({activeProjectName:e,userNickname:t,t:n}){const r=(e==null?void 0:e.trim())??"";if(r)return n("chat.emptyState.headingProject",{project:r});const i=(t==null?void 0:t.trim())??"";return i?n("chat.emptyState.headingNamed",{name:i}):n("chat.emptyState.heading")}function Hwt(e){return kBe(e)}const Ay=12,lk=10,Iie=128,Vwt=360,Mie=320;function Rie(e){const t=e.getBoundingClientRect(),n=window.innerWidth,r=window.innerHeight,i=Math.max(Mie,n-Ay*2),a=Math.min(Math.max(t.width,Mie),i),o=Math.min(Math.max(t.left,Ay),n-Ay-a),l=Math.max(0,t.top-Ay-lk),c=Math.max(0,r-t.bottom-Ay-lk),u=l>=Iie||l>=c,d=Math.max(Iie,Math.min(Vwt,u?l:c));return u?{left:o,width:a,bottom:r-t.top+lk,maxHeight:d}:{left:o,width:a,top:t.bottom+lk,maxHeight:d}}function Wwt(e){var r,i;const t=e.trim().toLowerCase();if(!t)return"bin";if(t==="text/plain")return"txt";if(t==="text/markdown")return"md";if(t==="application/json")return"json";if(t==="text/csv")return"csv";if(t==="text/html")return"html";if(t==="application/pdf")return"pdf";const n=(i=(r=t.split("/")[1])==null?void 0:r.split(";")[0])==null?void 0:i.trim();return n&&n.length>0?n:"bin"}async function Zwt(e,t){const n=await e.arrayBuffer(),r=e.name.trim()||`pasted-attachment-${t+1}.${Wwt(e.type)}`;return new File([n],r,{type:e.type,lastModified:e.lastModified||Date.now()})}function UC(e){return`${e.name}-${e.size}-${e.lastModified}`}function t8e(e){return e.originalFilename??e.name??e.assetId??"attachment"}function Gwt(e,t){return typeof window>"u"?{left:e,top:t}:{left:Math.min(e,Math.max(8,window.innerWidth-190)),top:Math.min(t,Math.max(8,window.innerHeight-96))}}function Qwt(e){return e.button===0&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey}const Ywt="No agents available",Oie="Read-only planning. The agent should investigate, produce a plan, and create an issue with that plan attached.";function Jwt(e,t){const n=new Map;for(const r of e)n.set(r.id,r);for(const r of t){const i=n.get(r.id);n.set(r.id,{...i??r,...r,replyingAgentId:r.replyingAgentId??(i==null?void 0:i.replyingAgentId)??null,chatTurnId:r.chatTurnId??(i==null?void 0:i.chatTurnId)??null,turnVariant:r.turnVariant??(i==null?void 0:i.turnVariant)??0,supersededAt:r.supersededAt??(i==null?void 0:i.supersededAt)??null})}return Array.from(n.values()).map(r=>({...r,replyingAgentId:r.replyingAgentId??null,chatTurnId:r.chatTurnId??null,turnVariant:r.turnVariant??0,supersededAt:r.supersededAt??null})).sort((r,i)=>new Date(r.createdAt).getTime()-new Date(i.createdAt).getTime())}function Xwt(e){e.scrollTo({top:e.scrollHeight,behavior:"auto"})}function e9t(e,t){const n=[...e].sort((c,u)=>new Date(c.createdAt).getTime()-new Date(u.createdAt).getTime());if(!t)return n.filter(c=>!c.supersededAt);const{chatTurnId:r,turnVariant:i}=t,a=n.filter(c=>c.chatTurnId===r&&c.turnVariant===i);if(a.length===0)return n.filter(c=>!c.supersededAt);const o=n.filter(c=>!c.supersededAt&&c.chatTurnId!==r),l=[...a].sort((c,u)=>new Date(c.createdAt).getTime()-new Date(u.createdAt).getTime());return[...o,...l].sort((c,u)=>new Date(c.createdAt).getTime()-new Date(u.createdAt).getTime())}function t9t(e,t,n){const r=e.filter(i=>i.id!==t.id);return n!=="all"&&t.status!==n?r:[t,...r]}function n9t(e,t){return fp(t)||fp(e.latestReplyPreview)||fp(e.summary)||"Start the conversation"}function F$(e){return e6(e)}function r9t(e,t){const n=n9t(e,t==null?void 0:t.preview);return{threadKey:`chat:${e.id}`,kind:"chat",title:F$(e),subtitle:n,preview:n,latestActivityAt:(t==null?void 0:t.latestActivityAt)??e.lastMessageAt??e.updatedAt,lastReadAt:e.lastReadAt,unreadCount:e.unreadCount,needsAttention:e.needsAttention,isPinned:e.isPinned,href:`/messenger/chat/${e.id}`}}function s9t(e,t){const n=e.filter(r=>r.threadKey!==t.threadKey);return[t,...n].sort((r,i)=>{const a=r.latestActivityAt?new Date(r.latestActivityAt).getTime():Number.NEGATIVE_INFINITY,o=i.latestActivityAt?new Date(i.latestActivityAt).getTime():Number.NEGATIVE_INFINITY;return a!==o?o-a:r.title.localeCompare(i.title)})}function i9t(e,t,n){const r=t.trim();return r?{...e,title:gBe(e.title,r),summary:e.summary??r,lastMessageAt:n,updatedAt:n}:e}function a9t(e,t){return e.planMode===t?e:{...e,planMode:t,updatedAt:new Date}}function o9t({hasConversation:e,preferredAgentId:t,hasLastMessageAt:n,hasMessages:r,hasActiveStream:i,hasActiveSendInFlight:a}){return!!(e&&(i||a||t&&(n||r)))}function l9t({hasConversation:e,hasLastMessageAt:t,hasMessages:n,hasActiveStream:r,hasActiveSendInFlight:i}){return!!(e&&(r||i||t||n))}function n8e(e){return(e==null?void 0:e.status)==="pending"}function Pie(e){var n;const t=(n=e.proposalTitle)==null?void 0:n.trim();return[t?`Please revise the proposal "${t}" based on the feedback below.`:"Please revise the current proposal based on the feedback below.","","Return a new proposal for review. Do not create the issue or apply the change yet.","","Requested changes:",e.feedback.trim()].join(`
1399
1399
  `)}function z$(e){const t=e.structuredPayload;if(!t)return null;const n=t.issueProposal&&typeof t.issueProposal=="object"&&!Array.isArray(t.issueProposal)?t.issueProposal:t;return typeof n.title!="string"||typeof n.description!="string"?null:n}function Die(e,t,n){var l;const r=t==="assignee"?"assigneeAgentId":"reviewerAgentId",i=t==="assignee"?"assigneeUserId":"reviewerUserId",a=typeof e[r]=="string"?e[r].trim():"";if(a)return((l=n==null?void 0:n.find(c=>c.id===a))==null?void 0:l.name)??(t==="assignee"?"Unknown agent":"Unknown reviewer");const o=typeof e[i]=="string"?e[i].trim():"";return o?Ol(o,null)??(t==="assignee"?"Human assignee":"Human reviewer"):null}function c9t(e){const t=e.structuredPayload;if(!t)return null;const n=t.planDocument&&typeof t.planDocument=="object"&&!Array.isArray(t.planDocument)?t.planDocument:t.plan&&typeof t.plan=="object"&&!Array.isArray(t.plan)?t.plan:null,r=typeof(n==null?void 0:n.body)=="string"?n.body.trim():"";return r?{title:typeof(n==null?void 0:n.title)=="string"&&n.title.trim().length>0?n.title.trim():"Plan",body:r}:null}function B$(e){const t=e.structuredPayload;if(!t)return null;const n=t.operationProposal&&typeof t.operationProposal=="object"&&!Array.isArray(t.operationProposal)?t.operationProposal:t;return typeof n.targetType!="string"||typeof n.targetId!="string"||typeof n.summary!="string"?null:n}function EH(e){var r;const t=(r=e.structuredPayload)!=null&&r.operationProposalState&&typeof e.structuredPayload.operationProposalState=="object"&&!Array.isArray(e.structuredPayload.operationProposalState)?e.structuredPayload.operationProposalState:null,n=typeof(t==null?void 0:t.status)=="string"?t.status:"pending";return n==="approved"||n==="rejected"||n==="revision_requested"||n==="pending"?n:"pending"}function u9t(e){var r;const t=(r=e.structuredPayload)!=null&&r.operationProposalState&&typeof e.structuredPayload.operationProposalState=="object"&&!Array.isArray(e.structuredPayload.operationProposalState)?e.structuredPayload.operationProposalState:null;return(typeof(t==null?void 0:t.decisionNote)=="string"?t.decisionNote.trim():"")||null}function d9t(e){if(e.approval){const{status:t}=e.approval;if(t==="pending"||t==="approved"||t==="rejected"||t==="revision_requested")return t}return e.kind==="operation_proposal"?EH(e):null}function f9t(e){return e==="approved"?"Approved. This proposal has been accepted.":e==="rejected"?"Rejected. This proposal will not move forward.":e==="revision_requested"?"Changes requested. Keep review context here until the proposal is updated.":e==="pending"?"Review this proposal here before continuing the conversation.":null}function CA(e){return e.kind!=="ask_user"?null:uRe(e.structuredPayload)}function m9t(e,t){if(e.kind!=="ask_user")return!1;const n=t.findIndex(r=>r.id===e.id);return n<0?!1:t.slice(n+1).some(r=>r.role==="user"&&!r.supersededAt)}function h9t(e){for(let t=e.length-1;t>=0;t-=1){const n=e[t];if(n&&!(n.kind!=="ask_user"||n.supersededAt)&&CA(n)&&!e.slice(t+1).some(r=>r.role==="user"&&!r.supersededAt))return n}return null}function z5(e){var t;return((t=e.header)==null?void 0:t.trim())||e.question}const r8e="Answering the requested input:";function p9t(e){const[t="",...n]=e.replace(/\r\n/g,`
1400
1400
  `).split(`
1401
1401
  `);return[` Answer: ${t}`,...n.map(r=>` ${r}`)]}function g9t(e,t){const n=[r8e];for(const r of e.questions){const i=t[r.id];if(!i)continue;const a=z5(r),o=i.kind==="freeform"?i.text:i.kind==="options"?i.labels.join(", "):i.label;n.push(""),n.push(`- ${a}`),n.push(...p9t(o))}return n.join(`