@paperclipai/server 0.3.0-canary.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/package.json +10 -10
  2. package/ui-dist/assets/{_basePickBy-D5lUMN0L.js → _basePickBy-BYrQlacK.js} +1 -1
  3. package/ui-dist/assets/{_baseUniq-DKtlPW-x.js → _baseUniq-DOSawgF3.js} +1 -1
  4. package/ui-dist/assets/{arc-DiGvh1x1.js → arc-CG7T0hfG.js} +1 -1
  5. package/ui-dist/assets/{architectureDiagram-VXUJARFQ-CnouQX_k.js → architectureDiagram-VXUJARFQ-Bcn7ytDO.js} +1 -1
  6. package/ui-dist/assets/{blockDiagram-VD42YOAC-DUuicXlz.js → blockDiagram-VD42YOAC-BQGrx2lv.js} +1 -1
  7. package/ui-dist/assets/{c4Diagram-YG6GDRKO-De9LeP_Z.js → c4Diagram-YG6GDRKO-owH9Kb3t.js} +1 -1
  8. package/ui-dist/assets/channel-DdXqC9Qy.js +1 -0
  9. package/ui-dist/assets/{chunk-4BX2VUAB-CPAs3LbP.js → chunk-4BX2VUAB-DY1UIe4g.js} +1 -1
  10. package/ui-dist/assets/{chunk-55IACEB6-nsONV40K.js → chunk-55IACEB6-CnWFPfPQ.js} +1 -1
  11. package/ui-dist/assets/{chunk-B4BG7PRW-cMiFBh_f.js → chunk-B4BG7PRW-DhlLW80l.js} +1 -1
  12. package/ui-dist/assets/{chunk-DI55MBZ5-D0bbaqRH.js → chunk-DI55MBZ5-DPt7dj6c.js} +1 -1
  13. package/ui-dist/assets/{chunk-FMBD7UC4-BcPITHeA.js → chunk-FMBD7UC4-GQwzgYa4.js} +1 -1
  14. package/ui-dist/assets/{chunk-QN33PNHL-CDoDSdfv.js → chunk-QN33PNHL-BFHLVk5s.js} +1 -1
  15. package/ui-dist/assets/{chunk-QZHKN3VN-BvRqGA5X.js → chunk-QZHKN3VN-CLe3KEAf.js} +1 -1
  16. package/ui-dist/assets/{chunk-TZMSLE5B-B3CRFcn6.js → chunk-TZMSLE5B-BhccYB4e.js} +1 -1
  17. package/ui-dist/assets/classDiagram-2ON5EDUG-ZV36NLFv.js +1 -0
  18. package/ui-dist/assets/classDiagram-v2-WZHVMYZB-ZV36NLFv.js +1 -0
  19. package/ui-dist/assets/clone-CvxIjPQa.js +1 -0
  20. package/ui-dist/assets/{cose-bilkent-S5V4N54A-C_xs8FvV.js → cose-bilkent-S5V4N54A-DqECYL1w.js} +1 -1
  21. package/ui-dist/assets/{dagre-6UL2VRFP-CWCUf_Lc.js → dagre-6UL2VRFP-DXeQqIJ2.js} +1 -1
  22. package/ui-dist/assets/{diagram-PSM6KHXK-C-HYlEiW.js → diagram-PSM6KHXK-DNu3Ctuy.js} +1 -1
  23. package/ui-dist/assets/{diagram-QEK2KX5R-5e5_NzxV.js → diagram-QEK2KX5R-1wUR_z9S.js} +1 -1
  24. package/ui-dist/assets/{diagram-S2PKOQOG-BmPqztvf.js → diagram-S2PKOQOG-D3IK8rZb.js} +1 -1
  25. package/ui-dist/assets/{erDiagram-Q2GNP2WA-B1qw7_FY.js → erDiagram-Q2GNP2WA-DU3L0RbU.js} +1 -1
  26. package/ui-dist/assets/{flowDiagram-NV44I4VS-DBQ0PFfm.js → flowDiagram-NV44I4VS-CN46A5Ez.js} +1 -1
  27. package/ui-dist/assets/{ganttDiagram-JELNMOA3-DY5cSTLF.js → ganttDiagram-JELNMOA3-DGbOi1Wz.js} +1 -1
  28. package/ui-dist/assets/{gitGraphDiagram-V2S2FVAM-DfSqJIFQ.js → gitGraphDiagram-V2S2FVAM-D98N7SOj.js} +1 -1
  29. package/ui-dist/assets/{graph-BP_RCbTu.js → graph-Cf7LCNJy.js} +1 -1
  30. package/ui-dist/assets/{index-CjQjoAz7.js → index--K1VLoF-.js} +1 -1
  31. package/ui-dist/assets/{index-aEHzrjcE.js → index-0BSerEC2.js} +1 -1
  32. package/ui-dist/assets/{index-B8hXk4LB.js → index-B-xuGUs-.js} +1 -1
  33. package/ui-dist/assets/{index-CtaVukcz.js → index-BD6My-aI.js} +1 -1
  34. package/ui-dist/assets/{index-pa9UoX78.js → index-BYw6Loly.js} +4 -4
  35. package/ui-dist/assets/{index-DTIo8uPQ.js → index-Beb2ZlSv.js} +1 -1
  36. package/ui-dist/assets/{index-CpmFy7gn.js → index-BfG2u5u0.js} +1 -1
  37. package/ui-dist/assets/{index-MBe5yEwm.js → index-BoAYxRAO.js} +1 -1
  38. package/ui-dist/assets/{index-BoyoInHy.js → index-C2-SE7P0.js} +1 -1
  39. package/ui-dist/assets/{index-CBSSPM1S.js → index-CI56poQD.js} +1 -1
  40. package/ui-dist/assets/{index-DfZRO-Sg.js → index-CP1BgxcV.js} +1 -1
  41. package/ui-dist/assets/{index-B5vJuk6w.js → index-Cick_QSL.js} +1 -1
  42. package/ui-dist/assets/{index-BRFNvIHS.js → index-CqG5WZHq.js} +1 -1
  43. package/ui-dist/assets/{index-B5lcBapM.js → index-D0EsfNYg.js} +1 -1
  44. package/ui-dist/assets/{index-B-qkRZNA.js → index-DB5nKqAA.js} +1 -1
  45. package/ui-dist/assets/{index-BHY-irKy.js → index-DXgtGequ.js} +1 -1
  46. package/ui-dist/assets/{index-CyUWI6Na.js → index-DZdNKByU.js} +1 -1
  47. package/ui-dist/assets/{index-D4gCO_aF.js → index-DiXE2gv-.js} +1 -1
  48. package/ui-dist/assets/{index-BRNSwivr.js → index-DujThSls.js} +1 -1
  49. package/ui-dist/assets/{index-B_3L_ixY.js → index-N1SX_i0z.js} +1 -1
  50. package/ui-dist/assets/{index-Dk1gv0CE.js → index-OkxoZoQy.js} +1 -1
  51. package/ui-dist/assets/{index-CruLAJPT.js → index-TFF7cXd7.js} +1 -1
  52. package/ui-dist/assets/{index-CDPRbL3N.js → index-cx0y6-1h.js} +1 -1
  53. package/ui-dist/assets/{infoDiagram-HS3SLOUP-DR9oY5-a.js → infoDiagram-HS3SLOUP-D_b1CK0Y.js} +1 -1
  54. package/ui-dist/assets/{journeyDiagram-XKPGCS4Q-KumVXYdq.js → journeyDiagram-XKPGCS4Q-4oCVXUve.js} +1 -1
  55. package/ui-dist/assets/{kanban-definition-3W4ZIXB7-DJU7FYaS.js → kanban-definition-3W4ZIXB7-0VcjP_qf.js} +1 -1
  56. package/ui-dist/assets/{layout-Dwrkxtrn.js → layout-BQcYXlNv.js} +1 -1
  57. package/ui-dist/assets/{linear-Df2MZ3xZ.js → linear-nz0Lfiys.js} +1 -1
  58. package/ui-dist/assets/{mermaid.core-CqZAL-kB.js → mermaid.core-BaxvgwjG.js} +4 -4
  59. package/ui-dist/assets/{mindmap-definition-VGOIOE7T-Dvxk8RjW.js → mindmap-definition-VGOIOE7T-BnW6nEhl.js} +1 -1
  60. package/ui-dist/assets/{pieDiagram-ADFJNKIX-DNhzkOZY.js → pieDiagram-ADFJNKIX-O1tvU_18.js} +1 -1
  61. package/ui-dist/assets/{quadrantDiagram-AYHSOK5B-rBLHbkvM.js → quadrantDiagram-AYHSOK5B-BfM2aQbf.js} +1 -1
  62. package/ui-dist/assets/{requirementDiagram-UZGBJVZJ-z2pd1nKR.js → requirementDiagram-UZGBJVZJ-rXVZupag.js} +1 -1
  63. package/ui-dist/assets/{sankeyDiagram-TZEHDZUN-_t0B7Xfo.js → sankeyDiagram-TZEHDZUN-BNgaPVo6.js} +1 -1
  64. package/ui-dist/assets/{sequenceDiagram-WL72ISMW-CuQKV2et.js → sequenceDiagram-WL72ISMW--KnZ0qRV.js} +1 -1
  65. package/ui-dist/assets/{stateDiagram-FKZM4ZOC-VqpbP0lR.js → stateDiagram-FKZM4ZOC-DlGdC88b.js} +1 -1
  66. package/ui-dist/assets/stateDiagram-v2-4FDKWEC3-CuVnpOfP.js +1 -0
  67. package/ui-dist/assets/{timeline-definition-IT6M3QCI-nyfhu7_P.js → timeline-definition-IT6M3QCI-CCwriy0-.js} +1 -1
  68. package/ui-dist/assets/{treemap-GDKQZRPO-C8_UXiS9.js → treemap-GDKQZRPO-C-79yojr.js} +1 -1
  69. package/ui-dist/assets/{xychartDiagram-PRI3JC2R-DEPrxhsP.js → xychartDiagram-PRI3JC2R-Dj0jcMBZ.js} +1 -1
  70. package/ui-dist/index.html +1 -1
  71. package/ui-dist/assets/channel-nzHnqxBH.js +0 -1
  72. package/ui-dist/assets/classDiagram-2ON5EDUG-C6QGJAqJ.js +0 -1
  73. package/ui-dist/assets/classDiagram-v2-WZHVMYZB-C6QGJAqJ.js +0 -1
  74. package/ui-dist/assets/clone-DElYSqOa.js +0 -1
  75. package/ui-dist/assets/stateDiagram-v2-4FDKWEC3-BHbVR_pJ.js +0 -1
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-B5lcBapM.js","assets/index-B_3L_ixY.js","assets/index-DfZRO-Sg.js","assets/index-DTIo8uPQ.js","assets/index-CtaVukcz.js","assets/index-Dk1gv0CE.js","assets/index-MBe5yEwm.js","assets/index-CjQjoAz7.js","assets/index-CBSSPM1S.js","assets/index-BRFNvIHS.js","assets/index-CruLAJPT.js","assets/index-D4gCO_aF.js","assets/index-B8hXk4LB.js","assets/index-B-qkRZNA.js","assets/index-CpmFy7gn.js","assets/index-CyUWI6Na.js","assets/index-B5vJuk6w.js","assets/index-BRNSwivr.js","assets/index-aEHzrjcE.js","assets/index-BoyoInHy.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-BHY-irKy.js","assets/index-CDPRbL3N.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-D0EsfNYg.js","assets/index-N1SX_i0z.js","assets/index-CP1BgxcV.js","assets/index-Beb2ZlSv.js","assets/index-BD6My-aI.js","assets/index-OkxoZoQy.js","assets/index-BoAYxRAO.js","assets/index--K1VLoF-.js","assets/index-CI56poQD.js","assets/index-CqG5WZHq.js","assets/index-TFF7cXd7.js","assets/index-DiXE2gv-.js","assets/index-B-xuGUs-.js","assets/index-DB5nKqAA.js","assets/index-BfG2u5u0.js","assets/index-DZdNKByU.js","assets/index-Cick_QSL.js","assets/index-DujThSls.js","assets/index-0BSerEC2.js","assets/index-C2-SE7P0.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-DXgtGequ.js","assets/index-cx0y6-1h.js"])))=>i.map(i=>d[i]);
2
2
  var ace=Object.defineProperty;var f7=t=>{throw TypeError(t)};var lce=(t,e,n)=>e in t?ace(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var Bi=(t,e,n)=>lce(t,typeof e!="symbol"?e+"":e,n),gE=(t,e,n)=>e.has(t)||f7("Cannot "+n);var se=(t,e,n)=>(gE(t,e,"read from private field"),n?n.call(t):e.get(t)),pt=(t,e,n)=>e.has(t)?f7("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),Ze=(t,e,n,r)=>(gE(t,e,"write to private field"),r?r.call(t,n):e.set(t,n),n),It=(t,e,n)=>(gE(t,e,"access private method"),n);var aw=(t,e,n,r)=>({set _(s){Ze(t,e,s,n)},get _(){return se(t,e,r)}});function cce(t,e){for(var n=0;n<e.length;n++){const r=e[n];if(typeof r!="string"&&!Array.isArray(r)){for(const s in r)if(s!=="default"&&!(s in t)){const i=Object.getOwnPropertyDescriptor(r,s);i&&Object.defineProperty(t,s,i.get?i:{enumerable:!0,get:()=>r[s]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const i of s)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(s){const i={};return s.integrity&&(i.integrity=s.integrity),s.referrerPolicy&&(i.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?i.credentials="include":s.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(s){if(s.ep)return;s.ep=!0;const i=n(s);fetch(s.href,i)}})();var h7=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ex(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function wKe(t){if(Object.prototype.hasOwnProperty.call(t,"__esModule"))return t;var e=t.default;if(typeof e=="function"){var n=function r(){return this instanceof r?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};n.prototype=e.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(t).forEach(function(r){var s=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,s.get?s:{enumerable:!0,get:function(){return t[r]}})}),n}var xE={exports:{}},w0={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.js
@@ -804,7 +804,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${e.do
804
804
  `))};if((dt.mac||dt.android)&&m.from==o-1&&/^\. ?$/.test(r.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(m={from:a,to:c,insert:Pn.of([r.text.replace("."," ")])}),this.pendingContextChange=m,!e.state.readOnly){let p=this.to-this.from+(m.to-m.from+m.insert.length);b9(e,m,De.single(this.toEditorPos(r.selectionStart,p),this.toEditorPos(r.selectionEnd,p)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),m.from<m.to&&!m.insert.length&&e.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 s=[],i=null;for(let o=this.toEditorPos(r.rangeStart),a=this.toEditorPos(r.rangeEnd);o<a;o++){let c=e.coordsForChar(o);i=c&&new DOMRect(c.left,c.top,c.right-c.left,c.bottom-c.top)||i||new DOMRect,s.push(i)}n.updateCharacterBounds(r.rangeStart,s)},this.handlers.textformatupdate=r=>{let s=[];for(let i of r.getTextFormats()){let o=i.underlineStyle,a=i.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(a)){let c=this.toEditorPos(i.rangeStart),d=this.toEditorPos(i.rangeEnd);if(c<d){let f=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(a)?1:2}px`;s.push(Mt.mark({attributes:{style:f}}).range(c,d))}}}e.dispatch({effects:Dne.of(Mt.set(s))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:r}=this.composing;this.composing=null,r&&this.reset(e.state)}};for(let r in this.handlers)n.addEventListener(r,this.handlers[r]);this.measureReq={read:r=>{this.editContext.updateControlBounds(r.contentDOM.getBoundingClientRect());let s=gb(r.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let n=0,r=!1,s=this.pendingContextChange;return e.changes.iterChanges((i,o,a,c,d)=>{if(r)return;let f=d.length-(o-i);if(s&&o>=s.to)if(s.from==i&&s.to==o&&s.insert.eq(d)){s=this.pendingContextChange=null,n+=f,this.to+=f;return}else s=null,this.revertPending(e.state);if(i+=n,o+=n,o<=this.from)this.from+=f,this.to+=f;else if(i<this.to){if(i<this.from||o>this.to||this.to-this.from+d.length>3e4){r=!0;return}this.editContext.updateText(this.toContextPos(i),this.toContextPos(o),d.toString()),this.to+=f}n+=f}),s&&!r&&this.revertPending(e.state),!r}update(e){let n=this.pendingContextChange,r=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(r.from,r.to)&&e.transactions.some(s=>!s.isUserEvent("input.type")&&s.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||n)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:n}=e.selection.main;this.from=Math.max(0,n-1e4),this.to=Math.min(e.doc.length,n+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let n=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(n.from),this.toContextPos(n.from+n.insert.length),e.doc.sliceString(n.from,n.to))}setSelection(e){let{main:n}=e.selection,r=this.toContextPos(Math.max(this.from,Math.min(this.to,n.anchor))),s=this.toContextPos(n.head);(this.editContext.selectionStart!=r||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(r,s)}rangeIsValid(e){let{head:n}=e.selection.main;return!(this.from>0&&n-this.from<500||this.to<e.doc.length&&this.to-n<500||this.to-this.from>1e4*3)}toEditorPos(e,n=this.to-this.from){e=Math.min(e,n);let r=this.composing;return r&&r.drifted?r.editorBase+(e-r.contextBase):e+this.from}toContextPos(e){let n=this.composing;return n&&n.drifted?n.contextBase+(e-n.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class at{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(e={}){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),e.parent&&e.parent.appendChild(this.dom);let{dispatch:r}=e;this.dispatchTransactions=e.dispatchTransactions||r&&(s=>s.forEach(i=>r(i,this)))||(s=>this.update(s)),this.dispatch=this.dispatch.bind(this),this._root=e.root||IOe(e.parent)||document,this.viewState=new Qz(e.state||Cn.create(e)),e.scrollTo&&e.scrollTo.is(zw)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Ip).map(s=>new Pj(s));for(let s of this.plugins)s.update(this);this.observer=new r9e(this),this.inputState=new NIe(this),this.inputState.ensureHandlers(this.plugins),this.docView=new $z(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(...e){let n=e.length==1&&e[0]instanceof is?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(n,this)}update(e){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,s,i=this.state;for(let p of e){if(p.startState!=i)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");i=p.state}if(this.destroyed){this.viewState.state=i;return}let o=this.hasFocus,a=0,c=null;e.some(p=>p.annotation(Zne))?(this.inputState.notifiedFocused=o,a=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,c=Qne(i,o),c||(a=1));let d=this.observer.delayedAndroidKey,f=null;if(d?(this.observer.clearDelayedAndroidKey(),f=this.observer.readChange(),(f&&!this.state.doc.eq(i.doc)||!this.state.selection.eq(i.selection))&&(f=null)):this.observer.clear(),i.facet(Cn.phrases)!=this.state.facet(Cn.phrases))return this.setState(i);s=Ak.create(this,i,e),s.flags|=a;let m=this.viewState.scrollTarget;try{this.updateState=2;for(let p of e){if(m&&(m=m.map(p.changes)),p.scrollIntoView){let{main:x}=p.state.selection;m=new Zp(x.empty?x:De.cursor(x.head,x.head>x.anchor?-1:1))}for(let x of p.effects)x.is(zw)&&(m=x.value.clip(this.state))}this.viewState.update(s,m),this.bidiCache=Ik.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),n=this.docView.update(s),this.state.facet(iy)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(n,e.some(p=>p.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(Ww)!=s.state.facet(Ww)&&(this.viewState.mustMeasureContent=!0),(n||r||m||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),n&&this.docViewUpdate(),!s.empty)for(let p of this.state.facet(F4))try{p(s)}catch(x){Xi(this.state,x,"update listener")}(c||f)&&Promise.resolve().then(()=>{c&&this.state==c.startState&&this.dispatch(c),f&&!Une(this,f)&&d.force&&Yp(this.contentDOM,d.key,d.keyCode)})}setState(e){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=e;return}this.updateState=2;let n=this.hasFocus;try{for(let r of this.plugins)r.destroy(this);this.viewState=new Qz(e),this.plugins=e.facet(Ip).map(r=>new Pj(r)),this.pluginMap.clear();for(let r of this.plugins)r.update(this);this.docView.destroy(),this.docView=new $z(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}n&&this.focus(),this.requestMeasure()}updatePlugins(e){let n=e.startState.facet(Ip),r=e.state.facet(Ip);if(n!=r){let s=[];for(let i of r){let o=n.indexOf(i);if(o<0)s.push(new Pj(i));else{let a=this.plugins[o];a.mustUpdate=e,s.push(a)}}for(let i of this.plugins)i.mustUpdate!=e&&i.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=e;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);n!=r&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let n=e.value;if(n&&n.docViewUpdate)try{n.docViewUpdate(this)}catch(r){Xi(this.state,r,"doc view update listener")}}}measure(e=!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,e&&this.observer.forceFlush();let n=null,r=this.scrollDOM,s=r.scrollTop*this.scaleY,{scrollAnchorPos:i,scrollAnchorHeight:o}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let a=0;;a++){if(o<0)if(yne(r))i=-1,o=this.viewState.heightMap.height;else{let x=this.viewState.scrollAnchorAt(s);i=x.from,o=x.top}this.updateState=1;let c=this.viewState.measure(this);if(!c&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(a>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let d=[];c&4||([this.measureRequests,d]=[d,this.measureRequests]);let f=d.map(x=>{try{return x.read(this)}catch(y){return Xi(this.state,y),rV}}),m=Ak.create(this,this.state,[]),p=!1;m.flags|=c,n?n.flags|=c:n=m,this.updateState=2,m.empty||(this.updatePlugins(m),this.inputState.update(m),this.updateAttrs(),p=this.docView.update(m),p&&this.docViewUpdate());for(let x=0;x<d.length;x++)if(f[x]!=rV)try{let y=d[x];y.write&&y.write(f[x],this)}catch(y){Xi(this.state,y)}if(p&&this.docView.updateSelection(!0),!m.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 y=(i<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(i).top)-o;if(y>1||y<-1){s=s+y,r.scrollTop=s/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(n&&!n.empty)for(let a of this.state.facet(F4))a(n)}get themeClasses(){return U4+" "+(this.state.facet(H4)?nre:tre)+" "+this.state.facet(Ww)}updateAttrs(){let e=sV(this,Lne,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),n={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(Zc)?"true":"false",class:"cm-content",style:`${dt.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(n["aria-readonly"]="true"),sV(this,g9,n);let r=this.observer.ignore(()=>{let s=Oz(this.contentDOM,this.contentAttrs,n),i=Oz(this.dom,this.editorAttrs,e);return s||i});return this.editorAttrs=e,this.contentAttrs=n,r}showAnnouncements(e){let n=!0;for(let r of e)for(let s of r.effects)if(s.is(at.announce)){n&&(this.announceDOM.textContent=""),n=!1;let i=this.announceDOM.appendChild(document.createElement("div"));i.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(iy);let e=this.state.facet(at.cspNonce);of.mount(this.root,this.styleModules.concat(t9e).reverse(),e?{nonce:e}: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(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let n=0;n<this.measureRequests.length;n++)if(this.measureRequests[n].key===e.key){this.measureRequests[n]=e;return}}this.measureRequests.push(e)}}plugin(e){let n=this.pluginMap.get(e);return(n===void 0||n&&n.plugin!=e)&&this.pluginMap.set(e,n=this.plugins.find(r=>r.plugin==e)||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(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,n,r){return zj(this,e,Bz(this,e,n,r))}moveByGroup(e,n){return zj(this,e,Bz(this,e,n,r=>gIe(this,e.head,r)))}visualLineSide(e,n){let r=this.bidiSpans(e),s=this.textDirectionAt(e.from),i=r[n?r.length-1:0];return De.cursor(i.side(n,s)+e.from,i.forward(!n,s)?1:-1)}moveToLineBoundary(e,n,r=!0){return pIe(this,e,n,r)}moveVertically(e,n,r){return zj(this,e,xIe(this,e,n,r))}domAtPos(e,n=1){return this.docView.domAtPos(e,n)}posAtDOM(e,n=0){return this.docView.posFromDOM(e,n)}posAtCoords(e,n=!0){this.readMeasured();let r=z4(this,e,n);return r&&r.pos}posAndSideAtCoords(e,n=!0){return this.readMeasured(),z4(this,e,n)}coordsAtPos(e,n=1){this.readMeasured();let r=this.docView.coordsAt(e,n);if(!r||r.left==r.right)return r;let s=this.state.doc.lineAt(e),i=this.bidiSpans(s),o=i[Ll.find(i,e-s.from,-1,n)];return jk(r,o.dir==lr.LTR==n>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(Rne)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>o9e)return Sne(e.length);let n=this.textDirectionAt(e.from),r;for(let i of this.bidiCache)if(i.from==e.from&&i.dir==n&&(i.fresh||kne(i.isolates,r=Lz(this,e))))return i.order;r||(r=Lz(this,e));let s=VOe(e.text,n,r);return this.bidiCache.push(new Ik(e.from,e.to,n,r,!0,s)),s}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||dt.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{xne(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.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(e,n={}){return zw.of(new Zp(typeof e=="number"?De.cursor(e):e,n.y,n.x,n.yMargin,n.xMargin))}scrollSnapshot(){let{scrollTop:e,scrollLeft:n}=this.scrollDOM,r=this.viewState.scrollAnchorAt(e);return zw.of(new Zp(De.cursor(r.from),"start","start",r.top-e,n,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return us.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return us.define(()=>({}),{eventObservers:e})}static theme(e,n){let r=of.newName(),s=[Ww.of(r),iy.of(q4(`.${r}`,e))];return n&&n.dark&&s.push(H4.of(!0)),s}static baseTheme(e){return Sf.lowest(iy.of(q4("."+U4,e,rre)))}static findFromDOM(e){var n;let r=e.querySelector(".cm-content"),s=r&&cs.get(r)||cs.get(e);return((n=s==null?void 0:s.root)===null||n===void 0?void 0:n.view)||null}}at.styleModule=iy;at.inputHandler=Tne;at.clipboardInputFilter=m9;at.clipboardOutputFilter=p9;at.scrollHandler=Ine;at.focusChangeEffect=Mne;at.perLineTextDirection=Rne;at.exceptionSink=Ane;at.updateListener=F4;at.editable=Zc;at.mouseSelectionStyle=jne;at.dragMovesSelection=Ene;at.clickAddsSelectionRange=Nne;at.decorations=V_;at.blockWrappers=Pne;at.outerDecorations=x9;at.atomicRanges=Fv;at.bidiIsolatedRanges=Fne;at.scrollMargins=$ne;at.darkTheme=H4;at.cspNonce=ut.define({combine:t=>t.length?t[0]:""});at.contentAttributes=g9;at.editorAttributes=Lne;at.lineWrapping=at.contentAttributes.of({class:"cm-lineWrapping"});at.announce=zt.define();const o9e=4096,rV={};class Ik{constructor(e,n,r,s,i,o){this.from=e,this.to=n,this.dir=r,this.isolates=s,this.fresh=i,this.order=o}static update(e,n){if(n.empty&&!e.some(i=>i.fresh))return e;let r=[],s=e.length?e[e.length-1].dir:lr.LTR;for(let i=Math.max(0,e.length-10);i<e.length;i++){let o=e[i];o.dir==s&&!n.touchesRange(o.from,o.to)&&r.push(new Ik(n.mapPos(o.from,1),n.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return r}}function sV(t,e,n){for(let r=t.state.facet(e),s=r.length-1;s>=0;s--){let i=r[s],o=typeof i=="function"?i(t):i;o&&d9(o,n)}return n}const a9e=dt.mac?"mac":dt.windows?"win":dt.linux?"linux":"key";function l9e(t,e){const n=t.split(/-(?!$)/);let r=n[n.length-1];r=="Space"&&(r=" ");let s,i,o,a;for(let c=0;c<n.length-1;++c){const d=n[c];if(/^(cmd|meta|m)$/i.test(d))a=!0;else if(/^a(lt)?$/i.test(d))s=!0;else if(/^(c|ctrl|control)$/i.test(d))i=!0;else if(/^s(hift)?$/i.test(d))o=!0;else if(/^mod$/i.test(d))e=="mac"?a=!0:i=!0;else throw new Error("Unrecognized modifier name: "+d)}return s&&(r="Alt-"+r),i&&(r="Ctrl-"+r),a&&(r="Meta-"+r),o&&(r="Shift-"+r),r}function Gw(t,e,n){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),n!==!1&&e.shiftKey&&(t="Shift-"+t),t}const c9e=Sf.default(at.domEventHandlers({keydown(t,e){return ire(sre(e.state),t,e,"editor")}})),$v=ut.define({enables:c9e}),iV=new WeakMap;function sre(t){let e=t.facet($v),n=iV.get(e);return n||iV.set(e,n=f9e(e.reduce((r,s)=>r.concat(s),[]))),n}function u9e(t,e,n){return ire(sre(t.state),e,t,n)}let Nd=null;const d9e=4e3;function f9e(t,e=a9e){let n=Object.create(null),r=Object.create(null),s=(o,a)=>{let c=r[o];if(c==null)r[o]=a;else if(c!=a)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},i=(o,a,c,d,f)=>{var m,p;let x=n[o]||(n[o]=Object.create(null)),y=a.split(/ (?!$)/).map(S=>l9e(S,e));for(let S=1;S<y.length;S++){let C=y.slice(0,S).join(" ");s(C,!0),x[C]||(x[C]={preventDefault:!0,stopPropagation:!1,run:[_=>{let E=Nd={view:_,prefix:C,scope:o};return setTimeout(()=>{Nd==E&&(Nd=null)},d9e),!0}]})}let w=y.join(" ");s(w,!1);let k=x[w]||(x[w]={preventDefault:!1,stopPropagation:!1,run:((p=(m=x._any)===null||m===void 0?void 0:m.run)===null||p===void 0?void 0:p.slice())||[]});c&&k.run.push(c),d&&(k.preventDefault=!0),f&&(k.stopPropagation=!0)};for(let o of t){let a=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let d of a){let f=n[d]||(n[d]=Object.create(null));f._any||(f._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:m}=o;for(let p in f)f[p].run.push(x=>m(x,K4))}let c=o[e]||o.key;if(c)for(let d of a)i(d,c,o.run,o.preventDefault,o.stopPropagation),o.shift&&i(d,"Shift-"+c,o.shift,o.preventDefault,o.stopPropagation)}return n}let K4=null;function ire(t,e,n,r){K4=e;let s=_Oe(e),i=Gi(s,0),o=Rl(i)==s.length&&s!=" ",a="",c=!1,d=!1,f=!1;Nd&&Nd.view==n&&Nd.scope==r&&(a=Nd.prefix+" ",Wne.indexOf(e.keyCode)<0&&(d=!0,Nd=null));let m=new Set,p=k=>{if(k){for(let S of k.run)if(!m.has(S)&&(m.add(S),S(n)))return k.stopPropagation&&(f=!0),!0;k.preventDefault&&(k.stopPropagation&&(f=!0),d=!0)}return!1},x=t[r],y,w;return x&&(p(x[a+Gw(s,e,!o)])?c=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(dt.windows&&e.ctrlKey&&e.altKey)&&!(dt.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(y=af[e.keyCode])&&y!=s?(p(x[a+Gw(y,e,!0)])||e.shiftKey&&(w=mb[e.keyCode])!=s&&w!=y&&p(x[a+Gw(w,e,!1)]))&&(c=!0):o&&e.shiftKey&&p(x[a+Gw(s,e,!0)])&&(c=!0),!c&&p(x._any)&&(c=!0)),d&&(c=!0),c&&f&&e.stopPropagation(),K4=null,c}class Bv{constructor(e,n,r,s,i){this.className=e,this.left=n,this.top=r,this.width=s,this.height=i}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,n){return n.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,n,r){if(r.empty){let s=e.coordsAtPos(r.head,r.assoc||1);if(!s)return[];let i=ore(e);return[new Bv(n,s.left-i.left,s.top-i.top,null,s.bottom-s.top)]}else return h9e(e,n,r)}}function ore(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==lr.LTR?e.left:e.right-t.scrollDOM.clientWidth*t.scaleX)-t.scrollDOM.scrollLeft*t.scaleX,top:e.top-t.scrollDOM.scrollTop*t.scaleY}}function oV(t,e,n,r){let s=t.coordsAtPos(e,n*2);if(!s)return r;let i=t.dom.getBoundingClientRect(),o=(s.top+s.bottom)/2,a=t.posAtCoords({x:i.left+1,y:o}),c=t.posAtCoords({x:i.right-1,y:o});return a==null||c==null?r:{from:Math.max(r.from,Math.min(a,c)),to:Math.min(r.to,Math.max(a,c))}}function h9e(t,e,n){if(n.to<=t.viewport.from||n.from>=t.viewport.to)return[];let r=Math.max(n.from,t.viewport.from),s=Math.min(n.to,t.viewport.to),i=t.textDirection==lr.LTR,o=t.contentDOM,a=o.getBoundingClientRect(),c=ore(t),d=o.querySelector(".cm-line"),f=d&&window.getComputedStyle(d),m=a.left+(f?parseInt(f.paddingLeft)+Math.min(0,parseInt(f.textIndent)):0),p=a.right-(f?parseInt(f.paddingRight):0),x=B4(t,r,1),y=B4(t,s,-1),w=x.type==Ks.Text?x:null,k=y.type==Ks.Text?y:null;if(w&&(t.lineWrapping||x.widgetLineBreaks)&&(w=oV(t,r,1,w)),k&&(t.lineWrapping||y.widgetLineBreaks)&&(k=oV(t,s,-1,k)),w&&k&&w.from==k.from&&w.to==k.to)return C(_(n.from,n.to,w));{let j=w?_(n.from,null,w):E(x,!1),R=k?_(null,n.to,k):E(y,!0),T=[];return(w||x).to<(k||y).from-(w&&k?1:0)||x.widgetLineBreaks>1&&j.bottom+t.defaultLineHeight/2<R.top?T.push(S(m,j.bottom,p,R.top)):j.bottom<R.top&&t.elementAtHeight((j.bottom+R.top)/2).type==Ks.Text&&(j.bottom=R.top=(j.bottom+R.top)/2),C(j).concat(T).concat(C(R))}function S(j,R,T,M){return new Bv(e,j-c.left,R-c.top,Math.max(0,T-j),M-R)}function C({top:j,bottom:R,horizontal:T}){let M=[];for(let O=0;O<T.length;O+=2)M.push(S(T[O],j,T[O+1],R));return M}function _(j,R,T){let M=1e9,O=-1e9,I=[];function $(W,J,G,F,L){let K=t.coordsAtPos(W,W==T.to?-2:2),D=t.coordsAtPos(G,G==T.from?2:-2);!K||!D||(M=Math.min(K.top,D.top,M),O=Math.max(K.bottom,D.bottom,O),L==lr.LTR?I.push(i&&J?m:K.left,i&&F?p:D.right):I.push(!i&&F?m:D.left,!i&&J?p:K.right))}let z=j??T.from,V=R??T.to;for(let W of t.visibleRanges)if(W.to>z&&W.from<V)for(let J=Math.max(W.from,z),G=Math.min(W.to,V);;){let F=t.state.doc.lineAt(J);for(let L of t.bidiSpans(F)){let K=L.from+F.from,D=L.to+F.from;if(K>=G)break;D>J&&$(Math.max(K,J),j==null&&K<=z,Math.min(D,G),R==null&&D>=V,L.dir)}if(J=F.to+1,J>=G)break}return I.length==0&&$(z,j==null,V,R==null,t.textDirection),{top:M,bottom:O,horizontal:I}}function E(j,R){let T=a.top+(R?j.top:j.bottom);return{top:T,bottom:T,horizontal:[]}}}function m9e(t,e){return t.constructor==e.constructor&&t.eq(e)}class p9e{constructor(e,n){this.view=e,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=e.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(e.state),e.requestMeasure(this.measureReq),n.mount&&n.mount(this.dom,e)}update(e){e.startState.facet(JC)!=e.state.facet(JC)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let n=0,r=e.facet(JC);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:e,scaleY:n}=this.view;(e!=this.scaleX||n!=this.scaleY)&&(this.scaleX=e,this.scaleY=n,this.dom.style.transform=`scale(${1/e}, ${1/n})`)}draw(e){if(e.length!=this.drawn.length||e.some((n,r)=>!m9e(n,this.drawn[r]))){let n=this.dom.firstChild,r=0;for(let s of e)s.update&&n&&s.constructor&&this.drawn[r].constructor&&s.update(n,this.drawn[r])?(n=n.nextSibling,r++):this.dom.insertBefore(s.draw(),n);for(;n;){let s=n.nextSibling;n.remove(),n=s}this.drawn=e,dt.safari&&dt.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 JC=ut.define();function are(t){return[us.define(e=>new p9e(e,t)),JC.of(t)]}const yb=ut.define({combine(t){return lc(t,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,n)=>Math.min(e,n),drawRangeCursor:(e,n)=>e||n})}});function g9e(t={}){return[yb.of(t),x9e,y9e,b9e,One.of(!0)]}function lre(t){return t.startState.facet(yb)!=t.state.facet(yb)}const x9e=are({above:!0,markers(t){let{state:e}=t,n=e.facet(yb),r=[];for(let s of e.selection.ranges){let i=s==e.selection.main;if(s.empty||n.drawRangeCursor){let o=i?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",a=s.empty?s:De.cursor(s.head,s.head>s.anchor?-1:1);for(let c of Bv.forRange(t,o,a))r.push(c)}}return r},update(t,e){t.transactions.some(r=>r.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let n=lre(t);return n&&aV(t.state,e),t.docChanged||t.selectionSet||n},mount(t,e){aV(e.state,t)},class:"cm-cursorLayer"});function aV(t,e){e.style.animationDuration=t.facet(yb).cursorBlinkRate+"ms"}const y9e=are({above:!1,markers(t){return t.state.selection.ranges.map(e=>e.empty?[]:Bv.forRange(t,"cm-selectionBackground",e)).reduce((e,n)=>e.concat(n))},update(t,e){return t.docChanged||t.selectionSet||t.viewportChanged||lre(t)},class:"cm-selectionLayer"}),b9e=Sf.highest(at.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"}}}})),cre=zt.define({map(t,e){return t==null?null:e.mapPos(t)}}),ly=Is.define({create(){return null},update(t,e){return t!=null&&(t=e.changes.mapPos(t)),e.effects.reduce((n,r)=>r.is(cre)?r.value:n,t)}}),v9e=us.fromClass(class{constructor(t){this.view=t,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(t){var e;let n=t.state.field(ly);n==null?this.cursor!=null&&((e=this.cursor)===null||e===void 0||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(t.startState.field(ly)!=n||t.docChanged||t.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:t}=this,e=t.state.field(ly),n=e!=null&&t.coordsAtPos(e);if(!n)return null;let r=t.scrollDOM.getBoundingClientRect();return{left:n.left-r.left+t.scrollDOM.scrollLeft*t.scaleX,top:n.top-r.top+t.scrollDOM.scrollTop*t.scaleY,height:n.bottom-n.top}}drawCursor(t){if(this.cursor){let{scaleX:e,scaleY:n}=this.view;t?(this.cursor.style.left=t.left/e+"px",this.cursor.style.top=t.top/n+"px",this.cursor.style.height=t.height/n+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(t){this.view.state.field(ly)!=t&&this.view.dispatch({effects:cre.of(t)})}},{eventObservers:{dragover(t){this.setDropPos(this.view.posAtCoords({x:t.clientX,y:t.clientY}))},dragleave(t){(t.target==this.view.contentDOM||!this.view.contentDOM.contains(t.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function w9e(){return[ly,v9e]}function lV(t,e,n,r,s){e.lastIndex=0;for(let i=t.iterRange(n,r),o=n,a;!i.next().done;o+=i.value.length)if(!i.lineBreak)for(;a=e.exec(i.value);)s(o+a.index,a)}function C9e(t,e){let n=t.visibleRanges;if(n.length==1&&n[0].from==t.viewport.from&&n[0].to==t.viewport.to)return n;let r=[];for(let{from:s,to:i}of n)s=Math.max(t.state.doc.lineAt(s).from,s-e),i=Math.min(t.state.doc.lineAt(i).to,i+e),r.length&&r[r.length-1].to>=s?r[r.length-1].to=i:r.push({from:s,to:i});return r}class k9e{constructor(e){const{regexp:n,decoration:r,decorate:s,boundary:i,maxLength:o=1e3}=e;if(!n.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=n,s)this.addMatch=(a,c,d,f)=>s(f,d,d+a[0].length,a,c);else if(typeof r=="function")this.addMatch=(a,c,d,f)=>{let m=r(a,c,d);m&&f(d,d+a[0].length,m)};else if(r)this.addMatch=(a,c,d,f)=>f(d,d+a[0].length,r);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=i,this.maxLength=o}createDeco(e){let n=new Su,r=n.add.bind(n);for(let{from:s,to:i}of C9e(e,this.maxLength))lV(e.state.doc,this.regexp,s,i,(o,a)=>this.addMatch(a,e,o,r));return n.finish()}updateDeco(e,n){let r=1e9,s=-1;return e.docChanged&&e.changes.iterChanges((i,o,a,c)=>{c>=e.view.viewport.from&&a<=e.view.viewport.to&&(r=Math.min(a,r),s=Math.max(c,s))}),e.viewportMoved||s-r>1e3?this.createDeco(e.view):s>-1?this.updateRange(e.view,n.map(e.changes),r,s):n}updateRange(e,n,r,s){for(let i of e.visibleRanges){let o=Math.max(i.from,r),a=Math.min(i.to,s);if(a>=o){let c=e.state.doc.lineAt(o),d=c.to<a?e.state.doc.lineAt(a):c,f=Math.max(i.from,c.from),m=Math.min(i.to,d.to);if(this.boundary){for(;o>c.from;o--)if(this.boundary.test(c.text[o-1-c.from])){f=o;break}for(;a<d.to;a++)if(this.boundary.test(d.text[a-d.from])){m=a;break}}let p=[],x,y=(w,k,S)=>p.push(S.range(w,k));if(c==d)for(this.regexp.lastIndex=f-c.from;(x=this.regexp.exec(c.text))&&x.index<m-c.from;)this.addMatch(x,e,x.index+c.from,y);else lV(e.state.doc,this.regexp,f,m,(w,k)=>this.addMatch(k,e,w,y));n=n.update({filterFrom:f,filterTo:m,filter:(w,k)=>w<f||k>m,add:p})}}return n}}const W4=/x/.unicode!=null?"gu":"g",S9e=new RegExp(`[\0-\b
805
805
  --Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\uFEFF-]`,W4),_9e={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 Uj=null;function N9e(){var t;if(Uj==null&&typeof document<"u"&&document.body){let e=document.body.style;Uj=((t=e.tabSize)!==null&&t!==void 0?t:e.MozTabSize)!=null}return Uj||!1}const YC=ut.define({combine(t){let e=lc(t,{render:null,specialChars:S9e,addSpecialChars:null});return(e.replaceTabs=!N9e())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,W4)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,W4)),e}});function E9e(t={}){return[YC.of(t),j9e()]}let cV=null;function j9e(){return cV||(cV=us.fromClass(class{constructor(t){this.view=t,this.decorations=Mt.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(t.state.facet(YC)),this.decorations=this.decorator.createDeco(t)}makeDecorator(t){return new k9e({regexp:t.specialChars,decoration:(e,n,r)=>{let{doc:s}=n.state,i=Gi(e[0],0);if(i==9){let o=s.lineAt(r),a=n.state.tabSize,c=Ex(o.text,a,r-o.from);return Mt.replace({widget:new R9e((a-c%a)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[i]||(this.decorationCache[i]=Mt.replace({widget:new M9e(t,i)}))},boundary:t.replaceTabs?void 0:/[^]/})}update(t){let e=t.state.facet(YC);t.startState.facet(YC)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(t.view)):this.decorations=this.decorator.updateDeco(t,this.decorations)}},{decorations:t=>t.decorations}))}const A9e="•";function T9e(t){return t>=32?A9e:t==10?"␤":String.fromCharCode(9216+t)}class M9e extends cc{constructor(e,n){super(),this.options=e,this.code=n}eq(e){return e.code==this.code}toDOM(e){let n=T9e(this.code),r=e.state.phrase("Control character")+" "+(_9e[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,r,n);if(s)return s;let i=document.createElement("span");return i.textContent=n,i.title=r,i.setAttribute("aria-label",r),i.className="cm-specialChar",i}ignoreEvent(){return!1}}class R9e extends cc{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent=" ",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}function O9e(){return D9e}const I9e=Mt.line({class:"cm-activeLine"}),D9e=us.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,n=[];for(let r of t.state.selection.ranges){let s=t.lineBlockAt(r.head);s.from>e&&(n.push(I9e.range(s.from)),e=s.from)}return Mt.set(n)}},{decorations:t=>t.decorations}),G4=2e3;function L9e(t,e,n){let r=Math.min(e.line,n.line),s=Math.max(e.line,n.line),i=[];if(e.off>G4||n.off>G4||e.col<0||n.col<0){let o=Math.min(e.off,n.off),a=Math.max(e.off,n.off);for(let c=r;c<=s;c++){let d=t.doc.line(c);d.length<=a&&i.push(De.range(d.from+o,d.to+a))}}else{let o=Math.min(e.col,n.col),a=Math.max(e.col,n.col);for(let c=r;c<=s;c++){let d=t.doc.line(c),f=E4(d.text,o,t.tabSize,!0);if(f<0)i.push(De.cursor(d.to));else{let m=E4(d.text,a,t.tabSize);i.push(De.range(d.from+f,d.from+m))}}}return i}function P9e(t,e){let n=t.coordsAtPos(t.viewport.from);return n?Math.round(Math.abs((n.left-e)/t.defaultCharacterWidth)):-1}function uV(t,e){let n=t.posAtCoords({x:e.clientX,y:e.clientY},!1),r=t.state.doc.lineAt(n),s=n-r.from,i=s>G4?-1:s==r.length?P9e(t,e.clientX):Ex(r.text,t.state.tabSize,n-r.from);return{line:r.number,col:i,off:s}}function F9e(t,e){let n=uV(t,e),r=t.state.selection;return n?{update(s){if(s.docChanged){let i=s.changes.mapPos(s.startState.doc.line(n.line).from),o=s.state.doc.lineAt(i);n={line:o.number,col:n.col,off:Math.min(n.off,o.length)},r=r.map(s.changes)}},get(s,i,o){let a=uV(t,s);if(!a)return r;let c=L9e(t.state,n,a);return c.length?o?De.create(c.concat(r.ranges)):De.create(c):r}}:null}function $9e(t){let e=(n=>n.altKey&&n.button==0);return at.mouseSelectionStyle.of((n,r)=>e(r)?F9e(n,r):null)}const B9e={Alt:[18,t=>!!t.altKey],Control:[17,t=>!!t.ctrlKey],Shift:[16,t=>!!t.shiftKey],Meta:[91,t=>!!t.metaKey]},z9e={style:"cursor: crosshair"};function V9e(t={}){let[e,n]=B9e[t.key||"Alt"],r=us.fromClass(class{constructor(s){this.view=s,this.isDown=!1}set(s){this.isDown!=s&&(this.isDown=s,this.view.update([]))}},{eventObservers:{keydown(s){this.set(s.keyCode==e||n(s))},keyup(s){(s.keyCode==e||!n(s))&&this.set(!1)},mousemove(s){this.set(n(s))}}});return[r,at.contentAttributes.of(s=>{var i;return!((i=s.plugin(r))===null||i===void 0)&&i.isDown?z9e:null})]}const Jw="-10000px";class ure{constructor(e,n,r,s){this.facet=n,this.createTooltipView=r,this.removeTooltipView=s,this.input=e.state.facet(n),this.tooltips=this.input.filter(o=>o);let i=null;this.tooltipViews=this.tooltips.map(o=>i=r(o,i))}update(e,n){var r;let s=e.state.facet(this.facet),i=s.filter(c=>c);if(s===this.input){for(let c of this.tooltipViews)c.update&&c.update(e);return!1}let o=[],a=n?[]:null;for(let c=0;c<i.length;c++){let d=i[c],f=-1;if(d){for(let m=0;m<this.tooltips.length;m++){let p=this.tooltips[m];p&&p.create==d.create&&(f=m)}if(f<0)o[c]=this.createTooltipView(d,c?o[c-1]:null),a&&(a[c]=!!d.above);else{let m=o[c]=this.tooltipViews[f];a&&(a[c]=n[f]),m.update&&m.update(e)}}}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&&(a.forEach((c,d)=>n[d]=c),n.length=a.length),this.input=s,this.tooltips=i,this.tooltipViews=o,!0}}function H9e(t){let e=t.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const qj=ut.define({combine:t=>{var e,n,r;return{position:dt.ios?"absolute":((e=t.find(s=>s.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((n=t.find(s=>s.parent))===null||n===void 0?void 0:n.parent)||null,tooltipSpace:((r=t.find(s=>s.tooltipSpace))===null||r===void 0?void 0:r.tooltipSpace)||H9e}}}),dV=new WeakMap,C9=us.fromClass(class{constructor(t){this.view=t,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=t.state.facet(qj);this.position=e.position,this.parent=e.parent,this.classes=t.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 ure(t,k9,(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(),t.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 t of this.manager.tooltipViews)this.intersectionObserver.observe(t.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(t){t.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(t,this.above);e&&this.observeIntersection();let n=e||t.geometryChanged,r=t.state.facet(qj);if(r.position!=this.position&&!this.madeAbsolute){this.position=r.position;for(let s of this.manager.tooltipViews)s.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 s of this.manager.tooltipViews)this.container.appendChild(s.dom);n=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);n&&this.maybeMeasure()}createTooltip(t,e){let n=t.create(this.view),r=e?e.dom:null;if(n.dom.classList.add("cm-tooltip"),t.arrow&&!n.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let s=document.createElement("div");s.className="cm-tooltip-arrow",n.dom.appendChild(s)}return n.dom.style.position=this.position,n.dom.style.top=Jw,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 t,e,n;this.view.win.removeEventListener("resize",this.measureSoon);for(let r of this.manager.tooltipViews)r.dom.remove(),(t=r.destroy)===null||t===void 0||t.call(r);this.parent&&this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(n=this.intersectionObserver)===null||n===void 0||n.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let t=1,e=1,n=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:i}=this.manager.tooltipViews[0];if(dt.safari){let o=i.getBoundingClientRect();n=Math.abs(o.top+1e4)>1||Math.abs(o.left)>1}else n=!!i.offsetParent&&i.offsetParent!=this.container.ownerDocument.body}if(n||this.position=="absolute")if(this.parent){let i=this.parent.getBoundingClientRect();i.width&&i.height&&(t=i.width/this.parent.offsetWidth,e=i.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:e}=this.view.viewState);let r=this.view.scrollDOM.getBoundingClientRect(),s=y9(this.view);return{visible:{left:r.left+s.left,top:r.top+s.top,right:r.right-s.right,bottom:r.bottom-s.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((i,o)=>{let a=this.manager.tooltipViews[o];return a.getCoords?a.getCoords(i.pos):this.view.coordsAtPos(i.pos)}),size:this.manager.tooltipViews.map(({dom:i})=>i.getBoundingClientRect()),space:this.view.state.facet(qj).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:n}}writeMeasure(t){var e;if(t.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let a of this.manager.tooltipViews)a.dom.style.position="absolute"}let{visible:n,space:r,scaleX:s,scaleY:i}=t,o=[];for(let a=0;a<this.manager.tooltips.length;a++){let c=this.manager.tooltips[a],d=this.manager.tooltipViews[a],{dom:f}=d,m=t.pos[a],p=t.size[a];if(!m||c.clip!==!1&&(m.bottom<=Math.max(n.top,r.top)||m.top>=Math.min(n.bottom,r.bottom)||m.right<Math.max(n.left,r.left)-.1||m.left>Math.min(n.right,r.right)+.1)){f.style.top=Jw;continue}let x=c.arrow?d.dom.querySelector(".cm-tooltip-arrow"):null,y=x?7:0,w=p.right-p.left,k=(e=dV.get(d))!==null&&e!==void 0?e:p.bottom-p.top,S=d.offset||q9e,C=this.view.textDirection==lr.LTR,_=p.width>r.right-r.left?C?r.left:r.right-p.width:C?Math.max(r.left,Math.min(m.left-(x?14:0)+S.x,r.right-w)):Math.min(Math.max(r.left,m.left-w+(x?14:0)-S.x),r.right-w),E=this.above[a];!c.strictSide&&(E?m.top-k-y-S.y<r.top:m.bottom+k+y+S.y>r.bottom)&&E==r.bottom-m.bottom>m.top-r.top&&(E=this.above[a]=!E);let j=(E?m.top-r.top:r.bottom-m.bottom)-y;if(j<k&&d.resize!==!1){if(j<this.view.defaultLineHeight){f.style.top=Jw;continue}dV.set(d,k),f.style.height=(k=j)/i+"px"}else f.style.height&&(f.style.height="");let R=E?m.top-k-y-S.y:m.bottom+y+S.y,T=_+w;if(d.overlap!==!0)for(let M of o)M.left<T&&M.right>_&&M.top<R+k&&M.bottom>R&&(R=E?M.top-k-2-y:M.bottom+y+2);if(this.position=="absolute"?(f.style.top=(R-t.parent.top)/i+"px",fV(f,(_-t.parent.left)/s)):(f.style.top=R/i+"px",fV(f,_/s)),x){let M=m.left+(C?S.x:-S.x)-(_+14-7);x.style.left=M/s+"px"}d.overlap!==!0&&o.push({left:_,top:R,right:T,bottom:R+k}),f.classList.toggle("cm-tooltip-above",E),f.classList.toggle("cm-tooltip-below",!E),d.positioned&&d.positioned(t.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 t of this.manager.tooltipViews)t.dom.style.top=Jw}},{eventObservers:{scroll(){this.maybeMeasure()}}});function fV(t,e){let n=parseInt(t.style.left,10);(isNaN(n)||Math.abs(e-n)>1)&&(t.style.left=e+"px")}const U9e=at.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"}}}),q9e={x:0,y:0},k9=ut.define({enables:[C9,U9e]}),Dk=ut.define({combine:t=>t.reduce((e,n)=>e.concat(n),[])});class K_{static create(e){return new K_(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new ure(e,Dk,(n,r)=>this.createHostedView(n,r),n=>n.dom.remove())}createHostedView(e,n){let r=e.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(e){for(let n of this.manager.tooltipViews)n.mount&&n.mount(e);this.mounted=!0}positioned(e){for(let n of this.manager.tooltipViews)n.positioned&&n.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let n of this.manager.tooltipViews)(e=n.destroy)===null||e===void 0||e.call(n)}passProp(e){let n;for(let r of this.manager.tooltipViews){let s=r[e];if(s!==void 0){if(n===void 0)n=s;else if(n!==s)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 K9e=k9.compute([Dk],t=>{let e=t.facet(Dk);return e.length===0?null:{pos:Math.min(...e.map(n=>n.pos)),end:Math.max(...e.map(n=>{var r;return(r=n.end)!==null&&r!==void 0?r:n.pos})),create:K_.create,above:e[0].above,arrow:e.some(n=>n.arrow)}});class W9e{constructor(e,n,r,s,i){this.view=e,this.source=n,this.field=r,this.setHover=s,this.hoverTime=i,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.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 e=Date.now()-this.lastMove.time;e<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-e):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:e,lastMove:n}=this,r=e.docView.tile.nearest(n.target);if(!r)return;let s,i=1;if(r.isWidget())s=r.posAtStart;else{if(s=e.posAtCoords(n),s==null)return;let a=e.coordsAtPos(s);if(!a||n.y<a.top||n.y>a.bottom||n.x<a.left-e.defaultCharacterWidth||n.x>a.right+e.defaultCharacterWidth)return;let c=e.bidiSpans(e.state.doc.lineAt(s)).find(f=>f.from<=s&&f.to>=s),d=c&&c.dir==lr.RTL?-1:1;i=n.x<a.left?-d:d}let o=this.source(e,s,i);if(o!=null&&o.then){let a=this.pending={pos:s};o.then(c=>{this.pending==a&&(this.pending=null,c&&!(Array.isArray(c)&&!c.length)&&e.dispatch({effects:this.setHover.of(Array.isArray(c)?c:[c])}))},c=>Xi(e.state,c,"hover tooltip"))}else o&&!(Array.isArray(o)&&!o.length)&&e.dispatch({effects:this.setHover.of(Array.isArray(o)?o:[o])})}get tooltip(){let e=this.view.plugin(C9),n=e?e.manager.tooltips.findIndex(r=>r.create==K_.create):-1;return n>-1?e.manager.tooltipViews[n]:null}mousemove(e){var n,r;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:s,tooltip:i}=this;if(s.length&&i&&!G9e(i.dom,e)||this.pending){let{pos:o}=s[0]||this.pending,a=(r=(n=s[0])===null||n===void 0?void 0:n.end)!==null&&r!==void 0?r:o;(o==a?this.view.posAtCoords(this.lastMove)!=o:!J9e(this.view,o,a,e.clientX,e.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(e){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:n}=this;if(n.length){let{tooltip:r}=this;r&&r.dom.contains(e.relatedTarget)?this.watchTooltipLeave(r.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(e){let n=r=>{e.removeEventListener("mouseleave",n),this.active.length&&!this.view.dom.contains(r.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};e.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 Yw=4;function G9e(t,e){let{left:n,right:r,top:s,bottom:i}=t.getBoundingClientRect(),o;if(o=t.querySelector(".cm-tooltip-arrow")){let a=o.getBoundingClientRect();s=Math.min(a.top,s),i=Math.max(a.bottom,i)}return e.clientX>=n-Yw&&e.clientX<=r+Yw&&e.clientY>=s-Yw&&e.clientY<=i+Yw}function J9e(t,e,n,r,s,i){let o=t.scrollDOM.getBoundingClientRect(),a=t.documentTop+t.documentPadding.top+t.contentHeight;if(o.left>r||o.right<r||o.top>s||Math.min(o.bottom,a)<s)return!1;let c=t.posAtCoords({x:r,y:s},!1);return c>=e&&c<=n}function Y9e(t,e={}){let n=zt.define(),r=Is.define({create(){return[]},update(s,i){if(s.length&&(e.hideOnChange&&(i.docChanged||i.selection)?s=[]:e.hideOn&&(s=s.filter(o=>!e.hideOn(i,o))),i.docChanged)){let o=[];for(let a of s){let c=i.changes.mapPos(a.pos,-1,qs.TrackDel);if(c!=null){let d=Object.assign(Object.create(null),a);d.pos=c,d.end!=null&&(d.end=i.changes.mapPos(d.end)),o.push(d)}}s=o}for(let o of i.effects)o.is(n)&&(s=o.value),o.is(Z9e)&&(s=[]);return s},provide:s=>Dk.from(s)});return{active:r,extension:[r,us.define(s=>new W9e(s,t,r,n,e.hoverTime||300)),K9e]}}function dre(t,e){let n=t.plugin(C9);if(!n)return null;let r=n.manager.tooltips.indexOf(e);return r<0?null:n.manager.tooltipViews[r]}const Z9e=zt.define(),hV=ut.define({combine(t){let e,n;for(let r of t)e=e||r.topContainer,n=n||r.bottomContainer;return{topContainer:e,bottomContainer:n}}});function S9(t,e){let n=t.plugin(fre),r=n?n.specs.indexOf(e):-1;return r>-1?n.panels[r]:null}const fre=us.fromClass(class{constructor(t){this.input=t.state.facet(bb),this.specs=this.input.filter(n=>n),this.panels=this.specs.map(n=>n(t));let e=t.state.facet(hV);this.top=new Zw(t,!0,e.topContainer),this.bottom=new Zw(t,!1,e.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(t){let e=t.state.facet(hV);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Zw(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Zw(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let n=t.state.facet(bb);if(n!=this.input){let r=n.filter(c=>c),s=[],i=[],o=[],a=[];for(let c of r){let d=this.specs.indexOf(c),f;d<0?(f=c(t.view),a.push(f)):(f=this.panels[d],f.update&&f.update(t)),s.push(f),(f.top?i:o).push(f)}this.specs=r,this.panels=s,this.top.sync(i),this.bottom.sync(o);for(let c of a)c.dom.classList.add("cm-panel"),c.mount&&c.mount()}else for(let r of this.panels)r.update&&r.update(t)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:t=>at.scrollMargins.of(e=>{let n=e.plugin(t);return n&&{top:n.top.scrollMargin(),bottom:n.bottom.scrollMargin()}})});class Zw{constructor(e,n,r){this.view=e,this.top=n,this.container=r,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let n of this.panels)n.destroy&&e.indexOf(n)<0&&n.destroy();this.panels=e,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 e=this.dom.firstChild;for(let n of this.panels)if(n.dom.parentNode==this.dom){for(;e!=n.dom;)e=mV(e);e=e.nextSibling}else this.dom.insertBefore(n.dom,e);for(;e;)e=mV(e)}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 e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function mV(t){let e=t.nextSibling;return t.remove(),e}const bb=ut.define({enables:fre});function Q9e(t,e){let n,r=new Promise(o=>n=o),s=o=>X9e(o,e,n);t.state.field(Kj,!1)?t.dispatch({effects:hre.of(s)}):t.dispatch({effects:zt.appendConfig.of(Kj.init(()=>[s]))});let i=mre.of(s);return{close:i,result:r.then(o=>((t.win.queueMicrotask||(c=>t.win.setTimeout(c,10)))(()=>{t.state.field(Kj).indexOf(s)>-1&&t.dispatch({effects:i})}),o))}}const Kj=Is.define({create(){return[]},update(t,e){for(let n of e.effects)n.is(hre)?t=[n.value].concat(t):n.is(mre)&&(t=t.filter(r=>r!=n.value));return t},provide:t=>bb.computeN([t],e=>e.field(t))}),hre=zt.define(),mre=zt.define();function X9e(t,e,n){let r=e.content?e.content(t,()=>o(null)):null;if(!r){if(r=Xn("form"),e.input){let a=Xn("input",e.input);/^(text|password|number|email|tel|url)$/.test(a.type)&&a.classList.add("cm-textfield"),a.name||(a.name="input"),r.appendChild(Xn("label",(e.label||"")+": ",a))}else r.appendChild(document.createTextNode(e.label||""));r.appendChild(document.createTextNode(" ")),r.appendChild(Xn("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let s=r.nodeName=="FORM"?[r]:r.querySelectorAll("form");for(let a=0;a<s.length;a++){let c=s[a];c.addEventListener("keydown",d=>{d.keyCode==27?(d.preventDefault(),o(null)):d.keyCode==13&&(d.preventDefault(),o(c))}),c.addEventListener("submit",d=>{d.preventDefault(),o(c)})}let i=Xn("div",r,Xn("button",{onclick:()=>o(null),"aria-label":t.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(i.className=e.class),i.classList.add("cm-dialog");function o(a){i.contains(i.ownerDocument.activeElement)&&t.focus(),n(a)}return{dom:i,top:e.top,mount:()=>{if(e.focus){let a;typeof e.focus=="string"?a=r.querySelector(e.focus):a=r.querySelector("input")||r.querySelector("button"),a&&"select"in a?a.select():a&&"focus"in a&&a.focus()}}}}class Nu extends sf{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}Nu.prototype.elementClass="";Nu.prototype.toDOM=void 0;Nu.prototype.mapMode=qs.TrackBefore;Nu.prototype.startSide=Nu.prototype.endSide=-1;Nu.prototype.point=!0;const ZC=ut.define(),e6e=ut.define(),t6e={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>un.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},My=ut.define();function n6e(t){return[pre(),My.of({...t6e,...t})]}const pV=ut.define({combine:t=>t.some(e=>e)});function pre(t){return[r6e]}const r6e=us.fromClass(class{constructor(t){this.view=t,this.domAfter=null,this.prevViewport=t.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=t.state.facet(My).map(e=>new xV(t,e)),this.fixed=!t.state.facet(pV);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.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(t){if(this.updateGutters(t)){let e=this.prevViewport,n=t.view.viewport,r=Math.min(e.to,n.to)-Math.max(e.from,n.from);this.syncGutters(r<(n.to-n.from)*.8)}if(t.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(pV)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let n=un.iter(this.view.state.facet(ZC),this.view.viewport.from),r=[],s=this.gutters.map(i=>new s6e(i,this.view.viewport,-this.view.documentPadding.top));for(let i of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(i.type)){let o=!0;for(let a of i.type)if(a.type==Ks.Text&&o){J4(n,r,a.from);for(let c of s)c.line(this.view,a,r);o=!1}else if(a.widget)for(let c of s)c.widget(this.view,a)}else if(i.type==Ks.Text){J4(n,r,i.from);for(let o of s)o.line(this.view,i,r)}else if(i.widget)for(let o of s)o.widget(this.view,i);for(let i of s)i.finish();t&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(t){let e=t.startState.facet(My),n=t.state.facet(My),r=t.docChanged||t.heightChanged||t.viewportChanged||!un.eq(t.startState.facet(ZC),t.state.facet(ZC),t.view.viewport.from,t.view.viewport.to);if(e==n)for(let s of this.gutters)s.update(t)&&(r=!0);else{r=!0;let s=[];for(let i of n){let o=e.indexOf(i);o<0?s.push(new xV(this.view,i)):(this.gutters[o].update(t),s.push(this.gutters[o]))}for(let i of this.gutters)i.dom.remove(),s.indexOf(i)<0&&i.destroy();for(let i of s)i.config.side=="after"?this.getDOMAfter().appendChild(i.dom):this.dom.appendChild(i.dom);this.gutters=s}return r}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:t=>at.scrollMargins.of(e=>{let n=e.plugin(t);if(!n||n.gutters.length==0||!n.fixed)return null;let r=n.dom.offsetWidth*e.scaleX,s=n.domAfter?n.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==lr.LTR?{left:r,right:s}:{right:r,left:s}})});function gV(t){return Array.isArray(t)?t:[t]}function J4(t,e,n){for(;t.value&&t.from<=n;)t.from==n&&e.push(t.value),t.next()}class s6e{constructor(e,n,r){this.gutter=e,this.height=r,this.i=0,this.cursor=un.iter(e.markers,n.from)}addElement(e,n,r){let{gutter:s}=this,i=(n.top-this.height)/e.scaleY,o=n.height/e.scaleY;if(this.i==s.elements.length){let a=new gre(e,o,i,r);s.elements.push(a),s.dom.appendChild(a.dom)}else s.elements[this.i].update(e,o,i,r);this.height=n.bottom,this.i++}line(e,n,r){let s=[];J4(this.cursor,s,n.from),r.length&&(s=s.concat(r));let i=this.gutter.config.lineMarker(e,n,s);i&&s.unshift(i);let o=this.gutter;s.length==0&&!o.config.renderEmptyElements||this.addElement(e,n,s)}widget(e,n){let r=this.gutter.config.widgetMarker(e,n.widget,n),s=r?[r]:null;for(let i of e.state.facet(e6e)){let o=i(e,n.widget,n);o&&(s||(s=[])).push(o)}s&&this.addElement(e,n,s)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let n=e.elements.pop();e.dom.removeChild(n.dom),n.destroy()}}}class xV{constructor(e,n){this.view=e,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,s=>{let i=s.target,o;if(i!=this.dom&&this.dom.contains(i)){for(;i.parentNode!=this.dom;)i=i.parentNode;let c=i.getBoundingClientRect();o=(c.top+c.bottom)/2}else o=s.clientY;let a=e.lineBlockAtHeight(o-e.documentTop);n.domEventHandlers[r](e,a,s)&&s.preventDefault()});this.markers=gV(n.markers(e)),n.initialSpacer&&(this.spacer=new gre(e,0,0,[n.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let n=this.markers;if(this.markers=gV(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],e);s!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[s])}let r=e.view.viewport;return!un.eq(this.markers,n,r.from,r.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class gre{constructor(e,n,r,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,n,r,s)}update(e,n,r,s){this.height!=n&&(this.height=n,this.dom.style.height=n+"px"),this.above!=r&&(this.dom.style.marginTop=(this.above=r)?r+"px":""),i6e(this.markers,s)||this.setMarkers(e,s)}setMarkers(e,n){let r="cm-gutterElement",s=this.dom.firstChild;for(let i=0,o=0;;){let a=o,c=i<n.length?n[i++]:null,d=!1;if(c){let f=c.elementClass;f&&(r+=" "+f);for(let m=o;m<this.markers.length;m++)if(this.markers[m].compare(c)){a=m,d=!0;break}}else a=this.markers.length;for(;o<a;){let f=this.markers[o++];if(f.toDOM){f.destroy(s);let m=s.nextSibling;s.remove(),s=m}}if(!c)break;c.toDOM&&(d?s=s.nextSibling:this.dom.insertBefore(c.toDOM(e),s)),d&&o++}this.dom.className=r,this.markers=n}destroy(){this.setMarkers(null,[])}}function i6e(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(!t[n].compare(e[n]))return!1;return!0}const o6e=ut.define(),a6e=ut.define(),Dp=ut.define({combine(t){return lc(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,n){let r=Object.assign({},e);for(let s in n){let i=r[s],o=n[s];r[s]=i?(a,c,d)=>i(a,c,d)||o(a,c,d):o}return r}})}});class Wj extends Nu{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function Gj(t,e){return t.state.facet(Dp).formatNumber(e,t.state)}const l6e=My.compute([Dp],t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(o6e)},lineMarker(e,n,r){return r.some(s=>s.toDOM)?null:new Wj(Gj(e,e.state.doc.lineAt(n.from).number))},widgetMarker:(e,n,r)=>{for(let s of e.state.facet(a6e)){let i=s(e,n,r);if(i)return i}return null},lineMarkerChange:e=>e.startState.facet(Dp)!=e.state.facet(Dp),initialSpacer(e){return new Wj(Gj(e,yV(e.state.doc.lines)))},updateSpacer(e,n){let r=Gj(n.view,yV(n.view.state.doc.lines));return r==e.number?e:new Wj(r)},domEventHandlers:t.facet(Dp).domEventHandlers,side:"before"}));function xre(t={}){return[Dp.of(t),pre(),l6e]}function yV(t){let e=9;for(;e<t;)e=e*10+9;return e}const c6e=new class extends Nu{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},u6e=ZC.compute(["selection"],t=>{let e=[],n=-1;for(let r of t.selection.ranges){let s=t.doc.lineAt(r.head).from;s>n&&(n=s,e.push(c6e.range(s)))}return un.of(e)});function d6e(){return u6e}const f6e=1024;let h6e=0,aa=class{constructor(e,n){this.from=e,this.to=n}};class sn{constructor(e={}){this.id=h6e++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=Ai.match(e)),n=>{let r=e(n);return r===void 0?null:[this,r]}}}sn.closedBy=new sn({deserialize:t=>t.split(" ")});sn.openedBy=new sn({deserialize:t=>t.split(" ")});sn.group=new sn({deserialize:t=>t.split(" ")});sn.isolate=new sn({deserialize:t=>{if(t&&t!="rtl"&&t!="ltr"&&t!="auto")throw new RangeError("Invalid value for isolate: "+t);return t||"auto"}});sn.contextHash=new sn({perNode:!0});sn.lookAhead=new sn({perNode:!0});sn.mounted=new sn({perNode:!0});class Qp{constructor(e,n,r,s=!1){this.tree=e,this.overlay=n,this.parser=r,this.bracketed=s}static get(e){return e&&e.props&&e.props[sn.mounted.id]}}const m6e=Object.create(null);class Ai{constructor(e,n,r,s=0){this.name=e,this.props=n,this.id=r,this.flags=s}static define(e){let n=e.props&&e.props.length?Object.create(null):m6e,r=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),s=new Ai(e.name||"",n,e.id,r);if(e.props){for(let i of e.props)if(Array.isArray(i)||(i=i(s)),i){if(i[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");n[i[0].id]=i[1]}}return s}prop(e){return this.props[e.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(e){if(typeof e=="string"){if(this.name==e)return!0;let n=this.prop(sn.group);return n?n.indexOf(e)>-1:!1}return this.id==e}static match(e){let n=Object.create(null);for(let r in e)for(let s of r.split(" "))n[s]=e[r];return r=>{for(let s=r.prop(sn.group),i=-1;i<(s?s.length:0);i++){let o=n[i<0?r.name:s[i]];if(o)return o}}}}Ai.none=new Ai("",Object.create(null),0,8);class _9{constructor(e){this.types=e;for(let n=0;n<e.length;n++)if(e[n].id!=n)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let n=[];for(let r of this.types){let s=null;for(let i of e){let o=i(r);if(o){s||(s=Object.assign({},r.props));let a=o[1],c=o[0];c.combine&&c.id in s&&(a=c.combine(s[c.id],a)),s[c.id]=a}}n.push(s?new Ai(r.name,s,r.id,r.flags):r)}return new _9(n)}}const Qw=new WeakMap,bV=new WeakMap;var ar;(function(t){t[t.ExcludeBuffers=1]="ExcludeBuffers",t[t.IncludeAnonymous=2]="IncludeAnonymous",t[t.IgnoreMounts=4]="IgnoreMounts",t[t.IgnoreOverlays=8]="IgnoreOverlays",t[t.EnterBracketed=16]="EnterBracketed"})(ar||(ar={}));class cr{constructor(e,n,r,s,i){if(this.type=e,this.children=n,this.positions=r,this.length=s,this.props=null,i&&i.length){this.props=Object.create(null);for(let[o,a]of i)this.props[typeof o=="number"?o:o.id]=a}}toString(){let e=Qp.get(this);if(e&&!e.overlay)return e.tree.toString();let n="";for(let r of this.children){let s=r.toString();s&&(n&&(n+=","),n+=s)}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(e=0){return new Lk(this.topNode,e)}cursorAt(e,n=0,r=0){let s=Qw.get(this)||this.topNode,i=new Lk(s);return i.moveTo(e,n),Qw.set(this,i._tree),i}get topNode(){return new ci(this,0,0,null)}resolve(e,n=0){let r=vb(Qw.get(this)||this.topNode,e,n,!1);return Qw.set(this,r),r}resolveInner(e,n=0){let r=vb(bV.get(this)||this.topNode,e,n,!0);return bV.set(this,r),r}resolveStack(e,n=0){return x6e(this,e,n)}iterate(e){let{enter:n,leave:r,from:s=0,to:i=this.length}=e,o=e.mode||0,a=(o&ar.IncludeAnonymous)>0;for(let c=this.cursor(o|ar.IncludeAnonymous);;){let d=!1;if(c.from<=i&&c.to>=s&&(!a&&c.type.isAnonymous||n(c)!==!1)){if(c.firstChild())continue;d=!0}for(;d&&r&&(a||!c.type.isAnonymous)&&r(c),!c.nextSibling();){if(!c.parent())return;d=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let n in this.props)e.push([+n,this.props[n]]);return e}balance(e={}){return this.children.length<=8?this:j9(Ai.none,this.children,this.positions,0,this.children.length,0,this.length,(n,r,s)=>new cr(this.type,n,r,s,this.propValues),e.makeTree||((n,r,s)=>new cr(Ai.none,n,r,s)))}static build(e){return y6e(e)}}cr.empty=new cr(Ai.none,[],[],0);class N9{constructor(e,n){this.buffer=e,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 N9(this.buffer,this.index)}}class cf{constructor(e,n,r){this.buffer=e,this.length=n,this.set=r}get type(){return Ai.none}toString(){let e=[];for(let n=0;n<this.buffer.length;)e.push(this.childString(n)),n=this.buffer[n+3];return e.join(",")}childString(e){let n=this.buffer[e],r=this.buffer[e+3],s=this.set.types[n],i=s.name;if(/\W/.test(i)&&!s.isError&&(i=JSON.stringify(i)),e+=4,r==e)return i;let o=[];for(;e<r;)o.push(this.childString(e)),e=this.buffer[e+3];return i+"("+o.join(",")+")"}findChild(e,n,r,s,i){let{buffer:o}=this,a=-1;for(let c=e;c!=n&&!(yre(i,s,o[c+1],o[c+2])&&(a=c,r>0));c=o[c+3]);return a}slice(e,n,r){let s=this.buffer,i=new Uint16Array(n-e),o=0;for(let a=e,c=0;a<n;){i[c++]=s[a++],i[c++]=s[a++]-r;let d=i[c++]=s[a++]-r;i[c++]=s[a++]-e,o=Math.max(o,d)}return new cf(i,o,this.set)}}function yre(t,e,n,r){switch(t){case-2:return n<e;case-1:return r>=e&&n<e;case 0:return n<e&&r>e;case 1:return n<=e&&r>e;case 2:return r>e;case 4:return!0}}function vb(t,e,n,r){for(var s;t.from==t.to||(n<1?t.from>=e:t.from>e)||(n>-1?t.to<=e:t.to<e);){let o=!r&&t instanceof ci&&t.index<0?null:t.parent;if(!o)return t;t=o}let i=r?0:ar.IgnoreOverlays;if(r)for(let o=t,a=o.parent;a;o=a,a=o.parent)o instanceof ci&&o.index<0&&((s=a.enter(e,n,i))===null||s===void 0?void 0:s.from)!=o.from&&(t=a);for(;;){let o=t.enter(e,n,i);if(!o)return t;t=o}}class bre{cursor(e=0){return new Lk(this,e)}getChild(e,n=null,r=null){let s=vV(this,e,n,r);return s.length?s[0]:null}getChildren(e,n=null,r=null){return vV(this,e,n,r)}resolve(e,n=0){return vb(this,e,n,!1)}resolveInner(e,n=0){return vb(this,e,n,!0)}matchContext(e){return Y4(this.parent,e)}enterUnfinishedNodesBefore(e){let n=this.childBefore(e),r=this;for(;n;){let s=n.lastChild;if(!s||s.to!=n.to)break;s.type.isError&&s.from==s.to?(r=n,n=s.prevSibling):n=s}return r}get node(){return this}get next(){return this.parent}}class ci extends bre{constructor(e,n,r,s){super(),this._tree=e,this.from=n,this.index=r,this._parent=s}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,n,r,s,i=0){for(let o=this;;){for(let{children:a,positions:c}=o._tree,d=n>0?a.length:-1;e!=d;e+=n){let f=a[e],m=c[e]+o.from,p;if(!(!(i&ar.EnterBracketed&&f instanceof cr&&(p=Qp.get(f))&&!p.overlay&&p.bracketed&&r>=m&&r<=m+f.length)&&!yre(s,r,m,m+f.length))){if(f instanceof cf){if(i&ar.ExcludeBuffers)continue;let x=f.findChild(0,f.buffer.length,n,r-m,s);if(x>-1)return new Pl(new p6e(o,f,e,m),null,x)}else if(i&ar.IncludeAnonymous||!f.type.isAnonymous||E9(f)){let x;if(!(i&ar.IgnoreMounts)&&(x=Qp.get(f))&&!x.overlay)return new ci(x.tree,m,e,o);let y=new ci(f,m,e,o);return i&ar.IncludeAnonymous||!y.type.isAnonymous?y:y.nextChild(n<0?f.children.length-1:0,n,r,s,i)}}}if(i&ar.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+n:e=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(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,n,r=0){let s;if(!(r&ar.IgnoreOverlays)&&(s=Qp.get(this._tree))&&s.overlay){let i=e-this.from,o=r&ar.EnterBracketed&&s.bracketed;for(let{from:a,to:c}of s.overlay)if((n>0||o?a<=i:a<i)&&(n<0||o?c>=i:c>i))return new ci(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,n,r)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}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 vV(t,e,n,r){let s=t.cursor(),i=[];if(!s.firstChild())return i;if(n!=null){for(let o=!1;!o;)if(o=s.type.is(n),!s.nextSibling())return i}for(;;){if(r!=null&&s.type.is(r))return i;if(s.type.is(e)&&i.push(s.node),!s.nextSibling())return r==null?i:[]}}function Y4(t,e,n=e.length-1){for(let r=t;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(e[n]&&e[n]!=r.name)return!1;n--}}return!0}class p6e{constructor(e,n,r,s){this.parent=e,this.buffer=n,this.index=r,this.start=s}}class Pl extends bre{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(e,n,r){super(),this.context=e,this._parent=n,this.index=r,this.type=e.buffer.set.types[e.buffer.buffer[r]]}child(e,n,r){let{buffer:s}=this.context,i=s.findChild(this.index+4,s.buffer[this.index+3],e,n-this.context.start,r);return i<0?null:new Pl(this.context,this,i)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,n,r=0){if(r&ar.ExcludeBuffers)return null;let{buffer:s}=this.context,i=s.findChild(this.index+4,s.buffer[this.index+3],n>0?1:-1,e-this.context.start,n);return i<0?null:new Pl(this.context,this,i)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,n=e.buffer[this.index+3];return n<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new Pl(this.context,this._parent,n):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,n=this._parent?this._parent.index+4:0;return this.index==n?this.externalSibling(-1):new Pl(this.context,this._parent,e.findChild(n,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],n=[],{buffer:r}=this.context,s=this.index+4,i=r.buffer[this.index+3];if(i>s){let o=r.buffer[this.index+1];e.push(r.slice(s,i,o)),n.push(0)}return new cr(this.type,e,n,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function vre(t){if(!t.length)return null;let e=0,n=t[0];for(let i=1;i<t.length;i++){let o=t[i];(o.from>n.from||o.to<n.to)&&(n=o,e=i)}let r=n instanceof ci&&n.index<0?null:n.parent,s=t.slice();return r?s[e]=r:s.splice(e,1),new g6e(s,n)}class g6e{constructor(e,n){this.heads=e,this.node=n}get next(){return vre(this.heads)}}function x6e(t,e,n){let r=t.resolveInner(e,n),s=null;for(let i=r instanceof ci?r:r.context.parent;i;i=i.parent)if(i.index<0){let o=i.parent;(s||(s=[r])).push(o.resolve(e,n)),i=o}else{let o=Qp.get(i.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let a=new ci(o.tree,o.overlay[0].from+i.from,-1,i);(s||(s=[r])).push(vb(a,e,n,!1))}}return s?vre(s):r}class Lk{get name(){return this.type.name}constructor(e,n=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=n&~ar.EnterBracketed,e instanceof ci)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let r=e._parent;r;r=r._parent)this.stack.unshift(r.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,n){this.index=e;let{start:r,buffer:s}=this.buffer;return this.type=n||s.set.types[s.buffer[e]],this.from=r+s.buffer[e+1],this.to=r+s.buffer[e+2],!0}yield(e){return e?e instanceof ci?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,n,r){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,n,r,this.mode));let{buffer:s}=this.buffer,i=s.findChild(this.index+4,s.buffer[this.index+3],e,n-this.buffer.start,r);return i<0?!1:(this.stack.push(this.index),this.yieldBuf(i))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,n,r=this.mode){return this.buffer?r&ar.ExcludeBuffers?!1:this.enterChild(1,e,n):this.yield(this._tree.enter(e,n,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&ar.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&ar.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:n}=this.buffer,r=this.stack.length-1;if(e<0){let s=r<0?0:this.stack[r]+4;if(this.index!=s)return this.yieldBuf(n.findChild(s,this.index,-1,0,4))}else{let s=n.buffer[this.index+3];if(s<(r<0?n.buffer.length:n.buffer[this.stack[r]+3]))return this.yieldBuf(s)}return r<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let n,r,{buffer:s}=this;if(s){if(e>0){if(this.index<s.buffer.buffer.length)return!1}else for(let i=0;i<this.index;i++)if(s.buffer.buffer[i+3]<this.index)return!1;({index:n,parent:r}=s)}else({index:n,_parent:r}=this._tree);for(;r;{index:n,_parent:r}=r)if(n>-1)for(let i=n+e,o=e<0?-1:r._tree.children.length;i!=o;i+=e){let a=r._tree.children[i];if(this.mode&ar.IncludeAnonymous||a instanceof cf||!a.type.isAnonymous||E9(a))return!1}return!0}move(e,n){if(n&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,n=0){for(;(this.from==this.to||(n<1?this.from>=e:this.from>e)||(n>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,n););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,n=null,r=0;if(e&&e.context==this.buffer)e:for(let s=this.index,i=this.stack.length;i>=0;){for(let o=e;o;o=o._parent)if(o.index==s){if(s==this.index)return o;n=o,r=i+1;break e}s=this.stack[--i]}for(let s=r;s<this.stack.length;s++)n=new Pl(this.buffer,n,this.stack[s]);return this.bufferNode=new Pl(this.buffer,n,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,n){for(let r=0;;){let s=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){r++;continue}this.type.isAnonymous||(s=!0)}for(;;){if(s&&n&&n(this),s=this.type.isAnonymous,!r)return;if(this.nextSibling())break;this.parent(),r--,s=!0}}}matchContext(e){if(!this.buffer)return Y4(this.node.parent,e);let{buffer:n}=this.buffer,{types:r}=n.set;for(let s=e.length-1,i=this.stack.length-1;s>=0;i--){if(i<0)return Y4(this._tree,e,s);let o=r[n.buffer[this.stack[i]]];if(!o.isAnonymous){if(e[s]&&e[s]!=o.name)return!1;s--}}return!0}}function E9(t){return t.children.some(e=>e instanceof cf||!e.type.isAnonymous||E9(e))}function y6e(t){var e;let{buffer:n,nodeSet:r,maxBufferLength:s=f6e,reused:i=[],minRepeatType:o=r.types.length}=t,a=Array.isArray(n)?new N9(n,n.length):n,c=r.types,d=0,f=0;function m(j,R,T,M,O,I){let{id:$,start:z,end:V,size:W}=a,J=f,G=d;if(W<0)if(a.next(),W==-1){let B=i[$];T.push(B),M.push(z-j);return}else if(W==-3){d=$;return}else if(W==-4){f=$;return}else throw new RangeError(`Unrecognized record size: ${W}`);let F=c[$],L,K,D=z-j;if(V-z<=s&&(K=k(a.pos-R,O))){let B=new Uint16Array(K.size-K.skip),q=a.pos-K.size,H=B.length;for(;a.pos>q;)H=S(K.start,B,H);L=new cf(B,V-K.start,r),D=K.start-j}else{let B=a.pos-W;a.next();let q=[],H=[],ie=$>=o?$:-1,ce=0,ee=V;for(;a.pos>B;)ie>=0&&a.id==ie&&a.size>=0?(a.end<=ee-s&&(y(q,H,z,ce,a.end,ee,ie,J,G),ce=q.length,ee=a.end),a.next()):I>2500?p(z,B,q,H):m(z,B,q,H,ie,I+1);if(ie>=0&&ce>0&&ce<q.length&&y(q,H,z,ce,z,ee,ie,J,G),q.reverse(),H.reverse(),ie>-1&&ce>0){let Q=x(F,G);L=j9(F,q,H,0,q.length,0,V-z,Q,Q)}else L=w(F,q,H,V-z,J-V,G)}T.push(L),M.push(D)}function p(j,R,T,M){let O=[],I=0,$=-1;for(;a.pos>R;){let{id:z,start:V,end:W,size:J}=a;if(J>4)a.next();else{if($>-1&&V<$)break;$<0&&($=W-s),O.push(z,V,W),I++,a.next()}}if(I){let z=new Uint16Array(I*4),V=O[O.length-2];for(let W=O.length-3,J=0;W>=0;W-=3)z[J++]=O[W],z[J++]=O[W+1]-V,z[J++]=O[W+2]-V,z[J++]=J;T.push(new cf(z,O[2]-V,r)),M.push(V-j)}}function x(j,R){return(T,M,O)=>{let I=0,$=T.length-1,z,V;if($>=0&&(z=T[$])instanceof cr){if(!$&&z.type==j&&z.length==O)return z;(V=z.prop(sn.lookAhead))&&(I=M[$]+z.length+V)}return w(j,T,M,O,I,R)}}function y(j,R,T,M,O,I,$,z,V){let W=[],J=[];for(;j.length>M;)W.push(j.pop()),J.push(R.pop()+T-O);j.push(w(r.types[$],W,J,I-O,z-I,V)),R.push(O-T)}function w(j,R,T,M,O,I,$){if(I){let z=[sn.contextHash,I];$=$?[z].concat($):[z]}if(O>25){let z=[sn.lookAhead,O];$=$?[z].concat($):[z]}return new cr(j,R,T,M,$)}function k(j,R){let T=a.fork(),M=0,O=0,I=0,$=T.end-s,z={size:0,start:0,skip:0};e:for(let V=T.pos-j;T.pos>V;){let W=T.size;if(T.id==R&&W>=0){z.size=M,z.start=O,z.skip=I,I+=4,M+=4,T.next();continue}let J=T.pos-W;if(W<0||J<V||T.start<$)break;let G=T.id>=o?4:0,F=T.start;for(T.next();T.pos>J;){if(T.size<0)if(T.size==-3||T.size==-4)G+=4;else break e;else T.id>=o&&(G+=4);T.next()}O=F,M+=W,I+=G}return(R<0||M==j)&&(z.size=M,z.start=O,z.skip=I),z.size>4?z:void 0}function S(j,R,T){let{id:M,start:O,end:I,size:$}=a;if(a.next(),$>=0&&M<o){let z=T;if($>4){let V=a.pos-($-4);for(;a.pos>V;)T=S(j,R,T)}R[--T]=z,R[--T]=I-j,R[--T]=O-j,R[--T]=M}else $==-3?d=M:$==-4&&(f=M);return T}let C=[],_=[];for(;a.pos>0;)m(t.start||0,t.bufferStart||0,C,_,-1,0);let E=(e=t.length)!==null&&e!==void 0?e:C.length?_[0]+C[0].length:0;return new cr(c[t.topID],C.reverse(),_.reverse(),E)}const wV=new WeakMap;function QC(t,e){if(!t.isAnonymous||e instanceof cf||e.type!=t)return 1;let n=wV.get(e);if(n==null){n=1;for(let r of e.children){if(r.type!=t||!(r instanceof cr)){n=1;break}n+=QC(t,r)}wV.set(e,n)}return n}function j9(t,e,n,r,s,i,o,a,c){let d=0;for(let y=r;y<s;y++)d+=QC(t,e[y]);let f=Math.ceil(d*1.5/8),m=[],p=[];function x(y,w,k,S,C){for(let _=k;_<S;){let E=_,j=w[_],R=QC(t,y[_]);for(_++;_<S;_++){let T=QC(t,y[_]);if(R+T>=f)break;R+=T}if(_==E+1){if(R>f){let T=y[E];x(T.children,T.positions,0,T.children.length,w[E]+C);continue}m.push(y[E])}else{let T=w[_-1]+y[_-1].length-j;m.push(j9(t,y,w,E,_,j,T,null,c))}p.push(j+C-i)}}return x(e,n,r,s,0),(a||c)(m,p,o)}class MKe{constructor(){this.map=new WeakMap}setBuffer(e,n,r){let s=this.map.get(e);s||this.map.set(e,s=new Map),s.set(n,r)}getBuffer(e,n){let r=this.map.get(e);return r&&r.get(n)}set(e,n){e instanceof Pl?this.setBuffer(e.context.buffer,e.index,n):e instanceof ci&&this.map.set(e.tree,n)}get(e){return e instanceof Pl?this.getBuffer(e.context.buffer,e.index):e instanceof ci?this.map.get(e.tree):void 0}cursorSet(e,n){e.buffer?this.setBuffer(e.buffer.buffer,e.index,n):this.map.set(e.tree,n)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class uu{constructor(e,n,r,s,i=!1,o=!1){this.from=e,this.to=n,this.tree=r,this.offset=s,this.open=(i?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,n=[],r=!1){let s=[new uu(0,e.length,e,0,!1,r)];for(let i of n)i.to>e.length&&s.push(i);return s}static applyChanges(e,n,r=128){if(!n.length)return e;let s=[],i=1,o=e.length?e[0]:null;for(let a=0,c=0,d=0;;a++){let f=a<n.length?n[a]:null,m=f?f.fromA:1e9;if(m-c>=r)for(;o&&o.from<m;){let p=o;if(c>=p.from||m<=p.to||d){let x=Math.max(p.from,c)-d,y=Math.min(p.to,m)-d;p=x>=y?null:new uu(x,y,p.tree,p.offset+d,a>0,!!f)}if(p&&s.push(p),o.to>m)break;o=i<e.length?e[i++]:null}if(!f)break;c=f.toA,d=f.toA-f.toB}return s}}class wre{startParse(e,n,r){return typeof e=="string"&&(e=new b6e(e)),r=r?r.length?r.map(s=>new aa(s.from,s.to)):[new aa(0,0)]:[new aa(0,e.length)],this.createParse(e,n||[],r)}parse(e,n,r){let s=this.startParse(e,n,r);for(;;){let i=s.advance();if(i)return i}}}class b6e{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,n){return this.string.slice(e,n)}}function RKe(t){return(e,n,r,s)=>new w6e(e,t,n,r,s)}class CV{constructor(e,n,r,s,i,o){this.parser=e,this.parse=n,this.overlay=r,this.bracketed=s,this.target=i,this.from=o}}function kV(t){if(!t.length||t.some(e=>e.from>=e.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(t))}class v6e{constructor(e,n,r,s,i,o,a,c){this.parser=e,this.predicate=n,this.mounts=r,this.index=s,this.start=i,this.bracketed=o,this.target=a,this.prev=c,this.depth=0,this.ranges=[]}}const Z4=new sn({perNode:!0});class w6e{constructor(e,n,r,s,i){this.nest=n,this.input=r,this.fragments=s,this.ranges=i,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}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 s of this.inner)s.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let r=this.baseTree;return this.stoppedAt!=null&&(r=new cr(r.type,r.children,r.positions,r.length,r.propValues.concat([[Z4,this.stoppedAt]]))),r}let e=this.inner[this.innerDone],n=e.parse.advance();if(n){this.innerDone++;let r=Object.assign(Object.create(null),e.target.props);r[sn.mounted.id]=new Qp(n,e.overlay,e.parser,e.bracketed),e.target.props=r}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let n=this.innerDone;n<this.inner.length;n++)this.inner[n].from<e&&(e=Math.min(e,this.inner[n].parse.parsedPos));return e}stopAt(e){if(this.stoppedAt=e,this.baseParse)this.baseParse.stopAt(e);else for(let n=this.innerDone;n<this.inner.length;n++)this.inner[n].parse.stopAt(e)}startInner(){let e=new S6e(this.fragments),n=null,r=null,s=new Lk(new ci(this.baseTree,this.ranges[0].from,0,null),ar.IncludeAnonymous|ar.IgnoreMounts);e:for(let i,o;;){let a=!0,c;if(this.stoppedAt!=null&&s.from>=this.stoppedAt)a=!1;else if(e.hasNode(s)){if(n){let d=n.mounts.find(f=>f.frag.from<=s.from&&f.frag.to>=s.to&&f.mount.overlay);if(d)for(let f of d.mount.overlay){let m=f.from+d.pos,p=f.to+d.pos;m>=s.from&&p<=s.to&&!n.ranges.some(x=>x.from<p&&x.to>m)&&n.ranges.push({from:m,to:p})}}a=!1}else if(r&&(o=C6e(r.ranges,s.from,s.to)))a=o!=2;else if(!s.type.isAnonymous&&(i=this.nest(s,this.input))&&(s.from<s.to||!i.overlay)){s.tree||(k6e(s),n&&n.depth++,r&&r.depth++);let d=e.findMounts(s.from,i.parser);if(typeof i.overlay=="function")n=new v6e(i.parser,i.overlay,d,this.inner.length,s.from,!!i.bracketed,s.tree,n);else{let f=NV(this.ranges,i.overlay||(s.from<s.to?[new aa(s.from,s.to)]:[]));f.length&&kV(f),(f.length||!i.overlay)&&this.inner.push(new CV(i.parser,f.length?i.parser.startParse(this.input,EV(d,f),f):i.parser.startParse(""),i.overlay?i.overlay.map(m=>new aa(m.from-s.from,m.to-s.from)):null,!!i.bracketed,s.tree,f.length?f[0].from:s.from)),i.overlay?f.length&&(r={ranges:f,depth:0,prev:r}):a=!1}}else if(n&&(c=n.predicate(s))&&(c===!0&&(c=new aa(s.from,s.to)),c.from<c.to)){let d=n.ranges.length-1;d>=0&&n.ranges[d].to==c.from?n.ranges[d]={from:n.ranges[d].from,to:c.to}:n.ranges.push(c)}if(a&&s.firstChild())n&&n.depth++,r&&r.depth++;else for(;!s.nextSibling();){if(!s.parent())break e;if(n&&!--n.depth){let d=NV(this.ranges,n.ranges);d.length&&(kV(d),this.inner.splice(n.index,0,new CV(n.parser,n.parser.startParse(this.input,EV(n.mounts,d),d),n.ranges.map(f=>new aa(f.from-n.start,f.to-n.start)),n.bracketed,n.target,d[0].from))),n=n.prev}r&&!--r.depth&&(r=r.prev)}}}}function C6e(t,e,n){for(let r of t){if(r.from>=n)break;if(r.to>e)return r.from<=e&&r.to>=n?2:1}return 0}function SV(t,e,n,r,s,i){if(e<n){let o=t.buffer[e+1];r.push(t.slice(e,n,o)),s.push(o-i)}}function k6e(t){let{node:e}=t,n=[],r=e.context.buffer;do n.push(t.index),t.parent();while(!t.tree);let s=t.tree,i=s.children.indexOf(r),o=s.children[i],a=o.buffer,c=[i];function d(f,m,p,x,y,w){let k=n[w],S=[],C=[];SV(o,f,k,S,C,x);let _=a[k+1],E=a[k+2];c.push(S.length);let j=w?d(k+4,a[k+3],o.set.types[a[k]],_,E-_,w-1):e.toTree();return S.push(j),C.push(_-x),SV(o,a[k+3],m,S,C,x),new cr(p,S,C,y)}s.children[i]=d(0,a.length,Ai.none,0,o.length,n.length-1);for(let f of c){let m=t.tree.children[f],p=t.tree.positions[f];t.yield(new ci(m,p+t.from,f,t._tree))}}class _V{constructor(e,n){this.offset=n,this.done=!1,this.cursor=e.cursor(ar.IncludeAnonymous|ar.IgnoreMounts)}moveTo(e){let{cursor:n}=this,r=e-this.offset;for(;!this.done&&n.from<r;)n.to>=e&&n.enter(r,1,ar.IgnoreOverlays|ar.ExcludeBuffers)||n.next(!1)||(this.done=!0)}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let n=this.cursor.tree;;){if(n==e.tree)return!0;if(n.children.length&&n.positions[0]==0&&n.children[0]instanceof cr)n=n.children[0];else break}return!1}}class S6e{constructor(e){var n;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let r=this.curFrag=e[0];this.curTo=(n=r.tree.prop(Z4))!==null&&n!==void 0?n:r.to,this.inner=new _V(r.tree,-r.offset)}else this.curFrag=this.inner=null}hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){var e;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let n=this.curFrag=this.fragments[this.fragI];this.curTo=(e=n.tree.prop(Z4))!==null&&e!==void 0?e:n.to,this.inner=new _V(n.tree,-n.offset)}}findMounts(e,n){var r;let s=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let i=this.inner.cursor.node;i;i=i.parent){let o=(r=i.tree)===null||r===void 0?void 0:r.prop(sn.mounted);if(o&&o.parser==n)for(let a=this.fragI;a<this.fragments.length;a++){let c=this.fragments[a];if(c.from>=i.to)break;c.tree==this.curFrag.tree&&s.push({frag:c,pos:i.from-c.offset,mount:o})}}}return s}}function NV(t,e){let n=null,r=e;for(let s=1,i=0;s<t.length;s++){let o=t[s-1].to,a=t[s].from;for(;i<r.length;i++){let c=r[i];if(c.from>=a)break;c.to<=o||(n||(r=n=e.slice()),c.from<o?(n[i]=new aa(c.from,o),c.to>a&&n.splice(i+1,0,new aa(a,c.to))):c.to>a?n[i--]=new aa(a,c.to):n.splice(i--,1))}}return r}function _6e(t,e,n,r){let s=0,i=0,o=!1,a=!1,c=-1e9,d=[];for(;;){let f=s==t.length?1e9:o?t[s].to:t[s].from,m=i==e.length?1e9:a?e[i].to:e[i].from;if(o!=a){let p=Math.max(c,n),x=Math.min(f,m,r);p<x&&d.push(new aa(p,x))}if(c=Math.min(f,m),c==1e9)break;f==c&&(o?(o=!1,s++):o=!0),m==c&&(a?(a=!1,i++):a=!0)}return d}function EV(t,e){let n=[];for(let{pos:r,mount:s,frag:i}of t){let o=r+(s.overlay?s.overlay[0].from:0),a=o+s.tree.length,c=Math.max(i.from,o),d=Math.min(i.to,a);if(s.overlay){let f=s.overlay.map(p=>new aa(p.from+r,p.to+r)),m=_6e(e,f,c,d);for(let p=0,x=c;;p++){let y=p==m.length,w=y?d:m[p].from;if(w>x&&n.push(new uu(x,w,s.tree,-o,i.from>=x||i.openStart,i.to<=w||i.openEnd)),y)break;x=m[p].to}}else n.push(new uu(c,d,s.tree,-o,i.from>=o||i.openStart,i.to<=a||i.openEnd))}return n}let N6e=0;class na{constructor(e,n,r,s){this.name=e,this.set=n,this.base=r,this.modified=s,this.id=N6e++}toString(){let{name:e}=this;for(let n of this.modified)n.name&&(e=`${n.name}(${e})`);return e}static define(e,n){let r=typeof e=="string"?e:"?";if(e instanceof na&&(n=e),n!=null&&n.base)throw new Error("Can not derive from a modified tag");let s=new na(r,[],null,[]);if(s.set.push(s),n)for(let i of n.set)s.set.push(i);return s}static defineModifier(e){let n=new Pk(e);return r=>r.modified.indexOf(n)>-1?r:Pk.get(r.base||r,r.modified.concat(n).sort((s,i)=>s.id-i.id))}}let E6e=0;class Pk{constructor(e){this.name=e,this.instances=[],this.id=E6e++}static get(e,n){if(!n.length)return e;let r=n[0].instances.find(a=>a.base==e&&j6e(n,a.modified));if(r)return r;let s=[],i=new na(e.name,s,e,n);for(let a of n)a.instances.push(i);let o=A6e(n);for(let a of e.set)if(!a.modified.length)for(let c of o)s.push(Pk.get(a,c));return i}}function j6e(t,e){return t.length==e.length&&t.every((n,r)=>n==e[r])}function A6e(t){let e=[[]];for(let n=0;n<t.length;n++)for(let r=0,s=e.length;r<s;r++)e.push(e[r].concat(t[n]));return e.sort((n,r)=>r.length-n.length)}function T6e(t){let e=Object.create(null);for(let n in t){let r=t[n];Array.isArray(r)||(r=[r]);for(let s of n.split(" "))if(s){let i=[],o=2,a=s;for(let m=0;;){if(a=="..."&&m>0&&m+3==s.length){o=1;break}let p=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(a);if(!p)throw new RangeError("Invalid path: "+s);if(i.push(p[0]=="*"?"":p[0][0]=='"'?JSON.parse(p[0]):p[0]),m+=p[0].length,m==s.length)break;let x=s[m++];if(m==s.length&&x=="!"){o=0;break}if(x!="/")throw new RangeError("Invalid path: "+s);a=s.slice(m)}let c=i.length-1,d=i[c];if(!d)throw new RangeError("Invalid path: "+s);let f=new wb(r,o,c>0?i.slice(0,c):null);e[d]=f.sort(e[d])}}return Cre.add(e)}const Cre=new sn({combine(t,e){let n,r,s;for(;t||e;){if(!t||e&&t.depth>=e.depth?(s=e,e=e.next):(s=t,t=t.next),n&&n.mode==s.mode&&!s.context&&!n.context)continue;let i=new wb(s.tags,s.mode,s.context);n?n.next=i:r=i,n=i}return r}});class wb{constructor(e,n,r,s){this.tags=e,this.mode=n,this.context=r,this.next=s}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}wb.empty=new wb([],2,null);function kre(t,e){let n=Object.create(null);for(let i of t)if(!Array.isArray(i.tag))n[i.tag.id]=i.class;else for(let o of i.tag)n[o.id]=i.class;let{scope:r,all:s=null}=e||{};return{style:i=>{let o=s;for(let a of i)for(let c of a.set){let d=n[c.id];if(d){o=o?o+" "+d:d;break}}return o},scope:r}}function M6e(t,e){let n=null;for(let r of t){let s=r.style(e);s&&(n=n?n+" "+s:s)}return n}function R6e(t,e,n,r=0,s=t.length){let i=new O6e(r,Array.isArray(e)?e:[e],n);i.highlightRange(t.cursor(),r,s,"",i.highlighters),i.flush(s)}class O6e{constructor(e,n,r){this.at=e,this.highlighters=n,this.span=r,this.class=""}startSpan(e,n){n!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=n)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,n,r,s,i){let{type:o,from:a,to:c}=e;if(a>=r||c<=n)return;o.isTop&&(i=this.highlighters.filter(x=>!x.scope||x.scope(o)));let d=s,f=I6e(e)||wb.empty,m=M6e(i,f.tags);if(m&&(d&&(d+=" "),d+=m,f.mode==1&&(s+=(s?" ":"")+m)),this.startSpan(Math.max(n,a),d),f.opaque)return;let p=e.tree&&e.tree.prop(sn.mounted);if(p&&p.overlay){let x=e.node.enter(p.overlay[0].from+a,1),y=this.highlighters.filter(k=>!k.scope||k.scope(p.tree.type)),w=e.firstChild();for(let k=0,S=a;;k++){let C=k<p.overlay.length?p.overlay[k]:null,_=C?C.from+a:c,E=Math.max(n,S),j=Math.min(r,_);if(E<j&&w)for(;e.from<j&&(this.highlightRange(e,E,j,s,i),this.startSpan(Math.min(j,e.to),d),!(e.to>=_||!e.nextSibling())););if(!C||_>r)break;S=C.to+a,S>n&&(this.highlightRange(x.cursor(),Math.max(n,C.from+a),Math.min(r,S),"",y),this.startSpan(Math.min(r,S),d))}w&&e.parent()}else if(e.firstChild()){p&&(s="");do if(!(e.to<=n)){if(e.from>=r)break;this.highlightRange(e,n,r,s,i),this.startSpan(Math.min(r,e.to),d)}while(e.nextSibling());e.parent()}}}function I6e(t){let e=t.type.prop(Cre);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}const nt=na.define,Xw=nt(),Sd=nt(),jV=nt(Sd),AV=nt(Sd),_d=nt(),eC=nt(_d),Jj=nt(_d),bl=nt(),Wf=nt(bl),gl=nt(),xl=nt(),Q4=nt(),F0=nt(Q4),tC=nt(),je={comment:Xw,lineComment:nt(Xw),blockComment:nt(Xw),docComment:nt(Xw),name:Sd,variableName:nt(Sd),typeName:jV,tagName:nt(jV),propertyName:AV,attributeName:nt(AV),className:nt(Sd),labelName:nt(Sd),namespace:nt(Sd),macroName:nt(Sd),literal:_d,string:eC,docString:nt(eC),character:nt(eC),attributeValue:nt(eC),number:Jj,integer:nt(Jj),float:nt(Jj),bool:nt(_d),regexp:nt(_d),escape:nt(_d),color:nt(_d),url:nt(_d),keyword:gl,self:nt(gl),null:nt(gl),atom:nt(gl),unit:nt(gl),modifier:nt(gl),operatorKeyword:nt(gl),controlKeyword:nt(gl),definitionKeyword:nt(gl),moduleKeyword:nt(gl),operator:xl,derefOperator:nt(xl),arithmeticOperator:nt(xl),logicOperator:nt(xl),bitwiseOperator:nt(xl),compareOperator:nt(xl),updateOperator:nt(xl),definitionOperator:nt(xl),typeOperator:nt(xl),controlOperator:nt(xl),punctuation:Q4,separator:nt(Q4),bracket:F0,angleBracket:nt(F0),squareBracket:nt(F0),paren:nt(F0),brace:nt(F0),content:bl,heading:Wf,heading1:nt(Wf),heading2:nt(Wf),heading3:nt(Wf),heading4:nt(Wf),heading5:nt(Wf),heading6:nt(Wf),contentSeparator:nt(bl),list:nt(bl),quote:nt(bl),emphasis:nt(bl),strong:nt(bl),link:nt(bl),monospace:nt(bl),strikethrough:nt(bl),inserted:nt(),deleted:nt(),changed:nt(),invalid:nt(),meta:tC,documentMeta:nt(tC),annotation:nt(tC),processingInstruction:nt(tC),definition:na.defineModifier("definition"),constant:na.defineModifier("constant"),function:na.defineModifier("function"),standard:na.defineModifier("standard"),local:na.defineModifier("local"),special:na.defineModifier("special")};for(let t in je){let e=je[t];e instanceof na&&(e.name=t)}kre([{tag:je.link,class:"tok-link"},{tag:je.heading,class:"tok-heading"},{tag:je.emphasis,class:"tok-emphasis"},{tag:je.strong,class:"tok-strong"},{tag:je.keyword,class:"tok-keyword"},{tag:je.atom,class:"tok-atom"},{tag:je.bool,class:"tok-bool"},{tag:je.url,class:"tok-url"},{tag:je.labelName,class:"tok-labelName"},{tag:je.inserted,class:"tok-inserted"},{tag:je.deleted,class:"tok-deleted"},{tag:je.literal,class:"tok-literal"},{tag:je.string,class:"tok-string"},{tag:je.number,class:"tok-number"},{tag:[je.regexp,je.escape,je.special(je.string)],class:"tok-string2"},{tag:je.variableName,class:"tok-variableName"},{tag:je.local(je.variableName),class:"tok-variableName tok-local"},{tag:je.definition(je.variableName),class:"tok-variableName tok-definition"},{tag:je.special(je.variableName),class:"tok-variableName2"},{tag:je.definition(je.propertyName),class:"tok-propertyName tok-definition"},{tag:je.typeName,class:"tok-typeName"},{tag:je.namespace,class:"tok-namespace"},{tag:je.className,class:"tok-className"},{tag:je.macroName,class:"tok-macroName"},{tag:je.propertyName,class:"tok-propertyName"},{tag:je.operator,class:"tok-operator"},{tag:je.comment,class:"tok-comment"},{tag:je.meta,class:"tok-meta"},{tag:je.invalid,class:"tok-invalid"},{tag:je.punctuation,class:"tok-punctuation"}]);var Yj;const ah=new sn;function Sre(t){return ut.define({combine:t?e=>e.concat(t):void 0})}const D6e=new sn;class la{constructor(e,n,r=[],s=""){this.data=e,this.name=s,Cn.prototype.hasOwnProperty("tree")||Object.defineProperty(Cn.prototype,"tree",{get(){return Ws(this)}}),this.parser=n,this.extension=[uf.of(this),Cn.languageData.of((i,o,a)=>{let c=TV(i,o,a),d=c.type.prop(ah);if(!d)return[];let f=i.facet(d),m=c.type.prop(D6e);if(m){let p=c.resolve(o-c.from,a);for(let x of m)if(x.test(p,i)){let y=i.facet(x.facet);return x.type=="replace"?y:y.concat(f)}}return f})].concat(r)}isActiveAt(e,n,r=-1){return TV(e,n,r).type.prop(ah)==this.data}findRegions(e){let n=e.facet(uf);if((n==null?void 0:n.data)==this.data)return[{from:0,to:e.doc.length}];if(!n||!n.allowsNesting)return[];let r=[],s=(i,o)=>{if(i.prop(ah)==this.data){r.push({from:o,to:o+i.length});return}let a=i.prop(sn.mounted);if(a){if(a.tree.prop(ah)==this.data){if(a.overlay)for(let c of a.overlay)r.push({from:c.from+o,to:c.to+o});else r.push({from:o,to:o+i.length});return}else if(a.overlay){let c=r.length;if(s(a.tree,a.overlay[0].from+o),r.length>c)return}}for(let c=0;c<i.children.length;c++){let d=i.children[c];d instanceof cr&&s(d,i.positions[c]+o)}};return s(Ws(e),0),r}get allowsNesting(){return!0}}la.setState=zt.define();function TV(t,e,n){let r=t.facet(uf),s=Ws(t).topNode;if(!r||r.allowsNesting)for(let i=s;i;i=i.enter(e,n,ar.ExcludeBuffers|ar.EnterBracketed))i.type.isTop&&(s=i);return s}class X4 extends la{constructor(e,n,r){super(e,n,[],r),this.parser=n}static define(e){let n=Sre(e.languageData);return new X4(n,e.parser.configure({props:[ah.add(r=>r.isTop?n:void 0)]}),e.name)}configure(e,n){return new X4(this.data,this.parser.configure(e),n||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function Ws(t){let e=t.field(la.state,!1);return e?e.tree:cr.empty}class L6e{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,n){let r=this.cursorPos-this.string.length;return e<r||n>=this.cursorPos?this.doc.sliceString(e,n):this.string.slice(e-r,n-r)}}let $0=null;class Wg{constructor(e,n,r=[],s,i,o,a,c){this.parser=e,this.state=n,this.fragments=r,this.tree=s,this.treeLen=i,this.viewport=o,this.skipped=a,this.scheduleOn=c,this.parse=null,this.tempSkipped=[]}static create(e,n,r){return new Wg(e,n,[],cr.empty,0,r,[],null)}startParse(){return this.parser.startParse(new L6e(this.state.doc),this.fragments)}work(e,n){return n!=null&&n>=this.state.doc.length&&(n=void 0),this.tree!=cr.empty&&this.isDone(n??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof e=="number"){let s=Date.now()+e;e=()=>Date.now()>s}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 s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(uu.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(n??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,n;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(n=this.parse.advance()););}),this.treeLen=e,this.tree=n,this.fragments=this.withoutTempSkipped(uu.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let n=$0;$0=this;try{return e()}finally{$0=n}}withoutTempSkipped(e){for(let n;n=this.tempSkipped.pop();)e=MV(e,n.from,n.to);return e}changes(e,n){let{fragments:r,tree:s,treeLen:i,viewport:o,skipped:a}=this;if(this.takeTree(),!e.empty){let c=[];if(e.iterChangedRanges((d,f,m,p)=>c.push({fromA:d,toA:f,fromB:m,toB:p})),r=uu.applyChanges(r,c),s=cr.empty,i=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){a=[];for(let d of this.skipped){let f=e.mapPos(d.from,1),m=e.mapPos(d.to,-1);f<m&&a.push({from:f,to:m})}}}return new Wg(this.parser,n,r,s,i,o,a,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let n=this.skipped.length;for(let r=0;r<this.skipped.length;r++){let{from:s,to:i}=this.skipped[r];s<e.to&&i>e.from&&(this.fragments=MV(this.fragments,s,i),this.skipped.splice(r--,1))}return this.skipped.length>=n?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,n){this.skipped.push({from:e,to:n})}static getSkippingParser(e){return new class extends wre{createParse(n,r,s){let i=s[0].from,o=s[s.length-1].to;return{parsedPos:i,advance(){let c=$0;if(c){for(let d of s)c.tempSkipped.push(d);e&&(c.scheduleOn=c.scheduleOn?Promise.all([c.scheduleOn,e]):e)}return this.parsedPos=o,new cr(Ai.none,[],[],o-i)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let n=this.fragments;return this.treeLen>=e&&n.length&&n[0].from==0&&n[0].to>=e}static get(){return $0}}function MV(t,e,n){return uu.applyChanges(t,[{fromA:e,toA:n,fromB:e,toB:n}])}class Gg{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let n=this.context.changes(e.changes,e.state),r=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),n.viewport.to);return n.work(20,r)||n.takeTree(),new Gg(n)}static init(e){let n=Math.min(3e3,e.doc.length),r=Wg.create(e.facet(uf).parser,e,{from:0,to:n});return r.work(20,n)||r.takeTree(),new Gg(r)}}la.state=Is.define({create:Gg.init,update(t,e){for(let n of e.effects)if(n.is(la.setState))return n.value;return e.startState.facet(uf)!=e.state.facet(uf)?Gg.init(e.state):t.apply(e)}});let _re=t=>{let e=setTimeout(()=>t(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(_re=t=>{let e=-1,n=setTimeout(()=>{e=requestIdleCallback(t,{timeout:400})},100);return()=>e<0?clearTimeout(n):cancelIdleCallback(e)});const Zj=typeof navigator<"u"&&(!((Yj=navigator.scheduling)===null||Yj===void 0)&&Yj.isInputPending)?()=>navigator.scheduling.isInputPending():null,P6e=us.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let n=this.view.state.field(la.state).context;(n.updateViewport(e.view.viewport)||this.view.viewport.to>n.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(n)}scheduleWork(){if(this.working)return;let{state:e}=this.view,n=e.field(la.state);(n.tree!=n.context.tree||!n.context.isDone(e.doc.length))&&(this.working=_re(this.work))}work(e){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:s}}=this.view,i=r.field(la.state);if(i.tree==i.context.tree&&i.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!Zj?Math.max(25,e.timeRemaining()-5):1e9),a=i.context.treeLen<s&&r.doc.length>s+1e3,c=i.context.work(()=>Zj&&Zj()||Date.now()>o,s+(a?0:1e5));this.chunkBudget-=Date.now()-n,(c||this.chunkBudget<=0)&&(i.context.takeTree(),this.view.dispatch({effects:la.setState.of(new Gg(i.context))})),this.chunkBudget>0&&!(c&&!a)&&this.scheduleWork(),this.checkAsyncSchedule(i.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(n=>Xi(this.view.state,n)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),uf=ut.define({combine(t){return t.length?t[0]:null},enables:t=>[la.state,P6e,at.contentAttributes.compute([t],e=>{let n=e.facet(t);return n&&n.name?{"data-language":n.name}:{}})]});class F6e{constructor(e,n=[]){this.language=e,this.support=n,this.extension=[e,n]}}class _e{constructor(e,n,r,s,i,o=void 0){this.name=e,this.alias=n,this.extensions=r,this.filename=s,this.loadFunc=i,this.support=o,this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then(e=>this.support=e,e=>{throw this.loading=null,e}))}static of(e){let{load:n,support:r}=e;if(!n){if(!r)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");n=()=>Promise.resolve(r)}return new _e(e.name,(e.alias||[]).concat(e.name).map(s=>s.toLowerCase()),e.extensions||[],e.filename,n,r)}static matchFilename(e,n){for(let s of e)if(s.filename&&s.filename.test(n))return s;let r=/\.([^.]+)$/.exec(n);if(r){for(let s of e)if(s.extensions.indexOf(r[1])>-1)return s}return null}static matchLanguageName(e,n,r=!0){n=n.toLowerCase();for(let s of e)if(s.alias.some(i=>i==n))return s;if(r)for(let s of e)for(let i of s.alias){let o=n.indexOf(i);if(o>-1&&(i.length>2||!/\w/.test(n[o-1])&&!/\w/.test(n[o+i.length])))return s}return null}}const $6e=ut.define(),W_=ut.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some(n=>n!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}});function rm(t){let e=t.facet(W_);return e.charCodeAt(0)==9?t.tabSize*e.length:e.length}function Cb(t,e){let n="",r=t.tabSize,s=t.facet(W_)[0];if(s==" "){for(;e>=r;)n+=" ",e-=r;s=" "}for(let i=0;i<e;i++)n+=s;return n}function A9(t,e){t instanceof Cn&&(t=new G_(t));for(let r of t.state.facet($6e)){let s=r(t,e);if(s!==void 0)return s}let n=Ws(t.state);return n.length>=e?B6e(t,n,e):null}class G_{constructor(e,n={}){this.state=e,this.options=n,this.unit=rm(e)}lineAt(e,n=1){let r=this.state.doc.lineAt(e),{simulateBreak:s,simulateDoubleBreak:i}=this.options;return s!=null&&s>=r.from&&s<=r.to?i&&s==e?{text:"",from:e}:(n<0?s<e:s<=e)?{text:r.text.slice(s-r.from),from:s}:{text:r.text.slice(0,s-r.from),from:r.from}:r}textAfterPos(e,n=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:r,from:s}=this.lineAt(e,n);return r.slice(e-s,Math.min(r.length,e+100-s))}column(e,n=1){let{text:r,from:s}=this.lineAt(e,n),i=this.countColumn(r,e-s),o=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return o>-1&&(i+=o-this.countColumn(r,r.search(/\S|$/))),i}countColumn(e,n=e.length){return Ex(e,this.state.tabSize,n)}lineIndent(e,n=1){let{text:r,from:s}=this.lineAt(e,n),i=this.options.overrideIndentation;if(i){let o=i(s);if(o>-1)return o}return this.countColumn(r,r.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Nre=new sn;function B6e(t,e,n){let r=e.resolveStack(n),s=e.resolveInner(n,-1).resolve(n,0).enterUnfinishedNodesBefore(n);if(s!=r.node){let i=[];for(let o=s;o&&!(o.from<r.node.from||o.to>r.node.to||o.from==r.node.from&&o.type==r.node.type);o=o.parent)i.push(o);for(let o=i.length-1;o>=0;o--)r={node:i[o],next:r}}return Ere(r,t,n)}function Ere(t,e,n){for(let r=t;r;r=r.next){let s=V6e(r.node);if(s)return s(T9.create(e,n,r))}return 0}function z6e(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}function V6e(t){let e=t.type.prop(Nre);if(e)return e;let n=t.firstChild,r;if(n&&(r=n.type.prop(sn.closedBy))){let s=t.lastChild,i=s&&r.indexOf(s.name)>-1;return o=>jre(o,!0,1,void 0,i&&!z6e(o)?s.from:void 0)}return t.parent==null?H6e:null}function H6e(){return 0}class T9 extends G_{constructor(e,n,r){super(e.state,e.options),this.base=e,this.pos=n,this.context=r}get node(){return this.context.node}static create(e,n,r){return new T9(e,n,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let n=this.state.doc.lineAt(e.from);for(;;){let r=e.resolve(n.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(U6e(r,e))break;n=this.state.doc.lineAt(r.from)}return this.lineIndent(n.from)}continue(){return Ere(this.context.next,this.base,this.pos)}}function U6e(t,e){for(let n=e;n;n=n.parent)if(t==n)return!0;return!1}function q6e(t){let e=t.node,n=e.childAfter(e.from),r=e.lastChild;if(!n)return null;let s=t.options.simulateBreak,i=t.state.doc.lineAt(n.from),o=s==null||s<=i.from?i.to:Math.min(i.to,s);for(let a=n.to;;){let c=e.childAfter(a);if(!c||c==r)return null;if(!c.type.isSkipped){if(c.from>=o)return null;let d=/^ */.exec(i.text.slice(n.to-i.from))[0].length;return{from:n.from,to:n.to+d}}a=c.to}}function IKe({closing:t,align:e=!0,units:n=1}){return r=>jre(r,e,n,t)}function jre(t,e,n,r,s){let i=t.textAfter,o=i.match(/^\s*/)[0].length,a=r&&i.slice(o,o+r.length)==r||s==t.pos+o,c=e?q6e(t):null;return c?a?t.column(c.from):t.column(c.to):t.baseIndent+(a?0:t.unit*n)}const DKe=t=>t.baseIndent;function LKe({except:t,units:e=1}={}){return n=>{let r=t&&t.test(n.textAfter);return n.baseIndent+(r?0:e*n.unit)}}const K6e=200;function W6e(){return Cn.transactionFilter.of(t=>{if(!t.docChanged||!t.isUserEvent("input.type")&&!t.isUserEvent("input.complete"))return t;let e=t.startState.languageDataAt("indentOnInput",t.startState.selection.main.head);if(!e.length)return t;let n=t.newDoc,{head:r}=t.newSelection.main,s=n.lineAt(r);if(r>s.from+K6e)return t;let i=n.sliceString(s.from,r);if(!e.some(d=>d.test(i)))return t;let{state:o}=t,a=-1,c=[];for(let{head:d}of o.selection.ranges){let f=o.doc.lineAt(d);if(f.from==a)continue;a=f.from;let m=A9(o,f.from);if(m==null)continue;let p=/^\s*/.exec(f.text)[0],x=Cb(o,m);p!=x&&c.push({from:f.from,to:f.from+p.length,insert:x})}return c.length?[t,{changes:c,sequential:!0}]:t})}const G6e=ut.define(),J6e=new sn;function PKe(t){let e=t.firstChild,n=t.lastChild;return e&&e.to<n.from?{from:e.to,to:n.type.isError?t.to:n.from}:null}function Y6e(t,e,n){let r=Ws(t);if(r.length<n)return null;let s=r.resolveStack(n,1),i=null;for(let o=s;o;o=o.next){let a=o.node;if(a.to<=n||a.from>n)continue;if(i&&a.from<e)break;let c=a.type.prop(J6e);if(c&&(a.to<r.length-50||r.length==t.doc.length||!Z6e(a))){let d=c(a,t);d&&d.from<=n&&d.from>=e&&d.to>n&&(i=d)}}return i}function Z6e(t){let e=t.lastChild;return e&&e.to==t.to&&e.type.isError}function Fk(t,e,n){for(let r of t.facet(G6e)){let s=r(t,e,n);if(s)return s}return Y6e(t,e,n)}function Are(t,e){let n=e.mapPos(t.from,1),r=e.mapPos(t.to,-1);return n>=r?void 0:{from:n,to:r}}const J_=zt.define({map:Are}),zv=zt.define({map:Are});function Tre(t){let e=[];for(let{head:n}of t.state.selection.ranges)e.some(r=>r.from<=n&&r.to>=n)||e.push(t.lineBlockAt(n));return e}const sm=Is.define({create(){return Mt.none},update(t,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((n,r)=>t=RV(t,n,r)),t=t.map(e.changes);for(let n of e.effects)if(n.is(J_)&&!Q6e(t,n.value.from,n.value.to)){let{preparePlaceholder:r}=e.state.facet(Ore),s=r?Mt.replace({widget:new iDe(r(e.state,n.value))}):OV;t=t.update({add:[s.range(n.value.from,n.value.to)]})}else n.is(zv)&&(t=t.update({filter:(r,s)=>n.value.from!=r||n.value.to!=s,filterFrom:n.value.from,filterTo:n.value.to}));return e.selection&&(t=RV(t,e.selection.main.head)),t},provide:t=>at.decorations.from(t),toJSON(t,e){let n=[];return t.between(0,e.doc.length,(r,s)=>{n.push(r,s)}),n},fromJSON(t){if(!Array.isArray(t)||t.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let n=0;n<t.length;){let r=t[n++],s=t[n++];if(typeof r!="number"||typeof s!="number")throw new RangeError("Invalid JSON for fold state");e.push(OV.range(r,s))}return Mt.set(e,!0)}});function RV(t,e,n=e){let r=!1;return t.between(e,n,(s,i)=>{s<n&&i>e&&(r=!0)}),r?t.update({filterFrom:e,filterTo:n,filter:(s,i)=>s>=n||i<=e}):t}function $k(t,e,n){var r;let s=null;return(r=t.field(sm,!1))===null||r===void 0||r.between(e,n,(i,o)=>{(!s||s.from>i)&&(s={from:i,to:o})}),s}function Q6e(t,e,n){let r=!1;return t.between(e,e,(s,i)=>{s==e&&i==n&&(r=!0)}),r}function Mre(t,e){return t.field(sm,!1)?e:e.concat(zt.appendConfig.of(Ire()))}const X6e=t=>{for(let e of Tre(t)){let n=Fk(t.state,e.from,e.to);if(n)return t.dispatch({effects:Mre(t.state,[J_.of(n),Rre(t,n)])}),!0}return!1},eDe=t=>{if(!t.state.field(sm,!1))return!1;let e=[];for(let n of Tre(t)){let r=$k(t.state,n.from,n.to);r&&e.push(zv.of(r),Rre(t,r,!1))}return e.length&&t.dispatch({effects:e}),e.length>0};function Rre(t,e,n=!0){let r=t.state.doc.lineAt(e.from).number,s=t.state.doc.lineAt(e.to).number;return at.announce.of(`${t.state.phrase(n?"Folded lines":"Unfolded lines")} ${r} ${t.state.phrase("to")} ${s}.`)}const tDe=t=>{let{state:e}=t,n=[];for(let r=0;r<e.doc.length;){let s=t.lineBlockAt(r),i=Fk(e,s.from,s.to);i&&n.push(J_.of(i)),r=(i?t.lineBlockAt(i.to):s).to+1}return n.length&&t.dispatch({effects:Mre(t.state,n)}),!!n.length},nDe=t=>{let e=t.state.field(sm,!1);if(!e||!e.size)return!1;let n=[];return e.between(0,t.state.doc.length,(r,s)=>{n.push(zv.of({from:r,to:s}))}),t.dispatch({effects:n}),!0},rDe=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:X6e},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:eDe},{key:"Ctrl-Alt-[",run:tDe},{key:"Ctrl-Alt-]",run:nDe}],sDe={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},Ore=ut.define({combine(t){return lc(t,sDe)}});function Ire(t){return[sm,lDe]}function Dre(t,e){let{state:n}=t,r=n.facet(Ore),s=o=>{let a=t.lineBlockAt(t.posAtDOM(o.target)),c=$k(t.state,a.from,a.to);c&&t.dispatch({effects:zv.of(c)}),o.preventDefault()};if(r.placeholderDOM)return r.placeholderDOM(t,s,e);let i=document.createElement("span");return i.textContent=r.placeholderText,i.setAttribute("aria-label",n.phrase("folded code")),i.title=n.phrase("unfold"),i.className="cm-foldPlaceholder",i.onclick=s,i}const OV=Mt.replace({widget:new class extends cc{toDOM(t){return Dre(t,null)}}});class iDe extends cc{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return Dre(e,this.value)}}const oDe={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class Qj extends Nu{constructor(e,n){super(),this.config=e,this.open=n}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){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=e.state.phrase(this.open?"Fold line":"Unfold line"),n}}function aDe(t={}){let e={...oDe,...t},n=new Qj(e,!0),r=new Qj(e,!1),s=us.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet(uf)!=o.state.facet(uf)||o.startState.field(sm,!1)!=o.state.field(sm,!1)||Ws(o.startState)!=Ws(o.state)||e.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let a=new Su;for(let c of o.viewportLineBlocks){let d=$k(o.state,c.from,c.to)?r:Fk(o.state,c.from,c.to)?n:null;d&&a.add(c.from,c.from,d)}return a.finish()}}),{domEventHandlers:i}=e;return[s,n6e({class:"cm-foldGutter",markers(o){var a;return((a=o.plugin(s))===null||a===void 0?void 0:a.markers)||un.empty},initialSpacer(){return new Qj(e,!1)},domEventHandlers:{...i,click:(o,a,c)=>{if(i.click&&i.click(o,a,c))return!0;let d=$k(o.state,a.from,a.to);if(d)return o.dispatch({effects:zv.of(d)}),!0;let f=Fk(o.state,a.from,a.to);return f?(o.dispatch({effects:J_.of(f)}),!0):!1}}}),Ire()]}const lDe=at.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 Vv{constructor(e,n){this.specs=e;let r;function s(a){let c=of.newName();return(r||(r=Object.create(null)))["."+c]=a,c}const i=typeof n.all=="string"?n.all:n.all?s(n.all):void 0,o=n.scope;this.scope=o instanceof la?a=>a.prop(ah)==o.data:o?a=>a==o:void 0,this.style=kre(e.map(a=>({tag:a.tag,class:a.class||s(Object.assign({},a,{tag:null}))})),{all:i}).style,this.module=r?new of(r):null,this.themeType=n.themeType}static define(e,n){return new Vv(e,n||{})}}const eM=ut.define(),Lre=ut.define({combine(t){return t.length?[t[0]]:null}});function Xj(t){let e=t.facet(eM);return e.length?e:t.facet(Lre)}function Pre(t,e){let n=[uDe],r;return t instanceof Vv&&(t.module&&n.push(at.styleModule.of(t.module)),r=t.themeType),e!=null&&e.fallback?n.push(Lre.of(t)):r?n.push(eM.computeN([at.darkTheme],s=>s.facet(at.darkTheme)==(r=="dark")?[t]:[])):n.push(eM.of(t)),n}class cDe{constructor(e){this.markCache=Object.create(null),this.tree=Ws(e.state),this.decorations=this.buildDeco(e,Xj(e.state)),this.decoratedTo=e.viewport.to}update(e){let n=Ws(e.state),r=Xj(e.state),s=r!=Xj(e.startState),{viewport:i}=e.view,o=e.changes.mapPos(this.decoratedTo,1);n.length<i.to&&!s&&n.type==this.tree.type&&o>=i.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(n!=this.tree||e.viewportChanged||s)&&(this.tree=n,this.decorations=this.buildDeco(e.view,r),this.decoratedTo=i.to)}buildDeco(e,n){if(!n||!this.tree.length)return Mt.none;let r=new Su;for(let{from:s,to:i}of e.visibleRanges)R6e(this.tree,n,(o,a,c)=>{r.add(o,a,this.markCache[c]||(this.markCache[c]=Mt.mark({class:c})))},s,i);return r.finish()}}const uDe=Sf.high(us.fromClass(cDe,{decorations:t=>t.decorations})),dDe=Vv.define([{tag:je.meta,color:"#404740"},{tag:je.link,textDecoration:"underline"},{tag:je.heading,textDecoration:"underline",fontWeight:"bold"},{tag:je.emphasis,fontStyle:"italic"},{tag:je.strong,fontWeight:"bold"},{tag:je.strikethrough,textDecoration:"line-through"},{tag:je.keyword,color:"#708"},{tag:[je.atom,je.bool,je.url,je.contentSeparator,je.labelName],color:"#219"},{tag:[je.literal,je.inserted],color:"#164"},{tag:[je.string,je.deleted],color:"#a11"},{tag:[je.regexp,je.escape,je.special(je.string)],color:"#e40"},{tag:je.definition(je.variableName),color:"#00f"},{tag:je.local(je.variableName),color:"#30a"},{tag:[je.typeName,je.namespace],color:"#085"},{tag:je.className,color:"#167"},{tag:[je.special(je.variableName),je.macroName],color:"#256"},{tag:je.definition(je.propertyName),color:"#00c"},{tag:je.comment,color:"#940"},{tag:je.invalid,color:"#f00"}]),fDe=at.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Fre=1e4,$re="()[]{}",Bre=ut.define({combine(t){return lc(t,{afterCursor:!0,brackets:$re,maxScanDistance:Fre,renderMatch:pDe})}}),hDe=Mt.mark({class:"cm-matchingBracket"}),mDe=Mt.mark({class:"cm-nonmatchingBracket"});function pDe(t){let e=[],n=t.matched?hDe:mDe;return e.push(n.range(t.start.from,t.start.to)),t.end&&e.push(n.range(t.end.from,t.end.to)),e}const gDe=Is.define({create(){return Mt.none},update(t,e){if(!e.docChanged&&!e.selection)return t;let n=[],r=e.state.facet(Bre);for(let s of e.state.selection.ranges){if(!s.empty)continue;let i=Fl(e.state,s.head,-1,r)||s.head>0&&Fl(e.state,s.head-1,1,r)||r.afterCursor&&(Fl(e.state,s.head,1,r)||s.head<e.state.doc.length&&Fl(e.state,s.head+1,-1,r));i&&(n=n.concat(r.renderMatch(i,e.state)))}return Mt.set(n,!0)},provide:t=>at.decorations.from(t)}),xDe=[gDe,fDe];function yDe(t={}){return[Bre.of(t),xDe]}const bDe=new sn;function tM(t,e,n){let r=t.prop(e<0?sn.openedBy:sn.closedBy);if(r)return r;if(t.name.length==1){let s=n.indexOf(t.name);if(s>-1&&s%2==(e<0?1:0))return[n[s+e]]}return null}function nM(t){let e=t.type.prop(bDe);return e?e(t.node):t}function Fl(t,e,n,r={}){let s=r.maxScanDistance||Fre,i=r.brackets||$re,o=Ws(t),a=o.resolveInner(e,n);for(let c=a;c;c=c.parent){let d=tM(c.type,n,i);if(d&&c.from<c.to){let f=nM(c);if(f&&(n>0?e>=f.from&&e<f.to:e>f.from&&e<=f.to))return vDe(t,e,n,c,f,d,i)}}return wDe(t,e,n,o,a.type,s,i)}function vDe(t,e,n,r,s,i,o){let a=r.parent,c={from:s.from,to:s.to},d=0,f=a==null?void 0:a.cursor();if(f&&(n<0?f.childBefore(r.from):f.childAfter(r.to)))do if(n<0?f.to<=r.from:f.from>=r.to){if(d==0&&i.indexOf(f.type.name)>-1&&f.from<f.to){let m=nM(f);return{start:c,end:m?{from:m.from,to:m.to}:void 0,matched:!0}}else if(tM(f.type,n,o))d++;else if(tM(f.type,-n,o)){if(d==0){let m=nM(f);return{start:c,end:m&&m.from<m.to?{from:m.from,to:m.to}:void 0,matched:!1}}d--}}while(n<0?f.prevSibling():f.nextSibling());return{start:c,matched:!1}}function wDe(t,e,n,r,s,i,o){let a=n<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1),c=o.indexOf(a);if(c<0||c%2==0!=n>0)return null;let d={from:n<0?e-1:e,to:n>0?e+1:e},f=t.doc.iterRange(e,n>0?t.doc.length:0),m=0;for(let p=0;!f.next().done&&p<=i;){let x=f.value;n<0&&(p+=x.length);let y=e+p*n;for(let w=n>0?0:x.length-1,k=n>0?x.length:-1;w!=k;w+=n){let S=o.indexOf(x[w]);if(!(S<0||r.resolveInner(y+w,1).type!=s))if(S%2==0==n>0)m++;else{if(m==1)return{start:d,end:{from:y+w,to:y+w+1},matched:S>>1==c>>1};m--}}n>0&&(p+=x.length)}return f.done?{start:d,matched:!1}:null}function IV(t,e,n,r=0,s=0){e==null&&(e=t.search(/[^\s\u00a0]/),e==-1&&(e=t.length));let i=s;for(let o=r;o<e;o++)t.charCodeAt(o)==9?i+=n-i%n:i++;return i}class zre{constructor(e,n,r,s){this.string=e,this.tabSize=n,this.indentUnit=r,this.overrideIndent=s,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(e){let n=this.string.charAt(this.pos),r;if(typeof e=="string"?r=n==e:r=n&&(e instanceof RegExp?e.test(n):e(n)),r)return++this.pos,n}eatWhile(e){let n=this.pos;for(;this.eat(e););return this.pos>n}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let n=this.string.indexOf(e,this.pos);if(n>-1)return this.pos=n,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPos<this.start&&(this.lastColumnValue=IV(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){var e;return(e=this.overrideIndent)!==null&&e!==void 0?e:IV(this.string,null,this.tabSize)}match(e,n,r){if(typeof e=="string"){let s=o=>r?o.toLowerCase():o,i=this.string.substr(this.pos,e.length);return s(i)==s(e)?(n!==!1&&(this.pos+=e.length),!0):null}else{let s=this.string.slice(this.pos).match(e);return s&&s.index>0?null:(s&&n!==!1&&(this.pos+=s[0].length),s)}}current(){return this.string.slice(this.start,this.pos)}}function CDe(t){return{name:t.name||"",token:t.token,blankLine:t.blankLine||(()=>{}),startState:t.startState||(()=>!0),copyState:t.copyState||kDe,indent:t.indent||(()=>null),languageData:t.languageData||{},tokenTable:t.tokenTable||O9,mergeTokens:t.mergeTokens!==!1}}function kDe(t){if(typeof t!="object")return t;let e={};for(let n in t){let r=t[n];e[n]=r instanceof Array?r.slice():r}return e}const DV=new WeakMap;class M9 extends la{constructor(e){let n=Sre(e.languageData),r=CDe(e),s,i=new class extends wre{createParse(o,a,c){return new _De(s,o,a,c)}};super(n,i,[],e.name),this.topNode=jDe(n,this),s=this,this.streamParser=r,this.stateAfter=new sn({perNode:!0}),this.tokenTable=e.tokenTable?new qre(r.tokenTable):EDe}static define(e){return new M9(e)}getIndent(e){let n,{overrideIndentation:r}=e.options;r&&(n=DV.get(e.state),n!=null&&n<e.pos-1e4&&(n=void 0));let s=R9(this,e.node.tree,e.node.from,e.node.from,n??e.pos),i,o;if(s?(o=s.state,i=s.pos+1):(o=this.streamParser.startState(e.unit),i=e.node.from),e.pos-i>1e4)return null;for(;i<e.pos;){let c=e.state.doc.lineAt(i),d=Math.min(e.pos,c.to);if(c.length){let f=r?r(c.from):-1,m=new zre(c.text,e.state.tabSize,e.unit,f<0?void 0:f);for(;m.pos<d-c.from;)Hre(this.streamParser.token,m,o)}else this.streamParser.blankLine(o,e.unit);if(d==e.pos)break;i=c.to+1}let a=e.lineAt(e.pos);return r&&n==null&&DV.set(e.state,a.from),this.streamParser.indent(o,/^\s*(.*)/.exec(a.text)[1],e)}get allowsNesting(){return!1}}function R9(t,e,n,r,s){let i=n>=r&&n+e.length<=s&&e.prop(t.stateAfter);if(i)return{state:t.streamParser.copyState(i),pos:n+e.length};for(let o=e.children.length-1;o>=0;o--){let a=e.children[o],c=n+e.positions[o],d=a instanceof cr&&c<s&&R9(t,a,c,r,s);if(d)return d}return null}function Vre(t,e,n,r,s){if(s&&n<=0&&r>=e.length)return e;!s&&n==0&&e.type==t.topNode&&(s=!0);for(let i=e.children.length-1;i>=0;i--){let o=e.positions[i],a=e.children[i],c;if(o<r&&a instanceof cr){if(!(c=Vre(t,a,n-o,r-o,s)))break;return s?new cr(e.type,e.children.slice(0,i).concat(c),e.positions.slice(0,i+1),o+c.length):c}}return null}function SDe(t,e,n,r,s){for(let i of e){let o=i.from+(i.openStart?25:0),a=i.to-(i.openEnd?25:0),c=o<=n&&a>n&&R9(t,i.tree,0-i.offset,n,a),d;if(c&&c.pos<=r&&(d=Vre(t,i.tree,n+i.offset,c.pos+i.offset,!1)))return{state:c.state,tree:d}}return{state:t.streamParser.startState(s?rm(s):4),tree:cr.empty}}class _De{constructor(e,n,r,s){this.lang=e,this.input=n,this.fragments=r,this.ranges=s,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=s[s.length-1].to;let i=Wg.get(),o=s[0].from,{state:a,tree:c}=SDe(e,r,o,this.to,i==null?void 0:i.state);this.state=a,this.parsedPos=this.chunkStart=o+c.length;for(let d=0;d<c.children.length;d++)this.chunks.push(c.children[d]),this.chunkPos.push(c.positions[d]);i&&this.parsedPos<i.viewport.from-1e5&&s.some(d=>d.from<=i.viewport.from&&d.to>=i.viewport.from)&&(this.state=this.lang.streamParser.startState(rm(i.state)),i.skipUntilInView(this.parsedPos,i.viewport.from),this.parsedPos=i.viewport.from),this.moveRangeIndex()}advance(){let e=Wg.get(),n=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),r=Math.min(n,this.chunkStart+512);for(e&&(r=Math.min(r,e.viewport.to));this.parsedPos<r;)this.parseLine(e);return this.chunkStart<this.parsedPos&&this.finishChunk(),this.parsedPos>=n?this.finish():e&&this.parsedPos>=e.viewport.to?(e.skipUntilInView(this.parsedPos,n),this.finish()):null}stopAt(e){this.stoppedAt=e}lineAfter(e){let n=this.input.chunk(e);if(this.input.lineChunks)n==`
806
806
  `&&(n="");else{let r=n.indexOf(`
807
- `);r>-1&&(n=n.slice(0,r))}return e+n.length<=this.to?n:n.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,n=this.lineAfter(e),r=e+n.length;for(let s=this.rangeIndex;;){let i=this.ranges[s].to;if(i>=r||(n=n.slice(0,i-(r-n.length)),s++,s==this.ranges.length))break;let o=this.ranges[s].from,a=this.lineAfter(o);n+=a,r=o+a.length}return{line:n,end:r}}skipGapsTo(e,n,r){for(;;){let s=this.ranges[this.rangeIndex].to,i=e+n;if(r>0?s>i:s>=i)break;let o=this.ranges[++this.rangeIndex].from;n+=o-s}return n}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(e,n,r,s){let i=4;if(this.ranges.length>1){s=this.skipGapsTo(n,s,1),n+=s;let a=this.chunk.length;s=this.skipGapsTo(r,s,-1),r+=s,i+=this.chunk.length-a}let o=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&i==4&&o>=0&&this.chunk[o]==e&&this.chunk[o+2]==n?this.chunk[o+2]=r:this.chunk.push(e,n,r,i),s}parseLine(e){let{line:n,end:r}=this.nextLine(),s=0,{streamParser:i}=this.lang,o=new zre(n,e?e.state.tabSize:4,e?rm(e.state):2);if(o.eol())i.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let a=Hre(i.token,o,this.state);if(a&&(s=this.emitToken(this.lang.tokenTable.resolve(a),this.parsedPos+o.start,this.parsedPos+o.pos,s)),o.start>1e4)break}this.parsedPos=r,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let e=cr.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:NDe,topID:0,maxBufferLength:512,reused:this.chunkReused});e=new cr(e.type,e.children,e.positions,e.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(e),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new cr(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function Hre(t,e,n){e.start=e.pos;for(let r=0;r<10;r++){let s=t(e,n);if(e.pos>e.start)return s}throw new Error("Stream parser failed to advance stream.")}const O9=Object.create(null),kb=[Ai.none],NDe=new _9(kb),LV=[],PV=Object.create(null),Ure=Object.create(null);for(let[t,e]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"]])Ure[t]=Kre(O9,e);class qre{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),Ure)}resolve(e){return e?this.table[e]||(this.table[e]=Kre(this.extra,e)):0}}const EDe=new qre(O9);function eA(t,e){LV.indexOf(t)>-1||(LV.push(t),console.warn(e))}function Kre(t,e){let n=[];for(let a of e.split(" ")){let c=[];for(let d of a.split(".")){let f=t[d]||je[d];f?typeof f=="function"?c.length?c=c.map(f):eA(d,`Modifier ${d} used at start of tag`):c.length?eA(d,`Tag ${d} used as modifier`):c=Array.isArray(f)?f:[f]:eA(d,`Unknown highlighting tag ${d}`)}for(let d of c)n.push(d)}if(!n.length)return 0;let r=e.replace(/ /g,"_"),s=r+" "+n.map(a=>a.id),i=PV[s];if(i)return i.id;let o=PV[s]=Ai.define({id:kb.length,name:r,props:[T6e({[r]:n})]});return kb.push(o),o.id}function jDe(t,e){let n=Ai.define({id:kb.length,name:"Document",props:[ah.add(()=>t),Nre.add(()=>r=>e.getIndent(r))],top:!0});return kb.push(n),n}lr.RTL,lr.LTR;class Wre{constructor(e,n,r,s){this.state=e,this.pos=n,this.explicit=r,this.view=s,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let n=Ws(this.state).resolveInner(this.pos,-1);for(;n&&e.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(e){let n=this.state.doc.lineAt(this.pos),r=Math.max(n.from,this.pos-250),s=n.text.slice(r-n.from,this.pos-n.from),i=s.search(Gre(e,!1));return i<0?null:{from:r+i,to:this.pos,text:s.slice(i)}}get aborted(){return this.abortListeners==null}addEventListener(e,n,r){e=="abort"&&this.abortListeners&&(this.abortListeners.push(n),r&&r.onDocChange&&(this.abortOnDocChange=!0))}}function FV(t){let e=Object.keys(t).join(""),n=/\w/.test(e);return n&&(e=e.replace(/\w/g,"")),`[${n?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function ADe(t){let e=Object.create(null),n=Object.create(null);for(let{label:s}of t){e[s[0]]=!0;for(let i=1;i<s.length;i++)n[s[i]]=!0}let r=FV(e)+FV(n)+"*$";return[new RegExp("^"+r),new RegExp(r)]}function TDe(t){let e=t.map(s=>typeof s=="string"?{label:s}:s),[n,r]=e.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:ADe(e);return s=>{let i=s.matchBefore(r);return i||s.explicit?{from:i?i.from:s.pos,options:e,validFor:n}:null}}function FKe(t,e){return n=>{for(let r=Ws(n.state).resolveInner(n.pos,-1);r;r=r.parent){if(t.indexOf(r.name)>-1)return null;if(r.type.isTop)break}return e(n)}}class $V{constructor(e,n,r,s){this.completion=e,this.source=n,this.match=r,this.score=s}}function _h(t){return t.selection.main.from}function Gre(t,e){var n;let{source:r}=t,s=e&&r[0]!="^",i=r[r.length-1]!="$";return!s&&!i?t:new RegExp(`${s?"^":""}(?:${r})${i?"$":""}`,(n=t.flags)!==null&&n!==void 0?n:t.ignoreCase?"i":"")}const I9=Pu.define();function MDe(t,e,n,r){let{main:s}=t.selection,i=n-s.from,o=r-s.from;return{...t.changeByRange(a=>{if(a!=s&&n!=r&&t.sliceDoc(a.from+i,a.from+o)!=t.sliceDoc(n,r))return{range:a};let c=t.toText(e);return{changes:{from:a.from+i,to:r==s.from?a.to:a.from+o,insert:c},range:De.cursor(a.from+i+c.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const BV=new WeakMap;function RDe(t){if(!Array.isArray(t))return t;let e=BV.get(t);return e||BV.set(t,e=TDe(t)),e}const Bk=zt.define(),Sb=zt.define();class ODe{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let n=0;n<e.length;){let r=Gi(e,n),s=Rl(r);this.chars.push(r);let i=e.slice(n,n+s),o=i.toUpperCase();this.folded.push(Gi(o==i?i.toLowerCase():o,0)),n+=s}this.astral=e.length!=this.chars.length}ret(e,n){return this.score=e,this.matched=n,this}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:n,folded:r,any:s,precise:i,byWord:o}=this;if(n.length==1){let C=Gi(e,0),_=Rl(C),E=_==e.length?0:-100;if(C!=n[0])if(C==r[0])E+=-200;else return null;return this.ret(E,[0,_])}let a=e.indexOf(this.pattern);if(a==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let c=n.length,d=0;if(a<0){for(let C=0,_=Math.min(e.length,200);C<_&&d<c;){let E=Gi(e,C);(E==n[d]||E==r[d])&&(s[d++]=C),C+=Rl(E)}if(d<c)return null}let f=0,m=0,p=!1,x=0,y=-1,w=-1,k=/[a-z]/.test(e),S=!0;for(let C=0,_=Math.min(e.length,200),E=0;C<_&&m<c;){let j=Gi(e,C);a<0&&(f<c&&j==n[f]&&(i[f++]=C),x<c&&(j==n[x]||j==r[x]?(x==0&&(y=C),w=C+1,x++):x=0));let R,T=j<255?j>=48&&j<=57||j>=97&&j<=122?2:j>=65&&j<=90?1:0:(R=o9(j))!=R.toLowerCase()?1:R!=R.toUpperCase()?2:0;(!C||T==1&&k||E==0&&T!=0)&&(n[m]==j||r[m]==j&&(p=!0)?o[m++]=C:o.length&&(S=!1)),E=T,C+=Rl(j)}return m==c&&o[0]==0&&S?this.result(-100+(p?-200:0),o,e):x==c&&y==0?this.ret(-200-e.length+(w==e.length?0:-100),[0,w]):a>-1?this.ret(-700-e.length,[a,a+this.pattern.length]):x==c?this.ret(-900-e.length,[y,w]):m==c?this.result(-100+(p?-200:0)+-700+(S?0:-1100),o,e):n.length==2?null:this.result((s[0]?-700:0)+-200+-1100,s,e)}result(e,n,r){let s=[],i=0;for(let o of n){let a=o+(this.astral?Rl(Gi(r,o)):1);i&&s[i-1]==o?s[i-1]=a:(s[i++]=o,s[i++]=a)}return this.ret(e-r.length,s)}}class IDe{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let n=e.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+(e.length==this.pattern.length?0:-100),this)}}const As=ut.define({combine(t){return lc(t,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:DDe,filterStrict:!1,compareCompletions:(e,n)=>(e.sortText||e.label).localeCompare(n.sortText||n.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,n)=>e&&n,closeOnBlur:(e,n)=>e&&n,icons:(e,n)=>e&&n,tooltipClass:(e,n)=>r=>zV(e(r),n(r)),optionClass:(e,n)=>r=>zV(e(r),n(r)),addToOptions:(e,n)=>e.concat(n),filterStrict:(e,n)=>e||n})}});function zV(t,e){return t?e?t+" "+e:t:e}function DDe(t,e,n,r,s,i){let o=t.textDirection==lr.RTL,a=o,c=!1,d="top",f,m,p=e.left-s.left,x=s.right-e.right,y=r.right-r.left,w=r.bottom-r.top;if(a&&p<Math.min(y,x)?a=!1:!a&&x<Math.min(y,p)&&(a=!0),y<=(a?p:x))f=Math.max(s.top,Math.min(n.top,s.bottom-w))-e.top,m=Math.min(400,a?p:x);else{c=!0,m=Math.min(400,(o?e.right:s.right-e.left)-30);let C=s.bottom-e.bottom;C>=w||C>e.top?f=n.bottom-e.top:(d="bottom",f=e.bottom-n.top)}let k=(e.bottom-e.top)/i.offsetHeight,S=(e.right-e.left)/i.offsetWidth;return{style:`${d}: ${f/k}px; max-width: ${m/S}px`,class:"cm-completionInfo-"+(c?o?"left-narrow":"right-narrow":a?"left":"right")}}function LDe(t){let e=t.addToOptions.slice();return t.icons&&e.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(s=>"cm-completionIcon-"+s)),r.setAttribute("aria-hidden","true"),r},position:20}),e.push({render(n,r,s,i){let o=document.createElement("span");o.className="cm-completionLabel";let a=n.displayLabel||n.label,c=0;for(let d=0;d<i.length;){let f=i[d++],m=i[d++];f>c&&o.appendChild(document.createTextNode(a.slice(c,f)));let p=o.appendChild(document.createElement("span"));p.appendChild(document.createTextNode(a.slice(f,m))),p.className="cm-completionMatchedText",c=m}return c<a.length&&o.appendChild(document.createTextNode(a.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}),e.sort((n,r)=>n.position-r.position).map(n=>n.render)}function tA(t,e,n){if(t<=n)return{from:0,to:t};if(e<0&&(e=0),e<=t>>1){let s=Math.floor(e/n);return{from:s*n,to:(s+1)*n}}let r=Math.floor((t-e)/n);return{from:t-(r+1)*n,to:t-r*n}}class PDe{constructor(e,n,r){this.view=e,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 s=e.state.field(n),{options:i,selected:o}=s.open,a=e.state.facet(As);this.optionContent=LDe(a),this.optionClass=a.optionClass,this.tooltipClass=a.tooltipClass,this.range=tA(i.length,o,a.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",c=>{let{options:d}=e.state.field(n).open;for(let f=c.target,m;f&&f!=this.dom;f=f.parentNode)if(f.nodeName=="LI"&&(m=/-(\d+)$/.exec(f.id))&&+m[1]<d.length){this.applyCompletion(e,d[+m[1]]),c.preventDefault();return}}),this.dom.addEventListener("focusout",c=>{let d=e.state.field(this.stateField,!1);d&&d.tooltip&&e.state.facet(As).closeOnBlur&&c.relatedTarget!=e.contentDOM&&e.dispatch({effects:Sb.of(null)})}),this.showOptions(i,s.id)}mount(){this.updateSel()}showOptions(e,n){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,n,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var n;let r=e.state.field(this.stateField),s=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),r!=s){let{options:i,selected:o,disabled:a}=r.open;(!s.open||s.open.options!=i)&&(this.range=tA(i.length,o,e.state.facet(As).maxRenderedOptions),this.showOptions(i,r.id)),this.updateSel(),a!=((n=s.open)===null||n===void 0?void 0:n.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!a)}}updateTooltipClass(e){let n=this.tooltipClass(e);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(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),n=e.open;(n.selected>-1&&n.selected<this.range.from||n.selected>=this.range.to)&&(this.range=tA(n.options.length,n.selected,this.view.state.facet(As).maxRenderedOptions),this.showOptions(n.options,e.id));let r=this.updateSelectedOption(n.selected);if(r){this.destroyInfo();let{completion:s}=n.options[n.selected],{info:i}=s;if(!i)return;let o=typeof i=="string"?document.createTextNode(i):i(s);if(!o)return;"then"in o?o.then(a=>{a&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(a,s)}).catch(a=>Xi(this.view.state,a,"completion info")):(this.addInfoPane(o,s),r.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,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),e.nodeType!=null)r.appendChild(e),this.infoDestroy=null;else{let{dom:s,destroy:i}=e;r.appendChild(s),this.infoDestroy=i||null}this.dom.appendChild(r),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let n=null;for(let r=this.list.firstChild,s=this.range.from;r;r=r.nextSibling,s++)r.nodeName!="LI"||!r.id?s--:s==e?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&&$De(this.list,n),n}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let n=this.dom.getBoundingClientRect(),r=this.info.getBoundingClientRect(),s=e.getBoundingClientRect(),i=this.space;if(!i){let o=this.dom.ownerDocument.documentElement;i={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return s.top>Math.min(i.bottom,n.bottom)-10||s.bottom<Math.max(i.top,n.top)+10?null:this.view.state.facet(As).positionInfo(this.view,n,s,r,i,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,n,r){const s=document.createElement("ul");s.id=n,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true"),s.setAttribute("aria-label",this.view.state.phrase("Completions")),s.addEventListener("mousedown",o=>{o.target==s&&o.preventDefault()});let i=null;for(let o=r.from;o<r.to;o++){let{completion:a,match:c}=e[o],{section:d}=a;if(d){let p=typeof d=="string"?d:d.name;if(p!=i&&(o>r.from||r.from==0))if(i=p,typeof d!="string"&&d.header)s.appendChild(d.header(d));else{let x=s.appendChild(document.createElement("completion-section"));x.textContent=p}}const f=s.appendChild(document.createElement("li"));f.id=n+"-"+o,f.setAttribute("role","option");let m=this.optionClass(a);m&&(f.className=m);for(let p of this.optionContent){let x=p(a,this.view.state,this.view,c);x&&f.appendChild(x)}}return r.from&&s.classList.add("cm-completionListIncompleteTop"),r.to<e.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function FDe(t,e){return n=>new PDe(n,t,e)}function $De(t,e){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect(),s=n.height/t.offsetHeight;r.top<n.top?t.scrollTop-=(n.top-r.top)/s:r.bottom>n.bottom&&(t.scrollTop+=(r.bottom-n.bottom)/s)}function VV(t){return(t.boost||0)*100+(t.apply?10:0)+(t.info?5:0)+(t.type?1:0)}function BDe(t,e){let n=[],r=null,s=null,i=f=>{n.push(f);let{section:m}=f.completion;if(m){r||(r=[]);let p=typeof m=="string"?m:m.name;r.some(x=>x.name==p)||r.push(typeof m=="string"?{name:p}:m)}},o=e.facet(As);for(let f of t)if(f.hasResult()){let m=f.result.getMatch;if(f.result.filter===!1)for(let p of f.result.options)i(new $V(p,f.source,m?m(p):[],1e9-n.length));else{let p=e.sliceDoc(f.from,f.to),x,y=o.filterStrict?new IDe(p):new ODe(p);for(let w of f.result.options)if(x=y.match(w.label)){let k=w.displayLabel?m?m(w,x.matched):[]:x.matched,S=x.score+(w.boost||0);if(i(new $V(w,f.source,k,S)),typeof w.section=="object"&&w.section.rank==="dynamic"){let{name:C}=w.section;s||(s=Object.create(null)),s[C]=Math.max(S,s[C]||-1e9)}}}}if(r){let f=Object.create(null),m=0,p=(x,y)=>(x.rank==="dynamic"&&y.rank==="dynamic"?s[y.name]-s[x.name]:0)||(typeof x.rank=="number"?x.rank:1e9)-(typeof y.rank=="number"?y.rank:1e9)||(x.name<y.name?-1:1);for(let x of r.sort(p))m-=1e5,f[x.name]=m;for(let x of n){let{section:y}=x.completion;y&&(x.score+=f[typeof y=="string"?y:y.name])}}let a=[],c=null,d=o.compareCompletions;for(let f of n.sort((m,p)=>p.score-m.score||d(m.completion,p.completion))){let m=f.completion;!c||c.label!=m.label||c.detail!=m.detail||c.type!=null&&m.type!=null&&c.type!=m.type||c.apply!=m.apply||c.boost!=m.boost?a.push(f):VV(f.completion)>VV(c)&&(a[a.length-1]=f),c=f.completion}return a}class Lp{constructor(e,n,r,s,i,o){this.options=e,this.attrs=n,this.tooltip=r,this.timestamp=s,this.selected=i,this.disabled=o}setSelected(e,n){return e==this.selected||e>=this.options.length?this:new Lp(this.options,HV(n,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,n,r,s,i,o){if(s&&!o&&e.some(d=>d.isPending))return s.setDisabled();let a=BDe(e,n);if(!a.length)return s&&e.some(d=>d.isPending)?s.setDisabled():null;let c=n.facet(As).selectOnOpen?0:-1;if(s&&s.selected!=c&&s.selected!=-1){let d=s.options[s.selected].completion;for(let f=0;f<a.length;f++)if(a[f].completion==d){c=f;break}}return new Lp(a,HV(r,c),{pos:e.reduce((d,f)=>f.hasResult()?Math.min(d,f.from):d,1e8),create:KDe,above:i.aboveCursor},s?s.timestamp:Date.now(),c,!1)}map(e){return new Lp(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Lp(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class zk{constructor(e,n,r){this.active=e,this.id=n,this.open=r}static start(){return new zk(UDe,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:n}=e,r=n.facet(As),i=(r.override||n.languageDataAt("autocomplete",_h(n)).map(RDe)).map(c=>(this.active.find(f=>f.source==c)||new ca(c,this.active.some(f=>f.state!=0)?1:0)).update(e,r));i.length==this.active.length&&i.every((c,d)=>c==this.active[d])&&(i=this.active);let o=this.open,a=e.effects.some(c=>c.is(D9));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||i.some(c=>c.hasResult()&&e.changes.touchesRange(c.from,c.to))||!zDe(i,this.active)||a?o=Lp.build(i,n,this.id,o,r,a):o&&o.disabled&&!i.some(c=>c.isPending)&&(o=null),!o&&i.every(c=>!c.isPending)&&i.some(c=>c.hasResult())&&(i=i.map(c=>c.hasResult()?new ca(c.source,0):c));for(let c of e.effects)c.is(Yre)&&(o=o&&o.setSelected(c.value,this.id));return i==this.active&&o==this.open?this:new zk(i,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?VDe:HDe}}function zDe(t,e){if(t==e)return!0;for(let n=0,r=0;;){for(;n<t.length&&!t[n].hasResult();)n++;for(;r<e.length&&!e[r].hasResult();)r++;let s=n==t.length,i=r==e.length;if(s||i)return s==i;if(t[n++].result!=e[r++].result)return!1}}const VDe={"aria-autocomplete":"list"},HDe={};function HV(t,e){let n={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":t};return e>-1&&(n["aria-activedescendant"]=t+"-"+e),n}const UDe=[];function Jre(t,e){if(t.isUserEvent("input.complete")){let r=t.annotation(I9);if(r&&e.activateOnCompletion(r))return 12}let n=t.isUserEvent("input.type");return n&&e.activateOnTyping?5:n?1:t.isUserEvent("delete.backward")?2:t.selection?8:t.docChanged?16:0}class ca{constructor(e,n,r=!1){this.source=e,this.state=n,this.explicit=r}hasResult(){return!1}get isPending(){return this.state==1}update(e,n){let r=Jre(e,n),s=this;(r&8||r&16&&this.touches(e))&&(s=new ca(s.source,0)),r&4&&s.state==0&&(s=new ca(this.source,1)),s=s.updateFor(e,r);for(let i of e.effects)if(i.is(Bk))s=new ca(s.source,1,i.value);else if(i.is(Sb))s=new ca(s.source,0);else if(i.is(D9))for(let o of i.value)o.source==s.source&&(s=o);return s}updateFor(e,n){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(_h(e.state))}}class Xp extends ca{constructor(e,n,r,s,i,o){super(e,3,n),this.limit=r,this.result=s,this.from=i,this.to=o}hasResult(){return!0}updateFor(e,n){var r;if(!(n&3))return this.map(e.changes);let s=this.result;s.map&&!e.changes.empty&&(s=s.map(s,e.changes));let i=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),a=_h(e.state);if(a>o||!s||n&2&&(_h(e.startState)==this.from||a<this.limit))return new ca(this.source,n&4?1:0);let c=e.changes.mapPos(this.limit);return qDe(s.validFor,e.state,i,o)?new Xp(this.source,this.explicit,c,s,i,o):s.update&&(s=s.update(s,i,o,new Wre(e.state,a,!1)))?new Xp(this.source,this.explicit,c,s,s.from,(r=s.to)!==null&&r!==void 0?r:_h(e.state)):new ca(this.source,1,this.explicit)}map(e){return e.empty?this:(this.result.map?this.result.map(this.result,e):this.result)?new Xp(this.source,this.explicit,e.mapPos(this.limit),this.result,e.mapPos(this.from),e.mapPos(this.to,1)):new ca(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}function qDe(t,e,n,r){if(!t)return!1;let s=e.sliceDoc(n,r);return typeof t=="function"?t(s,n,r,e):Gre(t,!0).test(s)}const D9=zt.define({map(t,e){return t.map(n=>n.map(e))}}),Yre=zt.define(),Ji=Is.define({create(){return zk.start()},update(t,e){return t.update(e)},provide:t=>[k9.from(t,e=>e.tooltip),at.contentAttributes.from(t,e=>e.attrs)]});function L9(t,e){const n=e.completion.apply||e.completion.label;let r=t.state.field(Ji).active.find(s=>s.source==e.source);return r instanceof Xp?(typeof n=="string"?t.dispatch({...MDe(t.state,n,r.from,r.to),annotations:I9.of(e.completion)}):n(t,e.completion,r.from,r.to),!0):!1}const KDe=FDe(Ji,L9);function nC(t,e="option"){return n=>{let r=n.state.field(Ji,!1);if(!r||!r.open||r.open.disabled||Date.now()-r.open.timestamp<n.state.facet(As).interactionDelay)return!1;let s=1,i;e=="page"&&(i=dre(n,r.open.tooltip))&&(s=Math.max(2,Math.floor(i.dom.offsetHeight/i.dom.querySelector("li").offsetHeight)-1));let{length:o}=r.open.options,a=r.open.selected>-1?r.open.selected+s*(t?1:-1):t?0:o-1;return a<0?a=e=="page"?0:o-1:a>=o&&(a=e=="page"?o-1:0),n.dispatch({effects:Yre.of(a)}),!0}}const WDe=t=>{let e=t.state.field(Ji,!1);return t.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<t.state.facet(As).interactionDelay?!1:L9(t,e.open.options[e.open.selected])},nA=t=>t.state.field(Ji,!1)?(t.dispatch({effects:Bk.of(!0)}),!0):!1,GDe=t=>{let e=t.state.field(Ji,!1);return!e||!e.active.some(n=>n.state!=0)?!1:(t.dispatch({effects:Sb.of(null)}),!0)};class JDe{constructor(e,n){this.active=e,this.context=n,this.time=Date.now(),this.updates=[],this.done=void 0}}const YDe=50,ZDe=1e3,QDe=us.fromClass(class{constructor(t){this.view=t,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of t.state.field(Ji).active)e.isPending&&this.startQuery(e)}update(t){let e=t.state.field(Ji),n=t.state.facet(As);if(!t.selectionSet&&!t.docChanged&&t.startState.field(Ji)==e)return;let r=t.transactions.some(i=>{let o=Jre(i,n);return o&8||(i.selection||i.docChanged)&&!(o&3)});for(let i=0;i<this.running.length;i++){let o=this.running[i];if(r||o.context.abortOnDocChange&&t.docChanged||o.updates.length+t.transactions.length>YDe&&Date.now()-o.time>ZDe){for(let a of o.context.abortListeners)try{a()}catch(c){Xi(this.view.state,c)}o.context.abortListeners=null,this.running.splice(i--,1)}else o.updates.push(...t.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),t.transactions.some(i=>i.effects.some(o=>o.is(Bk)))&&(this.pendingStart=!0);let s=this.pendingStart?50:n.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(i=>i.isPending&&!this.running.some(o=>o.active.source==i.source))?setTimeout(()=>this.startUpdate(),s):-1,this.composing!=0)for(let i of t.transactions)i.isUserEvent("input.type")?this.composing=2:this.composing==2&&i.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:t}=this.view,e=t.field(Ji);for(let n of e.active)n.isPending&&!this.running.some(r=>r.active.source==n.source)&&this.startQuery(n);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(As).updateSyncTime))}startQuery(t){let{state:e}=this.view,n=_h(e),r=new Wre(e,n,t.explicit,this.view),s=new JDe(t,r);this.running.push(s),Promise.resolve(t.source(r)).then(i=>{s.context.aborted||(s.done=i||null,this.scheduleAccept())},i=>{this.view.dispatch({effects:Sb.of(null)}),Xi(this.view.state,i)})}scheduleAccept(){this.running.every(t=>t.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(As).updateSyncTime))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],n=this.view.state.facet(As),r=this.view.state.field(Ji);for(let s=0;s<this.running.length;s++){let i=this.running[s];if(i.done===void 0)continue;if(this.running.splice(s--,1),i.done){let a=_h(i.updates.length?i.updates[0].startState:this.view.state),c=Math.min(a,i.done.from+(i.active.explicit?0:1)),d=new Xp(i.active.source,i.active.explicit,c,i.done,i.done.from,(t=i.done.to)!==null&&t!==void 0?t:a);for(let f of i.updates)d=d.update(f,n);if(d.hasResult()){e.push(d);continue}}let o=r.active.find(a=>a.source==i.active.source);if(o&&o.isPending)if(i.done==null){let a=new ca(i.active.source,0);for(let c of i.updates)a=a.update(c,n);a.isPending||e.push(a)}else this.startQuery(o)}(e.length||r.open&&r.open.disabled)&&this.view.dispatch({effects:D9.of(e)})}},{eventHandlers:{blur(t){let e=this.view.state.field(Ji,!1);if(e&&e.tooltip&&this.view.state.facet(As).closeOnBlur){let n=e.open&&dre(this.view,e.open.tooltip);(!n||!n.dom.contains(t.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Sb.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:Bk.of(!1)}),20),this.composing=0}}}),XDe=typeof navigator=="object"&&/Win/.test(navigator.platform),e8e=Sf.highest(at.domEventHandlers({keydown(t,e){let n=e.state.field(Ji,!1);if(!n||!n.open||n.open.disabled||n.open.selected<0||t.key.length>1||t.ctrlKey&&!(XDe&&t.altKey)||t.metaKey)return!1;let r=n.open.options[n.open.selected],s=n.active.find(o=>o.source==r.source),i=r.completion.commitCharacters||s.result.commitCharacters;return i&&i.indexOf(t.key)>-1&&L9(e,r),!1}})),Zre=at.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 t8e{constructor(e,n,r,s){this.field=e,this.line=n,this.from=r,this.to=s}}class P9{constructor(e,n,r){this.field=e,this.from=n,this.to=r}map(e){let n=e.mapPos(this.from,-1,qs.TrackDel),r=e.mapPos(this.to,1,qs.TrackDel);return n==null||r==null?null:new P9(this.field,n,r)}}class F9{constructor(e,n){this.lines=e,this.fieldPositions=n}instantiate(e,n){let r=[],s=[n],i=e.doc.lineAt(n),o=/^\s*/.exec(i.text)[0];for(let c of this.lines){if(r.length){let d=o,f=/^\t*/.exec(c)[0].length;for(let m=0;m<f;m++)d+=e.facet(W_);s.push(n+d.length-f),c=d+c.slice(f)}r.push(c),n+=c.length+1}let a=this.fieldPositions.map(c=>new P9(c.field,s[c.line]+c.from,s[c.line]+c.to));return{text:r,ranges:a}}static parse(e){let n=[],r=[],s=[],i;for(let o of e.split(/\r\n?|\n/)){for(;i=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let a=i[1]?+i[1]:null,c=i[2]||i[3]||"",d=-1,f=c.replace(/\\[{}]/g,m=>m[1]);for(let m=0;m<n.length;m++)(a!=null?n[m].seq==a:f&&n[m].name==f)&&(d=m);if(d<0){let m=0;for(;m<n.length&&(a==null||n[m].seq!=null&&n[m].seq<a);)m++;n.splice(m,0,{seq:a,name:f}),d=m;for(let p of s)p.field>=d&&p.field++}for(let m of s)if(m.line==r.length&&m.from>i.index){let p=i[2]?3+(i[1]||"").length:2;m.from-=p,m.to-=p}s.push(new t8e(d,r.length,i.index,i.index+f.length)),o=o.slice(0,i.index)+c+o.slice(i.index+i[0].length)}o=o.replace(/\\([{}])/g,(a,c,d)=>{for(let f of s)f.line==r.length&&f.from>d&&(f.from--,f.to--);return c}),r.push(o)}return new F9(r,s)}}let n8e=Mt.widget({widget:new class extends cc{toDOM(){let t=document.createElement("span");return t.className="cm-snippetFieldPosition",t}ignoreEvent(){return!1}}}),r8e=Mt.mark({class:"cm-snippetField"});class jx{constructor(e,n){this.ranges=e,this.active=n,this.deco=Mt.set(e.map(r=>(r.from==r.to?n8e:r8e).range(r.from,r.to)),!0)}map(e){let n=[];for(let r of this.ranges){let s=r.map(e);if(!s)return null;n.push(s)}return new jx(n,this.active)}selectionInsideField(e){return e.ranges.every(n=>this.ranges.some(r=>r.field==this.active&&r.from<=n.from&&r.to>=n.to))}}const Hv=zt.define({map(t,e){return t&&t.map(e)}}),s8e=zt.define(),_b=Is.define({create(){return null},update(t,e){for(let n of e.effects){if(n.is(Hv))return n.value;if(n.is(s8e)&&t)return new jx(t.ranges,n.value)}return t&&e.docChanged&&(t=t.map(e.changes)),t&&e.selection&&!t.selectionInsideField(e.selection)&&(t=null),t},provide:t=>at.decorations.from(t,e=>e?e.deco:Mt.none)});function $9(t,e){return De.create(t.filter(n=>n.field==e).map(n=>De.range(n.from,n.to)))}function i8e(t){let e=F9.parse(t);return(n,r,s,i)=>{let{text:o,ranges:a}=e.instantiate(n.state,s),{main:c}=n.state.selection,d={changes:{from:s,to:i==c.from?c.to:i,insert:Pn.of(o)},scrollIntoView:!0,annotations:r?[I9.of(r),is.userEvent.of("input.complete")]:void 0};if(a.length&&(d.selection=$9(a,0)),a.some(f=>f.field>0)){let f=new jx(a,0),m=d.effects=[Hv.of(f)];n.state.field(_b,!1)===void 0&&m.push(zt.appendConfig.of([_b,u8e,d8e,Zre]))}n.dispatch(n.state.update(d))}}function Qre(t){return({state:e,dispatch:n})=>{let r=e.field(_b,!1);if(!r||t<0&&r.active==0)return!1;let s=r.active+t,i=t>0&&!r.ranges.some(o=>o.field==s+t);return n(e.update({selection:$9(r.ranges,s),effects:Hv.of(i?null:new jx(r.ranges,s)),scrollIntoView:!0})),!0}}const o8e=({state:t,dispatch:e})=>t.field(_b,!1)?(e(t.update({effects:Hv.of(null)})),!0):!1,a8e=Qre(1),l8e=Qre(-1),c8e=[{key:"Tab",run:a8e,shift:l8e},{key:"Escape",run:o8e}],UV=ut.define({combine(t){return t.length?t[0]:c8e}}),u8e=Sf.highest($v.compute([UV],t=>t.facet(UV)));function $Ke(t,e){return{...e,apply:i8e(t)}}const d8e=at.domEventHandlers({mousedown(t,e){let n=e.state.field(_b,!1),r;if(!n||(r=e.posAtCoords({x:t.clientX,y:t.clientY}))==null)return!1;let s=n.ranges.find(i=>i.from<=r&&i.to>=r);return!s||s.field==n.active?!1:(e.dispatch({selection:$9(n.ranges,s.field),effects:Hv.of(n.ranges.some(i=>i.field>s.field)?new jx(n.ranges,s.field):null),scrollIntoView:!0}),!0)}}),Nb={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},lh=zt.define({map(t,e){let n=e.mapPos(t,-1,qs.TrackAfter);return n??void 0}}),B9=new class extends sf{};B9.startSide=1;B9.endSide=-1;const Xre=Is.define({create(){return un.empty},update(t,e){if(t=t.map(e.changes),e.selection){let n=e.state.doc.lineAt(e.selection.main.head);t=t.update({filter:r=>r>=n.from&&r<=n.to})}for(let n of e.effects)n.is(lh)&&(t=t.update({add:[B9.range(n.value,n.value+1)]}));return t}});function f8e(){return[m8e,Xre]}const rA="()[]{}<>«»»«[]{}";function ese(t){for(let e=0;e<rA.length;e+=2)if(rA.charCodeAt(e)==t)return rA.charAt(e+1);return o9(t<128?t:t+1)}function tse(t,e){return t.languageDataAt("closeBrackets",e)[0]||Nb}const h8e=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),m8e=at.inputHandler.of((t,e,n,r)=>{if((h8e?t.composing:t.compositionStarted)||t.state.readOnly)return!1;let s=t.state.selection.main;if(r.length>2||r.length==2&&Rl(Gi(r,0))==1||e!=s.from||n!=s.to)return!1;let i=x8e(t.state,r);return i?(t.dispatch(i),!0):!1}),p8e=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let r=tse(t,t.selection.main.head).brackets||Nb.brackets,s=null,i=t.changeByRange(o=>{if(o.empty){let a=y8e(t.doc,o.head);for(let c of r)if(c==a&&Y_(t.doc,o.head)==ese(Gi(c,0)))return{changes:{from:o.head-c.length,to:o.head+c.length},range:De.cursor(o.head-c.length)}}return{range:s=o}});return s||e(t.update(i,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},g8e=[{key:"Backspace",run:p8e}];function x8e(t,e){let n=tse(t,t.selection.main.head),r=n.brackets||Nb.brackets;for(let s of r){let i=ese(Gi(s,0));if(e==s)return i==s?w8e(t,s,r.indexOf(s+s+s)>-1,n):b8e(t,s,i,n.before||Nb.before);if(e==i&&nse(t,t.selection.main.from))return v8e(t,s,i)}return null}function nse(t,e){let n=!1;return t.field(Xre).between(0,t.doc.length,r=>{r==e&&(n=!0)}),n}function Y_(t,e){let n=t.sliceString(e,e+2);return n.slice(0,Rl(Gi(n,0)))}function y8e(t,e){let n=t.sliceString(e-2,e);return Rl(Gi(n,0))==n.length?n:n.slice(1)}function b8e(t,e,n,r){let s=null,i=t.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:n,from:o.to}],effects:lh.of(o.to+e.length),range:De.range(o.anchor+e.length,o.head+e.length)};let a=Y_(t.doc,o.head);return!a||/\s/.test(a)||r.indexOf(a)>-1?{changes:{insert:e+n,from:o.head},effects:lh.of(o.head+e.length),range:De.cursor(o.head+e.length)}:{range:s=o}});return s?null:t.update(i,{scrollIntoView:!0,userEvent:"input.type"})}function v8e(t,e,n){let r=null,s=t.changeByRange(i=>i.empty&&Y_(t.doc,i.head)==n?{changes:{from:i.head,to:i.head+n.length,insert:n},range:De.cursor(i.head+n.length)}:r={range:i});return r?null:t.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function w8e(t,e,n,r){let s=r.stringPrefixes||Nb.stringPrefixes,i=null,o=t.changeByRange(a=>{if(!a.empty)return{changes:[{insert:e,from:a.from},{insert:e,from:a.to}],effects:lh.of(a.to+e.length),range:De.range(a.anchor+e.length,a.head+e.length)};let c=a.head,d=Y_(t.doc,c),f;if(d==e){if(qV(t,c))return{changes:{insert:e+e,from:c},effects:lh.of(c+e.length),range:De.cursor(c+e.length)};if(nse(t,c)){let p=n&&t.sliceDoc(c,c+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:c,to:c+p.length,insert:p},range:De.cursor(c+p.length)}}}else{if(n&&t.sliceDoc(c-2*e.length,c)==e+e&&(f=KV(t,c-2*e.length,s))>-1&&qV(t,f))return{changes:{insert:e+e+e+e,from:c},effects:lh.of(c+e.length),range:De.cursor(c+e.length)};if(t.charCategorizer(c)(d)!=_r.Word&&KV(t,c,s)>-1&&!C8e(t,c,e,s))return{changes:{insert:e+e,from:c},effects:lh.of(c+e.length),range:De.cursor(c+e.length)}}return{range:i=a}});return i?null:t.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function qV(t,e){let n=Ws(t).resolveInner(e+1);return n.parent&&n.from==e}function C8e(t,e,n,r){let s=Ws(t).resolveInner(e,-1),i=r.reduce((o,a)=>Math.max(o,a.length),0);for(let o=0;o<5;o++){let a=t.sliceDoc(s.from,Math.min(s.to,s.from+n.length+i)),c=a.indexOf(n);if(!c||c>-1&&r.indexOf(a.slice(0,c))>-1){let f=s.firstChild;for(;f&&f.from==s.from&&f.to-f.from>n.length+c;){if(t.sliceDoc(f.to-n.length,f.to)==n)return!1;f=f.firstChild}return!0}let d=s.to==e&&s.parent;if(!d)break;s=d}return!1}function KV(t,e,n){let r=t.charCategorizer(e);if(r(t.sliceDoc(e-1,e))!=_r.Word)return e;for(let s of n){let i=e-s.length;if(t.sliceDoc(i,e)==s&&r(t.sliceDoc(i-1,i))!=_r.Word)return i}return-1}function k8e(t={}){return[e8e,Ji,As.of(t),QDe,S8e,Zre]}const rse=[{key:"Ctrl-Space",run:nA},{mac:"Alt-`",run:nA},{mac:"Alt-i",run:nA},{key:"Escape",run:GDe},{key:"ArrowDown",run:nC(!0)},{key:"ArrowUp",run:nC(!1)},{key:"PageDown",run:nC(!0,"page")},{key:"PageUp",run:nC(!1,"page")},{key:"Enter",run:WDe}],S8e=Sf.highest($v.computeN([As],t=>t.facet(As).defaultKeymap?[rse]:[])),_8e=t=>{let{state:e}=t,n=e.doc.lineAt(e.selection.main.from),r=V9(t.state,n.from);return r.line?N8e(t):r.block?j8e(t):!1};function z9(t,e){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let s=t(e,n);return s?(r(n.update(s)),!0):!1}}const N8e=z9(M8e,0),E8e=z9(sse,0),j8e=z9((t,e)=>sse(t,e,T8e(e)),0);function V9(t,e){let n=t.languageDataAt("commentTokens",e,1);return n.length?n[0]:{}}const B0=50;function A8e(t,{open:e,close:n},r,s){let i=t.sliceDoc(r-B0,r),o=t.sliceDoc(s,s+B0),a=/\s*$/.exec(i)[0].length,c=/^\s*/.exec(o)[0].length,d=i.length-a;if(i.slice(d-e.length,d)==e&&o.slice(c,c+n.length)==n)return{open:{pos:r-a,margin:a&&1},close:{pos:s+c,margin:c&&1}};let f,m;s-r<=2*B0?f=m=t.sliceDoc(r,s):(f=t.sliceDoc(r,r+B0),m=t.sliceDoc(s-B0,s));let p=/^\s*/.exec(f)[0].length,x=/\s*$/.exec(m)[0].length,y=m.length-x-n.length;return f.slice(p,p+e.length)==e&&m.slice(y,y+n.length)==n?{open:{pos:r+p+e.length,margin:/\s/.test(f.charAt(p+e.length))?1:0},close:{pos:s-x-n.length,margin:/\s/.test(m.charAt(y-1))?1:0}}:null}function T8e(t){let e=[];for(let n of t.selection.ranges){let r=t.doc.lineAt(n.from),s=n.to<=r.to?r:t.doc.lineAt(n.to);s.from>r.from&&s.from==n.to&&(s=n.to==r.to+1?r:t.doc.lineAt(n.to-1));let i=e.length-1;i>=0&&e[i].to>r.from?e[i].to=s.to:e.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:s.to})}return e}function sse(t,e,n=e.selection.ranges){let r=n.map(i=>V9(e,i.from).block);if(!r.every(i=>i))return null;let s=n.map((i,o)=>A8e(e,r[o],i.from,i.to));if(t!=2&&!s.every(i=>i))return{changes:e.changes(n.map((i,o)=>s[o]?[]:[{from:i.from,insert:r[o].open+" "},{from:i.to,insert:" "+r[o].close}]))};if(t!=1&&s.some(i=>i)){let i=[];for(let o=0,a;o<s.length;o++)if(a=s[o]){let c=r[o],{open:d,close:f}=a;i.push({from:d.pos-c.open.length,to:d.pos+d.margin},{from:f.pos-f.margin,to:f.pos+c.close.length})}return{changes:i}}return null}function M8e(t,e,n=e.selection.ranges){let r=[],s=-1;e:for(let{from:i,to:o}of n){let a=r.length,c=1e9,d;for(let f=i;f<=o;){let m=e.doc.lineAt(f);if(d==null&&(d=V9(e,m.from).line,!d))continue e;if(m.from>s&&(i==o||o>m.from)){s=m.from;let p=/^\s*/.exec(m.text)[0].length,x=p==m.length,y=m.text.slice(p,p+d.length)==d?p:-1;p<m.text.length&&p<c&&(c=p),r.push({line:m,comment:y,token:d,indent:p,empty:x,single:!1})}f=m.to+1}if(c<1e9)for(let f=a;f<r.length;f++)r[f].indent<r[f].line.text.length&&(r[f].indent=c);r.length==a+1&&(r[a].single=!0)}if(t!=2&&r.some(i=>i.comment<0&&(!i.empty||i.single))){let i=[];for(let{line:a,token:c,indent:d,empty:f,single:m}of r)(m||!f)&&i.push({from:a.from+d,insert:c+" "});let o=e.changes(i);return{changes:o,selection:e.selection.map(o,1)}}else if(t!=1&&r.some(i=>i.comment>=0)){let i=[];for(let{line:o,comment:a,token:c}of r)if(a>=0){let d=o.from+a,f=d+c.length;o.text[f-o.from]==" "&&f++,i.push({from:d,to:f})}return{changes:i}}return null}const rM=Pu.define(),R8e=Pu.define(),O8e=ut.define(),ise=ut.define({combine(t){return lc(t,{minDepth:100,newGroupDelay:500,joinToEvent:(e,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,n)=>(r,s)=>e(r,s)||n(r,s)})}}),ose=Is.define({create(){return $l.empty},update(t,e){let n=e.state.facet(ise),r=e.annotation(rM);if(r){let c=eo.fromTransaction(e,r.selection),d=r.side,f=d==0?t.undone:t.done;return c?f=Vk(f,f.length,n.minDepth,c):f=cse(f,e.startState.selection),new $l(d==0?r.rest:f,d==0?f:r.rest)}let s=e.annotation(R8e);if((s=="full"||s=="before")&&(t=t.isolate()),e.annotation(is.addToHistory)===!1)return e.changes.empty?t:t.addMapping(e.changes.desc);let i=eo.fromTransaction(e),o=e.annotation(is.time),a=e.annotation(is.userEvent);return i?t=t.addChanges(i,o,a,n,e):e.selection&&(t=t.addSelection(e.startState.selection,o,a,n.newGroupDelay)),(s=="full"||s=="after")&&(t=t.isolate()),t},toJSON(t){return{done:t.done.map(e=>e.toJSON()),undone:t.undone.map(e=>e.toJSON())}},fromJSON(t){return new $l(t.done.map(eo.fromJSON),t.undone.map(eo.fromJSON))}});function I8e(t={}){return[ose,ise.of(t),at.domEventHandlers({beforeinput(e,n){let r=e.inputType=="historyUndo"?ase:e.inputType=="historyRedo"?sM:null;return r?(e.preventDefault(),r(n)):!1}})]}function Z_(t,e){return function({state:n,dispatch:r}){if(!e&&n.readOnly)return!1;let s=n.field(ose,!1);if(!s)return!1;let i=s.pop(t,n,e);return i?(r(i),!0):!1}}const ase=Z_(0,!1),sM=Z_(1,!1),D8e=Z_(0,!0),L8e=Z_(1,!0);class eo{constructor(e,n,r,s,i){this.changes=e,this.effects=n,this.mapped=r,this.startSelection=s,this.selectionsAfter=i}setSelAfter(e){return new eo(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,n,r;return{changes:(e=this.changes)===null||e===void 0?void 0:e.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(s=>s.toJSON())}}static fromJSON(e){return new eo(e.changes&&ps.fromJSON(e.changes),[],e.mapped&&Kl.fromJSON(e.mapped),e.startSelection&&De.fromJSON(e.startSelection),e.selectionsAfter.map(De.fromJSON))}static fromTransaction(e,n){let r=ua;for(let s of e.startState.facet(O8e)){let i=s(e);i.length&&(r=r.concat(i))}return!r.length&&e.changes.empty?null:new eo(e.changes.invert(e.startState.doc),r,void 0,n||e.startState.selection,ua)}static selection(e){return new eo(void 0,ua,void 0,void 0,e)}}function Vk(t,e,n,r){let s=e+1>n+20?e-n-1:0,i=t.slice(s,e);return i.push(r),i}function P8e(t,e){let n=[],r=!1;return t.iterChangedRanges((s,i)=>n.push(s,i)),e.iterChangedRanges((s,i,o,a)=>{for(let c=0;c<n.length;){let d=n[c++],f=n[c++];a>=d&&o<=f&&(r=!0)}}),r}function F8e(t,e){return t.ranges.length==e.ranges.length&&t.ranges.filter((n,r)=>n.empty!=e.ranges[r].empty).length===0}function lse(t,e){return t.length?e.length?t.concat(e):t:e}const ua=[],$8e=200;function cse(t,e){if(t.length){let n=t[t.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-$8e));return r.length&&r[r.length-1].eq(e)?t:(r.push(e),Vk(t,t.length-1,1e9,n.setSelAfter(r)))}else return[eo.selection([e])]}function B8e(t){let e=t[t.length-1],n=t.slice();return n[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),n}function sA(t,e){if(!t.length)return t;let n=t.length,r=ua;for(;n;){let s=z8e(t[n-1],e,r);if(s.changes&&!s.changes.empty||s.effects.length){let i=t.slice(0,n);return i[n-1]=s,i}else e=s.mapped,n--,r=s.selectionsAfter}return r.length?[eo.selection(r)]:ua}function z8e(t,e,n){let r=lse(t.selectionsAfter.length?t.selectionsAfter.map(a=>a.map(e)):ua,n);if(!t.changes)return eo.selection(r);let s=t.changes.map(e),i=e.mapDesc(t.changes,!0),o=t.mapped?t.mapped.composeDesc(i):i;return new eo(s,zt.mapEffects(t.effects,e),o,t.startSelection.map(i),r)}const V8e=/^(input\.type|delete)($|\.)/;class $l{constructor(e,n,r=0,s=void 0){this.done=e,this.undone=n,this.prevTime=r,this.prevUserEvent=s}isolate(){return this.prevTime?new $l(this.done,this.undone):this}addChanges(e,n,r,s,i){let o=this.done,a=o[o.length-1];return a&&a.changes&&!a.changes.empty&&e.changes&&(!r||V8e.test(r))&&(!a.selectionsAfter.length&&n-this.prevTime<s.newGroupDelay&&s.joinToEvent(i,P8e(a.changes,e.changes))||r=="input.type.compose")?o=Vk(o,o.length-1,s.minDepth,new eo(e.changes.compose(a.changes),lse(zt.mapEffects(e.effects,a.changes),a.effects),a.mapped,a.startSelection,ua)):o=Vk(o,o.length,s.minDepth,e),new $l(o,ua,n,r)}addSelection(e,n,r,s){let i=this.done.length?this.done[this.done.length-1].selectionsAfter:ua;return i.length>0&&n-this.prevTime<s&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&F8e(i[i.length-1],e)?this:new $l(cse(this.done,e),this.undone,n,r)}addMapping(e){return new $l(sA(this.done,e),sA(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,n,r){let s=e==0?this.done:this.undone;if(s.length==0)return null;let i=s[s.length-1],o=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):n.selection);if(r&&i.selectionsAfter.length)return n.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:rM.of({side:e,rest:B8e(s),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(i.changes){let a=s.length==1?ua:s.slice(0,s.length-1);return i.mapped&&(a=sA(a,i.mapped)),n.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:rM.of({side:e,rest:a,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}$l.empty=new $l(ua,ua);const H8e=[{key:"Mod-z",run:ase,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:sM,preventDefault:!0},{linux:"Ctrl-Shift-z",run:sM,preventDefault:!0},{key:"Mod-u",run:D8e,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:L8e,preventDefault:!0}];function Ax(t,e){return De.create(t.ranges.map(e),t.mainIndex)}function cl(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function ul({state:t,dispatch:e},n){let r=Ax(t.selection,n);return r.eq(t.selection,!0)?!1:(e(cl(t,r)),!0)}function Q_(t,e){return De.cursor(e?t.to:t.from)}function use(t,e){return ul(t,n=>n.empty?t.moveByChar(n,e):Q_(n,e))}function mi(t){return t.textDirectionAt(t.state.selection.main.head)==lr.LTR}const dse=t=>use(t,!mi(t)),fse=t=>use(t,mi(t));function hse(t,e){return ul(t,n=>n.empty?t.moveByGroup(n,e):Q_(n,e))}const U8e=t=>hse(t,!mi(t)),q8e=t=>hse(t,mi(t));function K8e(t,e,n){if(e.type.prop(n))return!0;let r=e.to-e.from;return r&&(r>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function X_(t,e,n){let r=Ws(t).resolveInner(e.head),s=n?sn.closedBy:sn.openedBy;for(let c=e.head;;){let d=n?r.childAfter(c):r.childBefore(c);if(!d)break;K8e(t,d,s)?r=d:c=n?d.to:d.from}let i=r.type.prop(s),o,a;return i&&(o=n?Fl(t,r.from,1):Fl(t,r.to,-1))&&o.matched?a=n?o.end.to:o.end.from:a=n?r.to:r.from,De.cursor(a,n?-1:1)}const W8e=t=>ul(t,e=>X_(t.state,e,!mi(t))),G8e=t=>ul(t,e=>X_(t.state,e,mi(t)));function mse(t,e){return ul(t,n=>{if(!n.empty)return Q_(n,e);let r=t.moveVertically(n,e);return r.head!=n.head?r:t.moveToLineBoundary(n,e)})}const pse=t=>mse(t,!1),gse=t=>mse(t,!0);function xse(t){let e=t.scrollDOM.clientHeight<t.scrollDOM.scrollHeight-2,n=0,r=0,s;if(e){for(let i of t.state.facet(at.scrollMargins)){let o=i(t);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))}s=t.scrollDOM.clientHeight-n-r}else s=(t.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:e,height:Math.max(t.defaultLineHeight,s-5)}}function yse(t,e){let n=xse(t),{state:r}=t,s=Ax(r.selection,o=>o.empty?t.moveVertically(o,e,n.height):Q_(o,e));if(s.eq(r.selection))return!1;let i;if(n.selfScroll){let o=t.coordsAtPos(r.selection.main.head),a=t.scrollDOM.getBoundingClientRect(),c=a.top+n.marginTop,d=a.bottom-n.marginBottom;o&&o.top>c&&o.bottom<d&&(i=at.scrollIntoView(s.main.head,{y:"start",yMargin:o.top-c}))}return t.dispatch(cl(r,s),{effects:i}),!0}const WV=t=>yse(t,!1),iM=t=>yse(t,!0);function _f(t,e,n){let r=t.lineBlockAt(e.head),s=t.moveToLineBoundary(e,n);if(s.head==e.head&&s.head!=(n?r.to:r.from)&&(s=t.moveToLineBoundary(e,n,!1)),!n&&s.head==r.from&&r.length){let i=/^\s*/.exec(t.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;i&&e.head!=r.from+i&&(s=De.cursor(r.from+i))}return s}const J8e=t=>ul(t,e=>_f(t,e,!0)),Y8e=t=>ul(t,e=>_f(t,e,!1)),Z8e=t=>ul(t,e=>_f(t,e,!mi(t))),Q8e=t=>ul(t,e=>_f(t,e,mi(t))),X8e=t=>ul(t,e=>De.cursor(t.lineBlockAt(e.head).from,1)),eLe=t=>ul(t,e=>De.cursor(t.lineBlockAt(e.head).to,-1));function tLe(t,e,n){let r=!1,s=Ax(t.selection,i=>{let o=Fl(t,i.head,-1)||Fl(t,i.head,1)||i.head>0&&Fl(t,i.head-1,1)||i.head<t.doc.length&&Fl(t,i.head+1,-1);if(!o||!o.end)return i;r=!0;let a=o.start.from==i.head?o.end.to:o.end.from;return De.cursor(a)});return r?(e(cl(t,s)),!0):!1}const nLe=({state:t,dispatch:e})=>tLe(t,e);function _a(t,e){let n=Ax(t.state.selection,r=>{let s=e(r);return De.range(r.anchor,s.head,s.goalColumn,s.bidiLevel||void 0)});return n.eq(t.state.selection)?!1:(t.dispatch(cl(t.state,n)),!0)}function bse(t,e){return _a(t,n=>t.moveByChar(n,e))}const vse=t=>bse(t,!mi(t)),wse=t=>bse(t,mi(t));function Cse(t,e){return _a(t,n=>t.moveByGroup(n,e))}const rLe=t=>Cse(t,!mi(t)),sLe=t=>Cse(t,mi(t)),iLe=t=>_a(t,e=>X_(t.state,e,!mi(t))),oLe=t=>_a(t,e=>X_(t.state,e,mi(t)));function kse(t,e){return _a(t,n=>t.moveVertically(n,e))}const Sse=t=>kse(t,!1),_se=t=>kse(t,!0);function Nse(t,e){return _a(t,n=>t.moveVertically(n,e,xse(t).height))}const GV=t=>Nse(t,!1),JV=t=>Nse(t,!0),aLe=t=>_a(t,e=>_f(t,e,!0)),lLe=t=>_a(t,e=>_f(t,e,!1)),cLe=t=>_a(t,e=>_f(t,e,!mi(t))),uLe=t=>_a(t,e=>_f(t,e,mi(t))),dLe=t=>_a(t,e=>De.cursor(t.lineBlockAt(e.head).from)),fLe=t=>_a(t,e=>De.cursor(t.lineBlockAt(e.head).to)),YV=({state:t,dispatch:e})=>(e(cl(t,{anchor:0})),!0),ZV=({state:t,dispatch:e})=>(e(cl(t,{anchor:t.doc.length})),!0),QV=({state:t,dispatch:e})=>(e(cl(t,{anchor:t.selection.main.anchor,head:0})),!0),XV=({state:t,dispatch:e})=>(e(cl(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0),hLe=({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0),mLe=({state:t,dispatch:e})=>{let n=e5(t).map(({from:r,to:s})=>De.range(r,Math.min(s+1,t.doc.length)));return e(t.update({selection:De.create(n),userEvent:"select"})),!0},pLe=({state:t,dispatch:e})=>{let n=Ax(t.selection,r=>{let s=Ws(t),i=s.resolveStack(r.from,1);if(r.empty){let o=s.resolveStack(r.from,-1);o.node.from>=i.node.from&&o.node.to<=i.node.to&&(i=o)}for(let o=i;o;o=o.next){let{node:a}=o;if((a.from<r.from&&a.to>=r.to||a.to>r.to&&a.from<=r.from)&&o.next)return De.range(a.to,a.from)}return r});return n.eq(t.selection)?!1:(e(cl(t,n)),!0)};function Ese(t,e){let{state:n}=t,r=n.selection,s=n.selection.ranges.slice();for(let i of n.selection.ranges){let o=n.doc.lineAt(i.head);if(e?o.to<t.state.doc.length:o.from>0)for(let a=i;;){let c=t.moveVertically(a,e);if(c.head<o.from||c.head>o.to){s.some(d=>d.head==c.head)||s.push(c);break}else{if(c.head==a.head)break;a=c}}}return s.length==r.ranges.length?!1:(t.dispatch(cl(n,De.create(s,s.length-1))),!0)}const gLe=t=>Ese(t,!1),xLe=t=>Ese(t,!0),yLe=({state:t,dispatch:e})=>{let n=t.selection,r=null;return n.ranges.length>1?r=De.create([n.main]):n.main.empty||(r=De.create([De.cursor(n.main.head)])),r?(e(cl(t,r)),!0):!1};function Uv(t,e){if(t.state.readOnly)return!1;let n="delete.selection",{state:r}=t,s=r.changeByRange(i=>{let{from:o,to:a}=i;if(o==a){let c=e(i);c<o?(n="delete.backward",c=rC(t,c,!1)):c>o&&(n="delete.forward",c=rC(t,c,!0)),o=Math.min(o,c),a=Math.max(a,c)}else o=rC(t,o,!1),a=rC(t,a,!0);return o==a?{range:i}:{changes:{from:o,to:a},range:De.cursor(o,o<i.head?-1:1)}});return s.changes.empty?!1:(t.dispatch(r.update(s,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?at.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function rC(t,e,n){if(t instanceof at)for(let r of t.state.facet(at.atomicRanges).map(s=>s(t)))r.between(e,e,(s,i)=>{s<e&&i>e&&(e=n?i:s)});return e}const jse=(t,e,n)=>Uv(t,r=>{let s=r.from,{state:i}=t,o=i.doc.lineAt(s),a,c;if(n&&!e&&s>o.from&&s<o.from+200&&!/[^ \t]/.test(a=o.text.slice(0,s-o.from))){if(a[a.length-1]==" ")return s-1;let d=Ex(a,i.tabSize),f=d%rm(i)||rm(i);for(let m=0;m<f&&a[a.length-1-m]==" ";m++)s--;c=s}else c=Ms(o.text,s-o.from,e,e)+o.from,c==s&&o.number!=(e?i.doc.lines:1)?c+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,s-o.from))&&(c=Ms(o.text,c-o.from,!1,!1)+o.from);return c}),oM=t=>jse(t,!1,!0),Ase=t=>jse(t,!0,!1),Tse=(t,e)=>Uv(t,n=>{let r=n.head,{state:s}=t,i=s.doc.lineAt(r),o=s.charCategorizer(r);for(let a=null;;){if(r==(e?i.to:i.from)){r==n.head&&i.number!=(e?s.doc.lines:1)&&(r+=e?1:-1);break}let c=Ms(i.text,r-i.from,e)+i.from,d=i.text.slice(Math.min(r,c)-i.from,Math.max(r,c)-i.from),f=o(d);if(a!=null&&f!=a)break;(d!=" "||r!=n.head)&&(a=f),r=c}return r}),Mse=t=>Tse(t,!1),bLe=t=>Tse(t,!0),vLe=t=>Uv(t,e=>{let n=t.lineBlockAt(e.head).to;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)}),wLe=t=>Uv(t,e=>{let n=t.moveToLineBoundary(e,!1).head;return e.head>n?n:Math.max(0,e.head-1)}),CLe=t=>Uv(t,e=>{let n=t.moveToLineBoundary(e,!0).head;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)}),kLe=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:Pn.of(["",""])},range:De.cursor(r.from)}));return e(t.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},SLe=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(r=>{if(!r.empty||r.from==0||r.from==t.doc.length)return{range:r};let s=r.from,i=t.doc.lineAt(s),o=s==i.from?s-1:Ms(i.text,s-i.from,!1)+i.from,a=s==i.to?s+1:Ms(i.text,s-i.from,!0)+i.from;return{changes:{from:o,to:a,insert:t.doc.slice(s,a).append(t.doc.slice(o,s))},range:De.cursor(a)}});return n.changes.empty?!1:(e(t.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function e5(t){let e=[],n=-1;for(let r of t.selection.ranges){let s=t.doc.lineAt(r.from),i=t.doc.lineAt(r.to);if(!r.empty&&r.to==i.from&&(i=t.doc.lineAt(r.to-1)),n>=s.number){let o=e[e.length-1];o.to=i.to,o.ranges.push(r)}else e.push({from:s.from,to:i.to,ranges:[r]});n=i.number+1}return e}function Rse(t,e,n){if(t.readOnly)return!1;let r=[],s=[];for(let i of e5(t)){if(n?i.to==t.doc.length:i.from==0)continue;let o=t.doc.lineAt(n?i.to+1:i.from-1),a=o.length+1;if(n){r.push({from:i.to,to:o.to},{from:i.from,insert:o.text+t.lineBreak});for(let c of i.ranges)s.push(De.range(Math.min(t.doc.length,c.anchor+a),Math.min(t.doc.length,c.head+a)))}else{r.push({from:o.from,to:i.from},{from:i.to,insert:t.lineBreak+o.text});for(let c of i.ranges)s.push(De.range(c.anchor-a,c.head-a))}}return r.length?(e(t.update({changes:r,scrollIntoView:!0,selection:De.create(s,t.selection.mainIndex),userEvent:"move.line"})),!0):!1}const _Le=({state:t,dispatch:e})=>Rse(t,e,!1),NLe=({state:t,dispatch:e})=>Rse(t,e,!0);function Ose(t,e,n){if(t.readOnly)return!1;let r=[];for(let i of e5(t))n?r.push({from:i.from,insert:t.doc.slice(i.from,i.to)+t.lineBreak}):r.push({from:i.to,insert:t.lineBreak+t.doc.slice(i.from,i.to)});let s=t.changes(r);return e(t.update({changes:s,selection:t.selection.map(s,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const ELe=({state:t,dispatch:e})=>Ose(t,e,!1),jLe=({state:t,dispatch:e})=>Ose(t,e,!0),ALe=t=>{if(t.state.readOnly)return!1;let{state:e}=t,n=e.changes(e5(e).map(({from:s,to:i})=>(s>0?s--:i<e.doc.length&&i++,{from:s,to:i}))),r=Ax(e.selection,s=>{let i;if(t.lineWrapping){let o=t.lineBlockAt(s.head),a=t.coordsAtPos(s.head,s.assoc||1);a&&(i=o.bottom+t.documentTop-a.bottom+t.defaultLineHeight/2)}return t.moveVertically(s,!0,i)}).map(n);return t.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function TLe(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let n=Ws(t).resolveInner(e),r=n.childBefore(e),s=n.childAfter(e),i;return r&&s&&r.to<=e&&s.from>=e&&(i=r.type.prop(sn.closedBy))&&i.indexOf(s.name)>-1&&t.doc.lineAt(r.to).from==t.doc.lineAt(s.from).from&&!/\S/.test(t.sliceDoc(r.to,s.from))?{from:r.to,to:s.from}:null}const eH=Ise(!1),MLe=Ise(!0);function Ise(t){return({state:e,dispatch:n})=>{if(e.readOnly)return!1;let r=e.changeByRange(s=>{let{from:i,to:o}=s,a=e.doc.lineAt(i),c=!t&&i==o&&TLe(e,i);t&&(i=o=(o<=a.to?a:e.doc.lineAt(o)).to);let d=new G_(e,{simulateBreak:i,simulateDoubleBreak:!!c}),f=A9(d,i);for(f==null&&(f=Ex(/^\s*/.exec(e.doc.lineAt(i).text)[0],e.tabSize));o<a.to&&/\s/.test(a.text[o-a.from]);)o++;c?{from:i,to:o}=c:i>a.from&&i<a.from+100&&!/\S/.test(a.text.slice(0,i))&&(i=a.from);let m=["",Cb(e,f)];return c&&m.push(Cb(e,d.lineIndent(a.from,-1))),{changes:{from:i,to:o,insert:Pn.of(m)},range:De.cursor(i+1+m[1].length)}});return n(e.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function H9(t,e){let n=-1;return t.changeByRange(r=>{let s=[];for(let o=r.from;o<=r.to;){let a=t.doc.lineAt(o);a.number>n&&(r.empty||r.to>a.from)&&(e(a,s,r),n=a.number),o=a.to+1}let i=t.changes(s);return{changes:s,range:De.range(i.mapPos(r.anchor,1),i.mapPos(r.head,1))}})}const RLe=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=Object.create(null),r=new G_(t,{overrideIndentation:i=>{let o=n[i];return o??-1}}),s=H9(t,(i,o,a)=>{let c=A9(r,i.from);if(c==null)return;/\S/.test(i.text)||(c=0);let d=/^\s*/.exec(i.text)[0],f=Cb(t,c);(d!=f||a.from<i.from+d.length)&&(n[i.from]=c,o.push({from:i.from,to:i.from+d.length,insert:f}))});return s.changes.empty||e(t.update(s,{userEvent:"indent"})),!0},Dse=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(H9(t,(n,r)=>{r.push({from:n.from,insert:t.facet(W_)})}),{userEvent:"input.indent"})),!0),Lse=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(H9(t,(n,r)=>{let s=/^\s*/.exec(n.text)[0];if(!s)return;let i=Ex(s,t.tabSize),o=0,a=Cb(t,Math.max(0,i-rm(t)));for(;o<s.length&&o<a.length&&s.charCodeAt(o)==a.charCodeAt(o);)o++;r.push({from:n.from+o,to:n.from+s.length,insert:a.slice(o)})}),{userEvent:"delete.dedent"})),!0),OLe=t=>(t.setTabFocusMode(),!0),ILe=[{key:"Ctrl-b",run:dse,shift:vse,preventDefault:!0},{key:"Ctrl-f",run:fse,shift:wse},{key:"Ctrl-p",run:pse,shift:Sse},{key:"Ctrl-n",run:gse,shift:_se},{key:"Ctrl-a",run:X8e,shift:dLe},{key:"Ctrl-e",run:eLe,shift:fLe},{key:"Ctrl-d",run:Ase},{key:"Ctrl-h",run:oM},{key:"Ctrl-k",run:vLe},{key:"Ctrl-Alt-h",run:Mse},{key:"Ctrl-o",run:kLe},{key:"Ctrl-t",run:SLe},{key:"Ctrl-v",run:iM}],DLe=[{key:"ArrowLeft",run:dse,shift:vse,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:U8e,shift:rLe,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Z8e,shift:cLe,preventDefault:!0},{key:"ArrowRight",run:fse,shift:wse,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:q8e,shift:sLe,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Q8e,shift:uLe,preventDefault:!0},{key:"ArrowUp",run:pse,shift:Sse,preventDefault:!0},{mac:"Cmd-ArrowUp",run:YV,shift:QV},{mac:"Ctrl-ArrowUp",run:WV,shift:GV},{key:"ArrowDown",run:gse,shift:_se,preventDefault:!0},{mac:"Cmd-ArrowDown",run:ZV,shift:XV},{mac:"Ctrl-ArrowDown",run:iM,shift:JV},{key:"PageUp",run:WV,shift:GV},{key:"PageDown",run:iM,shift:JV},{key:"Home",run:Y8e,shift:lLe,preventDefault:!0},{key:"Mod-Home",run:YV,shift:QV},{key:"End",run:J8e,shift:aLe,preventDefault:!0},{key:"Mod-End",run:ZV,shift:XV},{key:"Enter",run:eH,shift:eH},{key:"Mod-a",run:hLe},{key:"Backspace",run:oM,shift:oM,preventDefault:!0},{key:"Delete",run:Ase,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Mse,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:bLe,preventDefault:!0},{mac:"Mod-Backspace",run:wLe,preventDefault:!0},{mac:"Mod-Delete",run:CLe,preventDefault:!0}].concat(ILe.map(t=>({mac:t.key,run:t.run,shift:t.shift}))),LLe=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:W8e,shift:iLe},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:G8e,shift:oLe},{key:"Alt-ArrowUp",run:_Le},{key:"Shift-Alt-ArrowUp",run:ELe},{key:"Alt-ArrowDown",run:NLe},{key:"Shift-Alt-ArrowDown",run:jLe},{key:"Mod-Alt-ArrowUp",run:gLe},{key:"Mod-Alt-ArrowDown",run:xLe},{key:"Escape",run:yLe},{key:"Mod-Enter",run:MLe},{key:"Alt-l",mac:"Ctrl-l",run:mLe},{key:"Mod-i",run:pLe,preventDefault:!0},{key:"Mod-[",run:Lse},{key:"Mod-]",run:Dse},{key:"Mod-Alt-\\",run:RLe},{key:"Shift-Mod-k",run:ALe},{key:"Shift-Mod-\\",run:nLe},{key:"Mod-/",run:_8e},{key:"Alt-A",run:E8e},{key:"Ctrl-m",mac:"Shift-Alt-m",run:OLe}].concat(DLe),PLe={key:"Tab",run:Dse,shift:Lse};function FLe(t,e,n,r){const s=Xl(Sr),i=No(yee),o=U.useRef(null),{lexicalNode:a}=m4(),c=U.useRef(!1),d=U.useRef(!1),f=U.useCallback(()=>{i({editorType:e,rootNode:a,editorRef:o.current})},[e,a,i]),m=U.useCallback(p=>{var x,y,w,k,S,C;if(p.key==="ArrowDown"){const _=(y=(x=o.current)==null?void 0:x.getCodemirror())==null?void 0:y.state;if(_){const E=_.doc.length,j=_.selection.ranges[0].to;E===j&&(c.current?(s==null||s.update(()=>{var R,T;const M=tr(t);M.getNextSibling()?((T=(R=o.current)==null?void 0:R.getCodemirror())==null||T.contentDOM.blur(),M.selectNext()):M.insertAfter(Mn())}),c.current=!1):c.current=!0)}}else if(p.key==="ArrowUp"){const _=(k=(w=o.current)==null?void 0:w.getCodemirror())==null?void 0:k.state;_&&_.selection.ranges[0].from===0&&(d.current?(s==null||s.update(()=>{var j,R;const T=tr(t);T.getPreviousSibling()&&((R=(j=o.current)==null?void 0:j.getCodemirror())==null||R.contentDOM.blur(),T.selectPrevious())}),d.current=!1):d.current=!0)}else if(p.key==="Enter")p.stopPropagation();else if(p.key==="Backspace"||p.key==="Delete"){const _=(C=(S=o.current)==null?void 0:S.getCodemirror())==null?void 0:C.state;(_==null?void 0:_.doc.length)===0&&(s==null||s.update(()=>{tr(t).remove()}))}},[s,t]);return U.useEffect(()=>{const p=o.current;return setTimeout(()=>{var x,y;(x=p==null?void 0:p.getCodemirror())==null||x.contentDOM.addEventListener("focus",f),(y=p==null?void 0:p.getCodemirror())==null||y.contentDOM.addEventListener("keydown",m)},300),()=>{var x,y;(x=p==null?void 0:p.getCodemirror())==null||x.contentDOM.removeEventListener("focus",f),(y=p==null?void 0:p.getCodemirror())==null||y.contentDOM.removeEventListener("keydown",m)}},[o,f,m,n]),U.useEffect(()=>{r.subscribe(()=>{var p,x;(x=(p=o.current)==null?void 0:p.getCodemirror())==null||x.focus(),f()})},[r,o,t,f]),o}function Ve(t){return new F6e(M9.define(t))}function hd(t){return Ae(()=>import("./index-B5lcBapM.js"),__vite__mapDeps([0,1])).then(e=>e.sql({dialect:e[t]}))}const $Le=[_e.of({name:"C",extensions:["c","h","ino"],load(){return Ae(()=>import("./index-DfZRO-Sg.js"),__vite__mapDeps([2,1])).then(t=>t.cpp())}}),_e.of({name:"C++",alias:["cpp"],extensions:["cpp","c++","cc","cxx","hpp","h++","hh","hxx"],load(){return Ae(()=>import("./index-DfZRO-Sg.js"),__vite__mapDeps([2,1])).then(t=>t.cpp())}}),_e.of({name:"CQL",alias:["cassandra"],extensions:["cql"],load(){return hd("Cassandra")}}),_e.of({name:"CSS",extensions:["css"],load(){return Ae(()=>import("./index-DTIo8uPQ.js"),__vite__mapDeps([3,1])).then(t=>t.css())}}),_e.of({name:"Go",extensions:["go"],load(){return Ae(()=>import("./index-CtaVukcz.js"),__vite__mapDeps([4,1])).then(t=>t.go())}}),_e.of({name:"HTML",alias:["xhtml"],extensions:["html","htm","handlebars","hbs"],load(){return Ae(()=>import("./index-Dk1gv0CE.js"),__vite__mapDeps([5,1,3,6])).then(t=>t.html())}}),_e.of({name:"Java",extensions:["java"],load(){return Ae(()=>import("./index-CjQjoAz7.js"),__vite__mapDeps([7,1])).then(t=>t.java())}}),_e.of({name:"JavaScript",alias:["ecmascript","js","node"],extensions:["js","mjs","cjs"],load(){return Ae(()=>import("./index-MBe5yEwm.js"),__vite__mapDeps([6,1])).then(t=>t.javascript())}}),_e.of({name:"Jinja",extensions:["j2","jinja","jinja2"],load(){return Ae(()=>import("./index-CBSSPM1S.js"),__vite__mapDeps([8,5,1,3,6])).then(t=>t.jinja())}}),_e.of({name:"JSON",alias:["json5"],extensions:["json","map"],load(){return Ae(()=>import("./index-BRFNvIHS.js"),__vite__mapDeps([9,1])).then(t=>t.json())}}),_e.of({name:"JSX",extensions:["jsx"],load(){return Ae(()=>import("./index-MBe5yEwm.js"),__vite__mapDeps([6,1])).then(t=>t.javascript({jsx:!0}))}}),_e.of({name:"LESS",extensions:["less"],load(){return Ae(()=>import("./index-CruLAJPT.js"),__vite__mapDeps([10,3,1])).then(t=>t.less())}}),_e.of({name:"Liquid",extensions:["liquid"],load(){return Ae(()=>import("./index-D4gCO_aF.js"),__vite__mapDeps([11,5,1,3,6])).then(t=>t.liquid())}}),_e.of({name:"MariaDB SQL",load(){return hd("MariaSQL")}}),_e.of({name:"Markdown",extensions:["md","markdown","mkd"],load(){return Ae(()=>import("./index-B8hXk4LB.js"),__vite__mapDeps([12,5,1,3,6])).then(t=>t.markdown())}}),_e.of({name:"MS SQL",load(){return hd("MSSQL")}}),_e.of({name:"MySQL",load(){return hd("MySQL")}}),_e.of({name:"PHP",extensions:["php","php3","php4","php5","php7","phtml"],load(){return Ae(()=>import("./index-B-qkRZNA.js"),__vite__mapDeps([13,1,5,3,6])).then(t=>t.php())}}),_e.of({name:"PLSQL",extensions:["pls"],load(){return hd("PLSQL")}}),_e.of({name:"PostgreSQL",load(){return hd("PostgreSQL")}}),_e.of({name:"Python",extensions:["BUILD","bzl","py","pyw"],filename:/^(BUCK|BUILD)$/,load(){return Ae(()=>import("./index-CpmFy7gn.js"),__vite__mapDeps([14,1])).then(t=>t.python())}}),_e.of({name:"Rust",extensions:["rs"],load(){return Ae(()=>import("./index-CyUWI6Na.js"),__vite__mapDeps([15,1])).then(t=>t.rust())}}),_e.of({name:"Sass",extensions:["sass"],load(){return Ae(()=>import("./index-B5vJuk6w.js"),__vite__mapDeps([16,1,3])).then(t=>t.sass({indented:!0}))}}),_e.of({name:"SCSS",extensions:["scss"],load(){return Ae(()=>import("./index-B5vJuk6w.js"),__vite__mapDeps([16,1,3])).then(t=>t.sass())}}),_e.of({name:"SQL",extensions:["sql"],load(){return hd("StandardSQL")}}),_e.of({name:"SQLite",load(){return hd("SQLite")}}),_e.of({name:"TSX",extensions:["tsx"],load(){return Ae(()=>import("./index-MBe5yEwm.js"),__vite__mapDeps([6,1])).then(t=>t.javascript({jsx:!0,typescript:!0}))}}),_e.of({name:"TypeScript",alias:["ts"],extensions:["ts","mts","cts"],load(){return Ae(()=>import("./index-MBe5yEwm.js"),__vite__mapDeps([6,1])).then(t=>t.javascript({typescript:!0}))}}),_e.of({name:"WebAssembly",extensions:["wat","wast"],load(){return Ae(()=>import("./index-BRNSwivr.js"),__vite__mapDeps([17,1])).then(t=>t.wast())}}),_e.of({name:"XML",alias:["rss","wsdl","xsd"],extensions:["xml","xsl","xsd","svg"],load(){return Ae(()=>import("./index-aEHzrjcE.js"),__vite__mapDeps([18,1])).then(t=>t.xml())}}),_e.of({name:"YAML",alias:["yml"],extensions:["yaml","yml"],load(){return Ae(()=>import("./index-BoyoInHy.js"),__vite__mapDeps([19,1])).then(t=>t.yaml())}}),_e.of({name:"APL",extensions:["dyalog","apl"],load(){return Ae(()=>import("./apl-B4CMkyY2.js"),[]).then(t=>Ve(t.apl))}}),_e.of({name:"PGP",alias:["asciiarmor"],extensions:["asc","pgp","sig"],load(){return Ae(()=>import("./asciiarmor-Df11BRmG.js"),[]).then(t=>Ve(t.asciiArmor))}}),_e.of({name:"ASN.1",extensions:["asn","asn1"],load(){return Ae(()=>import("./asn1-EdZsLKOL.js"),[]).then(t=>Ve(t.asn1({})))}}),_e.of({name:"Asterisk",filename:/^extensions\.conf$/i,load(){return Ae(()=>import("./asterisk-B-8jnY81.js"),[]).then(t=>Ve(t.asterisk))}}),_e.of({name:"Brainfuck",extensions:["b","bf"],load(){return Ae(()=>import("./brainfuck-C4LP7Hcl.js"),[]).then(t=>Ve(t.brainfuck))}}),_e.of({name:"Cobol",extensions:["cob","cpy"],load(){return Ae(()=>import("./cobol-CWcv1MsR.js"),[]).then(t=>Ve(t.cobol))}}),_e.of({name:"C#",alias:["csharp","cs"],extensions:["cs"],load(){return Ae(()=>import("./clike-B9uivgTg.js"),[]).then(t=>Ve(t.csharp))}}),_e.of({name:"Clojure",extensions:["clj","cljc","cljx"],load(){return Ae(()=>import("./clojure-BMjYHr_A.js"),[]).then(t=>Ve(t.clojure))}}),_e.of({name:"ClojureScript",extensions:["cljs"],load(){return Ae(()=>import("./clojure-BMjYHr_A.js"),[]).then(t=>Ve(t.clojure))}}),_e.of({name:"Closure Stylesheets (GSS)",extensions:["gss"],load(){return Ae(()=>import("./css-BnMrqG3P.js"),[]).then(t=>Ve(t.gss))}}),_e.of({name:"CMake",extensions:["cmake","cmake.in"],filename:/^CMakeLists\.txt$/,load(){return Ae(()=>import("./cmake-BQqOBYOt.js"),[]).then(t=>Ve(t.cmake))}}),_e.of({name:"CoffeeScript",alias:["coffee","coffee-script"],extensions:["coffee"],load(){return Ae(()=>import("./coffeescript-S37ZYGWr.js"),[]).then(t=>Ve(t.coffeeScript))}}),_e.of({name:"Common Lisp",alias:["lisp"],extensions:["cl","lisp","el"],load(){return Ae(()=>import("./commonlisp-DBKNyK5s.js"),[]).then(t=>Ve(t.commonLisp))}}),_e.of({name:"Cypher",extensions:["cyp","cypher"],load(){return Ae(()=>import("./cypher-C_CwsFkJ.js"),[]).then(t=>Ve(t.cypher))}}),_e.of({name:"Cython",extensions:["pyx","pxd","pxi"],load(){return Ae(()=>import("./python-BuPzkPfP.js"),[]).then(t=>Ve(t.cython))}}),_e.of({name:"Crystal",extensions:["cr"],load(){return Ae(()=>import("./crystal-SjHAIU92.js"),[]).then(t=>Ve(t.crystal))}}),_e.of({name:"D",extensions:["d"],load(){return Ae(()=>import("./d-pRatUO7H.js"),[]).then(t=>Ve(t.d))}}),_e.of({name:"Dart",extensions:["dart"],load(){return Ae(()=>import("./clike-B9uivgTg.js"),[]).then(t=>Ve(t.dart))}}),_e.of({name:"diff",extensions:["diff","patch"],load(){return Ae(()=>import("./diff-DbItnlRl.js"),[]).then(t=>Ve(t.diff))}}),_e.of({name:"Dockerfile",filename:/^Dockerfile$/,load(){return Ae(()=>import("./dockerfile-BKs6k2Af.js"),__vite__mapDeps([20,21])).then(t=>Ve(t.dockerFile))}}),_e.of({name:"DTD",extensions:["dtd"],load(){return Ae(()=>import("./dtd-DF_7sFjM.js"),[]).then(t=>Ve(t.dtd))}}),_e.of({name:"Dylan",extensions:["dylan","dyl","intr"],load(){return Ae(()=>import("./dylan-DwRh75JA.js"),[]).then(t=>Ve(t.dylan))}}),_e.of({name:"EBNF",load(){return Ae(()=>import("./ebnf-CDyGwa7X.js"),[]).then(t=>Ve(t.ebnf))}}),_e.of({name:"ECL",extensions:["ecl"],load(){return Ae(()=>import("./ecl-Cabwm37j.js"),[]).then(t=>Ve(t.ecl))}}),_e.of({name:"edn",extensions:["edn"],load(){return Ae(()=>import("./clojure-BMjYHr_A.js"),[]).then(t=>Ve(t.clojure))}}),_e.of({name:"Eiffel",extensions:["e"],load(){return Ae(()=>import("./eiffel-CnydiIhH.js"),[]).then(t=>Ve(t.eiffel))}}),_e.of({name:"Elm",extensions:["elm"],load(){return Ae(()=>import("./elm-vLlmbW-K.js"),[]).then(t=>Ve(t.elm))}}),_e.of({name:"Erlang",extensions:["erl"],load(){return Ae(()=>import("./erlang-BNw1qcRV.js"),[]).then(t=>Ve(t.erlang))}}),_e.of({name:"Esper",load(){return Ae(()=>import("./sql-D0XecflT.js"),[]).then(t=>Ve(t.esper))}}),_e.of({name:"Factor",extensions:["factor"],load(){return Ae(()=>import("./factor-kuTfRLto.js"),__vite__mapDeps([22,21])).then(t=>Ve(t.factor))}}),_e.of({name:"FCL",load(){return Ae(()=>import("./fcl-Kvtd6kyn.js"),[]).then(t=>Ve(t.fcl))}}),_e.of({name:"Forth",extensions:["forth","fth","4th"],load(){return Ae(()=>import("./forth-Ffai-XNe.js"),[]).then(t=>Ve(t.forth))}}),_e.of({name:"Fortran",extensions:["f","for","f77","f90","f95"],load(){return Ae(()=>import("./fortran-DYz_wnZ1.js"),[]).then(t=>Ve(t.fortran))}}),_e.of({name:"F#",alias:["fsharp"],extensions:["fs"],load(){return Ae(()=>import("./mllike-CXdrOF99.js"),[]).then(t=>Ve(t.fSharp))}}),_e.of({name:"Gas",extensions:["s"],load(){return Ae(()=>import("./gas-Bneqetm1.js"),[]).then(t=>Ve(t.gas))}}),_e.of({name:"Gherkin",extensions:["feature"],load(){return Ae(()=>import("./gherkin-heZmZLOM.js"),[]).then(t=>Ve(t.gherkin))}}),_e.of({name:"Groovy",extensions:["groovy","gradle"],filename:/^Jenkinsfile$/,load(){return Ae(()=>import("./groovy-D9Dt4D0W.js"),[]).then(t=>Ve(t.groovy))}}),_e.of({name:"Haskell",extensions:["hs"],load(){return Ae(()=>import("./haskell-Cw1EW3IL.js"),[]).then(t=>Ve(t.haskell))}}),_e.of({name:"Haxe",extensions:["hx"],load(){return Ae(()=>import("./haxe-H-WmDvRZ.js"),[]).then(t=>Ve(t.haxe))}}),_e.of({name:"HXML",extensions:["hxml"],load(){return Ae(()=>import("./haxe-H-WmDvRZ.js"),[]).then(t=>Ve(t.hxml))}}),_e.of({name:"HTTP",load(){return Ae(()=>import("./http-DBlCnlav.js"),[]).then(t=>Ve(t.http))}}),_e.of({name:"IDL",extensions:["pro"],load(){return Ae(()=>import("./idl-BEugSyMb.js"),[]).then(t=>Ve(t.idl))}}),_e.of({name:"JSON-LD",alias:["jsonld"],extensions:["jsonld"],load(){return Ae(()=>import("./javascript-iXu5QeM3.js"),[]).then(t=>Ve(t.jsonld))}}),_e.of({name:"Julia",extensions:["jl"],load(){return Ae(()=>import("./julia-DuME0IfC.js"),[]).then(t=>Ve(t.julia))}}),_e.of({name:"Kotlin",extensions:["kt","kts"],load(){return Ae(()=>import("./clike-B9uivgTg.js"),[]).then(t=>Ve(t.kotlin))}}),_e.of({name:"LiveScript",alias:["ls"],extensions:["ls"],load(){return Ae(()=>import("./livescript-BwQOo05w.js"),[]).then(t=>Ve(t.liveScript))}}),_e.of({name:"Lua",extensions:["lua"],load(){return Ae(()=>import("./lua-BgMRiT3U.js"),[]).then(t=>Ve(t.lua))}}),_e.of({name:"mIRC",extensions:["mrc"],load(){return Ae(()=>import("./mirc-CjQqDB4T.js"),[]).then(t=>Ve(t.mirc))}}),_e.of({name:"Mathematica",extensions:["m","nb","wl","wls"],load(){return Ae(()=>import("./mathematica-DTrFuWx2.js"),[]).then(t=>Ve(t.mathematica))}}),_e.of({name:"Modelica",extensions:["mo"],load(){return Ae(()=>import("./modelica-Dc1JOy9r.js"),[]).then(t=>Ve(t.modelica))}}),_e.of({name:"MUMPS",extensions:["mps"],load(){return Ae(()=>import("./mumps-BT43cFF4.js"),[]).then(t=>Ve(t.mumps))}}),_e.of({name:"Mbox",extensions:["mbox"],load(){return Ae(()=>import("./mbox-CNhZ1qSd.js"),[]).then(t=>Ve(t.mbox))}}),_e.of({name:"Nginx",filename:/nginx.*\.conf$/i,load(){return Ae(()=>import("./nginx-DdIZxoE0.js"),[]).then(t=>Ve(t.nginx))}}),_e.of({name:"NSIS",extensions:["nsh","nsi"],load(){return Ae(()=>import("./nsis-LdVXkNf5.js"),__vite__mapDeps([23,21])).then(t=>Ve(t.nsis))}}),_e.of({name:"NTriples",extensions:["nt","nq"],load(){return Ae(()=>import("./ntriples-BfvgReVJ.js"),[]).then(t=>Ve(t.ntriples))}}),_e.of({name:"Objective-C",alias:["objective-c","objc"],extensions:["m"],load(){return Ae(()=>import("./clike-B9uivgTg.js"),[]).then(t=>Ve(t.objectiveC))}}),_e.of({name:"Objective-C++",alias:["objective-c++","objc++"],extensions:["mm"],load(){return Ae(()=>import("./clike-B9uivgTg.js"),[]).then(t=>Ve(t.objectiveCpp))}}),_e.of({name:"OCaml",extensions:["ml","mli","mll","mly"],load(){return Ae(()=>import("./mllike-CXdrOF99.js"),[]).then(t=>Ve(t.oCaml))}}),_e.of({name:"Octave",extensions:["m"],load(){return Ae(()=>import("./octave-Ck1zUtKM.js"),[]).then(t=>Ve(t.octave))}}),_e.of({name:"Oz",extensions:["oz"],load(){return Ae(()=>import("./oz-BzwKVEFT.js"),[]).then(t=>Ve(t.oz))}}),_e.of({name:"Pascal",extensions:["p","pas"],load(){return Ae(()=>import("./pascal--L3eBynH.js"),[]).then(t=>Ve(t.pascal))}}),_e.of({name:"Perl",extensions:["pl","pm"],load(){return Ae(()=>import("./perl-CdXCOZ3F.js"),[]).then(t=>Ve(t.perl))}}),_e.of({name:"Pig",extensions:["pig"],load(){return Ae(()=>import("./pig-CevX1Tat.js"),[]).then(t=>Ve(t.pig))}}),_e.of({name:"PowerShell",extensions:["ps1","psd1","psm1"],load(){return Ae(()=>import("./powershell-CFHJl5sT.js"),[]).then(t=>Ve(t.powerShell))}}),_e.of({name:"Properties files",alias:["ini","properties"],extensions:["properties","ini","in"],load(){return Ae(()=>import("./properties-C78fOPTZ.js"),[]).then(t=>Ve(t.properties))}}),_e.of({name:"ProtoBuf",extensions:["proto"],load(){return Ae(()=>import("./protobuf-ChK-085T.js"),[]).then(t=>Ve(t.protobuf))}}),_e.of({name:"Pug",alias:["jade"],extensions:["pug","jade"],load(){return Ae(()=>import("./pug-DeIclll2.js"),__vite__mapDeps([24,25])).then(t=>Ve(t.pug))}}),_e.of({name:"Puppet",extensions:["pp"],load(){return Ae(()=>import("./puppet-DMA9R1ak.js"),[]).then(t=>Ve(t.puppet))}}),_e.of({name:"Q",extensions:["q"],load(){return Ae(()=>import("./q-pXgVlZs6.js"),[]).then(t=>Ve(t.q))}}),_e.of({name:"R",alias:["rscript"],extensions:["r","R"],load(){return Ae(()=>import("./r-B6wPVr8A.js"),[]).then(t=>Ve(t.r))}}),_e.of({name:"RPM Changes",load(){return Ae(()=>import("./rpm-CTu-6PCP.js"),[]).then(t=>Ve(t.rpmChanges))}}),_e.of({name:"RPM Spec",extensions:["spec"],load(){return Ae(()=>import("./rpm-CTu-6PCP.js"),[]).then(t=>Ve(t.rpmSpec))}}),_e.of({name:"Ruby",alias:["jruby","macruby","rake","rb","rbx"],extensions:["rb"],filename:/^(Gemfile|Rakefile)$/,load(){return Ae(()=>import("./ruby-B2Rjki9n.js"),[]).then(t=>Ve(t.ruby))}}),_e.of({name:"SAS",extensions:["sas"],load(){return Ae(()=>import("./sas-B4kiWyti.js"),[]).then(t=>Ve(t.sas))}}),_e.of({name:"Scala",extensions:["scala"],load(){return Ae(()=>import("./clike-B9uivgTg.js"),[]).then(t=>Ve(t.scala))}}),_e.of({name:"Scheme",extensions:["scm","ss"],load(){return Ae(()=>import("./scheme-C41bIUwD.js"),[]).then(t=>Ve(t.scheme))}}),_e.of({name:"Shell",alias:["bash","sh","zsh"],extensions:["sh","ksh","bash"],filename:/^PKGBUILD$/,load(){return Ae(()=>import("./shell-CjFT_Tl9.js"),[]).then(t=>Ve(t.shell))}}),_e.of({name:"Sieve",extensions:["siv","sieve"],load(){return Ae(()=>import("./sieve-C3Gn_uJK.js"),[]).then(t=>Ve(t.sieve))}}),_e.of({name:"Smalltalk",extensions:["st"],load(){return Ae(()=>import("./smalltalk-CnHTOXQT.js"),[]).then(t=>Ve(t.smalltalk))}}),_e.of({name:"Solr",load(){return Ae(()=>import("./solr-DehyRSwq.js"),[]).then(t=>Ve(t.solr))}}),_e.of({name:"SML",extensions:["sml","sig","fun","smackspec"],load(){return Ae(()=>import("./mllike-CXdrOF99.js"),[]).then(t=>Ve(t.sml))}}),_e.of({name:"SPARQL",alias:["sparul"],extensions:["rq","sparql"],load(){return Ae(()=>import("./sparql-DkYu6x3z.js"),[]).then(t=>Ve(t.sparql))}}),_e.of({name:"Spreadsheet",alias:["excel","formula"],load(){return Ae(()=>import("./spreadsheet-BCZA_wO0.js"),[]).then(t=>Ve(t.spreadsheet))}}),_e.of({name:"Squirrel",extensions:["nut"],load(){return Ae(()=>import("./clike-B9uivgTg.js"),[]).then(t=>Ve(t.squirrel))}}),_e.of({name:"Stylus",extensions:["styl"],load(){return Ae(()=>import("./stylus-B533Al4x.js"),[]).then(t=>Ve(t.stylus))}}),_e.of({name:"Swift",extensions:["swift"],load(){return Ae(()=>import("./swift-BzpIVaGY.js"),[]).then(t=>Ve(t.swift))}}),_e.of({name:"sTeX",load(){return Ae(()=>import("./stex-C3f8Ysf7.js"),[]).then(t=>Ve(t.stex))}}),_e.of({name:"LaTeX",alias:["tex"],extensions:["text","ltx","tex"],load(){return Ae(()=>import("./stex-C3f8Ysf7.js"),[]).then(t=>Ve(t.stex))}}),_e.of({name:"SystemVerilog",extensions:["v","sv","svh"],load(){return Ae(()=>import("./verilog-C6RDOZhf.js"),[]).then(t=>Ve(t.verilog))}}),_e.of({name:"Tcl",extensions:["tcl"],load(){return Ae(()=>import("./tcl-DVfN8rqt.js"),[]).then(t=>Ve(t.tcl))}}),_e.of({name:"Textile",extensions:["textile"],load(){return Ae(()=>import("./textile-CnDTJFAw.js"),[]).then(t=>Ve(t.textile))}}),_e.of({name:"TiddlyWiki",load(){return Ae(()=>import("./tiddlywiki-DO-Gjzrf.js"),[]).then(t=>Ve(t.tiddlyWiki))}}),_e.of({name:"Tiki wiki",load(){return Ae(()=>import("./tiki-DGYXhP31.js"),[]).then(t=>Ve(t.tiki))}}),_e.of({name:"TOML",extensions:["toml"],load(){return Ae(()=>import("./toml-Bm5Em-hy.js"),[]).then(t=>Ve(t.toml))}}),_e.of({name:"Troff",extensions:["1","2","3","4","5","6","7","8","9"],load(){return Ae(()=>import("./troff-wAsdV37c.js"),[]).then(t=>Ve(t.troff))}}),_e.of({name:"TTCN",extensions:["ttcn","ttcn3","ttcnpp"],load(){return Ae(()=>import("./ttcn-CfJYG6tj.js"),[]).then(t=>Ve(t.ttcn))}}),_e.of({name:"TTCN_CFG",extensions:["cfg"],load(){return Ae(()=>import("./ttcn-cfg-B9xdYoR4.js"),[]).then(t=>Ve(t.ttcnCfg))}}),_e.of({name:"Turtle",extensions:["ttl"],load(){return Ae(()=>import("./turtle-B1tBg_DP.js"),[]).then(t=>Ve(t.turtle))}}),_e.of({name:"Web IDL",extensions:["webidl"],load(){return Ae(()=>import("./webidl-ZXfAyPTL.js"),[]).then(t=>Ve(t.webIDL))}}),_e.of({name:"VB.NET",extensions:["vb"],load(){return Ae(()=>import("./vb-CmGdzxic.js"),[]).then(t=>Ve(t.vb))}}),_e.of({name:"VBScript",extensions:["vbs"],load(){return Ae(()=>import("./vbscript-BuJXcnF6.js"),[]).then(t=>Ve(t.vbScript))}}),_e.of({name:"Velocity",extensions:["vtl"],load(){return Ae(()=>import("./velocity-D8B20fx6.js"),[]).then(t=>Ve(t.velocity))}}),_e.of({name:"Verilog",extensions:["v"],load(){return Ae(()=>import("./verilog-C6RDOZhf.js"),[]).then(t=>Ve(t.verilog))}}),_e.of({name:"VHDL",extensions:["vhd","vhdl"],load(){return Ae(()=>import("./vhdl-lSbBsy5d.js"),[]).then(t=>Ve(t.vhdl))}}),_e.of({name:"XQuery",extensions:["xy","xquery","xq","xqm","xqy"],load(){return Ae(()=>import("./xquery-DzFWVndE.js"),[]).then(t=>Ve(t.xQuery))}}),_e.of({name:"Yacas",extensions:["ys"],load(){return Ae(()=>import("./yacas-BJ4BC0dw.js"),[]).then(t=>Ve(t.yacas))}}),_e.of({name:"Z80",extensions:["z80"],load(){return Ae(()=>import("./z80-Hz9HOZM7.js"),[]).then(t=>Ve(t.z80))}}),_e.of({name:"MscGen",extensions:["mscgen","mscin","msc"],load(){return Ae(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(t=>Ve(t.mscgen))}}),_e.of({name:"Xù",extensions:["xu"],load(){return Ae(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(t=>Ve(t.xu))}}),_e.of({name:"MsGenny",extensions:["msgenny"],load(){return Ae(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(t=>Ve(t.msgenny))}}),_e.of({name:"Vue",extensions:["vue"],load(){return Ae(()=>import("./index-BHY-irKy.js"),__vite__mapDeps([26,5,1,3,6])).then(t=>t.vue())}}),_e.of({name:"Angular Template",load(){return Ae(()=>import("./index-CDPRbL3N.js"),__vite__mapDeps([27,5,1,3,6])).then(t=>t.angular())}})],tH="#2e3440",U9="#3b4252",nH="#434c5e",sC="#4c566a",rH="#e5e9f0",aM="#eceff4",iA="#8fbcbb",sH="#88c0d0",BLe="#81a1c1",Ma="#5e81ac",zLe="#bf616a",pp="#d08770",oA="#ebcb8b",iH="#a3be8c",VLe="#b48ead",oH="#d30102",q9=aM,aA=q9,HLe="#ffffff",lA=U9,ULe=q9,aH=U9,qLe=at.theme({"&":{color:tH,backgroundColor:HLe},".cm-content":{caretColor:aH},".cm-cursor, .cm-dropCursor":{borderLeftColor:aH},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:ULe},".cm-panels":{backgroundColor:q9,color:sC},".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 ${sC}`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:rH},".cm-activeLine":{backgroundColor:aA},".cm-selectionMatch":{backgroundColor:rH},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{outline:`1px solid ${sC}`},"&.cm-focused .cm-matchingBracket":{backgroundColor:aM},".cm-gutters":{backgroundColor:aM,color:tH,border:"none"},".cm-activeLineGutter":{backgroundColor:aA},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:lA},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:lA,borderBottomColor:lA},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:aA,color:sC}}},{dark:!1}),KLe=Vv.define([{tag:je.keyword,color:Ma},{tag:[je.name,je.deleted,je.character,je.propertyName,je.macroName],color:pp},{tag:[je.variableName],color:pp},{tag:[je.function(je.variableName)],color:Ma},{tag:[je.labelName],color:BLe},{tag:[je.color,je.constant(je.name),je.standard(je.name)],color:Ma},{tag:[je.definition(je.name),je.separator],color:iH},{tag:[je.brace],color:iA},{tag:[je.annotation],color:oH},{tag:[je.number,je.changed,je.annotation,je.modifier,je.self,je.namespace],color:sH},{tag:[je.typeName,je.className],color:oA},{tag:[je.operator,je.operatorKeyword],color:iH},{tag:[je.tagName],color:VLe},{tag:[je.squareBracket],color:zLe},{tag:[je.angleBracket],color:pp},{tag:[je.attributeName],color:oA},{tag:[je.regexp],color:Ma},{tag:[je.quote],color:U9},{tag:[je.string],color:pp},{tag:je.link,color:iA,textDecoration:"underline",textUnderlinePosition:"under"},{tag:[je.url,je.escape,je.special(je.string)],color:pp},{tag:[je.meta],color:sH},{tag:[je.comment],color:nH,fontStyle:"italic"},{tag:je.strong,fontWeight:"bold",color:Ma},{tag:je.emphasis,fontStyle:"italic",color:Ma},{tag:je.strikethrough,textDecoration:"line-through"},{tag:je.heading,fontWeight:"bold",color:Ma},{tag:je.special(je.heading1),fontWeight:"bold",color:Ma},{tag:je.heading1,fontWeight:"bold",color:Ma},{tag:[je.heading2,je.heading3,je.heading4],fontWeight:"bold",color:Ma},{tag:[je.heading5,je.heading6],color:Ma},{tag:[je.atom,je.bool,je.special(je.variableName)],color:pp},{tag:[je.processingInstruction,je.inserted],color:iA},{tag:[je.contentSeparator],color:oA},{tag:je.invalid,color:nH,borderBottom:`1px dotted ${oH}`}]),WLe=[qLe,Pre(KLe)],lH=typeof String.prototype.normalize=="function"?t=>t.normalize("NFKD"):t=>t;class Jg{constructor(e,n,r=0,s=e.length,i,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(r,s),this.bufferStart=r,this.normalize=i?a=>i(lH(a)):lH,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 Gi(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let n=o9(e),r=this.bufferStart+this.bufferPos;this.bufferPos+=Rl(e);let s=this.normalize(n);if(s.length)for(let i=0,o=r;;i++){let a=s.charCodeAt(i),c=this.match(a,o,this.bufferPos+this.bufferStart);if(i==s.length-1){if(c)return this.value=c,this;break}o==r&&i<n.length&&n.charCodeAt(i)==a&&o++}}}match(e,n,r){let s=null;for(let i=0;i<this.matches.length;i+=2){let o=this.matches[i],a=!1;this.query.charCodeAt(o)==e&&(o==this.query.length-1?s={from:this.matches[i+1],to:r}:(this.matches[i]++,a=!0)),a||(this.matches.splice(i,2),i-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?s={from:n,to:r}:this.matches.push(1,n)),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}typeof Symbol<"u"&&(Jg.prototype[Symbol.iterator]=function(){return this});const Pse={from:-1,to:-1,match:/.*/.exec("")},K9="gm"+(/x/.unicode==null?"":"u");class Fse{constructor(e,n,r,s=0,i=e.length){if(this.text=e,this.to=i,this.curLine="",this.done=!1,this.value=Pse,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new $se(e,n,r,s,i);this.re=new RegExp(n,K9+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.iter=e.iter();let o=e.lineAt(s);this.curLineStart=o.from,this.matchPos=Hk(e,s),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),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 e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let n=this.matchPos<=this.to&&this.re.exec(this.curLine);if(n){let r=this.curLineStart+n.index,s=r+n[0].length;if(this.matchPos=Hk(this.text,s+(r==s?1:0)),r==this.curLineStart+this.curLine.length&&this.nextLine(),(r<s||r>this.value.to)&&(!this.test||this.test(r,s,n)))return this.value={from:r,to:s,match:n},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const cA=new WeakMap;class eg{constructor(e,n){this.from=e,this.text=n}get to(){return this.from+this.text.length}static get(e,n,r){let s=cA.get(e);if(!s||s.from>=r||s.to<=n){let a=new eg(n,e.sliceString(n,r));return cA.set(e,a),a}if(s.from==n&&s.to==r)return s;let{text:i,from:o}=s;return o>n&&(i=e.sliceString(n,o)+i,o=n),s.to<r&&(i+=e.sliceString(s.to,r)),cA.set(e,new eg(o,i)),new eg(n,i.slice(n-o,r-o))}}class $se{constructor(e,n,r,s,i){this.text=e,this.to=i,this.done=!1,this.value=Pse,this.matchPos=Hk(e,s),this.re=new RegExp(n,K9+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.flat=eg.get(e,s,this.chunkEnd(s+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,n=this.re.exec(this.flat.text);if(n&&!n[0]&&n.index==e&&(this.re.lastIndex=e+1,n=this.re.exec(this.flat.text)),n){let r=this.flat.from+n.index,s=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,s,n)))return this.value={from:r,to:s,match:n},this.matchPos=Hk(this.text,s+(r==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=eg.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(Fse.prototype[Symbol.iterator]=$se.prototype[Symbol.iterator]=function(){return this});function GLe(t){try{return new RegExp(t,K9),!0}catch{return!1}}function Hk(t,e){if(e>=t.length)return e;let n=t.lineAt(e),r;for(;e<n.to&&(r=n.text.charCodeAt(e-n.from))>=56320&&r<57344;)e++;return e}const JLe=t=>{let{state:e}=t,n=String(e.doc.lineAt(t.state.selection.main.head).number),{close:r,result:s}=Q9e(t,{label:e.phrase("Go to line"),input:{type:"text",name:"line",value:n},focus:!0,submitLabel:e.phrase("go")});return s.then(i=>{let o=i&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(i.elements.line.value);if(!o){t.dispatch({effects:r});return}let a=e.doc.lineAt(e.selection.main.head),[,c,d,f,m]=o,p=f?+f.slice(1):0,x=d?+d:a.number;if(d&&m){let k=x/100;c&&(k=k*(c=="-"?-1:1)+a.number/e.doc.lines),x=Math.round(e.doc.lines*k)}else d&&c&&(x=x*(c=="-"?-1:1)+a.number);let y=e.doc.line(Math.max(1,Math.min(e.doc.lines,x))),w=De.cursor(y.from+Math.max(0,Math.min(p,y.length)));t.dispatch({effects:[r,at.scrollIntoView(w.from,{y:"center"})],selection:w})}),!0},YLe={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},ZLe=ut.define({combine(t){return lc(t,YLe,{highlightWordAroundCursor:(e,n)=>e||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function QLe(t){return[r7e,n7e]}const XLe=Mt.mark({class:"cm-selectionMatch"}),e7e=Mt.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function cH(t,e,n,r){return(n==0||t(e.sliceDoc(n-1,n))!=_r.Word)&&(r==e.doc.length||t(e.sliceDoc(r,r+1))!=_r.Word)}function t7e(t,e,n,r){return t(e.sliceDoc(n,n+1))==_r.Word&&t(e.sliceDoc(r-1,r))==_r.Word}const n7e=us.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.selectionSet||t.docChanged||t.viewportChanged)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=t.state.facet(ZLe),{state:n}=t,r=n.selection;if(r.ranges.length>1)return Mt.none;let s=r.main,i,o=null;if(s.empty){if(!e.highlightWordAroundCursor)return Mt.none;let c=n.wordAt(s.head);if(!c)return Mt.none;o=n.charCategorizer(s.head),i=n.sliceDoc(c.from,c.to)}else{let c=s.to-s.from;if(c<e.minSelectionLength||c>200)return Mt.none;if(e.wholeWords){if(i=n.sliceDoc(s.from,s.to),o=n.charCategorizer(s.head),!(cH(o,n,s.from,s.to)&&t7e(o,n,s.from,s.to)))return Mt.none}else if(i=n.sliceDoc(s.from,s.to),!i)return Mt.none}let a=[];for(let c of t.visibleRanges){let d=new Jg(n.doc,i,c.from,c.to);for(;!d.next().done;){let{from:f,to:m}=d.value;if((!o||cH(o,n,f,m))&&(s.empty&&f<=s.from&&m>=s.to?a.push(e7e.range(f,m)):(f>=s.to||m<=s.from)&&a.push(XLe.range(f,m)),a.length>e.maxMatches))return Mt.none}}return Mt.set(a)}},{decorations:t=>t.decorations}),r7e=at.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),s7e=({state:t,dispatch:e})=>{let{selection:n}=t,r=De.create(n.ranges.map(s=>t.wordAt(s.head)||De.cursor(s.head)),n.mainIndex);return r.eq(n)?!1:(e(t.update({selection:r})),!0)};function i7e(t,e){let{main:n,ranges:r}=t.selection,s=t.wordAt(n.head),i=s&&s.from==n.from&&s.to==n.to;for(let o=!1,a=new Jg(t.doc,e,r[r.length-1].to);;)if(a.next(),a.done){if(o)return null;a=new Jg(t.doc,e,0,Math.max(0,r[r.length-1].from-1)),o=!0}else{if(o&&r.some(c=>c.from==a.value.from))continue;if(i){let c=t.wordAt(a.value.from);if(!c||c.from!=a.value.from||c.to!=a.value.to)continue}return a.value}}const o7e=({state:t,dispatch:e})=>{let{ranges:n}=t.selection;if(n.some(i=>i.from===i.to))return s7e({state:t,dispatch:e});let r=t.sliceDoc(n[0].from,n[0].to);if(t.selection.ranges.some(i=>t.sliceDoc(i.from,i.to)!=r))return!1;let s=i7e(t,r);return s?(e(t.update({selection:t.selection.addRange(De.range(s.from,s.to),!1),effects:at.scrollIntoView(s.to)})),!0):!1},Tx=ut.define({combine(t){return lc(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new v7e(e),scrollToMatch:e=>at.scrollIntoView(e)})}});class Bse{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||GLe(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(n,r)=>r=="n"?`
807
+ `);r>-1&&(n=n.slice(0,r))}return e+n.length<=this.to?n:n.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,n=this.lineAfter(e),r=e+n.length;for(let s=this.rangeIndex;;){let i=this.ranges[s].to;if(i>=r||(n=n.slice(0,i-(r-n.length)),s++,s==this.ranges.length))break;let o=this.ranges[s].from,a=this.lineAfter(o);n+=a,r=o+a.length}return{line:n,end:r}}skipGapsTo(e,n,r){for(;;){let s=this.ranges[this.rangeIndex].to,i=e+n;if(r>0?s>i:s>=i)break;let o=this.ranges[++this.rangeIndex].from;n+=o-s}return n}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(e,n,r,s){let i=4;if(this.ranges.length>1){s=this.skipGapsTo(n,s,1),n+=s;let a=this.chunk.length;s=this.skipGapsTo(r,s,-1),r+=s,i+=this.chunk.length-a}let o=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&i==4&&o>=0&&this.chunk[o]==e&&this.chunk[o+2]==n?this.chunk[o+2]=r:this.chunk.push(e,n,r,i),s}parseLine(e){let{line:n,end:r}=this.nextLine(),s=0,{streamParser:i}=this.lang,o=new zre(n,e?e.state.tabSize:4,e?rm(e.state):2);if(o.eol())i.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let a=Hre(i.token,o,this.state);if(a&&(s=this.emitToken(this.lang.tokenTable.resolve(a),this.parsedPos+o.start,this.parsedPos+o.pos,s)),o.start>1e4)break}this.parsedPos=r,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let e=cr.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:NDe,topID:0,maxBufferLength:512,reused:this.chunkReused});e=new cr(e.type,e.children,e.positions,e.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(e),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new cr(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function Hre(t,e,n){e.start=e.pos;for(let r=0;r<10;r++){let s=t(e,n);if(e.pos>e.start)return s}throw new Error("Stream parser failed to advance stream.")}const O9=Object.create(null),kb=[Ai.none],NDe=new _9(kb),LV=[],PV=Object.create(null),Ure=Object.create(null);for(let[t,e]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"]])Ure[t]=Kre(O9,e);class qre{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),Ure)}resolve(e){return e?this.table[e]||(this.table[e]=Kre(this.extra,e)):0}}const EDe=new qre(O9);function eA(t,e){LV.indexOf(t)>-1||(LV.push(t),console.warn(e))}function Kre(t,e){let n=[];for(let a of e.split(" ")){let c=[];for(let d of a.split(".")){let f=t[d]||je[d];f?typeof f=="function"?c.length?c=c.map(f):eA(d,`Modifier ${d} used at start of tag`):c.length?eA(d,`Tag ${d} used as modifier`):c=Array.isArray(f)?f:[f]:eA(d,`Unknown highlighting tag ${d}`)}for(let d of c)n.push(d)}if(!n.length)return 0;let r=e.replace(/ /g,"_"),s=r+" "+n.map(a=>a.id),i=PV[s];if(i)return i.id;let o=PV[s]=Ai.define({id:kb.length,name:r,props:[T6e({[r]:n})]});return kb.push(o),o.id}function jDe(t,e){let n=Ai.define({id:kb.length,name:"Document",props:[ah.add(()=>t),Nre.add(()=>r=>e.getIndent(r))],top:!0});return kb.push(n),n}lr.RTL,lr.LTR;class Wre{constructor(e,n,r,s){this.state=e,this.pos=n,this.explicit=r,this.view=s,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let n=Ws(this.state).resolveInner(this.pos,-1);for(;n&&e.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(e){let n=this.state.doc.lineAt(this.pos),r=Math.max(n.from,this.pos-250),s=n.text.slice(r-n.from,this.pos-n.from),i=s.search(Gre(e,!1));return i<0?null:{from:r+i,to:this.pos,text:s.slice(i)}}get aborted(){return this.abortListeners==null}addEventListener(e,n,r){e=="abort"&&this.abortListeners&&(this.abortListeners.push(n),r&&r.onDocChange&&(this.abortOnDocChange=!0))}}function FV(t){let e=Object.keys(t).join(""),n=/\w/.test(e);return n&&(e=e.replace(/\w/g,"")),`[${n?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function ADe(t){let e=Object.create(null),n=Object.create(null);for(let{label:s}of t){e[s[0]]=!0;for(let i=1;i<s.length;i++)n[s[i]]=!0}let r=FV(e)+FV(n)+"*$";return[new RegExp("^"+r),new RegExp(r)]}function TDe(t){let e=t.map(s=>typeof s=="string"?{label:s}:s),[n,r]=e.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:ADe(e);return s=>{let i=s.matchBefore(r);return i||s.explicit?{from:i?i.from:s.pos,options:e,validFor:n}:null}}function FKe(t,e){return n=>{for(let r=Ws(n.state).resolveInner(n.pos,-1);r;r=r.parent){if(t.indexOf(r.name)>-1)return null;if(r.type.isTop)break}return e(n)}}class $V{constructor(e,n,r,s){this.completion=e,this.source=n,this.match=r,this.score=s}}function _h(t){return t.selection.main.from}function Gre(t,e){var n;let{source:r}=t,s=e&&r[0]!="^",i=r[r.length-1]!="$";return!s&&!i?t:new RegExp(`${s?"^":""}(?:${r})${i?"$":""}`,(n=t.flags)!==null&&n!==void 0?n:t.ignoreCase?"i":"")}const I9=Pu.define();function MDe(t,e,n,r){let{main:s}=t.selection,i=n-s.from,o=r-s.from;return{...t.changeByRange(a=>{if(a!=s&&n!=r&&t.sliceDoc(a.from+i,a.from+o)!=t.sliceDoc(n,r))return{range:a};let c=t.toText(e);return{changes:{from:a.from+i,to:r==s.from?a.to:a.from+o,insert:c},range:De.cursor(a.from+i+c.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const BV=new WeakMap;function RDe(t){if(!Array.isArray(t))return t;let e=BV.get(t);return e||BV.set(t,e=TDe(t)),e}const Bk=zt.define(),Sb=zt.define();class ODe{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let n=0;n<e.length;){let r=Gi(e,n),s=Rl(r);this.chars.push(r);let i=e.slice(n,n+s),o=i.toUpperCase();this.folded.push(Gi(o==i?i.toLowerCase():o,0)),n+=s}this.astral=e.length!=this.chars.length}ret(e,n){return this.score=e,this.matched=n,this}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:n,folded:r,any:s,precise:i,byWord:o}=this;if(n.length==1){let C=Gi(e,0),_=Rl(C),E=_==e.length?0:-100;if(C!=n[0])if(C==r[0])E+=-200;else return null;return this.ret(E,[0,_])}let a=e.indexOf(this.pattern);if(a==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let c=n.length,d=0;if(a<0){for(let C=0,_=Math.min(e.length,200);C<_&&d<c;){let E=Gi(e,C);(E==n[d]||E==r[d])&&(s[d++]=C),C+=Rl(E)}if(d<c)return null}let f=0,m=0,p=!1,x=0,y=-1,w=-1,k=/[a-z]/.test(e),S=!0;for(let C=0,_=Math.min(e.length,200),E=0;C<_&&m<c;){let j=Gi(e,C);a<0&&(f<c&&j==n[f]&&(i[f++]=C),x<c&&(j==n[x]||j==r[x]?(x==0&&(y=C),w=C+1,x++):x=0));let R,T=j<255?j>=48&&j<=57||j>=97&&j<=122?2:j>=65&&j<=90?1:0:(R=o9(j))!=R.toLowerCase()?1:R!=R.toUpperCase()?2:0;(!C||T==1&&k||E==0&&T!=0)&&(n[m]==j||r[m]==j&&(p=!0)?o[m++]=C:o.length&&(S=!1)),E=T,C+=Rl(j)}return m==c&&o[0]==0&&S?this.result(-100+(p?-200:0),o,e):x==c&&y==0?this.ret(-200-e.length+(w==e.length?0:-100),[0,w]):a>-1?this.ret(-700-e.length,[a,a+this.pattern.length]):x==c?this.ret(-900-e.length,[y,w]):m==c?this.result(-100+(p?-200:0)+-700+(S?0:-1100),o,e):n.length==2?null:this.result((s[0]?-700:0)+-200+-1100,s,e)}result(e,n,r){let s=[],i=0;for(let o of n){let a=o+(this.astral?Rl(Gi(r,o)):1);i&&s[i-1]==o?s[i-1]=a:(s[i++]=o,s[i++]=a)}return this.ret(e-r.length,s)}}class IDe{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let n=e.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+(e.length==this.pattern.length?0:-100),this)}}const As=ut.define({combine(t){return lc(t,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:DDe,filterStrict:!1,compareCompletions:(e,n)=>(e.sortText||e.label).localeCompare(n.sortText||n.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,n)=>e&&n,closeOnBlur:(e,n)=>e&&n,icons:(e,n)=>e&&n,tooltipClass:(e,n)=>r=>zV(e(r),n(r)),optionClass:(e,n)=>r=>zV(e(r),n(r)),addToOptions:(e,n)=>e.concat(n),filterStrict:(e,n)=>e||n})}});function zV(t,e){return t?e?t+" "+e:t:e}function DDe(t,e,n,r,s,i){let o=t.textDirection==lr.RTL,a=o,c=!1,d="top",f,m,p=e.left-s.left,x=s.right-e.right,y=r.right-r.left,w=r.bottom-r.top;if(a&&p<Math.min(y,x)?a=!1:!a&&x<Math.min(y,p)&&(a=!0),y<=(a?p:x))f=Math.max(s.top,Math.min(n.top,s.bottom-w))-e.top,m=Math.min(400,a?p:x);else{c=!0,m=Math.min(400,(o?e.right:s.right-e.left)-30);let C=s.bottom-e.bottom;C>=w||C>e.top?f=n.bottom-e.top:(d="bottom",f=e.bottom-n.top)}let k=(e.bottom-e.top)/i.offsetHeight,S=(e.right-e.left)/i.offsetWidth;return{style:`${d}: ${f/k}px; max-width: ${m/S}px`,class:"cm-completionInfo-"+(c?o?"left-narrow":"right-narrow":a?"left":"right")}}function LDe(t){let e=t.addToOptions.slice();return t.icons&&e.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(s=>"cm-completionIcon-"+s)),r.setAttribute("aria-hidden","true"),r},position:20}),e.push({render(n,r,s,i){let o=document.createElement("span");o.className="cm-completionLabel";let a=n.displayLabel||n.label,c=0;for(let d=0;d<i.length;){let f=i[d++],m=i[d++];f>c&&o.appendChild(document.createTextNode(a.slice(c,f)));let p=o.appendChild(document.createElement("span"));p.appendChild(document.createTextNode(a.slice(f,m))),p.className="cm-completionMatchedText",c=m}return c<a.length&&o.appendChild(document.createTextNode(a.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}),e.sort((n,r)=>n.position-r.position).map(n=>n.render)}function tA(t,e,n){if(t<=n)return{from:0,to:t};if(e<0&&(e=0),e<=t>>1){let s=Math.floor(e/n);return{from:s*n,to:(s+1)*n}}let r=Math.floor((t-e)/n);return{from:t-(r+1)*n,to:t-r*n}}class PDe{constructor(e,n,r){this.view=e,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 s=e.state.field(n),{options:i,selected:o}=s.open,a=e.state.facet(As);this.optionContent=LDe(a),this.optionClass=a.optionClass,this.tooltipClass=a.tooltipClass,this.range=tA(i.length,o,a.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",c=>{let{options:d}=e.state.field(n).open;for(let f=c.target,m;f&&f!=this.dom;f=f.parentNode)if(f.nodeName=="LI"&&(m=/-(\d+)$/.exec(f.id))&&+m[1]<d.length){this.applyCompletion(e,d[+m[1]]),c.preventDefault();return}}),this.dom.addEventListener("focusout",c=>{let d=e.state.field(this.stateField,!1);d&&d.tooltip&&e.state.facet(As).closeOnBlur&&c.relatedTarget!=e.contentDOM&&e.dispatch({effects:Sb.of(null)})}),this.showOptions(i,s.id)}mount(){this.updateSel()}showOptions(e,n){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,n,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var n;let r=e.state.field(this.stateField),s=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),r!=s){let{options:i,selected:o,disabled:a}=r.open;(!s.open||s.open.options!=i)&&(this.range=tA(i.length,o,e.state.facet(As).maxRenderedOptions),this.showOptions(i,r.id)),this.updateSel(),a!=((n=s.open)===null||n===void 0?void 0:n.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!a)}}updateTooltipClass(e){let n=this.tooltipClass(e);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(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),n=e.open;(n.selected>-1&&n.selected<this.range.from||n.selected>=this.range.to)&&(this.range=tA(n.options.length,n.selected,this.view.state.facet(As).maxRenderedOptions),this.showOptions(n.options,e.id));let r=this.updateSelectedOption(n.selected);if(r){this.destroyInfo();let{completion:s}=n.options[n.selected],{info:i}=s;if(!i)return;let o=typeof i=="string"?document.createTextNode(i):i(s);if(!o)return;"then"in o?o.then(a=>{a&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(a,s)}).catch(a=>Xi(this.view.state,a,"completion info")):(this.addInfoPane(o,s),r.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,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),e.nodeType!=null)r.appendChild(e),this.infoDestroy=null;else{let{dom:s,destroy:i}=e;r.appendChild(s),this.infoDestroy=i||null}this.dom.appendChild(r),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let n=null;for(let r=this.list.firstChild,s=this.range.from;r;r=r.nextSibling,s++)r.nodeName!="LI"||!r.id?s--:s==e?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&&$De(this.list,n),n}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let n=this.dom.getBoundingClientRect(),r=this.info.getBoundingClientRect(),s=e.getBoundingClientRect(),i=this.space;if(!i){let o=this.dom.ownerDocument.documentElement;i={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return s.top>Math.min(i.bottom,n.bottom)-10||s.bottom<Math.max(i.top,n.top)+10?null:this.view.state.facet(As).positionInfo(this.view,n,s,r,i,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,n,r){const s=document.createElement("ul");s.id=n,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true"),s.setAttribute("aria-label",this.view.state.phrase("Completions")),s.addEventListener("mousedown",o=>{o.target==s&&o.preventDefault()});let i=null;for(let o=r.from;o<r.to;o++){let{completion:a,match:c}=e[o],{section:d}=a;if(d){let p=typeof d=="string"?d:d.name;if(p!=i&&(o>r.from||r.from==0))if(i=p,typeof d!="string"&&d.header)s.appendChild(d.header(d));else{let x=s.appendChild(document.createElement("completion-section"));x.textContent=p}}const f=s.appendChild(document.createElement("li"));f.id=n+"-"+o,f.setAttribute("role","option");let m=this.optionClass(a);m&&(f.className=m);for(let p of this.optionContent){let x=p(a,this.view.state,this.view,c);x&&f.appendChild(x)}}return r.from&&s.classList.add("cm-completionListIncompleteTop"),r.to<e.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function FDe(t,e){return n=>new PDe(n,t,e)}function $De(t,e){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect(),s=n.height/t.offsetHeight;r.top<n.top?t.scrollTop-=(n.top-r.top)/s:r.bottom>n.bottom&&(t.scrollTop+=(r.bottom-n.bottom)/s)}function VV(t){return(t.boost||0)*100+(t.apply?10:0)+(t.info?5:0)+(t.type?1:0)}function BDe(t,e){let n=[],r=null,s=null,i=f=>{n.push(f);let{section:m}=f.completion;if(m){r||(r=[]);let p=typeof m=="string"?m:m.name;r.some(x=>x.name==p)||r.push(typeof m=="string"?{name:p}:m)}},o=e.facet(As);for(let f of t)if(f.hasResult()){let m=f.result.getMatch;if(f.result.filter===!1)for(let p of f.result.options)i(new $V(p,f.source,m?m(p):[],1e9-n.length));else{let p=e.sliceDoc(f.from,f.to),x,y=o.filterStrict?new IDe(p):new ODe(p);for(let w of f.result.options)if(x=y.match(w.label)){let k=w.displayLabel?m?m(w,x.matched):[]:x.matched,S=x.score+(w.boost||0);if(i(new $V(w,f.source,k,S)),typeof w.section=="object"&&w.section.rank==="dynamic"){let{name:C}=w.section;s||(s=Object.create(null)),s[C]=Math.max(S,s[C]||-1e9)}}}}if(r){let f=Object.create(null),m=0,p=(x,y)=>(x.rank==="dynamic"&&y.rank==="dynamic"?s[y.name]-s[x.name]:0)||(typeof x.rank=="number"?x.rank:1e9)-(typeof y.rank=="number"?y.rank:1e9)||(x.name<y.name?-1:1);for(let x of r.sort(p))m-=1e5,f[x.name]=m;for(let x of n){let{section:y}=x.completion;y&&(x.score+=f[typeof y=="string"?y:y.name])}}let a=[],c=null,d=o.compareCompletions;for(let f of n.sort((m,p)=>p.score-m.score||d(m.completion,p.completion))){let m=f.completion;!c||c.label!=m.label||c.detail!=m.detail||c.type!=null&&m.type!=null&&c.type!=m.type||c.apply!=m.apply||c.boost!=m.boost?a.push(f):VV(f.completion)>VV(c)&&(a[a.length-1]=f),c=f.completion}return a}class Lp{constructor(e,n,r,s,i,o){this.options=e,this.attrs=n,this.tooltip=r,this.timestamp=s,this.selected=i,this.disabled=o}setSelected(e,n){return e==this.selected||e>=this.options.length?this:new Lp(this.options,HV(n,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,n,r,s,i,o){if(s&&!o&&e.some(d=>d.isPending))return s.setDisabled();let a=BDe(e,n);if(!a.length)return s&&e.some(d=>d.isPending)?s.setDisabled():null;let c=n.facet(As).selectOnOpen?0:-1;if(s&&s.selected!=c&&s.selected!=-1){let d=s.options[s.selected].completion;for(let f=0;f<a.length;f++)if(a[f].completion==d){c=f;break}}return new Lp(a,HV(r,c),{pos:e.reduce((d,f)=>f.hasResult()?Math.min(d,f.from):d,1e8),create:KDe,above:i.aboveCursor},s?s.timestamp:Date.now(),c,!1)}map(e){return new Lp(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Lp(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class zk{constructor(e,n,r){this.active=e,this.id=n,this.open=r}static start(){return new zk(UDe,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:n}=e,r=n.facet(As),i=(r.override||n.languageDataAt("autocomplete",_h(n)).map(RDe)).map(c=>(this.active.find(f=>f.source==c)||new ca(c,this.active.some(f=>f.state!=0)?1:0)).update(e,r));i.length==this.active.length&&i.every((c,d)=>c==this.active[d])&&(i=this.active);let o=this.open,a=e.effects.some(c=>c.is(D9));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||i.some(c=>c.hasResult()&&e.changes.touchesRange(c.from,c.to))||!zDe(i,this.active)||a?o=Lp.build(i,n,this.id,o,r,a):o&&o.disabled&&!i.some(c=>c.isPending)&&(o=null),!o&&i.every(c=>!c.isPending)&&i.some(c=>c.hasResult())&&(i=i.map(c=>c.hasResult()?new ca(c.source,0):c));for(let c of e.effects)c.is(Yre)&&(o=o&&o.setSelected(c.value,this.id));return i==this.active&&o==this.open?this:new zk(i,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?VDe:HDe}}function zDe(t,e){if(t==e)return!0;for(let n=0,r=0;;){for(;n<t.length&&!t[n].hasResult();)n++;for(;r<e.length&&!e[r].hasResult();)r++;let s=n==t.length,i=r==e.length;if(s||i)return s==i;if(t[n++].result!=e[r++].result)return!1}}const VDe={"aria-autocomplete":"list"},HDe={};function HV(t,e){let n={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":t};return e>-1&&(n["aria-activedescendant"]=t+"-"+e),n}const UDe=[];function Jre(t,e){if(t.isUserEvent("input.complete")){let r=t.annotation(I9);if(r&&e.activateOnCompletion(r))return 12}let n=t.isUserEvent("input.type");return n&&e.activateOnTyping?5:n?1:t.isUserEvent("delete.backward")?2:t.selection?8:t.docChanged?16:0}class ca{constructor(e,n,r=!1){this.source=e,this.state=n,this.explicit=r}hasResult(){return!1}get isPending(){return this.state==1}update(e,n){let r=Jre(e,n),s=this;(r&8||r&16&&this.touches(e))&&(s=new ca(s.source,0)),r&4&&s.state==0&&(s=new ca(this.source,1)),s=s.updateFor(e,r);for(let i of e.effects)if(i.is(Bk))s=new ca(s.source,1,i.value);else if(i.is(Sb))s=new ca(s.source,0);else if(i.is(D9))for(let o of i.value)o.source==s.source&&(s=o);return s}updateFor(e,n){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(_h(e.state))}}class Xp extends ca{constructor(e,n,r,s,i,o){super(e,3,n),this.limit=r,this.result=s,this.from=i,this.to=o}hasResult(){return!0}updateFor(e,n){var r;if(!(n&3))return this.map(e.changes);let s=this.result;s.map&&!e.changes.empty&&(s=s.map(s,e.changes));let i=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),a=_h(e.state);if(a>o||!s||n&2&&(_h(e.startState)==this.from||a<this.limit))return new ca(this.source,n&4?1:0);let c=e.changes.mapPos(this.limit);return qDe(s.validFor,e.state,i,o)?new Xp(this.source,this.explicit,c,s,i,o):s.update&&(s=s.update(s,i,o,new Wre(e.state,a,!1)))?new Xp(this.source,this.explicit,c,s,s.from,(r=s.to)!==null&&r!==void 0?r:_h(e.state)):new ca(this.source,1,this.explicit)}map(e){return e.empty?this:(this.result.map?this.result.map(this.result,e):this.result)?new Xp(this.source,this.explicit,e.mapPos(this.limit),this.result,e.mapPos(this.from),e.mapPos(this.to,1)):new ca(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}function qDe(t,e,n,r){if(!t)return!1;let s=e.sliceDoc(n,r);return typeof t=="function"?t(s,n,r,e):Gre(t,!0).test(s)}const D9=zt.define({map(t,e){return t.map(n=>n.map(e))}}),Yre=zt.define(),Ji=Is.define({create(){return zk.start()},update(t,e){return t.update(e)},provide:t=>[k9.from(t,e=>e.tooltip),at.contentAttributes.from(t,e=>e.attrs)]});function L9(t,e){const n=e.completion.apply||e.completion.label;let r=t.state.field(Ji).active.find(s=>s.source==e.source);return r instanceof Xp?(typeof n=="string"?t.dispatch({...MDe(t.state,n,r.from,r.to),annotations:I9.of(e.completion)}):n(t,e.completion,r.from,r.to),!0):!1}const KDe=FDe(Ji,L9);function nC(t,e="option"){return n=>{let r=n.state.field(Ji,!1);if(!r||!r.open||r.open.disabled||Date.now()-r.open.timestamp<n.state.facet(As).interactionDelay)return!1;let s=1,i;e=="page"&&(i=dre(n,r.open.tooltip))&&(s=Math.max(2,Math.floor(i.dom.offsetHeight/i.dom.querySelector("li").offsetHeight)-1));let{length:o}=r.open.options,a=r.open.selected>-1?r.open.selected+s*(t?1:-1):t?0:o-1;return a<0?a=e=="page"?0:o-1:a>=o&&(a=e=="page"?o-1:0),n.dispatch({effects:Yre.of(a)}),!0}}const WDe=t=>{let e=t.state.field(Ji,!1);return t.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<t.state.facet(As).interactionDelay?!1:L9(t,e.open.options[e.open.selected])},nA=t=>t.state.field(Ji,!1)?(t.dispatch({effects:Bk.of(!0)}),!0):!1,GDe=t=>{let e=t.state.field(Ji,!1);return!e||!e.active.some(n=>n.state!=0)?!1:(t.dispatch({effects:Sb.of(null)}),!0)};class JDe{constructor(e,n){this.active=e,this.context=n,this.time=Date.now(),this.updates=[],this.done=void 0}}const YDe=50,ZDe=1e3,QDe=us.fromClass(class{constructor(t){this.view=t,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of t.state.field(Ji).active)e.isPending&&this.startQuery(e)}update(t){let e=t.state.field(Ji),n=t.state.facet(As);if(!t.selectionSet&&!t.docChanged&&t.startState.field(Ji)==e)return;let r=t.transactions.some(i=>{let o=Jre(i,n);return o&8||(i.selection||i.docChanged)&&!(o&3)});for(let i=0;i<this.running.length;i++){let o=this.running[i];if(r||o.context.abortOnDocChange&&t.docChanged||o.updates.length+t.transactions.length>YDe&&Date.now()-o.time>ZDe){for(let a of o.context.abortListeners)try{a()}catch(c){Xi(this.view.state,c)}o.context.abortListeners=null,this.running.splice(i--,1)}else o.updates.push(...t.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),t.transactions.some(i=>i.effects.some(o=>o.is(Bk)))&&(this.pendingStart=!0);let s=this.pendingStart?50:n.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(i=>i.isPending&&!this.running.some(o=>o.active.source==i.source))?setTimeout(()=>this.startUpdate(),s):-1,this.composing!=0)for(let i of t.transactions)i.isUserEvent("input.type")?this.composing=2:this.composing==2&&i.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:t}=this.view,e=t.field(Ji);for(let n of e.active)n.isPending&&!this.running.some(r=>r.active.source==n.source)&&this.startQuery(n);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(As).updateSyncTime))}startQuery(t){let{state:e}=this.view,n=_h(e),r=new Wre(e,n,t.explicit,this.view),s=new JDe(t,r);this.running.push(s),Promise.resolve(t.source(r)).then(i=>{s.context.aborted||(s.done=i||null,this.scheduleAccept())},i=>{this.view.dispatch({effects:Sb.of(null)}),Xi(this.view.state,i)})}scheduleAccept(){this.running.every(t=>t.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(As).updateSyncTime))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],n=this.view.state.facet(As),r=this.view.state.field(Ji);for(let s=0;s<this.running.length;s++){let i=this.running[s];if(i.done===void 0)continue;if(this.running.splice(s--,1),i.done){let a=_h(i.updates.length?i.updates[0].startState:this.view.state),c=Math.min(a,i.done.from+(i.active.explicit?0:1)),d=new Xp(i.active.source,i.active.explicit,c,i.done,i.done.from,(t=i.done.to)!==null&&t!==void 0?t:a);for(let f of i.updates)d=d.update(f,n);if(d.hasResult()){e.push(d);continue}}let o=r.active.find(a=>a.source==i.active.source);if(o&&o.isPending)if(i.done==null){let a=new ca(i.active.source,0);for(let c of i.updates)a=a.update(c,n);a.isPending||e.push(a)}else this.startQuery(o)}(e.length||r.open&&r.open.disabled)&&this.view.dispatch({effects:D9.of(e)})}},{eventHandlers:{blur(t){let e=this.view.state.field(Ji,!1);if(e&&e.tooltip&&this.view.state.facet(As).closeOnBlur){let n=e.open&&dre(this.view,e.open.tooltip);(!n||!n.dom.contains(t.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Sb.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:Bk.of(!1)}),20),this.composing=0}}}),XDe=typeof navigator=="object"&&/Win/.test(navigator.platform),e8e=Sf.highest(at.domEventHandlers({keydown(t,e){let n=e.state.field(Ji,!1);if(!n||!n.open||n.open.disabled||n.open.selected<0||t.key.length>1||t.ctrlKey&&!(XDe&&t.altKey)||t.metaKey)return!1;let r=n.open.options[n.open.selected],s=n.active.find(o=>o.source==r.source),i=r.completion.commitCharacters||s.result.commitCharacters;return i&&i.indexOf(t.key)>-1&&L9(e,r),!1}})),Zre=at.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 t8e{constructor(e,n,r,s){this.field=e,this.line=n,this.from=r,this.to=s}}class P9{constructor(e,n,r){this.field=e,this.from=n,this.to=r}map(e){let n=e.mapPos(this.from,-1,qs.TrackDel),r=e.mapPos(this.to,1,qs.TrackDel);return n==null||r==null?null:new P9(this.field,n,r)}}class F9{constructor(e,n){this.lines=e,this.fieldPositions=n}instantiate(e,n){let r=[],s=[n],i=e.doc.lineAt(n),o=/^\s*/.exec(i.text)[0];for(let c of this.lines){if(r.length){let d=o,f=/^\t*/.exec(c)[0].length;for(let m=0;m<f;m++)d+=e.facet(W_);s.push(n+d.length-f),c=d+c.slice(f)}r.push(c),n+=c.length+1}let a=this.fieldPositions.map(c=>new P9(c.field,s[c.line]+c.from,s[c.line]+c.to));return{text:r,ranges:a}}static parse(e){let n=[],r=[],s=[],i;for(let o of e.split(/\r\n?|\n/)){for(;i=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let a=i[1]?+i[1]:null,c=i[2]||i[3]||"",d=-1,f=c.replace(/\\[{}]/g,m=>m[1]);for(let m=0;m<n.length;m++)(a!=null?n[m].seq==a:f&&n[m].name==f)&&(d=m);if(d<0){let m=0;for(;m<n.length&&(a==null||n[m].seq!=null&&n[m].seq<a);)m++;n.splice(m,0,{seq:a,name:f}),d=m;for(let p of s)p.field>=d&&p.field++}for(let m of s)if(m.line==r.length&&m.from>i.index){let p=i[2]?3+(i[1]||"").length:2;m.from-=p,m.to-=p}s.push(new t8e(d,r.length,i.index,i.index+f.length)),o=o.slice(0,i.index)+c+o.slice(i.index+i[0].length)}o=o.replace(/\\([{}])/g,(a,c,d)=>{for(let f of s)f.line==r.length&&f.from>d&&(f.from--,f.to--);return c}),r.push(o)}return new F9(r,s)}}let n8e=Mt.widget({widget:new class extends cc{toDOM(){let t=document.createElement("span");return t.className="cm-snippetFieldPosition",t}ignoreEvent(){return!1}}}),r8e=Mt.mark({class:"cm-snippetField"});class jx{constructor(e,n){this.ranges=e,this.active=n,this.deco=Mt.set(e.map(r=>(r.from==r.to?n8e:r8e).range(r.from,r.to)),!0)}map(e){let n=[];for(let r of this.ranges){let s=r.map(e);if(!s)return null;n.push(s)}return new jx(n,this.active)}selectionInsideField(e){return e.ranges.every(n=>this.ranges.some(r=>r.field==this.active&&r.from<=n.from&&r.to>=n.to))}}const Hv=zt.define({map(t,e){return t&&t.map(e)}}),s8e=zt.define(),_b=Is.define({create(){return null},update(t,e){for(let n of e.effects){if(n.is(Hv))return n.value;if(n.is(s8e)&&t)return new jx(t.ranges,n.value)}return t&&e.docChanged&&(t=t.map(e.changes)),t&&e.selection&&!t.selectionInsideField(e.selection)&&(t=null),t},provide:t=>at.decorations.from(t,e=>e?e.deco:Mt.none)});function $9(t,e){return De.create(t.filter(n=>n.field==e).map(n=>De.range(n.from,n.to)))}function i8e(t){let e=F9.parse(t);return(n,r,s,i)=>{let{text:o,ranges:a}=e.instantiate(n.state,s),{main:c}=n.state.selection,d={changes:{from:s,to:i==c.from?c.to:i,insert:Pn.of(o)},scrollIntoView:!0,annotations:r?[I9.of(r),is.userEvent.of("input.complete")]:void 0};if(a.length&&(d.selection=$9(a,0)),a.some(f=>f.field>0)){let f=new jx(a,0),m=d.effects=[Hv.of(f)];n.state.field(_b,!1)===void 0&&m.push(zt.appendConfig.of([_b,u8e,d8e,Zre]))}n.dispatch(n.state.update(d))}}function Qre(t){return({state:e,dispatch:n})=>{let r=e.field(_b,!1);if(!r||t<0&&r.active==0)return!1;let s=r.active+t,i=t>0&&!r.ranges.some(o=>o.field==s+t);return n(e.update({selection:$9(r.ranges,s),effects:Hv.of(i?null:new jx(r.ranges,s)),scrollIntoView:!0})),!0}}const o8e=({state:t,dispatch:e})=>t.field(_b,!1)?(e(t.update({effects:Hv.of(null)})),!0):!1,a8e=Qre(1),l8e=Qre(-1),c8e=[{key:"Tab",run:a8e,shift:l8e},{key:"Escape",run:o8e}],UV=ut.define({combine(t){return t.length?t[0]:c8e}}),u8e=Sf.highest($v.compute([UV],t=>t.facet(UV)));function $Ke(t,e){return{...e,apply:i8e(t)}}const d8e=at.domEventHandlers({mousedown(t,e){let n=e.state.field(_b,!1),r;if(!n||(r=e.posAtCoords({x:t.clientX,y:t.clientY}))==null)return!1;let s=n.ranges.find(i=>i.from<=r&&i.to>=r);return!s||s.field==n.active?!1:(e.dispatch({selection:$9(n.ranges,s.field),effects:Hv.of(n.ranges.some(i=>i.field>s.field)?new jx(n.ranges,s.field):null),scrollIntoView:!0}),!0)}}),Nb={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},lh=zt.define({map(t,e){let n=e.mapPos(t,-1,qs.TrackAfter);return n??void 0}}),B9=new class extends sf{};B9.startSide=1;B9.endSide=-1;const Xre=Is.define({create(){return un.empty},update(t,e){if(t=t.map(e.changes),e.selection){let n=e.state.doc.lineAt(e.selection.main.head);t=t.update({filter:r=>r>=n.from&&r<=n.to})}for(let n of e.effects)n.is(lh)&&(t=t.update({add:[B9.range(n.value,n.value+1)]}));return t}});function f8e(){return[m8e,Xre]}const rA="()[]{}<>«»»«[]{}";function ese(t){for(let e=0;e<rA.length;e+=2)if(rA.charCodeAt(e)==t)return rA.charAt(e+1);return o9(t<128?t:t+1)}function tse(t,e){return t.languageDataAt("closeBrackets",e)[0]||Nb}const h8e=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),m8e=at.inputHandler.of((t,e,n,r)=>{if((h8e?t.composing:t.compositionStarted)||t.state.readOnly)return!1;let s=t.state.selection.main;if(r.length>2||r.length==2&&Rl(Gi(r,0))==1||e!=s.from||n!=s.to)return!1;let i=x8e(t.state,r);return i?(t.dispatch(i),!0):!1}),p8e=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let r=tse(t,t.selection.main.head).brackets||Nb.brackets,s=null,i=t.changeByRange(o=>{if(o.empty){let a=y8e(t.doc,o.head);for(let c of r)if(c==a&&Y_(t.doc,o.head)==ese(Gi(c,0)))return{changes:{from:o.head-c.length,to:o.head+c.length},range:De.cursor(o.head-c.length)}}return{range:s=o}});return s||e(t.update(i,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},g8e=[{key:"Backspace",run:p8e}];function x8e(t,e){let n=tse(t,t.selection.main.head),r=n.brackets||Nb.brackets;for(let s of r){let i=ese(Gi(s,0));if(e==s)return i==s?w8e(t,s,r.indexOf(s+s+s)>-1,n):b8e(t,s,i,n.before||Nb.before);if(e==i&&nse(t,t.selection.main.from))return v8e(t,s,i)}return null}function nse(t,e){let n=!1;return t.field(Xre).between(0,t.doc.length,r=>{r==e&&(n=!0)}),n}function Y_(t,e){let n=t.sliceString(e,e+2);return n.slice(0,Rl(Gi(n,0)))}function y8e(t,e){let n=t.sliceString(e-2,e);return Rl(Gi(n,0))==n.length?n:n.slice(1)}function b8e(t,e,n,r){let s=null,i=t.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:n,from:o.to}],effects:lh.of(o.to+e.length),range:De.range(o.anchor+e.length,o.head+e.length)};let a=Y_(t.doc,o.head);return!a||/\s/.test(a)||r.indexOf(a)>-1?{changes:{insert:e+n,from:o.head},effects:lh.of(o.head+e.length),range:De.cursor(o.head+e.length)}:{range:s=o}});return s?null:t.update(i,{scrollIntoView:!0,userEvent:"input.type"})}function v8e(t,e,n){let r=null,s=t.changeByRange(i=>i.empty&&Y_(t.doc,i.head)==n?{changes:{from:i.head,to:i.head+n.length,insert:n},range:De.cursor(i.head+n.length)}:r={range:i});return r?null:t.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function w8e(t,e,n,r){let s=r.stringPrefixes||Nb.stringPrefixes,i=null,o=t.changeByRange(a=>{if(!a.empty)return{changes:[{insert:e,from:a.from},{insert:e,from:a.to}],effects:lh.of(a.to+e.length),range:De.range(a.anchor+e.length,a.head+e.length)};let c=a.head,d=Y_(t.doc,c),f;if(d==e){if(qV(t,c))return{changes:{insert:e+e,from:c},effects:lh.of(c+e.length),range:De.cursor(c+e.length)};if(nse(t,c)){let p=n&&t.sliceDoc(c,c+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:c,to:c+p.length,insert:p},range:De.cursor(c+p.length)}}}else{if(n&&t.sliceDoc(c-2*e.length,c)==e+e&&(f=KV(t,c-2*e.length,s))>-1&&qV(t,f))return{changes:{insert:e+e+e+e,from:c},effects:lh.of(c+e.length),range:De.cursor(c+e.length)};if(t.charCategorizer(c)(d)!=_r.Word&&KV(t,c,s)>-1&&!C8e(t,c,e,s))return{changes:{insert:e+e,from:c},effects:lh.of(c+e.length),range:De.cursor(c+e.length)}}return{range:i=a}});return i?null:t.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function qV(t,e){let n=Ws(t).resolveInner(e+1);return n.parent&&n.from==e}function C8e(t,e,n,r){let s=Ws(t).resolveInner(e,-1),i=r.reduce((o,a)=>Math.max(o,a.length),0);for(let o=0;o<5;o++){let a=t.sliceDoc(s.from,Math.min(s.to,s.from+n.length+i)),c=a.indexOf(n);if(!c||c>-1&&r.indexOf(a.slice(0,c))>-1){let f=s.firstChild;for(;f&&f.from==s.from&&f.to-f.from>n.length+c;){if(t.sliceDoc(f.to-n.length,f.to)==n)return!1;f=f.firstChild}return!0}let d=s.to==e&&s.parent;if(!d)break;s=d}return!1}function KV(t,e,n){let r=t.charCategorizer(e);if(r(t.sliceDoc(e-1,e))!=_r.Word)return e;for(let s of n){let i=e-s.length;if(t.sliceDoc(i,e)==s&&r(t.sliceDoc(i-1,i))!=_r.Word)return i}return-1}function k8e(t={}){return[e8e,Ji,As.of(t),QDe,S8e,Zre]}const rse=[{key:"Ctrl-Space",run:nA},{mac:"Alt-`",run:nA},{mac:"Alt-i",run:nA},{key:"Escape",run:GDe},{key:"ArrowDown",run:nC(!0)},{key:"ArrowUp",run:nC(!1)},{key:"PageDown",run:nC(!0,"page")},{key:"PageUp",run:nC(!1,"page")},{key:"Enter",run:WDe}],S8e=Sf.highest($v.computeN([As],t=>t.facet(As).defaultKeymap?[rse]:[])),_8e=t=>{let{state:e}=t,n=e.doc.lineAt(e.selection.main.from),r=V9(t.state,n.from);return r.line?N8e(t):r.block?j8e(t):!1};function z9(t,e){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let s=t(e,n);return s?(r(n.update(s)),!0):!1}}const N8e=z9(M8e,0),E8e=z9(sse,0),j8e=z9((t,e)=>sse(t,e,T8e(e)),0);function V9(t,e){let n=t.languageDataAt("commentTokens",e,1);return n.length?n[0]:{}}const B0=50;function A8e(t,{open:e,close:n},r,s){let i=t.sliceDoc(r-B0,r),o=t.sliceDoc(s,s+B0),a=/\s*$/.exec(i)[0].length,c=/^\s*/.exec(o)[0].length,d=i.length-a;if(i.slice(d-e.length,d)==e&&o.slice(c,c+n.length)==n)return{open:{pos:r-a,margin:a&&1},close:{pos:s+c,margin:c&&1}};let f,m;s-r<=2*B0?f=m=t.sliceDoc(r,s):(f=t.sliceDoc(r,r+B0),m=t.sliceDoc(s-B0,s));let p=/^\s*/.exec(f)[0].length,x=/\s*$/.exec(m)[0].length,y=m.length-x-n.length;return f.slice(p,p+e.length)==e&&m.slice(y,y+n.length)==n?{open:{pos:r+p+e.length,margin:/\s/.test(f.charAt(p+e.length))?1:0},close:{pos:s-x-n.length,margin:/\s/.test(m.charAt(y-1))?1:0}}:null}function T8e(t){let e=[];for(let n of t.selection.ranges){let r=t.doc.lineAt(n.from),s=n.to<=r.to?r:t.doc.lineAt(n.to);s.from>r.from&&s.from==n.to&&(s=n.to==r.to+1?r:t.doc.lineAt(n.to-1));let i=e.length-1;i>=0&&e[i].to>r.from?e[i].to=s.to:e.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:s.to})}return e}function sse(t,e,n=e.selection.ranges){let r=n.map(i=>V9(e,i.from).block);if(!r.every(i=>i))return null;let s=n.map((i,o)=>A8e(e,r[o],i.from,i.to));if(t!=2&&!s.every(i=>i))return{changes:e.changes(n.map((i,o)=>s[o]?[]:[{from:i.from,insert:r[o].open+" "},{from:i.to,insert:" "+r[o].close}]))};if(t!=1&&s.some(i=>i)){let i=[];for(let o=0,a;o<s.length;o++)if(a=s[o]){let c=r[o],{open:d,close:f}=a;i.push({from:d.pos-c.open.length,to:d.pos+d.margin},{from:f.pos-f.margin,to:f.pos+c.close.length})}return{changes:i}}return null}function M8e(t,e,n=e.selection.ranges){let r=[],s=-1;e:for(let{from:i,to:o}of n){let a=r.length,c=1e9,d;for(let f=i;f<=o;){let m=e.doc.lineAt(f);if(d==null&&(d=V9(e,m.from).line,!d))continue e;if(m.from>s&&(i==o||o>m.from)){s=m.from;let p=/^\s*/.exec(m.text)[0].length,x=p==m.length,y=m.text.slice(p,p+d.length)==d?p:-1;p<m.text.length&&p<c&&(c=p),r.push({line:m,comment:y,token:d,indent:p,empty:x,single:!1})}f=m.to+1}if(c<1e9)for(let f=a;f<r.length;f++)r[f].indent<r[f].line.text.length&&(r[f].indent=c);r.length==a+1&&(r[a].single=!0)}if(t!=2&&r.some(i=>i.comment<0&&(!i.empty||i.single))){let i=[];for(let{line:a,token:c,indent:d,empty:f,single:m}of r)(m||!f)&&i.push({from:a.from+d,insert:c+" "});let o=e.changes(i);return{changes:o,selection:e.selection.map(o,1)}}else if(t!=1&&r.some(i=>i.comment>=0)){let i=[];for(let{line:o,comment:a,token:c}of r)if(a>=0){let d=o.from+a,f=d+c.length;o.text[f-o.from]==" "&&f++,i.push({from:d,to:f})}return{changes:i}}return null}const rM=Pu.define(),R8e=Pu.define(),O8e=ut.define(),ise=ut.define({combine(t){return lc(t,{minDepth:100,newGroupDelay:500,joinToEvent:(e,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,n)=>(r,s)=>e(r,s)||n(r,s)})}}),ose=Is.define({create(){return $l.empty},update(t,e){let n=e.state.facet(ise),r=e.annotation(rM);if(r){let c=eo.fromTransaction(e,r.selection),d=r.side,f=d==0?t.undone:t.done;return c?f=Vk(f,f.length,n.minDepth,c):f=cse(f,e.startState.selection),new $l(d==0?r.rest:f,d==0?f:r.rest)}let s=e.annotation(R8e);if((s=="full"||s=="before")&&(t=t.isolate()),e.annotation(is.addToHistory)===!1)return e.changes.empty?t:t.addMapping(e.changes.desc);let i=eo.fromTransaction(e),o=e.annotation(is.time),a=e.annotation(is.userEvent);return i?t=t.addChanges(i,o,a,n,e):e.selection&&(t=t.addSelection(e.startState.selection,o,a,n.newGroupDelay)),(s=="full"||s=="after")&&(t=t.isolate()),t},toJSON(t){return{done:t.done.map(e=>e.toJSON()),undone:t.undone.map(e=>e.toJSON())}},fromJSON(t){return new $l(t.done.map(eo.fromJSON),t.undone.map(eo.fromJSON))}});function I8e(t={}){return[ose,ise.of(t),at.domEventHandlers({beforeinput(e,n){let r=e.inputType=="historyUndo"?ase:e.inputType=="historyRedo"?sM:null;return r?(e.preventDefault(),r(n)):!1}})]}function Z_(t,e){return function({state:n,dispatch:r}){if(!e&&n.readOnly)return!1;let s=n.field(ose,!1);if(!s)return!1;let i=s.pop(t,n,e);return i?(r(i),!0):!1}}const ase=Z_(0,!1),sM=Z_(1,!1),D8e=Z_(0,!0),L8e=Z_(1,!0);class eo{constructor(e,n,r,s,i){this.changes=e,this.effects=n,this.mapped=r,this.startSelection=s,this.selectionsAfter=i}setSelAfter(e){return new eo(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,n,r;return{changes:(e=this.changes)===null||e===void 0?void 0:e.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(s=>s.toJSON())}}static fromJSON(e){return new eo(e.changes&&ps.fromJSON(e.changes),[],e.mapped&&Kl.fromJSON(e.mapped),e.startSelection&&De.fromJSON(e.startSelection),e.selectionsAfter.map(De.fromJSON))}static fromTransaction(e,n){let r=ua;for(let s of e.startState.facet(O8e)){let i=s(e);i.length&&(r=r.concat(i))}return!r.length&&e.changes.empty?null:new eo(e.changes.invert(e.startState.doc),r,void 0,n||e.startState.selection,ua)}static selection(e){return new eo(void 0,ua,void 0,void 0,e)}}function Vk(t,e,n,r){let s=e+1>n+20?e-n-1:0,i=t.slice(s,e);return i.push(r),i}function P8e(t,e){let n=[],r=!1;return t.iterChangedRanges((s,i)=>n.push(s,i)),e.iterChangedRanges((s,i,o,a)=>{for(let c=0;c<n.length;){let d=n[c++],f=n[c++];a>=d&&o<=f&&(r=!0)}}),r}function F8e(t,e){return t.ranges.length==e.ranges.length&&t.ranges.filter((n,r)=>n.empty!=e.ranges[r].empty).length===0}function lse(t,e){return t.length?e.length?t.concat(e):t:e}const ua=[],$8e=200;function cse(t,e){if(t.length){let n=t[t.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-$8e));return r.length&&r[r.length-1].eq(e)?t:(r.push(e),Vk(t,t.length-1,1e9,n.setSelAfter(r)))}else return[eo.selection([e])]}function B8e(t){let e=t[t.length-1],n=t.slice();return n[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),n}function sA(t,e){if(!t.length)return t;let n=t.length,r=ua;for(;n;){let s=z8e(t[n-1],e,r);if(s.changes&&!s.changes.empty||s.effects.length){let i=t.slice(0,n);return i[n-1]=s,i}else e=s.mapped,n--,r=s.selectionsAfter}return r.length?[eo.selection(r)]:ua}function z8e(t,e,n){let r=lse(t.selectionsAfter.length?t.selectionsAfter.map(a=>a.map(e)):ua,n);if(!t.changes)return eo.selection(r);let s=t.changes.map(e),i=e.mapDesc(t.changes,!0),o=t.mapped?t.mapped.composeDesc(i):i;return new eo(s,zt.mapEffects(t.effects,e),o,t.startSelection.map(i),r)}const V8e=/^(input\.type|delete)($|\.)/;class $l{constructor(e,n,r=0,s=void 0){this.done=e,this.undone=n,this.prevTime=r,this.prevUserEvent=s}isolate(){return this.prevTime?new $l(this.done,this.undone):this}addChanges(e,n,r,s,i){let o=this.done,a=o[o.length-1];return a&&a.changes&&!a.changes.empty&&e.changes&&(!r||V8e.test(r))&&(!a.selectionsAfter.length&&n-this.prevTime<s.newGroupDelay&&s.joinToEvent(i,P8e(a.changes,e.changes))||r=="input.type.compose")?o=Vk(o,o.length-1,s.minDepth,new eo(e.changes.compose(a.changes),lse(zt.mapEffects(e.effects,a.changes),a.effects),a.mapped,a.startSelection,ua)):o=Vk(o,o.length,s.minDepth,e),new $l(o,ua,n,r)}addSelection(e,n,r,s){let i=this.done.length?this.done[this.done.length-1].selectionsAfter:ua;return i.length>0&&n-this.prevTime<s&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&F8e(i[i.length-1],e)?this:new $l(cse(this.done,e),this.undone,n,r)}addMapping(e){return new $l(sA(this.done,e),sA(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,n,r){let s=e==0?this.done:this.undone;if(s.length==0)return null;let i=s[s.length-1],o=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):n.selection);if(r&&i.selectionsAfter.length)return n.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:rM.of({side:e,rest:B8e(s),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(i.changes){let a=s.length==1?ua:s.slice(0,s.length-1);return i.mapped&&(a=sA(a,i.mapped)),n.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:rM.of({side:e,rest:a,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}$l.empty=new $l(ua,ua);const H8e=[{key:"Mod-z",run:ase,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:sM,preventDefault:!0},{linux:"Ctrl-Shift-z",run:sM,preventDefault:!0},{key:"Mod-u",run:D8e,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:L8e,preventDefault:!0}];function Ax(t,e){return De.create(t.ranges.map(e),t.mainIndex)}function cl(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function ul({state:t,dispatch:e},n){let r=Ax(t.selection,n);return r.eq(t.selection,!0)?!1:(e(cl(t,r)),!0)}function Q_(t,e){return De.cursor(e?t.to:t.from)}function use(t,e){return ul(t,n=>n.empty?t.moveByChar(n,e):Q_(n,e))}function mi(t){return t.textDirectionAt(t.state.selection.main.head)==lr.LTR}const dse=t=>use(t,!mi(t)),fse=t=>use(t,mi(t));function hse(t,e){return ul(t,n=>n.empty?t.moveByGroup(n,e):Q_(n,e))}const U8e=t=>hse(t,!mi(t)),q8e=t=>hse(t,mi(t));function K8e(t,e,n){if(e.type.prop(n))return!0;let r=e.to-e.from;return r&&(r>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function X_(t,e,n){let r=Ws(t).resolveInner(e.head),s=n?sn.closedBy:sn.openedBy;for(let c=e.head;;){let d=n?r.childAfter(c):r.childBefore(c);if(!d)break;K8e(t,d,s)?r=d:c=n?d.to:d.from}let i=r.type.prop(s),o,a;return i&&(o=n?Fl(t,r.from,1):Fl(t,r.to,-1))&&o.matched?a=n?o.end.to:o.end.from:a=n?r.to:r.from,De.cursor(a,n?-1:1)}const W8e=t=>ul(t,e=>X_(t.state,e,!mi(t))),G8e=t=>ul(t,e=>X_(t.state,e,mi(t)));function mse(t,e){return ul(t,n=>{if(!n.empty)return Q_(n,e);let r=t.moveVertically(n,e);return r.head!=n.head?r:t.moveToLineBoundary(n,e)})}const pse=t=>mse(t,!1),gse=t=>mse(t,!0);function xse(t){let e=t.scrollDOM.clientHeight<t.scrollDOM.scrollHeight-2,n=0,r=0,s;if(e){for(let i of t.state.facet(at.scrollMargins)){let o=i(t);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))}s=t.scrollDOM.clientHeight-n-r}else s=(t.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:e,height:Math.max(t.defaultLineHeight,s-5)}}function yse(t,e){let n=xse(t),{state:r}=t,s=Ax(r.selection,o=>o.empty?t.moveVertically(o,e,n.height):Q_(o,e));if(s.eq(r.selection))return!1;let i;if(n.selfScroll){let o=t.coordsAtPos(r.selection.main.head),a=t.scrollDOM.getBoundingClientRect(),c=a.top+n.marginTop,d=a.bottom-n.marginBottom;o&&o.top>c&&o.bottom<d&&(i=at.scrollIntoView(s.main.head,{y:"start",yMargin:o.top-c}))}return t.dispatch(cl(r,s),{effects:i}),!0}const WV=t=>yse(t,!1),iM=t=>yse(t,!0);function _f(t,e,n){let r=t.lineBlockAt(e.head),s=t.moveToLineBoundary(e,n);if(s.head==e.head&&s.head!=(n?r.to:r.from)&&(s=t.moveToLineBoundary(e,n,!1)),!n&&s.head==r.from&&r.length){let i=/^\s*/.exec(t.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;i&&e.head!=r.from+i&&(s=De.cursor(r.from+i))}return s}const J8e=t=>ul(t,e=>_f(t,e,!0)),Y8e=t=>ul(t,e=>_f(t,e,!1)),Z8e=t=>ul(t,e=>_f(t,e,!mi(t))),Q8e=t=>ul(t,e=>_f(t,e,mi(t))),X8e=t=>ul(t,e=>De.cursor(t.lineBlockAt(e.head).from,1)),eLe=t=>ul(t,e=>De.cursor(t.lineBlockAt(e.head).to,-1));function tLe(t,e,n){let r=!1,s=Ax(t.selection,i=>{let o=Fl(t,i.head,-1)||Fl(t,i.head,1)||i.head>0&&Fl(t,i.head-1,1)||i.head<t.doc.length&&Fl(t,i.head+1,-1);if(!o||!o.end)return i;r=!0;let a=o.start.from==i.head?o.end.to:o.end.from;return De.cursor(a)});return r?(e(cl(t,s)),!0):!1}const nLe=({state:t,dispatch:e})=>tLe(t,e);function _a(t,e){let n=Ax(t.state.selection,r=>{let s=e(r);return De.range(r.anchor,s.head,s.goalColumn,s.bidiLevel||void 0)});return n.eq(t.state.selection)?!1:(t.dispatch(cl(t.state,n)),!0)}function bse(t,e){return _a(t,n=>t.moveByChar(n,e))}const vse=t=>bse(t,!mi(t)),wse=t=>bse(t,mi(t));function Cse(t,e){return _a(t,n=>t.moveByGroup(n,e))}const rLe=t=>Cse(t,!mi(t)),sLe=t=>Cse(t,mi(t)),iLe=t=>_a(t,e=>X_(t.state,e,!mi(t))),oLe=t=>_a(t,e=>X_(t.state,e,mi(t)));function kse(t,e){return _a(t,n=>t.moveVertically(n,e))}const Sse=t=>kse(t,!1),_se=t=>kse(t,!0);function Nse(t,e){return _a(t,n=>t.moveVertically(n,e,xse(t).height))}const GV=t=>Nse(t,!1),JV=t=>Nse(t,!0),aLe=t=>_a(t,e=>_f(t,e,!0)),lLe=t=>_a(t,e=>_f(t,e,!1)),cLe=t=>_a(t,e=>_f(t,e,!mi(t))),uLe=t=>_a(t,e=>_f(t,e,mi(t))),dLe=t=>_a(t,e=>De.cursor(t.lineBlockAt(e.head).from)),fLe=t=>_a(t,e=>De.cursor(t.lineBlockAt(e.head).to)),YV=({state:t,dispatch:e})=>(e(cl(t,{anchor:0})),!0),ZV=({state:t,dispatch:e})=>(e(cl(t,{anchor:t.doc.length})),!0),QV=({state:t,dispatch:e})=>(e(cl(t,{anchor:t.selection.main.anchor,head:0})),!0),XV=({state:t,dispatch:e})=>(e(cl(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0),hLe=({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0),mLe=({state:t,dispatch:e})=>{let n=e5(t).map(({from:r,to:s})=>De.range(r,Math.min(s+1,t.doc.length)));return e(t.update({selection:De.create(n),userEvent:"select"})),!0},pLe=({state:t,dispatch:e})=>{let n=Ax(t.selection,r=>{let s=Ws(t),i=s.resolveStack(r.from,1);if(r.empty){let o=s.resolveStack(r.from,-1);o.node.from>=i.node.from&&o.node.to<=i.node.to&&(i=o)}for(let o=i;o;o=o.next){let{node:a}=o;if((a.from<r.from&&a.to>=r.to||a.to>r.to&&a.from<=r.from)&&o.next)return De.range(a.to,a.from)}return r});return n.eq(t.selection)?!1:(e(cl(t,n)),!0)};function Ese(t,e){let{state:n}=t,r=n.selection,s=n.selection.ranges.slice();for(let i of n.selection.ranges){let o=n.doc.lineAt(i.head);if(e?o.to<t.state.doc.length:o.from>0)for(let a=i;;){let c=t.moveVertically(a,e);if(c.head<o.from||c.head>o.to){s.some(d=>d.head==c.head)||s.push(c);break}else{if(c.head==a.head)break;a=c}}}return s.length==r.ranges.length?!1:(t.dispatch(cl(n,De.create(s,s.length-1))),!0)}const gLe=t=>Ese(t,!1),xLe=t=>Ese(t,!0),yLe=({state:t,dispatch:e})=>{let n=t.selection,r=null;return n.ranges.length>1?r=De.create([n.main]):n.main.empty||(r=De.create([De.cursor(n.main.head)])),r?(e(cl(t,r)),!0):!1};function Uv(t,e){if(t.state.readOnly)return!1;let n="delete.selection",{state:r}=t,s=r.changeByRange(i=>{let{from:o,to:a}=i;if(o==a){let c=e(i);c<o?(n="delete.backward",c=rC(t,c,!1)):c>o&&(n="delete.forward",c=rC(t,c,!0)),o=Math.min(o,c),a=Math.max(a,c)}else o=rC(t,o,!1),a=rC(t,a,!0);return o==a?{range:i}:{changes:{from:o,to:a},range:De.cursor(o,o<i.head?-1:1)}});return s.changes.empty?!1:(t.dispatch(r.update(s,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?at.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function rC(t,e,n){if(t instanceof at)for(let r of t.state.facet(at.atomicRanges).map(s=>s(t)))r.between(e,e,(s,i)=>{s<e&&i>e&&(e=n?i:s)});return e}const jse=(t,e,n)=>Uv(t,r=>{let s=r.from,{state:i}=t,o=i.doc.lineAt(s),a,c;if(n&&!e&&s>o.from&&s<o.from+200&&!/[^ \t]/.test(a=o.text.slice(0,s-o.from))){if(a[a.length-1]==" ")return s-1;let d=Ex(a,i.tabSize),f=d%rm(i)||rm(i);for(let m=0;m<f&&a[a.length-1-m]==" ";m++)s--;c=s}else c=Ms(o.text,s-o.from,e,e)+o.from,c==s&&o.number!=(e?i.doc.lines:1)?c+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,s-o.from))&&(c=Ms(o.text,c-o.from,!1,!1)+o.from);return c}),oM=t=>jse(t,!1,!0),Ase=t=>jse(t,!0,!1),Tse=(t,e)=>Uv(t,n=>{let r=n.head,{state:s}=t,i=s.doc.lineAt(r),o=s.charCategorizer(r);for(let a=null;;){if(r==(e?i.to:i.from)){r==n.head&&i.number!=(e?s.doc.lines:1)&&(r+=e?1:-1);break}let c=Ms(i.text,r-i.from,e)+i.from,d=i.text.slice(Math.min(r,c)-i.from,Math.max(r,c)-i.from),f=o(d);if(a!=null&&f!=a)break;(d!=" "||r!=n.head)&&(a=f),r=c}return r}),Mse=t=>Tse(t,!1),bLe=t=>Tse(t,!0),vLe=t=>Uv(t,e=>{let n=t.lineBlockAt(e.head).to;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)}),wLe=t=>Uv(t,e=>{let n=t.moveToLineBoundary(e,!1).head;return e.head>n?n:Math.max(0,e.head-1)}),CLe=t=>Uv(t,e=>{let n=t.moveToLineBoundary(e,!0).head;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)}),kLe=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:Pn.of(["",""])},range:De.cursor(r.from)}));return e(t.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},SLe=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(r=>{if(!r.empty||r.from==0||r.from==t.doc.length)return{range:r};let s=r.from,i=t.doc.lineAt(s),o=s==i.from?s-1:Ms(i.text,s-i.from,!1)+i.from,a=s==i.to?s+1:Ms(i.text,s-i.from,!0)+i.from;return{changes:{from:o,to:a,insert:t.doc.slice(s,a).append(t.doc.slice(o,s))},range:De.cursor(a)}});return n.changes.empty?!1:(e(t.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function e5(t){let e=[],n=-1;for(let r of t.selection.ranges){let s=t.doc.lineAt(r.from),i=t.doc.lineAt(r.to);if(!r.empty&&r.to==i.from&&(i=t.doc.lineAt(r.to-1)),n>=s.number){let o=e[e.length-1];o.to=i.to,o.ranges.push(r)}else e.push({from:s.from,to:i.to,ranges:[r]});n=i.number+1}return e}function Rse(t,e,n){if(t.readOnly)return!1;let r=[],s=[];for(let i of e5(t)){if(n?i.to==t.doc.length:i.from==0)continue;let o=t.doc.lineAt(n?i.to+1:i.from-1),a=o.length+1;if(n){r.push({from:i.to,to:o.to},{from:i.from,insert:o.text+t.lineBreak});for(let c of i.ranges)s.push(De.range(Math.min(t.doc.length,c.anchor+a),Math.min(t.doc.length,c.head+a)))}else{r.push({from:o.from,to:i.from},{from:i.to,insert:t.lineBreak+o.text});for(let c of i.ranges)s.push(De.range(c.anchor-a,c.head-a))}}return r.length?(e(t.update({changes:r,scrollIntoView:!0,selection:De.create(s,t.selection.mainIndex),userEvent:"move.line"})),!0):!1}const _Le=({state:t,dispatch:e})=>Rse(t,e,!1),NLe=({state:t,dispatch:e})=>Rse(t,e,!0);function Ose(t,e,n){if(t.readOnly)return!1;let r=[];for(let i of e5(t))n?r.push({from:i.from,insert:t.doc.slice(i.from,i.to)+t.lineBreak}):r.push({from:i.to,insert:t.lineBreak+t.doc.slice(i.from,i.to)});let s=t.changes(r);return e(t.update({changes:s,selection:t.selection.map(s,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const ELe=({state:t,dispatch:e})=>Ose(t,e,!1),jLe=({state:t,dispatch:e})=>Ose(t,e,!0),ALe=t=>{if(t.state.readOnly)return!1;let{state:e}=t,n=e.changes(e5(e).map(({from:s,to:i})=>(s>0?s--:i<e.doc.length&&i++,{from:s,to:i}))),r=Ax(e.selection,s=>{let i;if(t.lineWrapping){let o=t.lineBlockAt(s.head),a=t.coordsAtPos(s.head,s.assoc||1);a&&(i=o.bottom+t.documentTop-a.bottom+t.defaultLineHeight/2)}return t.moveVertically(s,!0,i)}).map(n);return t.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function TLe(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let n=Ws(t).resolveInner(e),r=n.childBefore(e),s=n.childAfter(e),i;return r&&s&&r.to<=e&&s.from>=e&&(i=r.type.prop(sn.closedBy))&&i.indexOf(s.name)>-1&&t.doc.lineAt(r.to).from==t.doc.lineAt(s.from).from&&!/\S/.test(t.sliceDoc(r.to,s.from))?{from:r.to,to:s.from}:null}const eH=Ise(!1),MLe=Ise(!0);function Ise(t){return({state:e,dispatch:n})=>{if(e.readOnly)return!1;let r=e.changeByRange(s=>{let{from:i,to:o}=s,a=e.doc.lineAt(i),c=!t&&i==o&&TLe(e,i);t&&(i=o=(o<=a.to?a:e.doc.lineAt(o)).to);let d=new G_(e,{simulateBreak:i,simulateDoubleBreak:!!c}),f=A9(d,i);for(f==null&&(f=Ex(/^\s*/.exec(e.doc.lineAt(i).text)[0],e.tabSize));o<a.to&&/\s/.test(a.text[o-a.from]);)o++;c?{from:i,to:o}=c:i>a.from&&i<a.from+100&&!/\S/.test(a.text.slice(0,i))&&(i=a.from);let m=["",Cb(e,f)];return c&&m.push(Cb(e,d.lineIndent(a.from,-1))),{changes:{from:i,to:o,insert:Pn.of(m)},range:De.cursor(i+1+m[1].length)}});return n(e.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function H9(t,e){let n=-1;return t.changeByRange(r=>{let s=[];for(let o=r.from;o<=r.to;){let a=t.doc.lineAt(o);a.number>n&&(r.empty||r.to>a.from)&&(e(a,s,r),n=a.number),o=a.to+1}let i=t.changes(s);return{changes:s,range:De.range(i.mapPos(r.anchor,1),i.mapPos(r.head,1))}})}const RLe=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=Object.create(null),r=new G_(t,{overrideIndentation:i=>{let o=n[i];return o??-1}}),s=H9(t,(i,o,a)=>{let c=A9(r,i.from);if(c==null)return;/\S/.test(i.text)||(c=0);let d=/^\s*/.exec(i.text)[0],f=Cb(t,c);(d!=f||a.from<i.from+d.length)&&(n[i.from]=c,o.push({from:i.from,to:i.from+d.length,insert:f}))});return s.changes.empty||e(t.update(s,{userEvent:"indent"})),!0},Dse=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(H9(t,(n,r)=>{r.push({from:n.from,insert:t.facet(W_)})}),{userEvent:"input.indent"})),!0),Lse=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(H9(t,(n,r)=>{let s=/^\s*/.exec(n.text)[0];if(!s)return;let i=Ex(s,t.tabSize),o=0,a=Cb(t,Math.max(0,i-rm(t)));for(;o<s.length&&o<a.length&&s.charCodeAt(o)==a.charCodeAt(o);)o++;r.push({from:n.from+o,to:n.from+s.length,insert:a.slice(o)})}),{userEvent:"delete.dedent"})),!0),OLe=t=>(t.setTabFocusMode(),!0),ILe=[{key:"Ctrl-b",run:dse,shift:vse,preventDefault:!0},{key:"Ctrl-f",run:fse,shift:wse},{key:"Ctrl-p",run:pse,shift:Sse},{key:"Ctrl-n",run:gse,shift:_se},{key:"Ctrl-a",run:X8e,shift:dLe},{key:"Ctrl-e",run:eLe,shift:fLe},{key:"Ctrl-d",run:Ase},{key:"Ctrl-h",run:oM},{key:"Ctrl-k",run:vLe},{key:"Ctrl-Alt-h",run:Mse},{key:"Ctrl-o",run:kLe},{key:"Ctrl-t",run:SLe},{key:"Ctrl-v",run:iM}],DLe=[{key:"ArrowLeft",run:dse,shift:vse,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:U8e,shift:rLe,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Z8e,shift:cLe,preventDefault:!0},{key:"ArrowRight",run:fse,shift:wse,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:q8e,shift:sLe,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Q8e,shift:uLe,preventDefault:!0},{key:"ArrowUp",run:pse,shift:Sse,preventDefault:!0},{mac:"Cmd-ArrowUp",run:YV,shift:QV},{mac:"Ctrl-ArrowUp",run:WV,shift:GV},{key:"ArrowDown",run:gse,shift:_se,preventDefault:!0},{mac:"Cmd-ArrowDown",run:ZV,shift:XV},{mac:"Ctrl-ArrowDown",run:iM,shift:JV},{key:"PageUp",run:WV,shift:GV},{key:"PageDown",run:iM,shift:JV},{key:"Home",run:Y8e,shift:lLe,preventDefault:!0},{key:"Mod-Home",run:YV,shift:QV},{key:"End",run:J8e,shift:aLe,preventDefault:!0},{key:"Mod-End",run:ZV,shift:XV},{key:"Enter",run:eH,shift:eH},{key:"Mod-a",run:hLe},{key:"Backspace",run:oM,shift:oM,preventDefault:!0},{key:"Delete",run:Ase,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Mse,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:bLe,preventDefault:!0},{mac:"Mod-Backspace",run:wLe,preventDefault:!0},{mac:"Mod-Delete",run:CLe,preventDefault:!0}].concat(ILe.map(t=>({mac:t.key,run:t.run,shift:t.shift}))),LLe=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:W8e,shift:iLe},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:G8e,shift:oLe},{key:"Alt-ArrowUp",run:_Le},{key:"Shift-Alt-ArrowUp",run:ELe},{key:"Alt-ArrowDown",run:NLe},{key:"Shift-Alt-ArrowDown",run:jLe},{key:"Mod-Alt-ArrowUp",run:gLe},{key:"Mod-Alt-ArrowDown",run:xLe},{key:"Escape",run:yLe},{key:"Mod-Enter",run:MLe},{key:"Alt-l",mac:"Ctrl-l",run:mLe},{key:"Mod-i",run:pLe,preventDefault:!0},{key:"Mod-[",run:Lse},{key:"Mod-]",run:Dse},{key:"Mod-Alt-\\",run:RLe},{key:"Shift-Mod-k",run:ALe},{key:"Shift-Mod-\\",run:nLe},{key:"Mod-/",run:_8e},{key:"Alt-A",run:E8e},{key:"Ctrl-m",mac:"Shift-Alt-m",run:OLe}].concat(DLe),PLe={key:"Tab",run:Dse,shift:Lse};function FLe(t,e,n,r){const s=Xl(Sr),i=No(yee),o=U.useRef(null),{lexicalNode:a}=m4(),c=U.useRef(!1),d=U.useRef(!1),f=U.useCallback(()=>{i({editorType:e,rootNode:a,editorRef:o.current})},[e,a,i]),m=U.useCallback(p=>{var x,y,w,k,S,C;if(p.key==="ArrowDown"){const _=(y=(x=o.current)==null?void 0:x.getCodemirror())==null?void 0:y.state;if(_){const E=_.doc.length,j=_.selection.ranges[0].to;E===j&&(c.current?(s==null||s.update(()=>{var R,T;const M=tr(t);M.getNextSibling()?((T=(R=o.current)==null?void 0:R.getCodemirror())==null||T.contentDOM.blur(),M.selectNext()):M.insertAfter(Mn())}),c.current=!1):c.current=!0)}}else if(p.key==="ArrowUp"){const _=(k=(w=o.current)==null?void 0:w.getCodemirror())==null?void 0:k.state;_&&_.selection.ranges[0].from===0&&(d.current?(s==null||s.update(()=>{var j,R;const T=tr(t);T.getPreviousSibling()&&((R=(j=o.current)==null?void 0:j.getCodemirror())==null||R.contentDOM.blur(),T.selectPrevious())}),d.current=!1):d.current=!0)}else if(p.key==="Enter")p.stopPropagation();else if(p.key==="Backspace"||p.key==="Delete"){const _=(C=(S=o.current)==null?void 0:S.getCodemirror())==null?void 0:C.state;(_==null?void 0:_.doc.length)===0&&(s==null||s.update(()=>{tr(t).remove()}))}},[s,t]);return U.useEffect(()=>{const p=o.current;return setTimeout(()=>{var x,y;(x=p==null?void 0:p.getCodemirror())==null||x.contentDOM.addEventListener("focus",f),(y=p==null?void 0:p.getCodemirror())==null||y.contentDOM.addEventListener("keydown",m)},300),()=>{var x,y;(x=p==null?void 0:p.getCodemirror())==null||x.contentDOM.removeEventListener("focus",f),(y=p==null?void 0:p.getCodemirror())==null||y.contentDOM.removeEventListener("keydown",m)}},[o,f,m,n]),U.useEffect(()=>{r.subscribe(()=>{var p,x;(x=(p=o.current)==null?void 0:p.getCodemirror())==null||x.focus(),f()})},[r,o,t,f]),o}function Ve(t){return new F6e(M9.define(t))}function hd(t){return Ae(()=>import("./index-D0EsfNYg.js"),__vite__mapDeps([0,1])).then(e=>e.sql({dialect:e[t]}))}const $Le=[_e.of({name:"C",extensions:["c","h","ino"],load(){return Ae(()=>import("./index-CP1BgxcV.js"),__vite__mapDeps([2,1])).then(t=>t.cpp())}}),_e.of({name:"C++",alias:["cpp"],extensions:["cpp","c++","cc","cxx","hpp","h++","hh","hxx"],load(){return Ae(()=>import("./index-CP1BgxcV.js"),__vite__mapDeps([2,1])).then(t=>t.cpp())}}),_e.of({name:"CQL",alias:["cassandra"],extensions:["cql"],load(){return hd("Cassandra")}}),_e.of({name:"CSS",extensions:["css"],load(){return Ae(()=>import("./index-Beb2ZlSv.js"),__vite__mapDeps([3,1])).then(t=>t.css())}}),_e.of({name:"Go",extensions:["go"],load(){return Ae(()=>import("./index-BD6My-aI.js"),__vite__mapDeps([4,1])).then(t=>t.go())}}),_e.of({name:"HTML",alias:["xhtml"],extensions:["html","htm","handlebars","hbs"],load(){return Ae(()=>import("./index-OkxoZoQy.js"),__vite__mapDeps([5,1,3,6])).then(t=>t.html())}}),_e.of({name:"Java",extensions:["java"],load(){return Ae(()=>import("./index--K1VLoF-.js"),__vite__mapDeps([7,1])).then(t=>t.java())}}),_e.of({name:"JavaScript",alias:["ecmascript","js","node"],extensions:["js","mjs","cjs"],load(){return Ae(()=>import("./index-BoAYxRAO.js"),__vite__mapDeps([6,1])).then(t=>t.javascript())}}),_e.of({name:"Jinja",extensions:["j2","jinja","jinja2"],load(){return Ae(()=>import("./index-CI56poQD.js"),__vite__mapDeps([8,5,1,3,6])).then(t=>t.jinja())}}),_e.of({name:"JSON",alias:["json5"],extensions:["json","map"],load(){return Ae(()=>import("./index-CqG5WZHq.js"),__vite__mapDeps([9,1])).then(t=>t.json())}}),_e.of({name:"JSX",extensions:["jsx"],load(){return Ae(()=>import("./index-BoAYxRAO.js"),__vite__mapDeps([6,1])).then(t=>t.javascript({jsx:!0}))}}),_e.of({name:"LESS",extensions:["less"],load(){return Ae(()=>import("./index-TFF7cXd7.js"),__vite__mapDeps([10,3,1])).then(t=>t.less())}}),_e.of({name:"Liquid",extensions:["liquid"],load(){return Ae(()=>import("./index-DiXE2gv-.js"),__vite__mapDeps([11,5,1,3,6])).then(t=>t.liquid())}}),_e.of({name:"MariaDB SQL",load(){return hd("MariaSQL")}}),_e.of({name:"Markdown",extensions:["md","markdown","mkd"],load(){return Ae(()=>import("./index-B-xuGUs-.js"),__vite__mapDeps([12,5,1,3,6])).then(t=>t.markdown())}}),_e.of({name:"MS SQL",load(){return hd("MSSQL")}}),_e.of({name:"MySQL",load(){return hd("MySQL")}}),_e.of({name:"PHP",extensions:["php","php3","php4","php5","php7","phtml"],load(){return Ae(()=>import("./index-DB5nKqAA.js"),__vite__mapDeps([13,1,5,3,6])).then(t=>t.php())}}),_e.of({name:"PLSQL",extensions:["pls"],load(){return hd("PLSQL")}}),_e.of({name:"PostgreSQL",load(){return hd("PostgreSQL")}}),_e.of({name:"Python",extensions:["BUILD","bzl","py","pyw"],filename:/^(BUCK|BUILD)$/,load(){return Ae(()=>import("./index-BfG2u5u0.js"),__vite__mapDeps([14,1])).then(t=>t.python())}}),_e.of({name:"Rust",extensions:["rs"],load(){return Ae(()=>import("./index-DZdNKByU.js"),__vite__mapDeps([15,1])).then(t=>t.rust())}}),_e.of({name:"Sass",extensions:["sass"],load(){return Ae(()=>import("./index-Cick_QSL.js"),__vite__mapDeps([16,1,3])).then(t=>t.sass({indented:!0}))}}),_e.of({name:"SCSS",extensions:["scss"],load(){return Ae(()=>import("./index-Cick_QSL.js"),__vite__mapDeps([16,1,3])).then(t=>t.sass())}}),_e.of({name:"SQL",extensions:["sql"],load(){return hd("StandardSQL")}}),_e.of({name:"SQLite",load(){return hd("SQLite")}}),_e.of({name:"TSX",extensions:["tsx"],load(){return Ae(()=>import("./index-BoAYxRAO.js"),__vite__mapDeps([6,1])).then(t=>t.javascript({jsx:!0,typescript:!0}))}}),_e.of({name:"TypeScript",alias:["ts"],extensions:["ts","mts","cts"],load(){return Ae(()=>import("./index-BoAYxRAO.js"),__vite__mapDeps([6,1])).then(t=>t.javascript({typescript:!0}))}}),_e.of({name:"WebAssembly",extensions:["wat","wast"],load(){return Ae(()=>import("./index-DujThSls.js"),__vite__mapDeps([17,1])).then(t=>t.wast())}}),_e.of({name:"XML",alias:["rss","wsdl","xsd"],extensions:["xml","xsl","xsd","svg"],load(){return Ae(()=>import("./index-0BSerEC2.js"),__vite__mapDeps([18,1])).then(t=>t.xml())}}),_e.of({name:"YAML",alias:["yml"],extensions:["yaml","yml"],load(){return Ae(()=>import("./index-C2-SE7P0.js"),__vite__mapDeps([19,1])).then(t=>t.yaml())}}),_e.of({name:"APL",extensions:["dyalog","apl"],load(){return Ae(()=>import("./apl-B4CMkyY2.js"),[]).then(t=>Ve(t.apl))}}),_e.of({name:"PGP",alias:["asciiarmor"],extensions:["asc","pgp","sig"],load(){return Ae(()=>import("./asciiarmor-Df11BRmG.js"),[]).then(t=>Ve(t.asciiArmor))}}),_e.of({name:"ASN.1",extensions:["asn","asn1"],load(){return Ae(()=>import("./asn1-EdZsLKOL.js"),[]).then(t=>Ve(t.asn1({})))}}),_e.of({name:"Asterisk",filename:/^extensions\.conf$/i,load(){return Ae(()=>import("./asterisk-B-8jnY81.js"),[]).then(t=>Ve(t.asterisk))}}),_e.of({name:"Brainfuck",extensions:["b","bf"],load(){return Ae(()=>import("./brainfuck-C4LP7Hcl.js"),[]).then(t=>Ve(t.brainfuck))}}),_e.of({name:"Cobol",extensions:["cob","cpy"],load(){return Ae(()=>import("./cobol-CWcv1MsR.js"),[]).then(t=>Ve(t.cobol))}}),_e.of({name:"C#",alias:["csharp","cs"],extensions:["cs"],load(){return Ae(()=>import("./clike-B9uivgTg.js"),[]).then(t=>Ve(t.csharp))}}),_e.of({name:"Clojure",extensions:["clj","cljc","cljx"],load(){return Ae(()=>import("./clojure-BMjYHr_A.js"),[]).then(t=>Ve(t.clojure))}}),_e.of({name:"ClojureScript",extensions:["cljs"],load(){return Ae(()=>import("./clojure-BMjYHr_A.js"),[]).then(t=>Ve(t.clojure))}}),_e.of({name:"Closure Stylesheets (GSS)",extensions:["gss"],load(){return Ae(()=>import("./css-BnMrqG3P.js"),[]).then(t=>Ve(t.gss))}}),_e.of({name:"CMake",extensions:["cmake","cmake.in"],filename:/^CMakeLists\.txt$/,load(){return Ae(()=>import("./cmake-BQqOBYOt.js"),[]).then(t=>Ve(t.cmake))}}),_e.of({name:"CoffeeScript",alias:["coffee","coffee-script"],extensions:["coffee"],load(){return Ae(()=>import("./coffeescript-S37ZYGWr.js"),[]).then(t=>Ve(t.coffeeScript))}}),_e.of({name:"Common Lisp",alias:["lisp"],extensions:["cl","lisp","el"],load(){return Ae(()=>import("./commonlisp-DBKNyK5s.js"),[]).then(t=>Ve(t.commonLisp))}}),_e.of({name:"Cypher",extensions:["cyp","cypher"],load(){return Ae(()=>import("./cypher-C_CwsFkJ.js"),[]).then(t=>Ve(t.cypher))}}),_e.of({name:"Cython",extensions:["pyx","pxd","pxi"],load(){return Ae(()=>import("./python-BuPzkPfP.js"),[]).then(t=>Ve(t.cython))}}),_e.of({name:"Crystal",extensions:["cr"],load(){return Ae(()=>import("./crystal-SjHAIU92.js"),[]).then(t=>Ve(t.crystal))}}),_e.of({name:"D",extensions:["d"],load(){return Ae(()=>import("./d-pRatUO7H.js"),[]).then(t=>Ve(t.d))}}),_e.of({name:"Dart",extensions:["dart"],load(){return Ae(()=>import("./clike-B9uivgTg.js"),[]).then(t=>Ve(t.dart))}}),_e.of({name:"diff",extensions:["diff","patch"],load(){return Ae(()=>import("./diff-DbItnlRl.js"),[]).then(t=>Ve(t.diff))}}),_e.of({name:"Dockerfile",filename:/^Dockerfile$/,load(){return Ae(()=>import("./dockerfile-BKs6k2Af.js"),__vite__mapDeps([20,21])).then(t=>Ve(t.dockerFile))}}),_e.of({name:"DTD",extensions:["dtd"],load(){return Ae(()=>import("./dtd-DF_7sFjM.js"),[]).then(t=>Ve(t.dtd))}}),_e.of({name:"Dylan",extensions:["dylan","dyl","intr"],load(){return Ae(()=>import("./dylan-DwRh75JA.js"),[]).then(t=>Ve(t.dylan))}}),_e.of({name:"EBNF",load(){return Ae(()=>import("./ebnf-CDyGwa7X.js"),[]).then(t=>Ve(t.ebnf))}}),_e.of({name:"ECL",extensions:["ecl"],load(){return Ae(()=>import("./ecl-Cabwm37j.js"),[]).then(t=>Ve(t.ecl))}}),_e.of({name:"edn",extensions:["edn"],load(){return Ae(()=>import("./clojure-BMjYHr_A.js"),[]).then(t=>Ve(t.clojure))}}),_e.of({name:"Eiffel",extensions:["e"],load(){return Ae(()=>import("./eiffel-CnydiIhH.js"),[]).then(t=>Ve(t.eiffel))}}),_e.of({name:"Elm",extensions:["elm"],load(){return Ae(()=>import("./elm-vLlmbW-K.js"),[]).then(t=>Ve(t.elm))}}),_e.of({name:"Erlang",extensions:["erl"],load(){return Ae(()=>import("./erlang-BNw1qcRV.js"),[]).then(t=>Ve(t.erlang))}}),_e.of({name:"Esper",load(){return Ae(()=>import("./sql-D0XecflT.js"),[]).then(t=>Ve(t.esper))}}),_e.of({name:"Factor",extensions:["factor"],load(){return Ae(()=>import("./factor-kuTfRLto.js"),__vite__mapDeps([22,21])).then(t=>Ve(t.factor))}}),_e.of({name:"FCL",load(){return Ae(()=>import("./fcl-Kvtd6kyn.js"),[]).then(t=>Ve(t.fcl))}}),_e.of({name:"Forth",extensions:["forth","fth","4th"],load(){return Ae(()=>import("./forth-Ffai-XNe.js"),[]).then(t=>Ve(t.forth))}}),_e.of({name:"Fortran",extensions:["f","for","f77","f90","f95"],load(){return Ae(()=>import("./fortran-DYz_wnZ1.js"),[]).then(t=>Ve(t.fortran))}}),_e.of({name:"F#",alias:["fsharp"],extensions:["fs"],load(){return Ae(()=>import("./mllike-CXdrOF99.js"),[]).then(t=>Ve(t.fSharp))}}),_e.of({name:"Gas",extensions:["s"],load(){return Ae(()=>import("./gas-Bneqetm1.js"),[]).then(t=>Ve(t.gas))}}),_e.of({name:"Gherkin",extensions:["feature"],load(){return Ae(()=>import("./gherkin-heZmZLOM.js"),[]).then(t=>Ve(t.gherkin))}}),_e.of({name:"Groovy",extensions:["groovy","gradle"],filename:/^Jenkinsfile$/,load(){return Ae(()=>import("./groovy-D9Dt4D0W.js"),[]).then(t=>Ve(t.groovy))}}),_e.of({name:"Haskell",extensions:["hs"],load(){return Ae(()=>import("./haskell-Cw1EW3IL.js"),[]).then(t=>Ve(t.haskell))}}),_e.of({name:"Haxe",extensions:["hx"],load(){return Ae(()=>import("./haxe-H-WmDvRZ.js"),[]).then(t=>Ve(t.haxe))}}),_e.of({name:"HXML",extensions:["hxml"],load(){return Ae(()=>import("./haxe-H-WmDvRZ.js"),[]).then(t=>Ve(t.hxml))}}),_e.of({name:"HTTP",load(){return Ae(()=>import("./http-DBlCnlav.js"),[]).then(t=>Ve(t.http))}}),_e.of({name:"IDL",extensions:["pro"],load(){return Ae(()=>import("./idl-BEugSyMb.js"),[]).then(t=>Ve(t.idl))}}),_e.of({name:"JSON-LD",alias:["jsonld"],extensions:["jsonld"],load(){return Ae(()=>import("./javascript-iXu5QeM3.js"),[]).then(t=>Ve(t.jsonld))}}),_e.of({name:"Julia",extensions:["jl"],load(){return Ae(()=>import("./julia-DuME0IfC.js"),[]).then(t=>Ve(t.julia))}}),_e.of({name:"Kotlin",extensions:["kt","kts"],load(){return Ae(()=>import("./clike-B9uivgTg.js"),[]).then(t=>Ve(t.kotlin))}}),_e.of({name:"LiveScript",alias:["ls"],extensions:["ls"],load(){return Ae(()=>import("./livescript-BwQOo05w.js"),[]).then(t=>Ve(t.liveScript))}}),_e.of({name:"Lua",extensions:["lua"],load(){return Ae(()=>import("./lua-BgMRiT3U.js"),[]).then(t=>Ve(t.lua))}}),_e.of({name:"mIRC",extensions:["mrc"],load(){return Ae(()=>import("./mirc-CjQqDB4T.js"),[]).then(t=>Ve(t.mirc))}}),_e.of({name:"Mathematica",extensions:["m","nb","wl","wls"],load(){return Ae(()=>import("./mathematica-DTrFuWx2.js"),[]).then(t=>Ve(t.mathematica))}}),_e.of({name:"Modelica",extensions:["mo"],load(){return Ae(()=>import("./modelica-Dc1JOy9r.js"),[]).then(t=>Ve(t.modelica))}}),_e.of({name:"MUMPS",extensions:["mps"],load(){return Ae(()=>import("./mumps-BT43cFF4.js"),[]).then(t=>Ve(t.mumps))}}),_e.of({name:"Mbox",extensions:["mbox"],load(){return Ae(()=>import("./mbox-CNhZ1qSd.js"),[]).then(t=>Ve(t.mbox))}}),_e.of({name:"Nginx",filename:/nginx.*\.conf$/i,load(){return Ae(()=>import("./nginx-DdIZxoE0.js"),[]).then(t=>Ve(t.nginx))}}),_e.of({name:"NSIS",extensions:["nsh","nsi"],load(){return Ae(()=>import("./nsis-LdVXkNf5.js"),__vite__mapDeps([23,21])).then(t=>Ve(t.nsis))}}),_e.of({name:"NTriples",extensions:["nt","nq"],load(){return Ae(()=>import("./ntriples-BfvgReVJ.js"),[]).then(t=>Ve(t.ntriples))}}),_e.of({name:"Objective-C",alias:["objective-c","objc"],extensions:["m"],load(){return Ae(()=>import("./clike-B9uivgTg.js"),[]).then(t=>Ve(t.objectiveC))}}),_e.of({name:"Objective-C++",alias:["objective-c++","objc++"],extensions:["mm"],load(){return Ae(()=>import("./clike-B9uivgTg.js"),[]).then(t=>Ve(t.objectiveCpp))}}),_e.of({name:"OCaml",extensions:["ml","mli","mll","mly"],load(){return Ae(()=>import("./mllike-CXdrOF99.js"),[]).then(t=>Ve(t.oCaml))}}),_e.of({name:"Octave",extensions:["m"],load(){return Ae(()=>import("./octave-Ck1zUtKM.js"),[]).then(t=>Ve(t.octave))}}),_e.of({name:"Oz",extensions:["oz"],load(){return Ae(()=>import("./oz-BzwKVEFT.js"),[]).then(t=>Ve(t.oz))}}),_e.of({name:"Pascal",extensions:["p","pas"],load(){return Ae(()=>import("./pascal--L3eBynH.js"),[]).then(t=>Ve(t.pascal))}}),_e.of({name:"Perl",extensions:["pl","pm"],load(){return Ae(()=>import("./perl-CdXCOZ3F.js"),[]).then(t=>Ve(t.perl))}}),_e.of({name:"Pig",extensions:["pig"],load(){return Ae(()=>import("./pig-CevX1Tat.js"),[]).then(t=>Ve(t.pig))}}),_e.of({name:"PowerShell",extensions:["ps1","psd1","psm1"],load(){return Ae(()=>import("./powershell-CFHJl5sT.js"),[]).then(t=>Ve(t.powerShell))}}),_e.of({name:"Properties files",alias:["ini","properties"],extensions:["properties","ini","in"],load(){return Ae(()=>import("./properties-C78fOPTZ.js"),[]).then(t=>Ve(t.properties))}}),_e.of({name:"ProtoBuf",extensions:["proto"],load(){return Ae(()=>import("./protobuf-ChK-085T.js"),[]).then(t=>Ve(t.protobuf))}}),_e.of({name:"Pug",alias:["jade"],extensions:["pug","jade"],load(){return Ae(()=>import("./pug-DeIclll2.js"),__vite__mapDeps([24,25])).then(t=>Ve(t.pug))}}),_e.of({name:"Puppet",extensions:["pp"],load(){return Ae(()=>import("./puppet-DMA9R1ak.js"),[]).then(t=>Ve(t.puppet))}}),_e.of({name:"Q",extensions:["q"],load(){return Ae(()=>import("./q-pXgVlZs6.js"),[]).then(t=>Ve(t.q))}}),_e.of({name:"R",alias:["rscript"],extensions:["r","R"],load(){return Ae(()=>import("./r-B6wPVr8A.js"),[]).then(t=>Ve(t.r))}}),_e.of({name:"RPM Changes",load(){return Ae(()=>import("./rpm-CTu-6PCP.js"),[]).then(t=>Ve(t.rpmChanges))}}),_e.of({name:"RPM Spec",extensions:["spec"],load(){return Ae(()=>import("./rpm-CTu-6PCP.js"),[]).then(t=>Ve(t.rpmSpec))}}),_e.of({name:"Ruby",alias:["jruby","macruby","rake","rb","rbx"],extensions:["rb"],filename:/^(Gemfile|Rakefile)$/,load(){return Ae(()=>import("./ruby-B2Rjki9n.js"),[]).then(t=>Ve(t.ruby))}}),_e.of({name:"SAS",extensions:["sas"],load(){return Ae(()=>import("./sas-B4kiWyti.js"),[]).then(t=>Ve(t.sas))}}),_e.of({name:"Scala",extensions:["scala"],load(){return Ae(()=>import("./clike-B9uivgTg.js"),[]).then(t=>Ve(t.scala))}}),_e.of({name:"Scheme",extensions:["scm","ss"],load(){return Ae(()=>import("./scheme-C41bIUwD.js"),[]).then(t=>Ve(t.scheme))}}),_e.of({name:"Shell",alias:["bash","sh","zsh"],extensions:["sh","ksh","bash"],filename:/^PKGBUILD$/,load(){return Ae(()=>import("./shell-CjFT_Tl9.js"),[]).then(t=>Ve(t.shell))}}),_e.of({name:"Sieve",extensions:["siv","sieve"],load(){return Ae(()=>import("./sieve-C3Gn_uJK.js"),[]).then(t=>Ve(t.sieve))}}),_e.of({name:"Smalltalk",extensions:["st"],load(){return Ae(()=>import("./smalltalk-CnHTOXQT.js"),[]).then(t=>Ve(t.smalltalk))}}),_e.of({name:"Solr",load(){return Ae(()=>import("./solr-DehyRSwq.js"),[]).then(t=>Ve(t.solr))}}),_e.of({name:"SML",extensions:["sml","sig","fun","smackspec"],load(){return Ae(()=>import("./mllike-CXdrOF99.js"),[]).then(t=>Ve(t.sml))}}),_e.of({name:"SPARQL",alias:["sparul"],extensions:["rq","sparql"],load(){return Ae(()=>import("./sparql-DkYu6x3z.js"),[]).then(t=>Ve(t.sparql))}}),_e.of({name:"Spreadsheet",alias:["excel","formula"],load(){return Ae(()=>import("./spreadsheet-BCZA_wO0.js"),[]).then(t=>Ve(t.spreadsheet))}}),_e.of({name:"Squirrel",extensions:["nut"],load(){return Ae(()=>import("./clike-B9uivgTg.js"),[]).then(t=>Ve(t.squirrel))}}),_e.of({name:"Stylus",extensions:["styl"],load(){return Ae(()=>import("./stylus-B533Al4x.js"),[]).then(t=>Ve(t.stylus))}}),_e.of({name:"Swift",extensions:["swift"],load(){return Ae(()=>import("./swift-BzpIVaGY.js"),[]).then(t=>Ve(t.swift))}}),_e.of({name:"sTeX",load(){return Ae(()=>import("./stex-C3f8Ysf7.js"),[]).then(t=>Ve(t.stex))}}),_e.of({name:"LaTeX",alias:["tex"],extensions:["text","ltx","tex"],load(){return Ae(()=>import("./stex-C3f8Ysf7.js"),[]).then(t=>Ve(t.stex))}}),_e.of({name:"SystemVerilog",extensions:["v","sv","svh"],load(){return Ae(()=>import("./verilog-C6RDOZhf.js"),[]).then(t=>Ve(t.verilog))}}),_e.of({name:"Tcl",extensions:["tcl"],load(){return Ae(()=>import("./tcl-DVfN8rqt.js"),[]).then(t=>Ve(t.tcl))}}),_e.of({name:"Textile",extensions:["textile"],load(){return Ae(()=>import("./textile-CnDTJFAw.js"),[]).then(t=>Ve(t.textile))}}),_e.of({name:"TiddlyWiki",load(){return Ae(()=>import("./tiddlywiki-DO-Gjzrf.js"),[]).then(t=>Ve(t.tiddlyWiki))}}),_e.of({name:"Tiki wiki",load(){return Ae(()=>import("./tiki-DGYXhP31.js"),[]).then(t=>Ve(t.tiki))}}),_e.of({name:"TOML",extensions:["toml"],load(){return Ae(()=>import("./toml-Bm5Em-hy.js"),[]).then(t=>Ve(t.toml))}}),_e.of({name:"Troff",extensions:["1","2","3","4","5","6","7","8","9"],load(){return Ae(()=>import("./troff-wAsdV37c.js"),[]).then(t=>Ve(t.troff))}}),_e.of({name:"TTCN",extensions:["ttcn","ttcn3","ttcnpp"],load(){return Ae(()=>import("./ttcn-CfJYG6tj.js"),[]).then(t=>Ve(t.ttcn))}}),_e.of({name:"TTCN_CFG",extensions:["cfg"],load(){return Ae(()=>import("./ttcn-cfg-B9xdYoR4.js"),[]).then(t=>Ve(t.ttcnCfg))}}),_e.of({name:"Turtle",extensions:["ttl"],load(){return Ae(()=>import("./turtle-B1tBg_DP.js"),[]).then(t=>Ve(t.turtle))}}),_e.of({name:"Web IDL",extensions:["webidl"],load(){return Ae(()=>import("./webidl-ZXfAyPTL.js"),[]).then(t=>Ve(t.webIDL))}}),_e.of({name:"VB.NET",extensions:["vb"],load(){return Ae(()=>import("./vb-CmGdzxic.js"),[]).then(t=>Ve(t.vb))}}),_e.of({name:"VBScript",extensions:["vbs"],load(){return Ae(()=>import("./vbscript-BuJXcnF6.js"),[]).then(t=>Ve(t.vbScript))}}),_e.of({name:"Velocity",extensions:["vtl"],load(){return Ae(()=>import("./velocity-D8B20fx6.js"),[]).then(t=>Ve(t.velocity))}}),_e.of({name:"Verilog",extensions:["v"],load(){return Ae(()=>import("./verilog-C6RDOZhf.js"),[]).then(t=>Ve(t.verilog))}}),_e.of({name:"VHDL",extensions:["vhd","vhdl"],load(){return Ae(()=>import("./vhdl-lSbBsy5d.js"),[]).then(t=>Ve(t.vhdl))}}),_e.of({name:"XQuery",extensions:["xy","xquery","xq","xqm","xqy"],load(){return Ae(()=>import("./xquery-DzFWVndE.js"),[]).then(t=>Ve(t.xQuery))}}),_e.of({name:"Yacas",extensions:["ys"],load(){return Ae(()=>import("./yacas-BJ4BC0dw.js"),[]).then(t=>Ve(t.yacas))}}),_e.of({name:"Z80",extensions:["z80"],load(){return Ae(()=>import("./z80-Hz9HOZM7.js"),[]).then(t=>Ve(t.z80))}}),_e.of({name:"MscGen",extensions:["mscgen","mscin","msc"],load(){return Ae(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(t=>Ve(t.mscgen))}}),_e.of({name:"Xù",extensions:["xu"],load(){return Ae(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(t=>Ve(t.xu))}}),_e.of({name:"MsGenny",extensions:["msgenny"],load(){return Ae(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(t=>Ve(t.msgenny))}}),_e.of({name:"Vue",extensions:["vue"],load(){return Ae(()=>import("./index-DXgtGequ.js"),__vite__mapDeps([26,5,1,3,6])).then(t=>t.vue())}}),_e.of({name:"Angular Template",load(){return Ae(()=>import("./index-cx0y6-1h.js"),__vite__mapDeps([27,5,1,3,6])).then(t=>t.angular())}})],tH="#2e3440",U9="#3b4252",nH="#434c5e",sC="#4c566a",rH="#e5e9f0",aM="#eceff4",iA="#8fbcbb",sH="#88c0d0",BLe="#81a1c1",Ma="#5e81ac",zLe="#bf616a",pp="#d08770",oA="#ebcb8b",iH="#a3be8c",VLe="#b48ead",oH="#d30102",q9=aM,aA=q9,HLe="#ffffff",lA=U9,ULe=q9,aH=U9,qLe=at.theme({"&":{color:tH,backgroundColor:HLe},".cm-content":{caretColor:aH},".cm-cursor, .cm-dropCursor":{borderLeftColor:aH},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:ULe},".cm-panels":{backgroundColor:q9,color:sC},".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 ${sC}`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:rH},".cm-activeLine":{backgroundColor:aA},".cm-selectionMatch":{backgroundColor:rH},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{outline:`1px solid ${sC}`},"&.cm-focused .cm-matchingBracket":{backgroundColor:aM},".cm-gutters":{backgroundColor:aM,color:tH,border:"none"},".cm-activeLineGutter":{backgroundColor:aA},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:lA},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:lA,borderBottomColor:lA},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:aA,color:sC}}},{dark:!1}),KLe=Vv.define([{tag:je.keyword,color:Ma},{tag:[je.name,je.deleted,je.character,je.propertyName,je.macroName],color:pp},{tag:[je.variableName],color:pp},{tag:[je.function(je.variableName)],color:Ma},{tag:[je.labelName],color:BLe},{tag:[je.color,je.constant(je.name),je.standard(je.name)],color:Ma},{tag:[je.definition(je.name),je.separator],color:iH},{tag:[je.brace],color:iA},{tag:[je.annotation],color:oH},{tag:[je.number,je.changed,je.annotation,je.modifier,je.self,je.namespace],color:sH},{tag:[je.typeName,je.className],color:oA},{tag:[je.operator,je.operatorKeyword],color:iH},{tag:[je.tagName],color:VLe},{tag:[je.squareBracket],color:zLe},{tag:[je.angleBracket],color:pp},{tag:[je.attributeName],color:oA},{tag:[je.regexp],color:Ma},{tag:[je.quote],color:U9},{tag:[je.string],color:pp},{tag:je.link,color:iA,textDecoration:"underline",textUnderlinePosition:"under"},{tag:[je.url,je.escape,je.special(je.string)],color:pp},{tag:[je.meta],color:sH},{tag:[je.comment],color:nH,fontStyle:"italic"},{tag:je.strong,fontWeight:"bold",color:Ma},{tag:je.emphasis,fontStyle:"italic",color:Ma},{tag:je.strikethrough,textDecoration:"line-through"},{tag:je.heading,fontWeight:"bold",color:Ma},{tag:je.special(je.heading1),fontWeight:"bold",color:Ma},{tag:je.heading1,fontWeight:"bold",color:Ma},{tag:[je.heading2,je.heading3,je.heading4],fontWeight:"bold",color:Ma},{tag:[je.heading5,je.heading6],color:Ma},{tag:[je.atom,je.bool,je.special(je.variableName)],color:pp},{tag:[je.processingInstruction,je.inserted],color:iA},{tag:[je.contentSeparator],color:oA},{tag:je.invalid,color:nH,borderBottom:`1px dotted ${oH}`}]),WLe=[qLe,Pre(KLe)],lH=typeof String.prototype.normalize=="function"?t=>t.normalize("NFKD"):t=>t;class Jg{constructor(e,n,r=0,s=e.length,i,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(r,s),this.bufferStart=r,this.normalize=i?a=>i(lH(a)):lH,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 Gi(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let n=o9(e),r=this.bufferStart+this.bufferPos;this.bufferPos+=Rl(e);let s=this.normalize(n);if(s.length)for(let i=0,o=r;;i++){let a=s.charCodeAt(i),c=this.match(a,o,this.bufferPos+this.bufferStart);if(i==s.length-1){if(c)return this.value=c,this;break}o==r&&i<n.length&&n.charCodeAt(i)==a&&o++}}}match(e,n,r){let s=null;for(let i=0;i<this.matches.length;i+=2){let o=this.matches[i],a=!1;this.query.charCodeAt(o)==e&&(o==this.query.length-1?s={from:this.matches[i+1],to:r}:(this.matches[i]++,a=!0)),a||(this.matches.splice(i,2),i-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?s={from:n,to:r}:this.matches.push(1,n)),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}typeof Symbol<"u"&&(Jg.prototype[Symbol.iterator]=function(){return this});const Pse={from:-1,to:-1,match:/.*/.exec("")},K9="gm"+(/x/.unicode==null?"":"u");class Fse{constructor(e,n,r,s=0,i=e.length){if(this.text=e,this.to=i,this.curLine="",this.done=!1,this.value=Pse,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new $se(e,n,r,s,i);this.re=new RegExp(n,K9+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.iter=e.iter();let o=e.lineAt(s);this.curLineStart=o.from,this.matchPos=Hk(e,s),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),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 e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let n=this.matchPos<=this.to&&this.re.exec(this.curLine);if(n){let r=this.curLineStart+n.index,s=r+n[0].length;if(this.matchPos=Hk(this.text,s+(r==s?1:0)),r==this.curLineStart+this.curLine.length&&this.nextLine(),(r<s||r>this.value.to)&&(!this.test||this.test(r,s,n)))return this.value={from:r,to:s,match:n},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const cA=new WeakMap;class eg{constructor(e,n){this.from=e,this.text=n}get to(){return this.from+this.text.length}static get(e,n,r){let s=cA.get(e);if(!s||s.from>=r||s.to<=n){let a=new eg(n,e.sliceString(n,r));return cA.set(e,a),a}if(s.from==n&&s.to==r)return s;let{text:i,from:o}=s;return o>n&&(i=e.sliceString(n,o)+i,o=n),s.to<r&&(i+=e.sliceString(s.to,r)),cA.set(e,new eg(o,i)),new eg(n,i.slice(n-o,r-o))}}class $se{constructor(e,n,r,s,i){this.text=e,this.to=i,this.done=!1,this.value=Pse,this.matchPos=Hk(e,s),this.re=new RegExp(n,K9+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.flat=eg.get(e,s,this.chunkEnd(s+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,n=this.re.exec(this.flat.text);if(n&&!n[0]&&n.index==e&&(this.re.lastIndex=e+1,n=this.re.exec(this.flat.text)),n){let r=this.flat.from+n.index,s=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,s,n)))return this.value={from:r,to:s,match:n},this.matchPos=Hk(this.text,s+(r==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=eg.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(Fse.prototype[Symbol.iterator]=$se.prototype[Symbol.iterator]=function(){return this});function GLe(t){try{return new RegExp(t,K9),!0}catch{return!1}}function Hk(t,e){if(e>=t.length)return e;let n=t.lineAt(e),r;for(;e<n.to&&(r=n.text.charCodeAt(e-n.from))>=56320&&r<57344;)e++;return e}const JLe=t=>{let{state:e}=t,n=String(e.doc.lineAt(t.state.selection.main.head).number),{close:r,result:s}=Q9e(t,{label:e.phrase("Go to line"),input:{type:"text",name:"line",value:n},focus:!0,submitLabel:e.phrase("go")});return s.then(i=>{let o=i&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(i.elements.line.value);if(!o){t.dispatch({effects:r});return}let a=e.doc.lineAt(e.selection.main.head),[,c,d,f,m]=o,p=f?+f.slice(1):0,x=d?+d:a.number;if(d&&m){let k=x/100;c&&(k=k*(c=="-"?-1:1)+a.number/e.doc.lines),x=Math.round(e.doc.lines*k)}else d&&c&&(x=x*(c=="-"?-1:1)+a.number);let y=e.doc.line(Math.max(1,Math.min(e.doc.lines,x))),w=De.cursor(y.from+Math.max(0,Math.min(p,y.length)));t.dispatch({effects:[r,at.scrollIntoView(w.from,{y:"center"})],selection:w})}),!0},YLe={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},ZLe=ut.define({combine(t){return lc(t,YLe,{highlightWordAroundCursor:(e,n)=>e||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function QLe(t){return[r7e,n7e]}const XLe=Mt.mark({class:"cm-selectionMatch"}),e7e=Mt.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function cH(t,e,n,r){return(n==0||t(e.sliceDoc(n-1,n))!=_r.Word)&&(r==e.doc.length||t(e.sliceDoc(r,r+1))!=_r.Word)}function t7e(t,e,n,r){return t(e.sliceDoc(n,n+1))==_r.Word&&t(e.sliceDoc(r-1,r))==_r.Word}const n7e=us.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.selectionSet||t.docChanged||t.viewportChanged)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=t.state.facet(ZLe),{state:n}=t,r=n.selection;if(r.ranges.length>1)return Mt.none;let s=r.main,i,o=null;if(s.empty){if(!e.highlightWordAroundCursor)return Mt.none;let c=n.wordAt(s.head);if(!c)return Mt.none;o=n.charCategorizer(s.head),i=n.sliceDoc(c.from,c.to)}else{let c=s.to-s.from;if(c<e.minSelectionLength||c>200)return Mt.none;if(e.wholeWords){if(i=n.sliceDoc(s.from,s.to),o=n.charCategorizer(s.head),!(cH(o,n,s.from,s.to)&&t7e(o,n,s.from,s.to)))return Mt.none}else if(i=n.sliceDoc(s.from,s.to),!i)return Mt.none}let a=[];for(let c of t.visibleRanges){let d=new Jg(n.doc,i,c.from,c.to);for(;!d.next().done;){let{from:f,to:m}=d.value;if((!o||cH(o,n,f,m))&&(s.empty&&f<=s.from&&m>=s.to?a.push(e7e.range(f,m)):(f>=s.to||m<=s.from)&&a.push(XLe.range(f,m)),a.length>e.maxMatches))return Mt.none}}return Mt.set(a)}},{decorations:t=>t.decorations}),r7e=at.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),s7e=({state:t,dispatch:e})=>{let{selection:n}=t,r=De.create(n.ranges.map(s=>t.wordAt(s.head)||De.cursor(s.head)),n.mainIndex);return r.eq(n)?!1:(e(t.update({selection:r})),!0)};function i7e(t,e){let{main:n,ranges:r}=t.selection,s=t.wordAt(n.head),i=s&&s.from==n.from&&s.to==n.to;for(let o=!1,a=new Jg(t.doc,e,r[r.length-1].to);;)if(a.next(),a.done){if(o)return null;a=new Jg(t.doc,e,0,Math.max(0,r[r.length-1].from-1)),o=!0}else{if(o&&r.some(c=>c.from==a.value.from))continue;if(i){let c=t.wordAt(a.value.from);if(!c||c.from!=a.value.from||c.to!=a.value.to)continue}return a.value}}const o7e=({state:t,dispatch:e})=>{let{ranges:n}=t.selection;if(n.some(i=>i.from===i.to))return s7e({state:t,dispatch:e});let r=t.sliceDoc(n[0].from,n[0].to);if(t.selection.ranges.some(i=>t.sliceDoc(i.from,i.to)!=r))return!1;let s=i7e(t,r);return s?(e(t.update({selection:t.selection.addRange(De.range(s.from,s.to),!1),effects:at.scrollIntoView(s.to)})),!0):!1},Tx=ut.define({combine(t){return lc(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new v7e(e),scrollToMatch:e=>at.scrollIntoView(e)})}});class Bse{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||GLe(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(n,r)=>r=="n"?`
808
808
  `:r=="r"?"\r":r=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new f7e(this):new c7e(this)}getCursor(e,n=0,r){let s=e.doc?e:Cn.create({doc:e});return r==null&&(r=s.doc.length),this.regexp?Mp(this,s,n,r):Tp(this,s,n,r)}}class zse{constructor(e){this.spec=e}}function a7e(t,e,n){return(r,s,i,o)=>{if(n&&!n(r,s,i,o))return!1;let a=r>=o&&s<=o+i.length?i.slice(r-o,s-o):e.doc.sliceString(r,s);return t(a,e,r,s)}}function Tp(t,e,n,r){let s;return t.wholeWord&&(s=l7e(e.doc,e.charCategorizer(e.selection.main.head))),t.test&&(s=a7e(t.test,e,s)),new Jg(e.doc,t.unquoted,n,r,t.caseSensitive?void 0:i=>i.toLowerCase(),s)}function l7e(t,e){return(n,r,s,i)=>((i>n||i+s.length<r)&&(i=Math.max(0,n-2),s=t.sliceString(i,Math.min(t.length,r+2))),(e(Uk(s,n-i))!=_r.Word||e(qk(s,n-i))!=_r.Word)&&(e(qk(s,r-i))!=_r.Word||e(Uk(s,r-i))!=_r.Word))}class c7e extends zse{constructor(e){super(e)}nextMatch(e,n,r){let s=Tp(this.spec,e,r,e.doc.length).nextOverlapping();if(s.done){let i=Math.min(e.doc.length,n+this.spec.unquoted.length);s=Tp(this.spec,e,0,i).nextOverlapping()}return s.done||s.value.from==n&&s.value.to==r?null:s.value}prevMatchInRange(e,n,r){for(let s=r;;){let i=Math.max(n,s-1e4-this.spec.unquoted.length),o=Tp(this.spec,e,i,s),a=null;for(;!o.nextOverlapping().done;)a=o.value;if(a)return a;if(i==n)return null;s-=1e4}}prevMatch(e,n,r){let s=this.prevMatchInRange(e,0,n);return s||(s=this.prevMatchInRange(e,Math.max(0,r-this.spec.unquoted.length),e.doc.length)),s&&(s.from!=n||s.to!=r)?s:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,n){let r=Tp(this.spec,e,0,e.doc.length),s=[];for(;!r.next().done;){if(s.length>=n)return null;s.push(r.value)}return s}highlight(e,n,r,s){let i=Tp(this.spec,e,Math.max(0,n-this.spec.unquoted.length),Math.min(r+this.spec.unquoted.length,e.doc.length));for(;!i.next().done;)s(i.value.from,i.value.to)}}function u7e(t,e,n){return(r,s,i)=>(!n||n(r,s,i))&&t(i[0],e,r,s)}function Mp(t,e,n,r){let s;return t.wholeWord&&(s=d7e(e.charCategorizer(e.selection.main.head))),t.test&&(s=u7e(t.test,e,s)),new Fse(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:s},n,r)}function Uk(t,e){return t.slice(Ms(t,e,!1),e)}function qk(t,e){return t.slice(e,Ms(t,e))}function d7e(t){return(e,n,r)=>!r[0].length||(t(Uk(r.input,r.index))!=_r.Word||t(qk(r.input,r.index))!=_r.Word)&&(t(qk(r.input,r.index+r[0].length))!=_r.Word||t(Uk(r.input,r.index+r[0].length))!=_r.Word)}class f7e extends zse{nextMatch(e,n,r){let s=Mp(this.spec,e,r,e.doc.length).next();return s.done&&(s=Mp(this.spec,e,0,n).next()),s.done?null:s.value}prevMatchInRange(e,n,r){for(let s=1;;s++){let i=Math.max(n,r-s*1e4),o=Mp(this.spec,e,i,r),a=null;for(;!o.next().done;)a=o.value;if(a&&(i==n||a.from>i+10))return a;if(i==n)return null}}prevMatch(e,n,r){return this.prevMatchInRange(e,0,n)||this.prevMatchInRange(e,r,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(n,r)=>{if(r=="&")return e.match[0];if(r=="$")return"$";for(let s=r.length;s>0;s--){let i=+r.slice(0,s);if(i>0&&i<e.match.length)return e.match[i]+r.slice(s)}return n})}matchAll(e,n){let r=Mp(this.spec,e,0,e.doc.length),s=[];for(;!r.next().done;){if(s.length>=n)return null;s.push(r.value)}return s}highlight(e,n,r,s){let i=Mp(this.spec,e,Math.max(0,n-250),Math.min(r+250,e.doc.length));for(;!i.next().done;)s(i.value.from,i.value.to)}}const Eb=zt.define(),W9=zt.define(),Gd=Is.define({create(t){return new uA(lM(t).create(),null)},update(t,e){for(let n of e.effects)n.is(Eb)?t=new uA(n.value.create(),t.panel):n.is(W9)&&(t=new uA(t.query,n.value?G9:null));return t},provide:t=>bb.from(t,e=>e.panel)});class uA{constructor(e,n){this.query=e,this.panel=n}}const h7e=Mt.mark({class:"cm-searchMatch"}),m7e=Mt.mark({class:"cm-searchMatch cm-searchMatch-selected"}),p7e=us.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(Gd))}update(t){let e=t.state.field(Gd);(e!=t.startState.field(Gd)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return Mt.none;let{view:n}=this,r=new Su;for(let s=0,i=n.visibleRanges,o=i.length;s<o;s++){let{from:a,to:c}=i[s];for(;s<o-1&&c>i[s+1].from-500;)c=i[++s].to;t.highlight(n.state,a,c,(d,f)=>{let m=n.state.selection.ranges.some(p=>p.from==d&&p.to==f);r.add(d,f,m?m7e:h7e)})}return r.finish()}},{decorations:t=>t.decorations});function qv(t){return e=>{let n=e.state.field(Gd,!1);return n&&n.query.spec.valid?t(e,n):Use(e)}}const Kk=qv((t,{query:e})=>{let{to:n}=t.state.selection.main,r=e.nextMatch(t.state,n,n);if(!r)return!1;let s=De.single(r.from,r.to),i=t.state.facet(Tx);return t.dispatch({selection:s,effects:[J9(t,r),i.scrollToMatch(s.main,t)],userEvent:"select.search"}),Hse(t),!0}),Wk=qv((t,{query:e})=>{let{state:n}=t,{from:r}=n.selection.main,s=e.prevMatch(n,r,r);if(!s)return!1;let i=De.single(s.from,s.to),o=t.state.facet(Tx);return t.dispatch({selection:i,effects:[J9(t,s),o.scrollToMatch(i.main,t)],userEvent:"select.search"}),Hse(t),!0}),g7e=qv((t,{query:e})=>{let n=e.matchAll(t.state,1e3);return!n||!n.length?!1:(t.dispatch({selection:De.create(n.map(r=>De.range(r.from,r.to))),userEvent:"select.search.matches"}),!0)}),x7e=({state:t,dispatch:e})=>{let n=t.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:s}=n.main,i=[],o=0;for(let a=new Jg(t.doc,t.sliceDoc(r,s));!a.next().done;){if(i.length>1e3)return!1;a.value.from==r&&(o=i.length),i.push(De.range(a.value.from,a.value.to))}return e(t.update({selection:De.create(i,o),userEvent:"select.search.matches"})),!0},uH=qv((t,{query:e})=>{let{state:n}=t,{from:r,to:s}=n.selection.main;if(n.readOnly)return!1;let i=e.nextMatch(n,r,r);if(!i)return!1;let o=i,a=[],c,d,f=[];o.from==r&&o.to==s&&(d=n.toText(e.getReplacement(o)),a.push({from:o.from,to:o.to,insert:d}),o=e.nextMatch(n,o.from,o.to),f.push(at.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(r).number)+".")));let m=t.state.changes(a);return o&&(c=De.single(o.from,o.to).map(m),f.push(J9(t,o)),f.push(n.facet(Tx).scrollToMatch(c.main,t))),t.dispatch({changes:m,selection:c,effects:f,userEvent:"input.replace"}),!0}),y7e=qv((t,{query:e})=>{if(t.state.readOnly)return!1;let n=e.matchAll(t.state,1e9).map(s=>{let{from:i,to:o}=s;return{from:i,to:o,insert:e.getReplacement(s)}});if(!n.length)return!1;let r=t.state.phrase("replaced $ matches",n.length)+".";return t.dispatch({changes:n,effects:at.announce.of(r),userEvent:"input.replace.all"}),!0});function G9(t){return t.state.facet(Tx).createPanel(t)}function lM(t,e){var n,r,s,i,o;let a=t.selection.main,c=a.empty||a.to>a.from+100?"":t.sliceDoc(a.from,a.to);if(e&&!c)return e;let d=t.facet(Tx);return new Bse({search:((n=e==null?void 0:e.literal)!==null&&n!==void 0?n:d.literal)?c:c.replace(/\n/g,"\\n"),caseSensitive:(r=e==null?void 0:e.caseSensitive)!==null&&r!==void 0?r:d.caseSensitive,literal:(s=e==null?void 0:e.literal)!==null&&s!==void 0?s:d.literal,regexp:(i=e==null?void 0:e.regexp)!==null&&i!==void 0?i:d.regexp,wholeWord:(o=e==null?void 0:e.wholeWord)!==null&&o!==void 0?o:d.wholeWord})}function Vse(t){let e=S9(t,G9);return e&&e.dom.querySelector("[main-field]")}function Hse(t){let e=Vse(t);e&&e==t.root.activeElement&&e.select()}const Use=t=>{let e=t.state.field(Gd,!1);if(e&&e.panel){let n=Vse(t);if(n&&n!=t.root.activeElement){let r=lM(t.state,e.query.spec);r.valid&&t.dispatch({effects:Eb.of(r)}),n.focus(),n.select()}}else t.dispatch({effects:[W9.of(!0),e?Eb.of(lM(t.state,e.query.spec)):zt.appendConfig.of(C7e)]});return!0},qse=t=>{let e=t.state.field(Gd,!1);if(!e||!e.panel)return!1;let n=S9(t,G9);return n&&n.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:W9.of(!1)}),!0},b7e=[{key:"Mod-f",run:Use,scope:"editor search-panel"},{key:"F3",run:Kk,shift:Wk,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Kk,shift:Wk,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:qse,scope:"editor search-panel"},{key:"Mod-Shift-l",run:x7e},{key:"Mod-Alt-g",run:JLe},{key:"Mod-d",run:o7e,preventDefault:!0}];class v7e{constructor(e){this.view=e;let n=this.query=e.state.field(Gd).query.spec;this.commit=this.commit.bind(this),this.searchField=Xn("input",{value:n.search,placeholder:go(e,"Find"),"aria-label":go(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Xn("input",{value:n.replace,placeholder:go(e,"Replace"),"aria-label":go(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=Xn("input",{type:"checkbox",name:"case",form:"",checked:n.caseSensitive,onchange:this.commit}),this.reField=Xn("input",{type:"checkbox",name:"re",form:"",checked:n.regexp,onchange:this.commit}),this.wordField=Xn("input",{type:"checkbox",name:"word",form:"",checked:n.wholeWord,onchange:this.commit});function r(s,i,o){return Xn("button",{class:"cm-button",name:s,onclick:i,type:"button"},o)}this.dom=Xn("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,r("next",()=>Kk(e),[go(e,"next")]),r("prev",()=>Wk(e),[go(e,"previous")]),r("select",()=>g7e(e),[go(e,"all")]),Xn("label",null,[this.caseField,go(e,"match case")]),Xn("label",null,[this.reField,go(e,"regexp")]),Xn("label",null,[this.wordField,go(e,"by word")]),...e.state.readOnly?[]:[Xn("br"),this.replaceField,r("replace",()=>uH(e),[go(e,"replace")]),r("replaceAll",()=>y7e(e),[go(e,"replace all")])],Xn("button",{name:"close",onclick:()=>qse(e),"aria-label":go(e,"close"),type:"button"},["×"])])}commit(){let e=new Bse({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:Eb.of(e)}))}keydown(e){u9e(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?Wk:Kk)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),uH(this.view))}update(e){for(let n of e.transactions)for(let r of n.effects)r.is(Eb)&&!r.value.eq(this.query)&&this.setQuery(r.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Tx).top}}function go(t,e){return t.state.phrase(e)}const iC=30,oC=/[\s\.,:;?!]/;function J9(t,{from:e,to:n}){let r=t.state.doc.lineAt(e),s=t.state.doc.lineAt(n).to,i=Math.max(r.from,e-iC),o=Math.min(s,n+iC),a=t.state.sliceDoc(i,o);if(i!=r.from){for(let c=0;c<iC;c++)if(!oC.test(a[c+1])&&oC.test(a[c])){a=a.slice(c);break}}if(o!=s){for(let c=a.length-1;c>a.length-iC;c--)if(!oC.test(a[c-1])&&oC.test(a[c])){a=a.slice(0,c);break}}return at.announce.of(`${t.state.phrase("current match")}. ${a} ${t.state.phrase("on line")} ${r.number}.`)}const w7e=at.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"}}),C7e=[Gd,Sf.low(p7e),w7e];class dH{constructor(e,n,r){this.from=e,this.to=n,this.diagnostic=r}}class th{constructor(e,n,r){this.diagnostics=e,this.panel=n,this.selected=r}static init(e,n,r){let s=r.facet(jb).markerFilter;s&&(e=s(e,r));let i=e.slice().sort((x,y)=>x.from-y.from||x.to-y.to),o=new Su,a=[],c=0,d=r.doc.iter(),f=0,m=r.doc.length;for(let x=0;;){let y=x==i.length?null:i[x];if(!y&&!a.length)break;let w,k;if(a.length)w=c,k=a.reduce((_,E)=>Math.min(_,E.to),y&&y.from>w?y.from:1e8);else{if(w=y.from,w>m)break;k=y.to,a.push(y),x++}for(;x<i.length;){let _=i[x];if(_.from==w&&(_.to>_.from||_.to==w))a.push(_),x++,k=Math.min(_.to,k);else{k=Math.min(_.from,k);break}}k=Math.min(k,m);let S=!1;if(a.some(_=>_.from==w&&(_.to==k||k==m))&&(S=w==k,!S&&k-w<10)){let _=w-(f+d.value.length);_>0&&(d.next(_),f=w);for(let E=w;;){if(E>=k){S=!0;break}if(!d.lineBreak&&f+d.value.length>E)break;E=f+d.value.length,f+=d.value.length,d.next()}}let C=D7e(a);if(S)o.add(w,w,Mt.widget({widget:new M7e(C),diagnostics:a.slice()}));else{let _=a.reduce((E,j)=>j.markClass?E+" "+j.markClass:E,"");o.add(w,k,Mt.mark({class:"cm-lintRange cm-lintRange-"+C+_,diagnostics:a.slice(),inclusiveEnd:a.some(E=>E.to>k)}))}if(c=k,c==m)break;for(let _=0;_<a.length;_++)a[_].to<=c&&a.splice(_--,1)}let p=o.finish();return new th(p,n,df(p))}}function df(t,e=null,n=0){let r=null;return t.between(n,1e9,(s,i,{spec:o})=>{if(!(e&&o.diagnostics.indexOf(e)<0))if(!r)r=new dH(s,i,e||o.diagnostics[0]);else{if(o.diagnostics.indexOf(r.diagnostic)<0)return!1;r=new dH(r.from,i,r.diagnostic)}}),r}function k7e(t,e){let n=e.pos,r=e.end||n,s=t.state.facet(jb).hideOn(t,n,r);if(s!=null)return s;let i=t.startState.doc.lineAt(e.pos);return!!(t.effects.some(o=>o.is(Kse))||t.changes.touchesRange(i.from,Math.max(i.to,r)))}function S7e(t,e){return t.field(Ao,!1)?e:e.concat(zt.appendConfig.of(L7e))}const Kse=zt.define(),Y9=zt.define(),Wse=zt.define(),Ao=Is.define({create(){return new th(Mt.none,null,null)},update(t,e){if(e.docChanged&&t.diagnostics.size){let n=t.diagnostics.map(e.changes),r=null,s=t.panel;if(t.selected){let i=e.changes.mapPos(t.selected.from,1);r=df(n,t.selected.diagnostic,i)||df(n,null,i)}!n.size&&s&&e.state.facet(jb).autoPanel&&(s=null),t=new th(n,s,r)}for(let n of e.effects)if(n.is(Kse)){let r=e.state.facet(jb).autoPanel?n.value.length?Ab.open:null:t.panel;t=th.init(n.value,r,e.state)}else n.is(Y9)?t=new th(t.diagnostics,n.value?Ab.open:null,t.selected):n.is(Wse)&&(t=new th(t.diagnostics,t.panel,n.value));return t},provide:t=>[bb.from(t,e=>e.panel),at.decorations.from(t,e=>e.diagnostics)]}),_7e=Mt.mark({class:"cm-lintRange cm-lintRange-active"});function N7e(t,e,n){let{diagnostics:r}=t.state.field(Ao),s,i=-1,o=-1;r.between(e-(n<0?1:0),e+(n>0?1:0),(c,d,{spec:f})=>{if(e>=c&&e<=d&&(c==d||(e>c||n>0)&&(e<d||n<0)))return s=f.diagnostics,i=c,o=d,!1});let a=t.state.facet(jb).tooltipFilter;return s&&a&&(s=a(s,t.state)),s?{pos:i,end:o,above:t.state.doc.lineAt(i).to<o,create(){return{dom:E7e(t,s)}}}:null}function E7e(t,e){return Xn("ul",{class:"cm-tooltip-lint"},e.map(n=>Jse(t,n,!1)))}const j7e=t=>{let e=t.state.field(Ao,!1);(!e||!e.panel)&&t.dispatch({effects:S7e(t.state,[Y9.of(!0)])});let n=S9(t,Ab.open);return n&&n.dom.querySelector(".cm-panel-lint ul").focus(),!0},fH=t=>{let e=t.state.field(Ao,!1);return!e||!e.panel?!1:(t.dispatch({effects:Y9.of(!1)}),!0)},A7e=t=>{let e=t.state.field(Ao,!1);if(!e)return!1;let n=t.state.selection.main,r=df(e.diagnostics,null,n.to+1);return!r&&(r=df(e.diagnostics,null,0),!r||r.from==n.from&&r.to==n.to)?!1:(t.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),!0)},T7e=[{key:"Mod-Shift-m",run:j7e,preventDefault:!0},{key:"F8",run:A7e}],jb=ut.define({combine(t){return{sources:t.map(e=>e.source).filter(e=>e!=null),...lc(t.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:hH,tooltipFilter:hH,needsRefresh:(e,n)=>e?n?r=>e(r)||n(r):e:n,hideOn:(e,n)=>e?n?(r,s,i)=>e(r,s,i)||n(r,s,i):e:n,autoPanel:(e,n)=>e||n})}}});function hH(t,e){return t?e?(n,r)=>e(t(n,r),r):t:e}function Gse(t){let e=[];if(t)e:for(let{name:n}of t){for(let r=0;r<n.length;r++){let s=n[r];if(/[a-zA-Z]/.test(s)&&!e.some(i=>i.toLowerCase()==s.toLowerCase())){e.push(s);continue e}}e.push("")}return e}function Jse(t,e,n){var r;let s=n?Gse(e.actions):[];return Xn("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},Xn("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(t):e.message),(r=e.actions)===null||r===void 0?void 0:r.map((i,o)=>{let a=!1,c=x=>{if(x.preventDefault(),a)return;a=!0;let y=df(t.state.field(Ao).diagnostics,e);y&&i.apply(t,y.from,y.to)},{name:d}=i,f=s[o]?d.indexOf(s[o]):-1,m=f<0?d:[d.slice(0,f),Xn("u",d.slice(f,f+1)),d.slice(f+1)],p=i.markClass?" "+i.markClass:"";return Xn("button",{type:"button",class:"cm-diagnosticAction"+p,onclick:c,onmousedown:c,"aria-label":` Action: ${d}${f<0?"":` (access key "${s[o]})"`}.`},m)}),e.source&&Xn("div",{class:"cm-diagnosticSource"},e.source))}class M7e extends cc{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return Xn("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class mH{constructor(e,n){this.diagnostic=n,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=Jse(e,n,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class Ab{constructor(e){this.view=e,this.items=[];let n=s=>{if(!(s.ctrlKey||s.altKey||s.metaKey)){if(s.keyCode==27)fH(this.view),this.view.focus();else if(s.keyCode==38||s.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(s.keyCode==40||s.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(s.keyCode==36)this.moveSelection(0);else if(s.keyCode==35)this.moveSelection(this.items.length-1);else if(s.keyCode==13)this.view.focus();else if(s.keyCode>=65&&s.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:i}=this.items[this.selectedIndex],o=Gse(i.actions);for(let a=0;a<o.length;a++)if(o[a].toUpperCase().charCodeAt(0)==s.keyCode){let c=df(this.view.state.field(Ao).diagnostics,i);c&&i.actions[a].apply(e,c.from,c.to)}}else return;s.preventDefault()}},r=s=>{for(let i=0;i<this.items.length;i++)this.items[i].dom.contains(s.target)&&this.moveSelection(i)};this.list=Xn("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:n,onclick:r}),this.dom=Xn("div",{class:"cm-panel-lint"},this.list,Xn("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>fH(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(Ao).selected;if(!e)return-1;for(let n=0;n<this.items.length;n++)if(this.items[n].diagnostic==e.diagnostic)return n;return-1}update(){let{diagnostics:e,selected:n}=this.view.state.field(Ao),r=0,s=!1,i=null,o=new Set;for(e.between(0,this.view.state.doc.length,(a,c,{spec:d})=>{for(let f of d.diagnostics){if(o.has(f))continue;o.add(f);let m=-1,p;for(let x=r;x<this.items.length;x++)if(this.items[x].diagnostic==f){m=x;break}m<0?(p=new mH(this.view,f),this.items.splice(r,0,p),s=!0):(p=this.items[m],m>r&&(this.items.splice(r,m-r),s=!0)),n&&p.diagnostic==n.diagnostic?p.dom.hasAttribute("aria-selected")||(p.dom.setAttribute("aria-selected","true"),i=p):p.dom.hasAttribute("aria-selected")&&p.dom.removeAttribute("aria-selected"),r++}});r<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)s=!0,this.items.pop();this.items.length==0&&(this.items.push(new mH(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),s=!0),i?(this.list.setAttribute("aria-activedescendant",i.id),this.view.requestMeasure({key:this,read:()=>({sel:i.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:a,panel:c})=>{let d=c.height/this.list.offsetHeight;a.top<c.top?this.list.scrollTop-=(c.top-a.top)/d:a.bottom>c.bottom&&(this.list.scrollTop+=(a.bottom-c.bottom)/d)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let e=this.list.firstChild;function n(){let r=e;e=r.nextSibling,r.remove()}for(let r of this.items)if(r.dom.parentNode==this.list){for(;e!=r.dom;)n();e=r.dom.nextSibling}else this.list.insertBefore(r.dom,e);for(;e;)n()}moveSelection(e){if(this.selectedIndex<0)return;let n=this.view.state.field(Ao),r=df(n.diagnostics,this.items[e].diagnostic);r&&this.view.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0,effects:Wse.of(r)})}static open(e){return new Ab(e)}}function R7e(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(t)}</svg>')`}function aC(t){return R7e(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${t}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const O7e=at.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:aC("#d11")},".cm-lintRange-warning":{backgroundImage:aC("orange")},".cm-lintRange-info":{backgroundImage:aC("#999")},".cm-lintRange-hint":{backgroundImage:aC("#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}}});function I7e(t){return t=="error"?4:t=="warning"?3:t=="info"?2:1}function D7e(t){let e="hint",n=1;for(let r of t){let s=I7e(r.severity);s>n&&(n=s,e=r.severity)}return e}const L7e=[Ao,at.decorations.compute([Ao],t=>{let{selected:e,panel:n}=t.field(Ao);return!e||!n||e.from==e.to?Mt.none:Mt.set([_7e.range(e.from,e.to)])}),Y9e(N7e,{hideOn:k7e}),O7e],P7e=[xre(),d6e(),E9e(),I8e(),aDe(),g9e(),w9e(),Cn.allowMultipleSelections.of(!0),W6e(),Pre(dDe,{fallback:!0}),yDe(),f8e(),k8e(),$9e(),V9e(),O9e(),QLe(),$v.of([...g8e,...LLe,...b7e,...H8e,...rDe,...rse,...T7e])],F7e=U.forwardRef(({title:t,children:e},n)=>{const r=Xl(bm);return U.createElement(AR,{delayDuration:100},U.createElement(TR,null,U.createElement(MR,{ref:n,asChild:!0},U.createElement("span",{className:Ke.tooltipTrigger},e)),U.createElement(RR,{container:r==null?void 0:r.current},U.createElement(OR,{className:er(Ke.tooltipContent),sideOffset:10},t))))}),$7e=U.forwardRef(({children:t,className:e,...n},r)=>U.createElement(eJ,{...n,ref:r,className:er(e,Ke.selectItem)},U.createElement(tJ,null,t))),B7e=({title:t,placeholder:e,className:n})=>{const[r,s]=al(sl,Ru);return U.createElement(F7e,{title:t},U.createElement(GG,{"aria-label":e,className:er(Ke.selectTrigger,n),"data-toolbar-item":!0,disabled:r},U.createElement(JG,{placeholder:e}),U.createElement(YG,{className:Ke.selectDropdownArrow},s("arrow_drop_down"))))},z7e=({children:t,className:e=Ke.selectContainer})=>{const n=Xl(bm);return U.createElement(ZG,{container:n==null?void 0:n.current},U.createElement(QG,{className:er(e,"mdxeditor-select-content"),onCloseAutoFocus:r=>{r.preventDefault()},position:"popper"},U.createElement(XG,{"data-editor-dropdown":!0},t)))},V7e=t=>U.createElement(WG,{value:t.value||"",onValueChange:t.onChange,disabled:t.disabled},U.createElement(B7e,{title:t.triggerTitle,placeholder:t.placeholder}),U.createElement(z7e,null,t.items.map((e,n)=>e==="separator"?U.createElement(yxe,{key:n}):U.createElement($7e,{key:n,value:e.value},e.label)))),pH="__EMPTY_VALUE__",Yse=({language:t,nodeKey:e,code:n,focusEmitter:r})=>{const s=Ou(),{parentEditor:i,lexicalNode:o}=m4(),[a,c,d,f,m]=al(sl,uM,dM,Ru,cM),p=FLe(e,"codeblock",t,r),{setCode:x}=m4(),y=U.useRef(null),w=U.useRef(null),k=U.useRef(x);return k.current=x,p.current={getCodemirror:()=>y.current},U.useEffect(()=>{const S=w.current;return(async()=>{const C=[...c,P7e,WLe,xre(),$v.of([PLe]),at.lineWrapping,at.updateListener.of(({state:_})=>{k.current(_.doc.toString())}),at.domEventHandlers({focus:()=>{i.update(()=>{Mr(null)})}})];if(a&&C.push(Cn.readOnly.of(!0)),t!==""&&d){const _=$Le.find(E=>E.name===t||E.alias.includes(t)||E.extensions.includes(t));if(_)try{const E=await _.load();C.push(E.extension)}catch{console.warn("failed to load language support for",t)}}S.innerHTML="",y.current=new at({parent:S,state:Cn.create({doc:n,extensions:C})}),S.addEventListener("keydown",gH)})(),()=>{var C;(C=y.current)==null||C.destroy(),y.current=null,S.removeEventListener("keydown",gH)}},[a,t,...c]),U.createElement("div",{className:Ke.codeMirrorWrapper},U.createElement("div",{className:Ke.codeMirrorToolbar},U.createElement(V7e,{disabled:a,value:t,onChange:S=>{i.update(()=>{o.setLanguage(S===pH?"":S),setTimeout(()=>{i.update(()=>{o.getLatest().select()})})})},triggerTitle:s("codeBlock.selectLanguage","Select code block language"),placeholder:s("codeBlock.inlineLanguage","Language"),items:Object.entries(m).map(([S,C])=>({value:S||pH,label:C}))}),U.createElement("button",{className:Ke.iconButton,type:"button",disabled:a,title:s("codeblock.delete","Delete code block"),onClick:S=>{S.preventDefault(),i.update(()=>{o.remove()})}},f("delete_small"))),U.createElement("div",{ref:w}))};function gH(t){t.stopPropagation()}const cM=mt({js:"JavaScript",ts:"TypeScript",tsx:"TypeScript (React)",jsx:"JavaScript (React)",css:"CSS"}),H7e=Gr(t=>{t.link(t.pipe(H7e,ef(({language:e,code:n})=>({code:n,language:e,meta:""}))),Kte)}),uM=mt([]),dM=mt(!0),U7e=Sa({update(t,e){t.pubIn({[cM]:e==null?void 0:e.codeBlockLanguages,[uM]:(e==null?void 0:e.codeMirrorExtensions)??[],[dM]:(e==null?void 0:e.autoLoadLanguageSupport)??!0})},init(t,e){t.pubIn({[cM]:e==null?void 0:e.codeBlockLanguages,[uM]:(e==null?void 0:e.codeMirrorExtensions)??[],[XRe]:q7e((e==null?void 0:e.codeBlockLanguages)??{}),[dM]:(e==null?void 0:e.autoLoadLanguageSupport)??!0})}});function q7e(t){return{match(e,n){return Object.hasOwn(t,e??"")&&!n},priority:1,Editor:Yse}}function K7e({url:t,title:e,text:n,onSubmit:r,onCancel:s,linkAutocompleteSuggestions:i,showLinkTitleField:o,showAnchorTextField:a}){const{register:c,handleSubmit:d,control:f,setValue:m,reset:p}=wte({values:{url:t,title:e,text:n}}),x=Ou();return U.createElement("form",{onSubmit:y=>{d(r)(y),y.stopPropagation(),y.preventDefault()},onReset:y=>{y.stopPropagation(),s()},onKeyDown:y=>{y.key==="Escape"&&(y.stopPropagation(),s())},className:er(Ke.multiFieldForm,Ke.linkDialogEditForm)},U.createElement("div",{className:Ke.formField},U.createElement("label",{htmlFor:"link-url"},x("createLink.url","URL")),U.createElement($te,{register:c,initialInputValue:t,inputName:"url",suggestions:i,setValue:m,control:f,placeholder:x("createLink.urlPlaceholder","Select or paste an URL"),autofocus:!0})),a?U.createElement("div",{className:Ke.formField},U.createElement("label",{htmlFor:"link-text",title:x("createLink.textTooltip","The text to be displayed for the link")},x("createLink.text","Anchor text")),U.createElement("input",{id:"link-text",className:Ke.textInput,size:40,...c("text")})):null,o?U.createElement("div",{className:Ke.formField},U.createElement("label",{htmlFor:"link-title",title:x("createLink.titleTooltip","The link's title attribute, shown on hover")},x("createLink.title","Link title")),U.createElement("input",{id:"link-title",className:Ke.textInput,size:40,...c("title")})):null,U.createElement("div",{style:{display:"flex",justifyContent:"flex-end",gap:"var(--spacing-2)"}},U.createElement("button",{type:"submit",title:x("createLink.saveTooltip","Set URL"),"aria-label":x("createLink.saveTooltip","Set URL"),className:er(Ke.primaryButton)},x("dialogControls.save","Save")),U.createElement("button",{type:"reset",title:x("createLink.cancelTooltip","Cancel change"),"aria-label":x("createLink.cancelTooltip","Cancel change"),className:er(Ke.secondaryButton)},x("dialogControls.cancel","Cancel"))))}const W7e=()=>{const[t,e,n,r,s,i,o]=al(bm,Sr,Ru,Vi,rie,sie,oie),a=No(Zse),c=No(Qse),d=No(Xse),f=No(eie),m=No(tie);U.useEffect(()=>{const S=()=>{e==null||e.getEditorState().read(()=>{a(!0)})};return window.addEventListener("resize",S),window.addEventListener("scroll",S),()=>{window.removeEventListener("resize",S),window.removeEventListener("scroll",S)}},[e,a]);const[p,x]=U.useState(!1),y=Ou();if(r.type==="inactive")return null;const w=r.rectangle,k=r.type==="preview"&&r.url.startsWith("http");return U.createElement(OS,{open:!0},U.createElement(Mge,{"data-visible":r.type==="edit",className:Ke.linkDialogAnchor,style:{top:`${w.top}px`,left:`${w.left}px`,width:`${w.width}px`,height:`${w.height}px`}}),U.createElement(IS,{container:t==null?void 0:t.current},U.createElement(oG,{className:er(Ke.linkDialogPopoverContent),sideOffset:5,onOpenAutoFocus:S=>{S.preventDefault()},key:r.linkNodeKey},r.type==="edit"&&U.createElement(K7e,{url:r.url,title:r.title,text:r.text,onSubmit:c,onCancel:d.bind(null),linkAutocompleteSuggestions:s,showLinkTitleField:o,showAnchorTextField:r.withAnchorText}),r.type==="preview"&&U.createElement(U.Fragment,null,U.createElement("a",{className:Ke.linkDialogPreviewAnchor,href:r.url,...k?{target:"_blank",rel:"noreferrer"}:{},onClick:S=>{i!==null&&(S.preventDefault(),i(r.url))},title:k?y("linkPreview.open","Open {{url}} in new window",{url:r.url}):r.url},U.createElement("span",null,r.url),k&&n("open_in_new")),U.createElement(dA,{onClick:()=>{f()},title:y("linkPreview.edit","Edit link URL"),"aria-label":y("linkPreview.edit","Edit link URL")},n("edit")),U.createElement(AR,null,U.createElement(TR,{open:p},U.createElement(MR,{asChild:!0},U.createElement(dA,{title:y("linkPreview.copyToClipboard","Copy to clipboard"),"aria-label":y("linkPreview.copyToClipboard","Copy to clipboard"),onClick:()=>{window.navigator.clipboard.writeText(r.url).then(()=>{x(!0),setTimeout(()=>{x(!1)},1e3)})}},n(p?"check":"content_copy"))),U.createElement(RR,{container:t==null?void 0:t.current},U.createElement(OR,{className:er(Ke.tooltipContent),sideOffset:5},y("linkPreview.copied","Copied!"),U.createElement(zJ,null))))),U.createElement(dA,{title:y("linkPreview.remove","Remove link"),"aria-label":y("linkPreview.remove","Remove link"),onClick:()=>{m()}},n("link_off"))),U.createElement(xR,{className:Ke.popoverArrow}))))},dA=U.forwardRef(({className:t,...e},n)=>U.createElement("button",{className:er(Ke.actionButton,t),ref:n,...e}));function fM(t){if(!t)return null;const e=_3e(t);if(e===null)return null;const n=e.getParent();return Wi(n)?n:Wi(e)?e:null}const Zse=Gr(),Vi=mt({type:"inactive"},t=>{t.pub(ob,e=>e.registerCommand(bv,()=>t.getValue(Vi).type==="preview"?(t.pub(Vi,{type:"inactive"}),!0):!1,pr)),t.sub(t.pipe(ab),e=>{e!=="rich-text"&&t.pub(Vi,{type:"inactive"})}),t.pub(ob,e=>e.registerCommand(LO,n=>{if(n.key==="k"&&(Kee?n.metaKey:n.ctrlKey)&&!t.getValue(sl)){const r=Ge();return Fe(r)?(t.pub(nie),n.stopPropagation(),n.preventDefault(),!0):!1}return!1},w3)),t.sub(t.pipe(eie,Ar(Vi,Sr)),([,e,n])=>{if(e.type==="preview")setTimeout(()=>{n==null||n.getEditorState().read(()=>{const r=tr(e.linkNodeKey),s=Wi(r)?r.getTextContent().length>0&&r.getChildrenSize()<=1:!1,i=s&&r?r.getTextContent():"";t.pub(Vi,{type:"edit",initialUrl:e.url,url:e.url,title:e.title,text:i,withAnchorText:s,linkNodeKey:e.linkNodeKey,rectangle:e.rectangle})})});else throw new Error("Cannot switch to edit mode when not in preview mode")}),t.sub(t.pipe(Qse,Ar(Sr,Vi,Bg)),([e,n,r,s])=>{var i,o,a;const c=((i=e.text)==null?void 0:i.trim())??"",d=((o=e.url)==null?void 0:o.trim())??"",f=((a=e.title)==null?void 0:a.trim())??"";if(d!==""){if(s!=null&&s.isCollapsed()){const m=c||f||d;n==null||n.update(()=>{const p=fM(s);if(p)if(Pa(p)){const x=ku(d,{title:f});x.append(ir(c)),p.replace(x),x.select()}else p.setURL(d),p.setTitle(f),xH(p.getFirstChild(),c);else{const x=ku(d,{title:f});x.append(ir(m)),yx([x]),x.select()}},{discrete:!0})}else n==null||n.update(()=>{xH(s==null?void 0:s.anchor.getNode(),c)}),n==null||n.dispatchCommand(zg,{url:d,title:f});t.pub(Vi,{type:"preview",linkNodeKey:r.linkNodeKey,rectangle:r.rectangle,title:f,url:d})}else r.type==="edit"&&r.initialUrl!==""&&(n==null||n.dispatchCommand(zg,null)),t.pub(Vi,{type:"inactive"})}),t.link(t.pipe(Xse,Ar(Vi,Sr),ef(([,e,n])=>{if(e.type==="edit")return n==null||n.focus(),e.initialUrl===""?{type:"inactive"}:{type:"preview",url:e.initialUrl,linkNodeKey:e.linkNodeKey,rectangle:e.rectangle};throw new Error("Cannot cancel edit when not in edit mode")})),Vi),t.link(t.pipe(t.combine(Bg,Zse),Ar(Sr,Vi,sl),ef(([[e],n,r,s])=>{if(Fe(e)&&n&&!s){const i=fM(e);if(!e.isCollapsed())return{type:"inactive"};if(i){const o=Hee(n);return o?{type:"preview",url:i.getURL(),linkNodeKey:i.getKey(),title:i.getTitle(),rectangle:o}:{type:"inactive"}}else return{type:"inactive"}}else return{type:"inactive"}})),Vi)}),Qse=Gr(),Xse=vf();vf();const eie=vf(),tie=vf(t=>{t.sub(t.pipe(tie,Ar(Sr)),([,e])=>{e==null||e.dispatchCommand(zg,null)})}),nie=vf(t=>{t.sub(t.pipe(nie,Ar(Bg,Sr),xv(([,e])=>Fe(e))),([,e,n])=>{n==null||n.focus(()=>{setTimeout(()=>{n.getEditorState().read(()=>{const r=fM(e),s=Hee(n),i=(r==null?void 0:r.getURL())??"",o=(r==null?void 0:r.getURL())??"",a=(r==null?void 0:r.getTitle())??"",c=(r==null?void 0:r.getKey())??"",d=r?r.getTextContent().length>0&&r.getChildrenSize()<=1:!!(e!=null&&e.isCollapsed()),f=d&&r?r.getTextContent():"";t.pub(Vi,{type:"edit",initialUrl:i,url:o,title:a,text:f,withAnchorText:d,linkNodeKey:c,rectangle:s})})})})})}),rie=mt([]),sie=mt(null),iie=mt(null,t=>{t.pub(ob,e=>{function n(r){const[s,i]=t.getValues([sl,iie]);!s||i===null||e.update(()=>{const o=tc(r.target);if(o!==null){const a=Wa(o,c=>c instanceof Iu);a!==null&&i(r,a,a.getURL())}})}return e.registerRootListener((r,s)=>{r&&r.addEventListener("click",n),s&&s.removeEventListener("click",n)})})});function xH(t,e){Ye(t)&&e&&(t.setTextContent(e),t.selectStart())}const oie=mt(!0),G7e=Sa({init(t,e){t.pub(vm,(e==null?void 0:e.LinkDialog)??W7e),t.pub(sie,(e==null?void 0:e.onClickLinkCallback)??null),t.pub(iie,(e==null?void 0:e.onReadOnlyClickLinkCallback)??null),t.pub(oie,(e==null?void 0:e.showLinkTitleField)??!0)},update(t,e={}){t.pub(rie,e.linkAutocompleteSuggestions??[])}});var fA={exports:{}},yH;function J7e(){return yH||(yH=1,(function(t){var e=typeof window<"u"?window:typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?self:{};/**
809
809
  * Prism: Lightweight, robust, elegant syntax highlighting
810
810
  *
@@ -851,7 +851,7 @@ And after you've finished that, hire yourself a Founding Engineer agent`;functio
851
851
  `}),n.push(t[r]);return e&&t.length>0&&n.push({type:"text",value:`
852
852
  `}),n}function mU(t){let e=0,n=t.charCodeAt(e);for(;n===9||n===32;)e++,n=t.charCodeAt(e);return t.slice(e)}function pU(t,e){const n=iVe(t,e),r=n.one(t,void 0),s=rVe(n),i=Array.isArray(r)?{type:"root",children:r}:r||{type:"root",children:[]};return s&&i.children.push({type:"text",value:`
853
853
  `},s),i}function uVe(t,e){return t&&"run"in t?async function(n,r){const s=pU(n,{file:r,...e});await t.run(s,r)}:function(n,r){return pU(n,{file:r,...t||e})}}function gU(t){if(t)throw t}var SA,xU;function dVe(){if(xU)return SA;xU=1;var t=Object.prototype.hasOwnProperty,e=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,s=function(d){return typeof Array.isArray=="function"?Array.isArray(d):e.call(d)==="[object Array]"},i=function(d){if(!d||e.call(d)!=="[object Object]")return!1;var f=t.call(d,"constructor"),m=d.constructor&&d.constructor.prototype&&t.call(d.constructor.prototype,"isPrototypeOf");if(d.constructor&&!f&&!m)return!1;var p;for(p in d);return typeof p>"u"||t.call(d,p)},o=function(d,f){n&&f.name==="__proto__"?n(d,f.name,{enumerable:!0,configurable:!0,value:f.newValue,writable:!0}):d[f.name]=f.newValue},a=function(d,f){if(f==="__proto__")if(t.call(d,f)){if(r)return r(d,f).value}else return;return d[f]};return SA=function c(){var d,f,m,p,x,y,w=arguments[0],k=1,S=arguments.length,C=!1;for(typeof w=="boolean"&&(C=w,w=arguments[1]||{},k=2),(w==null||typeof w!="object"&&typeof w!="function")&&(w={});k<S;++k)if(d=arguments[k],d!=null)for(f in d)m=a(w,f),p=a(d,f),w!==p&&(C&&p&&(i(p)||(x=s(p)))?(x?(x=!1,y=m&&s(m)?m:[]):y=m&&i(m)?m:{},o(w,{name:f,newValue:c(C,y,p)})):typeof p<"u"&&o(w,{name:f,newValue:p}));return w},SA}var fVe=dVe();const _A=ex(fVe);function CM(t){if(typeof t!="object"||t===null)return!1;const e=Object.getPrototypeOf(t);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)}function hVe(){const t=[],e={run:n,use:r};return e;function n(...s){let i=-1;const o=s.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);a(null,...s);function a(c,...d){const f=t[++i];let m=-1;if(c){o(c);return}for(;++m<s.length;)(d[m]===null||d[m]===void 0)&&(d[m]=s[m]);s=d,f?mVe(f,a)(...d):o(null,...d)}}function r(s){if(typeof s!="function")throw new TypeError("Expected `middelware` to be a function, not "+s);return t.push(s),e}}function mVe(t,e){let n;return r;function r(...o){const a=t.length>o.length;let c;a&&o.push(s);try{c=t.apply(this,o)}catch(d){const f=d;if(a&&n)throw f;return s(f)}a||(c&&c.then&&typeof c.then=="function"?c.then(i,s):c instanceof Error?s(c):i(c))}function s(o,...a){n||(n=!0,e(o,...a))}function i(o){s(null,o)}}const kl={basename:pVe,dirname:gVe,extname:xVe,join:yVe,sep:"/"};function pVe(t,e){if(e!==void 0&&typeof e!="string")throw new TypeError('"ext" argument must be a string');Gv(t);let n=0,r=-1,s=t.length,i;if(e===void 0||e.length===0||e.length>t.length){for(;s--;)if(t.codePointAt(s)===47){if(i){n=s+1;break}}else r<0&&(i=!0,r=s+1);return r<0?"":t.slice(n,r)}if(e===t)return"";let o=-1,a=e.length-1;for(;s--;)if(t.codePointAt(s)===47){if(i){n=s+1;break}}else o<0&&(i=!0,o=s+1),a>-1&&(t.codePointAt(s)===e.codePointAt(a--)?a<0&&(r=s):(a=-1,r=o));return n===r?r=o:r<0&&(r=t.length),t.slice(n,r)}function gVe(t){if(Gv(t),t.length===0)return".";let e=-1,n=t.length,r;for(;--n;)if(t.codePointAt(n)===47){if(r){e=n;break}}else r||(r=!0);return e<0?t.codePointAt(0)===47?"/":".":e===1&&t.codePointAt(0)===47?"//":t.slice(0,e)}function xVe(t){Gv(t);let e=t.length,n=-1,r=0,s=-1,i=0,o;for(;e--;){const a=t.codePointAt(e);if(a===47){if(o){r=e+1;break}continue}n<0&&(o=!0,n=e+1),a===46?s<0?s=e:i!==1&&(i=1):s>-1&&(i=-1)}return s<0||n<0||i===0||i===1&&s===n-1&&s===r+1?"":t.slice(s,n)}function yVe(...t){let e=-1,n;for(;++e<t.length;)Gv(t[e]),t[e]&&(n=n===void 0?t[e]:n+"/"+t[e]);return n===void 0?".":bVe(n)}function bVe(t){Gv(t);const e=t.codePointAt(0)===47;let n=vVe(t,!e);return n.length===0&&!e&&(n="."),n.length>0&&t.codePointAt(t.length-1)===47&&(n+="/"),e?"/"+n:n}function vVe(t,e){let n="",r=0,s=-1,i=0,o=-1,a,c;for(;++o<=t.length;){if(o<t.length)a=t.codePointAt(o);else{if(a===47)break;a=47}if(a===47){if(!(s===o-1||i===1))if(s!==o-1&&i===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("/")),s=o,i=0;continue}}else if(n.length>0){n="",r=0,s=o,i=0;continue}}e&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+t.slice(s+1,o):n=t.slice(s+1,o),r=o-s-1;s=o,i=0}else a===46&&i>-1?i++:i=-1}return n}function Gv(t){if(typeof t!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(t))}const wVe={cwd:CVe};function CVe(){return"/"}function kM(t){return!!(t!==null&&typeof t=="object"&&"href"in t&&t.href&&"protocol"in t&&t.protocol&&t.auth===void 0)}function kVe(t){if(typeof t=="string")t=new URL(t);else if(!kM(t)){const e=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+t+"`");throw e.code="ERR_INVALID_ARG_TYPE",e}if(t.protocol!=="file:"){const e=new TypeError("The URL must be of scheme file");throw e.code="ERR_INVALID_URL_SCHEME",e}return SVe(t)}function SVe(t){if(t.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 e=t.pathname;let n=-1;for(;++n<e.length;)if(e.codePointAt(n)===37&&e.codePointAt(n+1)===50){const r=e.codePointAt(n+2);if(r===70||r===102){const s=new TypeError("File URL path must not include encoded / characters");throw s.code="ERR_INVALID_FILE_URL_PATH",s}}return decodeURIComponent(e)}const NA=["history","path","basename","stem","extname","dirname"];class boe{constructor(e){let n;e?kM(e)?n={path:e}:typeof e=="string"||_Ve(e)?n={value:e}:n=e:n={},this.cwd="cwd"in n?"":wVe.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<NA.length;){const i=NA[r];i in n&&n[i]!==void 0&&n[i]!==null&&(this[i]=i==="history"?[...n[i]]:n[i])}let s;for(s in n)NA.includes(s)||(this[s]=n[s])}get basename(){return typeof this.path=="string"?kl.basename(this.path):void 0}set basename(e){jA(e,"basename"),EA(e,"basename"),this.path=kl.join(this.dirname||"",e)}get dirname(){return typeof this.path=="string"?kl.dirname(this.path):void 0}set dirname(e){yU(this.basename,"dirname"),this.path=kl.join(e||"",this.basename)}get extname(){return typeof this.path=="string"?kl.extname(this.path):void 0}set extname(e){if(EA(e,"extname"),yU(this.dirname,"extname"),e){if(e.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(e.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=kl.join(this.dirname,this.stem+(e||""))}get path(){return this.history[this.history.length-1]}set path(e){kM(e)&&(e=kVe(e)),jA(e,"path"),this.path!==e&&this.history.push(e)}get stem(){return typeof this.path=="string"?kl.basename(this.path,this.extname):void 0}set stem(e){jA(e,"stem"),EA(e,"stem"),this.path=kl.join(this.dirname||"",e+(this.extname||""))}fail(e,n,r){const s=this.message(e,n,r);throw s.fatal=!0,s}info(e,n,r){const s=this.message(e,n,r);return s.fatal=void 0,s}message(e,n,r){const s=new Ln(e,n,r);return this.path&&(s.name=this.path+":"+s.name,s.file=this.path),s.fatal=!1,this.messages.push(s),s}toString(e){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(e||void 0).decode(this.value)}}function EA(t,e){if(t&&t.includes(kl.sep))throw new Error("`"+e+"` cannot be a path: did not expect `"+kl.sep+"`")}function jA(t,e){if(!t)throw new Error("`"+e+"` cannot be empty")}function yU(t,e){if(!t)throw new Error("Setting `"+e+"` requires `path` to be set too")}function _Ve(t){return!!(t&&typeof t=="object"&&"byteLength"in t&&"byteOffset"in t)}const NVe=(function(t){const r=this.constructor.prototype,s=r[t],i=function(){return s.apply(i,arguments)};return Object.setPrototypeOf(i,r),i}),EVe={}.hasOwnProperty;class p6 extends NVe{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=hVe()}copy(){const e=new p6;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];e.use(...r)}return e.data(_A(!0,{},this.namespace)),e}data(e,n){return typeof e=="string"?arguments.length===2?(MA("data",this.frozen),this.namespace[e]=n,this):EVe.call(this.namespace,e)&&this.namespace[e]||void 0:e?(MA("data",this.frozen),this.namespace=e,this):this.namespace}freeze(){if(this.frozen)return this;const e=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 s=n.call(e,...r);typeof s=="function"&&this.transformers.use(s)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(e){this.freeze();const n=pC(e),r=this.parser||this.Parser;return AA("parse",r),r(String(n),n)}process(e,n){const r=this;return this.freeze(),AA("process",this.parser||this.Parser),TA("process",this.compiler||this.Compiler),n?s(void 0,n):new Promise(s);function s(i,o){const a=pC(e),c=r.parse(a);r.run(c,a,function(f,m,p){if(f||!m||!p)return d(f);const x=m,y=r.stringify(x,p);TVe(y)?p.value=y:p.result=y,d(f,p)});function d(f,m){f||!m?o(f):i?i(m):n(void 0,m)}}}processSync(e){let n=!1,r;return this.freeze(),AA("processSync",this.parser||this.Parser),TA("processSync",this.compiler||this.Compiler),this.process(e,s),vU("processSync","process",n),r;function s(i,o){n=!0,gU(i),r=o}}run(e,n,r){bU(e),this.freeze();const s=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?i(void 0,r):new Promise(i);function i(o,a){const c=pC(n);s.run(e,c,d);function d(f,m,p){const x=m||e;f?a(f):o?o(x):r(void 0,x,p)}}}runSync(e,n){let r=!1,s;return this.run(e,n,i),vU("runSync","run",r),s;function i(o,a){gU(o),s=a,r=!0}}stringify(e,n){this.freeze();const r=pC(n),s=this.compiler||this.Compiler;return TA("stringify",s),bU(e),s(e,r)}use(e,...n){const r=this.attachers,s=this.namespace;if(MA("use",this.frozen),e!=null)if(typeof e=="function")c(e,n);else if(typeof e=="object")Array.isArray(e)?a(e):o(e);else throw new TypeError("Expected usable value, not `"+e+"`");return this;function i(d){if(typeof d=="function")c(d,[]);else if(typeof d=="object")if(Array.isArray(d)){const[f,...m]=d;c(f,m)}else o(d);else throw new TypeError("Expected usable value, not `"+d+"`")}function o(d){if(!("plugins"in d)&&!("settings"in d))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");a(d.plugins),d.settings&&(s.settings=_A(!0,s.settings,d.settings))}function a(d){let f=-1;if(d!=null)if(Array.isArray(d))for(;++f<d.length;){const m=d[f];i(m)}else throw new TypeError("Expected a list of plugins, not `"+d+"`")}function c(d,f){let m=-1,p=-1;for(;++m<r.length;)if(r[m][0]===d){p=m;break}if(p===-1)r.push([d,...f]);else if(f.length>0){let[x,...y]=f;const w=r[p][1];CM(w)&&CM(x)&&(x=_A(!0,w,x)),r[p]=[d,x,...y]}}}}const jVe=new p6().freeze();function AA(t,e){if(typeof e!="function")throw new TypeError("Cannot `"+t+"` without `parser`")}function TA(t,e){if(typeof e!="function")throw new TypeError("Cannot `"+t+"` without `compiler`")}function MA(t,e){if(e)throw new Error("Cannot call `"+t+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function bU(t){if(!CM(t)||typeof t.type!="string")throw new TypeError("Expected node, got `"+t+"`")}function vU(t,e,n){if(!n)throw new Error("`"+t+"` finished async. Use `"+e+"` instead")}function pC(t){return AVe(t)?t:new boe(t)}function AVe(t){return!!(t&&typeof t=="object"&&"message"in t&&"messages"in t)}function TVe(t){return typeof t=="string"||MVe(t)}function MVe(t){return!!(t&&typeof t=="object"&&"byteLength"in t&&"byteOffset"in t)}const RVe="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",wU=[],CU={allowDangerousHtml:!0},OVe=/^(https?|ircs?|mailto|xmpp)$/i,IVe=[{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 DVe(t){const e=LVe(t),n=PVe(t);return FVe(e.runSync(e.parse(n),n),t)}function LVe(t){const e=t.rehypePlugins||wU,n=t.remarkPlugins||wU,r=t.remarkRehypeOptions?{...t.remarkRehypeOptions,...CU}:CU;return jVe().use(Sze).use(n).use(uVe,r).use(e)}function PVe(t){const e=t.children||"",n=new boe;return typeof e=="string"&&(n.value=e),n}function FVe(t,e){const n=e.allowedElements,r=e.allowElement,s=e.components,i=e.disallowedElements,o=e.skipHtml,a=e.unwrapDisallowed,c=e.urlTransform||$Ve;for(const f of IVe)Object.hasOwn(e,f.from)&&(""+f.from+(f.to?"use `"+f.to+"` instead":"remove it")+RVe+f.id,void 0);return xI(t,d),lze(t,{Fragment:l.Fragment,components:s,ignoreInvalidStyle:!0,jsx:l.jsx,jsxs:l.jsxs,passKeys:!0,passNode:!0});function d(f,m,p){if(f.type==="raw"&&p&&typeof m=="number")return o?p.children.splice(m,1):p.children[m]={type:"text",value:f.value},m;if(f.type==="element"){let x;for(x in kA)if(Object.hasOwn(kA,x)&&Object.hasOwn(f.properties,x)){const y=f.properties[x],w=kA[x];(w===null||w.includes(f.tagName))&&(f.properties[x]=c(String(y||""),x,f))}}if(f.type==="element"){let x=n?!n.includes(f.tagName):i?i.includes(f.tagName):!1;if(!x&&r&&typeof m=="number"&&(x=!r(f,m,p)),x&&p&&typeof m=="number")return a&&f.children?p.children.splice(m,1,...f.children):p.children.splice(m,1),m}}}function $Ve(t){const e=t.indexOf(":"),n=t.indexOf("?"),r=t.indexOf("#"),s=t.indexOf("/");return e===-1||s!==-1&&e>s||n!==-1&&e>n||r!==-1&&e>r||OVe.test(t.slice(0,e))?t:""}function BVe(t,e,n){const s=R_((n||{}).ignore||[]),i=zVe(e);let o=-1;for(;++o<i.length;)AX(t,"text",a);function a(d,f){let m=-1,p;for(;++m<f.length;){const x=f[m],y=p?p.children:void 0;if(s(x,y?y.indexOf(x):void 0,p))return;p=x}if(p)return c(d,f)}function c(d,f){const m=f[f.length-1],p=i[o][0],x=i[o][1];let y=0;const k=m.children.indexOf(d);let S=!1,C=[];p.lastIndex=0;let _=p.exec(d.value);for(;_;){const E=_.index,j={index:_.index,input:_.input,stack:[...f,d]};let R=x(..._,j);if(typeof R=="string"&&(R=R.length>0?{type:"text",value:R}:void 0),R===!1?p.lastIndex=E+1:(y!==E&&C.push({type:"text",value:d.value.slice(y,E)}),Array.isArray(R)?C.push(...R):R&&C.push(R),y=E+_[0].length,S=!0),!p.global)break;_=p.exec(d.value)}return S?(y<d.value.length&&C.push({type:"text",value:d.value.slice(y)}),m.children.splice(k,1,...C)):C=[d],k+C.length}}function zVe(t){const e=[];if(!Array.isArray(t))throw new TypeError("Expected find and replace tuple or list of tuples");const n=!t[0]||Array.isArray(t[0])?t:[t];let r=-1;for(;++r<n.length;){const s=n[r];e.push([VVe(s[0]),HVe(s[1])])}return e}function VVe(t){return typeof t=="string"?new RegExp(zRe(t),"g"):t}function HVe(t){return typeof t=="function"?t:function(){return t}}const RA="phrasing",OA=["autolink","link","image","label"];function UVe(){return{transforms:[ZVe],enter:{literalAutolink:KVe,literalAutolinkEmail:IA,literalAutolinkHttp:IA,literalAutolinkWww:IA},exit:{literalAutolink:YVe,literalAutolinkEmail:JVe,literalAutolinkHttp:WVe,literalAutolinkWww:GVe}}}function qVe(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:RA,notInConstruct:OA},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:RA,notInConstruct:OA},{character:":",before:"[ps]",after:"\\/",inConstruct:RA,notInConstruct:OA}]}}function KVe(t){this.enter({type:"link",title:null,url:"",children:[]},t)}function IA(t){this.config.enter.autolinkProtocol.call(this,t)}function WVe(t){this.config.exit.autolinkProtocol.call(this,t)}function GVe(t){this.config.exit.data.call(this,t);const e=this.stack[this.stack.length-1];e.type,e.url="http://"+this.sliceSerialize(t)}function JVe(t){this.config.exit.autolinkEmail.call(this,t)}function YVe(t){this.exit(t)}function ZVe(t){BVe(t,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,QVe],[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)","gu"),XVe]],{ignore:["link","linkReference"]})}function QVe(t,e,n,r,s){let i="";if(!voe(s)||(/^w/i.test(e)&&(n=e+n,e="",i="http://"),!eHe(n)))return!1;const o=tHe(n+r);if(!o[0])return!1;const a={type:"link",title:null,url:i+e+o[0],children:[{type:"text",value:e+o[0]}]};return o[1]?[a,{type:"text",value:o[1]}]:a}function XVe(t,e,n,r){return!voe(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+e+"@"+n,children:[{type:"text",value:e+"@"+n}]}}function eHe(t){const e=t.split(".");return!(e.length<2||e[e.length-1]&&(/_/.test(e[e.length-1])||!/[a-zA-Z\d]/.test(e[e.length-1]))||e[e.length-2]&&(/_/.test(e[e.length-2])||!/[a-zA-Z\d]/.test(e[e.length-2])))}function tHe(t){const e=/[!"&'),.:;<>?\]}]+$/.exec(t);if(!e)return[t,void 0];t=t.slice(0,e.index);let n=e[0],r=n.indexOf(")");const s=lk(t,"(");let i=lk(t,")");for(;r!==-1&&s>i;)t+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),i++;return[t,n]}function voe(t,e){const n=t.input.charCodeAt(t.index-1);return(t.index===0||yi(n)||M_(n))&&(!e||n!==47)}woe.peek=uHe;function nHe(){this.buffer()}function rHe(t){this.enter({type:"footnoteReference",identifier:"",label:""},t)}function sHe(){this.buffer()}function iHe(t){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},t)}function oHe(t){const e=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ga(this.sliceSerialize(t)).toLowerCase(),n.label=e}function aHe(t){this.exit(t)}function lHe(t){const e=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Ga(this.sliceSerialize(t)).toLowerCase(),n.label=e}function cHe(t){this.exit(t)}function uHe(){return"["}function woe(t,e,n,r){const s=n.createTracker(r);let i=s.move("[^");const o=n.enter("footnoteReference"),a=n.enter("reference");return i+=s.move(n.safe(n.associationId(t),{after:"]",before:i})),a(),o(),i+=s.move("]"),i}function dHe(){return{enter:{gfmFootnoteCallString:nHe,gfmFootnoteCall:rHe,gfmFootnoteDefinitionLabelString:sHe,gfmFootnoteDefinition:iHe},exit:{gfmFootnoteCallString:oHe,gfmFootnoteCall:aHe,gfmFootnoteDefinitionLabelString:lHe,gfmFootnoteDefinition:cHe}}}function fHe(t){let e=!1;return t&&t.firstLineBlank&&(e=!0),{handlers:{footnoteDefinition:n,footnoteReference:woe},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,s,i,o){const a=i.createTracker(o);let c=a.move("[^");const d=i.enter("footnoteDefinition"),f=i.enter("label");return c+=a.move(i.safe(i.associationId(r),{before:c,after:"]"})),f(),c+=a.move("]:"),r.children&&r.children.length>0&&(a.shift(4),c+=a.move((e?`
854
- `:" ")+i.indentLines(i.containerFlow(r,a.current()),e?Coe:hHe))),d(),c}}function hHe(t,e,n){return e===0?t:Coe(t,e,n)}function Coe(t,e,n){return(n?"":" ")+t}function mHe(){return[UVe(),dHe(),cX(),ete(),Qee()]}function pHe(t){return{extensions:[qVe(),fHe(t),uX(),tte(t),Xee()]}}const gHe={tokenize:CHe,partial:!0},koe={tokenize:kHe,partial:!0},Soe={tokenize:SHe,partial:!0},_oe={tokenize:_He,partial:!0},xHe={tokenize:NHe,partial:!0},Noe={name:"wwwAutolink",tokenize:vHe,previous:joe},Eoe={name:"protocolAutolink",tokenize:wHe,previous:Aoe},$u={name:"emailAutolink",tokenize:bHe,previous:Toe},uc={};function yHe(){return{text:uc}}let Jf=48;for(;Jf<123;)uc[Jf]=$u,Jf++,Jf===58?Jf=65:Jf===91&&(Jf=97);uc[43]=$u;uc[45]=$u;uc[46]=$u;uc[95]=$u;uc[72]=[$u,Eoe];uc[104]=[$u,Eoe];uc[87]=[$u,Noe];uc[119]=[$u,Noe];function bHe(t,e,n){const r=this;let s,i;return o;function o(m){return!SM(m)||!Toe.call(r,r.previous)||g6(r.events)?n(m):(t.enter("literalAutolink"),t.enter("literalAutolinkEmail"),a(m))}function a(m){return SM(m)?(t.consume(m),a):m===64?(t.consume(m),c):n(m)}function c(m){return m===46?t.check(xHe,f,d)(m):m===45||m===95||ri(m)?(i=!0,t.consume(m),c):f(m)}function d(m){return t.consume(m),s=!0,c}function f(m){return i&&s&&wi(r.previous)?(t.exit("literalAutolinkEmail"),t.exit("literalAutolink"),e(m)):n(m)}}function vHe(t,e,n){const r=this;return s;function s(o){return o!==87&&o!==119||!joe.call(r,r.previous)||g6(r.events)?n(o):(t.enter("literalAutolink"),t.enter("literalAutolinkWww"),t.check(gHe,t.attempt(koe,t.attempt(Soe,i),n),n)(o))}function i(o){return t.exit("literalAutolinkWww"),t.exit("literalAutolink"),e(o)}}function wHe(t,e,n){const r=this;let s="",i=!1;return o;function o(m){return(m===72||m===104)&&Aoe.call(r,r.previous)&&!g6(r.events)?(t.enter("literalAutolink"),t.enter("literalAutolinkHttp"),s+=String.fromCodePoint(m),t.consume(m),a):n(m)}function a(m){if(wi(m)&&s.length<5)return s+=String.fromCodePoint(m),t.consume(m),a;if(m===58){const p=s.toLowerCase();if(p==="http"||p==="https")return t.consume(m),c}return n(m)}function c(m){return m===47?(t.consume(m),i?d:(i=!0,c)):n(m)}function d(m){return m===null||ak(m)||kn(m)||yi(m)||M_(m)?n(m):t.attempt(koe,t.attempt(Soe,f),n)(m)}function f(m){return t.exit("literalAutolinkHttp"),t.exit("literalAutolink"),e(m)}}function CHe(t,e,n){let r=0;return s;function s(o){return(o===87||o===119)&&r<3?(r++,t.consume(o),s):o===46&&r===3?(t.consume(o),i):n(o)}function i(o){return o===null?n(o):e(o)}}function kHe(t,e,n){let r,s,i;return o;function o(d){return d===46||d===95?t.check(_oe,c,a)(d):d===null||kn(d)||yi(d)||d!==45&&M_(d)?c(d):(i=!0,t.consume(d),o)}function a(d){return d===95?r=!0:(s=r,r=void 0),t.consume(d),o}function c(d){return s||r||!i?n(d):e(d)}}function SHe(t,e){let n=0,r=0;return s;function s(o){return o===40?(n++,t.consume(o),s):o===41&&r<n?i(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?t.check(_oe,e,i)(o):o===null||kn(o)||yi(o)?e(o):(t.consume(o),s)}function i(o){return o===41&&r++,t.consume(o),s}}function _He(t,e,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(t.consume(a),r):a===38?(t.consume(a),i):a===93?(t.consume(a),s):a===60||a===null||kn(a)||yi(a)?e(a):n(a)}function s(a){return a===null||a===40||a===91||kn(a)||yi(a)?e(a):r(a)}function i(a){return wi(a)?o(a):n(a)}function o(a){return a===59?(t.consume(a),r):wi(a)?(t.consume(a),o):n(a)}}function NHe(t,e,n){return r;function r(i){return t.consume(i),s}function s(i){return ri(i)?n(i):e(i)}}function joe(t){return t===null||t===40||t===42||t===95||t===91||t===93||t===126||kn(t)}function Aoe(t){return!wi(t)}function Toe(t){return!(t===47||SM(t))}function SM(t){return t===43||t===45||t===46||t===95||ri(t)}function g6(t){let e=t.length,n=!1;for(;e--;){const r=t[e][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return t.length>0&&!n&&(t[t.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const EHe={tokenize:DHe,partial:!0};function jHe(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:RHe,continuation:{tokenize:OHe},exit:IHe}},text:{91:{name:"gfmFootnoteCall",tokenize:MHe},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:AHe,resolveTo:THe}}}}function AHe(t,e,n){const r=this;let s=r.events.length;const i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;s--;){const c=r.events[s][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 a;function a(c){if(!o||!o._balanced)return n(c);const d=Ga(r.sliceSerialize({start:o.end,end:r.now()}));return d.codePointAt(0)!==94||!i.includes(d.slice(1))?n(c):(t.enter("gfmFootnoteCallLabelMarker"),t.consume(c),t.exit("gfmFootnoteCallLabelMarker"),e(c))}}function THe(t,e){let n=t.length;for(;n--;)if(t[n][1].type==="labelImage"&&t[n][0]==="enter"){t[n][1];break}t[n+1][1].type="data",t[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},t[n+3][1].start),end:Object.assign({},t[t.length-1][1].end)},s={type:"gfmFootnoteCallMarker",start:Object.assign({},t[n+3][1].end),end:Object.assign({},t[n+3][1].end)};s.end.column++,s.end.offset++,s.end._bufferIndex++;const i={type:"gfmFootnoteCallString",start:Object.assign({},s.end),end:Object.assign({},t[t.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},i.start),end:Object.assign({},i.end)},a=[t[n+1],t[n+2],["enter",r,e],t[n+3],t[n+4],["enter",s,e],["exit",s,e],["enter",i,e],["enter",o,e],["exit",o,e],["exit",i,e],t[t.length-2],t[t.length-1],["exit",r,e]];return t.splice(n,t.length-n+1,...a),t}function MHe(t,e,n){const r=this,s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i=0,o;return a;function a(m){return t.enter("gfmFootnoteCall"),t.enter("gfmFootnoteCallLabelMarker"),t.consume(m),t.exit("gfmFootnoteCallLabelMarker"),c}function c(m){return m!==94?n(m):(t.enter("gfmFootnoteCallMarker"),t.consume(m),t.exit("gfmFootnoteCallMarker"),t.enter("gfmFootnoteCallString"),t.enter("chunkString").contentType="string",d)}function d(m){if(i>999||m===93&&!o||m===null||m===91||kn(m))return n(m);if(m===93){t.exit("chunkString");const p=t.exit("gfmFootnoteCallString");return s.includes(Ga(r.sliceSerialize(p)))?(t.enter("gfmFootnoteCallLabelMarker"),t.consume(m),t.exit("gfmFootnoteCallLabelMarker"),t.exit("gfmFootnoteCall"),e):n(m)}return kn(m)||(o=!0),i++,t.consume(m),m===92?f:d}function f(m){return m===91||m===92||m===93?(t.consume(m),i++,d):d(m)}}function RHe(t,e,n){const r=this,s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i,o=0,a;return c;function c(y){return t.enter("gfmFootnoteDefinition")._container=!0,t.enter("gfmFootnoteDefinitionLabel"),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(y),t.exit("gfmFootnoteDefinitionLabelMarker"),d}function d(y){return y===94?(t.enter("gfmFootnoteDefinitionMarker"),t.consume(y),t.exit("gfmFootnoteDefinitionMarker"),t.enter("gfmFootnoteDefinitionLabelString"),t.enter("chunkString").contentType="string",f):n(y)}function f(y){if(o>999||y===93&&!a||y===null||y===91||kn(y))return n(y);if(y===93){t.exit("chunkString");const w=t.exit("gfmFootnoteDefinitionLabelString");return i=Ga(r.sliceSerialize(w)),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(y),t.exit("gfmFootnoteDefinitionLabelMarker"),t.exit("gfmFootnoteDefinitionLabel"),p}return kn(y)||(a=!0),o++,t.consume(y),y===92?m:f}function m(y){return y===91||y===92||y===93?(t.consume(y),o++,f):f(y)}function p(y){return y===58?(t.enter("definitionMarker"),t.consume(y),t.exit("definitionMarker"),s.includes(i)||s.push(i),dn(t,x,"gfmFootnoteDefinitionWhitespace")):n(y)}function x(y){return e(y)}}function OHe(t,e,n){return t.check(Av,e,t.attempt(EHe,e,n))}function IHe(t){t.exit("gfmFootnoteDefinition")}function DHe(t,e,n){const r=this;return dn(t,s,"gfmFootnoteDefinitionIndent",5);function s(i){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?e(i):n(i)}}function LHe(t){return GX([yHe(),jHe(),lX(t),nte(),Zee()])}const PHe={};function FHe(t){const e=this,n=t||PHe,r=e.data(),s=r.micromarkExtensions||(r.micromarkExtensions=[]),i=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);s.push(LHe(n)),i.push(mHe()),o.push(pHe(n))}let DA=null;function $He(){return DA||(DA=Ae(()=>import("./mermaid.core-CqZAL-kB.js").then(t=>t.bC),[]).then(t=>t.default)),DA}function Moe(t){return t==null?"":typeof t=="string"||typeof t=="number"?String(t):Array.isArray(t)?t.map(e=>Moe(e)).join(""):""}function BHe(t){if(!v.isValidElement(t))return null;const e=t.props;return typeof e.className!="string"||!/\blanguage-mermaid\b/i.test(e.className)?null:Moe(e.children).replace(/\n$/,"")}function zHe(t){const e=/^#([0-9a-f]{6})$/i.exec(t.trim());if(!e)return null;const n=e[1];return{r:parseInt(n.slice(0,2),16),g:parseInt(n.slice(2,4),16),b:parseInt(n.slice(4,6),16)}}function VHe(t){if(!t)return;const e=zHe(t);if(!e)return;const n=(.299*e.r+.587*e.g+.114*e.b)/255;return{borderColor:t,backgroundColor:`rgba(${e.r}, ${e.g}, ${e.b}, 0.22)`,color:n>.55?"#111827":"#f8fafc"}}function HHe({source:t,darkMode:e}){const n=v.useId().replace(/[^a-zA-Z0-9_-]/g,""),[r,s]=v.useState(null),[i,o]=v.useState(null);return v.useEffect(()=>{let a=!0;return s(null),o(null),$He().then(async c=>{c.initialize({startOnLoad:!1,securityLevel:"strict",theme:e?"dark":"default",fontFamily:"inherit",suppressErrorRendering:!0});const d=await c.render(`paperclip-mermaid-${n}`,t);a&&s(d.svg)}).catch(c=>{if(!a)return;const d=c instanceof Error&&c.message?c.message:"Failed to render Mermaid diagram.";o(d)}),()=>{a=!1}},[e,n,t]),l.jsx("div",{className:"paperclip-mermaid",children:r?l.jsx("div",{dangerouslySetInnerHTML:{__html:r}}):l.jsxs(l.Fragment,{children:[l.jsx("p",{className:re("paperclip-mermaid-status",i&&"paperclip-mermaid-status-error"),children:i?`Unable to render Mermaid diagram: ${i}`:"Rendering Mermaid diagram..."}),l.jsx("pre",{className:"paperclip-mermaid-source",children:l.jsx("code",{className:"language-mermaid",children:t})})]})})}function i5({children:t,className:e}){const{theme:n}=Mie();return l.jsx("div",{className:re("prose prose-sm max-w-none prose-p:my-2 prose-p:leading-[1.4] prose-ul:my-1.5 prose-ol:my-1.5 prose-li:my-0.5 prose-li:leading-[1.4] prose-pre:my-2 prose-pre:whitespace-pre-wrap prose-pre:break-words prose-headings:my-2 prose-headings:text-sm prose-blockquote:leading-[1.4] prose-table:my-2 prose-th:px-3 prose-th:py-1.5 prose-td:px-3 prose-td:py-1.5 prose-code:break-all [&_ul]:list-disc [&_ul]:pl-5 [&_ol]:list-decimal [&_ol]:pl-5 [&_li]:list-item",n==="dark"&&"prose-invert",e),children:l.jsx(DVe,{remarkPlugins:[FHe],components:{pre:({node:r,children:s,...i})=>{const o=BHe(s);return o?l.jsx(HHe,{source:o,darkMode:n==="dark"}):l.jsx("pre",{...i,children:s})},a:({href:r,children:s})=>{const i=r?yY(r):null;if(i){const o=s;return l.jsx("a",{href:`/projects/${i.projectId}`,className:"paperclip-project-mention-chip",style:VHe(i.color),children:o})}return l.jsx("a",{href:r,rel:"noreferrer",children:s})}},children:t})})}function kU({text:t,children:e,className:n,copiedLabel:r="Copied!"}){const[s,i]=v.useState(!1),[o,a]=v.useState(r),c=v.useRef(void 0),d=v.useRef(null),f=v.useCallback(async()=>{try{await navigator.clipboard.writeText(t),a(r)}catch{a("Copy failed")}clearTimeout(c.current),i(!0),c.current=setTimeout(()=>i(!1),1500)},[r,t]);return l.jsxs("span",{className:"relative inline-flex",children:[l.jsx("button",{ref:d,type:"button",className:re("cursor-copy hover:text-foreground transition-colors",n),onClick:f,children:e??t}),l.jsx("span",{role:"status","aria-live":"polite",className:re("pointer-events-none absolute left-1/2 -translate-x-1/2 bottom-full mb-1.5 rounded-md bg-foreground text-background px-2 py-1 text-xs whitespace-nowrap transition-opacity duration-300",s?"opacity-100":"opacity-0"),children:o})]})}function Roe(){const[t,e]=v.useState(!1);v.useEffect(()=>{const r=document.getElementById("main-content");if(!r)return;const s=()=>{const i=r.scrollHeight-r.scrollTop-r.clientHeight;e(i>300)};return s(),r.addEventListener("scroll",s,{passive:!0}),()=>r.removeEventListener("scroll",s)},[]);const n=v.useCallback(()=>{const r=document.getElementById("main-content");r&&r.scrollTo({top:r.scrollHeight,behavior:"smooth"})},[]);return t?l.jsx("button",{onClick:n,className:"fixed bottom-[calc(1.5rem+5rem+env(safe-area-inset-bottom))] right-6 z-40 flex h-9 w-9 items-center justify-center rounded-full border border-border bg-background shadow-md hover:bg-accent transition-colors md:bottom-6","aria-label":"Scroll to bottom",children:l.jsx(qR,{className:"h-4 w-4"})}):null}const Ooe={succeeded:{icon:WR,color:"text-green-600 dark:text-green-400"},failed:{icon:GR,color:"text-red-600 dark:text-red-400"},running:{icon:ty,color:"text-cyan-600 dark:text-cyan-400"},queued:{icon:Ng,color:"text-yellow-600 dark:text-yellow-400"},timed_out:{icon:twe,color:"text-orange-600 dark:text-orange-400"},cancelled:{icon:F1e,color:"text-neutral-500 dark:text-neutral-400"}},UHe="***REDACTED***",qHe=/(api[-_]?key|access[-_]?token|auth(?:_?token)?|authorization|bearer|secret|passwd|password|credential|jwt|private[-_]?key|cookie|connectionstring)/i,KHe=/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)?$/;function WHe(t,e){return qHe.test(t)?!0:typeof e!="string"?!1:KHe.test(e)}function GHe(t,e){if(typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.type==="secret_ref")return"***SECRET_REF***";if(WHe(t,e))return UHe;if(e==null)return"";if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}function JHe(t){const e=ng(t);if(!e)return"<unable-to-parse>";const n=Object.keys(e);return n.length===0?"<empty>":n.sort().map(r=>`${r}=${GHe(r,e[r])}`).join(`
854
+ `:" ")+i.indentLines(i.containerFlow(r,a.current()),e?Coe:hHe))),d(),c}}function hHe(t,e,n){return e===0?t:Coe(t,e,n)}function Coe(t,e,n){return(n?"":" ")+t}function mHe(){return[UVe(),dHe(),cX(),ete(),Qee()]}function pHe(t){return{extensions:[qVe(),fHe(t),uX(),tte(t),Xee()]}}const gHe={tokenize:CHe,partial:!0},koe={tokenize:kHe,partial:!0},Soe={tokenize:SHe,partial:!0},_oe={tokenize:_He,partial:!0},xHe={tokenize:NHe,partial:!0},Noe={name:"wwwAutolink",tokenize:vHe,previous:joe},Eoe={name:"protocolAutolink",tokenize:wHe,previous:Aoe},$u={name:"emailAutolink",tokenize:bHe,previous:Toe},uc={};function yHe(){return{text:uc}}let Jf=48;for(;Jf<123;)uc[Jf]=$u,Jf++,Jf===58?Jf=65:Jf===91&&(Jf=97);uc[43]=$u;uc[45]=$u;uc[46]=$u;uc[95]=$u;uc[72]=[$u,Eoe];uc[104]=[$u,Eoe];uc[87]=[$u,Noe];uc[119]=[$u,Noe];function bHe(t,e,n){const r=this;let s,i;return o;function o(m){return!SM(m)||!Toe.call(r,r.previous)||g6(r.events)?n(m):(t.enter("literalAutolink"),t.enter("literalAutolinkEmail"),a(m))}function a(m){return SM(m)?(t.consume(m),a):m===64?(t.consume(m),c):n(m)}function c(m){return m===46?t.check(xHe,f,d)(m):m===45||m===95||ri(m)?(i=!0,t.consume(m),c):f(m)}function d(m){return t.consume(m),s=!0,c}function f(m){return i&&s&&wi(r.previous)?(t.exit("literalAutolinkEmail"),t.exit("literalAutolink"),e(m)):n(m)}}function vHe(t,e,n){const r=this;return s;function s(o){return o!==87&&o!==119||!joe.call(r,r.previous)||g6(r.events)?n(o):(t.enter("literalAutolink"),t.enter("literalAutolinkWww"),t.check(gHe,t.attempt(koe,t.attempt(Soe,i),n),n)(o))}function i(o){return t.exit("literalAutolinkWww"),t.exit("literalAutolink"),e(o)}}function wHe(t,e,n){const r=this;let s="",i=!1;return o;function o(m){return(m===72||m===104)&&Aoe.call(r,r.previous)&&!g6(r.events)?(t.enter("literalAutolink"),t.enter("literalAutolinkHttp"),s+=String.fromCodePoint(m),t.consume(m),a):n(m)}function a(m){if(wi(m)&&s.length<5)return s+=String.fromCodePoint(m),t.consume(m),a;if(m===58){const p=s.toLowerCase();if(p==="http"||p==="https")return t.consume(m),c}return n(m)}function c(m){return m===47?(t.consume(m),i?d:(i=!0,c)):n(m)}function d(m){return m===null||ak(m)||kn(m)||yi(m)||M_(m)?n(m):t.attempt(koe,t.attempt(Soe,f),n)(m)}function f(m){return t.exit("literalAutolinkHttp"),t.exit("literalAutolink"),e(m)}}function CHe(t,e,n){let r=0;return s;function s(o){return(o===87||o===119)&&r<3?(r++,t.consume(o),s):o===46&&r===3?(t.consume(o),i):n(o)}function i(o){return o===null?n(o):e(o)}}function kHe(t,e,n){let r,s,i;return o;function o(d){return d===46||d===95?t.check(_oe,c,a)(d):d===null||kn(d)||yi(d)||d!==45&&M_(d)?c(d):(i=!0,t.consume(d),o)}function a(d){return d===95?r=!0:(s=r,r=void 0),t.consume(d),o}function c(d){return s||r||!i?n(d):e(d)}}function SHe(t,e){let n=0,r=0;return s;function s(o){return o===40?(n++,t.consume(o),s):o===41&&r<n?i(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?t.check(_oe,e,i)(o):o===null||kn(o)||yi(o)?e(o):(t.consume(o),s)}function i(o){return o===41&&r++,t.consume(o),s}}function _He(t,e,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(t.consume(a),r):a===38?(t.consume(a),i):a===93?(t.consume(a),s):a===60||a===null||kn(a)||yi(a)?e(a):n(a)}function s(a){return a===null||a===40||a===91||kn(a)||yi(a)?e(a):r(a)}function i(a){return wi(a)?o(a):n(a)}function o(a){return a===59?(t.consume(a),r):wi(a)?(t.consume(a),o):n(a)}}function NHe(t,e,n){return r;function r(i){return t.consume(i),s}function s(i){return ri(i)?n(i):e(i)}}function joe(t){return t===null||t===40||t===42||t===95||t===91||t===93||t===126||kn(t)}function Aoe(t){return!wi(t)}function Toe(t){return!(t===47||SM(t))}function SM(t){return t===43||t===45||t===46||t===95||ri(t)}function g6(t){let e=t.length,n=!1;for(;e--;){const r=t[e][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return t.length>0&&!n&&(t[t.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const EHe={tokenize:DHe,partial:!0};function jHe(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:RHe,continuation:{tokenize:OHe},exit:IHe}},text:{91:{name:"gfmFootnoteCall",tokenize:MHe},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:AHe,resolveTo:THe}}}}function AHe(t,e,n){const r=this;let s=r.events.length;const i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;s--;){const c=r.events[s][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 a;function a(c){if(!o||!o._balanced)return n(c);const d=Ga(r.sliceSerialize({start:o.end,end:r.now()}));return d.codePointAt(0)!==94||!i.includes(d.slice(1))?n(c):(t.enter("gfmFootnoteCallLabelMarker"),t.consume(c),t.exit("gfmFootnoteCallLabelMarker"),e(c))}}function THe(t,e){let n=t.length;for(;n--;)if(t[n][1].type==="labelImage"&&t[n][0]==="enter"){t[n][1];break}t[n+1][1].type="data",t[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},t[n+3][1].start),end:Object.assign({},t[t.length-1][1].end)},s={type:"gfmFootnoteCallMarker",start:Object.assign({},t[n+3][1].end),end:Object.assign({},t[n+3][1].end)};s.end.column++,s.end.offset++,s.end._bufferIndex++;const i={type:"gfmFootnoteCallString",start:Object.assign({},s.end),end:Object.assign({},t[t.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},i.start),end:Object.assign({},i.end)},a=[t[n+1],t[n+2],["enter",r,e],t[n+3],t[n+4],["enter",s,e],["exit",s,e],["enter",i,e],["enter",o,e],["exit",o,e],["exit",i,e],t[t.length-2],t[t.length-1],["exit",r,e]];return t.splice(n,t.length-n+1,...a),t}function MHe(t,e,n){const r=this,s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i=0,o;return a;function a(m){return t.enter("gfmFootnoteCall"),t.enter("gfmFootnoteCallLabelMarker"),t.consume(m),t.exit("gfmFootnoteCallLabelMarker"),c}function c(m){return m!==94?n(m):(t.enter("gfmFootnoteCallMarker"),t.consume(m),t.exit("gfmFootnoteCallMarker"),t.enter("gfmFootnoteCallString"),t.enter("chunkString").contentType="string",d)}function d(m){if(i>999||m===93&&!o||m===null||m===91||kn(m))return n(m);if(m===93){t.exit("chunkString");const p=t.exit("gfmFootnoteCallString");return s.includes(Ga(r.sliceSerialize(p)))?(t.enter("gfmFootnoteCallLabelMarker"),t.consume(m),t.exit("gfmFootnoteCallLabelMarker"),t.exit("gfmFootnoteCall"),e):n(m)}return kn(m)||(o=!0),i++,t.consume(m),m===92?f:d}function f(m){return m===91||m===92||m===93?(t.consume(m),i++,d):d(m)}}function RHe(t,e,n){const r=this,s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i,o=0,a;return c;function c(y){return t.enter("gfmFootnoteDefinition")._container=!0,t.enter("gfmFootnoteDefinitionLabel"),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(y),t.exit("gfmFootnoteDefinitionLabelMarker"),d}function d(y){return y===94?(t.enter("gfmFootnoteDefinitionMarker"),t.consume(y),t.exit("gfmFootnoteDefinitionMarker"),t.enter("gfmFootnoteDefinitionLabelString"),t.enter("chunkString").contentType="string",f):n(y)}function f(y){if(o>999||y===93&&!a||y===null||y===91||kn(y))return n(y);if(y===93){t.exit("chunkString");const w=t.exit("gfmFootnoteDefinitionLabelString");return i=Ga(r.sliceSerialize(w)),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(y),t.exit("gfmFootnoteDefinitionLabelMarker"),t.exit("gfmFootnoteDefinitionLabel"),p}return kn(y)||(a=!0),o++,t.consume(y),y===92?m:f}function m(y){return y===91||y===92||y===93?(t.consume(y),o++,f):f(y)}function p(y){return y===58?(t.enter("definitionMarker"),t.consume(y),t.exit("definitionMarker"),s.includes(i)||s.push(i),dn(t,x,"gfmFootnoteDefinitionWhitespace")):n(y)}function x(y){return e(y)}}function OHe(t,e,n){return t.check(Av,e,t.attempt(EHe,e,n))}function IHe(t){t.exit("gfmFootnoteDefinition")}function DHe(t,e,n){const r=this;return dn(t,s,"gfmFootnoteDefinitionIndent",5);function s(i){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?e(i):n(i)}}function LHe(t){return GX([yHe(),jHe(),lX(t),nte(),Zee()])}const PHe={};function FHe(t){const e=this,n=t||PHe,r=e.data(),s=r.micromarkExtensions||(r.micromarkExtensions=[]),i=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);s.push(LHe(n)),i.push(mHe()),o.push(pHe(n))}let DA=null;function $He(){return DA||(DA=Ae(()=>import("./mermaid.core-BaxvgwjG.js").then(t=>t.bC),[]).then(t=>t.default)),DA}function Moe(t){return t==null?"":typeof t=="string"||typeof t=="number"?String(t):Array.isArray(t)?t.map(e=>Moe(e)).join(""):""}function BHe(t){if(!v.isValidElement(t))return null;const e=t.props;return typeof e.className!="string"||!/\blanguage-mermaid\b/i.test(e.className)?null:Moe(e.children).replace(/\n$/,"")}function zHe(t){const e=/^#([0-9a-f]{6})$/i.exec(t.trim());if(!e)return null;const n=e[1];return{r:parseInt(n.slice(0,2),16),g:parseInt(n.slice(2,4),16),b:parseInt(n.slice(4,6),16)}}function VHe(t){if(!t)return;const e=zHe(t);if(!e)return;const n=(.299*e.r+.587*e.g+.114*e.b)/255;return{borderColor:t,backgroundColor:`rgba(${e.r}, ${e.g}, ${e.b}, 0.22)`,color:n>.55?"#111827":"#f8fafc"}}function HHe({source:t,darkMode:e}){const n=v.useId().replace(/[^a-zA-Z0-9_-]/g,""),[r,s]=v.useState(null),[i,o]=v.useState(null);return v.useEffect(()=>{let a=!0;return s(null),o(null),$He().then(async c=>{c.initialize({startOnLoad:!1,securityLevel:"strict",theme:e?"dark":"default",fontFamily:"inherit",suppressErrorRendering:!0});const d=await c.render(`paperclip-mermaid-${n}`,t);a&&s(d.svg)}).catch(c=>{if(!a)return;const d=c instanceof Error&&c.message?c.message:"Failed to render Mermaid diagram.";o(d)}),()=>{a=!1}},[e,n,t]),l.jsx("div",{className:"paperclip-mermaid",children:r?l.jsx("div",{dangerouslySetInnerHTML:{__html:r}}):l.jsxs(l.Fragment,{children:[l.jsx("p",{className:re("paperclip-mermaid-status",i&&"paperclip-mermaid-status-error"),children:i?`Unable to render Mermaid diagram: ${i}`:"Rendering Mermaid diagram..."}),l.jsx("pre",{className:"paperclip-mermaid-source",children:l.jsx("code",{className:"language-mermaid",children:t})})]})})}function i5({children:t,className:e}){const{theme:n}=Mie();return l.jsx("div",{className:re("prose prose-sm max-w-none prose-p:my-2 prose-p:leading-[1.4] prose-ul:my-1.5 prose-ol:my-1.5 prose-li:my-0.5 prose-li:leading-[1.4] prose-pre:my-2 prose-pre:whitespace-pre-wrap prose-pre:break-words prose-headings:my-2 prose-headings:text-sm prose-blockquote:leading-[1.4] prose-table:my-2 prose-th:px-3 prose-th:py-1.5 prose-td:px-3 prose-td:py-1.5 prose-code:break-all [&_ul]:list-disc [&_ul]:pl-5 [&_ol]:list-decimal [&_ol]:pl-5 [&_li]:list-item",n==="dark"&&"prose-invert",e),children:l.jsx(DVe,{remarkPlugins:[FHe],components:{pre:({node:r,children:s,...i})=>{const o=BHe(s);return o?l.jsx(HHe,{source:o,darkMode:n==="dark"}):l.jsx("pre",{...i,children:s})},a:({href:r,children:s})=>{const i=r?yY(r):null;if(i){const o=s;return l.jsx("a",{href:`/projects/${i.projectId}`,className:"paperclip-project-mention-chip",style:VHe(i.color),children:o})}return l.jsx("a",{href:r,rel:"noreferrer",children:s})}},children:t})})}function kU({text:t,children:e,className:n,copiedLabel:r="Copied!"}){const[s,i]=v.useState(!1),[o,a]=v.useState(r),c=v.useRef(void 0),d=v.useRef(null),f=v.useCallback(async()=>{try{await navigator.clipboard.writeText(t),a(r)}catch{a("Copy failed")}clearTimeout(c.current),i(!0),c.current=setTimeout(()=>i(!1),1500)},[r,t]);return l.jsxs("span",{className:"relative inline-flex",children:[l.jsx("button",{ref:d,type:"button",className:re("cursor-copy hover:text-foreground transition-colors",n),onClick:f,children:e??t}),l.jsx("span",{role:"status","aria-live":"polite",className:re("pointer-events-none absolute left-1/2 -translate-x-1/2 bottom-full mb-1.5 rounded-md bg-foreground text-background px-2 py-1 text-xs whitespace-nowrap transition-opacity duration-300",s?"opacity-100":"opacity-0"),children:o})]})}function Roe(){const[t,e]=v.useState(!1);v.useEffect(()=>{const r=document.getElementById("main-content");if(!r)return;const s=()=>{const i=r.scrollHeight-r.scrollTop-r.clientHeight;e(i>300)};return s(),r.addEventListener("scroll",s,{passive:!0}),()=>r.removeEventListener("scroll",s)},[]);const n=v.useCallback(()=>{const r=document.getElementById("main-content");r&&r.scrollTo({top:r.scrollHeight,behavior:"smooth"})},[]);return t?l.jsx("button",{onClick:n,className:"fixed bottom-[calc(1.5rem+5rem+env(safe-area-inset-bottom))] right-6 z-40 flex h-9 w-9 items-center justify-center rounded-full border border-border bg-background shadow-md hover:bg-accent transition-colors md:bottom-6","aria-label":"Scroll to bottom",children:l.jsx(qR,{className:"h-4 w-4"})}):null}const Ooe={succeeded:{icon:WR,color:"text-green-600 dark:text-green-400"},failed:{icon:GR,color:"text-red-600 dark:text-red-400"},running:{icon:ty,color:"text-cyan-600 dark:text-cyan-400"},queued:{icon:Ng,color:"text-yellow-600 dark:text-yellow-400"},timed_out:{icon:twe,color:"text-orange-600 dark:text-orange-400"},cancelled:{icon:F1e,color:"text-neutral-500 dark:text-neutral-400"}},UHe="***REDACTED***",qHe=/(api[-_]?key|access[-_]?token|auth(?:_?token)?|authorization|bearer|secret|passwd|password|credential|jwt|private[-_]?key|cookie|connectionstring)/i,KHe=/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)?$/;function WHe(t,e){return qHe.test(t)?!0:typeof e!="string"?!1:KHe.test(e)}function GHe(t,e){if(typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.type==="secret_ref")return"***SECRET_REF***";if(WHe(t,e))return UHe;if(e==null)return"";if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}function JHe(t){const e=ng(t);if(!e)return"<unable-to-parse>";const n=Object.keys(e);return n.length===0?"<empty>":n.sort().map(r=>`${r}=${GHe(r,e[r])}`).join(`
855
855
  `)}const Ioe={timer:"Timer",assignment:"Assignment",on_demand:"On-demand",automation:"Automation"},SU=32;function Doe(t){return t===window}function YHe(t){const e=window.getComputedStyle(t).overflowY;return e==="auto"||e==="scroll"||e==="overlay"}function ZHe(t){let e=(t==null?void 0:t.parentElement)??null;for(;e;){if(YHe(e))return e;e=e.parentElement}return window}function gC(t){if(Doe(t)){const n=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight),r=window.scrollY+window.innerHeight;return{scrollHeight:n,distanceFromBottom:Math.max(0,n-r)}}const e=t.scrollTop+t.clientHeight;return{scrollHeight:t.scrollHeight,distanceFromBottom:Math.max(0,t.scrollHeight-e)}}function _U(t,e="auto"){if(Doe(t)){const n=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);window.scrollTo({top:n,behavior:e});return}t.scrollTo({top:t.scrollHeight,behavior:e})}function QHe(t){return t==="configure"||t==="configuration"?"configure":t==="runs"?t:"overview"}function K0(t,...e){if(!t)return 0;for(const n of e){const r=t[n];if(typeof r=="number"&&Number.isFinite(r))return r}return 0}function Loe(t){const e=t.usageJson??null,n=t.resultJson??null,r=K0(e,"inputTokens","input_tokens"),s=K0(e,"outputTokens","output_tokens"),i=K0(e,"cachedInputTokens","cached_input_tokens","cache_read_input_tokens"),o=K0(e,"costUsd","cost_usd","total_cost_usd")||K0(n,"total_cost_usd","cost_usd","costUsd");return{input:r,output:s,cached:i,cost:o,totalTokens:r+s}}function ng(t){return typeof t!="object"||t===null||Array.isArray(t)?null:t}function ei(t){if(typeof t!="string")return null;const e=t.trim();return e.length>0?e:null}function LA(){const{companyPrefix:t,agentId:e,tab:n,runId:r}=Eu(),{companies:s,selectedCompanyId:i,setSelectedCompanyId:o}=en(),{closePanel:a}=hx(),{openNewIssue:c}=$r(),{setBreadcrumbs:d}=bs(),f=Nn(),m=Ti(),[p,x]=v.useState(null),[y,w]=v.useState(!1),k=r?"runs":QHe(n??null),[S,C]=v.useState(!1),[_,E]=v.useState(!1),j=v.useRef(null),R=v.useRef(null),{isMobile:T}=oc(),M=e??"",I=v.useMemo(()=>{var ye;if(!t)return null;const Me=t.toUpperCase();return((ye=s.find(et=>et.issuePrefix.toUpperCase()===Me))==null?void 0:ye.id)??null},[s,t])??i??void 0,$=M.length>0&&(HR(M)||!!I),z=v.useCallback(Me=>{j.current=Me},[]),V=v.useCallback(Me=>{R.current=Me},[]),{data:W,isLoading:J,error:G}=Be({queryKey:[...te.agents.detail(M),I??null],queryFn:()=>Ot.get(M,I),enabled:$}),F=(W==null?void 0:W.companyId)??i,L=W?yu(W):M,K=(W==null?void 0:W.id)??M,D=(W==null?void 0:W.id)??null,{data:B}=Be({queryKey:te.agents.runtimeState(D??M),queryFn:()=>Ot.runtimeState(D,F??void 0),enabled:!!D}),{data:q}=Be({queryKey:te.heartbeats(F,(W==null?void 0:W.id)??void 0),queryFn:()=>Kr.list(F,(W==null?void 0:W.id)??void 0),enabled:!!F&&!!(W!=null&&W.id)}),{data:H}=Be({queryKey:te.issues.list(F),queryFn:()=>Dn.list(F),enabled:!!F}),{data:ie}=Be({queryKey:te.agents.list(F),queryFn:()=>Ot.list(F),enabled:!!F}),ce=(H??[]).filter(Me=>Me.assigneeAgentId===(W==null?void 0:W.id)).sort((Me,ye)=>new Date(ye.updatedAt).getTime()-new Date(Me.updatedAt).getTime()),ee=(ie??[]).find(Me=>Me.id===(W==null?void 0:W.reportsTo)),Q=(ie??[]).filter(Me=>Me.reportsTo===(W==null?void 0:W.id)&&Me.status!=="terminated"),ae=v.useMemo(()=>(q??[]).find(Me=>Me.status==="running"||Me.status==="queued")??null,[q]);v.useEffect(()=>{if(W&&M!==L){if(r){m(`/agents/${L}/runs/${r}`,{replace:!0});return}if(n){m(`/agents/${L}/${n}`,{replace:!0});return}m(`/agents/${L}`,{replace:!0})}},[W,M,L,r,n,m]),v.useEffect(()=>{!(W!=null&&W.companyId)||W.companyId===i||o(W.companyId,{source:"route_sync"})},[W==null?void 0:W.companyId,i,o]);const ue=yt({mutationFn:async Me=>{if(!K)return Promise.reject(new Error("No agent reference"));switch(Me){case"invoke":return Ot.invoke(K,F??void 0);case"pause":return Ot.pause(K,F??void 0);case"resume":return Ot.resume(K,F??void 0);case"terminate":return Ot.terminate(K,F??void 0)}},onSuccess:(Me,ye)=>{x(null),f.invalidateQueries({queryKey:te.agents.detail(M)}),f.invalidateQueries({queryKey:te.agents.detail(K)}),f.invalidateQueries({queryKey:te.agents.runtimeState(K)}),f.invalidateQueries({queryKey:te.agents.taskSessions(K)}),F&&(f.invalidateQueries({queryKey:te.agents.list(F)}),W!=null&&W.id&&f.invalidateQueries({queryKey:te.heartbeats(F,W.id)})),ye==="invoke"&&Me&&typeof Me=="object"&&"id"in Me&&m(`/agents/${L}/runs/${Me.id}`)},onError:Me=>{x(Me instanceof Error?Me.message:"Action failed")}}),ge=yt({mutationFn:Me=>Ot.update(K,{icon:Me},F??void 0),onSuccess:()=>{f.invalidateQueries({queryKey:te.agents.detail(M)}),f.invalidateQueries({queryKey:te.agents.detail(K)}),F&&f.invalidateQueries({queryKey:te.agents.list(F)})}}),$e=yt({mutationFn:Me=>Ot.resetSession(K,Me,F??void 0),onSuccess:()=>{x(null),f.invalidateQueries({queryKey:te.agents.runtimeState(K)}),f.invalidateQueries({queryKey:te.agents.taskSessions(K)})},onError:Me=>{x(Me instanceof Error?Me.message:"Failed to reset session")}}),He=yt({mutationFn:Me=>Ot.updatePermissions(K,{canCreateAgents:Me},F??void 0),onSuccess:()=>{x(null),f.invalidateQueries({queryKey:te.agents.detail(M)}),f.invalidateQueries({queryKey:te.agents.detail(K)}),F&&f.invalidateQueries({queryKey:te.agents.list(F)})},onError:Me=>{x(Me instanceof Error?Me.message:"Failed to update permissions")}});if(v.useEffect(()=>{const Me=[{label:"Agents",href:"/agents"}],ye=(W==null?void 0:W.name)??M??"Agent";k==="overview"&&!r?Me.push({label:ye}):(Me.push({label:ye,href:`/agents/${L}`}),r?(Me.push({label:"Runs",href:`/agents/${L}/runs`}),Me.push({label:`Run ${r.slice(0,8)}`})):k==="configure"?Me.push({label:"Configure"}):k==="runs"&&Me.push({label:"Runs"})),d(Me)},[d,W,M,L,k,r]),v.useEffect(()=>(a(),()=>a()),[]),Zue(v.useCallback(Me=>{S&&(Me.preventDefault(),Me.returnValue="")},[S])),J)return l.jsx(ui,{variant:"detail"});if(G)return l.jsx("p",{className:"text-sm text-destructive",children:G.message});if(!W)return null;const lt=W.status==="pending_approval",rt=k==="configure"&&S;return l.jsxs("div",{className:re("space-y-6",T&&rt&&"pb-24"),children:[l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[l.jsx(C2e,{value:W.icon,onChange:Me=>ge.mutate(Me),children:l.jsx("button",{className:"shrink-0 flex items-center justify-center h-12 w-12 rounded-lg bg-accent hover:bg-accent/80 transition-colors",children:l.jsx(Ql,{icon:W.icon,className:"h-6 w-6"})})}),l.jsxs("div",{className:"min-w-0",children:[l.jsx("h2",{className:"text-2xl font-bold truncate",children:W.name}),l.jsxs("p",{className:"text-sm text-muted-foreground truncate",children:[Ry[W.role]??W.role,W.title?` - ${W.title}`:""]})]})]}),l.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 shrink-0",children:[l.jsxs(ke,{variant:"outline",size:"sm",onClick:()=>c({assigneeAgentId:W.id}),children:[l.jsx(Pr,{className:"h-3.5 w-3.5 sm:mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:"Assign Task"})]}),l.jsxs(ke,{variant:"outline",size:"sm",onClick:()=>ue.mutate("invoke"),disabled:ue.isPending||lt,children:[l.jsx(HP,{className:"h-3.5 w-3.5 sm:mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:"Run Heartbeat"})]}),W.status==="paused"?l.jsxs(ke,{variant:"outline",size:"sm",onClick:()=>ue.mutate("resume"),disabled:ue.isPending||lt,children:[l.jsx(HP,{className:"h-3.5 w-3.5 sm:mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:"Resume"})]}):l.jsxs(ke,{variant:"outline",size:"sm",onClick:()=>ue.mutate("pause"),disabled:ue.isPending||lt,children:[l.jsx(w1e,{className:"h-3.5 w-3.5 sm:mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:"Pause"})]}),l.jsx("span",{className:"hidden sm:inline",children:l.jsx(Fn,{status:W.status})}),ae&&l.jsxs(Bt,{to:`/agents/${L}/runs/${ae.id}`,className:"sm:hidden flex items-center gap-1.5 px-2 py-0.5 rounded-full bg-blue-500/10 hover:bg-blue-500/20 transition-colors no-underline",children:[l.jsxs("span",{className:"relative flex h-2 w-2",children:[l.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),l.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-blue-500"})]}),l.jsx("span",{className:"text-[11px] font-medium text-blue-600 dark:text-blue-400",children:"Live"})]}),l.jsxs(Bn,{open:y,onOpenChange:w,children:[l.jsx(zn,{asChild:!0,children:l.jsx(ke,{variant:"ghost",size:"icon-xs",children:l.jsx(qS,{className:"h-4 w-4"})})}),l.jsxs(Vn,{className:"w-44 p-1",align:"end",children:[l.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",onClick:()=>{m(`/agents/${L}/configure`),w(!1)},children:[l.jsx(Eg,{className:"h-3 w-3"}),"Configure Agent"]}),l.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",onClick:()=>{navigator.clipboard.writeText(W.id),w(!1)},children:[l.jsx(YR,{className:"h-3 w-3"}),"Copy Agent ID"]}),l.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",onClick:()=>{$e.mutate(null),w(!1)},children:[l.jsx(I2,{className:"h-3 w-3"}),"Reset Sessions"]}),l.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:()=>{ue.mutate("terminate"),w(!1)},children:[l.jsx(lu,{className:"h-3 w-3"}),"Terminate"]})]})]})]})]}),p&&l.jsx("p",{className:"text-sm text-destructive",children:p}),lt&&l.jsx("p",{className:"text-sm text-amber-500",children:"This agent is pending board approval and cannot be invoked yet."}),!T&&l.jsx("div",{className:re("sticky top-6 z-10 float-right transition-opacity duration-150",rt?"opacity-100":"opacity-0 pointer-events-none"),children:l.jsxs("div",{className:"flex items-center gap-2 bg-background/90 backdrop-blur-sm border border-border rounded-lg px-3 py-1.5 shadow-lg",children:[l.jsx(ke,{variant:"ghost",size:"sm",onClick:()=>{var Me;return(Me=R.current)==null?void 0:Me.call(R)},disabled:_,children:"Cancel"}),l.jsx(ke,{size:"sm",onClick:()=>{var Me;return(Me=j.current)==null?void 0:Me.call(j)},disabled:_,children:_?"Saving…":"Save"})]})}),T&&rt&&l.jsx("div",{className:"fixed inset-x-0 bottom-0 z-30 border-t border-border bg-background/95 backdrop-blur-sm",children:l.jsxs("div",{className:"flex items-center justify-end gap-2 px-3 py-2",style:{paddingBottom:"max(env(safe-area-inset-bottom), 0.5rem)"},children:[l.jsx(ke,{variant:"ghost",size:"sm",onClick:()=>{var Me;return(Me=R.current)==null?void 0:Me.call(R)},disabled:_,children:"Cancel"}),l.jsx(ke,{size:"sm",onClick:()=>{var Me;return(Me=j.current)==null?void 0:Me.call(j)},disabled:_,children:_?"Saving…":"Save"})]})}),k==="overview"&&l.jsx(eUe,{agent:W,runs:q??[],assignedIssues:ce,runtimeState:B,reportsToAgent:ee??null,directReports:Q,agentId:W.id,agentRouteId:L}),k==="configure"&&l.jsx(rUe,{agent:W,agentId:W.id,companyId:F??void 0,onDirtyChange:C,onSaveActionChange:z,onCancelActionChange:V,onSavingChange:E,updatePermissions:He}),k==="runs"&&l.jsx(iUe,{runs:q??[],companyId:F,agentId:W.id,agentRouteId:L,selectedRunId:r??null,adapterType:W.adapterType})]})}function xC({label:t,children:e}){return l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("span",{className:"text-muted-foreground text-xs",children:t}),l.jsx("div",{className:"flex items-center gap-1",children:e})]})}function XHe({runs:t,agentId:e}){if(t.length===0)return null;const n=[...t].sort((d,f)=>new Date(f.createdAt).getTime()-new Date(d.createdAt).getTime()),s=n.find(d=>d.status==="running"||d.status==="queued")??n[0],i=s.status==="running"||s.status==="queued",o=Ooe[s.status]??{icon:Ng,color:"text-neutral-400"},a=o.icon,c=s.resultJson?String(s.resultJson.summary??s.resultJson.result??""):s.error??"";return l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"flex w-full items-center justify-between",children:[l.jsxs("h3",{className:"flex items-center gap-2 text-sm font-medium",children:[i&&l.jsxs("span",{className:"relative flex h-2 w-2",children:[l.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-cyan-400 opacity-75"}),l.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-cyan-400"})]}),i?"Live Run":"Latest Run"]}),l.jsx(Bt,{to:`/agents/${e}/runs/${s.id}`,className:"shrink-0 text-xs text-muted-foreground hover:text-foreground transition-colors no-underline",children:"View details →"})]}),l.jsxs(Bt,{to:`/agents/${e}/runs/${s.id}`,className:re("block border rounded-lg p-4 space-y-2 w-full no-underline transition-colors hover:bg-muted/50 cursor-pointer",i?"border-cyan-500/30 shadow-[0_0_12px_rgba(6,182,212,0.08)]":"border-border"),children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(a,{className:re("h-3.5 w-3.5",o.color,s.status==="running"&&"animate-spin")}),l.jsx(Fn,{status:s.status}),l.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:s.id.slice(0,8)}),l.jsx("span",{className:re("inline-flex items-center rounded-full px-1.5 py-0.5 text-[10px] font-medium",s.invocationSource==="timer"?"bg-blue-100 text-blue-700 dark:bg-blue-900/50 dark:text-blue-300":s.invocationSource==="assignment"?"bg-violet-100 text-violet-700 dark:bg-violet-900/50 dark:text-violet-300":s.invocationSource==="on_demand"?"bg-cyan-100 text-cyan-700 dark:bg-cyan-900/50 dark:text-cyan-300":"bg-muted text-muted-foreground"),children:Ioe[s.invocationSource]??s.invocationSource}),l.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:to(s.createdAt)})]}),c&&l.jsx("div",{className:"overflow-hidden max-h-16",children:l.jsx(i5,{className:"[&>*:first-child]:mt-0 [&>*:last-child]:mb-0",children:c})})]})]})}function eUe({agent:t,runs:e,assignedIssues:n,runtimeState:r,reportsToAgent:s,directReports:i,agentId:o,agentRouteId:a}){return l.jsxs("div",{className:"space-y-8",children:[l.jsx(XHe,{runs:e,agentId:a}),l.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[l.jsx(Ud,{title:"Run Activity",subtitle:"Last 14 days",children:l.jsx(zie,{runs:e})}),l.jsx(Ud,{title:"Issues by Priority",subtitle:"Last 14 days",children:l.jsx(Vie,{issues:n})}),l.jsx(Ud,{title:"Issues by Status",subtitle:"Last 14 days",children:l.jsx(Hie,{issues:n})}),l.jsx(Ud,{title:"Success Rate",subtitle:"Last 14 days",children:l.jsx(Uie,{runs:e})})]}),l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("h3",{className:"text-sm font-medium",children:"Recent Issues"}),l.jsx(Bt,{to:`/issues?assignee=${o}`,className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:"See All →"})]}),n.length===0?l.jsx("p",{className:"text-sm text-muted-foreground",children:"No assigned issues."}):l.jsxs("div",{className:"border border-border rounded-lg",children:[n.slice(0,10).map(c=>l.jsx(Al,{identifier:c.identifier??c.id.slice(0,8),title:c.title,to:`/issues/${c.identifier??c.id}`,trailing:l.jsx(Fn,{status:c.status})},c.id)),n.length>10&&l.jsxs("div",{className:"px-3 py-2 text-xs text-muted-foreground text-center border-t border-border",children:["+",n.length-10," more issues"]})]})]}),l.jsxs("div",{className:"space-y-3",children:[l.jsx("h3",{className:"text-sm font-medium",children:"Costs"}),l.jsx(nUe,{runtimeState:r,runs:e})]}),l.jsx(tUe,{agent:t,agentRouteId:a,reportsToAgent:s,directReports:i})]})}function tUe({agent:t,agentRouteId:e,reportsToAgent:n,directReports:r}){var o;const s=t.adapterConfig,i=typeof(s==null?void 0:s.promptTemplate)=="string"?s.promptTemplate:"";return l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("h3",{className:"text-sm font-medium",children:"Configuration"}),l.jsxs(Bt,{to:`/agents/${e}/configure`,className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors no-underline",children:[l.jsx(Eg,{className:"h-3 w-3"}),"Manage →"]})]}),l.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[l.jsxs("div",{className:"border border-border rounded-lg p-4 space-y-3",children:[l.jsx("h4",{className:"text-xs text-muted-foreground font-medium",children:"Agent Details"}),l.jsxs("div",{className:"space-y-2 text-sm",children:[l.jsxs(xC,{label:"Adapter",children:[l.jsx("span",{className:"font-mono",children:r6[t.adapterType]??t.adapterType}),String((s==null?void 0:s.model)??"")!==""&&l.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",String(s.model),")"]})]}),l.jsx(xC,{label:"Heartbeat",children:(o=t.runtimeConfig)!=null&&o.heartbeat?(()=>{const a=t.runtimeConfig.heartbeat;if(!a.enabled)return l.jsx("span",{className:"text-muted-foreground",children:"Disabled"});const c=Number(a.intervalSec)||300,d=Math.max(1,Math.floor(Number(a.maxConcurrentRuns)||1)),f=c>=60?`${Math.round(c/60)} min`:`${c}s`;return l.jsxs("span",{children:["Every ",f,d>1?` (max ${d} concurrent)`:""]})})():l.jsx("span",{className:"text-muted-foreground",children:"Not configured"})}),l.jsx(xC,{label:"Last heartbeat",children:t.lastHeartbeatAt?l.jsx("span",{children:to(t.lastHeartbeatAt)}):l.jsx("span",{className:"text-muted-foreground",children:"Never"})}),l.jsx(xC,{label:"Reports to",children:n?l.jsx(Bt,{to:`/agents/${yu(n)}`,className:"text-blue-600 hover:underline dark:text-blue-400",children:l.jsx(Sn,{name:n.name,size:"sm"})}):l.jsx("span",{className:"text-muted-foreground",children:"Nobody (top-level)"})})]}),r.length>0&&l.jsxs("div",{className:"pt-1",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Direct reports"}),l.jsx("div",{className:"mt-1 space-y-1",children:r.map(a=>l.jsxs(Bt,{to:`/agents/${yu(a)}`,className:"flex items-center gap-2 text-sm text-blue-600 hover:underline dark:text-blue-400",children:[l.jsx("span",{className:"relative flex h-2 w-2",children:l.jsx("span",{className:`absolute inline-flex h-full w-full rounded-full ${r_[a.status]??s_}`})}),a.name,l.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",Ry[a.role]??a.role,")"]})]},a.id))})]}),t.capabilities&&l.jsxs("div",{className:"pt-1",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Capabilities"}),l.jsx("p",{className:"text-sm mt-0.5",children:t.capabilities})]})]}),i&&l.jsxs("div",{className:"border border-border rounded-lg p-4 space-y-2",children:[l.jsx("h4",{className:"text-xs text-muted-foreground font-medium",children:"Prompt Template"}),l.jsx("pre",{className:"text-xs text-muted-foreground line-clamp-[12] font-mono whitespace-pre-wrap",children:i})]})]})]})}function nUe({runtimeState:t,runs:e}){const n=e.filter(r=>{const s=r.usageJson;return s&&(s.cost_usd||s.total_cost_usd||s.input_tokens)}).sort((r,s)=>new Date(s.createdAt).getTime()-new Date(r.createdAt).getTime());return l.jsxs("div",{className:"space-y-4",children:[t&&l.jsx("div",{className:"border border-border rounded-lg p-4",children:l.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[l.jsxs("div",{children:[l.jsx("span",{className:"text-xs text-muted-foreground block",children:"Input tokens"}),l.jsx("span",{className:"text-lg font-semibold",children:Lr(t.totalInputTokens)})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-xs text-muted-foreground block",children:"Output tokens"}),l.jsx("span",{className:"text-lg font-semibold",children:Lr(t.totalOutputTokens)})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-xs text-muted-foreground block",children:"Cached tokens"}),l.jsx("span",{className:"text-lg font-semibold",children:Lr(t.totalCachedInputTokens)})]}),l.jsxs("div",{children:[l.jsx("span",{className:"text-xs text-muted-foreground block",children:"Total cost"}),l.jsx("span",{className:"text-lg font-semibold",children:Xc(t.totalCostCents)})]})]})}),n.length>0&&l.jsx("div",{className:"border border-border rounded-lg overflow-hidden",children:l.jsxs("table",{className:"w-full text-xs",children:[l.jsx("thead",{children:l.jsxs("tr",{className:"border-b border-border bg-accent/20",children:[l.jsx("th",{className:"text-left px-3 py-2 font-medium text-muted-foreground",children:"Date"}),l.jsx("th",{className:"text-left px-3 py-2 font-medium text-muted-foreground",children:"Run"}),l.jsx("th",{className:"text-right px-3 py-2 font-medium text-muted-foreground",children:"Input"}),l.jsx("th",{className:"text-right px-3 py-2 font-medium text-muted-foreground",children:"Output"}),l.jsx("th",{className:"text-right px-3 py-2 font-medium text-muted-foreground",children:"Cost"})]})}),l.jsx("tbody",{children:n.slice(0,10).map(r=>{const s=r.usageJson;return l.jsxs("tr",{className:"border-b border-border last:border-b-0",children:[l.jsx("td",{className:"px-3 py-2",children:ki(r.createdAt)}),l.jsx("td",{className:"px-3 py-2 font-mono",children:r.id.slice(0,8)}),l.jsx("td",{className:"px-3 py-2 text-right",children:Lr(Number(s.input_tokens??0))}),l.jsx("td",{className:"px-3 py-2 text-right",children:Lr(Number(s.output_tokens??0))}),l.jsx("td",{className:"px-3 py-2 text-right",children:s.cost_usd||s.total_cost_usd?`$${Number(s.cost_usd??s.total_cost_usd??0).toFixed(4)}`:"-"})]},r.id)})})]})})]})}function rUe({agent:t,agentId:e,companyId:n,onDirtyChange:r,onSaveActionChange:s,onCancelActionChange:i,onSavingChange:o,updatePermissions:a}){const c=Nn(),[d,f]=v.useState(!1),{data:m}=Be({queryKey:te.agents.configRevisions(t.id),queryFn:()=>Ot.listConfigRevisions(t.id,n)}),p=yt({mutationFn:x=>Ot.rollbackConfigRevision(t.id,x,n),onSuccess:()=>{c.invalidateQueries({queryKey:te.agents.detail(t.id)}),c.invalidateQueries({queryKey:te.agents.detail(t.urlKey)}),c.invalidateQueries({queryKey:te.agents.configRevisions(t.id)})}});return l.jsxs("div",{className:"max-w-3xl space-y-6",children:[l.jsx(sUe,{agent:t,onDirtyChange:r,onSaveActionChange:s,onCancelActionChange:i,onSavingChange:o,updatePermissions:a,companyId:n}),l.jsxs("div",{children:[l.jsx("h3",{className:"text-sm font-medium mb-3",children:"API Keys"}),l.jsx(aUe,{agentId:e,companyId:n})]}),l.jsxs("div",{children:[l.jsxs("button",{className:"flex items-center gap-2 text-sm font-medium hover:text-foreground transition-colors",onClick:()=>f(x=>!x),children:[d?l.jsx(ga,{className:"h-3.5 w-3.5 text-muted-foreground"}):l.jsx(xa,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Configuration Revisions",l.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:(m==null?void 0:m.length)??0})]}),d&&l.jsx("div",{className:"mt-3",children:(m??[]).length===0?l.jsx("p",{className:"text-sm text-muted-foreground",children:"No configuration revisions yet."}):l.jsx("div",{className:"space-y-2",children:(m??[]).slice(0,10).map(x=>l.jsxs("div",{className:"border border-border/70 rounded-md p-3 space-y-2",children:[l.jsxs("div",{className:"flex items-center justify-between gap-3",children:[l.jsxs("div",{className:"text-xs text-muted-foreground",children:[l.jsx("span",{className:"font-mono",children:x.id.slice(0,8)}),l.jsx("span",{className:"mx-1",children:"·"}),l.jsx("span",{children:ki(x.createdAt)}),l.jsx("span",{className:"mx-1",children:"·"}),l.jsx("span",{children:x.source})]}),l.jsx(ke,{size:"sm",variant:"outline",className:"h-7 px-2.5 text-xs",onClick:()=>p.mutate(x.id),disabled:p.isPending,children:"Restore"})]}),l.jsxs("p",{className:"text-xs text-muted-foreground",children:["Changed:"," ",x.changedKeys.length>0?x.changedKeys.join(", "):"no tracked changes"]})]},x.id))})})]})]})}function sUe({agent:t,companyId:e,onDirtyChange:n,onSaveActionChange:r,onCancelActionChange:s,onSavingChange:i,updatePermissions:o}){var f,m;const a=Nn(),{data:c}=Be({queryKey:e?te.agents.adapterModels(e,t.adapterType):["agents","none","adapter-models",t.adapterType],queryFn:()=>Ot.adapterModels(e,t.adapterType),enabled:!!e}),d=yt({mutationFn:p=>Ot.update(t.id,p,e),onSuccess:()=>{a.invalidateQueries({queryKey:te.agents.detail(t.id)}),a.invalidateQueries({queryKey:te.agents.detail(t.urlKey)}),a.invalidateQueries({queryKey:te.agents.configRevisions(t.id)})}});return v.useEffect(()=>{i(d.isPending)},[i,d.isPending]),l.jsxs("div",{className:"space-y-6",children:[l.jsx(eoe,{mode:"edit",agent:t,onSave:p=>d.mutate(p),isSaving:d.isPending,adapterModels:c,onDirtyChange:n,onSaveActionChange:r,onCancelActionChange:s,hideInlineSave:!0,sectionLayout:"cards"}),l.jsxs("div",{children:[l.jsx("h3",{className:"text-sm font-medium mb-3",children:"Permissions"}),l.jsx("div",{className:"border border-border rounded-lg p-4",children:l.jsxs("div",{className:"flex items-center justify-between text-sm",children:[l.jsx("span",{children:"Can create new agents"}),l.jsx(ke,{variant:(f=t.permissions)!=null&&f.canCreateAgents?"default":"outline",size:"sm",className:"h-7 px-2.5 text-xs",onClick:()=>{var p;return o.mutate(!((p=t.permissions)!=null&&p.canCreateAgents))},disabled:o.isPending,children:(m=t.permissions)!=null&&m.canCreateAgents?"Enabled":"Disabled"})]})})]})]})}function NU({run:t,isSelected:e,agentId:n}){const r=Ooe[t.status]??{icon:Ng,color:"text-neutral-400"},s=r.icon,i=Loe(t),o=t.resultJson?String(t.resultJson.summary??t.resultJson.result??""):t.error??"";return l.jsxs(Bt,{to:e?`/agents/${n}/runs`:`/agents/${n}/runs/${t.id}`,className:re("flex flex-col gap-1 w-full px-3 py-2.5 text-left border-b border-border last:border-b-0 transition-colors no-underline text-inherit",e?"bg-accent/40":"hover:bg-accent/20"),children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(s,{className:re("h-3.5 w-3.5 shrink-0",r.color,t.status==="running"&&"animate-spin")}),l.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:t.id.slice(0,8)}),l.jsx("span",{className:re("inline-flex items-center rounded-full px-1.5 py-0.5 text-[10px] font-medium shrink-0",t.invocationSource==="timer"?"bg-blue-100 text-blue-700 dark:bg-blue-900/50 dark:text-blue-300":t.invocationSource==="assignment"?"bg-violet-100 text-violet-700 dark:bg-violet-900/50 dark:text-violet-300":t.invocationSource==="on_demand"?"bg-cyan-100 text-cyan-700 dark:bg-cyan-900/50 dark:text-cyan-300":"bg-muted text-muted-foreground"),children:Ioe[t.invocationSource]??t.invocationSource}),l.jsx("span",{className:"ml-auto text-[11px] text-muted-foreground shrink-0",children:to(t.createdAt)})]}),o&&l.jsx("span",{className:"text-xs text-muted-foreground truncate pl-5.5",children:o.slice(0,60)}),(i.totalTokens>0||i.cost>0)&&l.jsxs("div",{className:"flex items-center gap-2 pl-5.5 text-[11px] text-muted-foreground",children:[i.totalTokens>0&&l.jsxs("span",{children:[Lr(i.totalTokens)," tok"]}),i.cost>0&&l.jsxs("span",{children:["$",i.cost.toFixed(3)]})]})]})}function iUe({runs:t,companyId:e,agentId:n,agentRouteId:r,selectedRunId:s,adapterType:i}){var f;const{isMobile:o}=oc();if(t.length===0)return l.jsx("p",{className:"text-sm text-muted-foreground",children:"No runs yet."});const a=[...t].sort((m,p)=>new Date(p.createdAt).getTime()-new Date(m.createdAt).getTime()),c=o?s:s??((f=a[0])==null?void 0:f.id)??null,d=a.find(m=>m.id===c)??null;return o?d?l.jsxs("div",{className:"space-y-3 min-w-0 overflow-x-hidden",children:[l.jsxs(Bt,{to:`/agents/${r}/runs`,className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors no-underline",children:[l.jsx(KR,{className:"h-3.5 w-3.5"}),"Back to runs"]}),l.jsx(EU,{run:d,agentRouteId:r,adapterType:i},d.id)]}):l.jsx("div",{className:"border border-border rounded-lg overflow-x-hidden",children:a.map(m=>l.jsx(NU,{run:m,isSelected:!1,agentId:r},m.id))}):l.jsxs("div",{className:"flex gap-0",children:[l.jsx("div",{className:re("shrink-0 border border-border rounded-lg",d?"w-72":"w-full"),children:l.jsx("div",{className:"sticky top-4 overflow-y-auto",style:{maxHeight:"calc(100vh - 2rem)"},children:a.map(m=>l.jsx(NU,{run:m,isSelected:m.id===c,agentId:r},m.id))})}),d&&l.jsx("div",{className:"flex-1 min-w-0 pl-4",children:l.jsx(EU,{run:d,agentRouteId:r,adapterType:i},d.id)})]})}function EU({run:t,agentRouteId:e,adapterType:n}){const r=Nn(),s=Ti(),i=Loe(t),[o,a]=v.useState(!1),[c,d]=v.useState(null);v.useEffect(()=>{d(null)},[t.id]);const f=yt({mutationFn:()=>Kr.cancel(t.id),onSuccess:()=>{r.invalidateQueries({queryKey:te.heartbeats(t.companyId,t.agentId)})}}),m=t.errorCode==="process_lost"&&t.status==="failed",p=v.useMemo(()=>{const F={resumeFromRunId:t.id},L=ng(t.contextSnapshot);if(!L)return F;const K=ei(L.issueId),D=ei(L.taskId),B=ei(L.taskKey),q=ei(L.wakeCommentId)??ei(L.commentId);return K&&(F.issueId=K),D&&(F.taskId=D),B&&(F.taskKey=B),q&&(F.commentId=q),F},[t.contextSnapshot,t.id]),x=yt({mutationFn:async()=>{const F=await Ot.wakeup(t.agentId,{source:"on_demand",triggerDetail:"manual",reason:"resume_process_lost_run",payload:p},t.companyId);if(!("id"in F))throw new Error("Resume request was skipped because the agent is not currently invokable.");return F},onSuccess:F=>{r.invalidateQueries({queryKey:te.heartbeats(t.companyId,t.agentId)}),s(`/agents/${e}/runs/${F.id}`)}}),y=t.status==="failed"||t.status==="timed_out",w=v.useMemo(()=>{const F={},L=ng(t.contextSnapshot);if(!L)return F;const K=ei(L.issueId),D=ei(L.taskId),B=ei(L.taskKey);return K&&(F.issueId=K),D&&(F.taskId=D),B&&(F.taskKey=B),F},[t.contextSnapshot]),k=yt({mutationFn:async()=>{const F=await Ot.wakeup(t.agentId,{source:"on_demand",triggerDetail:"manual",reason:"retry_failed_run",payload:w},t.companyId);if(!("id"in F))throw new Error("Retry was skipped because the agent is not currently invokable.");return F},onSuccess:F=>{r.invalidateQueries({queryKey:te.heartbeats(t.companyId,t.agentId)}),s(`/agents/${e}/runs/${F.id}`)}}),{data:S}=Be({queryKey:te.runIssues(t.id),queryFn:()=>Rb.issuesForRun(t.id)}),C=v.useMemo(()=>Array.from(new Set((S??[]).map(F=>F.issueId))),[S]),_=yt({mutationFn:async()=>C.length===0?0:(await Promise.all(C.map(F=>Ot.resetSession(t.agentId,F,t.companyId))),C.length),onSuccess:()=>{r.invalidateQueries({queryKey:te.agents.runtimeState(t.agentId)}),r.invalidateQueries({queryKey:te.agents.taskSessions(t.agentId)}),r.invalidateQueries({queryKey:te.runIssues(t.id)})}}),E=yt({mutationFn:()=>Ot.loginWithClaude(t.agentId,t.companyId),onSuccess:F=>{d(F)}}),j=t.status==="running"&&!!t.startedAt&&!t.finishedAt,[R,T]=v.useState(()=>t.startedAt?Math.max(0,Math.round((Date.now()-new Date(t.startedAt).getTime())/1e3)):0);v.useEffect(()=>{if(!j||!t.startedAt)return;const F=new Date(t.startedAt).getTime();T(Math.max(0,Math.round((Date.now()-F)/1e3)));const L=setInterval(()=>{T(Math.max(0,Math.round((Date.now()-F)/1e3)))},1e3);return()=>clearInterval(L)},[j,t.startedAt]);const M={hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1},O=t.startedAt?new Date(t.startedAt).toLocaleTimeString("en-US",M):null,I=t.finishedAt?new Date(t.finishedAt).toLocaleTimeString("en-US",M):null,z=(t.startedAt&&t.finishedAt?Math.round((new Date(t.finishedAt).getTime()-new Date(t.startedAt).getTime())/1e3):null)??(j?R:null),V=i.input>0||i.output>0||i.cached>0||i.cost>0,W=!!(t.sessionIdBefore||t.sessionIdAfter),J=t.sessionIdBefore&&t.sessionIdAfter&&t.sessionIdBefore!==t.sessionIdAfter;t.sessionIdAfter||t.sessionIdBefore;const G=t.exitCode!==null&&t.exitCode!==0;return l.jsxs("div",{className:"space-y-4 min-w-0",children:[l.jsxs("div",{className:"border border-border rounded-lg overflow-hidden",children:[l.jsxs("div",{className:"flex flex-col sm:flex-row",children:[l.jsxs("div",{className:"flex-1 p-4 space-y-3",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(Fn,{status:t.status}),(t.status==="running"||t.status==="queued")&&l.jsx(ke,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive text-xs h-6 px-2",onClick:()=>f.mutate(),disabled:f.isPending,children:f.isPending?"Cancelling…":"Cancel"}),m&&l.jsxs(ke,{variant:"ghost",size:"sm",className:"text-xs h-6 px-2",onClick:()=>x.mutate(),disabled:x.isPending,children:[l.jsx(I2,{className:"h-3.5 w-3.5 mr-1"}),x.isPending?"Resuming…":"Resume"]}),y&&!m&&l.jsxs(ke,{variant:"ghost",size:"sm",className:"text-xs h-6 px-2",onClick:()=>k.mutate(),disabled:k.isPending,children:[l.jsx(I2,{className:"h-3.5 w-3.5 mr-1"}),k.isPending?"Retrying…":"Retry"]})]}),x.isError&&l.jsx("div",{className:"text-xs text-destructive",children:x.error instanceof Error?x.error.message:"Failed to resume run"}),k.isError&&l.jsx("div",{className:"text-xs text-destructive",children:k.error instanceof Error?k.error.message:"Failed to retry run"}),O&&l.jsxs("div",{className:"space-y-0.5",children:[l.jsxs("div",{className:"text-sm font-mono",children:[O,I&&l.jsx("span",{className:"text-muted-foreground",children:" → "}),I]}),l.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[to(t.startedAt),t.finishedAt&&l.jsxs(l.Fragment,{children:[" → ",to(t.finishedAt)]})]}),z!==null&&l.jsxs("div",{className:"text-xs text-muted-foreground",children:["Duration: ",z>=60?`${Math.floor(z/60)}m ${z%60}s`:`${z}s`]})]}),t.error&&l.jsxs("div",{className:"text-xs",children:[l.jsx("span",{className:"text-red-600 dark:text-red-400",children:t.error}),t.errorCode&&l.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",t.errorCode,")"]})]}),t.errorCode==="claude_auth_required"&&n==="claude_local"&&l.jsxs("div",{className:"space-y-2",children:[l.jsx(ke,{variant:"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>E.mutate(),disabled:E.isPending,children:E.isPending?"Running claude login...":"Login to Claude Code"}),E.isError&&l.jsx("p",{className:"text-xs text-destructive",children:E.error instanceof Error?E.error.message:"Failed to run Claude login"}),(c==null?void 0:c.loginUrl)&&l.jsxs("p",{className:"text-xs",children:["Login URL:",l.jsx("a",{href:c.loginUrl,className:"text-blue-600 underline underline-offset-2 ml-1 break-all dark:text-blue-400",target:"_blank",rel:"noreferrer",children:c.loginUrl})]}),c&&l.jsxs(l.Fragment,{children:[!!c.stdout&&l.jsx("pre",{className:"bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-foreground overflow-x-auto whitespace-pre-wrap",children:c.stdout}),!!c.stderr&&l.jsx("pre",{className:"bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-red-700 dark:text-red-300 overflow-x-auto whitespace-pre-wrap",children:c.stderr})]})]}),G&&l.jsxs("div",{className:"text-xs text-red-600 dark:text-red-400",children:["Exit code ",t.exitCode,t.signal&&l.jsxs("span",{className:"text-muted-foreground ml-1",children:["(signal: ",t.signal,")"]})]})]}),V&&l.jsxs("div",{className:"border-t sm:border-t-0 sm:border-l border-border p-4 grid grid-cols-2 gap-x-4 sm:gap-x-8 gap-y-3 content-center",children:[l.jsxs("div",{children:[l.jsx("div",{className:"text-xs text-muted-foreground",children:"Input"}),l.jsx("div",{className:"text-sm font-medium font-mono",children:Lr(i.input)})]}),l.jsxs("div",{children:[l.jsx("div",{className:"text-xs text-muted-foreground",children:"Output"}),l.jsx("div",{className:"text-sm font-medium font-mono",children:Lr(i.output)})]}),l.jsxs("div",{children:[l.jsx("div",{className:"text-xs text-muted-foreground",children:"Cached"}),l.jsx("div",{className:"text-sm font-medium font-mono",children:Lr(i.cached)})]}),l.jsxs("div",{children:[l.jsx("div",{className:"text-xs text-muted-foreground",children:"Cost"}),l.jsx("div",{className:"text-sm font-medium font-mono",children:i.cost>0?`$${i.cost.toFixed(4)}`:"-"})]})]})]}),W&&l.jsxs("div",{className:"border-t border-border",children:[l.jsxs("button",{className:"flex items-center gap-1.5 w-full px-4 py-2 text-xs text-muted-foreground hover:text-foreground transition-colors",onClick:()=>a(F=>!F),children:[l.jsx(xa,{className:re("h-3 w-3 transition-transform",o&&"rotate-90")}),"Session",J&&l.jsx("span",{className:"text-yellow-400 ml-1",children:"(changed)"})]}),o&&l.jsxs("div",{className:"px-4 pb-3 space-y-1 text-xs",children:[t.sessionIdBefore&&l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-muted-foreground w-12",children:J?"Before":"ID"}),l.jsx(kU,{text:t.sessionIdBefore,className:"font-mono"})]}),J&&t.sessionIdAfter&&l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-muted-foreground w-12",children:"After"}),l.jsx(kU,{text:t.sessionIdAfter,className:"font-mono"})]}),C.length>0&&l.jsxs("div",{className:"pt-1",children:[l.jsx("button",{type:"button",className:"text-[11px] text-muted-foreground underline underline-offset-2 hover:text-foreground disabled:opacity-60",disabled:_.isPending,onClick:()=>{const F=C.length;window.confirm(`Clear session for ${F} issue${F===1?"":"s"} touched by this run?`)&&_.mutate()},children:_.isPending?"clearing session...":"clear session for these issues"}),_.isError&&l.jsx("p",{className:"text-[11px] text-destructive mt-1",children:_.error instanceof Error?_.error.message:"Failed to clear sessions"})]})]})]})]}),S&&S.length>0&&l.jsxs("div",{className:"space-y-2",children:[l.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:["Issues Touched (",S.length,")"]}),l.jsx("div",{className:"border border-border rounded-lg divide-y divide-border",children:S.map(F=>l.jsxs(Bt,{to:`/issues/${F.identifier??F.issueId}`,className:"flex items-center justify-between w-full px-3 py-2 text-xs hover:bg-accent/20 transition-colors text-left no-underline text-inherit",children:[l.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[l.jsx(Fn,{status:F.status}),l.jsx("span",{className:"truncate",children:F.title})]}),l.jsx("span",{className:"font-mono text-muted-foreground shrink-0 ml-2",children:F.identifier??F.issueId.slice(0,8)})]},F.issueId))})]}),t.stderrExcerpt&&l.jsxs("div",{className:"space-y-1",children:[l.jsx("span",{className:"text-xs font-medium text-red-600 dark:text-red-400",children:"stderr"}),l.jsx("pre",{className:"bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-red-700 dark:text-red-300 overflow-x-auto whitespace-pre-wrap",children:t.stderrExcerpt})]}),t.stdoutExcerpt&&!t.logRef&&l.jsxs("div",{className:"space-y-1",children:[l.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"stdout"}),l.jsx("pre",{className:"bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-foreground overflow-x-auto whitespace-pre-wrap",children:t.stdoutExcerpt})]}),l.jsx(oUe,{run:t,adapterType:n}),l.jsx(Roe,{})]})}function oUe({run:t,adapterType:e}){const[n,r]=v.useState([]),[s,i]=v.useState([]),[o,a]=v.useState(!0),[c,d]=v.useState(!!t.logRef),[f,m]=v.useState(null),[p,x]=v.useState(0),[y,w]=v.useState(!1),[k,S]=v.useState(!1),C=v.useRef(null),_=v.useRef(""),E=v.useRef(null),j=v.useRef(!1),R=v.useRef({scrollHeight:0,distanceFromBottom:Number.POSITIVE_INFINITY}),T=t.status==="running"||t.status==="queued";function M(L){return L instanceof Xb&&L.status===404}function O(L,K=!1){if(!L&&!K)return;const B=`${_.current}${L}`.split(`
856
856
  `);_.current=B.pop()??"",K&&_.current&&(B.push(_.current),_.current="");const q=[];for(const H of B){const ie=H.trim();if(ie)try{const ce=JSON.parse(ie),ee=ce.stream==="stderr"||ce.stream==="system"?ce.stream:"stdout",Q=typeof ce.chunk=="string"?ce.chunk:"",ae=typeof ce.ts=="string"?ce.ts:new Date().toISOString();if(!Q)continue;q.push({ts:ae,stream:ee,chunk:Q})}catch{}}q.length>0&&i(H=>[...H,...q])}const{data:I}=Be({queryKey:["run-events",t.id],queryFn:()=>Kr.events(t.id,0,200)});v.useEffect(()=>{I&&(r(I),a(!1))},[I]);const $=v.useCallback(()=>{if(E.current)return E.current;const L=ZHe(C.current);return E.current=L,L},[]),z=v.useCallback(()=>{const L=$(),K=gC(L);R.current=K;const D=K.distanceFromBottom<=SU;j.current=D,w(B=>B===D?B:D)},[$]);v.useEffect(()=>{if(E.current=null,R.current={scrollHeight:0,distanceFromBottom:Number.POSITIVE_INFINITY},!T){j.current=!1,w(!1);return}z()},[T,t.id,z]),v.useEffect(()=>{if(!T)return;const L=$();return z(),L===window?window.addEventListener("scroll",z,{passive:!0}):L.addEventListener("scroll",z,{passive:!0}),window.addEventListener("resize",z),()=>{L===window?window.removeEventListener("scroll",z):L.removeEventListener("scroll",z),window.removeEventListener("resize",z)}},[T,t.id,$,z]),v.useEffect(()=>{if(!T||!j.current)return;const L=$(),K=R.current,D=gC(L),B=Math.max(0,D.scrollHeight-K.scrollHeight),q=K.distanceFromBottom+B;if(D.distanceFromBottom-q>SU){j.current=!1,w(!1),R.current=D;return}_U(L,"auto");const ie=gC(L);R.current=ie,j.current||(j.current=!0),w(ce=>ce||!0)},[n.length,s.length,T,$]),v.useEffect(()=>{let L=!1;if(_.current="",i([]),x(0),m(null),!t.logRef&&!T)return d(!1),()=>{L=!0};d(!0);const K=typeof t.logBytes=="number"&&t.logBytes>0?Math.min(Math.max(t.logBytes+1024,256e3),2e6):256e3;return(async()=>{try{let B=0,q=!0;for(;!L;){const H=await Kr.log(t.id,B,q?K:256e3);if(L)break;O(H.content,H.nextOffset===void 0);const ie=H.nextOffset??B+H.content.length;if(x(ie),B=ie,q=!1,H.nextOffset===void 0||T)break}}catch(B){if(!L){if(T&&M(B)){d(!1);return}m(B instanceof Error?B.message:"Failed to load run log")}}finally{L||d(!1)}})(),()=>{L=!0}},[t.id,t.logRef,t.logBytes,T]),v.useEffect(()=>{if(!T||k)return;const L=setInterval(async()=>{const K=n.length>0?Math.max(...n.map(D=>D.seq)):0;try{const D=await Kr.events(t.id,K,100);D.length>0&&r(B=>[...B,...D])}catch{}},2e3);return()=>clearInterval(L)},[t.id,T,k,n]),v.useEffect(()=>{if(!T||k)return;const L=setInterval(async()=>{try{const K=await Kr.log(t.id,p,256e3);K.content&&O(K.content,K.nextOffset===void 0),K.nextOffset!==void 0?x(K.nextOffset):K.content.length>0&&x(D=>D+K.content.length)}catch(K){if(M(K))return}},2e3);return()=>clearInterval(L)},[t.id,T,k,p]),v.useEffect(()=>{if(!T)return;let L=!1,K=null,D=null;const B=()=>{L||(K=window.setTimeout(q,1500))},q=()=>{if(L)return;const ie=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/api/companies/${encodeURIComponent(t.companyId)}/events/ws`;D=new WebSocket(ie),D.onopen=()=>{S(!0)},D.onmessage=ce=>{const ee=typeof ce.data=="string"?ce.data:"";if(!ee)return;let Q;try{Q=JSON.parse(ee)}catch{return}if(Q.companyId!==t.companyId)return;const ae=ng(Q.payload),ue=ei(ae==null?void 0:ae.runId);if(!ae||ue!==t.id)return;if(Q.type==="heartbeat.run.log"){const ye=typeof ae.chunk=="string"?ae.chunk:"";if(!ye)return;const et=ei(ae.stream),At=et==="stderr"||et==="system"?et:"stdout",Wt=ei(ae.ts)??Q.createdAt;i(Ut=>[...Ut,{ts:Wt,stream:At,chunk:ye}]);return}if(Q.type!=="heartbeat.run.event")return;const ge=typeof ae.seq=="number"?ae.seq:null;if(ge===null||!Number.isFinite(ge))return;const $e=ei(ae.stream),He=$e==="stdout"||$e==="stderr"||$e==="system"?$e:null,lt=ei(ae.level),rt=lt==="info"||lt==="warn"||lt==="error"?lt:null,Me={id:ge,companyId:t.companyId,runId:t.id,agentId:t.agentId,seq:ge,eventType:ei(ae.eventType)??"event",stream:He,level:rt,color:ei(ae.color),message:ei(ae.message),payload:ng(ae.payload),createdAt:new Date(Q.createdAt)};r(ye=>ye.some(et=>et.seq===ge)?ye:[...ye,Me])},D.onerror=()=>{D==null||D.close()},D.onclose=()=>{S(!1),B()}};return q(),()=>{L=!0,S(!1),K!==null&&window.clearTimeout(K),D&&(D.onopen=null,D.onmessage=null,D.onerror=null,D.onclose=null,D.close(1e3,"run_detail_unmount"))}},[T,t.companyId,t.id,t.agentId]);const V=v.useMemo(()=>{const L=n.find(K=>K.eventType==="adapter.invoke");return ng((L==null?void 0:L.payload)??null)},[n]),W=v.useMemo(()=>im(e),[e]),J=v.useMemo(()=>Y$e(s,W.parseStdoutLine),[s,W]);if(o&&c)return l.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading run logs..."});if(n.length===0&&s.length===0&&!f)return l.jsx("p",{className:"text-xs text-muted-foreground",children:"No log events."});const G={info:"text-foreground",warn:"text-yellow-600 dark:text-yellow-400",error:"text-red-600 dark:text-red-400"},F={stdout:"text-foreground",stderr:"text-red-600 dark:text-red-300",system:"text-blue-600 dark:text-blue-300"};return l.jsxs("div",{className:"space-y-3",children:[V&&l.jsxs("div",{className:"rounded-lg border border-border bg-background/60 p-3 space-y-2",children:[l.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Invocation"}),typeof V.adapterType=="string"&&l.jsxs("div",{className:"text-xs",children:[l.jsx("span",{className:"text-muted-foreground",children:"Adapter: "}),V.adapterType]}),typeof V.cwd=="string"&&l.jsxs("div",{className:"text-xs break-all",children:[l.jsx("span",{className:"text-muted-foreground",children:"Working dir: "}),l.jsx("span",{className:"font-mono",children:V.cwd})]}),typeof V.command=="string"&&l.jsxs("div",{className:"text-xs break-all",children:[l.jsx("span",{className:"text-muted-foreground",children:"Command: "}),l.jsx("span",{className:"font-mono",children:[V.command,...Array.isArray(V.commandArgs)?V.commandArgs.filter(L=>typeof L=="string"):[]].join(" ")})]}),Array.isArray(V.commandNotes)&&V.commandNotes.length>0&&l.jsxs("div",{children:[l.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"Command notes"}),l.jsx("ul",{className:"list-disc pl-5 space-y-1",children:V.commandNotes.filter(L=>typeof L=="string"&&L.trim().length>0).map((L,K)=>l.jsx("li",{className:"text-xs break-all font-mono",children:L},`${K}-${L}`))})]}),V.prompt!==void 0&&l.jsxs("div",{children:[l.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"Prompt"}),l.jsx("pre",{className:"bg-neutral-100 dark:bg-neutral-950 rounded-md p-2 text-xs overflow-x-auto whitespace-pre-wrap",children:typeof V.prompt=="string"?V.prompt:JSON.stringify(V.prompt,null,2)})]}),V.context!==void 0&&l.jsxs("div",{children:[l.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"Context"}),l.jsx("pre",{className:"bg-neutral-100 dark:bg-neutral-950 rounded-md p-2 text-xs overflow-x-auto whitespace-pre-wrap",children:JSON.stringify(V.context,null,2)})]}),V.env!==void 0&&l.jsxs("div",{children:[l.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"Environment"}),l.jsx("pre",{className:"bg-neutral-100 dark:bg-neutral-950 rounded-md p-2 text-xs overflow-x-auto whitespace-pre-wrap font-mono",children:JHe(V.env)})]})]}),l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:["Transcript (",J.length,")"]}),l.jsxs("div",{className:"flex items-center gap-2",children:[T&&!y&&l.jsx(ke,{variant:"ghost",size:"xs",onClick:()=>{const L=$();j.current=!0,w(!0),_U(L,"auto"),R.current=gC(L)},children:"Jump to live"}),T&&l.jsxs("span",{className:"flex items-center gap-1 text-xs text-cyan-400",children:[l.jsxs("span",{className:"relative flex h-2 w-2",children:[l.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-cyan-400 opacity-75"}),l.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-cyan-400"})]}),"Live"]})]})]}),l.jsxs("div",{className:"bg-neutral-100 dark:bg-neutral-950 rounded-lg p-3 font-mono text-xs space-y-0.5 overflow-x-hidden",children:[J.length===0&&!t.logRef&&l.jsx("div",{className:"text-neutral-500",children:"No persisted transcript for this run."}),J.map((L,K)=>{const D=new Date(L.ts).toLocaleTimeString("en-US",{hour12:!1}),B="grid grid-cols-[auto_auto_1fr] gap-x-2 sm:gap-x-3 items-baseline",q="text-neutral-400 dark:text-neutral-600 select-none w-12 sm:w-16 text-[10px] sm:text-xs",H="w-14 sm:w-20 text-[10px] sm:text-xs",ie="min-w-0 whitespace-pre-wrap break-words overflow-hidden",ce="col-span-full md:col-start-3 md:col-span-1";if(L.kind==="assistant")return l.jsxs("div",{className:re(B,"py-0.5"),children:[l.jsx("span",{className:q,children:D}),l.jsx("span",{className:re(H,"text-green-700 dark:text-green-300"),children:"assistant"}),l.jsx("span",{className:re(ie,"text-green-900 dark:text-green-100"),children:L.text})]},`${L.ts}-assistant-${K}`);if(L.kind==="thinking")return l.jsxs("div",{className:re(B,"py-0.5"),children:[l.jsx("span",{className:q,children:D}),l.jsx("span",{className:re(H,"text-green-600/60 dark:text-green-300/60"),children:"thinking"}),l.jsx("span",{className:re(ie,"text-green-800/60 dark:text-green-100/60 italic"),children:L.text})]},`${L.ts}-thinking-${K}`);if(L.kind==="user")return l.jsxs("div",{className:re(B,"py-0.5"),children:[l.jsx("span",{className:q,children:D}),l.jsx("span",{className:re(H,"text-neutral-500 dark:text-neutral-400"),children:"user"}),l.jsx("span",{className:re(ie,"text-neutral-700 dark:text-neutral-300"),children:L.text})]},`${L.ts}-user-${K}`);if(L.kind==="tool_call")return l.jsxs("div",{className:re(B,"gap-y-1 py-0.5"),children:[l.jsx("span",{className:q,children:D}),l.jsx("span",{className:re(H,"text-yellow-700 dark:text-yellow-300"),children:"tool_call"}),l.jsx("span",{className:"text-yellow-900 dark:text-yellow-100 min-w-0",children:L.name}),l.jsx("pre",{className:re(ce,"bg-neutral-200 dark:bg-neutral-900 rounded p-2 text-[11px] overflow-x-auto whitespace-pre-wrap text-neutral-800 dark:text-neutral-200"),children:JSON.stringify(L.input,null,2)})]},`${L.ts}-tool-${K}`);if(L.kind==="tool_result")return l.jsxs("div",{className:re(B,"gap-y-1 py-0.5"),children:[l.jsx("span",{className:q,children:D}),l.jsx("span",{className:re(H,L.isError?"text-red-600 dark:text-red-300":"text-purple-600 dark:text-purple-300"),children:"tool_result"}),L.isError?l.jsx("span",{className:"text-red-600 dark:text-red-400 min-w-0",children:"error"}):l.jsx("span",{}),l.jsx("pre",{className:re(ce,"bg-neutral-100 dark:bg-neutral-900 rounded p-2 text-[11px] overflow-x-auto whitespace-pre-wrap text-neutral-700 dark:text-neutral-300 max-h-60 overflow-y-auto"),children:(()=>{try{return JSON.stringify(JSON.parse(L.content),null,2)}catch{return L.content}})()})]},`${L.ts}-toolres-${K}`);if(L.kind==="init")return l.jsxs("div",{className:B,children:[l.jsx("span",{className:q,children:D}),l.jsx("span",{className:re(H,"text-blue-700 dark:text-blue-300"),children:"init"}),l.jsxs("span",{className:re(ie,"text-blue-900 dark:text-blue-100"),children:["model: ",L.model,L.sessionId?`, session: ${L.sessionId}`:""]})]},`${L.ts}-init-${K}`);if(L.kind==="result")return l.jsxs("div",{className:re(B,"gap-y-1 py-0.5"),children:[l.jsx("span",{className:q,children:D}),l.jsx("span",{className:re(H,"text-cyan-700 dark:text-cyan-300"),children:"result"}),l.jsxs("span",{className:re(ie,"text-cyan-900 dark:text-cyan-100"),children:["tokens in=",Lr(L.inputTokens)," out=",Lr(L.outputTokens)," cached=",Lr(L.cachedTokens)," cost=$",L.costUsd.toFixed(6)]}),(L.subtype||L.isError||L.errors.length>0)&&l.jsxs("div",{className:re(ce,"text-red-600 dark:text-red-300 whitespace-pre-wrap break-words"),children:["subtype=",L.subtype||"unknown"," is_error=",L.isError?"true":"false",L.errors.length>0?` errors=${L.errors.join(" | ")}`:""]}),L.text&&l.jsx("div",{className:re(ce,"whitespace-pre-wrap break-words text-neutral-800 dark:text-neutral-100"),children:L.text})]},`${L.ts}-result-${K}`);const ee=L.text,Q=L.kind==="stderr"?"stderr":L.kind==="system"?"system":"stdout",ae=L.kind==="stderr"?"text-red-600 dark:text-red-300":L.kind==="system"?"text-blue-600 dark:text-blue-300":"text-neutral-500";return l.jsxs("div",{className:B,children:[l.jsx("span",{className:q,children:D}),l.jsx("span",{className:re(H,ae),children:Q}),l.jsx("span",{className:re(ie,ae),children:ee})]},`${L.ts}-raw-${K}`)}),f&&l.jsx("div",{className:"text-red-600 dark:text-red-300",children:f}),l.jsx("div",{ref:C})]}),(t.status==="failed"||t.status==="timed_out")&&l.jsxs("div",{className:"rounded-lg border border-red-300 dark:border-red-500/30 bg-red-50 dark:bg-red-950/20 p-3 space-y-2",children:[l.jsx("div",{className:"text-xs font-medium text-red-700 dark:text-red-300",children:"Failure details"}),t.error&&l.jsxs("div",{className:"text-xs text-red-600 dark:text-red-200",children:[l.jsx("span",{className:"text-red-700 dark:text-red-300",children:"Error: "}),t.error]}),t.stderrExcerpt&&t.stderrExcerpt.trim()&&l.jsxs("div",{children:[l.jsx("div",{className:"text-xs text-red-700 dark:text-red-300 mb-1",children:"stderr excerpt"}),l.jsx("pre",{className:"bg-red-50 dark:bg-neutral-950 rounded-md p-2 text-xs overflow-x-auto whitespace-pre-wrap text-red-800 dark:text-red-100",children:t.stderrExcerpt})]}),t.resultJson&&l.jsxs("div",{children:[l.jsx("div",{className:"text-xs text-red-700 dark:text-red-300 mb-1",children:"adapter result JSON"}),l.jsx("pre",{className:"bg-red-50 dark:bg-neutral-950 rounded-md p-2 text-xs overflow-x-auto whitespace-pre-wrap text-red-800 dark:text-red-100",children:JSON.stringify(t.resultJson,null,2)})]}),t.stdoutExcerpt&&t.stdoutExcerpt.trim()&&!t.resultJson&&l.jsxs("div",{children:[l.jsx("div",{className:"text-xs text-red-700 dark:text-red-300 mb-1",children:"stdout excerpt"}),l.jsx("pre",{className:"bg-red-50 dark:bg-neutral-950 rounded-md p-2 text-xs overflow-x-auto whitespace-pre-wrap text-red-800 dark:text-red-100",children:t.stdoutExcerpt})]})]}),n.length>0&&l.jsxs("div",{children:[l.jsxs("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:["Events (",n.length,")"]}),l.jsx("div",{className:"bg-neutral-100 dark:bg-neutral-950 rounded-lg p-3 font-mono text-xs space-y-0.5",children:n.map(L=>{const K=L.color??(L.level?G[L.level]:null)??(L.stream?F[L.stream]:null)??"text-foreground";return l.jsxs("div",{className:"flex gap-2",children:[l.jsx("span",{className:"text-neutral-400 dark:text-neutral-600 shrink-0 select-none w-16",children:new Date(L.createdAt).toLocaleTimeString("en-US",{hour12:!1})}),l.jsx("span",{className:re("shrink-0 w-14",L.stream?F[L.stream]??"text-neutral-500":"text-neutral-500"),children:L.stream?`[${L.stream}]`:""}),l.jsx("span",{className:re("break-all",K),children:L.message??(L.payload?JSON.stringify(L.payload):"")})]},L.id)})})]})]})}function aUe({agentId:t,companyId:e}){const n=Nn(),[r,s]=v.useState(""),[i,o]=v.useState(null),[a,c]=v.useState(!1),[d,f]=v.useState(!1),{data:m,isLoading:p}=Be({queryKey:te.agents.keys(t),queryFn:()=>Ot.listKeys(t,e)}),x=yt({mutationFn:()=>Ot.createKey(t,r.trim()||"Default",e),onSuccess:C=>{o(C.token),c(!0),s(""),n.invalidateQueries({queryKey:te.agents.keys(t)})}}),y=yt({mutationFn:C=>Ot.revokeKey(t,C,e),onSuccess:()=>{n.invalidateQueries({queryKey:te.agents.keys(t)})}});function w(){i&&(navigator.clipboard.writeText(i),f(!0),setTimeout(()=>f(!1),2e3))}const k=(m??[]).filter(C=>!C.revokedAt),S=(m??[]).filter(C=>C.revokedAt);return l.jsxs("div",{className:"space-y-6",children:[i&&l.jsxs("div",{className:"border border-yellow-300 dark:border-yellow-600/40 bg-yellow-50 dark:bg-yellow-500/5 rounded-lg p-4 space-y-2",children:[l.jsx("p",{className:"text-sm font-medium text-yellow-700 dark:text-yellow-400",children:"API key created — copy it now, it will not be shown again."}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("code",{className:"flex-1 bg-neutral-100 dark:bg-neutral-950 rounded px-3 py-1.5 text-xs font-mono text-green-700 dark:text-green-300 truncate",children:a?i:i.replace(/./g,"•")}),l.jsx(ke,{variant:"ghost",size:"icon-sm",onClick:()=>c(C=>!C),title:a?"Hide":"Show",children:a?l.jsx(R2,{className:"h-3.5 w-3.5"}):l.jsx(QR,{className:"h-3.5 w-3.5"})}),l.jsx(ke,{variant:"ghost",size:"icon-sm",onClick:w,title:"Copy",children:l.jsx(YR,{className:"h-3.5 w-3.5"})}),d&&l.jsx("span",{className:"text-xs text-green-400",children:"Copied!"})]}),l.jsx(ke,{variant:"ghost",size:"sm",className:"text-muted-foreground text-xs",onClick:()=>o(null),children:"Dismiss"})]}),l.jsxs("div",{className:"border border-border rounded-lg p-4 space-y-3",children:[l.jsxs("h3",{className:"text-xs font-medium text-muted-foreground flex items-center gap-2",children:[l.jsx(Kve,{className:"h-3.5 w-3.5"}),"Create API Key"]}),l.jsx("p",{className:"text-xs text-muted-foreground",children:"API keys allow this agent to authenticate calls to the Paperclip server."}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(Jc,{placeholder:"Key name (e.g. production)",value:r,onChange:C=>s(C.target.value),className:"h-8 text-sm",onKeyDown:C=>{C.key==="Enter"&&x.mutate()}}),l.jsxs(ke,{size:"sm",onClick:()=>x.mutate(),disabled:x.isPending,children:[l.jsx(Pr,{className:"h-3.5 w-3.5 mr-1"}),"Create"]})]})]}),p&&l.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading keys..."}),!p&&k.length===0&&!i&&l.jsx("p",{className:"text-sm text-muted-foreground",children:"No active API keys."}),k.length>0&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:"Active Keys"}),l.jsx("div",{className:"border border-border rounded-lg divide-y divide-border",children:k.map(C=>l.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5",children:[l.jsxs("div",{children:[l.jsx("span",{className:"text-sm font-medium",children:C.name}),l.jsxs("span",{className:"text-xs text-muted-foreground ml-3",children:["Created ",ki(C.createdAt)]})]}),l.jsx(ke,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive text-xs",onClick:()=>y.mutate(C.id),disabled:y.isPending,children:"Revoke"})]},C.id))})]}),S.length>0&&l.jsxs("div",{children:[l.jsx("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:"Revoked Keys"}),l.jsx("div",{className:"border border-border rounded-lg divide-y divide-border opacity-50",children:S.map(C=>l.jsx("div",{className:"flex items-center justify-between px-4 py-2.5",children:l.jsxs("div",{children:[l.jsx("span",{className:"text-sm line-through",children:C.name}),l.jsxs("span",{className:"text-xs text-muted-foreground ml-3",children:["Revoked ",C.revokedAt?ki(C.revokedAt):""]})]})},C.id))})]})]})}function lUe(){const{selectedCompanyId:t}=en(),{openNewProject:e}=$r(),{setBreadcrumbs:n}=bs();v.useEffect(()=>{n([{label:"Projects"}])},[n]);const{data:r,isLoading:s,error:i}=Be({queryKey:te.projects.list(t),queryFn:()=>oi.list(t),enabled:!!t});return t?s?l.jsx(ui,{variant:"list"}):l.jsxs("div",{className:"space-y-4",children:[l.jsx("div",{className:"flex items-center justify-end",children:l.jsxs(ke,{size:"sm",variant:"outline",onClick:e,children:[l.jsx(Pr,{className:"h-4 w-4 mr-1"}),"Add Project"]})}),i&&l.jsx("p",{className:"text-sm text-destructive",children:i.message}),r&&r.length===0&&l.jsx(Os,{icon:Jl,message:"No projects yet.",action:"Add Project",onAction:e}),r&&r.length>0&&l.jsx("div",{className:"border border-border",children:r.map(o=>l.jsx(Al,{title:o.name,subtitle:o.description??void 0,to:US(o),trailing:l.jsxs("div",{className:"flex items-center gap-3",children:[o.targetDate&&l.jsx("span",{className:"text-xs text-muted-foreground",children:ki(o.targetDate)}),l.jsx(Fn,{status:o.status})]})},o.id))})]}):l.jsx(Os,{icon:Jl,message:"Select a company to view projects."})}function Yi({className:t,orientation:e="horizontal",decorative:n=!0,...r}){return l.jsx(rJ,{"data-slot":"separator",decorative:n,orientation:e,className:re("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",t),...r})}const cUe=[{value:"backlog",label:"Backlog"},{value:"planned",label:"Planned"},{value:"in_progress",label:"In Progress"},{value:"completed",label:"Completed"},{value:"cancelled",label:"Cancelled"}],PA="/__paperclip_repo_only__";function W0({label:t,children:e}){return l.jsxs("div",{className:"flex items-center gap-3 py-1.5",children:[l.jsx("span",{className:"text-xs text-muted-foreground shrink-0 w-20",children:t}),l.jsx("div",{className:"flex items-center gap-1.5 min-w-0",children:e})]})}function uUe({status:t,onChange:e}){const[n,r]=v.useState(!1),s=OZ[t]??IZ;return l.jsxs(Bn,{open:n,onOpenChange:r,children:[l.jsx(zn,{asChild:!0,children:l.jsx("button",{className:re("inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium whitespace-nowrap shrink-0 cursor-pointer hover:opacity-80 transition-opacity",s),children:t.replace("_"," ")})}),l.jsx(Vn,{className:"w-40 p-1",align:"start",children:cUe.map(i=>l.jsx(ke,{variant:"ghost",size:"sm",className:re("w-full justify-start gap-2 text-xs",i.value===t&&"bg-accent"),onClick:()=>{e(i.value),r(!1)},children:i.label},i.value))})]})}function jU({project:t,onUpdate:e}){const{selectedCompanyId:n}=en(),r=Nn(),[s,i]=v.useState(!1),[o,a]=v.useState(null),[c,d]=v.useState(""),[f,m]=v.useState(""),[p,x]=v.useState(null),{data:y}=Be({queryKey:te.goals.list(n),queryFn:()=>Ja.list(n),enabled:!!n}),w=t.goalIds.length>0?t.goalIds:t.goalId?[t.goalId]:[],k=t.goals.length>0?t.goals:w.map(L=>{var K;return{id:L,title:((K=y==null?void 0:y.find(D=>D.id===L))==null?void 0:K.title)??L.slice(0,8)}}),S=(y??[]).filter(L=>!w.includes(L.id)),C=t.workspaces??[],_=()=>{r.invalidateQueries({queryKey:te.projects.detail(t.id)}),n&&r.invalidateQueries({queryKey:te.projects.list(n)})},E=yt({mutationFn:L=>oi.createWorkspace(t.id,L),onSuccess:()=>{d(""),m(""),a(null),x(null),_()}}),j=yt({mutationFn:L=>oi.removeWorkspace(t.id,L),onSuccess:_}),R=yt({mutationFn:({workspaceId:L,data:K})=>oi.updateWorkspace(t.id,L,K),onSuccess:_}),T=L=>{e&&e({goalIds:w.filter(K=>K!==L)})},M=L=>{!e||w.includes(L)||(e({goalIds:[...w,L]}),i(!1))},O=L=>L.startsWith("/")||/^[A-Za-z]:[\\/]/.test(L),I=L=>{try{const K=new URL(L),D=K.hostname.toLowerCase();return D!=="github.com"&&D!=="www.github.com"?!1:K.pathname.split("/").filter(Boolean).length>=2}catch{return!1}},$=L=>{const D=L.trim().replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean);return D[D.length-1]??"Local folder"},z=L=>{var K;try{const B=new URL(L).pathname.split("/").filter(Boolean);return(((K=B[B.length-1])==null?void 0:K.replace(/\.git$/i,""))??"")||"GitHub repo"}catch{return"GitHub repo"}},V=L=>{var K;try{const B=new URL(L).pathname.split("/").filter(Boolean);if(B.length<2)return L;const q=B[0],H=(K=B[1])==null?void 0:K.replace(/\.git$/i,"");return!q||!H?L:`${q}/${H}`}catch{return L}},W=()=>{const L=c.trim();if(!O(L)){x("Local folder must be a full absolute path.");return}x(null),E.mutate({name:$(L),cwd:L})},J=()=>{const L=f.trim();if(!I(L)){x("Repo workspace must use a valid GitHub repo URL.");return}x(null),E.mutate({name:z(L),cwd:PA,repoUrl:L})},G=L=>{if(window.confirm(L.repoUrl?"Clear local folder from this workspace?":"Delete this workspace local folder?")){if(L.repoUrl){R.mutate({workspaceId:L.id,data:{cwd:null}});return}j.mutate(L.id)}},F=L=>{const K=!!(L.cwd&&L.cwd!==PA);if(window.confirm(K?"Clear GitHub repo from this workspace?":"Delete this workspace repo?")){if(K){R.mutate({workspaceId:L.id,data:{repoUrl:null,repoRef:null}});return}j.mutate(L.id)}};return l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsx(W0,{label:"Status",children:e?l.jsx(uUe,{status:t.status,onChange:L=>e({status:L})}):l.jsx(Fn,{status:t.status})}),t.leadAgentId&&l.jsx(W0,{label:"Lead",children:l.jsx("span",{className:"text-sm font-mono",children:t.leadAgentId.slice(0,8)})}),l.jsx("div",{className:"py-1.5",children:l.jsxs("div",{className:"flex items-start justify-between gap-2",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Goals"}),l.jsxs("div",{className:"flex flex-col items-end gap-1.5",children:[k.length===0?l.jsx("span",{className:"text-sm text-muted-foreground",children:"None"}):l.jsx("div",{className:"flex flex-wrap justify-end gap-1.5 max-w-[220px]",children:k.map(L=>l.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs",children:[l.jsx(Bt,{to:`/goals/${L.id}`,className:"hover:underline max-w-[140px] truncate",children:L.title}),e&&l.jsx("button",{className:"text-muted-foreground hover:text-foreground",type:"button",onClick:()=>T(L.id),"aria-label":`Remove goal ${L.title}`,children:l.jsx(ii,{className:"h-3 w-3"})})]},L.id))}),e&&l.jsxs(Bn,{open:s,onOpenChange:i,children:[l.jsx(zn,{asChild:!0,children:l.jsxs(ke,{variant:"outline",size:"xs",className:"h-6 px-2",disabled:S.length===0,children:[l.jsx(Pr,{className:"h-3 w-3 mr-1"}),"Goal"]})}),l.jsx(Vn,{className:"w-56 p-1",align:"end",children:S.length===0?l.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"All goals linked."}):S.map(L=>l.jsx("button",{className:"flex items-center w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",onClick:()=>M(L.id),children:L.title},L.id))})]})]})]})}),t.targetDate&&l.jsx(W0,{label:"Target Date",children:l.jsx("span",{className:"text-sm",children:ki(t.targetDate)})})]}),l.jsx(Yi,{}),l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"py-1.5 space-y-2",children:[l.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[l.jsx("span",{children:"Workspaces"}),l.jsxs(jg,{children:[l.jsx(Ag,{asChild:!0,children:l.jsx("button",{type:"button",className:"inline-flex h-4 w-4 items-center justify-center rounded-full border border-border text-[10px] text-muted-foreground hover:text-foreground","aria-label":"Workspaces help",children:"?"})}),l.jsx(Tg,{side:"top",children:"Workspaces give your agents hints about where the work is"})]})]}),C.length===0?l.jsx("p",{className:"rounded-md border border-dashed border-border px-3 py-2 text-sm text-muted-foreground",children:"No workspace configured."}):l.jsx("div",{className:"space-y-1",children:C.map(L=>l.jsxs("div",{className:"space-y-1",children:[L.cwd&&L.cwd!==PA?l.jsxs("div",{className:"flex items-center justify-between gap-2 py-1",children:[l.jsx("span",{className:"min-w-0 truncate font-mono text-xs text-muted-foreground",children:L.cwd}),l.jsx(ke,{variant:"ghost",size:"icon-xs",onClick:()=>G(L),"aria-label":"Delete local folder",children:l.jsx(lu,{className:"h-3 w-3"})})]}):null,L.repoUrl?l.jsxs("div",{className:"flex items-center justify-between gap-2 py-1",children:[l.jsxs("a",{href:L.repoUrl,target:"_blank",rel:"noreferrer",className:"inline-flex min-w-0 items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground hover:underline",children:[l.jsx(wY,{className:"h-3 w-3 shrink-0"}),l.jsx("span",{className:"truncate",children:V(L.repoUrl)}),l.jsx(ZR,{className:"h-3 w-3 shrink-0"})]}),l.jsx(ke,{variant:"ghost",size:"icon-xs",onClick:()=>F(L),"aria-label":"Delete workspace repo",children:l.jsx(lu,{className:"h-3 w-3"})})]}):null]},L.id))}),l.jsxs("div",{className:"flex flex-col items-start gap-2",children:[l.jsx(ke,{variant:"outline",size:"xs",className:"h-7 px-2.5",onClick:()=>{a("local"),x(null)},children:"Add workspace local folder"}),l.jsx(ke,{variant:"outline",size:"xs",className:"h-7 px-2.5",onClick:()=>{a("repo"),x(null)},children:"Add workspace repo"})]}),o==="local"&&l.jsxs("div",{className:"space-y-1.5 rounded-md border border-border p-2",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("input",{className:"w-full rounded border border-border bg-transparent px-2 py-1 text-xs font-mono outline-none",value:c,onChange:L=>d(L.target.value),placeholder:"/absolute/path/to/workspace"}),l.jsx(Fu,{})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(ke,{variant:"outline",size:"xs",className:"h-6 px-2",disabled:!c.trim()||E.isPending,onClick:W,children:"Save"}),l.jsx(ke,{variant:"ghost",size:"xs",className:"h-6 px-2",onClick:()=>{a(null),d(""),x(null)},children:"Cancel"})]})]}),o==="repo"&&l.jsxs("div",{className:"space-y-1.5 rounded-md border border-border p-2",children:[l.jsx("input",{className:"w-full rounded border border-border bg-transparent px-2 py-1 text-xs outline-none",value:f,onChange:L=>m(L.target.value),placeholder:"https://github.com/org/repo"}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(ke,{variant:"outline",size:"xs",className:"h-6 px-2",disabled:!f.trim()||E.isPending,onClick:J,children:"Save"}),l.jsx(ke,{variant:"ghost",size:"xs",className:"h-6 px-2",onClick:()=>{a(null),m(""),x(null)},children:"Cancel"})]})]}),p&&l.jsx("p",{className:"text-xs text-destructive",children:p}),E.isError&&l.jsx("p",{className:"text-xs text-destructive",children:"Failed to save workspace."}),j.isError&&l.jsx("p",{className:"text-xs text-destructive",children:"Failed to delete workspace."}),R.isError&&l.jsx("p",{className:"text-xs text-destructive",children:"Failed to update workspace."})]}),l.jsx(Yi,{}),l.jsx(W0,{label:"Created",children:l.jsx("span",{className:"text-sm",children:ki(t.createdAt)})}),l.jsx(W0,{label:"Updated",children:l.jsx("span",{className:"text-sm",children:ki(t.updatedAt)})})]})]})}const FA="px-1 -mx-1";function du({value:t,onSave:e,as:n="span",className:r,placeholder:s="Click to edit...",multiline:i=!1,imageUploadHandler:o,mentions:a}){const[c,d]=v.useState(!1),[f,m]=v.useState(t),p=v.useRef(null);v.useEffect(()=>{m(t)},[t]);const x=v.useCallback(S=>{S&&(S.style.height="auto",S.style.height=`${S.scrollHeight}px`)},[]);v.useEffect(()=>{c&&p.current&&(p.current.focus(),p.current.select(),p.current instanceof HTMLTextAreaElement&&x(p.current))},[c,x]);function y(){const S=f.trim();S&&S!==t?e(S):m(t),d(!1)}function w(S){S.key==="Enter"&&!i&&(S.preventDefault(),y()),S.key==="Escape"&&(m(t),d(!1))}if(c)return i?l.jsxs("div",{className:re("space-y-2",FA),children:[l.jsx(su,{value:f,onChange:m,placeholder:s,contentClassName:r,imageUploadHandler:o,mentions:a,onSubmit:y}),l.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l.jsx(ke,{variant:"outline",size:"sm",onClick:()=>{m(t),d(!1)},children:"Cancel"}),l.jsx(ke,{size:"sm",onClick:y,children:"Save"})]})]}):l.jsx("textarea",{ref:p,value:f,rows:1,onChange:S=>{m(S.target.value),x(S.target)},onBlur:y,onKeyDown:w,className:re("w-full bg-transparent rounded outline-none resize-none overflow-hidden",FA,r)});const k=t&&i?"div":n;return l.jsx(k,{className:re("cursor-pointer rounded hover:bg-accent/50 transition-colors",FA,!t&&"text-muted-foreground italic",r),onClick:()=>d(!0),children:t&&i?l.jsx(i5,{children:t}):t||s})}function $A(t,e){const n={};for(const r of t){const s=e(r);n[s]||(n[s]=[]),n[s].push(r)}return n}function ch({className:t,...e}){return l.jsx(PK,{"data-slot":"checkbox",className:re("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",t),...e,children:l.jsx($K,{"data-slot":"checkbox-indicator",className:"grid place-content-center text-current transition-none",children:l.jsx(fa,{className:"size-3.5"})})})}const BA=["backlog","todo","in_progress","in_review","blocked","done","cancelled"];function dUe(t){return t.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function fUe({status:t,issues:e,agents:n,liveIssueIds:r}){const{setNodeRef:s,isOver:i}=XY({id:t});return l.jsxs("div",{className:"flex flex-col min-w-[260px] w-[260px] shrink-0",children:[l.jsxs("div",{className:"flex items-center gap-2 px-2 py-2 mb-1",children:[l.jsx(qr,{status:t}),l.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:dUe(t)}),l.jsx("span",{className:"text-xs text-muted-foreground/60 ml-auto tabular-nums",children:e.length})]}),l.jsx("div",{ref:s,className:`flex-1 min-h-[120px] rounded-md p-1 space-y-1 transition-colors ${i?"bg-accent/40":"bg-muted/20"}`,children:l.jsx(gO,{items:e.map(o=>o.id),strategy:pO,children:e.map(o=>l.jsx(Poe,{issue:o,agents:n,isLive:r==null?void 0:r.has(o.id)},o.id))})})]})}function Poe({issue:t,agents:e,isLive:n,isOverlay:r}){const{attributes:s,listeners:i,setNodeRef:o,transform:a,transition:c,isDragging:d}=xO({id:t.id,data:{issue:t}}),f={transform:Zl.Transform.toString(a),transition:c},m=p=>{var x;return!p||!e?null:((x=e.find(y=>y.id===p))==null?void 0:x.name)??null};return l.jsx("div",{ref:o,style:f,...s,...i,className:`rounded-md border bg-card p-2.5 cursor-grab active:cursor-grabbing transition-shadow ${d&&!r?"opacity-30":""} ${r?"shadow-lg ring-1 ring-primary/20":"hover:shadow-sm"}`,children:l.jsxs(Bt,{to:`/issues/${t.identifier??t.id}`,className:"block no-underline text-inherit",onClick:p=>{d&&p.preventDefault()},children:[l.jsxs("div",{className:"flex items-start gap-1.5 mb-1.5",children:[l.jsx("span",{className:"text-xs text-muted-foreground font-mono shrink-0",children:t.identifier??t.id.slice(0,8)}),n&&l.jsxs("span",{className:"relative flex h-2 w-2 shrink-0 mt-0.5",children:[l.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),l.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-blue-500"})]})]}),l.jsx("p",{className:"text-sm leading-snug line-clamp-2 mb-2",children:t.title}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(Ss,{priority:t.priority}),t.assigneeAgentId&&(()=>{const p=m(t.assigneeAgentId);return p?l.jsx(Sn,{name:p,size:"xs"}):l.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:t.assigneeAgentId.slice(0,8)})})()]})]})})}function hUe({issues:t,agents:e,liveIssueIds:n,onUpdateIssue:r}){const[s,i]=v.useState(null),o=cO(lO(mv,{activationConstraint:{distance:5}})),a=v.useMemo(()=>{const p={};for(const x of BA)p[x]=[];for(const x of t)p[x.status]&&p[x.status].push(x);return p},[t]),c=v.useMemo(()=>s?t.find(p=>p.id===s):null,[s,t]);function d(p){i(p.active.id)}function f(p){i(null);const{active:x,over:y}=p;if(!y)return;const w=x.id,k=t.find(C=>C.id===w);if(!k)return;let S=null;if(BA.includes(y.id))S=y.id;else{const C=t.find(_=>_.id===y.id);C&&(S=C.status)}S&&S!==k.status&&r(w,{status:S})}function m(p){}return l.jsxs(mO,{sensors:o,onDragStart:d,onDragOver:m,onDragEnd:f,children:[l.jsx("div",{className:"flex gap-3 overflow-x-auto pb-4 -mx-2 px-2",children:BA.map(p=>l.jsx(fUe,{status:p,issues:a[p]??[],agents:e,liveIssueIds:n},p))}),l.jsx(UCe,{children:c?l.jsx(Poe,{issue:c,agents:e,isOverlay:!0}):null})]})}const Xk=["in_progress","todo","backlog","in_review","blocked","done","cancelled"],eS=["critical","high","medium","low"];function yC(t){return t.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase())}const tS={statuses:[],priorities:[],assignees:[],labels:[],sortField:"updated",sortDir:"desc",groupBy:"none",viewMode:"list",collapsedGroups:[]},mUe=[{label:"All",statuses:[]},{label:"Active",statuses:["todo","in_progress","in_review","blocked"]},{label:"Backlog",statuses:["backlog"]},{label:"Done",statuses:["done","cancelled"]}];function AU(t){try{const e=localStorage.getItem(t);if(e)return{...tS,...JSON.parse(e)}}catch{}return{...tS}}function pUe(t,e){localStorage.setItem(t,JSON.stringify(e))}function gUe(t,e){if(t.length!==e.length)return!1;const n=[...t].sort(),r=[...e].sort();return n.every((s,i)=>s===r[i])}function bC(t,e){return t.includes(e)?t.filter(n=>n!==e):[...t,e]}function xUe(t,e){let n=t;return e.statuses.length>0&&(n=n.filter(r=>e.statuses.includes(r.status))),e.priorities.length>0&&(n=n.filter(r=>e.priorities.includes(r.priority))),e.assignees.length>0&&(n=n.filter(r=>r.assigneeAgentId!=null&&e.assignees.includes(r.assigneeAgentId))),e.labels.length>0&&(n=n.filter(r=>(r.labelIds??[]).some(s=>e.labels.includes(s)))),n}function yUe(t,e){const n=[...t],r=e.sortDir==="asc"?1:-1;return n.sort((s,i)=>{switch(e.sortField){case"status":return r*(Xk.indexOf(s.status)-Xk.indexOf(i.status));case"priority":return r*(eS.indexOf(s.priority)-eS.indexOf(i.priority));case"title":return r*s.title.localeCompare(i.title);case"created":return r*(new Date(s.createdAt).getTime()-new Date(i.createdAt).getTime());case"updated":return r*(new Date(s.updatedAt).getTime()-new Date(i.updatedAt).getTime());default:return 0}}),n}function bUe(t){let e=0;return t.statuses.length>0&&e++,t.priorities.length>0&&e++,t.assignees.length>0&&e++,t.labels.length>0&&e++,e}function Foe({issues:t,isLoading:e,error:n,agents:r,liveIssueIds:s,projectId:i,viewStateKey:o,initialAssignees:a,initialSearch:c,onSearchChange:d,onUpdateIssue:f}){const{selectedCompanyId:m}=en(),{openNewIssue:p}=$r(),x=m?`${o}:${m}`:o,[y,w]=v.useState(()=>a?{...tS,assignees:a,statuses:[]}:AU(x)),[k,S]=v.useState(null),[C,_]=v.useState(""),[E,j]=v.useState(c??""),[R,T]=v.useState(E),M=R.trim();v.useEffect(()=>{j(c??"")},[c]),v.useEffect(()=>{const K=window.setTimeout(()=>{T(E)},300);return()=>window.clearTimeout(K)},[E]);const O=v.useRef(x);v.useEffect(()=>{O.current!==x&&(O.current=x,w(a?{...tS,assignees:a,statuses:[]}:AU(x)))},[x,a]);const I=v.useCallback(K=>{w(D=>{const B={...D,...K};return pUe(x,B),B})},[x]),{data:$=[]}=Be({queryKey:te.issues.search(m,M,i),queryFn:()=>Dn.list(m,{q:M,projectId:i}),enabled:!!m&&M.length>0}),z=v.useCallback(K=>{var D;return!K||!r?null:((D=r.find(B=>B.id===K))==null?void 0:D.name)??null},[r]),V=v.useMemo(()=>{const K=M.length>0?$:t,D=xUe(K,y);return yUe(D,y)},[t,$,y,M]),{data:W}=Be({queryKey:te.issues.labels(m),queryFn:()=>Dn.listLabels(m),enabled:!!m}),J=bUe(y),G=v.useMemo(()=>{if(y.groupBy==="none")return[{key:"__all",label:null,items:V}];if(y.groupBy==="status"){const D=$A(V,B=>B.status);return Xk.filter(B=>{var q;return(q=D[B])==null?void 0:q.length}).map(B=>({key:B,label:yC(B),items:D[B]}))}if(y.groupBy==="priority"){const D=$A(V,B=>B.priority);return eS.filter(B=>{var q;return(q=D[B])==null?void 0:q.length}).map(B=>({key:B,label:yC(B),items:D[B]}))}const K=$A(V,D=>D.assigneeAgentId??"__unassigned");return Object.keys(K).map(D=>({key:D,label:D==="__unassigned"?"Unassigned":z(D)??D.slice(0,8),items:K[D]}))},[V,y.groupBy,r]),F=K=>{const D={};return i&&(D.projectId=i),K&&(y.groupBy==="status"?D.status=K:y.groupBy==="priority"?D.priority=K:y.groupBy==="assignee"&&K!=="__unassigned"&&(D.assigneeAgentId=K)),D},L=(K,D)=>{f(K,{assigneeAgentId:D,assigneeUserId:null}),S(null),_("")};return l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"flex items-center justify-between gap-2 sm:gap-3",children:[l.jsxs("div",{className:"flex min-w-0 items-center gap-2 sm:gap-3",children:[l.jsxs(ke,{size:"sm",variant:"outline",onClick:()=>p(F()),children:[l.jsx(Pr,{className:"h-4 w-4 sm:mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:"New Issue"})]}),l.jsxs("div",{className:"relative w-48 sm:w-64 md:w-80",children:[l.jsx(Gc,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),l.jsx(Jc,{value:E,onChange:K=>{j(K.target.value),d==null||d(K.target.value)},placeholder:"Search issues...",className:"pl-7 text-xs sm:text-sm","aria-label":"Search issues"})]})]}),l.jsxs("div",{className:"flex items-center gap-0.5 sm:gap-1 shrink-0",children:[l.jsxs("div",{className:"flex items-center border border-border rounded-md overflow-hidden mr-1",children:[l.jsx("button",{className:`p-1.5 transition-colors ${y.viewMode==="list"?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>I({viewMode:"list"}),title:"List view",children:l.jsx(SY,{className:"h-3.5 w-3.5"})}),l.jsx("button",{className:`p-1.5 transition-colors ${y.viewMode==="board"?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>I({viewMode:"board"}),title:"Board view",children:l.jsx(ave,{className:"h-3.5 w-3.5"})})]}),l.jsxs(Bn,{children:[l.jsx(zn,{asChild:!0,children:l.jsxs(ke,{variant:"ghost",size:"sm",className:`text-xs ${J>0?"text-blue-600 dark:text-blue-400":""}`,children:[l.jsx(Tve,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:J>0?`Filters: ${J}`:"Filter"}),J>0&&l.jsx("span",{className:"sm:hidden text-[10px] font-medium ml-0.5",children:J}),J>0&&l.jsx(ii,{className:"h-3 w-3 ml-1 hidden sm:block",onClick:K=>{K.stopPropagation(),I({statuses:[],priorities:[],assignees:[],labels:[]})}})]})}),l.jsx(Vn,{align:"end",className:"w-[min(480px,calc(100vw-2rem))] p-0",children:l.jsxs("div",{className:"p-3 space-y-3",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("span",{className:"text-sm font-medium",children:"Filters"}),J>0&&l.jsx("button",{className:"text-xs text-muted-foreground hover:text-foreground",onClick:()=>I({statuses:[],priorities:[],assignees:[],labels:[]}),children:"Clear"})]}),l.jsxs("div",{className:"space-y-1.5",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Quick filters"}),l.jsx("div",{className:"flex flex-wrap gap-1.5",children:mUe.map(K=>{const D=gUe(y.statuses,K.statuses);return l.jsx("button",{className:`px-2.5 py-1 text-xs rounded-full border transition-colors ${D?"bg-primary text-primary-foreground border-primary":"border-border text-muted-foreground hover:text-foreground hover:border-foreground/30"}`,onClick:()=>I({statuses:D?[]:[...K.statuses]}),children:K.label},K.label)})})]}),l.jsx("div",{className:"border-t border-border"}),l.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Status"}),l.jsx("div",{className:"space-y-0.5",children:Xk.map(K=>l.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[l.jsx(ch,{checked:y.statuses.includes(K),onCheckedChange:()=>I({statuses:bC(y.statuses,K)})}),l.jsx(qr,{status:K}),l.jsx("span",{className:"text-sm",children:yC(K)})]},K))})]}),l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Priority"}),l.jsx("div",{className:"space-y-0.5",children:eS.map(K=>l.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[l.jsx(ch,{checked:y.priorities.includes(K),onCheckedChange:()=>I({priorities:bC(y.priorities,K)})}),l.jsx(Ss,{priority:K}),l.jsx("span",{className:"text-sm",children:yC(K)})]},K))})]}),r&&r.length>0&&l.jsxs("div",{className:"space-y-1",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Assignee"}),l.jsx("div",{className:"space-y-0.5 max-h-32 overflow-y-auto",children:r.map(K=>l.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[l.jsx(ch,{checked:y.assignees.includes(K.id),onCheckedChange:()=>I({assignees:bC(y.assignees,K.id)})}),l.jsx("span",{className:"text-sm",children:K.name})]},K.id))})]}),W&&W.length>0&&l.jsxs("div",{className:"space-y-1",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Labels"}),l.jsx("div",{className:"space-y-0.5 max-h-32 overflow-y-auto",children:W.map(K=>l.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[l.jsx(ch,{checked:y.labels.includes(K.id),onCheckedChange:()=>I({labels:bC(y.labels,K.id)})}),l.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:K.color}}),l.jsx("span",{className:"text-sm",children:K.name})]},K.id))})]})]})]})]})})]}),y.viewMode==="list"&&l.jsxs(Bn,{children:[l.jsx(zn,{asChild:!0,children:l.jsxs(ke,{variant:"ghost",size:"sm",className:"text-xs",children:[l.jsx(Mbe,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:"Sort"})]})}),l.jsx(Vn,{align:"end",className:"w-48 p-0",children:l.jsx("div",{className:"p-2 space-y-0.5",children:[["status","Status"],["priority","Priority"],["title","Title"],["created","Created"],["updated","Updated"]].map(([K,D])=>l.jsxs("button",{className:`flex items-center justify-between w-full px-2 py-1.5 text-sm rounded-sm ${y.sortField===K?"bg-accent/50 text-foreground":"hover:bg-accent/50 text-muted-foreground"}`,onClick:()=>{y.sortField===K?I({sortDir:y.sortDir==="asc"?"desc":"asc"}):I({sortField:K,sortDir:"asc"})},children:[l.jsx("span",{children:D}),y.sortField===K&&l.jsx("span",{className:"text-xs text-muted-foreground",children:y.sortDir==="asc"?"↑":"↓"})]},K))})})]}),y.viewMode==="list"&&l.jsxs(Bn,{children:[l.jsx(zn,{asChild:!0,children:l.jsxs(ke,{variant:"ghost",size:"sm",className:"text-xs",children:[l.jsx(CY,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),l.jsx("span",{className:"hidden sm:inline",children:"Group"})]})}),l.jsx(Vn,{align:"end",className:"w-44 p-0",children:l.jsx("div",{className:"p-2 space-y-0.5",children:[["status","Status"],["priority","Priority"],["assignee","Assignee"],["none","None"]].map(([K,D])=>l.jsxs("button",{className:`flex items-center justify-between w-full px-2 py-1.5 text-sm rounded-sm ${y.groupBy===K?"bg-accent/50 text-foreground":"hover:bg-accent/50 text-muted-foreground"}`,onClick:()=>I({groupBy:K}),children:[l.jsx("span",{children:D}),y.groupBy===K&&l.jsx(fa,{className:"h-3.5 w-3.5"})]},K))})})]})]})]}),e&&l.jsx(ui,{variant:"issues-list"}),n&&l.jsx("p",{className:"text-sm text-destructive",children:n.message}),!e&&V.length===0&&y.viewMode==="list"&&l.jsx(Os,{icon:Qi,message:"No issues match the current filters or search.",action:"Create Issue",onAction:()=>p(F())}),y.viewMode==="board"?l.jsx(hUe,{issues:V,agents:r,liveIssueIds:s,onUpdateIssue:f}):G.map(K=>l.jsxs(Mg,{open:!y.collapsedGroups.includes(K.key),onOpenChange:D=>{I({collapsedGroups:D?y.collapsedGroups.filter(B=>B!==K.key):[...y.collapsedGroups,K.key]})},children:[K.label&&l.jsxs("div",{className:"flex items-center py-1.5 pl-1 pr-3",children:[l.jsxs(Rg,{className:"flex items-center gap-1.5",children:[l.jsx(xa,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform [[data-state=open]>&]:rotate-90"}),l.jsx("span",{className:"text-sm font-semibold uppercase tracking-wide",children:K.label})]}),l.jsx(ke,{variant:"ghost",size:"icon-xs",className:"ml-auto text-muted-foreground",onClick:()=>p(F(K.key)),children:l.jsx(Pr,{className:"h-3 w-3"})})]}),l.jsx(Og,{children:K.items.map(D=>l.jsxs(Bt,{to:`/issues/${D.identifier??D.id}`,className:"flex items-start gap-2 py-2.5 pl-2 pr-3 text-sm border-b border-border last:border-b-0 cursor-pointer hover:bg-accent/50 transition-colors no-underline text-inherit sm:items-center sm:py-2 sm:pl-1",children:[l.jsx("span",{className:"shrink-0 pt-px sm:hidden",onClick:B=>{B.preventDefault(),B.stopPropagation()},children:l.jsx(qr,{status:D.status,onChange:B=>f(D.id,{status:B})})}),l.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-1 sm:contents",children:[l.jsx("span",{className:"line-clamp-2 text-sm sm:order-2 sm:flex-1 sm:min-w-0 sm:line-clamp-none sm:truncate",children:D.title}),l.jsxs("span",{className:"flex items-center gap-2 sm:order-1 sm:shrink-0",children:[l.jsx("span",{className:"w-3.5 shrink-0 hidden sm:block"}),l.jsx("span",{className:"hidden sm:inline-flex",children:l.jsx(Ss,{priority:D.priority})}),l.jsx("span",{className:"hidden shrink-0 sm:inline-flex",onClick:B=>{B.preventDefault(),B.stopPropagation()},children:l.jsx(qr,{status:D.status,onChange:B=>f(D.id,{status:B})})}),l.jsx("span",{className:"text-xs text-muted-foreground font-mono shrink-0",children:D.identifier??D.id.slice(0,8)}),(s==null?void 0:s.has(D.id))&&l.jsxs("span",{className:"inline-flex items-center gap-1 sm:gap-1.5 px-1.5 sm:px-2 py-0.5 rounded-full bg-blue-500/10",children:[l.jsxs("span",{className:"relative flex h-2 w-2",children:[l.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),l.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-blue-500"})]}),l.jsx("span",{className:"text-[11px] font-medium text-blue-600 dark:text-blue-400 hidden sm:inline",children:"Live"})]}),l.jsx("span",{className:"text-xs text-muted-foreground sm:hidden",children:"·"}),l.jsx("span",{className:"text-xs text-muted-foreground sm:hidden",children:Bl(D.updatedAt)})]})]}),l.jsxs("span",{className:"hidden sm:flex sm:order-3 items-center gap-2 sm:gap-3 shrink-0 ml-auto",children:[(D.labels??[]).length>0&&l.jsxs("span",{className:"hidden md:flex items-center gap-1 max-w-[240px] overflow-hidden",children:[(D.labels??[]).slice(0,3).map(B=>l.jsx("span",{className:"inline-flex items-center rounded-full border px-1.5 py-0.5 text-[10px] font-medium",style:{borderColor:B.color,color:B.color,backgroundColor:`${B.color}1f`},children:B.name},B.id)),(D.labels??[]).length>3&&l.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",(D.labels??[]).length-3]})]}),l.jsxs(Bn,{open:k===D.id,onOpenChange:B=>{S(B?D.id:null),B||_("")},children:[l.jsx(zn,{asChild:!0,children:l.jsx("button",{className:"flex w-[180px] shrink-0 items-center rounded-md px-2 py-1 hover:bg-accent/50 transition-colors",onClick:B=>{B.preventDefault(),B.stopPropagation()},children:D.assigneeAgentId&&z(D.assigneeAgentId)?l.jsx(Sn,{name:z(D.assigneeAgentId),size:"sm"}):l.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[l.jsx("span",{className:"inline-flex h-5 w-5 items-center justify-center rounded-full border border-dashed border-muted-foreground/35 bg-muted/30",children:l.jsx(zp,{className:"h-3 w-3"})}),"Assignee"]})})}),l.jsxs(Vn,{className:"w-56 p-1",align:"end",onClick:B=>B.stopPropagation(),onPointerDownOutside:()=>_(""),children:[l.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 agents...",value:C,onChange:B=>_(B.target.value),autoFocus:!0}),l.jsxs("div",{className:"max-h-48 overflow-y-auto overscroll-contain",children:[l.jsx("button",{className:re("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",!D.assigneeAgentId&&"bg-accent"),onClick:B=>{B.preventDefault(),B.stopPropagation(),L(D.id,null)},children:"No assignee"}),(r??[]).filter(B=>C.trim()?B.name.toLowerCase().includes(C.toLowerCase()):!0).map(B=>l.jsx("button",{className:re("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-left",D.assigneeAgentId===B.id&&"bg-accent"),onClick:q=>{q.preventDefault(),q.stopPropagation(),L(D.id,B.id)},children:l.jsx(Sn,{name:B.name,size:"sm",className:"min-w-0"})},B.id))]})]})]}),l.jsx("span",{className:"text-xs text-muted-foreground",children:ki(D.createdAt)})]})]},D.id))})]},K.key))]})}function x6({...t}){return l.jsx(mS,{"data-slot":"sheet",...t})}function vUe({...t}){return l.jsx(_K,{"data-slot":"sheet-trigger",...t})}function wUe({...t}){return l.jsx(pS,{"data-slot":"sheet-portal",...t})}function CUe({className:t,...e}){return l.jsx(gS,{"data-slot":"sheet-overlay",className:re("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",t),...e})}function y6({className:t,children:e,side:n="right",showCloseButton:r=!0,...s}){return l.jsxs(wUe,{children:[l.jsx(CUe,{}),l.jsxs(xS,{"data-slot":"sheet-content",className:re("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",t),...s,children:[e,r&&l.jsxs(nv,{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:[l.jsx(ii,{className:"size-4"}),l.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function b6({className:t,...e}){return l.jsx("div",{"data-slot":"sheet-header",className:re("flex flex-col gap-1.5 p-4",t),...e})}function kUe({className:t,...e}){return l.jsx("div",{"data-slot":"sheet-footer",className:re("mt-auto flex flex-col gap-2 p-4",t),...e})}function v6({className:t,...e}){return l.jsx(QM,{"data-slot":"sheet-title",className:re("text-foreground font-semibold",t),...e})}function SUe({className:t,...e}){return l.jsx(NK,{"data-slot":"sheet-description",className:re("text-muted-foreground text-sm",t),...e})}function _Ue(t,e){const n=t.split("/").filter(Boolean),r=n.indexOf("projects");if(r===-1||n[r+1]!==e)return null;const s=n[r+2];return s==="overview"?"overview":s==="issues"?"list":null}function NUe({project:t,onUpdate:e,imageUploadHandler:n}){return l.jsxs("div",{className:"space-y-6",children:[l.jsx(du,{value:t.description??"",onSave:r=>e({description:r}),as:"p",className:"text-sm text-muted-foreground",placeholder:"Add a description...",multiline:!0,imageUploadHandler:n}),l.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 text-sm",children:[l.jsxs("div",{children:[l.jsx("span",{className:"text-muted-foreground",children:"Status"}),l.jsx("div",{className:"mt-1",children:l.jsx(Fn,{status:t.status})})]}),t.targetDate&&l.jsxs("div",{children:[l.jsx("span",{className:"text-muted-foreground",children:"Target Date"}),l.jsx("p",{children:t.targetDate})]})]})]})}function EUe({currentColor:t,onSelect:e}){const[n,r]=v.useState(!1),s=v.useRef(null);return v.useEffect(()=>{if(!n)return;function i(o){s.current&&!s.current.contains(o.target)&&r(!1)}return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[n]),l.jsxs("div",{className:"relative",ref:s,children:[l.jsx("button",{onClick:()=>r(!n),className:"shrink-0 h-5 w-5 rounded-md cursor-pointer hover:ring-2 hover:ring-foreground/20 transition-[box-shadow]",style:{backgroundColor:t},"aria-label":"Change project color"}),n&&l.jsx("div",{className:"absolute top-full left-0 mt-2 p-2 bg-popover border border-border rounded-lg shadow-lg z-50 w-max",children:l.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:RT.map(i=>l.jsx("button",{onClick:()=>{e(i),r(!1)},className:`h-6 w-6 rounded-md cursor-pointer transition-[transform,box-shadow] duration-150 hover:scale-110 ${i===t?"ring-2 ring-foreground ring-offset-1 ring-offset-background":"hover:ring-2 hover:ring-foreground/30"}`,style:{backgroundColor:i},"aria-label":`Select color ${i}`},i))})})]})}function jUe({projectId:t,companyId:e}){const n=Nn(),{data:r}=Be({queryKey:te.agents.list(e),queryFn:()=>Ot.list(e),enabled:!!e}),{data:s}=Be({queryKey:te.liveRuns(e),queryFn:()=>Kr.liveRunsForCompany(e),enabled:!!e,refetchInterval:5e3}),i=v.useMemo(()=>{const f=new Set;for(const m of s??[])m.issueId&&f.add(m.issueId);return f},[s]),{data:o,isLoading:a,error:c}=Be({queryKey:te.issues.listByProject(e,t),queryFn:()=>Dn.list(e,{projectId:t}),enabled:!!e}),d=yt({mutationFn:({id:f,data:m})=>Dn.update(f,m),onSuccess:()=>{n.invalidateQueries({queryKey:te.issues.listByProject(e,t)}),n.invalidateQueries({queryKey:te.issues.list(e)})}});return l.jsx(Foe,{issues:o??[],isLoading:a,error:c,agents:r,liveIssueIds:i,projectId:t,viewStateKey:`paperclip:project-view:${t}`,onUpdateIssue:(f,m)=>d.mutate({id:f,data:m})})}function vC(){const{companyPrefix:t,projectId:e,filter:n}=Eu(),{companies:r,selectedCompanyId:s,setSelectedCompanyId:i}=en(),{openPanel:o,closePanel:a,panelVisible:c,setPanelVisible:d}=hx(),{setBreadcrumbs:f}=bs(),[m,p]=v.useState(!1),x=Nn(),y=Ti(),w=Fr(),k=e??"",C=v.useMemo(()=>{var G;if(!t)return null;const J=t.toUpperCase();return((G=r.find(F=>F.issuePrefix.toUpperCase()===J))==null?void 0:G.id)??null},[r,t])??s??void 0,_=k.length>0&&(HR(k)||!!C),E=k?_Ue(w.pathname,k):null,{data:j,isLoading:R,error:T}=Be({queryKey:[...te.projects.detail(k),C??null],queryFn:()=>oi.get(k,C),enabled:_}),M=j?UR(j):k,O=(j==null?void 0:j.id)??k,I=(j==null?void 0:j.companyId)??s;v.useEffect(()=>{!(j!=null&&j.companyId)||j.companyId===s||i(j.companyId,{source:"route_sync"})},[j==null?void 0:j.companyId,s,i]);const z=yt({mutationFn:J=>oi.update(O,J,I??C),onSuccess:()=>{x.invalidateQueries({queryKey:te.projects.detail(k)}),x.invalidateQueries({queryKey:te.projects.detail(O)}),I&&x.invalidateQueries({queryKey:te.projects.list(I)})}}),V=yt({mutationFn:async J=>{if(!I)throw new Error("No company selected");return mx.uploadImage(I,J,`projects/${O||"draft"}`)}});if(v.useEffect(()=>{f([{label:"Projects",href:"/projects"},{label:(j==null?void 0:j.name)??k??"Project"}])},[f,j,k]),v.useEffect(()=>{if(j&&k!==M){if(E==="overview"){y(`/projects/${M}/overview`,{replace:!0});return}if(E==="list"){if(n){y(`/projects/${M}/issues/${n}`,{replace:!0});return}y(`/projects/${M}/issues`,{replace:!0});return}y(`/projects/${M}`,{replace:!0})}},[j,k,M,E,n,y]),v.useEffect(()=>(j&&o(l.jsx(jU,{project:j,onUpdate:J=>z.mutate(J)})),()=>a()),[j]),k&&E===null)return l.jsx(vo,{to:`/projects/${M}/issues`,replace:!0});if(R)return l.jsx(ui,{variant:"detail"});if(T)return l.jsx("p",{className:"text-sm text-destructive",children:T.message});if(!j)return null;const W=J=>{y(J==="overview"?`/projects/${M}/overview`:`/projects/${M}/issues`)};return l.jsxs("div",{className:"space-y-6",children:[l.jsxs("div",{className:"flex items-start gap-3",children:[l.jsx("div",{className:"h-7 flex items-center",children:l.jsx(EUe,{currentColor:j.color??"#6366f1",onSelect:J=>z.mutate({color:J})})}),l.jsx(du,{value:j.name,onSave:J=>z.mutate({name:J}),as:"h2",className:"text-xl font-bold"}),l.jsx(ke,{variant:"ghost",size:"icon-xs",className:"ml-auto md:hidden shrink-0",onClick:()=>p(!0),title:"Properties",children:l.jsx(Ky,{className:"h-4 w-4"})}),l.jsx(ke,{variant:"ghost",size:"icon-xs",className:re("shrink-0 ml-auto transition-opacity duration-200 hidden md:flex",c?"opacity-0 pointer-events-none w-0 overflow-hidden":"opacity-100"),onClick:()=>d(!0),title:"Show properties",children:l.jsx(Ky,{className:"h-4 w-4"})})]}),l.jsxs("div",{className:"flex items-center gap-1 border-b border-border",children:[l.jsx("button",{className:`px-3 py-2 text-sm font-medium transition-colors border-b-2 ${E==="overview"?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,onClick:()=>W("overview"),children:"Overview"}),l.jsx("button",{className:`px-3 py-2 text-sm font-medium transition-colors border-b-2 ${E==="list"?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,onClick:()=>W("list"),children:"List"})]}),E==="overview"&&l.jsx(NUe,{project:j,onUpdate:J=>z.mutate(J),imageUploadHandler:async J=>(await V.mutateAsync(J)).contentPath}),E==="list"&&(j==null?void 0:j.id)&&I&&l.jsx(jUe,{projectId:j.id,companyId:I}),l.jsx(x6,{open:m,onOpenChange:p,children:l.jsxs(y6,{side:"bottom",className:"max-h-[85dvh] pb-[env(safe-area-inset-bottom)]",children:[l.jsx(b6,{children:l.jsx(v6,{className:"text-sm",children:"Properties"})}),l.jsx(t_,{className:"flex-1 overflow-y-auto",children:l.jsx("div",{className:"px-4 pb-4",children:l.jsx(jU,{project:j,onUpdate:J=>z.mutate(J)})})})]})})]})}function AUe(){const{selectedCompanyId:t}=en(),{setBreadcrumbs:e}=bs(),[n]=Qb(),r=Nn(),s=n.get("q")??"",i=v.useRef(void 0),o=v.useCallback(y=>{clearTimeout(i.current),i.current=setTimeout(()=>{const w=y.trim();if((new URLSearchParams(window.location.search).get("q")??"")===w)return;const S=new URL(window.location.href);w?S.searchParams.set("q",w):S.searchParams.delete("q");const C=`${S.pathname}${S.search}${S.hash}`;window.history.replaceState(window.history.state,"",C)},300)},[]);v.useEffect(()=>()=>clearTimeout(i.current),[]);const{data:a}=Be({queryKey:te.agents.list(t),queryFn:()=>Ot.list(t),enabled:!!t}),{data:c}=Be({queryKey:te.liveRuns(t),queryFn:()=>Kr.liveRunsForCompany(t),enabled:!!t,refetchInterval:5e3}),d=v.useMemo(()=>{const y=new Set;for(const w of c??[])w.issueId&&y.add(w.issueId);return y},[c]);v.useEffect(()=>{e([{label:"Issues"}])},[e]);const{data:f,isLoading:m,error:p}=Be({queryKey:te.issues.list(t),queryFn:()=>Dn.list(t),enabled:!!t}),x=yt({mutationFn:({id:y,data:w})=>Dn.update(y,w),onSuccess:()=>{r.invalidateQueries({queryKey:te.issues.list(t)})}});return t?l.jsx(Foe,{issues:f??[],isLoading:m,error:p,agents:a,liveIssueIds:d,viewStateKey:"paperclip:issues-view",initialAssignees:n.get("assignee")?[n.get("assignee")]:void 0,initialSearch:s,onSearchChange:o,onUpdateIssue:(y,w)=>x.mutate({id:y,data:w})}):l.jsx(Os,{icon:Qi,message:"Select a company to view issues."})}const TUe=new Set(["done","cancelled"]),MUe=800;function RUe(t){try{return localStorage.getItem(t)??""}catch{return""}}function OUe(t,e){try{e.trim()?localStorage.setItem(t,e):localStorage.removeItem(t)}catch{}}function IUe(t){try{localStorage.removeItem(t)}catch{}}function DUe(t){if(!t||t==="__none__")return{assigneeAgentId:null,assigneeUserId:null};if(t.startsWith("agent:")){const e=t.slice(6);return e?{assigneeAgentId:e,assigneeUserId:null}:null}if(t.startsWith("user:")){const e=t.slice(5);return e?{assigneeAgentId:null,assigneeUserId:e}:null}return null}function LUe({text:t}){const[e,n]=v.useState(!1);return l.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground transition-colors",title:"Copy as markdown",onClick:()=>{navigator.clipboard.writeText(t).then(()=>{n(!0),setTimeout(()=>n(!1),2e3)})},children:e?l.jsx(fa,{className:"h-3 w-3"}):l.jsx(YR,{className:"h-3 w-3"})})}const PUe=v.memo(function({timeline:e,agentMap:n,highlightCommentId:r}){return e.length===0?l.jsx("p",{className:"text-sm text-muted-foreground",children:"No comments or runs yet."}):l.jsx("div",{className:"space-y-3",children:e.map(s=>{var a,c;if(s.kind==="run"){const d=s.run;return l.jsxs("div",{className:"border border-border bg-accent/20 p-3 overflow-hidden min-w-0 rounded-sm",children:[l.jsxs("div",{className:"flex items-center justify-between mb-2",children:[l.jsx(za,{to:`/agents/${d.agentId}`,className:"hover:underline",children:l.jsx(Sn,{name:((a=n==null?void 0:n.get(d.agentId))==null?void 0:a.name)??d.agentId.slice(0,8),size:"sm"})}),l.jsx("span",{className:"text-xs text-muted-foreground",children:VT(d.startedAt??d.createdAt)})]}),l.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[l.jsx("span",{className:"text-muted-foreground",children:"Run"}),l.jsx(za,{to:`/agents/${d.agentId}/runs/${d.runId}`,className:"inline-flex items-center rounded-md border border-border bg-accent/40 px-2 py-1 font-mono text-muted-foreground hover:text-foreground hover:bg-accent/60 transition-colors",children:d.runId.slice(0,8)}),l.jsx(Fn,{status:d.status})]})]},`run:${d.runId}`)}const i=s.comment,o=r===i.id;return l.jsxs("div",{id:`comment-${i.id}`,className:`border p-3 overflow-hidden min-w-0 rounded-sm transition-colors duration-1000 ${o?"border-primary/50 bg-primary/5":"border-border"}`,children:[l.jsxs("div",{className:"flex items-center justify-between mb-1",children:[i.authorAgentId?l.jsx(za,{to:`/agents/${i.authorAgentId}`,className:"hover:underline",children:l.jsx(Sn,{name:((c=n==null?void 0:n.get(i.authorAgentId))==null?void 0:c.name)??i.authorAgentId.slice(0,8),size:"sm"})}):l.jsx(Sn,{name:"You",size:"sm"}),l.jsxs("span",{className:"flex items-center gap-1.5",children:[l.jsx("a",{href:`#comment-${i.id}`,className:"text-xs text-muted-foreground hover:text-foreground hover:underline transition-colors",children:VT(i.createdAt)}),l.jsx(LUe,{text:i.body})]})]}),l.jsx(i5,{className:"text-sm",children:i.body}),i.runId&&l.jsx("div",{className:"mt-2 pt-2 border-t border-border/60",children:i.runAgentId?l.jsxs(za,{to:`/agents/${i.runAgentId}/runs/${i.runId}`,className:"inline-flex items-center rounded-md border border-border bg-accent/30 px-2 py-1 text-[10px] font-mono text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors",children:["run ",i.runId.slice(0,8)]}):l.jsxs("span",{className:"inline-flex items-center rounded-md border border-border bg-accent/30 px-2 py-1 text-[10px] font-mono text-muted-foreground",children:["run ",i.runId.slice(0,8)]})})]},i.id)})})});function FUe({comments:t,linkedRuns:e=[],onAdd:n,issueStatus:r,agentMap:s,imageUploadHandler:i,onAttachImage:o,draftKey:a,liveRunSlot:c,enableReassign:d=!1,reassignOptions:f=[],currentAssigneeValue:m="",mentions:p}){const[x,y]=v.useState(""),[w,k]=v.useState(!0),[S,C]=v.useState(!1),[_,E]=v.useState(!1),[j,R]=v.useState(m),[T,M]=v.useState(null),O=v.useRef(null),I=v.useRef(null),$=v.useRef(null),z=Fr(),V=v.useRef(!1),W=r?TUe.has(r):!1,J=v.useMemo(()=>{const D=t.map(q=>({kind:"comment",id:q.id,createdAtMs:new Date(q.createdAt).getTime(),comment:q})),B=e.map(q=>({kind:"run",id:q.runId,createdAtMs:new Date(q.startedAt??q.createdAt).getTime(),run:q}));return[...D,...B].sort((q,H)=>q.createdAtMs!==H.createdAtMs?q.createdAtMs-H.createdAtMs:q.kind===H.kind?q.id.localeCompare(H.id):q.kind==="comment"?-1:1)},[t,e]),G=v.useMemo(()=>p||(s?Array.from(s.values()).filter(D=>D.status!=="terminated").map(D=>({id:D.id,name:D.name})):[]),[s,p]);v.useEffect(()=>{a&&y(RUe(a))},[a]),v.useEffect(()=>{a&&($.current&&clearTimeout($.current),$.current=setTimeout(()=>{OUe(a,x)},MUe))},[x,a]),v.useEffect(()=>()=>{$.current&&clearTimeout($.current)},[]),v.useEffect(()=>{R(m)},[m]),v.useEffect(()=>{const D=z.hash;if(!D.startsWith("#comment-")||t.length===0)return;const B=D.slice(9);if(V.current)return;const q=document.getElementById(`comment-${B}`);if(q){V.current=!0,M(B),q.scrollIntoView({behavior:"smooth",block:"center"});const H=setTimeout(()=>M(null),3e3);return()=>clearTimeout(H)}},[z.hash,t]);async function F(){const D=x.trim();if(!D)return;const q=d&&j!==m?DUe(j):null;C(!0);try{await n(D,W&&w?!0:void 0,q??void 0),y(""),a&&IUe(a),k(!1),R(m)}finally{C(!1)}}async function L(D){var q;const B=(q=D.target.files)==null?void 0:q[0];if(!(!B||!o)){E(!0);try{await o(B)}finally{E(!1),I.current&&(I.current.value="")}}}const K=!S&&!!x.trim();return l.jsxs("div",{className:"space-y-4",children:[l.jsxs("h3",{className:"text-sm font-semibold",children:["Comments & Runs (",J.length,")"]}),l.jsx(PUe,{timeline:J,agentMap:s,highlightCommentId:T}),c,l.jsxs("div",{className:"space-y-2",children:[l.jsx(su,{ref:O,value:x,onChange:y,placeholder:"Leave a comment...",mentions:G,onSubmit:F,imageUploadHandler:i,contentClassName:"min-h-[60px] text-sm"}),l.jsxs("div",{className:"flex items-center justify-end gap-3",children:[o&&l.jsxs("div",{className:"mr-auto flex items-center gap-3",children:[l.jsx("input",{ref:I,type:"file",accept:"image/png,image/jpeg,image/webp,image/gif",className:"hidden",onChange:L}),l.jsx(ke,{variant:"ghost",size:"icon-sm",onClick:()=>{var D;return(D=I.current)==null?void 0:D.click()},disabled:_,title:"Attach image",children:l.jsx(KS,{className:"h-4 w-4"})})]}),W&&l.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-muted-foreground cursor-pointer select-none",children:[l.jsx("input",{type:"checkbox",checked:w,onChange:D=>k(D.target.checked),className:"rounded border-border"}),"Re-open"]}),d&&f.length>0&&l.jsx(XC,{value:j,options:f,placeholder:"Assignee",noneLabel:"No assignee",searchPlaceholder:"Search assignees...",emptyMessage:"No assignees found.",onChange:R,className:"text-xs h-8",renderTriggerValue:D=>{if(!D)return l.jsx("span",{className:"text-muted-foreground",children:"Assignee"});const B=D.id.startsWith("agent:")?D.id.slice(6):null,q=B?s==null?void 0:s.get(B):null;return l.jsxs(l.Fragment,{children:[q?l.jsx(Ql,{icon:q.icon,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):null,l.jsx("span",{className:"truncate",children:D.label})]})},renderOption:D=>{if(!D.id)return l.jsx("span",{className:"truncate",children:D.label});const B=D.id.startsWith("agent:")?D.id.slice(6):null,q=B?s==null?void 0:s.get(B):null;return l.jsxs(l.Fragment,{children:[q?l.jsx(Ql,{icon:q.icon,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):null,l.jsx("span",{className:"truncate",children:D.label})]})}}),l.jsx(ke,{size:"sm",disabled:!K,onClick:F,children:S?"Posting...":"Comment"})]})]})]})}function Sl({label:t,children:e}){return l.jsxs("div",{className:"flex items-center gap-3 py-1.5",children:[l.jsx("span",{className:"text-xs text-muted-foreground shrink-0 w-20",children:t}),l.jsx("div",{className:"flex items-center gap-1.5 min-w-0 flex-1",children:e})]})}function zA({inline:t,label:e,open:n,onOpenChange:r,triggerContent:s,triggerClassName:i,popoverClassName:o,popoverAlign:a="end",extra:c,children:d}){const f=re("inline-flex items-center gap-1.5 cursor-pointer hover:bg-accent/50 rounded px-1 -mx-1 py-0.5 transition-colors",i);return t?l.jsxs("div",{children:[l.jsxs(Sl,{label:e,children:[l.jsx("button",{className:f,onClick:()=>r(!n),children:s}),c]}),n&&l.jsx("div",{className:re("rounded-md border border-border bg-popover p-1 mb-2",o),children:d})]}):l.jsxs(Sl,{label:e,children:[l.jsxs(Bn,{open:n,onOpenChange:r,children:[l.jsx(zn,{asChild:!0,children:l.jsx("button",{className:f,children:s})}),l.jsx(Vn,{className:re("p-1",o),align:a,collisionPadding:16,children:d})]}),c]})}function TU({issue:t,onUpdate:e,inline:n}){var ue,ge,$e,He,lt,rt,Me;const{selectedCompanyId:r}=en(),s=Nn(),i=t.companyId??r,[o,a]=v.useState(!1),[c,d]=v.useState(""),[f,m]=v.useState(!1),[p,x]=v.useState(""),[y,w]=v.useState(!1),[k,S]=v.useState(""),[C,_]=v.useState(""),[E,j]=v.useState("#6366f1"),{data:R}=Be({queryKey:te.auth.session,queryFn:()=>Ua.getSession()}),T=((ue=R==null?void 0:R.user)==null?void 0:ue.id)??((ge=R==null?void 0:R.session)==null?void 0:ge.userId),{data:M}=Be({queryKey:te.agents.list(i),queryFn:()=>Ot.list(i),enabled:!!i}),{data:O}=Be({queryKey:te.projects.list(i),queryFn:()=>oi.list(i),enabled:!!i}),{orderedProjects:I}=e_({projects:O??[],companyId:i,userId:T}),{data:$}=Be({queryKey:te.issues.labels(i),queryFn:()=>Dn.listLabels(i),enabled:!!i}),z=yt({mutationFn:ye=>Dn.createLabel(i,ye),onSuccess:async ye=>{await s.invalidateQueries({queryKey:te.issues.labels(i)}),e({labelIds:[...t.labelIds??[],ye.id]}),_("")}}),V=yt({mutationFn:ye=>Dn.deleteLabel(ye),onSuccess:()=>{s.invalidateQueries({queryKey:te.issues.labels(i)}),s.invalidateQueries({queryKey:te.issues.list(i)}),s.invalidateQueries({queryKey:te.issues.detail(t.id)})}}),W=ye=>{const et=t.labelIds??[],At=et.includes(ye)?et.filter(Wt=>Wt!==ye):[...et,ye];e({labelIds:At})},J=ye=>{if(!ye)return(ye==null?void 0:ye.slice(0,8))??"None";const et=I.find(At=>At.id===ye);return(et==null?void 0:et.name)??ye.slice(0,8)},G=ye=>{if(!ye)return null;const et=(O==null?void 0:O.find(At=>At.id===ye))??null;return et?US(et):`/projects/${ye}`},F=v.useMemo(()=>SO(),[o]),L=v.useMemo(()=>MZ((M??[]).filter(ye=>ye.status!=="terminated"),F),[M,F]),K=t.assigneeAgentId?M==null?void 0:M.find(ye=>ye.id===t.assigneeAgentId):null,D=ye=>ye?ye==="local-board"?"Board":T&&ye===T?"Me":ye.slice(0,5):null,B=D(t.assigneeUserId),q=D(t.createdByUserId),H=(t.labels??[]).length>0?l.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[(t.labels??[]).slice(0,3).map(ye=>l.jsx("span",{className:"inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium border",style:{borderColor:ye.color,backgroundColor:`${ye.color}22`,color:ye.color},children:ye.name},ye.id)),(t.labels??[]).length>3&&l.jsxs("span",{className:"text-xs text-muted-foreground",children:["+",(t.labels??[]).length-3]})]}):l.jsxs(l.Fragment,{children:[l.jsx(TY,{className:"h-3.5 w-3.5 text-muted-foreground"}),l.jsx("span",{className:"text-sm text-muted-foreground",children:"No labels"})]}),ie=l.jsxs(l.Fragment,{children:[l.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:k,onChange:ye=>S(ye.target.value),autoFocus:!n}),l.jsx("div",{className:"max-h-44 overflow-y-auto overscroll-contain space-y-0.5",children:($??[]).filter(ye=>k.trim()?ye.name.toLowerCase().includes(k.toLowerCase()):!0).map(ye=>{const et=(t.labelIds??[]).includes(ye.id);return l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsxs("button",{className:re("flex items-center gap-2 flex-1 px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-left",et&&"bg-accent"),onClick:()=>W(ye.id),children:[l.jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{backgroundColor:ye.color}}),l.jsx("span",{className:"truncate",children:ye.name})]}),l.jsx("button",{type:"button",className:"p-1 text-muted-foreground hover:text-destructive rounded",onClick:()=>V.mutate(ye.id),title:`Delete ${ye.name}`,children:l.jsx(lu,{className:"h-3 w-3"})})]},ye.id)})}),l.jsxs("div",{className:"mt-2 border-t border-border pt-2 space-y-1",children:[l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx("input",{className:"h-7 w-7 p-0 rounded bg-transparent",type:"color",value:E,onChange:ye=>j(ye.target.value)}),l.jsx("input",{className:"flex-1 px-2 py-1.5 text-xs bg-transparent outline-none rounded placeholder:text-muted-foreground/50",placeholder:"New label",value:C,onChange:ye=>_(ye.target.value)})]}),l.jsxs("button",{className:"flex items-center justify-center gap-1.5 w-full px-2 py-1.5 text-xs rounded border border-border hover:bg-accent/50 disabled:opacity-50",disabled:!C.trim()||z.isPending,onClick:()=>z.mutate({name:C.trim(),color:E}),children:[l.jsx(Pr,{className:"h-3 w-3"}),z.isPending?"Creating…":"Create label"]})]})]}),ce=K?l.jsx(Sn,{name:K.name,size:"sm"}):B?l.jsxs(l.Fragment,{children:[l.jsx(zp,{className:"h-3.5 w-3.5 text-muted-foreground"}),l.jsx("span",{className:"text-sm",children:B})]}):l.jsxs(l.Fragment,{children:[l.jsx(zp,{className:"h-3.5 w-3.5 text-muted-foreground"}),l.jsx("span",{className:"text-sm text-muted-foreground",children:"Unassigned"})]}),ee=l.jsxs(l.Fragment,{children:[l.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:c,onChange:ye=>d(ye.target.value),autoFocus:!n}),l.jsxs("div",{className:"max-h-48 overflow-y-auto overscroll-contain",children:[l.jsx("button",{className:re("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",!t.assigneeAgentId&&!t.assigneeUserId&&"bg-accent"),onClick:()=>{e({assigneeAgentId:null,assigneeUserId:null}),a(!1)},children:"No assignee"}),t.createdByUserId&&l.jsxs("button",{className:re("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",t.assigneeUserId===t.createdByUserId&&"bg-accent"),onClick:()=>{e({assigneeAgentId:null,assigneeUserId:t.createdByUserId}),a(!1)},children:[l.jsx(zp,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),q?`Assign to ${q==="Me"?"me":q}`:"Assign to requester"]}),L.filter(ye=>{if(!c.trim())return!0;const et=c.toLowerCase();return ye.name.toLowerCase().includes(et)}).map(ye=>l.jsxs("button",{className:re("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",ye.id===t.assigneeAgentId&&"bg-accent"),onClick:()=>{TZ(ye.id),e({assigneeAgentId:ye.id,assigneeUserId:null}),a(!1)},children:[l.jsx(Ql,{icon:ye.icon,className:"shrink-0 h-3 w-3 text-muted-foreground"}),ye.name]},ye.id))]})]}),Q=t.projectId?l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"shrink-0 h-3 w-3 rounded-sm",style:{backgroundColor:(($e=I.find(ye=>ye.id===t.projectId))==null?void 0:$e.color)??"#6366f1"}}),l.jsx("span",{className:"text-sm truncate",children:J(t.projectId)})]}):l.jsxs(l.Fragment,{children:[l.jsx(Jl,{className:"h-3.5 w-3.5 text-muted-foreground"}),l.jsx("span",{className:"text-sm text-muted-foreground",children:"No project"})]}),ae=l.jsxs(l.Fragment,{children:[l.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:p,onChange:ye=>x(ye.target.value),autoFocus:!n}),l.jsxs("div",{className:"max-h-48 overflow-y-auto overscroll-contain",children:[l.jsx("button",{className:re("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 whitespace-nowrap",!t.projectId&&"bg-accent"),onClick:()=>{e({projectId:null}),m(!1)},children:"No project"}),I.filter(ye=>{if(!p.trim())return!0;const et=p.toLowerCase();return ye.name.toLowerCase().includes(et)}).map(ye=>l.jsxs("button",{className:re("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 whitespace-nowrap",ye.id===t.projectId&&"bg-accent"),onClick:()=>{e({projectId:ye.id}),m(!1)},children:[l.jsx("span",{className:"shrink-0 h-3 w-3 rounded-sm",style:{backgroundColor:ye.color??"#6366f1"}}),ye.name]},ye.id))]})]});return l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsx(Sl,{label:"Status",children:l.jsx(qr,{status:t.status,onChange:ye=>e({status:ye}),showLabel:!0})}),l.jsx(Sl,{label:"Priority",children:l.jsx(Ss,{priority:t.priority,onChange:ye=>e({priority:ye}),showLabel:!0})}),l.jsx(zA,{inline:n,label:"Labels",open:y,onOpenChange:ye=>{w(ye),ye||S("")},triggerContent:H,triggerClassName:"min-w-0 max-w-full",popoverClassName:"w-64",children:ie}),l.jsx(zA,{inline:n,label:"Assignee",open:o,onOpenChange:ye=>{a(ye),ye||d("")},triggerContent:ce,popoverClassName:"w-52",extra:t.assigneeAgentId?l.jsx(Bt,{to:`/agents/${t.assigneeAgentId}`,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:ye=>ye.stopPropagation(),children:l.jsx(HT,{className:"h-3 w-3"})}):void 0,children:ee}),l.jsx(zA,{inline:n,label:"Project",open:f,onOpenChange:ye=>{m(ye),ye||x("")},triggerContent:Q,triggerClassName:"min-w-0 max-w-full",popoverClassName:"w-fit min-w-[11rem]",extra:t.projectId?l.jsx(Bt,{to:G(t.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:ye=>ye.stopPropagation(),children:l.jsx(HT,{className:"h-3 w-3"})}):void 0,children:ae}),t.parentId&&l.jsx(Sl,{label:"Parent",children:l.jsx(Bt,{to:`/issues/${((lt=(He=t.ancestors)==null?void 0:He[0])==null?void 0:lt.identifier)??t.parentId}`,className:"text-sm hover:underline",children:((Me=(rt=t.ancestors)==null?void 0:rt[0])==null?void 0:Me.title)??t.parentId.slice(0,8)})}),t.requestDepth>0&&l.jsx(Sl,{label:"Depth",children:l.jsx("span",{className:"text-sm font-mono",children:t.requestDepth})})]}),l.jsx(Yi,{}),l.jsxs("div",{className:"space-y-1",children:[t.startedAt&&l.jsx(Sl,{label:"Started",children:l.jsx("span",{className:"text-sm",children:ki(t.startedAt)})}),t.completedAt&&l.jsx(Sl,{label:"Completed",children:l.jsx("span",{className:"text-sm",children:ki(t.completedAt)})}),l.jsx(Sl,{label:"Created",children:l.jsx("span",{className:"text-sm",children:ki(t.createdAt)})}),l.jsx(Sl,{label:"Updated",children:l.jsx("span",{className:"text-sm",children:Bl(t.updatedAt)})})]})]})}const $Ue=220,_M=4e3,BUe=2e3,zUe=256e3;function Yf(t){return typeof t=="string"&&t.trim().length>0?t:null}function VA(t){return t?typeof t=="string"?t:t.toISOString():null}function VUe(t){if(t.kind==="assistant"){const e=t.text.trim();return e?{text:e,tone:"assistant"}:null}if(t.kind==="thinking"){const e=t.text.trim();return e?{text:`[thinking] ${e}`,tone:"info"}:null}if(t.kind==="tool_call")return{text:`tool ${t.name}`,tone:"tool"};if(t.kind==="tool_result"){const e=t.content.trim();return{text:t.isError?`tool error: ${e}`:`tool result: ${e}`,tone:t.isError?"error":"tool"}}if(t.kind==="stderr"){const e=t.text.trim();return e?{text:e,tone:"error"}:null}if(t.kind==="system"){const e=t.text.trim();return e?{text:e,tone:"warn"}:null}if(t.kind==="stdout"){const e=t.text.trim();return e?{text:e,tone:"info"}:null}return null}function rg(t,e,n,r,s,i){if(!n.trim())return null;const o=i!=null&&i.preserveWhitespace?n:n.trim(),a=i!=null&&i.streamingKind?_M:$Ue,c=o.length>a?o.slice(-a):o;return{id:`${t.id}:${s}`,ts:e,runId:t.id,agentId:t.agentId,agentName:t.agentName,text:c,tone:r,dedupeKey:`feed:${t.id}:${e}:${r}:${c}`,streamingKind:i==null?void 0:i.streamingKind}}function MU(t,e,n,r,s){const i=`${t.id}:stdout`,a=`${r.get(i)??""}${e}`.split(/\r?\n/);r.set(i,a.pop()??"");const c=im(t.adapterType),d=[],f=p=>{if(p.kind==="assistant"&&p.delta){const y=p.text;if(!y.trim())return;const w=d[d.length-1];w&&w.streamingKind==="assistant"?w.text+=y:d.push({text:y,tone:"assistant",streamingKind:"assistant"});return}if(p.kind==="thinking"&&p.delta){const y=p.text;if(!y.trim())return;const w=d[d.length-1];w&&w.streamingKind==="thinking"?w.text+=y:d.push({text:`[thinking] ${y}`,tone:"info",streamingKind:"thinking"});return}const x=VUe(p);x&&d.push({text:x.text,tone:x.tone})},m=[];for(const p of a.slice(-8)){const x=p.trim();if(!x)continue;const y=c.parseStdoutLine(x,n);if(y.length===0){if(t.adapterType==="openclaw_gateway")continue;const w=rg(t,n,x,"info",s.current++);w&&m.push(w);continue}for(const w of y)f(w)}for(const p of d){const x=rg(t,n,p.text,p.tone,s.current++,{streamingKind:p.streamingKind,preserveWhitespace:!!p.streamingKind});x&&m.push(x)}return m}function RU(t,e,n,r,s){const i=`${t.id}:stderr`,a=`${r.get(i)??""}${e}`.split(/\r?\n/);r.set(i,a.pop()??"");const c=[];for(const d of a.slice(-8)){const f=rg(t,n,d,"error",s.current++);f&&c.push(f)}return c}function HUe(t,e,n){if(!e)return[];const r=`${t}:records`,i=`${n.get(r)??""}${e}`.split(`
857
857
  `);n.set(r,i.pop()??"");const o=[];for(const a of i){const c=a.trim();if(c)try{const d=JSON.parse(c),f=d.stream==="stderr"||d.stream==="system"?d.stream:"stdout",m=typeof d.chunk=="string"?d.chunk:"",p=typeof d.ts=="string"?d.ts:new Date().toISOString();if(!m)continue;o.push({ts:p,stream:f,chunk:m})}catch{}}return o}function UUe({issueId:t,companyId:e}){const n=Nn(),[r,s]=v.useState([]),[i,o]=v.useState(new Set),a=v.useRef(new Set),c=v.useRef(new Map),d=v.useRef(new Map),f=v.useRef(new Map),m=v.useRef(new Map),p=v.useRef(1),x=v.useRef(null),y=async T=>{o(M=>new Set(M).add(T));try{await Kr.cancel(T),n.invalidateQueries({queryKey:te.issues.liveRuns(t)}),n.invalidateQueries({queryKey:te.issues.activeRun(t)})}finally{o(M=>{const O=new Set(M);return O.delete(T),O})}},{data:w}=Be({queryKey:te.issues.liveRuns(t),queryFn:()=>Kr.liveRunsForIssue(t),enabled:!!t,refetchInterval:3e3}),{data:k}=Be({queryKey:te.issues.activeRun(t),queryFn:()=>Kr.activeRunForIssue(t),enabled:!!t,refetchInterval:3e3}),S=v.useMemo(()=>{const T=new Map;for(const M of w??[])T.set(M.id,M);return k&&T.set(k.id,{id:k.id,status:k.status,invocationSource:k.invocationSource,triggerDetail:k.triggerDetail,startedAt:VA(k.startedAt),finishedAt:VA(k.finishedAt),createdAt:VA(k.createdAt)??new Date().toISOString(),agentId:k.agentId,agentName:k.agentName,adapterType:k.adapterType,issueId:t}),[...T.values()].sort((M,O)=>new Date(O.createdAt).getTime()-new Date(M.createdAt).getTime())},[k,t,w]),C=v.useMemo(()=>new Map(S.map(T=>[T.id,T])),[S]),_=v.useMemo(()=>new Set(S.map(T=>T.id)),[S]),E=v.useMemo(()=>S.map(T=>T.id).sort((T,M)=>T.localeCompare(M)).join(","),[S]),j=T=>{T.length!==0&&s(M=>{const O=[...M];for(const I of T){if(a.current.has(I.dedupeKey))continue;a.current.add(I.dedupeKey);const $=O[O.length-1];if(I.streamingKind&&$&&$.runId===I.runId&&$.streamingKind===I.streamingKind){const z=`${$.text}${I.text}`,V=z.length>_M?z.slice(-_M):z;O[O.length-1]={...$,ts:I.ts,text:V,dedupeKey:$.dedupeKey};continue}O.push(I)}return a.current.size>6e3&&a.current.clear(),O.length===M.length?M:O.slice(-80)})};if(v.useEffect(()=>{const T=x.current;T&&T.scrollTo({top:T.scrollHeight,behavior:"smooth"})},[r.length]),v.useEffect(()=>{for(const T of S)m.current.set(T.id,{agentId:T.agentId,agentName:T.agentName})},[S]),v.useEffect(()=>{const T=new Set;for(const O of _)T.add(`${O}:stdout`),T.add(`${O}:stderr`);for(const O of c.current.keys())T.has(O)||c.current.delete(O);const M=new Set(_);for(const O of d.current.keys()){const I=O.replace(/:records$/,"");M.has(I)||d.current.delete(O)}for(const O of f.current.keys())M.has(O)||f.current.delete(O)},[_]),v.useEffect(()=>{if(S.length===0)return;let T=!1;const M=async $=>{const z=f.current.get($.id)??0;try{const V=await Kr.log($.id,z,zUe);if(T)return;const W=HUe($.id,V.content,d.current),J=[];for(const G of W){if(G.stream==="stderr"){J.push(...RU($,G.chunk,G.ts,c.current,p));continue}if(G.stream==="system"){const F=rg($,G.ts,G.chunk,"warn",p.current++);F&&J.push(F);continue}J.push(...MU($,G.chunk,G.ts,c.current,p))}if(j(J),V.nextOffset!==void 0){f.current.set($.id,V.nextOffset);return}V.content.length>0&&f.current.set($.id,z+V.content.length)}catch{}},O=async()=>{await Promise.all(S.map($=>M($)))};O();const I=window.setInterval(()=>{O()},BUe);return()=>{T=!0,window.clearInterval(I)}},[E,S]),v.useEffect(()=>{if(!e||_.size===0)return;let T=!1,M=null,O=null;const I=()=>{T||(M=window.setTimeout($,1500))},$=()=>{if(T)return;const V=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/api/companies/${encodeURIComponent(e)}/events/ws`;O=new WebSocket(V),O.onmessage=W=>{const J=typeof W.data=="string"?W.data:"";if(!J)return;let G;try{G=JSON.parse(J)}catch{return}if(G.companyId!==e)return;const F=G.payload??{},L=Yf(F.runId);if(!L||!_.has(L))return;const K=C.get(L);if(K){if(G.type==="heartbeat.run.event"){const D=typeof F.seq=="number"?F.seq:null,B=Yf(F.eventType)??"event",q=Yf(F.message)??B,H=`${L}:event:${D??`${B}:${q}:${G.createdAt}`}`;if(a.current.has(H))return;a.current.add(H),a.current.size>2e3&&a.current.clear();const ie=B==="error"?"error":B==="lifecycle"?"warn":"info",ce=rg(K,G.createdAt,q,ie,p.current++);ce&&j([ce]);return}if(G.type==="heartbeat.run.status"){const D=Yf(F.status)??"updated",B=`${L}:status:${D}:${Yf(F.finishedAt)??""}`;if(a.current.has(B))return;a.current.add(B),a.current.size>2e3&&a.current.clear();const q=D==="failed"||D==="timed_out"?"error":"warn",H=rg(K,G.createdAt,`run ${D}`,q,p.current++);H&&j([H]);return}if(G.type==="heartbeat.run.log"){const D=Yf(F.chunk);if(!D)return;if((Yf(F.stream)==="stderr"?"stderr":"stdout")==="stderr"){j(RU(K,D,G.createdAt,c.current,p));return}j(MU(K,D,G.createdAt,c.current,p))}}},O.onerror=()=>{O==null||O.close()},O.onclose=()=>{I()}};return $(),()=>{T=!0,M!==null&&window.clearTimeout(M),O&&(O.onmessage=null,O.onerror=null,O.onclose=null,O.close(1e3,"issue_live_widget_unmount"))}},[_,e,C]),S.length===0&&r.length===0)return null;const R=r.slice(-25);return l.jsxs("div",{className:"rounded-lg border border-cyan-500/30 bg-background/80 overflow-hidden shadow-[0_0_12px_rgba(6,182,212,0.08)]",children:[S.length>0?S.map(T=>l.jsxs("div",{className:"px-3 py-2 border-b border-border/50",children:[l.jsxs("div",{className:"flex items-center justify-between mb-2",children:[l.jsx(Bt,{to:`/agents/${T.agentId}`,className:"hover:underline",children:l.jsx(Sn,{name:T.agentName,size:"sm"})}),l.jsx("span",{className:"text-xs text-muted-foreground",children:VT(T.startedAt??T.createdAt)})]}),l.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[l.jsx("span",{className:"text-muted-foreground",children:"Run"}),l.jsx(Bt,{to:`/agents/${T.agentId}/runs/${T.id}`,className:"inline-flex items-center rounded-md border border-border bg-accent/40 px-2 py-1 font-mono text-muted-foreground hover:text-foreground hover:bg-accent/60 transition-colors",children:T.id.slice(0,8)}),l.jsx(Fn,{status:T.status}),l.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[l.jsxs("button",{onClick:()=>y(T.id),disabled:i.has(T.id),className:"inline-flex items-center gap-1 text-[10px] text-red-600 hover:text-red-500 dark:text-red-400 dark:hover:text-red-300 disabled:opacity-50",children:[l.jsx(H1e,{className:"h-2 w-2",fill:"currentColor"}),i.has(T.id)?"Stopping…":"Stop"]}),l.jsxs(Bt,{to:`/agents/${T.agentId}/runs/${T.id}`,className:"inline-flex items-center gap-1 text-[10px] text-cyan-600 hover:text-cyan-500 dark:text-cyan-300 dark:hover:text-cyan-200",children:["Open run",l.jsx(ZR,{className:"h-2.5 w-2.5"})]})]})]})]},T.id)):l.jsx("div",{className:"flex items-center px-3 py-2 border-b border-border/50",children:l.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Recent run updates"})}),l.jsxs("div",{ref:x,className:"max-h-[220px] overflow-y-auto p-2 font-mono text-[11px] space-y-1",children:[R.length===0&&l.jsx("div",{className:"text-xs text-muted-foreground",children:"Waiting for run output..."}),R.map((T,M)=>l.jsxs("div",{className:re("grid grid-cols-[auto_1fr] gap-2 items-start",M===R.length-1&&"animate-in fade-in slide-in-from-bottom-1 duration-300"),children:[l.jsx("span",{className:"text-[10px] text-muted-foreground",children:to(T.ts)}),l.jsxs("div",{className:re("min-w-0",T.tone==="error"&&"text-red-600 dark:text-red-300",T.tone==="warn"&&"text-amber-600 dark:text-amber-300",T.tone==="assistant"&&"text-emerald-700 dark:text-emerald-200",T.tone==="tool"&&"text-cyan-600 dark:text-cyan-300",T.tone==="info"&&"text-foreground/80"),children:[l.jsx(Sn,{name:T.agentName,size:"sm",className:"text-cyan-600 dark:text-cyan-400"}),l.jsxs("span",{className:"text-muted-foreground",children:[" [",T.runId.slice(0,8),"] "]}),l.jsx("span",{className:"break-words",children:T.text})]})]},T.id))]})]})}const qUe={"issue.created":"created the issue","issue.updated":"updated the issue","issue.checked_out":"checked out the issue","issue.released":"released the issue","issue.comment_added":"added a comment","issue.attachment_added":"added an attachment","issue.attachment_removed":"removed an attachment","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 wp(t){return typeof t!="string"?String(t??"none"):t.replace(/_/g," ")}function OU(t){return typeof t!="object"||t===null||Array.isArray(t)?null:t}function G0(t,...e){if(!t)return 0;for(const n of e){const r=t[n];if(typeof r=="number"&&Number.isFinite(r))return r}return 0}function KUe(t,e){if(t==="issue.updated"&&e){const n=e._previous??{},r=[];if(e.status!==void 0){const s=n.status;r.push(s?`changed the status from ${wp(s)} to ${wp(e.status)}`:`changed the status to ${wp(e.status)}`)}if(e.priority!==void 0){const s=n.priority;r.push(s?`changed the priority from ${wp(s)} to ${wp(e.priority)}`:`changed the priority to ${wp(e.priority)}`)}if((e.assigneeAgentId!==void 0||e.assigneeUserId!==void 0)&&r.push(e.assigneeAgentId||e.assigneeUserId?"assigned the issue":"unassigned the issue"),e.title!==void 0&&r.push("updated the title"),e.description!==void 0&&r.push("updated the description"),r.length>0)return r.join(", ")}return qUe[t]??t.replace(/[._]/g," ")}function WUe({evt:t,agentMap:e}){const n=t.actorId;if(t.actorType==="agent"){const r=e.get(n);return l.jsx(Sn,{name:(r==null?void 0:r.name)??n.slice(0,8),size:"sm"})}return t.actorType==="system"?l.jsx(Sn,{name:"System",size:"sm"}):t.actorType==="user"?l.jsx(Sn,{name:"Board",size:"sm"}):l.jsx(Sn,{name:n||"Unknown",size:"sm"})}function GUe(){var Ut,ne,he;const{issueId:t}=Eu(),{selectedCompanyId:e}=en(),{openPanel:n,closePanel:r,panelVisible:s,setPanelVisible:i}=hx(),{setBreadcrumbs:o}=bs(),a=Nn(),c=sx(),[d,f]=v.useState(!1),[m,p]=v.useState(!1),[x,y]=v.useState("comments"),[w,k]=v.useState({approvals:!1,cost:!1}),[S,C]=v.useState(null),_=v.useRef(null),E=v.useRef(null),{data:j,isLoading:R,error:T}=Be({queryKey:te.issues.detail(t),queryFn:()=>Dn.get(t),enabled:!!t}),{data:M}=Be({queryKey:te.issues.comments(t),queryFn:()=>Dn.listComments(t),enabled:!!t}),{data:O}=Be({queryKey:te.issues.activity(t),queryFn:()=>Rb.forIssue(t),enabled:!!t}),{data:I}=Be({queryKey:te.issues.runs(t),queryFn:()=>Rb.runsForIssue(t),enabled:!!t,refetchInterval:5e3}),{data:$}=Be({queryKey:te.issues.approvals(t),queryFn:()=>Dn.listApprovals(t),enabled:!!t}),{data:z}=Be({queryKey:te.issues.attachments(t),queryFn:()=>Dn.listAttachments(t),enabled:!!t}),{data:V}=Be({queryKey:te.issues.liveRuns(t),queryFn:()=>Kr.liveRunsForIssue(t),enabled:!!t,refetchInterval:3e3}),{data:W}=Be({queryKey:te.issues.activeRun(t),queryFn:()=>Kr.activeRunForIssue(t),enabled:!!t,refetchInterval:3e3}),J=(V??[]).length>0||!!W,G=v.useMemo(()=>{const X=new Set;for(const xe of V??[])X.add(xe.id);return W&&X.add(W.id),X.size===0?I??[]:(I??[]).filter(xe=>!X.has(xe.runId))},[I,V,W]),{data:F}=Be({queryKey:te.issues.list(e),queryFn:()=>Dn.list(e),enabled:!!e}),{data:L}=Be({queryKey:te.agents.list(e),queryFn:()=>Ot.list(e),enabled:!!e}),{data:K}=Be({queryKey:te.auth.session,queryFn:()=>Ua.getSession()}),{data:D}=Be({queryKey:te.projects.list(e),queryFn:()=>oi.list(e),enabled:!!e}),B=((Ut=K==null?void 0:K.user)==null?void 0:Ut.id)??((ne=K==null?void 0:K.session)==null?void 0:ne.userId)??null,{orderedProjects:q}=e_({projects:D??[],companyId:e,userId:B}),H=v.useMemo(()=>{const X=new Map;for(const xe of L??[])X.set(xe.id,xe);return X},[L]),ie=v.useMemo(()=>{const X=[],xe=[...L??[]].filter(we=>we.status!=="terminated").sort((we,oe)=>we.name.localeCompare(oe.name));for(const we of xe)X.push({id:`agent:${we.id}`,name:we.name,kind:"agent"});for(const we of q)X.push({id:`project:${we.id}`,name:we.name,kind:"project",projectId:we.id,projectColor:we.color});return X},[L,q]),ce=v.useMemo(()=>!F||!j?[]:F.filter(X=>X.parentId===j.id).sort((X,xe)=>new Date(X.createdAt).getTime()-new Date(xe.createdAt).getTime()),[F,j]),ee=v.useMemo(()=>{const X=[],xe=[...L??[]].filter(we=>we.status!=="terminated").sort((we,oe)=>we.name.localeCompare(oe.name));for(const we of xe)X.push({id:`agent:${we.id}`,label:we.name});if(B){const we=B==="local-board"?"Board":"Me (Board)";X.push({id:`user:${B}`,label:we})}return X},[L,B]),Q=v.useMemo(()=>j!=null&&j.assigneeAgentId?`agent:${j.assigneeAgentId}`:j!=null&&j.assigneeUserId?`user:${j.assigneeUserId}`:"",[j==null?void 0:j.assigneeAgentId,j==null?void 0:j.assigneeUserId]),ae=v.useMemo(()=>{const X=new Map,xe=new Map;for(const we of I??[])xe.set(we.runId,we.agentId);for(const we of O??[]){if(we.action!=="issue.comment_added"||!we.runId)continue;const oe=we.details??{},fe=typeof oe.commentId=="string"?oe.commentId:null;!fe||X.has(fe)||X.set(fe,{runId:we.runId,runAgentId:we.agentId??xe.get(we.runId)??null})}return(M??[]).map(we=>{const oe=X.get(we.id);return oe?{...we,...oe}:we})},[O,M,I]),ue=v.useMemo(()=>{let X=0,xe=0,we=0,oe=0,fe=!1,Y=!1;for(const We of I??[]){const st=OU(We.usageJson),St=OU(We.resultJson),on=G0(st,"inputTokens","input_tokens"),wn=G0(st,"outputTokens","output_tokens"),Ce=G0(st,"cachedInputTokens","cached_input_tokens","cache_read_input_tokens"),_t=G0(st,"costUsd","cost_usd","total_cost_usd")||G0(St,"total_cost_usd","cost_usd","costUsd");_t>0&&(fe=!0),on+wn+Ce>0&&(Y=!0),X+=on,xe+=wn,we+=Ce,oe+=_t}return{input:X,output:xe,cached:we,cost:oe,totalTokens:X+xe,hasCost:fe,hasTokens:Y}},[I]),ge=()=>{a.invalidateQueries({queryKey:te.issues.detail(t)}),a.invalidateQueries({queryKey:te.issues.activity(t)}),a.invalidateQueries({queryKey:te.issues.runs(t)}),a.invalidateQueries({queryKey:te.issues.approvals(t)}),a.invalidateQueries({queryKey:te.issues.attachments(t)}),a.invalidateQueries({queryKey:te.issues.liveRuns(t)}),a.invalidateQueries({queryKey:te.issues.activeRun(t)}),e&&(a.invalidateQueries({queryKey:te.issues.list(e)}),a.invalidateQueries({queryKey:te.issues.listTouchedByMe(e)}),a.invalidateQueries({queryKey:te.issues.listUnreadTouchedByMe(e)}),a.invalidateQueries({queryKey:te.sidebarBadges(e)}))},$e=yt({mutationFn:X=>Dn.markRead(X),onSuccess:()=>{e&&(a.invalidateQueries({queryKey:te.issues.listTouchedByMe(e)}),a.invalidateQueries({queryKey:te.issues.listUnreadTouchedByMe(e)}),a.invalidateQueries({queryKey:te.sidebarBadges(e)}))}}),He=yt({mutationFn:X=>Dn.update(t,X),onSuccess:()=>{ge()}}),lt=yt({mutationFn:({body:X,reopen:xe})=>Dn.addComment(t,X,xe),onSuccess:()=>{ge(),a.invalidateQueries({queryKey:te.issues.comments(t)})}}),rt=yt({mutationFn:({body:X,reopen:xe,reassignment:we})=>Dn.update(t,{comment:X,assigneeAgentId:we.assigneeAgentId,assigneeUserId:we.assigneeUserId,...xe?{status:"todo"}:{}}),onSuccess:()=>{ge(),a.invalidateQueries({queryKey:te.issues.comments(t)})}}),Me=yt({mutationFn:async X=>{if(!e)throw new Error("No company selected");return Dn.uploadAttachment(e,t,X)},onSuccess:()=>{C(null),a.invalidateQueries({queryKey:te.issues.attachments(t)}),ge()},onError:X=>{C(X instanceof Error?X.message:"Upload failed")}}),ye=yt({mutationFn:X=>Dn.deleteAttachment(X),onSuccess:()=>{C(null),a.invalidateQueries({queryKey:te.issues.attachments(t)}),ge()},onError:X=>{C(X instanceof Error?X.message:"Delete failed")}});if(v.useEffect(()=>{const X=(j==null?void 0:j.title)??t??"Issue";o([{label:"Issues",href:"/issues"},{label:J?`🔵 ${X}`:X}])},[o,j,t,J]),v.useEffect(()=>{j!=null&&j.identifier&&t!==j.identifier&&c(`/issues/${j.identifier}`,{replace:!0})},[j,t,c]),v.useEffect(()=>{j!=null&&j.id&&E.current!==j.id&&(E.current=j.id,$e.mutate(j.id))},[j==null?void 0:j.id]),v.useEffect(()=>(j&&n(l.jsx(TU,{issue:j,onUpdate:X=>He.mutate(X)})),()=>r()),[j]),R)return l.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading..."});if(T)return l.jsx("p",{className:"text-sm text-destructive",children:T.message});if(!j)return null;const et=j.ancestors??[],At=async X=>{var we;const xe=(we=X.target.files)==null?void 0:we[0];xe&&(await Me.mutateAsync(xe),_.current&&(_.current.value=""))},Wt=X=>X.contentType.startsWith("image/");return l.jsxs("div",{className:"max-w-2xl space-y-6",children:[et.length>0&&l.jsxs("nav",{className:"flex items-center gap-1 text-xs text-muted-foreground flex-wrap",children:[[...et].reverse().map((X,xe)=>l.jsxs("span",{className:"flex items-center gap-1",children:[xe>0&&l.jsx(xa,{className:"h-3 w-3 shrink-0"}),l.jsx(za,{to:`/issues/${X.identifier??X.id}`,className:"hover:text-foreground transition-colors truncate max-w-[200px]",title:X.title,children:X.title})]},X.id)),l.jsx(xa,{className:"h-3 w-3 shrink-0"}),l.jsx("span",{className:"text-foreground/60 truncate max-w-[200px]",children:j.title})]}),j.hiddenAt&&l.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:[l.jsx(R2,{className:"h-4 w-4 shrink-0"}),"This issue is hidden"]}),l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-wrap",children:[l.jsx(qr,{status:j.status,onChange:X=>He.mutate({status:X})}),l.jsx(Ss,{priority:j.priority,onChange:X=>He.mutate({priority:X})}),l.jsx("span",{className:"text-sm font-mono text-muted-foreground shrink-0",children:j.identifier??j.id.slice(0,8)}),J&&l.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:[l.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[l.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-cyan-400 opacity-75"}),l.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-cyan-400"})]}),"Live"]}),j.projectId?l.jsxs(za,{to:`/projects/${j.projectId}`,className:"inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors rounded px-1 -mx-1 py-0.5 min-w-0",children:[l.jsx(Jl,{className:"h-3 w-3 shrink-0"}),l.jsx("span",{className:"truncate",children:((he=(D??[]).find(X=>X.id===j.projectId))==null?void 0:he.name)??j.projectId.slice(0,8)})]}):l.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-muted-foreground opacity-50 px-1 -mx-1 py-0.5",children:[l.jsx(Jl,{className:"h-3 w-3 shrink-0"}),"No project"]}),(j.labels??[]).length>0&&l.jsxs("div",{className:"hidden sm:flex items-center gap-1",children:[(j.labels??[]).slice(0,4).map(X=>l.jsx("span",{className:"inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-medium",style:{borderColor:X.color,color:X.color,backgroundColor:`${X.color}1f`},children:X.name},X.id)),(j.labels??[]).length>4&&l.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",(j.labels??[]).length-4]})]}),l.jsx(ke,{variant:"ghost",size:"icon-xs",className:"ml-auto md:hidden shrink-0",onClick:()=>p(!0),title:"Properties",children:l.jsx(Ky,{className:"h-4 w-4"})}),l.jsxs("div",{className:"hidden md:flex items-center md:ml-auto shrink-0",children:[l.jsx(ke,{variant:"ghost",size:"icon-xs",className:re("shrink-0 transition-opacity duration-200",s?"opacity-0 pointer-events-none w-0 overflow-hidden":"opacity-100"),onClick:()=>i(!0),title:"Show properties",children:l.jsx(Ky,{className:"h-4 w-4"})}),l.jsxs(Bn,{open:d,onOpenChange:f,children:[l.jsx(zn,{asChild:!0,children:l.jsx(ke,{variant:"ghost",size:"icon-xs",className:"shrink-0",children:l.jsx(qS,{className:"h-4 w-4"})})}),l.jsx(Vn,{className:"w-44 p-1",align:"end",children:l.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:()=>{He.mutate({hiddenAt:new Date().toISOString()},{onSuccess:()=>c("/issues/all")}),f(!1)},children:[l.jsx(R2,{className:"h-3 w-3"}),"Hide this Issue"]})})]})]})]}),l.jsx(du,{value:j.title,onSave:X=>He.mutate({title:X}),as:"h2",className:"text-xl font-bold"}),l.jsx(du,{value:j.description??"",onSave:X=>He.mutate({description:X}),as:"p",className:"text-sm text-muted-foreground",placeholder:"Add a description...",multiline:!0,mentions:ie,imageUploadHandler:async X=>(await Me.mutateAsync(X)).contentPath})]}),l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:"Attachments"}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("input",{ref:_,type:"file",accept:"image/png,image/jpeg,image/webp,image/gif",className:"hidden",onChange:At}),l.jsxs(ke,{variant:"outline",size:"sm",onClick:()=>{var X;return(X=_.current)==null?void 0:X.click()},disabled:Me.isPending,children:[l.jsx(KS,{className:"h-3.5 w-3.5 mr-1.5"}),Me.isPending?"Uploading...":"Upload image"]})]})]}),S&&l.jsx("p",{className:"text-xs text-destructive",children:S}),!z||z.length===0?l.jsx("p",{className:"text-xs text-muted-foreground",children:"No attachments yet."}):l.jsx("div",{className:"space-y-2",children:z.map(X=>l.jsxs("div",{className:"border border-border rounded-md p-2",children:[l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx("a",{href:X.contentPath,target:"_blank",rel:"noreferrer",className:"text-xs hover:underline truncate",title:X.originalFilename??X.id,children:X.originalFilename??X.id}),l.jsx("button",{type:"button",className:"text-muted-foreground hover:text-destructive",onClick:()=>ye.mutate(X.id),disabled:ye.isPending,title:"Delete attachment",children:l.jsx(lu,{className:"h-3.5 w-3.5"})})]}),l.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[X.contentType," · ",(X.byteSize/1024).toFixed(1)," KB"]}),Wt(X)&&l.jsx("a",{href:X.contentPath,target:"_blank",rel:"noreferrer",children:l.jsx("img",{src:X.contentPath,alt:X.originalFilename??"attachment",className:"mt-2 max-h-56 rounded border border-border object-contain bg-accent/10",loading:"lazy"})})]},X.id))})]}),l.jsx(Yi,{}),l.jsxs(om,{value:x,onValueChange:y,className:"space-y-3",children:[l.jsxs(Ib,{variant:"line",className:"w-full justify-start gap-1",children:[l.jsxs(ko,{value:"comments",className:"gap-1.5",children:[l.jsx(NY,{className:"h-3.5 w-3.5"}),"Comments"]}),l.jsxs(ko,{value:"subissues",className:"gap-1.5",children:[l.jsx(Qve,{className:"h-3.5 w-3.5"}),"Sub-issues"]}),l.jsxs(ko,{value:"activity",className:"gap-1.5",children:[l.jsx(Sbe,{className:"h-3.5 w-3.5"}),"Activity"]})]}),l.jsx(ea,{value:"comments",children:l.jsx(FUe,{comments:ae,linkedRuns:G,issueStatus:j.status,agentMap:H,draftKey:`paperclip:issue-comment-draft:${j.id}`,enableReassign:!0,reassignOptions:ee,currentAssigneeValue:Q,mentions:ie,onAdd:async(X,xe,we)=>{if(we){await rt.mutateAsync({body:X,reopen:xe,reassignment:we});return}await lt.mutateAsync({body:X,reopen:xe})},imageUploadHandler:async X=>(await Me.mutateAsync(X)).contentPath,onAttachImage:async X=>{await Me.mutateAsync(X)},liveRunSlot:l.jsx(UUe,{issueId:t,companyId:j.companyId})})}),l.jsx(ea,{value:"subissues",children:ce.length===0?l.jsx("p",{className:"text-xs text-muted-foreground",children:"No sub-issues."}):l.jsx("div",{className:"border border-border rounded-lg divide-y divide-border",children:ce.map(X=>l.jsxs(za,{to:`/issues/${X.identifier??X.id}`,className:"flex items-center justify-between px-3 py-2 text-sm hover:bg-accent/20 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[l.jsx(qr,{status:X.status}),l.jsx(Ss,{priority:X.priority}),l.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:X.identifier??X.id.slice(0,8)}),l.jsx("span",{className:"truncate",children:X.title})]}),X.assigneeAgentId&&(()=>{var we;const xe=(we=H.get(X.assigneeAgentId))==null?void 0:we.name;return xe?l.jsx(Sn,{name:xe,size:"sm"}):l.jsx("span",{className:"text-muted-foreground font-mono",children:X.assigneeAgentId.slice(0,8)})})()]},X.id))})}),l.jsx(ea,{value:"activity",children:!O||O.length===0?l.jsx("p",{className:"text-xs text-muted-foreground",children:"No activity yet."}):l.jsx("div",{className:"space-y-1.5",children:O.slice(0,20).map(X=>l.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[l.jsx(WUe,{evt:X,agentMap:H}),l.jsx("span",{children:KUe(X.action,X.details)}),l.jsx("span",{className:"ml-auto shrink-0",children:to(X.createdAt)})]},X.id))})})]}),$&&$.length>0&&l.jsxs(Mg,{open:w.approvals,onOpenChange:X=>k(xe=>({...xe,approvals:X})),className:"rounded-lg border border-border",children:[l.jsxs(Rg,{className:"flex w-full items-center justify-between px-3 py-2 text-left",children:[l.jsxs("span",{className:"text-sm font-medium text-muted-foreground",children:["Linked Approvals (",$.length,")"]}),l.jsx(ga,{className:re("h-4 w-4 text-muted-foreground transition-transform",w.approvals&&"rotate-180")})]}),l.jsx(Og,{children:l.jsx("div",{className:"border-t border-border divide-y divide-border",children:$.map(X=>l.jsxs(za,{to:`/approvals/${X.id}`,className:"flex items-center justify-between px-3 py-2 text-xs hover:bg-accent/20 transition-colors",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(Fn,{status:X.status}),l.jsx("span",{className:"font-medium",children:X.type.replace(/_/g," ").replace(/\b\w/g,xe=>xe.toUpperCase())}),l.jsx("span",{className:"font-mono text-muted-foreground",children:X.id.slice(0,8)})]}),l.jsx("span",{className:"text-muted-foreground",children:to(X.createdAt)})]},X.id))})})]}),I&&I.length>0&&l.jsxs(Mg,{open:w.cost,onOpenChange:X=>k(xe=>({...xe,cost:X})),className:"rounded-lg border border-border",children:[l.jsxs(Rg,{className:"flex w-full items-center justify-between px-3 py-2 text-left",children:[l.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Cost Summary"}),l.jsx(ga,{className:re("h-4 w-4 text-muted-foreground transition-transform",w.cost&&"rotate-180")})]}),l.jsx(Og,{children:l.jsx("div",{className:"border-t border-border px-3 py-2",children:!ue.hasCost&&!ue.hasTokens?l.jsx("div",{className:"text-xs text-muted-foreground",children:"No cost data yet."}):l.jsxs("div",{className:"flex flex-wrap gap-3 text-xs text-muted-foreground",children:[ue.hasCost&&l.jsxs("span",{className:"font-medium text-foreground",children:["$",ue.cost.toFixed(4)]}),ue.hasTokens&&l.jsxs("span",{children:["Tokens ",Lr(ue.totalTokens),ue.cached>0?` (in ${Lr(ue.input)}, out ${Lr(ue.output)}, cached ${Lr(ue.cached)})`:` (in ${Lr(ue.input)}, out ${Lr(ue.output)})`]})]})})})]}),l.jsx(x6,{open:m,onOpenChange:p,children:l.jsxs(y6,{side:"bottom",className:"max-h-[85dvh] pb-[env(safe-area-inset-bottom)]",children:[l.jsx(b6,{children:l.jsx(v6,{className:"text-sm",children:"Properties"})}),l.jsx(t_,{className:"flex-1 overflow-y-auto",children:l.jsx("div",{className:"px-4 pb-4",children:l.jsx(TU,{issue:j,onUpdate:X=>He.mutate(X),inline:!0})})})]})}),l.jsx(Roe,{})]})}function $oe({goal:t,children:e,allGoals:n,depth:r,goalLink:s,onSelect:i}){const[o,a]=v.useState(!0),c=e.length>0,d=s==null?void 0:s(t),f=l.jsxs(l.Fragment,{children:[c?l.jsx("button",{className:"p-0.5",onClick:p=>{p.preventDefault(),p.stopPropagation(),a(!o)},children:l.jsx(xa,{className:re("h-3 w-3 transition-transform",o&&"rotate-90")})}):l.jsx("span",{className:"w-4"}),l.jsx("span",{className:"text-xs text-muted-foreground capitalize",children:t.level}),l.jsx("span",{className:"flex-1 truncate",children:t.title}),l.jsx(Fn,{status:t.status})]}),m=re("flex items-center gap-2 px-3 py-1.5 text-sm transition-colors cursor-pointer hover:bg-accent/50");return l.jsxs("div",{children:[d?l.jsx(Bt,{to:d,className:re(m,"no-underline text-inherit"),style:{paddingLeft:`${r*16+12}px`},children:f}):l.jsx("div",{className:m,style:{paddingLeft:`${r*16+12}px`},onClick:()=>i==null?void 0:i(t),children:f}),c&&o&&l.jsx("div",{children:e.map(p=>l.jsx($oe,{goal:p,children:n.filter(x=>x.parentId===p.id),allGoals:n,depth:r+1,goalLink:s,onSelect:i},p.id))})]})}function Boe({goals:t,goalLink:e,onSelect:n}){const r=new Set(t.map(i=>i.id)),s=t.filter(i=>!i.parentId||!r.has(i.parentId));return t.length===0?l.jsx("p",{className:"text-sm text-muted-foreground",children:"No goals."}):l.jsx("div",{className:"border border-border py-1",children:s.map(i=>l.jsx($oe,{goal:i,children:t.filter(o=>o.parentId===i.id),allGoals:t,depth:0,goalLink:e,onSelect:n},i.id))})}function JUe(){const{selectedCompanyId:t}=en(),{openNewGoal:e}=$r(),{setBreadcrumbs:n}=bs();v.useEffect(()=>{n([{label:"Goals"}])},[n]);const{data:r,isLoading:s,error:i}=Be({queryKey:te.goals.list(t),queryFn:()=>Ja.list(t),enabled:!!t});return t?s?l.jsx(ui,{variant:"list"}):l.jsxs("div",{className:"space-y-4",children:[i&&l.jsx("p",{className:"text-sm text-destructive",children:i.message}),r&&r.length===0&&l.jsx(Os,{icon:Yl,message:"No goals yet.",action:"Add Goal",onAction:()=>e()}),r&&r.length>0&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"flex items-center justify-start",children:l.jsxs(ke,{size:"sm",variant:"outline",onClick:()=>e(),children:[l.jsx(Pr,{className:"h-3.5 w-3.5 mr-1.5"}),"New Goal"]})}),l.jsx(Boe,{goals:r,goalLink:o=>`/goals/${o.id}`})]})]}):l.jsx(Os,{icon:Yl,message:"Select a company to view goals."})}function Cp({label:t,children:e}){return l.jsxs("div",{className:"flex items-center gap-3 py-1.5",children:[l.jsx("span",{className:"text-xs text-muted-foreground shrink-0 w-20",children:t}),l.jsx("div",{className:"flex items-center gap-1.5 min-w-0",children:e})]})}function YUe(t){return t.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function IU({current:t,options:e,onChange:n,children:r}){const[s,i]=v.useState(!1);return l.jsxs(Bn,{open:s,onOpenChange:i,children:[l.jsx(zn,{asChild:!0,children:l.jsx("button",{className:"cursor-pointer hover:opacity-80 transition-opacity",children:r})}),l.jsx(Vn,{className:"w-40 p-1",align:"end",children:e.map(o=>l.jsx(ke,{variant:"ghost",size:"sm",className:re("w-full justify-start text-xs",o===t&&"bg-accent"),onClick:()=>{n(o),i(!1)},children:YUe(o)},o))})]})}function ZUe({goal:t,onUpdate:e}){const{selectedCompanyId:n}=en(),{data:r}=Be({queryKey:te.agents.list(n),queryFn:()=>Ot.list(n),enabled:!!n}),{data:s}=Be({queryKey:te.goals.list(n),queryFn:()=>Ja.list(n),enabled:!!n}),i=t.ownerAgentId?r==null?void 0:r.find(a=>a.id===t.ownerAgentId):null,o=t.parentId?s==null?void 0:s.find(a=>a.id===t.parentId):null;return l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsx(Cp,{label:"Status",children:e?l.jsx(IU,{current:t.status,options:$R,onChange:a=>e({status:a}),children:l.jsx(Fn,{status:t.status})}):l.jsx(Fn,{status:t.status})}),l.jsx(Cp,{label:"Level",children:e?l.jsx(IU,{current:t.level,options:FR,onChange:a=>e({level:a}),children:l.jsx("span",{className:"text-sm capitalize",children:t.level})}):l.jsx("span",{className:"text-sm capitalize",children:t.level})}),l.jsx(Cp,{label:"Owner",children:i?l.jsx(Bt,{to:fm(i),className:"text-sm hover:underline",children:i.name}):l.jsx("span",{className:"text-sm text-muted-foreground",children:"None"})}),t.parentId&&l.jsx(Cp,{label:"Parent Goal",children:l.jsx(Bt,{to:`/goals/${t.parentId}`,className:"text-sm hover:underline",children:(o==null?void 0:o.title)??t.parentId.slice(0,8)})})]}),l.jsx(Yi,{}),l.jsxs("div",{className:"space-y-1",children:[l.jsx(Cp,{label:"Created",children:l.jsx("span",{className:"text-sm",children:ki(t.createdAt)})}),l.jsx(Cp,{label:"Updated",children:l.jsx("span",{className:"text-sm",children:ki(t.updatedAt)})})]})]})}function QUe(){const{goalId:t}=Eu(),{selectedCompanyId:e,setSelectedCompanyId:n}=en(),{openNewGoal:r}=$r(),{openPanel:s,closePanel:i}=hx(),{setBreadcrumbs:o}=bs(),a=Nn(),{data:c,isLoading:d,error:f}=Be({queryKey:te.goals.detail(t),queryFn:()=>Ja.get(t),enabled:!!t}),m=(c==null?void 0:c.companyId)??e,{data:p}=Be({queryKey:te.goals.list(m),queryFn:()=>Ja.list(m),enabled:!!m}),{data:x}=Be({queryKey:te.projects.list(m),queryFn:()=>oi.list(m),enabled:!!m});v.useEffect(()=>{!(c!=null&&c.companyId)||c.companyId===e||n(c.companyId,{source:"route_sync"})},[c==null?void 0:c.companyId,e,n]);const y=yt({mutationFn:C=>Ja.update(t,C),onSuccess:()=>{a.invalidateQueries({queryKey:te.goals.detail(t)}),m&&a.invalidateQueries({queryKey:te.goals.list(m)})}}),w=yt({mutationFn:async C=>{if(!m)throw new Error("No company selected");return mx.uploadImage(m,C,`goals/${t??"draft"}`)}}),k=(p??[]).filter(C=>C.parentId===t),S=(x??[]).filter(C=>t?C.goalIds.includes(t)||C.goals.some(_=>_.id===t)?!0:C.goalId===t:!1);return v.useEffect(()=>{o([{label:"Goals",href:"/goals"},{label:(c==null?void 0:c.title)??t??"Goal"}])},[o,c,t]),v.useEffect(()=>(c&&s(l.jsx(ZUe,{goal:c,onUpdate:C=>y.mutate(C)})),()=>i()),[c]),d?l.jsx(ui,{variant:"detail"}):f?l.jsx("p",{className:"text-sm text-destructive",children:f.message}):c?l.jsxs("div",{className:"space-y-6",children:[l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-xs uppercase text-muted-foreground",children:c.level}),l.jsx(Fn,{status:c.status})]}),l.jsx(du,{value:c.title,onSave:C=>y.mutate({title:C}),as:"h2",className:"text-xl font-bold"}),l.jsx(du,{value:c.description??"",onSave:C=>y.mutate({description:C}),as:"p",className:"text-sm text-muted-foreground",placeholder:"Add a description...",multiline:!0,imageUploadHandler:async C=>(await w.mutateAsync(C)).contentPath})]}),l.jsxs(om,{defaultValue:"children",children:[l.jsxs(Ib,{children:[l.jsxs(ko,{value:"children",children:["Sub-Goals (",k.length,")"]}),l.jsxs(ko,{value:"projects",children:["Projects (",S.length,")"]})]}),l.jsxs(ea,{value:"children",className:"mt-4 space-y-3",children:[l.jsx("div",{className:"flex items-center justify-start",children:l.jsxs(ke,{size:"sm",variant:"outline",onClick:()=>r({parentId:t}),children:[l.jsx(Pr,{className:"h-3.5 w-3.5 mr-1.5"}),"Sub Goal"]})}),k.length===0?l.jsx("p",{className:"text-sm text-muted-foreground",children:"No sub-goals."}):l.jsx(Boe,{goals:k,goalLink:C=>`/goals/${C.id}`})]}),l.jsx(ea,{value:"projects",className:"mt-4",children:S.length===0?l.jsx("p",{className:"text-sm text-muted-foreground",children:"No linked projects."}):l.jsx("div",{className:"border border-border",children:S.map(C=>l.jsx(Al,{title:C.name,subtitle:C.description??void 0,to:US(C),trailing:l.jsx(Fn,{status:C.status})},C.id))})})]})]}):null}const Ki={list:(t,e)=>Le.get(`/companies/${t}/approvals${e?`?status=${encodeURIComponent(e)}`:""}`),create:(t,e)=>Le.post(`/companies/${t}/approvals`,e),get:t=>Le.get(`/approvals/${t}`),approve:(t,e)=>Le.post(`/approvals/${t}/approve`,{decisionNote:e}),reject:(t,e)=>Le.post(`/approvals/${t}/reject`,{decisionNote:e}),requestRevision:(t,e)=>Le.post(`/approvals/${t}/request-revision`,{decisionNote:e}),resubmit:(t,e)=>Le.post(`/approvals/${t}/resubmit`,{payload:e}),listComments:t=>Le.get(`/approvals/${t}/comments`),addComment:(t,e)=>Le.post(`/approvals/${t}/comments`,{body:e}),listIssues:t=>Le.get(`/approvals/${t}/issues`)},zoe={hire_agent:"Hire Agent",approve_ceo_strategy:"CEO Strategy"},Voe={hire_agent:owe,approve_ceo_strategy:kY},Hoe=sO;function t2({label:t,value:e}){return e?l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-muted-foreground w-20 sm:w-24 shrink-0 text-xs",children:t}),l.jsx("span",{children:String(e)})]}):null}function XUe({payload:t}){return l.jsxs("div",{className:"mt-3 space-y-1.5 text-sm",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-muted-foreground w-20 sm:w-24 shrink-0 text-xs",children:"Name"}),l.jsx("span",{className:"font-medium",children:String(t.name??"—")})]}),l.jsx(t2,{label:"Role",value:t.role}),l.jsx(t2,{label:"Title",value:t.title}),l.jsx(t2,{label:"Icon",value:t.icon}),!!t.capabilities&&l.jsxs("div",{className:"flex items-start gap-2",children:[l.jsx("span",{className:"text-muted-foreground w-20 sm:w-24 shrink-0 text-xs pt-0.5",children:"Capabilities"}),l.jsx("span",{className:"text-muted-foreground",children:String(t.capabilities)})]}),!!t.adapterType&&l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-muted-foreground w-20 sm:w-24 shrink-0 text-xs",children:"Adapter"}),l.jsx("span",{className:"font-mono text-xs bg-muted px-1.5 py-0.5 rounded",children:String(t.adapterType)})]})]})}function eqe({payload:t}){const e=t.plan??t.description??t.strategy??t.text;return l.jsxs("div",{className:"mt-3 space-y-1.5 text-sm",children:[l.jsx(t2,{label:"Title",value:t.title}),!!e&&l.jsx("div",{className:"mt-2 rounded-md bg-muted/40 px-3 py-2 text-sm text-muted-foreground whitespace-pre-wrap font-mono text-xs max-h-48 overflow-y-auto",children:String(e)}),!e&&l.jsx("pre",{className:"mt-2 rounded-md bg-muted/40 px-3 py-2 text-xs text-muted-foreground overflow-x-auto max-h-48",children:JSON.stringify(t,null,2)})]})}function Uoe({type:t,payload:e}){return t==="hire_agent"?l.jsx(XUe,{payload:e}):l.jsx(eqe,{payload:e})}function tqe(t){return t==="approved"?l.jsx(WR,{className:"h-3.5 w-3.5 text-green-600 dark:text-green-400"}):t==="rejected"?l.jsx(GR,{className:"h-3.5 w-3.5 text-red-600 dark:text-red-400"}):t==="revision_requested"?l.jsx(Ng,{className:"h-3.5 w-3.5 text-amber-600 dark:text-amber-400"}):t==="pending"?l.jsx(Ng,{className:"h-3.5 w-3.5 text-yellow-600 dark:text-yellow-400"}):null}function qoe({approval:t,requesterAgent:e,onApprove:n,onReject:r,onOpen:s,detailLink:i,isPending:o}){const a=Voe[t.type]??Hoe,c=zoe[t.type]??t.type;return l.jsxs("div",{className:"border border-border rounded-lg p-4 space-y-0",children:[l.jsxs("div",{className:"flex items-start justify-between gap-3",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(a,{className:"h-4 w-4 text-muted-foreground shrink-0"}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"font-medium text-sm",children:c}),e&&l.jsxs("span",{className:"text-xs text-muted-foreground",children:["requested by ",l.jsx(Sn,{name:e.name,size:"sm",className:"inline-flex"})]})]})]}),l.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[tqe(t.status),l.jsx("span",{className:"text-xs text-muted-foreground capitalize",children:t.status}),l.jsxs("span",{className:"text-xs text-muted-foreground",children:["· ",Bl(t.createdAt)]})]})]}),l.jsx(Uoe,{type:t.type,payload:t.payload}),t.decisionNote&&l.jsxs("div",{className:"mt-3 text-xs text-muted-foreground italic border-t border-border pt-2",children:["Note: ",t.decisionNote]}),(t.status==="pending"||t.status==="revision_requested")&&l.jsxs("div",{className:"flex gap-2 mt-4 pt-3 border-t border-border",children:[l.jsx(ke,{size:"sm",className:"bg-green-700 hover:bg-green-600 text-white",onClick:n,disabled:o,children:"Approve"}),l.jsx(ke,{variant:"destructive",size:"sm",onClick:r,disabled:o,children:"Reject"})]}),l.jsx("div",{className:"mt-3",children:i?l.jsx(ke,{variant:"ghost",size:"sm",className:"text-xs px-0",asChild:!0,children:l.jsx(Bt,{to:i,children:"View details"})}):l.jsx(ke,{variant:"ghost",size:"sm",className:"text-xs px-0",onClick:s,children:"View details"})})]})}function DU(){const{selectedCompanyId:t}=en(),{setBreadcrumbs:e}=bs(),n=Nn(),r=Ti(),o=(Fr().pathname.split("/").pop()??"pending")==="all"?"all":"pending",[a,c]=v.useState(null);v.useEffect(()=>{e([{label:"Approvals"}])},[e]);const{data:d,isLoading:f,error:m}=Be({queryKey:te.approvals.list(t),queryFn:()=>Ki.list(t),enabled:!!t}),{data:p}=Be({queryKey:te.agents.list(t),queryFn:()=>Ot.list(t),enabled:!!t}),x=yt({mutationFn:S=>Ki.approve(S),onSuccess:(S,C)=>{c(null),n.invalidateQueries({queryKey:te.approvals.list(t)}),r(`/approvals/${C}?resolved=approved`)},onError:S=>{c(S instanceof Error?S.message:"Failed to approve")}}),y=yt({mutationFn:S=>Ki.reject(S),onSuccess:()=>{c(null),n.invalidateQueries({queryKey:te.approvals.list(t)})},onError:S=>{c(S instanceof Error?S.message:"Failed to reject")}}),w=(d??[]).filter(S=>o==="all"||S.status==="pending"||S.status==="revision_requested").sort((S,C)=>new Date(C.createdAt).getTime()-new Date(S.createdAt).getTime()),k=(d??[]).filter(S=>S.status==="pending"||S.status==="revision_requested").length;return t?f?l.jsx(ui,{variant:"approvals"}):l.jsxs("div",{className:"space-y-4",children:[l.jsx("div",{className:"flex items-center justify-between",children:l.jsx(om,{value:o,onValueChange:S=>r(`/approvals/${S}`),children:l.jsx(s6,{items:[{value:"pending",label:l.jsxs(l.Fragment,{children:["Pending",k>0&&l.jsx("span",{className:re("ml-1.5 rounded-full px-1.5 py-0.5 text-[10px] font-medium","bg-yellow-500/20 text-yellow-500"),children:k})]})},{value:"all",label:"All"}]})})}),m&&l.jsx("p",{className:"text-sm text-destructive",children:m.message}),a&&l.jsx("p",{className:"text-sm text-destructive",children:a}),w.length===0&&l.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[l.jsx(sO,{className:"h-8 w-8 text-muted-foreground/30 mb-3"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:o==="pending"?"No pending approvals.":"No approvals yet."})]}),w.length>0&&l.jsx("div",{className:"grid gap-3",children:w.map(S=>l.jsx(qoe,{approval:S,requesterAgent:S.requestedByAgentId?(p??[]).find(C=>C.id===S.requestedByAgentId)??null:null,onApprove:()=>x.mutate(S.id),onReject:()=>y.mutate(S.id),detailLink:`/approvals/${S.id}`,isPending:x.isPending||y.isPending},S.id))})]}):l.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a company first."})}function dy({className:t,...e}){return l.jsx("textarea",{"data-slot":"textarea",className:re("border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),...e})}function nqe(){const{approvalId:t}=Eu(),{selectedCompanyId:e,setSelectedCompanyId:n}=en(),{setBreadcrumbs:r}=bs(),s=Ti(),[i]=Qb(),o=Nn(),[a,c]=v.useState(""),[d,f]=v.useState(null),[m,p]=v.useState(!1),{data:x,isLoading:y}=Be({queryKey:te.approvals.detail(t),queryFn:()=>Ki.get(t),enabled:!!t}),w=(x==null?void 0:x.companyId)??e,{data:k}=Be({queryKey:te.approvals.comments(t),queryFn:()=>Ki.listComments(t),enabled:!!t}),{data:S}=Be({queryKey:te.approvals.issues(t),queryFn:()=>Ki.listIssues(t),enabled:!!t}),{data:C}=Be({queryKey:te.agents.list(w??""),queryFn:()=>Ot.list(w??""),enabled:!!w});v.useEffect(()=>{!(x!=null&&x.companyId)||x.companyId===e||n(x.companyId,{source:"route_sync"})},[x==null?void 0:x.companyId,e,n]);const _=v.useMemo(()=>{const L=new Map;for(const K of C??[])L.set(K.id,K.name);return L},[C]);v.useEffect(()=>{var L;r([{label:"Approvals",href:"/approvals"},{label:((L=x==null?void 0:x.id)==null?void 0:L.slice(0,8))??t??"Approval"}])},[r,x,t]);const E=()=>{t&&(o.invalidateQueries({queryKey:te.approvals.detail(t)}),o.invalidateQueries({queryKey:te.approvals.comments(t)}),o.invalidateQueries({queryKey:te.approvals.issues(t)}),x!=null&&x.companyId&&(o.invalidateQueries({queryKey:te.approvals.list(x.companyId)}),o.invalidateQueries({queryKey:te.approvals.list(x.companyId,"pending")}),o.invalidateQueries({queryKey:te.agents.list(x.companyId)})))},j=yt({mutationFn:()=>Ki.approve(t),onSuccess:()=>{f(null),E(),s(`/approvals/${t}?resolved=approved`,{replace:!0})},onError:L=>f(L instanceof Error?L.message:"Approve failed")}),R=yt({mutationFn:()=>Ki.reject(t),onSuccess:()=>{f(null),E()},onError:L=>f(L instanceof Error?L.message:"Reject failed")}),T=yt({mutationFn:()=>Ki.requestRevision(t),onSuccess:()=>{f(null),E()},onError:L=>f(L instanceof Error?L.message:"Revision request failed")}),M=yt({mutationFn:()=>Ki.resubmit(t),onSuccess:()=>{f(null),E()},onError:L=>f(L instanceof Error?L.message:"Resubmit failed")}),O=yt({mutationFn:()=>Ki.addComment(t,a.trim()),onSuccess:()=>{c(""),f(null),E()},onError:L=>f(L instanceof Error?L.message:"Comment failed")}),I=yt({mutationFn:L=>Ot.remove(L),onSuccess:()=>{f(null),E(),s("/approvals")},onError:L=>f(L instanceof Error?L.message:"Delete failed")});if(y)return l.jsx(ui,{variant:"detail"});if(!x)return l.jsx("p",{className:"text-sm text-muted-foreground",children:"Approval not found."});const $=x.payload,z=typeof $.agentId=="string"?$.agentId:null,V=x.status==="pending"||x.status==="revision_requested",W=Voe[x.type]??Hoe,J=i.get("resolved")==="approved"&&x.status==="approved",G=(S==null?void 0:S[0])??null,F=G?{label:((S==null?void 0:S.length)??0)>1?"Review linked issues":"Review linked issue",to:`/issues/${G.identifier??G.id}`}:z?{label:"Open hired agent",to:`/agents/${z}`}:{label:"Back to approvals",to:"/approvals"};return l.jsxs("div",{className:"space-y-6 max-w-3xl",children:[J&&l.jsx("div",{className:"border border-green-300 dark:border-green-700/40 bg-green-50 dark:bg-green-900/20 rounded-lg px-4 py-3 animate-in fade-in zoom-in-95 duration-300",children:l.jsxs("div",{className:"flex items-start justify-between gap-3",children:[l.jsxs("div",{className:"flex items-start gap-2",children:[l.jsxs("div",{className:"relative mt-0.5",children:[l.jsx(WR,{className:"h-4 w-4 text-green-600 dark:text-green-300"}),l.jsx($h,{className:"h-3 w-3 text-green-500 dark:text-green-200 absolute -right-2 -top-1 animate-pulse"})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-sm text-green-800 dark:text-green-100 font-medium",children:"Approval confirmed"}),l.jsx("p",{className:"text-xs text-green-700 dark:text-green-200/90",children:"Requesting agent was notified to review this approval and linked issues."})]})]}),l.jsx(ke,{size:"sm",variant:"outline",className:"border-green-400 dark:border-green-600/50 text-green-800 dark:text-green-100 hover:bg-green-100 dark:hover:bg-green-900/30",onClick:()=>s(F.to),children:F.label})]})}),l.jsxs("div",{className:"border border-border rounded-lg p-4 space-y-3",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(W,{className:"h-5 w-5 text-muted-foreground shrink-0"}),l.jsxs("div",{children:[l.jsx("h2",{className:"text-lg font-semibold",children:zoe[x.type]??x.type.replace(/_/g," ")}),l.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:x.id})]})]}),l.jsx(Fn,{status:x.status})]}),l.jsxs("div",{className:"text-sm space-y-1",children:[x.requestedByAgentId&&l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"text-muted-foreground text-xs",children:"Requested by"}),l.jsx(Sn,{name:_.get(x.requestedByAgentId)??x.requestedByAgentId.slice(0,8),size:"sm"})]}),l.jsx(Uoe,{type:x.type,payload:$}),l.jsxs("button",{type:"button",className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors mt-2",onClick:()=>p(L=>!L),children:[l.jsx(xa,{className:`h-3 w-3 transition-transform ${m?"rotate-90":""}`}),"See full request"]}),m&&l.jsx("pre",{className:"text-xs bg-muted/40 rounded-md p-3 overflow-x-auto",children:JSON.stringify($,null,2)}),x.decisionNote&&l.jsxs("p",{className:"text-xs text-muted-foreground",children:["Decision note: ",x.decisionNote]})]}),d&&l.jsx("p",{className:"text-sm text-destructive",children:d}),S&&S.length>0&&l.jsxs("div",{className:"pt-2 border-t border-border/60",children:[l.jsx("p",{className:"text-xs text-muted-foreground mb-1.5",children:"Linked Issues"}),l.jsx("div",{className:"space-y-1.5",children:S.map(L=>l.jsxs(Bt,{to:`/issues/${L.identifier??L.id}`,className:"block text-xs rounded border border-border/70 px-2 py-1.5 hover:bg-accent/20",children:[l.jsx("span",{className:"font-mono text-muted-foreground mr-2",children:L.identifier??L.id.slice(0,8)}),l.jsx("span",{children:L.title})]},L.id))}),l.jsx("p",{className:"text-[11px] text-muted-foreground mt-2",children:"Linked issues remain open until the requesting agent follows up and closes them."})]}),l.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[V&&l.jsxs(l.Fragment,{children:[l.jsx(ke,{size:"sm",className:"bg-green-700 hover:bg-green-600 text-white",onClick:()=>j.mutate(),disabled:j.isPending,children:"Approve"}),l.jsx(ke,{variant:"destructive",size:"sm",onClick:()=>R.mutate(),disabled:R.isPending,children:"Reject"})]}),x.status==="pending"&&l.jsx(ke,{size:"sm",variant:"outline",onClick:()=>T.mutate(),disabled:T.isPending,children:"Request revision"}),x.status==="revision_requested"&&l.jsx(ke,{size:"sm",variant:"outline",onClick:()=>M.mutate(),disabled:M.isPending,children:"Mark resubmitted"}),x.status==="rejected"&&x.type==="hire_agent"&&z&&l.jsx(ke,{size:"sm",variant:"outline",className:"text-destructive border-destructive/40",onClick:()=>{window.confirm("Delete this disapproved agent? This cannot be undone.")&&I.mutate(z)},disabled:I.isPending,children:"Delete disapproved agent"})]})]}),l.jsxs("div",{className:"border border-border rounded-lg p-4 space-y-3",children:[l.jsxs("h3",{className:"text-sm font-medium",children:["Comments (",(k==null?void 0:k.length)??0,")"]}),l.jsx("div",{className:"space-y-2",children:(k??[]).map(L=>l.jsxs("div",{className:"border border-border/60 rounded-md p-3",children:[l.jsxs("div",{className:"flex items-center justify-between mb-1",children:[L.authorAgentId?l.jsx(Bt,{to:`/agents/${L.authorAgentId}`,className:"hover:underline",children:l.jsx(Sn,{name:_.get(L.authorAgentId)??L.authorAgentId.slice(0,8),size:"sm"})}):l.jsx(Sn,{name:"Board",size:"sm"}),l.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(L.createdAt).toLocaleString()})]}),l.jsx(i5,{className:"text-sm",children:L.body})]},L.id))}),l.jsx(dy,{value:a,onChange:L=>c(L.target.value),placeholder:"Add a comment...",rows:3}),l.jsx("div",{className:"flex justify-end",children:l.jsx(ke,{size:"sm",onClick:()=>O.mutate(),disabled:!a.trim()||O.isPending,children:O.isPending?"Posting…":"Post comment"})})]})]})}function HA(t,e){const n=new URLSearchParams;t&&n.set("from",t),e&&n.set("to",e);const r=n.toString();return r?`?${r}`:""}const UA={summary:(t,e,n)=>Le.get(`/companies/${t}/costs/summary${HA(e,n)}`),byAgent:(t,e,n)=>Le.get(`/companies/${t}/costs/by-agent${HA(e,n)}`),byProject:(t,e,n)=>Le.get(`/companies/${t}/costs/by-project${HA(e,n)}`)};function n2({className:t,...e}){return l.jsx("div",{"data-slot":"card",className:re("bg-card text-card-foreground flex flex-col gap-6 border py-6 shadow-sm",t),...e})}function rqe({className:t,...e}){return l.jsx("div",{"data-slot":"card-header",className:re("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",t),...e})}function sqe({className:t,...e}){return l.jsx("div",{"data-slot":"card-title",className:re("leading-none font-semibold",t),...e})}function iqe({className:t,...e}){return l.jsx("div",{"data-slot":"card-description",className:re("text-muted-foreground text-sm",t),...e})}function r2({className:t,...e}){return l.jsx("div",{"data-slot":"card-content",className:re("px-6",t),...e})}function oqe({className:t,...e}){return l.jsx("div",{"data-slot":"card-footer",className:re("flex items-center px-6 [.border-t]:pt-6",t),...e})}const LU={mtd:"Month to Date","7d":"Last 7 Days","30d":"Last 30 Days",ytd:"Year to Date",all:"All Time",custom:"Custom"};function aqe(t){const e=new Date,n=e.toISOString();switch(t){case"mtd":return{from:new Date(e.getFullYear(),e.getMonth(),1).toISOString(),to:n};case"7d":return{from:new Date(e.getTime()-6048e5).toISOString(),to:n};case"30d":return{from:new Date(e.getTime()-2592e6).toISOString(),to:n};case"ytd":return{from:new Date(e.getFullYear(),0,1).toISOString(),to:n};case"all":return{from:"",to:""};case"custom":return{from:"",to:""}}}function lqe(){const{selectedCompanyId:t}=en(),{setBreadcrumbs:e}=bs(),[n,r]=v.useState("mtd"),[s,i]=v.useState(""),[o,a]=v.useState("");v.useEffect(()=>{e([{label:"Costs"}])},[e]);const{from:c,to:d}=v.useMemo(()=>n==="custom"?{from:s?new Date(s).toISOString():"",to:o?new Date(o+"T23:59:59.999Z").toISOString():""}:aqe(n),[n,s,o]),{data:f,isLoading:m,error:p}=Be({queryKey:te.costs(t,c||void 0,d||void 0),queryFn:async()=>{const[y,w,k]=await Promise.all([UA.summary(t,c||void 0,d||void 0),UA.byAgent(t,c||void 0,d||void 0),UA.byProject(t,c||void 0,d||void 0)]);return{summary:y,byAgent:w,byProject:k}},enabled:!!t});if(!t)return l.jsx(Os,{icon:Ph,message:"Select a company to view costs."});if(m)return l.jsx(ui,{variant:"costs"});const x=["mtd","7d","30d","ytd","all","custom"];return l.jsxs("div",{className:"space-y-6",children:[l.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[x.map(y=>l.jsx(ke,{variant:n===y?"secondary":"ghost",size:"sm",onClick:()=>r(y),children:LU[y]},y)),n==="custom"&&l.jsxs("div",{className:"flex items-center gap-2 ml-2",children:[l.jsx("input",{type:"date",value:s,onChange:y=>i(y.target.value),className:"h-8 rounded-md border border-input bg-background px-2 text-sm text-foreground"}),l.jsx("span",{className:"text-sm text-muted-foreground",children:"to"}),l.jsx("input",{type:"date",value:o,onChange:y=>a(y.target.value),className:"h-8 rounded-md border border-input bg-background px-2 text-sm text-foreground"})]})]}),p&&l.jsx("p",{className:"text-sm text-destructive",children:p.message}),f&&l.jsxs(l.Fragment,{children:[l.jsx(n2,{children:l.jsxs(r2,{className:"p-4 space-y-3",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("p",{className:"text-sm text-muted-foreground",children:LU[n]}),f.summary.budgetCents>0&&l.jsxs("p",{className:"text-sm text-muted-foreground",children:[f.summary.utilizationPercent,"% utilized"]})]}),l.jsxs("p",{className:"text-2xl font-bold",children:[Xc(f.summary.spendCents)," ",l.jsx("span",{className:"text-base font-normal text-muted-foreground",children:f.summary.budgetCents>0?`/ ${Xc(f.summary.budgetCents)}`:"Unlimited budget"})]}),f.summary.budgetCents>0&&l.jsx("div",{className:"w-full h-2 bg-muted rounded-full overflow-hidden",children:l.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-150 ${f.summary.utilizationPercent>90?"bg-red-400":f.summary.utilizationPercent>70?"bg-yellow-400":"bg-green-400"}`,style:{width:`${Math.min(100,f.summary.utilizationPercent)}%`}})})]})}),l.jsxs("div",{className:"grid md:grid-cols-2 gap-4",children:[l.jsx(n2,{children:l.jsxs(r2,{className:"p-4",children:[l.jsx("h3",{className:"text-sm font-semibold mb-3",children:"By Agent"}),f.byAgent.length===0?l.jsx("p",{className:"text-sm text-muted-foreground",children:"No cost events yet."}):l.jsx("div",{className:"space-y-2",children:f.byAgent.map(y=>l.jsxs("div",{className:"flex items-start justify-between text-sm",children:[l.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[l.jsx(Sn,{name:y.agentName??y.agentId,size:"sm"}),y.agentStatus==="terminated"&&l.jsx(Fn,{status:"terminated"})]}),l.jsxs("div",{className:"text-right shrink-0 ml-2",children:[l.jsx("span",{className:"font-medium block",children:Xc(y.costCents)}),l.jsxs("span",{className:"text-xs text-muted-foreground block",children:["in ",Lr(y.inputTokens)," / out ",Lr(y.outputTokens)," tok"]}),(y.apiRunCount>0||y.subscriptionRunCount>0)&&l.jsxs("span",{className:"text-xs text-muted-foreground block",children:[y.apiRunCount>0?`api runs: ${y.apiRunCount}`:null,y.apiRunCount>0&&y.subscriptionRunCount>0?" | ":null,y.subscriptionRunCount>0?`subscription runs: ${y.subscriptionRunCount} (${Lr(y.subscriptionInputTokens)} in / ${Lr(y.subscriptionOutputTokens)} out tok)`:null]})]})]},y.agentId))})]})}),l.jsx(n2,{children:l.jsxs(r2,{className:"p-4",children:[l.jsx("h3",{className:"text-sm font-semibold mb-3",children:"By Project"}),f.byProject.length===0?l.jsx("p",{className:"text-sm text-muted-foreground",children:"No project-attributed run costs yet."}):l.jsx("div",{className:"space-y-2",children:f.byProject.map(y=>l.jsxs("div",{className:"flex items-center justify-between text-sm",children:[l.jsx("span",{className:"truncate",children:y.projectName??y.projectId??"Unattributed"}),l.jsx("span",{className:"font-medium",children:Xc(y.costCents)})]},y.projectId??"na"))})]})})]})]})]})}function Lb({...t}){return l.jsx(WG,{"data-slot":"select",...t})}function Pb({...t}){return l.jsx(JG,{"data-slot":"select-value",...t})}function Fb({className:t,size:e="default",children:n,...r}){return l.jsxs(GG,{"data-slot":"select-trigger","data-size":e,className:re("border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",t),...r,children:[n,l.jsx(YG,{asChild:!0,children:l.jsx(ga,{className:"size-4 opacity-50"})})]})}function $b({className:t,children:e,position:n="item-aligned",align:r="center",...s}){return l.jsx(ZG,{children:l.jsxs(QG,{"data-slot":"select-content",className:re("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:n,align:r,...s,children:[l.jsx(cqe,{}),l.jsx(XG,{className:re("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:e}),l.jsx(uqe,{})]})})}function Hr({className:t,children:e,...n}){return l.jsxs(eJ,{"data-slot":"select-item",className:re("focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",t),...n,children:[l.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:l.jsx(pxe,{children:l.jsx(fa,{className:"size-4"})})}),l.jsx(tJ,{children:e})]})}function cqe({className:t,...e}){return l.jsx(gxe,{"data-slot":"select-scroll-up-button",className:re("flex cursor-default items-center justify-center py-1",t),...e,children:l.jsx(Gbe,{className:"size-4"})})}function uqe({className:t,...e}){return l.jsx(xxe,{"data-slot":"select-scroll-down-button",className:re("flex cursor-default items-center justify-center py-1",t),...e,children:l.jsx(ga,{className:"size-4"})})}function dqe(){const{selectedCompanyId:t}=en(),{setBreadcrumbs:e}=bs(),[n,r]=v.useState("all");v.useEffect(()=>{e([{label:"Activity"}])},[e]);const{data:s,isLoading:i,error:o}=Be({queryKey:te.activity(t),queryFn:()=>Rb.list(t),enabled:!!t}),{data:a}=Be({queryKey:te.agents.list(t),queryFn:()=>Ot.list(t),enabled:!!t}),{data:c}=Be({queryKey:te.issues.list(t),queryFn:()=>Dn.list(t),enabled:!!t}),{data:d}=Be({queryKey:te.projects.list(t),queryFn:()=>oi.list(t),enabled:!!t}),{data:f}=Be({queryKey:te.goals.list(t),queryFn:()=>Ja.list(t),enabled:!!t}),m=v.useMemo(()=>{const k=new Map;for(const S of a??[])k.set(S.id,S);return k},[a]),p=v.useMemo(()=>{const k=new Map;for(const S of c??[])k.set(`issue:${S.id}`,S.identifier??S.id.slice(0,8));for(const S of a??[])k.set(`agent:${S.id}`,S.name);for(const S of d??[])k.set(`project:${S.id}`,S.name);for(const S of f??[])k.set(`goal:${S.id}`,S.title);return k},[c,a,d,f]),x=v.useMemo(()=>{const k=new Map;for(const S of c??[])k.set(`issue:${S.id}`,S.title);return k},[c]);if(!t)return l.jsx(Os,{icon:qy,message:"Select a company to view activity."});if(i)return l.jsx(ui,{variant:"list"});const y=s&&n!=="all"?s.filter(k=>k.entityType===n):s,w=s?[...new Set(s.map(k=>k.entityType))].sort():[];return l.jsxs("div",{className:"space-y-4",children:[l.jsx("div",{className:"flex items-center justify-end",children:l.jsxs(Lb,{value:n,onValueChange:r,children:[l.jsx(Fb,{className:"w-[140px] h-8 text-xs",children:l.jsx(Pb,{placeholder:"Filter by type"})}),l.jsxs($b,{children:[l.jsx(Hr,{value:"all",children:"All types"}),w.map(k=>l.jsx(Hr,{value:k,children:k.charAt(0).toUpperCase()+k.slice(1)},k))]})]})}),o&&l.jsx("p",{className:"text-sm text-destructive",children:o.message}),y&&y.length===0&&l.jsx(Os,{icon:qy,message:"No activity yet."}),y&&y.length>0&&l.jsx("div",{className:"border border-border divide-y divide-border",children:y.map(k=>l.jsx($ie,{event:k,agentMap:m,entityNameMap:p,entityTitleMap:x},k.id))})]})}const Ha={createCompanyInvite:(t,e={})=>Le.post(`/companies/${t}/invites`,e),createOpenClawInvitePrompt:(t,e={})=>Le.post(`/companies/${t}/openclaw/invite-prompt`,e),getInvite:t=>Le.get(`/invites/${t}`),getInviteOnboarding:t=>Le.get(`/invites/${t}/onboarding`),acceptInvite:(t,e)=>Le.post(`/invites/${t}/accept`,e),listJoinRequests:(t,e="pending_approval")=>Le.get(`/companies/${t}/join-requests?status=${e}`),approveJoinRequest:(t,e)=>Le.post(`/companies/${t}/join-requests/${e}/approve`,{}),rejectJoinRequest:(t,e)=>Le.post(`/companies/${t}/join-requests/${e}/reject`,{}),claimJoinRequestApiKey:(t,e)=>Le.post(`/join-requests/${t}/claim-api-key`,{claimSecret:e}),getBoardClaimStatus:(t,e)=>Le.get(`/board-claim/${t}?code=${encodeURIComponent(e)}`),claimBoard:(t,e)=>Le.post(`/board-claim/${t}/claim`,{code:e})},fqe=1440*60*1e3,hqe=100,mqe=new Set(["failed","timed_out"]),PU=new Set(["pending","revision_requested"]),Koe="paperclip:inbox:dismissed";function pqe(){try{const t=localStorage.getItem(Koe);return t?new Set(JSON.parse(t)):new Set}catch{return new Set}}function gqe(t){localStorage.setItem(Koe,JSON.stringify([...t]))}function xqe(){const[t,e]=v.useState(pqe),n=v.useCallback(r=>{e(s=>{const i=new Set(s);return i.add(r),gqe(i),i})},[]);return{dismissed:t,dismiss:n}}const yqe={timer:"Scheduled",assignment:"Assignment",on_demand:"Manual",automation:"Automation"};function bqe(t){const e=Date.now();return t.filter(n=>["in_progress","todo"].includes(n.status)&&e-new Date(n.updatedAt).getTime()>fqe).sort((n,r)=>new Date(n.updatedAt).getTime()-new Date(r.updatedAt).getTime())}function vqe(t){const e=[...t].sort((r,s)=>new Date(s.createdAt).getTime()-new Date(r.createdAt).getTime()),n=new Map;for(const r of e)n.has(r.agentId)||n.set(r.agentId,r);return Array.from(n.values()).filter(r=>mqe.has(r.status))}function FU(t){return t?t.split(`
@@ -897,4 +897,4 @@ Before you do anything, please respond to your user that you understand the inst
897
897
 
898
898
  Then after you've connected to Paperclip (exchanged keys etc.) you MUST review and follow the onboarding instructions in onboarding.txt they give you.
899
899
 
900
- `}function _qe(t){const e=(t.connectionCandidates??[]).map(i=>i.trim()).filter(Boolean),n=new Set;let r=null;try{r=new URL(t.onboardingTextUrl),n.add(r.toString())}catch{const i=t.onboardingTextUrl.trim();i&&n.add(i)}if(!r){for(const i of e)n.add(i);return Array.from(n)}const s=`${r.pathname}${r.search}`;for(const i of e)try{const o=new URL(i);n.add(`${o.origin}${s}`)}catch{n.add(i)}return Array.from(n)}function Nqe(t){var n;const e=(n=t.testResolutionUrl)==null?void 0:n.trim();if(e)return e;try{const r=new URL(t.onboardingTextUrl),s=r.pathname.replace(/\/onboarding\.txt$/,"/test-resolution");return`${r.origin}${s}`}catch{return null}}const Eqe=HM("inline-flex items-center justify-center rounded-full border border-transparent px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",{variants:{variant:{default:"bg-primary text-primary-foreground [a&]:hover:bg-primary/90",secondary:"bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",destructive:"bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",ghost:"[a&]:hover:bg-accent [a&]:hover:text-accent-foreground",link:"text-primary underline-offset-4 [a&]:hover:underline"}},defaultVariants:{variant:"default"}});function wd({className:t,variant:e="default",asChild:n=!1,...r}){const s=n?UM:"span";return l.jsx(s,{"data-slot":"badge","data-variant":e,className:re(Eqe({variant:e}),t),...r})}function md({className:t,...e}){return l.jsx(Cge,{"data-slot":"label",className:re("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",t),...e})}function jqe({filters:t,onRemove:e,onClear:n}){return t.length===0?null:l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.map(r=>l.jsxs(wd,{variant:"secondary",className:"gap-1 pr-1",children:[l.jsxs("span",{className:"text-muted-foreground",children:[r.label,":"]}),l.jsx("span",{children:r.value}),l.jsx("button",{className:"ml-1 rounded-full hover:bg-accent p-0.5",onClick:()=>e(r.key),children:l.jsx(ii,{className:"h-3 w-3"})})]},r.key)),l.jsx(ke,{variant:"ghost",size:"sm",className:"text-xs h-6",onClick:n,children:"Clear all"})]})}function mn({title:t,children:e}){return l.jsxs("section",{className:"space-y-4",children:[l.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:t}),l.jsx(Yi,{}),e]})}function pn({title:t,children:e}){return l.jsxs("div",{className:"space-y-3",children:[l.jsx("h4",{className:"text-sm font-medium",children:t}),e]})}function hs({name:t,cssVar:e}){return l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("div",{className:"h-8 w-8 rounded-md border border-border shrink-0",style:{backgroundColor:`var(${e})`}}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs font-mono",children:e}),l.jsx("p",{className:"text-xs text-muted-foreground",children:t})]})]})}function Aqe(){const[t,e]=v.useState("todo"),[n,r]=v.useState("medium"),[s,i]=v.useState("in_progress"),[o,a]=v.useState(!0),[c,d]=v.useState(!1),[f,m]=v.useState("Click to edit this text"),[p,x]=v.useState("Editable Title"),[y,w]=v.useState("This is an editable description. Click to edit it — the textarea auto-sizes to fit the content without layout shift."),[k,S]=v.useState([{key:"status",label:"Status",value:"Active"},{key:"priority",label:"Priority",value:"High"}]);return l.jsxs("div",{className:"space-y-10 max-w-4xl",children:[l.jsxs("div",{children:[l.jsx("h2",{className:"text-xl font-bold",children:"Design Guide"}),l.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Every component, style, and pattern used across Paperclip."})]}),l.jsxs(mn,{title:"Component Coverage",children:[l.jsx("p",{className:"text-sm text-muted-foreground",children:"This page should be updated when new UI primitives or app-level patterns ship."}),l.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[l.jsx(pn,{title:"UI primitives",children:l.jsx("div",{className:"flex flex-wrap gap-2",children:["avatar","badge","breadcrumb","button","card","checkbox","collapsible","command","dialog","dropdown-menu","input","label","popover","scroll-area","select","separator","sheet","skeleton","tabs","textarea","tooltip"].map(C=>l.jsx(wd,{variant:"outline",className:"font-mono text-[10px]",children:C},C))})}),l.jsx(pn,{title:"App components",children:l.jsx("div",{className:"flex flex-wrap gap-2",children:["StatusBadge","StatusIcon","PriorityIcon","EntityRow","EmptyState","MetricCard","FilterBar","InlineEditor","PageSkeleton","Identity","CommentThread","MarkdownEditor","PropertiesPanel","Sidebar","CommandPalette"].map(C=>l.jsx(wd,{variant:"ghost",className:"font-mono text-[10px]",children:C},C))})})]})]}),l.jsxs(mn,{title:"Colors",children:[l.jsx(pn,{title:"Core",children:l.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[l.jsx(hs,{name:"Background",cssVar:"--background"}),l.jsx(hs,{name:"Foreground",cssVar:"--foreground"}),l.jsx(hs,{name:"Card",cssVar:"--card"}),l.jsx(hs,{name:"Primary",cssVar:"--primary"}),l.jsx(hs,{name:"Primary foreground",cssVar:"--primary-foreground"}),l.jsx(hs,{name:"Secondary",cssVar:"--secondary"}),l.jsx(hs,{name:"Muted",cssVar:"--muted"}),l.jsx(hs,{name:"Muted foreground",cssVar:"--muted-foreground"}),l.jsx(hs,{name:"Accent",cssVar:"--accent"}),l.jsx(hs,{name:"Destructive",cssVar:"--destructive"}),l.jsx(hs,{name:"Border",cssVar:"--border"}),l.jsx(hs,{name:"Ring",cssVar:"--ring"})]})}),l.jsx(pn,{title:"Sidebar",children:l.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[l.jsx(hs,{name:"Sidebar",cssVar:"--sidebar"}),l.jsx(hs,{name:"Sidebar border",cssVar:"--sidebar-border"})]})}),l.jsx(pn,{title:"Chart",children:l.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[l.jsx(hs,{name:"Chart 1",cssVar:"--chart-1"}),l.jsx(hs,{name:"Chart 2",cssVar:"--chart-2"}),l.jsx(hs,{name:"Chart 3",cssVar:"--chart-3"}),l.jsx(hs,{name:"Chart 4",cssVar:"--chart-4"}),l.jsx(hs,{name:"Chart 5",cssVar:"--chart-5"})]})})]}),l.jsx(mn,{title:"Typography",children:l.jsxs("div",{className:"space-y-3",children:[l.jsx("h2",{className:"text-xl font-bold",children:"Page Title — text-xl font-bold"}),l.jsx("h2",{className:"text-lg font-semibold",children:"Section Title — text-lg font-semibold"}),l.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Section Heading — text-sm font-semibold uppercase tracking-wide"}),l.jsx("p",{className:"text-sm font-medium",children:"Card Title — text-sm font-medium"}),l.jsx("p",{className:"text-sm font-semibold",children:"Card Title Alt — text-sm font-semibold"}),l.jsx("p",{className:"text-sm",children:"Body text — text-sm"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Muted description — text-sm text-muted-foreground"}),l.jsx("p",{className:"text-xs text-muted-foreground",children:"Tiny label — text-xs text-muted-foreground"}),l.jsx("p",{className:"text-sm font-mono text-muted-foreground",children:"Mono identifier — text-sm font-mono text-muted-foreground"}),l.jsx("p",{className:"text-2xl font-bold",children:"Large stat — text-2xl font-bold"}),l.jsx("p",{className:"font-mono text-xs",children:"Log/code text — font-mono text-xs"})]})}),l.jsx(mn,{title:"Radius",children:l.jsx("div",{className:"flex items-end gap-4 flex-wrap",children:[["sm","var(--radius-sm)"],["md","var(--radius-md)"],["lg","var(--radius-lg)"],["xl","var(--radius-xl)"],["full","9999px"]].map(([C,_])=>l.jsxs("div",{className:"flex flex-col items-center gap-1",children:[l.jsx("div",{className:"h-12 w-12 bg-primary",style:{borderRadius:_}}),l.jsx("span",{className:"text-xs text-muted-foreground",children:C})]},C))})}),l.jsxs(mn,{title:"Buttons",children:[l.jsx(pn,{title:"Variants",children:l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l.jsx(ke,{variant:"default",children:"Default"}),l.jsx(ke,{variant:"secondary",children:"Secondary"}),l.jsx(ke,{variant:"outline",children:"Outline"}),l.jsx(ke,{variant:"ghost",children:"Ghost"}),l.jsx(ke,{variant:"destructive",children:"Destructive"}),l.jsx(ke,{variant:"link",children:"Link"})]})}),l.jsx(pn,{title:"Sizes",children:l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l.jsx(ke,{size:"xs",children:"Extra Small"}),l.jsx(ke,{size:"sm",children:"Small"}),l.jsx(ke,{size:"default",children:"Default"}),l.jsx(ke,{size:"lg",children:"Large"})]})}),l.jsx(pn,{title:"Icon buttons",children:l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l.jsx(ke,{variant:"ghost",size:"icon-xs",children:l.jsx(Gc,{})}),l.jsx(ke,{variant:"ghost",size:"icon-sm",children:l.jsx(Gc,{})}),l.jsx(ke,{variant:"outline",size:"icon",children:l.jsx(Gc,{})}),l.jsx(ke,{variant:"outline",size:"icon-lg",children:l.jsx(Gc,{})})]})}),l.jsx(pn,{title:"With icons",children:l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l.jsxs(ke,{children:[l.jsx(Pr,{})," New Issue"]}),l.jsxs(ke,{variant:"outline",children:[l.jsx(qP,{})," Upload"]}),l.jsxs(ke,{variant:"destructive",children:[l.jsx(lu,{})," Delete"]}),l.jsxs(ke,{size:"sm",children:[l.jsx(Pr,{})," Add"]})]})}),l.jsx(pn,{title:"States",children:l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l.jsx(ke,{disabled:!0,children:"Disabled"}),l.jsx(ke,{variant:"outline",disabled:!0,children:"Disabled Outline"})]})})]}),l.jsx(mn,{title:"Badges",children:l.jsx(pn,{title:"Variants",children:l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l.jsx(wd,{variant:"default",children:"Default"}),l.jsx(wd,{variant:"secondary",children:"Secondary"}),l.jsx(wd,{variant:"outline",children:"Outline"}),l.jsx(wd,{variant:"destructive",children:"Destructive"}),l.jsx(wd,{variant:"ghost",children:"Ghost"})]})})}),l.jsxs(mn,{title:"Status System",children:[l.jsx(pn,{title:"StatusBadge (all statuses)",children:l.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:["active","running","paused","idle","archived","planned","achieved","completed","failed","timed_out","succeeded","error","pending_approval","backlog","todo","in_progress","in_review","blocked","done","terminated","cancelled","pending","revision_requested","approved","rejected"].map(C=>l.jsx(Fn,{status:C},C))})}),l.jsxs(pn,{title:"StatusIcon (interactive)",children:[l.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:["backlog","todo","in_progress","in_review","done","cancelled","blocked"].map(C=>l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(qr,{status:C}),l.jsx("span",{className:"text-xs text-muted-foreground",children:C})]},C))}),l.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[l.jsx(qr,{status:t,onChange:e}),l.jsxs("span",{className:"text-sm",children:["Click the icon to change status (current: ",t,")"]})]})]}),l.jsxs(pn,{title:"PriorityIcon (interactive)",children:[l.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:["critical","high","medium","low"].map(C=>l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(Ss,{priority:C}),l.jsx("span",{className:"text-xs text-muted-foreground",children:C})]},C))}),l.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[l.jsx(Ss,{priority:n,onChange:r}),l.jsxs("span",{className:"text-sm",children:["Click the icon to change (current: ",n,")"]})]})]}),l.jsx(pn,{title:"Agent status dots",children:l.jsx("div",{className:"flex items-center gap-4 flex-wrap",children:["running","active","paused","error","archived"].map(C=>l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"relative flex h-2.5 w-2.5",children:l.jsx("span",{className:`inline-flex h-full w-full rounded-full ${r_[C]??s_}`})}),l.jsx("span",{className:"text-xs text-muted-foreground",children:C})]},C))})}),l.jsx(pn,{title:"Run invocation badges",children:l.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:[["timer","bg-blue-100 text-blue-700 dark:bg-blue-900/50 dark:text-blue-300"],["assignment","bg-violet-100 text-violet-700 dark:bg-violet-900/50 dark:text-violet-300"],["on_demand","bg-cyan-100 text-cyan-700 dark:bg-cyan-900/50 dark:text-cyan-300"],["automation","bg-muted text-muted-foreground"]].map(([C,_])=>l.jsx("span",{className:`rounded-full px-1.5 py-0.5 text-[10px] font-medium ${_}`,children:C},C))})})]}),l.jsx(mn,{title:"Form Elements",children:l.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[l.jsxs(pn,{title:"Input",children:[l.jsx(Jc,{placeholder:"Default input"}),l.jsx(Jc,{placeholder:"Disabled input",disabled:!0,className:"mt-2"})]}),l.jsx(pn,{title:"Textarea",children:l.jsx(dy,{placeholder:"Write something..."})}),l.jsx(pn,{title:"Checkbox & Label",children:l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(ch,{id:"check1",defaultChecked:!0}),l.jsx(md,{htmlFor:"check1",children:"Checked item"})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(ch,{id:"check2"}),l.jsx(md,{htmlFor:"check2",children:"Unchecked item"})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(ch,{id:"check3",disabled:!0}),l.jsx(md,{htmlFor:"check3",children:"Disabled item"})]})]})}),l.jsx(pn,{title:"Inline Editor",children:l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Title (single-line)"}),l.jsx(du,{value:p,onSave:x,as:"h2",className:"text-xl font-bold"})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Body text (single-line)"}),l.jsx(du,{value:f,onSave:m,as:"p",className:"text-sm"})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Description (multiline, auto-sizing)"}),l.jsx(du,{value:y,onSave:w,as:"p",className:"text-sm text-muted-foreground",placeholder:"Add a description...",multiline:!0})]})]})})]})}),l.jsx(mn,{title:"Select",children:l.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[l.jsxs(pn,{title:"Default size",children:[l.jsxs(Lb,{value:s,onValueChange:i,children:[l.jsx(Fb,{className:"w-full",children:l.jsx(Pb,{placeholder:"Select status"})}),l.jsxs($b,{children:[l.jsx(Hr,{value:"backlog",children:"Backlog"}),l.jsx(Hr,{value:"todo",children:"Todo"}),l.jsx(Hr,{value:"in_progress",children:"In Progress"}),l.jsx(Hr,{value:"in_review",children:"In Review"}),l.jsx(Hr,{value:"done",children:"Done"})]})]}),l.jsxs("p",{className:"text-xs text-muted-foreground",children:["Current value: ",s]})]}),l.jsx(pn,{title:"Small trigger",children:l.jsxs(Lb,{defaultValue:"high",children:[l.jsx(Fb,{size:"sm",className:"w-full",children:l.jsx(Pb,{})}),l.jsxs($b,{children:[l.jsx(Hr,{value:"critical",children:"Critical"}),l.jsx(Hr,{value:"high",children:"High"}),l.jsx(Hr,{value:"medium",children:"Medium"}),l.jsx(Hr,{value:"low",children:"Low"})]})]})})]})}),l.jsx(mn,{title:"Dropdown Menu",children:l.jsxs(qie,{children:[l.jsx(Kie,{asChild:!0,children:l.jsxs(ke,{variant:"outline",size:"sm",children:["Quick Actions",l.jsx(ga,{className:"h-4 w-4"})]})}),l.jsxs(Wie,{align:"start",className:"w-56",children:[l.jsxs(Oy,{children:[l.jsx(fa,{className:"h-4 w-4"}),"Mark as done",l.jsx(bBe,{children:"⌘D"})]}),l.jsxs(Oy,{children:[l.jsx(UT,{className:"h-4 w-4"}),"Open docs"]}),l.jsx(Gie,{}),l.jsx(yBe,{checked:o,onCheckedChange:C=>a(C===!0),children:"Watch issue"}),l.jsxs(Oy,{variant:"destructive",children:[l.jsx(lu,{className:"h-4 w-4"}),"Delete issue"]})]})]})}),l.jsx(mn,{title:"Popover",children:l.jsxs(Bn,{children:[l.jsx(zn,{asChild:!0,children:l.jsx(ke,{variant:"outline",size:"sm",children:"Open Popover"})}),l.jsxs(Vn,{className:"space-y-2",children:[l.jsx("p",{className:"text-sm font-medium",children:"Agent heartbeat"}),l.jsx("p",{className:"text-xs text-muted-foreground",children:"Last run succeeded 24s ago. Next timer run in 9m."}),l.jsx(ke,{size:"xs",children:"Wake now"})]})]})}),l.jsx(mn,{title:"Collapsible",children:l.jsxs(Mg,{open:c,onOpenChange:d,className:"space-y-2",children:[l.jsx(Rg,{asChild:!0,children:l.jsxs(ke,{variant:"outline",size:"sm",children:[c?"Hide":"Show"," advanced filters"]})}),l.jsx(Og,{className:"rounded-md border border-border p-3",children:l.jsxs("div",{className:"space-y-2",children:[l.jsx(md,{htmlFor:"owner-filter",children:"Owner"}),l.jsx(Jc,{id:"owner-filter",placeholder:"Filter by agent name"})]})})]})}),l.jsx(mn,{title:"Sheet",children:l.jsxs(x6,{children:[l.jsx(vUe,{asChild:!0,children:l.jsx(ke,{variant:"outline",size:"sm",children:"Open Side Panel"})}),l.jsxs(y6,{side:"right",children:[l.jsxs(b6,{children:[l.jsx(v6,{children:"Issue Properties"}),l.jsx(SUe,{children:"Edit metadata without leaving the current page."})]}),l.jsxs("div",{className:"space-y-4 px-4",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsx(md,{htmlFor:"sheet-title",children:"Title"}),l.jsx(Jc,{id:"sheet-title",defaultValue:"Improve onboarding docs"})]}),l.jsxs("div",{className:"space-y-1",children:[l.jsx(md,{htmlFor:"sheet-description",children:"Description"}),l.jsx(dy,{id:"sheet-description",defaultValue:"Capture setup pitfalls and screenshots."})]})]}),l.jsxs(kUe,{children:[l.jsx(ke,{variant:"outline",children:"Cancel"}),l.jsx(ke,{children:"Save"})]})]})]})}),l.jsx(mn,{title:"Scroll Area",children:l.jsx(t_,{className:"h-36 rounded-md border border-border",children:l.jsx("div",{className:"space-y-2 p-3",children:Array.from({length:12}).map((C,_)=>l.jsxs("div",{className:"rounded-md border border-border p-2 text-sm",children:["Heartbeat run #",_+1,": completed successfully"]},_))})})}),l.jsx(mn,{title:"Command (CMDK)",children:l.jsx("div",{className:"rounded-md border border-border",children:l.jsxs(_Z,{children:[l.jsx(NZ,{placeholder:"Type a command or search..."}),l.jsxs(EZ,{children:[l.jsx(jZ,{children:"No results found."}),l.jsxs(Qf,{heading:"Pages",children:[l.jsxs(ks,{children:[l.jsx(vh,{className:"h-4 w-4"}),"Dashboard"]}),l.jsxs(ks,{children:[l.jsx(Qi,{className:"h-4 w-4"}),"Issues"]})]}),l.jsx(ny,{}),l.jsxs(Qf,{heading:"Actions",children:[l.jsxs(ks,{children:[l.jsx(cve,{className:"h-4 w-4"}),"Open command palette"]}),l.jsxs(ks,{children:[l.jsx(Pr,{className:"h-4 w-4"}),"Create new issue"]})]})]})]})})}),l.jsx(mn,{title:"Breadcrumb",children:l.jsx(dZ,{children:l.jsxs(fZ,{children:[l.jsx(jC,{children:l.jsx(QT,{href:"#",children:"Projects"})}),l.jsx(XT,{}),l.jsx(jC,{children:l.jsx(QT,{href:"#",children:"Paperclip App"})}),l.jsx(XT,{}),l.jsx(jC,{children:l.jsx(hZ,{children:"Issue List"})})]})})}),l.jsxs(mn,{title:"Cards",children:[l.jsx(pn,{title:"Standard Card",children:l.jsxs(n2,{children:[l.jsxs(rqe,{children:[l.jsx(sqe,{children:"Card Title"}),l.jsx(iqe,{children:"Card description with supporting text."})]}),l.jsx(r2,{children:l.jsx("p",{className:"text-sm",children:"Card content goes here. This is the main body area."})}),l.jsxs(oqe,{className:"gap-2",children:[l.jsx(ke,{size:"sm",children:"Action"}),l.jsx(ke,{variant:"outline",size:"sm",children:"Cancel"})]})]})}),l.jsx(pn,{title:"Metric Cards",children:l.jsxs("div",{className:"grid md:grid-cols-2 xl:grid-cols-4 gap-4",children:[l.jsx(Hd,{icon:Si,value:12,label:"Active Agents",description:"+3 this week"}),l.jsx(Hd,{icon:Qi,value:48,label:"Open Issues"}),l.jsx(Hd,{icon:Ph,value:"$1,234",label:"Monthly Cost",description:"Under budget"}),l.jsx(Hd,{icon:KT,value:"99.9%",label:"Uptime"})]})})]}),l.jsxs(mn,{title:"Tabs",children:[l.jsx(pn,{title:"Default (pill) variant",children:l.jsxs(om,{defaultValue:"overview",children:[l.jsxs(Ib,{children:[l.jsx(ko,{value:"overview",children:"Overview"}),l.jsx(ko,{value:"runs",children:"Runs"}),l.jsx(ko,{value:"config",children:"Config"}),l.jsx(ko,{value:"costs",children:"Costs"})]}),l.jsx(ea,{value:"overview",children:l.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Overview tab content."})}),l.jsx(ea,{value:"runs",children:l.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Runs tab content."})}),l.jsx(ea,{value:"config",children:l.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Config tab content."})}),l.jsx(ea,{value:"costs",children:l.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Costs tab content."})})]})}),l.jsx(pn,{title:"Line variant",children:l.jsxs(om,{defaultValue:"summary",children:[l.jsxs(Ib,{variant:"line",children:[l.jsx(ko,{value:"summary",children:"Summary"}),l.jsx(ko,{value:"details",children:"Details"}),l.jsx(ko,{value:"comments",children:"Comments"})]}),l.jsx(ea,{value:"summary",children:l.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Summary content with underline tabs."})}),l.jsx(ea,{value:"details",children:l.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Details content."})}),l.jsx(ea,{value:"comments",children:l.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Comments content."})})]})})]}),l.jsx(mn,{title:"Entity Rows",children:l.jsxs("div",{className:"border border-border rounded-md",children:[l.jsx(Al,{leading:l.jsxs(l.Fragment,{children:[l.jsx(qr,{status:"in_progress"}),l.jsx(Ss,{priority:"high"})]}),identifier:"PAP-001",title:"Implement authentication flow",subtitle:"Assigned to Agent Alpha",trailing:l.jsx(Fn,{status:"in_progress"}),onClick:()=>{}}),l.jsx(Al,{leading:l.jsxs(l.Fragment,{children:[l.jsx(qr,{status:"done"}),l.jsx(Ss,{priority:"medium"})]}),identifier:"PAP-002",title:"Set up CI/CD pipeline",subtitle:"Completed 2 days ago",trailing:l.jsx(Fn,{status:"done"}),onClick:()=>{}}),l.jsx(Al,{leading:l.jsxs(l.Fragment,{children:[l.jsx(qr,{status:"todo"}),l.jsx(Ss,{priority:"low"})]}),identifier:"PAP-003",title:"Write API documentation",trailing:l.jsx(Fn,{status:"todo"}),onClick:()=>{}}),l.jsx(Al,{leading:l.jsxs(l.Fragment,{children:[l.jsx(qr,{status:"blocked"}),l.jsx(Ss,{priority:"critical"})]}),identifier:"PAP-004",title:"Deploy to production",subtitle:"Blocked by PAP-001",trailing:l.jsx(Fn,{status:"blocked"}),selected:!0})]})}),l.jsxs(mn,{title:"Filter Bar",children:[l.jsx(jqe,{filters:k,onRemove:C=>S(_=>_.filter(E=>E.key!==C)),onClear:()=>S([])}),k.length===0&&l.jsx(ke,{variant:"outline",size:"sm",onClick:()=>S([{key:"status",label:"Status",value:"Active"},{key:"priority",label:"Priority",value:"High"}]),children:"Reset filters"})]}),l.jsxs(mn,{title:"Avatars",children:[l.jsx(pn,{title:"Sizes",children:l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx(xd,{size:"sm",children:l.jsx(yd,{children:"SM"})}),l.jsx(xd,{children:l.jsx(yd,{children:"DF"})}),l.jsx(xd,{size:"lg",children:l.jsx(yd,{children:"LG"})})]})}),l.jsx(pn,{title:"Group",children:l.jsxs(oke,{children:[l.jsx(xd,{children:l.jsx(yd,{children:"A1"})}),l.jsx(xd,{children:l.jsx(yd,{children:"A2"})}),l.jsx(xd,{children:l.jsx(yd,{children:"A3"})}),l.jsx(ake,{children:"+5"})]})})]}),l.jsxs(mn,{title:"Identity",children:[l.jsx(pn,{title:"Sizes",children:l.jsxs("div",{className:"flex items-center gap-6",children:[l.jsx(Sn,{name:"Agent Alpha",size:"sm"}),l.jsx(Sn,{name:"Agent Alpha"}),l.jsx(Sn,{name:"Agent Alpha",size:"lg"})]})}),l.jsx(pn,{title:"Initials derivation",children:l.jsxs("div",{className:"flex flex-col gap-2",children:[l.jsx(Sn,{name:"CEO Agent",size:"sm"}),l.jsx(Sn,{name:"Alpha",size:"sm"}),l.jsx(Sn,{name:"Quality Assurance Lead",size:"sm"})]})}),l.jsx(pn,{title:"Custom initials",children:l.jsx(Sn,{name:"Backend Service",initials:"BS",size:"sm"})})]}),l.jsx(mn,{title:"Tooltips",children:l.jsxs("div",{className:"flex items-center gap-4",children:[l.jsxs(jg,{children:[l.jsx(Ag,{asChild:!0,children:l.jsx(ke,{variant:"outline",size:"sm",children:"Hover me"})}),l.jsx(Tg,{children:"This is a tooltip"})]}),l.jsxs(jg,{children:[l.jsx(Ag,{asChild:!0,children:l.jsx(ke,{variant:"ghost",size:"icon-sm",children:l.jsx(Eg,{})})}),l.jsx(Tg,{children:"Settings"})]})]})}),l.jsx(mn,{title:"Dialog",children:l.jsxs(bf,{children:[l.jsx(tke,{asChild:!0,children:l.jsx(ke,{variant:"outline",children:"Open Dialog"})}),l.jsxs(mm,{children:[l.jsxs(wO,{children:[l.jsx(CO,{children:"Dialog Title"}),l.jsx(kO,{children:"This is a sample dialog showing the standard layout with header, content, and footer."})]}),l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{children:[l.jsx(md,{children:"Name"}),l.jsx(Jc,{placeholder:"Enter a name",className:"mt-1.5"})]}),l.jsxs("div",{children:[l.jsx(md,{children:"Description"}),l.jsx(dy,{placeholder:"Describe...",className:"mt-1.5"})]})]}),l.jsxs(rke,{children:[l.jsx(ke,{variant:"outline",children:"Cancel"}),l.jsx(ke,{children:"Save"})]})]})]})}),l.jsx(mn,{title:"Empty State",children:l.jsx("div",{className:"border border-border rounded-md",children:l.jsx(Os,{icon:Fh,message:"No items to show. Create your first one to get started.",action:"Create Item",onAction:()=>{}})})}),l.jsx(mn,{title:"Progress Bars (Budget)",children:l.jsx("div",{className:"space-y-3",children:[{label:"Under budget (40%)",pct:40,color:"bg-green-400"},{label:"Warning (75%)",pct:75,color:"bg-yellow-400"},{label:"Over budget (95%)",pct:95,color:"bg-red-400"}].map(({label:C,pct:_,color:E})=>l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:C}),l.jsxs("span",{className:"text-xs font-mono",children:[_,"%"]})]}),l.jsx("div",{className:"w-full h-2 bg-muted rounded-full overflow-hidden",children:l.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-150 ${E}`,style:{width:`${_}%`}})})]},C))})}),l.jsx(mn,{title:"Log Viewer",children:l.jsxs("div",{className:"bg-neutral-950 rounded-lg p-3 font-mono text-xs max-h-80 overflow-y-auto",children:[l.jsx("div",{className:"text-foreground",children:"[12:00:01] INFO Agent started successfully"}),l.jsx("div",{className:"text-foreground",children:"[12:00:02] INFO Processing task PAP-001"}),l.jsx("div",{className:"text-yellow-400",children:"[12:00:05] WARN Rate limit approaching (80%)"}),l.jsx("div",{className:"text-foreground",children:"[12:00:08] INFO Task PAP-001 completed"}),l.jsx("div",{className:"text-red-400",children:"[12:00:12] ERROR Connection timeout to upstream service"}),l.jsx("div",{className:"text-blue-300",children:"[12:00:12] SYS Retrying connection in 5s..."}),l.jsx("div",{className:"text-foreground",children:"[12:00:17] INFO Reconnected successfully"}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[l.jsx("span",{className:"absolute inline-flex h-full w-full rounded-full bg-cyan-400 animate-ping"}),l.jsx("span",{className:"inline-flex h-full w-full rounded-full bg-cyan-400"})]}),l.jsx("span",{className:"text-cyan-400",children:"Live"})]})]})}),l.jsx(mn,{title:"Property Row Pattern",children:l.jsxs("div",{className:"border border-border rounded-md p-4 space-y-1 max-w-sm",children:[l.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Status"}),l.jsx(Fn,{status:"active"})]}),l.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Priority"}),l.jsx(Ss,{priority:"high"})]}),l.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Assignee"}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(xd,{size:"sm",children:l.jsx(yd,{children:"A"})}),l.jsx("span",{className:"text-xs",children:"Agent Alpha"})]})]}),l.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Created"}),l.jsx("span",{className:"text-xs",children:"Jan 15, 2025"})]})]})}),l.jsxs(mn,{title:"Navigation Patterns",children:[l.jsx(pn,{title:"Sidebar nav items",children:l.jsxs("div",{className:"w-60 border border-border rounded-md p-3 space-y-0.5 bg-card",children:[l.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium bg-accent text-accent-foreground",children:[l.jsx(vh,{className:"h-4 w-4"}),"Dashboard"]}),l.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground cursor-pointer",children:[l.jsx(Qi,{className:"h-4 w-4"}),"Issues",l.jsx("span",{className:"ml-auto text-xs bg-primary text-primary-foreground rounded-full px-1.5 py-0.5",children:"12"})]}),l.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground cursor-pointer",children:[l.jsx(Si,{className:"h-4 w-4"}),"Agents"]}),l.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground cursor-pointer",children:[l.jsx(Jl,{className:"h-4 w-4"}),"Projects"]})]})}),l.jsx(pn,{title:"View toggle",children:l.jsxs("div",{className:"flex items-center border border-border rounded-md w-fit",children:[l.jsxs("button",{className:"px-3 py-1.5 text-xs font-medium bg-accent text-foreground rounded-l-md",children:[l.jsx(O2,{className:"h-3.5 w-3.5 inline mr-1"}),"List"]}),l.jsxs("button",{className:"px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-accent/50 rounded-r-md",children:[l.jsx(Yl,{className:"h-3.5 w-3.5 inline mr-1"}),"Org"]})]})})]}),l.jsx(mn,{title:"Grouped List (Issues pattern)",children:l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-muted/50 rounded-t-md",children:[l.jsx(qr,{status:"in_progress"}),l.jsx("span",{className:"text-sm font-medium",children:"In Progress"}),l.jsx("span",{className:"text-xs text-muted-foreground ml-1",children:"2"})]}),l.jsxs("div",{className:"border border-border rounded-b-md",children:[l.jsx(Al,{leading:l.jsx(Ss,{priority:"high"}),identifier:"PAP-101",title:"Build agent heartbeat system",onClick:()=>{}}),l.jsx(Al,{leading:l.jsx(Ss,{priority:"medium"}),identifier:"PAP-102",title:"Add cost tracking dashboard",onClick:()=>{}})]})]})}),l.jsx(mn,{title:"Comment Thread Pattern",children:l.jsxs("div",{className:"space-y-3 max-w-2xl",children:[l.jsx("h3",{className:"text-sm font-semibold",children:"Comments (2)"}),l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"rounded-md border border-border p-3",children:[l.jsxs("div",{className:"flex items-center justify-between mb-1",children:[l.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Agent"}),l.jsx("span",{className:"text-xs text-muted-foreground",children:"Jan 15, 2025"})]}),l.jsx("p",{className:"text-sm",children:"Started working on the authentication module. Will need API keys configured."})]}),l.jsxs("div",{className:"rounded-md border border-border p-3",children:[l.jsxs("div",{className:"flex items-center justify-between mb-1",children:[l.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Human"}),l.jsx("span",{className:"text-xs text-muted-foreground",children:"Jan 16, 2025"})]}),l.jsx("p",{className:"text-sm",children:"API keys have been added to the vault. Please proceed."})]})]}),l.jsxs("div",{className:"space-y-2",children:[l.jsx(dy,{placeholder:"Leave a comment...",rows:3}),l.jsx(ke,{size:"sm",children:"Comment"})]})]})}),l.jsx(mn,{title:"Cost Table Pattern",children:l.jsx("div",{className:"border border-border rounded-lg overflow-hidden",children:l.jsxs("table",{className:"w-full text-xs",children:[l.jsx("thead",{className:"border-b border-border bg-accent/20",children:l.jsxs("tr",{children:[l.jsx("th",{className:"text-left px-3 py-2 font-medium text-muted-foreground",children:"Model"}),l.jsx("th",{className:"text-left px-3 py-2 font-medium text-muted-foreground",children:"Tokens"}),l.jsx("th",{className:"text-left px-3 py-2 font-medium text-muted-foreground",children:"Cost"})]})}),l.jsxs("tbody",{children:[l.jsxs("tr",{className:"border-b border-border",children:[l.jsx("td",{className:"px-3 py-2",children:"claude-sonnet-4-20250514"}),l.jsx("td",{className:"px-3 py-2 font-mono",children:"1.2M"}),l.jsx("td",{className:"px-3 py-2 font-mono",children:"$18.00"})]}),l.jsxs("tr",{className:"border-b border-border",children:[l.jsx("td",{className:"px-3 py-2",children:"claude-haiku-4-20250506"}),l.jsx("td",{className:"px-3 py-2 font-mono",children:"500k"}),l.jsx("td",{className:"px-3 py-2 font-mono",children:"$1.25"})]}),l.jsxs("tr",{children:[l.jsx("td",{className:"px-3 py-2 font-medium",children:"Total"}),l.jsx("td",{className:"px-3 py-2 font-mono",children:"1.7M"}),l.jsx("td",{className:"px-3 py-2 font-mono font-medium",children:"$19.25"})]})]})]})})}),l.jsxs(mn,{title:"Skeletons",children:[l.jsx(pn,{title:"Individual",children:l.jsxs("div",{className:"space-y-2",children:[l.jsx(Kt,{className:"h-4 w-48"}),l.jsx(Kt,{className:"h-8 w-full max-w-sm"}),l.jsx(Kt,{className:"h-20 w-full"})]})}),l.jsx(pn,{title:"Page Skeleton (list)",children:l.jsx("div",{className:"border border-border rounded-md p-4",children:l.jsx(ui,{variant:"list"})})}),l.jsx(pn,{title:"Page Skeleton (detail)",children:l.jsx("div",{className:"border border-border rounded-md p-4",children:l.jsx(ui,{variant:"detail"})})})]}),l.jsx(mn,{title:"Separator",children:l.jsxs("div",{className:"space-y-4",children:[l.jsx("p",{className:"text-sm text-muted-foreground",children:"Horizontal"}),l.jsx(Yi,{}),l.jsxs("div",{className:"flex items-center gap-4 h-8",children:[l.jsx("span",{className:"text-sm",children:"Left"}),l.jsx(Yi,{orientation:"vertical"}),l.jsx("span",{className:"text-sm",children:"Right"})]})]})}),l.jsx(mn,{title:"Common Icons (Lucide)",children:l.jsx("div",{className:"grid grid-cols-4 md:grid-cols-6 gap-4",children:[["Inbox",Fh],["ListTodo",O2],["CircleDot",Qi],["Hexagon",Jl],["Target",Yl],["LayoutDashboard",vh],["Bot",Si],["DollarSign",Ph],["History",qy],["Search",Gc],["Plus",Pr],["Trash2",lu],["Settings",Eg],["User",zp],["Mail",_Y],["Upload",qP],["Zap",KT]].map(([C,_])=>{const E=_;return l.jsxs("div",{className:"flex flex-col items-center gap-1.5 p-2",children:[l.jsx(E,{className:"h-4 w-4 text-muted-foreground"}),l.jsx("span",{className:"text-[10px] text-muted-foreground font-mono",children:C})]},C)})})}),l.jsx(mn,{title:"Keyboard Shortcuts",children:l.jsx("div",{className:"border border-border rounded-md divide-y divide-border text-sm",children:[["Cmd+K / Ctrl+K","Open Command Palette"],["C","New Issue (outside inputs)"],["[","Toggle Sidebar"],["]","Toggle Properties Panel"],["Cmd+1..9 / Ctrl+1..9","Switch Company (by rail order)"],["Cmd+Enter / Ctrl+Enter","Submit markdown comment"]].map(([C,_])=>l.jsxs("div",{className:"flex items-center justify-between px-4 py-2",children:[l.jsx("span",{className:"text-muted-foreground",children:_}),l.jsx("kbd",{className:"px-2 py-0.5 text-xs font-mono bg-muted rounded border border-border",children:C})]},C))})})]})}const uh=200,s2=100,Bb=32,Tqe=80,nS=60;function sg(t){if(t.reports.length===0)return uh;const e=t.reports.reduce((r,s)=>r+sg(s),0),n=(t.reports.length-1)*Bb;return Math.max(uh,e+n)}function Woe(t,e,n){const r=sg(t),s=[];if(t.reports.length>0){const i=t.reports.reduce((c,d)=>c+sg(d),0),o=(t.reports.length-1)*Bb;let a=e+(r-i-o)/2;for(const c of t.reports){const d=sg(c);s.push(Woe(c,a,n+s2+Tqe)),a+=d+Bb}}return{id:t.id,name:t.name,role:t.role,status:t.status,x:e+(r-uh)/2,y:n,children:s}}function Mqe(t){if(t.length===0)return[];t.reduce((s,i)=>s+sg(i),0),(t.length-1)*Bb;let e=nS;const n=nS,r=[];for(const s of t){const i=sg(s);r.push(Woe(s,e,n)),e+=i+Bb}return r}function Rqe(t){const e=[];function n(r){e.push(r),r.children.forEach(n)}return t.forEach(n),e}function Oqe(t){const e=[];function n(r){for(const s of r.children)e.push({parent:r,child:s}),n(s)}return t.forEach(n),e}const Iqe={claude_local:"Claude",codex_local:"Codex",opencode_local:"OpenCode",cursor:"Cursor",openclaw_gateway:"OpenClaw Gateway",process:"Process",http:"HTTP"},Dqe={running:"#22d3ee",active:"#4ade80",paused:"#facc15",idle:"#facc15",error:"#f87171",terminated:"#a3a3a3"},Lqe="#a3a3a3";function Pqe(){const{selectedCompanyId:t}=en(),{setBreadcrumbs:e}=bs(),n=Ti(),{data:r,isLoading:s}=Be({queryKey:te.org(t),queryFn:()=>Ot.org(t),enabled:!!t}),{data:i}=Be({queryKey:te.agents.list(t),queryFn:()=>Ot.list(t),enabled:!!t}),o=v.useMemo(()=>{const M=new Map;for(const O of i??[])M.set(O.id,O);return M},[i]);v.useEffect(()=>{e([{label:"Org Chart"}])},[e]);const a=v.useMemo(()=>Mqe(r??[]),[r]),c=v.useMemo(()=>Rqe(a),[a]),d=v.useMemo(()=>Oqe(a),[a]),f=v.useMemo(()=>{if(c.length===0)return{width:800,height:600};let M=0,O=0;for(const I of c)M=Math.max(M,I.x+uh),O=Math.max(O,I.y+s2);return{width:M+nS,height:O+nS}},[c]),m=v.useRef(null),[p,x]=v.useState({x:0,y:0}),[y,w]=v.useState(1),[k,S]=v.useState(!1),C=v.useRef({x:0,y:0,panX:0,panY:0}),_=v.useRef(!1);v.useEffect(()=>{if(_.current||c.length===0||!m.current)return;_.current=!0;const M=m.current,O=M.clientWidth,I=M.clientHeight,$=(O-40)/f.width,z=(I-40)/f.height,V=Math.min($,z,1),W=f.width*V,J=f.height*V;w(V),x({x:(O-W)/2,y:(I-J)/2})},[c,f]);const E=v.useCallback(M=>{M.button!==0||M.target.closest("[data-org-card]")||(S(!0),C.current={x:M.clientX,y:M.clientY,panX:p.x,panY:p.y})},[p]),j=v.useCallback(M=>{if(!k)return;const O=M.clientX-C.current.x,I=M.clientY-C.current.y;x({x:C.current.panX+O,y:C.current.panY+I})},[k]),R=v.useCallback(()=>{S(!1)},[]),T=v.useCallback(M=>{M.preventDefault();const O=m.current;if(!O)return;const I=O.getBoundingClientRect(),$=M.clientX-I.left,z=M.clientY-I.top,V=M.deltaY<0?1.1:.9,W=Math.min(Math.max(y*V,.2),2),J=W/y;x({x:$-J*($-p.x),y:z-J*(z-p.y)}),w(W)},[y,p]);return t?s?l.jsx(ui,{variant:"org-chart"}):r&&r.length===0?l.jsx(Os,{icon:qT,message:"No organizational hierarchy defined."}):l.jsxs("div",{ref:m,className:"w-full h-[calc(100vh-4rem)] overflow-hidden relative bg-muted/20 border border-border rounded-lg",style:{cursor:k?"grabbing":"grab"},onMouseDown:E,onMouseMove:j,onMouseUp:R,onMouseLeave:R,onWheel:T,children:[l.jsxs("div",{className:"absolute top-3 right-3 z-10 flex flex-col gap-1",children:[l.jsx("button",{className:"w-7 h-7 flex items-center justify-center bg-background border border-border rounded text-sm hover:bg-accent transition-colors",onClick:()=>{const M=Math.min(y*1.2,2),O=m.current;if(O){const I=O.clientWidth/2,$=O.clientHeight/2,z=M/y;x({x:I-z*(I-p.x),y:$-z*($-p.y)})}w(M)},"aria-label":"Zoom in",children:"+"}),l.jsx("button",{className:"w-7 h-7 flex items-center justify-center bg-background border border-border rounded text-sm hover:bg-accent transition-colors",onClick:()=>{const M=Math.max(y*.8,.2),O=m.current;if(O){const I=O.clientWidth/2,$=O.clientHeight/2,z=M/y;x({x:I-z*(I-p.x),y:$-z*($-p.y)})}w(M)},"aria-label":"Zoom out",children:"−"}),l.jsx("button",{className:"w-7 h-7 flex items-center justify-center bg-background border border-border rounded text-[10px] hover:bg-accent transition-colors",onClick:()=>{if(!m.current)return;const M=m.current.clientWidth,O=m.current.clientHeight,I=(M-40)/f.width,$=(O-40)/f.height,z=Math.min(I,$,1),V=f.width*z,W=f.height*z;w(z),x({x:(M-V)/2,y:(O-W)/2})},title:"Fit to screen","aria-label":"Fit chart to screen",children:"Fit"})]}),l.jsx("svg",{className:"absolute inset-0 pointer-events-none",style:{width:"100%",height:"100%"},children:l.jsx("g",{transform:`translate(${p.x}, ${p.y}) scale(${y})`,children:d.map(({parent:M,child:O})=>{const I=M.x+uh/2,$=M.y+s2,z=O.x+uh/2,V=O.y,W=($+V)/2;return l.jsx("path",{d:`M ${I} ${$} L ${I} ${W} L ${z} ${W} L ${z} ${V}`,fill:"none",stroke:"var(--border)",strokeWidth:1.5},`${M.id}-${O.id}`)})})}),l.jsx("div",{className:"absolute inset-0",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${y})`,transformOrigin:"0 0"},children:c.map(M=>{const O=o.get(M.id),I=Dqe[M.status]??Lqe;return l.jsx("div",{"data-org-card":!0,className:"absolute bg-card border border-border rounded-lg shadow-sm hover:shadow-md hover:border-foreground/20 transition-[box-shadow,border-color] duration-150 cursor-pointer select-none",style:{left:M.x,top:M.y,width:uh,minHeight:s2},onClick:()=>n(O?fm(O):`/agents/${M.id}`),children:l.jsxs("div",{className:"flex items-center px-4 py-3 gap-3",children:[l.jsxs("div",{className:"relative shrink-0",children:[l.jsx("div",{className:"w-9 h-9 rounded-full bg-muted flex items-center justify-center",children:l.jsx(Ql,{icon:O==null?void 0:O.icon,className:"h-4.5 w-4.5 text-foreground/70"})}),l.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 h-3 w-3 rounded-full border-2 border-card",style:{backgroundColor:I}})]}),l.jsxs("div",{className:"flex flex-col items-start min-w-0 flex-1",children:[l.jsx("span",{className:"text-sm font-semibold text-foreground leading-tight",children:M.name}),l.jsx("span",{className:"text-[11px] text-muted-foreground leading-tight mt-0.5",children:(O==null?void 0:O.title)??$qe(M.role)}),O&&l.jsx("span",{className:"text-[10px] text-muted-foreground/60 font-mono leading-tight mt-1",children:Iqe[O.adapterType]??O.adapterType})]})]})},M.id)})})]}):l.jsx(Os,{icon:qT,message:"Select a company to view the org chart."})}const Fqe=LR;function $qe(t){return Fqe[t]??t}const Bqe=new Set(["claude_local","codex_local","opencode_local","pi_local","cursor","openclaw_gateway"]);function zqe(t){const{adapterType:e,...n}=Mb,r={...n,adapterType:t};return t==="codex_local"?(r.model=Qg,r.dangerouslyBypassSandbox=Tb):t==="cursor"?r.model=Xg:t==="opencode_local"&&(r.model=""),r}function Vqe(){const{selectedCompanyId:t}=en(),{setBreadcrumbs:e}=bs(),n=Nn(),r=Ti(),[s]=Qb(),i=s.get("adapterType"),[o,a]=v.useState(""),[c,d]=v.useState(""),[f,m]=v.useState("general"),[p,x]=v.useState(""),[y,w]=v.useState(Mb),[k,S]=v.useState(!1),[C,_]=v.useState(!1),[E,j]=v.useState(null),{data:R}=Be({queryKey:te.agents.list(t),queryFn:()=>Ot.list(t),enabled:!!t}),{data:T,error:M,isLoading:O,isFetching:I}=Be({queryKey:t?te.agents.adapterModels(t,y.adapterType):["agents","none","adapter-models",y.adapterType],queryFn:()=>Ot.adapterModels(t,y.adapterType),enabled:!!t}),$=!R||R.length===0,z=$?"ceo":f;v.useEffect(()=>{e([{label:"Agents",href:"/agents"},{label:"New Agent"}])},[e]),v.useEffect(()=>{$&&(o||a("CEO"),c||d("CEO"))},[$]),v.useEffect(()=>{const F=i;F&&Bqe.has(F)&&w(L=>L.adapterType===F?L:zqe(F))},[i]);const V=yt({mutationFn:F=>Ot.hire(t,F),onSuccess:F=>{n.invalidateQueries({queryKey:te.agents.list(t)}),n.invalidateQueries({queryKey:te.approvals.list(t)}),r(fm(F.agent))},onError:F=>{j(F instanceof Error?F.message:"Failed to create agent")}});function W(){return im(y.adapterType).buildAdapterConfig(y)}function J(){if(!(!t||!o.trim())){if(j(null),y.adapterType==="opencode_local"){const F=y.model.trim();if(!F){j("OpenCode requires an explicit model in provider/model format.");return}if(M){j(M instanceof Error?M.message:"Failed to load OpenCode models.");return}if(O||I){j("OpenCode models are still loading. Please wait and try again.");return}const L=T??[];if(!L.some(K=>K.id===F)){j(L.length===0?"No OpenCode models discovered. Run `opencode models` and authenticate providers.":`Configured OpenCode model is unavailable: ${F}`);return}}V.mutate({name:o.trim(),role:z,...c.trim()?{title:c.trim()}:{},...p?{reportsTo:p}:{},adapterType:y.adapterType,adapterConfig:W(),runtimeConfig:{heartbeat:{enabled:y.heartbeatEnabled,intervalSec:y.intervalSec,wakeOnDemand:!0,cooldownSec:10,maxConcurrentRuns:1}},budgetMonthlyCents:0})}}const G=(R??[]).find(F=>F.id===p);return l.jsxs("div",{className:"mx-auto max-w-2xl space-y-6",children:[l.jsxs("div",{children:[l.jsx("h1",{className:"text-lg font-semibold",children:"New Agent"}),l.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Advanced agent configuration"})]}),l.jsxs("div",{className:"border border-border",children:[l.jsx("div",{className:"px-4 pt-4 pb-2",children:l.jsx("input",{className:"w-full text-lg font-semibold bg-transparent outline-none placeholder:text-muted-foreground/50",placeholder:"Agent name",value:o,onChange:F=>a(F.target.value),autoFocus:!0})}),l.jsx("div",{className:"px-4 pb-2",children:l.jsx("input",{className:"w-full bg-transparent outline-none text-sm text-muted-foreground placeholder:text-muted-foreground/40",placeholder:"Title (e.g. VP of Engineering)",value:c,onChange:F=>d(F.target.value)})}),l.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-2 border-t border-border flex-wrap",children:[l.jsxs(Bn,{open:k,onOpenChange:S,children:[l.jsx(zn,{asChild:!0,children:l.jsxs("button",{className:re("inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",$&&"opacity-60 cursor-not-allowed"),disabled:$,children:[l.jsx(AY,{className:"h-3 w-3 text-muted-foreground"}),Ry[z]??z]})}),l.jsx(Vn,{className:"w-36 p-1",align:"start",children:nY.map(F=>l.jsx("button",{className:re("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",F===f&&"bg-accent"),onClick:()=>{m(F),S(!1)},children:Ry[F]??F},F))})]}),l.jsxs(Bn,{open:C,onOpenChange:_,children:[l.jsx(zn,{asChild:!0,children:l.jsx("button",{className:re("inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",$&&"opacity-60 cursor-not-allowed"),disabled:$,children:G?l.jsxs(l.Fragment,{children:[l.jsx(Ql,{icon:G.icon,className:"h-3 w-3 text-muted-foreground"}),`Reports to ${G.name}`]}):l.jsxs(l.Fragment,{children:[l.jsx(zp,{className:"h-3 w-3 text-muted-foreground"}),$?"Reports to: N/A (CEO)":"Reports to..."]})})}),l.jsxs(Vn,{className:"w-48 p-1",align:"start",children:[l.jsx("button",{className:re("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",!p&&"bg-accent"),onClick:()=>{x(""),_(!1)},children:"No manager"}),(R??[]).map(F=>l.jsxs("button",{className:re("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 truncate",F.id===p&&"bg-accent"),onClick:()=>{x(F.id),_(!1)},children:[l.jsx(Ql,{icon:F.icon,className:"shrink-0 h-3 w-3 text-muted-foreground"}),F.name,l.jsx("span",{className:"text-muted-foreground ml-auto",children:Ry[F.role]??F.role})]},F.id))]})]})]}),l.jsx(eoe,{mode:"create",values:y,onChange:F=>w(L=>({...L,...F})),adapterModels:T}),l.jsxs("div",{className:"border-t border-border px-4 py-3",children:[$&&l.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"This will be the CEO"}),E&&l.jsx("p",{className:"text-xs text-destructive mb-2",children:E}),l.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l.jsx(ke,{variant:"outline",size:"sm",onClick:()=>r("/agents"),children:"Cancel"}),l.jsx(ke,{size:"sm",disabled:!o.trim()||V.isPending,onClick:J,children:V.isPending?"Creating…":"Create agent"})]})]})]})]})}function Hqe(){const t=Nn(),e=Ti(),[n]=Qb(),[r,s]=v.useState("sign_in"),[i,o]=v.useState(""),[a,c]=v.useState(""),[d,f]=v.useState(""),[m,p]=v.useState(null),x=v.useMemo(()=>n.get("next")||"/",[n]),{data:y,isLoading:w}=Be({queryKey:te.auth.session,queryFn:()=>Ua.getSession(),retry:!1});v.useEffect(()=>{y&&e(x,{replace:!0})},[y,e,x]);const k=yt({mutationFn:async()=>{if(r==="sign_in"){await Ua.signInEmail({email:a.trim(),password:d});return}await Ua.signUpEmail({name:i.trim(),email:a.trim(),password:d})},onSuccess:async()=>{p(null),await t.invalidateQueries({queryKey:te.auth.session}),await t.invalidateQueries({queryKey:te.companies.all}),e(x,{replace:!0})},onError:C=>{p(C instanceof Error?C.message:"Authentication failed")}}),S=a.trim().length>0&&d.trim().length>=8&&(r==="sign_in"||i.trim().length>0);return w?l.jsx("div",{className:"fixed inset-0 flex items-center justify-center",children:l.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading…"})}):l.jsxs("div",{className:"fixed inset-0 flex bg-background",children:[l.jsx("div",{className:"w-full md:w-1/2 flex flex-col overflow-y-auto",children:l.jsxs("div",{className:"w-full max-w-md mx-auto my-auto px-8 py-12",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-8",children:[l.jsx($h,{className:"h-4 w-4 text-muted-foreground"}),l.jsx("span",{className:"text-sm font-medium",children:"Paperclip"})]}),l.jsx("h1",{className:"text-xl font-semibold",children:r==="sign_in"?"Sign in to Paperclip":"Create your Paperclip account"}),l.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:r==="sign_in"?"Use your email and password to access this instance.":"Create an account for this instance. Email confirmation is not required in v1."}),l.jsxs("form",{className:"mt-6 space-y-4",onSubmit:C=>{C.preventDefault(),k.mutate()},children:[r==="sign_up"&&l.jsxs("div",{children:[l.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Name"}),l.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",value:i,onChange:C=>o(C.target.value),autoComplete:"name",autoFocus:!0})]}),l.jsxs("div",{children:[l.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Email"}),l.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",type:"email",value:a,onChange:C=>c(C.target.value),autoComplete:"email",autoFocus:r==="sign_in"})]}),l.jsxs("div",{children:[l.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Password"}),l.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",type:"password",value:d,onChange:C=>f(C.target.value),autoComplete:r==="sign_in"?"current-password":"new-password"})]}),m&&l.jsx("p",{className:"text-xs text-destructive",children:m}),l.jsx(ke,{type:"submit",disabled:!S||k.isPending,className:"w-full",children:k.isPending?"Working…":r==="sign_in"?"Sign In":"Create Account"})]}),l.jsxs("div",{className:"mt-5 text-sm text-muted-foreground",children:[r==="sign_in"?"Need an account?":"Already have an account?"," ",l.jsx("button",{type:"button",className:"font-medium text-foreground underline underline-offset-2",onClick:()=>{p(null),s(r==="sign_in"?"sign_up":"sign_in")},children:r==="sign_in"?"Create one":"Sign in"})]})]})}),l.jsx("div",{className:"hidden md:block w-1/2 overflow-hidden",children:l.jsx(Pie,{})})]})}function Uqe(){const t=Nn(),e=Eu(),[n]=Qb(),r=(e.token??"").trim(),s=(n.get("code")??"").trim(),i=v.useMemo(()=>`/board-claim/${encodeURIComponent(r)}${s?`?code=${encodeURIComponent(s)}`:""}`,[r,s]),o=Be({queryKey:te.auth.session,queryFn:()=>Ua.getSession(),retry:!1}),a=Be({queryKey:["board-claim",r,s],queryFn:()=>Ha.getBoardClaimStatus(r,s),enabled:r.length>0&&s.length>0,retry:!1}),c=yt({mutationFn:()=>Ha.claimBoard(r,s),onSuccess:async()=>{await t.invalidateQueries({queryKey:te.auth.session}),await t.invalidateQueries({queryKey:te.health}),await t.invalidateQueries({queryKey:te.companies.all}),await t.invalidateQueries({queryKey:te.companies.stats}),await a.refetch()}});if(!r||!s)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"Invalid board claim URL."});if(a.isLoading||o.isLoading)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading claim challenge..."});if(a.error)return l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-lg font-semibold",children:"Claim challenge unavailable"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:a.error instanceof Error?a.error.message:"Challenge is invalid or expired."})]})});const d=a.data;return d?d.status==="claimed"?l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-lg font-semibold",children:"Board ownership claimed"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"This instance is now linked to your authenticated user."}),l.jsx(ke,{asChild:!0,className:"mt-4",children:l.jsx(Bt,{to:"/",children:"Open board"})})]})}):o.data?l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-xl font-semibold",children:"Claim Board ownership"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"This will promote your user to instance admin and migrate company ownership access from local trusted mode."}),c.error&&l.jsx("p",{className:"mt-3 text-sm text-destructive",children:c.error instanceof Error?c.error.message:"Failed to claim board ownership"}),l.jsx(ke,{className:"mt-5",onClick:()=>c.mutate(),disabled:c.isPending,children:c.isPending?"Claiming…":"Claim ownership"})]})}):l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-lg font-semibold",children:"Sign in required"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Sign in or create an account, then return to this page to claim Board ownership."}),l.jsx(ke,{asChild:!0,className:"mt-4",children:l.jsx(Bt,{to:`/auth?next=${encodeURIComponent(i)}`,children:"Sign in / Create account"})})]})}):l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"Claim challenge unavailable."})}const qqe=[...HS],Kqe={claude_local:"Claude (local)",codex_local:"Codex (local)",opencode_local:"OpenCode (local)",openclaw_gateway:"OpenClaw Gateway",cursor:"Cursor (local)",process:"Process",http:"HTTP"},VU=new Set(["claude_local","codex_local","opencode_local","cursor"]);function Wqe(t){return new Date(t).toLocaleString()}function J0(t,e){let n=t;for(const r of e){if(!n||typeof n!="object")return null;n=n[r]}return typeof n=="string"&&n.trim().length>0?n:null}function Gqe(){var T;const t=Nn(),n=(Eu().token??"").trim(),[r,s]=v.useState("human"),[i,o]=v.useState(""),[a,c]=v.useState("claude_local"),[d,f]=v.useState(""),[m,p]=v.useState(null),[x,y]=v.useState(null),w=Be({queryKey:te.health,queryFn:()=>n6.get(),retry:!1}),k=Be({queryKey:te.auth.session,queryFn:()=>Ua.getSession(),retry:!1}),S=Be({queryKey:te.access.invite(n),queryFn:()=>Ha.getInvite(n),enabled:n.length>0,retry:!1}),C=S.data,_=(C==null?void 0:C.allowedJoinTypes)??"both",E=v.useMemo(()=>(C==null?void 0:C.inviteType)==="bootstrap_ceo"?["human"]:_==="both"?["human","agent"]:[_],[C==null?void 0:C.inviteType,_]);v.useEffect(()=>{E.includes(r)||s(E[0]??"human")},[E,r]);const j=r==="human"&&((T=w.data)==null?void 0:T.deploymentMode)==="authenticated"&&!k.data,R=yt({mutationFn:async()=>{if(!C)throw new Error("Invite not found");return C.inviteType==="bootstrap_ceo"?Ha.acceptInvite(n,{requestType:"human"}):r==="human"?Ha.acceptInvite(n,{requestType:"human"}):Ha.acceptInvite(n,{requestType:"agent",agentName:i.trim(),adapterType:a,capabilities:d.trim()||null})},onSuccess:async M=>{y(null),await t.invalidateQueries({queryKey:te.auth.session}),await t.invalidateQueries({queryKey:te.companies.all});const O=M&&typeof M=="object"&&"bootstrapAccepted"in M;p({kind:O?"bootstrap":"join",payload:M})},onError:M=>{y(M instanceof Error?M.message:"Failed to accept invite")}});if(!n)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"Invalid invite token."});if(S.isLoading||w.isLoading||k.isLoading)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading invite..."});if(S.error||!C)return l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-lg font-semibold",children:"Invite not available"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"This invite may be expired, revoked, or already used."})]})});if((m==null?void 0:m.kind)==="bootstrap")return l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-lg font-semibold",children:"Bootstrap complete"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"The first instance admin is now configured. You can continue to the board."}),l.jsx(ke,{asChild:!0,className:"mt-4",children:l.jsx(Bt,{to:"/",children:"Open board"})})]})});if((m==null?void 0:m.kind)==="join"){const M=m.payload,O=typeof M.claimSecret=="string"?M.claimSecret:null,I=typeof M.claimApiKeyPath=="string"?M.claimApiKeyPath:null,$=J0(M.onboarding,["skill","url"]),z=J0(M.onboarding,["skill","path"]),V=J0(M.onboarding,["skill","installPath"]),W=J0(M.onboarding,["textInstructions","url"]),J=J0(M.onboarding,["textInstructions","path"]),G=Array.isArray(M.diagnostics)?M.diagnostics:[];return l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-lg font-semibold",children:"Join request submitted"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Your request is pending admin approval. You will not have access until approved."}),l.jsxs("div",{className:"mt-4 rounded-md border border-border bg-muted/30 p-3 text-xs text-muted-foreground",children:["Request ID: ",l.jsx("span",{className:"font-mono",children:M.id})]}),O&&I&&l.jsxs("div",{className:"mt-3 space-y-1 rounded-md border border-border bg-muted/30 p-3 text-xs text-muted-foreground",children:[l.jsx("p",{className:"font-medium text-foreground",children:"One-time claim secret (save now)"}),l.jsx("p",{className:"font-mono break-all",children:O}),l.jsxs("p",{className:"font-mono break-all",children:["POST ",I]})]}),($||z||V)&&l.jsxs("div",{className:"mt-3 space-y-1 rounded-md border border-border bg-muted/30 p-3 text-xs text-muted-foreground",children:[l.jsx("p",{className:"font-medium text-foreground",children:"Paperclip skill bootstrap"}),$&&l.jsxs("p",{className:"font-mono break-all",children:["GET ",$]}),!$&&z&&l.jsxs("p",{className:"font-mono break-all",children:["GET ",z]}),V&&l.jsxs("p",{className:"font-mono break-all",children:["Install to ",V]})]}),(W||J)&&l.jsxs("div",{className:"mt-3 space-y-1 rounded-md border border-border bg-muted/30 p-3 text-xs text-muted-foreground",children:[l.jsx("p",{className:"font-medium text-foreground",children:"Agent-readable onboarding text"}),W&&l.jsxs("p",{className:"font-mono break-all",children:["GET ",W]}),!W&&J&&l.jsxs("p",{className:"font-mono break-all",children:["GET ",J]})]}),G.length>0&&l.jsxs("div",{className:"mt-3 space-y-1 rounded-md border border-border bg-muted/30 p-3 text-xs text-muted-foreground",children:[l.jsx("p",{className:"font-medium text-foreground",children:"Connectivity diagnostics"}),G.map((F,L)=>l.jsxs("div",{className:"space-y-0.5",children:[l.jsxs("p",{className:F.level==="warn"?"text-amber-600 dark:text-amber-400":void 0,children:["[",F.level,"] ",F.message]}),F.hint&&l.jsx("p",{className:"font-mono break-all",children:F.hint})]},`${F.code}:${L}`))]})]})})}return l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-xl font-semibold",children:C.inviteType==="bootstrap_ceo"?"Bootstrap your Paperclip instance":"Join this Paperclip company"}),l.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["Invite expires ",Wqe(C.expiresAt),"."]}),C.inviteType!=="bootstrap_ceo"&&l.jsx("div",{className:"mt-5 flex gap-2",children:E.map(M=>l.jsxs("button",{type:"button",onClick:()=>s(M),className:`rounded-md border px-3 py-1.5 text-sm ${r===M?"border-foreground bg-foreground text-background":"border-border bg-background text-foreground"}`,children:["Join as ",M]},M))}),r==="agent"&&C.inviteType!=="bootstrap_ceo"&&l.jsxs("div",{className:"mt-4 space-y-3",children:[l.jsxs("label",{className:"block text-sm",children:[l.jsx("span",{className:"mb-1 block text-muted-foreground",children:"Agent name"}),l.jsx("input",{className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm",value:i,onChange:M=>o(M.target.value)})]}),l.jsxs("label",{className:"block text-sm",children:[l.jsx("span",{className:"mb-1 block text-muted-foreground",children:"Adapter type"}),l.jsx("select",{className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm",value:a,onChange:M=>c(M.target.value),children:qqe.map(M=>l.jsxs("option",{value:M,disabled:!VU.has(M),children:[Kqe[M],VU.has(M)?"":" (Coming soon)"]},M))})]}),l.jsxs("label",{className:"block text-sm",children:[l.jsx("span",{className:"mb-1 block text-muted-foreground",children:"Capabilities (optional)"}),l.jsx("textarea",{className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm",rows:4,value:d,onChange:M=>f(M.target.value)})]})]}),j&&l.jsxs("div",{className:"mt-4 rounded-md border border-border bg-muted/30 p-3 text-sm",children:["Sign in or create an account before submitting a human join request.",l.jsx("div",{className:"mt-2",children:l.jsx(ke,{asChild:!0,size:"sm",variant:"outline",children:l.jsx(Bt,{to:`/auth?next=${encodeURIComponent(`/invite/${n}`)}`,children:"Sign in / Create account"})})})]}),x&&l.jsx("p",{className:"mt-3 text-sm text-destructive",children:x}),l.jsx(ke,{className:"mt-5",disabled:R.isPending||r==="agent"&&C.inviteType!=="bootstrap_ceo"&&i.trim().length===0||j,onClick:()=>R.mutate(),children:R.isPending?"Submitting…":C.inviteType==="bootstrap_ceo"?"Accept bootstrap invite":"Submit join request"})]})})}function Jqe({hasActiveInvite:t=!1}){return l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-xl font-semibold",children:"Instance setup required"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:t?"No instance admin exists yet. A bootstrap invite is already active. Check your Paperclip startup logs for the first admin invite URL, or run this command to rotate it:":"No instance admin exists yet. Run this command in your Paperclip environment to generate the first admin invite URL:"}),l.jsx("pre",{className:"mt-4 overflow-x-auto rounded-md border border-border bg-muted/30 p-3 text-xs",children:"pnpm paperclipai auth bootstrap-ceo"})]})})}function Yqe(){var s,i;const t=Fr(),e=Be({queryKey:te.health,queryFn:()=>n6.get(),retry:!1}),n=((s=e.data)==null?void 0:s.deploymentMode)==="authenticated",r=Be({queryKey:te.auth.session,queryFn:()=>Ua.getSession(),enabled:n,retry:!1});if(e.isLoading||n&&r.isLoading)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading..."});if(e.error)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:e.error instanceof Error?e.error.message:"Failed to load app state"});if(n&&((i=e.data)==null?void 0:i.bootstrapStatus)==="bootstrap_pending")return l.jsx(Jqe,{hasActiveInvite:e.data.bootstrapInviteActive});if(n&&!r.data){const o=encodeURIComponent(`${t.pathname}${t.search}`);return l.jsx(vo,{to:`/auth?next=${o}`,replace:!0})}return l.jsx(gq,{})}function Zqe(){return l.jsxs(l.Fragment,{children:[l.jsx(Nt,{index:!0,element:l.jsx(vo,{to:"dashboard",replace:!0})}),l.jsx(Nt,{path:"dashboard",element:l.jsx(xBe,{})}),l.jsx(Nt,{path:"companies",element:l.jsx(vBe,{})}),l.jsx(Nt,{path:"company/settings",element:l.jsx(Sqe,{})}),l.jsx(Nt,{path:"org",element:l.jsx(Pqe,{})}),l.jsx(Nt,{path:"agents",element:l.jsx(vo,{to:"/agents/all",replace:!0})}),l.jsx(Nt,{path:"agents/all",element:l.jsx(fC,{})}),l.jsx(Nt,{path:"agents/active",element:l.jsx(fC,{})}),l.jsx(Nt,{path:"agents/paused",element:l.jsx(fC,{})}),l.jsx(Nt,{path:"agents/error",element:l.jsx(fC,{})}),l.jsx(Nt,{path:"agents/new",element:l.jsx(Vqe,{})}),l.jsx(Nt,{path:"agents/:agentId",element:l.jsx(LA,{})}),l.jsx(Nt,{path:"agents/:agentId/:tab",element:l.jsx(LA,{})}),l.jsx(Nt,{path:"agents/:agentId/runs/:runId",element:l.jsx(LA,{})}),l.jsx(Nt,{path:"projects",element:l.jsx(lUe,{})}),l.jsx(Nt,{path:"projects/:projectId",element:l.jsx(vC,{})}),l.jsx(Nt,{path:"projects/:projectId/overview",element:l.jsx(vC,{})}),l.jsx(Nt,{path:"projects/:projectId/issues",element:l.jsx(vC,{})}),l.jsx(Nt,{path:"projects/:projectId/issues/:filter",element:l.jsx(vC,{})}),l.jsx(Nt,{path:"issues",element:l.jsx(AUe,{})}),l.jsx(Nt,{path:"issues/all",element:l.jsx(vo,{to:"/issues",replace:!0})}),l.jsx(Nt,{path:"issues/active",element:l.jsx(vo,{to:"/issues",replace:!0})}),l.jsx(Nt,{path:"issues/backlog",element:l.jsx(vo,{to:"/issues",replace:!0})}),l.jsx(Nt,{path:"issues/done",element:l.jsx(vo,{to:"/issues",replace:!0})}),l.jsx(Nt,{path:"issues/recent",element:l.jsx(vo,{to:"/issues",replace:!0})}),l.jsx(Nt,{path:"issues/:issueId",element:l.jsx(GUe,{})}),l.jsx(Nt,{path:"goals",element:l.jsx(JUe,{})}),l.jsx(Nt,{path:"goals/:goalId",element:l.jsx(QUe,{})}),l.jsx(Nt,{path:"approvals",element:l.jsx(vo,{to:"/approvals/pending",replace:!0})}),l.jsx(Nt,{path:"approvals/pending",element:l.jsx(DU,{})}),l.jsx(Nt,{path:"approvals/all",element:l.jsx(DU,{})}),l.jsx(Nt,{path:"approvals/:approvalId",element:l.jsx(nqe,{})}),l.jsx(Nt,{path:"costs",element:l.jsx(lqe,{})}),l.jsx(Nt,{path:"activity",element:l.jsx(dqe,{})}),l.jsx(Nt,{path:"inbox",element:l.jsx(vo,{to:"/inbox/new",replace:!0})}),l.jsx(Nt,{path:"inbox/new",element:l.jsx(BU,{})}),l.jsx(Nt,{path:"inbox/all",element:l.jsx(BU,{})}),l.jsx(Nt,{path:"design-guide",element:l.jsx(Aqe,{})})]})}function Qqe(){const{companies:t,selectedCompany:e,loading:n}=en(),{onboardingOpen:r}=$r();if(n)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading..."});if(r)return l.jsx(NM,{autoOpen:!1});const s=e??t[0]??null;return s?l.jsx(vo,{to:`/${s.issuePrefix}/dashboard`,replace:!0}):l.jsx(NM,{})}function xo(){const t=Fr(),{companies:e,selectedCompany:n,loading:r}=en();if(r)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading..."});const s=n??e[0]??null;return s?l.jsx(vo,{to:`/${s.issuePrefix}${t.pathname}${t.search}${t.hash}`,replace:!0}):l.jsx(NM,{})}function NM({autoOpen:t=!0}){const{openOnboarding:e}=$r(),n=v.useRef(!1);return v.useEffect(()=>{t&&(n.current||(n.current=!0,e()))},[t,e]),l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-xl font-semibold",children:"Create your first company"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Get started by creating a company."}),l.jsx("div",{className:"mt-4",children:l.jsx(ke,{onClick:()=>e(),children:"New Company"})})]})})}function Xqe(){return l.jsxs(l.Fragment,{children:[l.jsxs(yue,{children:[l.jsx(Nt,{path:"auth",element:l.jsx(Hqe,{})}),l.jsx(Nt,{path:"board-claim/:token",element:l.jsx(Uqe,{})}),l.jsx(Nt,{path:"invite/:token",element:l.jsx(Gqe,{})}),l.jsxs(Nt,{element:l.jsx(Yqe,{}),children:[l.jsx(Nt,{index:!0,element:l.jsx(Qqe,{})}),l.jsx(Nt,{path:"companies",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"issues",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"issues/:issueId",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"agents",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"agents/new",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"agents/:agentId",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"agents/:agentId/:tab",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"agents/:agentId/runs/:runId",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"projects",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"projects/:projectId",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"projects/:projectId/overview",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"projects/:projectId/issues",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"projects/:projectId/issues/:filter",element:l.jsx(xo,{})}),l.jsx(Nt,{path:":companyPrefix",element:l.jsx(yFe,{}),children:Zqe()})]})]}),l.jsx(eBe,{})]})}const eKe=1e4,tKe=3,nKe=2e3;function An(t){return typeof t=="string"&&t.length>0?t:null}function w6(t){return typeof t!="object"||t===null||Array.isArray(t)?null:t}function o5(t){return t.slice(0,8)}function Goe(t,e,n){const r=t.getQueryData(te.agents.list(e));if(!r)return null;const s=r.find(i=>i.id===n);return(s==null?void 0:s.name)??null}function nh(t,e){return t.length<=e?t:t.slice(0,e-1)+"…"}function rKe(t,e,n,r){return n==="agent"&&r?Goe(t,e,r)??`Agent ${o5(r)}`:n==="system"?"System":n==="user"&&r?"Board":"Someone"}function Joe(t,e,n,r){const s=new Set([n]),i=t.getQueryData(te.issues.detail(n)),o=t.getQueryData(te.issues.list(e)),a=An(r==null?void 0:r.identifier)??An(r==null?void 0:r.issueIdentifier);a&&s.add(a),i!=null&&i.id&&s.add(i.id),i!=null&&i.identifier&&s.add(i.identifier);const c=o==null?void 0:o.find(d=>!!(d.id===n||d.identifier&&d.identifier===n||a&&d.identifier===a));return c!=null&&c.id&&s.add(c.id),c!=null&&c.identifier&&s.add(c.identifier),Array.from(s)}function sKe(t,e,n,r){var f;const s=Joe(t,e,n,r),i=s.map(m=>t.getQueryData(te.issues.detail(m))).find(m=>!!m),o=(f=t.getQueryData(te.issues.list(e)))==null?void 0:f.find(m=>s.some(p=>m.id===p||m.identifier===p)),a=i??o??null,c=An(r==null?void 0:r.identifier)??An(r==null?void 0:r.issueIdentifier)??(a==null?void 0:a.identifier)??`Issue ${o5(n)}`,d=An(r==null?void 0:r.title)??An(r==null?void 0:r.issueTitle)??(a==null?void 0:a.title)??null;return{ref:c,title:d,label:d?`${c} - ${nh(d,72)}`:c,href:`/issues/${(a==null?void 0:a.identifier)??n}`}}const iKe=new Set(["issue.created","issue.updated","issue.comment_added"]),oKe=new Set(["running","error"]),aKe=new Set(["succeeded","failed","timed_out","cancelled"]);function lKe(t){if(!t)return null;const e=[];if(typeof t.status=="string"&&e.push(`status -> ${t.status.replace(/_/g," ")}`),typeof t.priority=="string"&&e.push(`priority -> ${t.priority}`),typeof t.assigneeAgentId=="string"||typeof t.assigneeUserId=="string"?e.push("reassigned"):(t.assigneeAgentId===null||t.assigneeUserId===null)&&e.push("unassigned"),t.reopened===!0){const n=An(t.reopenedFrom);e.push(n?`reopened from ${n.replace(/_/g," ")}`:"reopened")}return typeof t.title=="string"&&e.push("title changed"),typeof t.description=="string"&&e.push("description changed"),e.length>0?e.join(", "):null}function cKe(t,e,n,r){const s=An(n.entityType),i=An(n.entityId),o=An(n.action),a=w6(n.details),c=An(n.actorId),d=An(n.actorType);if(s!=="issue"||!i||!o||!iKe.has(o))return null;const f=sKe(t,e,i,a),m=rKe(t,e,d,c);if(d==="user"&&!!r.userId&&c===r.userId||d==="agent"&&!1)return null;if(o==="issue.created")return{title:`${m} created ${f.ref}`,body:f.title?nh(f.title,96):void 0,tone:"success",action:{label:`View ${f.ref}`,href:f.href},dedupeKey:`activity:${o}:${i}`};if(o==="issue.updated"){if(An(a==null?void 0:a.source)==="comment")return null;const j=lKe(a),R=j?f.title?`${nh(f.title,64)} - ${j}`:j:f.title?nh(f.title,96):f.label;return{title:`${m} updated ${f.ref}`,body:nh(R,100),tone:"info",action:{label:`View ${f.ref}`,href:f.href},dedupeKey:`activity:${o}:${i}`}}const x=An(a==null?void 0:a.commentId),y=An(a==null?void 0:a.bodySnippet),w=(a==null?void 0:a.reopened)===!0,k=(a==null?void 0:a.updated)===!0,S=An(a==null?void 0:a.reopenedFrom),C=w?S?`reopened from ${S.replace(/_/g," ")}`:"reopened":null,_=w?`${m} reopened and commented on ${f.ref}`:k?`${m} commented and updated ${f.ref}`:`${m} commented on ${f.ref}`,E=y?C?`${C} - ${y.replace(/^#+\s*/m,"").replace(/\n/g," ")}`:y.replace(/^#+\s*/m,"").replace(/\n/g," "):C?f.title?`${C} - ${f.title}`:C:f.title??void 0;return{title:_,body:E?nh(E,96):void 0,tone:"info",action:{label:`View ${f.ref}`,href:f.href},dedupeKey:`activity:${o}:${i}:${x??"na"}`}}function uKe(t){const e=An(t.entityType),n=An(t.action),r=An(t.entityId),s=w6(t.details);return e!=="join_request"||!n||!r||n!=="join.requested"&&n!=="join.request_replayed"?null:{title:`${An(s==null?void 0:s.requestType)==="agent"?"Agent":"Someone"} wants to join`,body:"A new join request is waiting for approval.",tone:"info",action:{label:"View inbox",href:"/inbox/new"},dedupeKey:`join-request:${r}`}}function dKe(t,e,n,r){const s=An(t.agentId),i=An(t.status);if(!s||!i||!oKe.has(i))return null;const o=i==="error"?"error":"info",a=e(s)??`Agent ${o5(s)}`,c=i==="running"?`${a} started`:`${a} errored`,d=n.getQueryData(te.agents.list(r)),f=d==null?void 0:d.find(p=>p.id===s),m=(f==null?void 0:f.title)??void 0;return{title:c,body:m,tone:o,action:{label:"View agent",href:`/agents/${s}`},dedupeKey:`agent-status:${s}:${i}`}}function fKe(t,e){const n=An(t.runId),r=An(t.agentId),s=An(t.status);if(!n||!r||!s||!aKe.has(s))return null;const i=An(t.error),o=An(t.triggerDetail),a=e(r)??`Agent ${o5(r)}`,c=s==="succeeded"?"success":s==="cancelled"?"warn":"error",f=`${a} run ${s==="succeeded"?"succeeded":s==="failed"?"failed":s==="timed_out"?"timed out":"cancelled"}`;let m;return i?m=nh(i,100):o&&(m=`Trigger: ${o}`),{title:f,body:m,tone:c,ttlMs:s==="succeeded"?5e3:7e3,action:{label:"View run",href:`/agents/${r}/runs/${n}`},dedupeKey:`run-status:${n}:${s}`}}function hKe(t,e,n){t.invalidateQueries({queryKey:te.liveRuns(e)}),t.invalidateQueries({queryKey:te.heartbeats(e)}),t.invalidateQueries({queryKey:te.agents.list(e)}),t.invalidateQueries({queryKey:te.dashboard(e)}),t.invalidateQueries({queryKey:te.costs(e)}),t.invalidateQueries({queryKey:te.sidebarBadges(e)});const r=An(n.agentId);r&&(t.invalidateQueries({queryKey:te.agents.detail(r)}),t.invalidateQueries({queryKey:te.heartbeats(e,r)}))}function mKe(t,e,n){t.invalidateQueries({queryKey:te.activity(e)}),t.invalidateQueries({queryKey:te.dashboard(e)}),t.invalidateQueries({queryKey:te.sidebarBadges(e)});const r=An(n.entityType),s=An(n.entityId);if(r==="issue"){if(t.invalidateQueries({queryKey:te.issues.list(e)}),s){const i=w6(n.details),o=Joe(t,e,s,i);for(const a of o)t.invalidateQueries({queryKey:te.issues.detail(a)}),t.invalidateQueries({queryKey:te.issues.comments(a)}),t.invalidateQueries({queryKey:te.issues.activity(a)}),t.invalidateQueries({queryKey:te.issues.runs(a)}),t.invalidateQueries({queryKey:te.issues.liveRuns(a)}),t.invalidateQueries({queryKey:te.issues.activeRun(a)})}return}if(r==="agent"){t.invalidateQueries({queryKey:te.agents.list(e)}),t.invalidateQueries({queryKey:te.org(e)}),s&&(t.invalidateQueries({queryKey:te.agents.detail(s)}),t.invalidateQueries({queryKey:te.heartbeats(e,s)}));return}if(r==="project"){t.invalidateQueries({queryKey:te.projects.list(e)}),s&&t.invalidateQueries({queryKey:te.projects.detail(s)});return}if(r==="goal"){t.invalidateQueries({queryKey:te.goals.list(e)}),s&&t.invalidateQueries({queryKey:te.goals.detail(s)});return}if(r==="approval"){t.invalidateQueries({queryKey:te.approvals.list(e)});return}if(r==="join_request"){t.invalidateQueries({queryKey:te.access.joinRequests(e)});return}if(r==="cost_event"){t.invalidateQueries({queryKey:te.costs(e)});return}r==="company"&&t.invalidateQueries({queryKey:te.companies.all})}function pKe(t,e){const n=Date.now();if(n<t.suppressUntil)return!0;const r=t.cooldownHits.get(e);if(!r)return!1;const s=r.filter(i=>n-i<eKe);return t.cooldownHits.set(e,s),s.length>=tKe}function gKe(t,e){const n=Date.now(),r=t.cooldownHits.get(e)??[];r.push(n),t.cooldownHits.set(e,r)}function qA(t,e,n,r){if(pKe(t,n))return;e(r)!==null&&gKe(t,n)}function xKe(t,e,n,r,s,i){if(n.companyId!==e)return;const o=c=>Goe(t,e,c),a=n.payload??{};if(n.type!=="heartbeat.run.log"){if(n.type==="heartbeat.run.queued"||n.type==="heartbeat.run.status"){if(hKe(t,e,a),n.type==="heartbeat.run.status"){const c=fKe(a,o);c&&qA(s,r,"run-status",c)}return}if(n.type!=="heartbeat.run.event"){if(n.type==="agent.status"){t.invalidateQueries({queryKey:te.agents.list(e)}),t.invalidateQueries({queryKey:te.dashboard(e)}),t.invalidateQueries({queryKey:te.org(e)});const c=An(a.agentId);c&&t.invalidateQueries({queryKey:te.agents.detail(c)});const d=dKe(a,o,t,e);d&&qA(s,r,"agent-status",d);return}if(n.type==="activity.logged"){mKe(t,e,a);const c=An(a.action),d=cKe(t,e,a,i)??uKe(a);d&&qA(s,r,`activity:${c??"unknown"}`,d)}}}}function yKe({children:t}){var a,c;const{selectedCompanyId:e}=en(),n=Nn(),{pushToast:r}=Aie(),s=v.useRef({cooldownHits:new Map,suppressUntil:0}),{data:i}=Be({queryKey:te.auth.session,queryFn:()=>Ua.getSession(),retry:!1}),o=((a=i==null?void 0:i.user)==null?void 0:a.id)??((c=i==null?void 0:i.session)==null?void 0:c.userId)??null;return v.useEffect(()=>{if(!e)return;let d=!1,f=0,m=null,p=null;const x=()=>{m!==null&&(window.clearTimeout(m),m=null)},y=()=>{if(d)return;f+=1;const k=Math.min(15e3,1e3*2**Math.min(f-1,4));m=window.setTimeout(()=>{m=null,w()},k)},w=()=>{if(d)return;const S=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/api/companies/${encodeURIComponent(e)}/events/ws`;p=new WebSocket(S),p.onopen=()=>{f>0&&(s.current.suppressUntil=Date.now()+nKe),f=0},p.onmessage=C=>{const _=typeof C.data=="string"?C.data:"";if(_)try{const E=JSON.parse(_);xKe(n,e,E,r,s.current,{userId:o,agentId:null})}catch{}},p.onerror=()=>{p==null||p.close()},p.onclose=()=>{d||y()}};return w(),()=>{d=!0,x(),p&&(p.onopen=null,p.onmessage=null,p.onerror=null,p.onclose=null,p.close(1e3,"provider_unmount"))}},[n,e,r,o]),l.jsx(l.Fragment,{children:t})}"serviceWorker"in navigator&&window.addEventListener("load",()=>{navigator.serviceWorker.register("/sw.js")});const bKe=new Sde({defaultOptions:{queries:{staleTime:3e4,refetchOnWindowFocus:!0}}});yce.createRoot(document.getElementById("root")).render(l.jsx(v.StrictMode,{children:l.jsx(_de,{client:bKe,children:l.jsx(hFe,{children:l.jsx(Mde,{children:l.jsx(nFe,{children:l.jsx(yKe,{children:l.jsx(Hue,{children:l.jsx(r2e,{children:l.jsx(_2e,{children:l.jsx(f2e,{children:l.jsx(j2e,{children:l.jsx(n2e,{children:l.jsx(Xqe,{})})})})})})})})})})})})}));export{Cn as A,ah as B,Wre as C,f6e as D,at as E,_e as F,Wg as G,bDe as H,ar as I,D6e as J,ex as K,X4 as L,wKe as M,_9 as N,wre as P,cr as T,Ae as _,F6e as a,FKe as b,LKe as c,TDe as d,Ws as e,J6e as f,De as g,IKe as h,Nre as i,PKe as j,Ai as k,sn as l,DKe as m,$Ke as n,MKe as o,RKe as p,na as q,Ex as r,T6e as s,je as t,Sf as u,$v as v,la as w,W_ as x,G6e as y,Sre as z};
900
+ `}function _qe(t){const e=(t.connectionCandidates??[]).map(i=>i.trim()).filter(Boolean),n=new Set;let r=null;try{r=new URL(t.onboardingTextUrl),n.add(r.toString())}catch{const i=t.onboardingTextUrl.trim();i&&n.add(i)}if(!r){for(const i of e)n.add(i);return Array.from(n)}const s=`${r.pathname}${r.search}`;for(const i of e)try{const o=new URL(i);n.add(`${o.origin}${s}`)}catch{n.add(i)}return Array.from(n)}function Nqe(t){var n;const e=(n=t.testResolutionUrl)==null?void 0:n.trim();if(e)return e;try{const r=new URL(t.onboardingTextUrl),s=r.pathname.replace(/\/onboarding\.txt$/,"/test-resolution");return`${r.origin}${s}`}catch{return null}}const Eqe=HM("inline-flex items-center justify-center rounded-full border border-transparent px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",{variants:{variant:{default:"bg-primary text-primary-foreground [a&]:hover:bg-primary/90",secondary:"bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",destructive:"bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",ghost:"[a&]:hover:bg-accent [a&]:hover:text-accent-foreground",link:"text-primary underline-offset-4 [a&]:hover:underline"}},defaultVariants:{variant:"default"}});function wd({className:t,variant:e="default",asChild:n=!1,...r}){const s=n?UM:"span";return l.jsx(s,{"data-slot":"badge","data-variant":e,className:re(Eqe({variant:e}),t),...r})}function md({className:t,...e}){return l.jsx(Cge,{"data-slot":"label",className:re("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",t),...e})}function jqe({filters:t,onRemove:e,onClear:n}){return t.length===0?null:l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.map(r=>l.jsxs(wd,{variant:"secondary",className:"gap-1 pr-1",children:[l.jsxs("span",{className:"text-muted-foreground",children:[r.label,":"]}),l.jsx("span",{children:r.value}),l.jsx("button",{className:"ml-1 rounded-full hover:bg-accent p-0.5",onClick:()=>e(r.key),children:l.jsx(ii,{className:"h-3 w-3"})})]},r.key)),l.jsx(ke,{variant:"ghost",size:"sm",className:"text-xs h-6",onClick:n,children:"Clear all"})]})}function mn({title:t,children:e}){return l.jsxs("section",{className:"space-y-4",children:[l.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:t}),l.jsx(Yi,{}),e]})}function pn({title:t,children:e}){return l.jsxs("div",{className:"space-y-3",children:[l.jsx("h4",{className:"text-sm font-medium",children:t}),e]})}function hs({name:t,cssVar:e}){return l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx("div",{className:"h-8 w-8 rounded-md border border-border shrink-0",style:{backgroundColor:`var(${e})`}}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs font-mono",children:e}),l.jsx("p",{className:"text-xs text-muted-foreground",children:t})]})]})}function Aqe(){const[t,e]=v.useState("todo"),[n,r]=v.useState("medium"),[s,i]=v.useState("in_progress"),[o,a]=v.useState(!0),[c,d]=v.useState(!1),[f,m]=v.useState("Click to edit this text"),[p,x]=v.useState("Editable Title"),[y,w]=v.useState("This is an editable description. Click to edit it — the textarea auto-sizes to fit the content without layout shift."),[k,S]=v.useState([{key:"status",label:"Status",value:"Active"},{key:"priority",label:"Priority",value:"High"}]);return l.jsxs("div",{className:"space-y-10 max-w-4xl",children:[l.jsxs("div",{children:[l.jsx("h2",{className:"text-xl font-bold",children:"Design Guide"}),l.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Every component, style, and pattern used across Paperclip."})]}),l.jsxs(mn,{title:"Component Coverage",children:[l.jsx("p",{className:"text-sm text-muted-foreground",children:"This page should be updated when new UI primitives or app-level patterns ship."}),l.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[l.jsx(pn,{title:"UI primitives",children:l.jsx("div",{className:"flex flex-wrap gap-2",children:["avatar","badge","breadcrumb","button","card","checkbox","collapsible","command","dialog","dropdown-menu","input","label","popover","scroll-area","select","separator","sheet","skeleton","tabs","textarea","tooltip"].map(C=>l.jsx(wd,{variant:"outline",className:"font-mono text-[10px]",children:C},C))})}),l.jsx(pn,{title:"App components",children:l.jsx("div",{className:"flex flex-wrap gap-2",children:["StatusBadge","StatusIcon","PriorityIcon","EntityRow","EmptyState","MetricCard","FilterBar","InlineEditor","PageSkeleton","Identity","CommentThread","MarkdownEditor","PropertiesPanel","Sidebar","CommandPalette"].map(C=>l.jsx(wd,{variant:"ghost",className:"font-mono text-[10px]",children:C},C))})})]})]}),l.jsxs(mn,{title:"Colors",children:[l.jsx(pn,{title:"Core",children:l.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[l.jsx(hs,{name:"Background",cssVar:"--background"}),l.jsx(hs,{name:"Foreground",cssVar:"--foreground"}),l.jsx(hs,{name:"Card",cssVar:"--card"}),l.jsx(hs,{name:"Primary",cssVar:"--primary"}),l.jsx(hs,{name:"Primary foreground",cssVar:"--primary-foreground"}),l.jsx(hs,{name:"Secondary",cssVar:"--secondary"}),l.jsx(hs,{name:"Muted",cssVar:"--muted"}),l.jsx(hs,{name:"Muted foreground",cssVar:"--muted-foreground"}),l.jsx(hs,{name:"Accent",cssVar:"--accent"}),l.jsx(hs,{name:"Destructive",cssVar:"--destructive"}),l.jsx(hs,{name:"Border",cssVar:"--border"}),l.jsx(hs,{name:"Ring",cssVar:"--ring"})]})}),l.jsx(pn,{title:"Sidebar",children:l.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[l.jsx(hs,{name:"Sidebar",cssVar:"--sidebar"}),l.jsx(hs,{name:"Sidebar border",cssVar:"--sidebar-border"})]})}),l.jsx(pn,{title:"Chart",children:l.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[l.jsx(hs,{name:"Chart 1",cssVar:"--chart-1"}),l.jsx(hs,{name:"Chart 2",cssVar:"--chart-2"}),l.jsx(hs,{name:"Chart 3",cssVar:"--chart-3"}),l.jsx(hs,{name:"Chart 4",cssVar:"--chart-4"}),l.jsx(hs,{name:"Chart 5",cssVar:"--chart-5"})]})})]}),l.jsx(mn,{title:"Typography",children:l.jsxs("div",{className:"space-y-3",children:[l.jsx("h2",{className:"text-xl font-bold",children:"Page Title — text-xl font-bold"}),l.jsx("h2",{className:"text-lg font-semibold",children:"Section Title — text-lg font-semibold"}),l.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Section Heading — text-sm font-semibold uppercase tracking-wide"}),l.jsx("p",{className:"text-sm font-medium",children:"Card Title — text-sm font-medium"}),l.jsx("p",{className:"text-sm font-semibold",children:"Card Title Alt — text-sm font-semibold"}),l.jsx("p",{className:"text-sm",children:"Body text — text-sm"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Muted description — text-sm text-muted-foreground"}),l.jsx("p",{className:"text-xs text-muted-foreground",children:"Tiny label — text-xs text-muted-foreground"}),l.jsx("p",{className:"text-sm font-mono text-muted-foreground",children:"Mono identifier — text-sm font-mono text-muted-foreground"}),l.jsx("p",{className:"text-2xl font-bold",children:"Large stat — text-2xl font-bold"}),l.jsx("p",{className:"font-mono text-xs",children:"Log/code text — font-mono text-xs"})]})}),l.jsx(mn,{title:"Radius",children:l.jsx("div",{className:"flex items-end gap-4 flex-wrap",children:[["sm","var(--radius-sm)"],["md","var(--radius-md)"],["lg","var(--radius-lg)"],["xl","var(--radius-xl)"],["full","9999px"]].map(([C,_])=>l.jsxs("div",{className:"flex flex-col items-center gap-1",children:[l.jsx("div",{className:"h-12 w-12 bg-primary",style:{borderRadius:_}}),l.jsx("span",{className:"text-xs text-muted-foreground",children:C})]},C))})}),l.jsxs(mn,{title:"Buttons",children:[l.jsx(pn,{title:"Variants",children:l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l.jsx(ke,{variant:"default",children:"Default"}),l.jsx(ke,{variant:"secondary",children:"Secondary"}),l.jsx(ke,{variant:"outline",children:"Outline"}),l.jsx(ke,{variant:"ghost",children:"Ghost"}),l.jsx(ke,{variant:"destructive",children:"Destructive"}),l.jsx(ke,{variant:"link",children:"Link"})]})}),l.jsx(pn,{title:"Sizes",children:l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l.jsx(ke,{size:"xs",children:"Extra Small"}),l.jsx(ke,{size:"sm",children:"Small"}),l.jsx(ke,{size:"default",children:"Default"}),l.jsx(ke,{size:"lg",children:"Large"})]})}),l.jsx(pn,{title:"Icon buttons",children:l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l.jsx(ke,{variant:"ghost",size:"icon-xs",children:l.jsx(Gc,{})}),l.jsx(ke,{variant:"ghost",size:"icon-sm",children:l.jsx(Gc,{})}),l.jsx(ke,{variant:"outline",size:"icon",children:l.jsx(Gc,{})}),l.jsx(ke,{variant:"outline",size:"icon-lg",children:l.jsx(Gc,{})})]})}),l.jsx(pn,{title:"With icons",children:l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l.jsxs(ke,{children:[l.jsx(Pr,{})," New Issue"]}),l.jsxs(ke,{variant:"outline",children:[l.jsx(qP,{})," Upload"]}),l.jsxs(ke,{variant:"destructive",children:[l.jsx(lu,{})," Delete"]}),l.jsxs(ke,{size:"sm",children:[l.jsx(Pr,{})," Add"]})]})}),l.jsx(pn,{title:"States",children:l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l.jsx(ke,{disabled:!0,children:"Disabled"}),l.jsx(ke,{variant:"outline",disabled:!0,children:"Disabled Outline"})]})})]}),l.jsx(mn,{title:"Badges",children:l.jsx(pn,{title:"Variants",children:l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l.jsx(wd,{variant:"default",children:"Default"}),l.jsx(wd,{variant:"secondary",children:"Secondary"}),l.jsx(wd,{variant:"outline",children:"Outline"}),l.jsx(wd,{variant:"destructive",children:"Destructive"}),l.jsx(wd,{variant:"ghost",children:"Ghost"})]})})}),l.jsxs(mn,{title:"Status System",children:[l.jsx(pn,{title:"StatusBadge (all statuses)",children:l.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:["active","running","paused","idle","archived","planned","achieved","completed","failed","timed_out","succeeded","error","pending_approval","backlog","todo","in_progress","in_review","blocked","done","terminated","cancelled","pending","revision_requested","approved","rejected"].map(C=>l.jsx(Fn,{status:C},C))})}),l.jsxs(pn,{title:"StatusIcon (interactive)",children:[l.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:["backlog","todo","in_progress","in_review","done","cancelled","blocked"].map(C=>l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(qr,{status:C}),l.jsx("span",{className:"text-xs text-muted-foreground",children:C})]},C))}),l.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[l.jsx(qr,{status:t,onChange:e}),l.jsxs("span",{className:"text-sm",children:["Click the icon to change status (current: ",t,")"]})]})]}),l.jsxs(pn,{title:"PriorityIcon (interactive)",children:[l.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:["critical","high","medium","low"].map(C=>l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(Ss,{priority:C}),l.jsx("span",{className:"text-xs text-muted-foreground",children:C})]},C))}),l.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[l.jsx(Ss,{priority:n,onChange:r}),l.jsxs("span",{className:"text-sm",children:["Click the icon to change (current: ",n,")"]})]})]}),l.jsx(pn,{title:"Agent status dots",children:l.jsx("div",{className:"flex items-center gap-4 flex-wrap",children:["running","active","paused","error","archived"].map(C=>l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"relative flex h-2.5 w-2.5",children:l.jsx("span",{className:`inline-flex h-full w-full rounded-full ${r_[C]??s_}`})}),l.jsx("span",{className:"text-xs text-muted-foreground",children:C})]},C))})}),l.jsx(pn,{title:"Run invocation badges",children:l.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:[["timer","bg-blue-100 text-blue-700 dark:bg-blue-900/50 dark:text-blue-300"],["assignment","bg-violet-100 text-violet-700 dark:bg-violet-900/50 dark:text-violet-300"],["on_demand","bg-cyan-100 text-cyan-700 dark:bg-cyan-900/50 dark:text-cyan-300"],["automation","bg-muted text-muted-foreground"]].map(([C,_])=>l.jsx("span",{className:`rounded-full px-1.5 py-0.5 text-[10px] font-medium ${_}`,children:C},C))})})]}),l.jsx(mn,{title:"Form Elements",children:l.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[l.jsxs(pn,{title:"Input",children:[l.jsx(Jc,{placeholder:"Default input"}),l.jsx(Jc,{placeholder:"Disabled input",disabled:!0,className:"mt-2"})]}),l.jsx(pn,{title:"Textarea",children:l.jsx(dy,{placeholder:"Write something..."})}),l.jsx(pn,{title:"Checkbox & Label",children:l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(ch,{id:"check1",defaultChecked:!0}),l.jsx(md,{htmlFor:"check1",children:"Checked item"})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(ch,{id:"check2"}),l.jsx(md,{htmlFor:"check2",children:"Unchecked item"})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(ch,{id:"check3",disabled:!0}),l.jsx(md,{htmlFor:"check3",children:"Disabled item"})]})]})}),l.jsx(pn,{title:"Inline Editor",children:l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Title (single-line)"}),l.jsx(du,{value:p,onSave:x,as:"h2",className:"text-xl font-bold"})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Body text (single-line)"}),l.jsx(du,{value:f,onSave:m,as:"p",className:"text-sm"})]}),l.jsxs("div",{children:[l.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Description (multiline, auto-sizing)"}),l.jsx(du,{value:y,onSave:w,as:"p",className:"text-sm text-muted-foreground",placeholder:"Add a description...",multiline:!0})]})]})})]})}),l.jsx(mn,{title:"Select",children:l.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[l.jsxs(pn,{title:"Default size",children:[l.jsxs(Lb,{value:s,onValueChange:i,children:[l.jsx(Fb,{className:"w-full",children:l.jsx(Pb,{placeholder:"Select status"})}),l.jsxs($b,{children:[l.jsx(Hr,{value:"backlog",children:"Backlog"}),l.jsx(Hr,{value:"todo",children:"Todo"}),l.jsx(Hr,{value:"in_progress",children:"In Progress"}),l.jsx(Hr,{value:"in_review",children:"In Review"}),l.jsx(Hr,{value:"done",children:"Done"})]})]}),l.jsxs("p",{className:"text-xs text-muted-foreground",children:["Current value: ",s]})]}),l.jsx(pn,{title:"Small trigger",children:l.jsxs(Lb,{defaultValue:"high",children:[l.jsx(Fb,{size:"sm",className:"w-full",children:l.jsx(Pb,{})}),l.jsxs($b,{children:[l.jsx(Hr,{value:"critical",children:"Critical"}),l.jsx(Hr,{value:"high",children:"High"}),l.jsx(Hr,{value:"medium",children:"Medium"}),l.jsx(Hr,{value:"low",children:"Low"})]})]})})]})}),l.jsx(mn,{title:"Dropdown Menu",children:l.jsxs(qie,{children:[l.jsx(Kie,{asChild:!0,children:l.jsxs(ke,{variant:"outline",size:"sm",children:["Quick Actions",l.jsx(ga,{className:"h-4 w-4"})]})}),l.jsxs(Wie,{align:"start",className:"w-56",children:[l.jsxs(Oy,{children:[l.jsx(fa,{className:"h-4 w-4"}),"Mark as done",l.jsx(bBe,{children:"⌘D"})]}),l.jsxs(Oy,{children:[l.jsx(UT,{className:"h-4 w-4"}),"Open docs"]}),l.jsx(Gie,{}),l.jsx(yBe,{checked:o,onCheckedChange:C=>a(C===!0),children:"Watch issue"}),l.jsxs(Oy,{variant:"destructive",children:[l.jsx(lu,{className:"h-4 w-4"}),"Delete issue"]})]})]})}),l.jsx(mn,{title:"Popover",children:l.jsxs(Bn,{children:[l.jsx(zn,{asChild:!0,children:l.jsx(ke,{variant:"outline",size:"sm",children:"Open Popover"})}),l.jsxs(Vn,{className:"space-y-2",children:[l.jsx("p",{className:"text-sm font-medium",children:"Agent heartbeat"}),l.jsx("p",{className:"text-xs text-muted-foreground",children:"Last run succeeded 24s ago. Next timer run in 9m."}),l.jsx(ke,{size:"xs",children:"Wake now"})]})]})}),l.jsx(mn,{title:"Collapsible",children:l.jsxs(Mg,{open:c,onOpenChange:d,className:"space-y-2",children:[l.jsx(Rg,{asChild:!0,children:l.jsxs(ke,{variant:"outline",size:"sm",children:[c?"Hide":"Show"," advanced filters"]})}),l.jsx(Og,{className:"rounded-md border border-border p-3",children:l.jsxs("div",{className:"space-y-2",children:[l.jsx(md,{htmlFor:"owner-filter",children:"Owner"}),l.jsx(Jc,{id:"owner-filter",placeholder:"Filter by agent name"})]})})]})}),l.jsx(mn,{title:"Sheet",children:l.jsxs(x6,{children:[l.jsx(vUe,{asChild:!0,children:l.jsx(ke,{variant:"outline",size:"sm",children:"Open Side Panel"})}),l.jsxs(y6,{side:"right",children:[l.jsxs(b6,{children:[l.jsx(v6,{children:"Issue Properties"}),l.jsx(SUe,{children:"Edit metadata without leaving the current page."})]}),l.jsxs("div",{className:"space-y-4 px-4",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsx(md,{htmlFor:"sheet-title",children:"Title"}),l.jsx(Jc,{id:"sheet-title",defaultValue:"Improve onboarding docs"})]}),l.jsxs("div",{className:"space-y-1",children:[l.jsx(md,{htmlFor:"sheet-description",children:"Description"}),l.jsx(dy,{id:"sheet-description",defaultValue:"Capture setup pitfalls and screenshots."})]})]}),l.jsxs(kUe,{children:[l.jsx(ke,{variant:"outline",children:"Cancel"}),l.jsx(ke,{children:"Save"})]})]})]})}),l.jsx(mn,{title:"Scroll Area",children:l.jsx(t_,{className:"h-36 rounded-md border border-border",children:l.jsx("div",{className:"space-y-2 p-3",children:Array.from({length:12}).map((C,_)=>l.jsxs("div",{className:"rounded-md border border-border p-2 text-sm",children:["Heartbeat run #",_+1,": completed successfully"]},_))})})}),l.jsx(mn,{title:"Command (CMDK)",children:l.jsx("div",{className:"rounded-md border border-border",children:l.jsxs(_Z,{children:[l.jsx(NZ,{placeholder:"Type a command or search..."}),l.jsxs(EZ,{children:[l.jsx(jZ,{children:"No results found."}),l.jsxs(Qf,{heading:"Pages",children:[l.jsxs(ks,{children:[l.jsx(vh,{className:"h-4 w-4"}),"Dashboard"]}),l.jsxs(ks,{children:[l.jsx(Qi,{className:"h-4 w-4"}),"Issues"]})]}),l.jsx(ny,{}),l.jsxs(Qf,{heading:"Actions",children:[l.jsxs(ks,{children:[l.jsx(cve,{className:"h-4 w-4"}),"Open command palette"]}),l.jsxs(ks,{children:[l.jsx(Pr,{className:"h-4 w-4"}),"Create new issue"]})]})]})]})})}),l.jsx(mn,{title:"Breadcrumb",children:l.jsx(dZ,{children:l.jsxs(fZ,{children:[l.jsx(jC,{children:l.jsx(QT,{href:"#",children:"Projects"})}),l.jsx(XT,{}),l.jsx(jC,{children:l.jsx(QT,{href:"#",children:"Paperclip App"})}),l.jsx(XT,{}),l.jsx(jC,{children:l.jsx(hZ,{children:"Issue List"})})]})})}),l.jsxs(mn,{title:"Cards",children:[l.jsx(pn,{title:"Standard Card",children:l.jsxs(n2,{children:[l.jsxs(rqe,{children:[l.jsx(sqe,{children:"Card Title"}),l.jsx(iqe,{children:"Card description with supporting text."})]}),l.jsx(r2,{children:l.jsx("p",{className:"text-sm",children:"Card content goes here. This is the main body area."})}),l.jsxs(oqe,{className:"gap-2",children:[l.jsx(ke,{size:"sm",children:"Action"}),l.jsx(ke,{variant:"outline",size:"sm",children:"Cancel"})]})]})}),l.jsx(pn,{title:"Metric Cards",children:l.jsxs("div",{className:"grid md:grid-cols-2 xl:grid-cols-4 gap-4",children:[l.jsx(Hd,{icon:Si,value:12,label:"Active Agents",description:"+3 this week"}),l.jsx(Hd,{icon:Qi,value:48,label:"Open Issues"}),l.jsx(Hd,{icon:Ph,value:"$1,234",label:"Monthly Cost",description:"Under budget"}),l.jsx(Hd,{icon:KT,value:"99.9%",label:"Uptime"})]})})]}),l.jsxs(mn,{title:"Tabs",children:[l.jsx(pn,{title:"Default (pill) variant",children:l.jsxs(om,{defaultValue:"overview",children:[l.jsxs(Ib,{children:[l.jsx(ko,{value:"overview",children:"Overview"}),l.jsx(ko,{value:"runs",children:"Runs"}),l.jsx(ko,{value:"config",children:"Config"}),l.jsx(ko,{value:"costs",children:"Costs"})]}),l.jsx(ea,{value:"overview",children:l.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Overview tab content."})}),l.jsx(ea,{value:"runs",children:l.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Runs tab content."})}),l.jsx(ea,{value:"config",children:l.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Config tab content."})}),l.jsx(ea,{value:"costs",children:l.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Costs tab content."})})]})}),l.jsx(pn,{title:"Line variant",children:l.jsxs(om,{defaultValue:"summary",children:[l.jsxs(Ib,{variant:"line",children:[l.jsx(ko,{value:"summary",children:"Summary"}),l.jsx(ko,{value:"details",children:"Details"}),l.jsx(ko,{value:"comments",children:"Comments"})]}),l.jsx(ea,{value:"summary",children:l.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Summary content with underline tabs."})}),l.jsx(ea,{value:"details",children:l.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Details content."})}),l.jsx(ea,{value:"comments",children:l.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Comments content."})})]})})]}),l.jsx(mn,{title:"Entity Rows",children:l.jsxs("div",{className:"border border-border rounded-md",children:[l.jsx(Al,{leading:l.jsxs(l.Fragment,{children:[l.jsx(qr,{status:"in_progress"}),l.jsx(Ss,{priority:"high"})]}),identifier:"PAP-001",title:"Implement authentication flow",subtitle:"Assigned to Agent Alpha",trailing:l.jsx(Fn,{status:"in_progress"}),onClick:()=>{}}),l.jsx(Al,{leading:l.jsxs(l.Fragment,{children:[l.jsx(qr,{status:"done"}),l.jsx(Ss,{priority:"medium"})]}),identifier:"PAP-002",title:"Set up CI/CD pipeline",subtitle:"Completed 2 days ago",trailing:l.jsx(Fn,{status:"done"}),onClick:()=>{}}),l.jsx(Al,{leading:l.jsxs(l.Fragment,{children:[l.jsx(qr,{status:"todo"}),l.jsx(Ss,{priority:"low"})]}),identifier:"PAP-003",title:"Write API documentation",trailing:l.jsx(Fn,{status:"todo"}),onClick:()=>{}}),l.jsx(Al,{leading:l.jsxs(l.Fragment,{children:[l.jsx(qr,{status:"blocked"}),l.jsx(Ss,{priority:"critical"})]}),identifier:"PAP-004",title:"Deploy to production",subtitle:"Blocked by PAP-001",trailing:l.jsx(Fn,{status:"blocked"}),selected:!0})]})}),l.jsxs(mn,{title:"Filter Bar",children:[l.jsx(jqe,{filters:k,onRemove:C=>S(_=>_.filter(E=>E.key!==C)),onClear:()=>S([])}),k.length===0&&l.jsx(ke,{variant:"outline",size:"sm",onClick:()=>S([{key:"status",label:"Status",value:"Active"},{key:"priority",label:"Priority",value:"High"}]),children:"Reset filters"})]}),l.jsxs(mn,{title:"Avatars",children:[l.jsx(pn,{title:"Sizes",children:l.jsxs("div",{className:"flex items-center gap-3",children:[l.jsx(xd,{size:"sm",children:l.jsx(yd,{children:"SM"})}),l.jsx(xd,{children:l.jsx(yd,{children:"DF"})}),l.jsx(xd,{size:"lg",children:l.jsx(yd,{children:"LG"})})]})}),l.jsx(pn,{title:"Group",children:l.jsxs(oke,{children:[l.jsx(xd,{children:l.jsx(yd,{children:"A1"})}),l.jsx(xd,{children:l.jsx(yd,{children:"A2"})}),l.jsx(xd,{children:l.jsx(yd,{children:"A3"})}),l.jsx(ake,{children:"+5"})]})})]}),l.jsxs(mn,{title:"Identity",children:[l.jsx(pn,{title:"Sizes",children:l.jsxs("div",{className:"flex items-center gap-6",children:[l.jsx(Sn,{name:"Agent Alpha",size:"sm"}),l.jsx(Sn,{name:"Agent Alpha"}),l.jsx(Sn,{name:"Agent Alpha",size:"lg"})]})}),l.jsx(pn,{title:"Initials derivation",children:l.jsxs("div",{className:"flex flex-col gap-2",children:[l.jsx(Sn,{name:"CEO Agent",size:"sm"}),l.jsx(Sn,{name:"Alpha",size:"sm"}),l.jsx(Sn,{name:"Quality Assurance Lead",size:"sm"})]})}),l.jsx(pn,{title:"Custom initials",children:l.jsx(Sn,{name:"Backend Service",initials:"BS",size:"sm"})})]}),l.jsx(mn,{title:"Tooltips",children:l.jsxs("div",{className:"flex items-center gap-4",children:[l.jsxs(jg,{children:[l.jsx(Ag,{asChild:!0,children:l.jsx(ke,{variant:"outline",size:"sm",children:"Hover me"})}),l.jsx(Tg,{children:"This is a tooltip"})]}),l.jsxs(jg,{children:[l.jsx(Ag,{asChild:!0,children:l.jsx(ke,{variant:"ghost",size:"icon-sm",children:l.jsx(Eg,{})})}),l.jsx(Tg,{children:"Settings"})]})]})}),l.jsx(mn,{title:"Dialog",children:l.jsxs(bf,{children:[l.jsx(tke,{asChild:!0,children:l.jsx(ke,{variant:"outline",children:"Open Dialog"})}),l.jsxs(mm,{children:[l.jsxs(wO,{children:[l.jsx(CO,{children:"Dialog Title"}),l.jsx(kO,{children:"This is a sample dialog showing the standard layout with header, content, and footer."})]}),l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{children:[l.jsx(md,{children:"Name"}),l.jsx(Jc,{placeholder:"Enter a name",className:"mt-1.5"})]}),l.jsxs("div",{children:[l.jsx(md,{children:"Description"}),l.jsx(dy,{placeholder:"Describe...",className:"mt-1.5"})]})]}),l.jsxs(rke,{children:[l.jsx(ke,{variant:"outline",children:"Cancel"}),l.jsx(ke,{children:"Save"})]})]})]})}),l.jsx(mn,{title:"Empty State",children:l.jsx("div",{className:"border border-border rounded-md",children:l.jsx(Os,{icon:Fh,message:"No items to show. Create your first one to get started.",action:"Create Item",onAction:()=>{}})})}),l.jsx(mn,{title:"Progress Bars (Budget)",children:l.jsx("div",{className:"space-y-3",children:[{label:"Under budget (40%)",pct:40,color:"bg-green-400"},{label:"Warning (75%)",pct:75,color:"bg-yellow-400"},{label:"Over budget (95%)",pct:95,color:"bg-red-400"}].map(({label:C,pct:_,color:E})=>l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:C}),l.jsxs("span",{className:"text-xs font-mono",children:[_,"%"]})]}),l.jsx("div",{className:"w-full h-2 bg-muted rounded-full overflow-hidden",children:l.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-150 ${E}`,style:{width:`${_}%`}})})]},C))})}),l.jsx(mn,{title:"Log Viewer",children:l.jsxs("div",{className:"bg-neutral-950 rounded-lg p-3 font-mono text-xs max-h-80 overflow-y-auto",children:[l.jsx("div",{className:"text-foreground",children:"[12:00:01] INFO Agent started successfully"}),l.jsx("div",{className:"text-foreground",children:"[12:00:02] INFO Processing task PAP-001"}),l.jsx("div",{className:"text-yellow-400",children:"[12:00:05] WARN Rate limit approaching (80%)"}),l.jsx("div",{className:"text-foreground",children:"[12:00:08] INFO Task PAP-001 completed"}),l.jsx("div",{className:"text-red-400",children:"[12:00:12] ERROR Connection timeout to upstream service"}),l.jsx("div",{className:"text-blue-300",children:"[12:00:12] SYS Retrying connection in 5s..."}),l.jsx("div",{className:"text-foreground",children:"[12:00:17] INFO Reconnected successfully"}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[l.jsx("span",{className:"absolute inline-flex h-full w-full rounded-full bg-cyan-400 animate-ping"}),l.jsx("span",{className:"inline-flex h-full w-full rounded-full bg-cyan-400"})]}),l.jsx("span",{className:"text-cyan-400",children:"Live"})]})]})}),l.jsx(mn,{title:"Property Row Pattern",children:l.jsxs("div",{className:"border border-border rounded-md p-4 space-y-1 max-w-sm",children:[l.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Status"}),l.jsx(Fn,{status:"active"})]}),l.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Priority"}),l.jsx(Ss,{priority:"high"})]}),l.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Assignee"}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(xd,{size:"sm",children:l.jsx(yd,{children:"A"})}),l.jsx("span",{className:"text-xs",children:"Agent Alpha"})]})]}),l.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:"Created"}),l.jsx("span",{className:"text-xs",children:"Jan 15, 2025"})]})]})}),l.jsxs(mn,{title:"Navigation Patterns",children:[l.jsx(pn,{title:"Sidebar nav items",children:l.jsxs("div",{className:"w-60 border border-border rounded-md p-3 space-y-0.5 bg-card",children:[l.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium bg-accent text-accent-foreground",children:[l.jsx(vh,{className:"h-4 w-4"}),"Dashboard"]}),l.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground cursor-pointer",children:[l.jsx(Qi,{className:"h-4 w-4"}),"Issues",l.jsx("span",{className:"ml-auto text-xs bg-primary text-primary-foreground rounded-full px-1.5 py-0.5",children:"12"})]}),l.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground cursor-pointer",children:[l.jsx(Si,{className:"h-4 w-4"}),"Agents"]}),l.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground cursor-pointer",children:[l.jsx(Jl,{className:"h-4 w-4"}),"Projects"]})]})}),l.jsx(pn,{title:"View toggle",children:l.jsxs("div",{className:"flex items-center border border-border rounded-md w-fit",children:[l.jsxs("button",{className:"px-3 py-1.5 text-xs font-medium bg-accent text-foreground rounded-l-md",children:[l.jsx(O2,{className:"h-3.5 w-3.5 inline mr-1"}),"List"]}),l.jsxs("button",{className:"px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-accent/50 rounded-r-md",children:[l.jsx(Yl,{className:"h-3.5 w-3.5 inline mr-1"}),"Org"]})]})})]}),l.jsx(mn,{title:"Grouped List (Issues pattern)",children:l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-muted/50 rounded-t-md",children:[l.jsx(qr,{status:"in_progress"}),l.jsx("span",{className:"text-sm font-medium",children:"In Progress"}),l.jsx("span",{className:"text-xs text-muted-foreground ml-1",children:"2"})]}),l.jsxs("div",{className:"border border-border rounded-b-md",children:[l.jsx(Al,{leading:l.jsx(Ss,{priority:"high"}),identifier:"PAP-101",title:"Build agent heartbeat system",onClick:()=>{}}),l.jsx(Al,{leading:l.jsx(Ss,{priority:"medium"}),identifier:"PAP-102",title:"Add cost tracking dashboard",onClick:()=>{}})]})]})}),l.jsx(mn,{title:"Comment Thread Pattern",children:l.jsxs("div",{className:"space-y-3 max-w-2xl",children:[l.jsx("h3",{className:"text-sm font-semibold",children:"Comments (2)"}),l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"rounded-md border border-border p-3",children:[l.jsxs("div",{className:"flex items-center justify-between mb-1",children:[l.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Agent"}),l.jsx("span",{className:"text-xs text-muted-foreground",children:"Jan 15, 2025"})]}),l.jsx("p",{className:"text-sm",children:"Started working on the authentication module. Will need API keys configured."})]}),l.jsxs("div",{className:"rounded-md border border-border p-3",children:[l.jsxs("div",{className:"flex items-center justify-between mb-1",children:[l.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Human"}),l.jsx("span",{className:"text-xs text-muted-foreground",children:"Jan 16, 2025"})]}),l.jsx("p",{className:"text-sm",children:"API keys have been added to the vault. Please proceed."})]})]}),l.jsxs("div",{className:"space-y-2",children:[l.jsx(dy,{placeholder:"Leave a comment...",rows:3}),l.jsx(ke,{size:"sm",children:"Comment"})]})]})}),l.jsx(mn,{title:"Cost Table Pattern",children:l.jsx("div",{className:"border border-border rounded-lg overflow-hidden",children:l.jsxs("table",{className:"w-full text-xs",children:[l.jsx("thead",{className:"border-b border-border bg-accent/20",children:l.jsxs("tr",{children:[l.jsx("th",{className:"text-left px-3 py-2 font-medium text-muted-foreground",children:"Model"}),l.jsx("th",{className:"text-left px-3 py-2 font-medium text-muted-foreground",children:"Tokens"}),l.jsx("th",{className:"text-left px-3 py-2 font-medium text-muted-foreground",children:"Cost"})]})}),l.jsxs("tbody",{children:[l.jsxs("tr",{className:"border-b border-border",children:[l.jsx("td",{className:"px-3 py-2",children:"claude-sonnet-4-20250514"}),l.jsx("td",{className:"px-3 py-2 font-mono",children:"1.2M"}),l.jsx("td",{className:"px-3 py-2 font-mono",children:"$18.00"})]}),l.jsxs("tr",{className:"border-b border-border",children:[l.jsx("td",{className:"px-3 py-2",children:"claude-haiku-4-20250506"}),l.jsx("td",{className:"px-3 py-2 font-mono",children:"500k"}),l.jsx("td",{className:"px-3 py-2 font-mono",children:"$1.25"})]}),l.jsxs("tr",{children:[l.jsx("td",{className:"px-3 py-2 font-medium",children:"Total"}),l.jsx("td",{className:"px-3 py-2 font-mono",children:"1.7M"}),l.jsx("td",{className:"px-3 py-2 font-mono font-medium",children:"$19.25"})]})]})]})})}),l.jsxs(mn,{title:"Skeletons",children:[l.jsx(pn,{title:"Individual",children:l.jsxs("div",{className:"space-y-2",children:[l.jsx(Kt,{className:"h-4 w-48"}),l.jsx(Kt,{className:"h-8 w-full max-w-sm"}),l.jsx(Kt,{className:"h-20 w-full"})]})}),l.jsx(pn,{title:"Page Skeleton (list)",children:l.jsx("div",{className:"border border-border rounded-md p-4",children:l.jsx(ui,{variant:"list"})})}),l.jsx(pn,{title:"Page Skeleton (detail)",children:l.jsx("div",{className:"border border-border rounded-md p-4",children:l.jsx(ui,{variant:"detail"})})})]}),l.jsx(mn,{title:"Separator",children:l.jsxs("div",{className:"space-y-4",children:[l.jsx("p",{className:"text-sm text-muted-foreground",children:"Horizontal"}),l.jsx(Yi,{}),l.jsxs("div",{className:"flex items-center gap-4 h-8",children:[l.jsx("span",{className:"text-sm",children:"Left"}),l.jsx(Yi,{orientation:"vertical"}),l.jsx("span",{className:"text-sm",children:"Right"})]})]})}),l.jsx(mn,{title:"Common Icons (Lucide)",children:l.jsx("div",{className:"grid grid-cols-4 md:grid-cols-6 gap-4",children:[["Inbox",Fh],["ListTodo",O2],["CircleDot",Qi],["Hexagon",Jl],["Target",Yl],["LayoutDashboard",vh],["Bot",Si],["DollarSign",Ph],["History",qy],["Search",Gc],["Plus",Pr],["Trash2",lu],["Settings",Eg],["User",zp],["Mail",_Y],["Upload",qP],["Zap",KT]].map(([C,_])=>{const E=_;return l.jsxs("div",{className:"flex flex-col items-center gap-1.5 p-2",children:[l.jsx(E,{className:"h-4 w-4 text-muted-foreground"}),l.jsx("span",{className:"text-[10px] text-muted-foreground font-mono",children:C})]},C)})})}),l.jsx(mn,{title:"Keyboard Shortcuts",children:l.jsx("div",{className:"border border-border rounded-md divide-y divide-border text-sm",children:[["Cmd+K / Ctrl+K","Open Command Palette"],["C","New Issue (outside inputs)"],["[","Toggle Sidebar"],["]","Toggle Properties Panel"],["Cmd+1..9 / Ctrl+1..9","Switch Company (by rail order)"],["Cmd+Enter / Ctrl+Enter","Submit markdown comment"]].map(([C,_])=>l.jsxs("div",{className:"flex items-center justify-between px-4 py-2",children:[l.jsx("span",{className:"text-muted-foreground",children:_}),l.jsx("kbd",{className:"px-2 py-0.5 text-xs font-mono bg-muted rounded border border-border",children:C})]},C))})})]})}const uh=200,s2=100,Bb=32,Tqe=80,nS=60;function sg(t){if(t.reports.length===0)return uh;const e=t.reports.reduce((r,s)=>r+sg(s),0),n=(t.reports.length-1)*Bb;return Math.max(uh,e+n)}function Woe(t,e,n){const r=sg(t),s=[];if(t.reports.length>0){const i=t.reports.reduce((c,d)=>c+sg(d),0),o=(t.reports.length-1)*Bb;let a=e+(r-i-o)/2;for(const c of t.reports){const d=sg(c);s.push(Woe(c,a,n+s2+Tqe)),a+=d+Bb}}return{id:t.id,name:t.name,role:t.role,status:t.status,x:e+(r-uh)/2,y:n,children:s}}function Mqe(t){if(t.length===0)return[];t.reduce((s,i)=>s+sg(i),0),(t.length-1)*Bb;let e=nS;const n=nS,r=[];for(const s of t){const i=sg(s);r.push(Woe(s,e,n)),e+=i+Bb}return r}function Rqe(t){const e=[];function n(r){e.push(r),r.children.forEach(n)}return t.forEach(n),e}function Oqe(t){const e=[];function n(r){for(const s of r.children)e.push({parent:r,child:s}),n(s)}return t.forEach(n),e}const Iqe={claude_local:"Claude",codex_local:"Codex",opencode_local:"OpenCode",cursor:"Cursor",openclaw_gateway:"OpenClaw Gateway",process:"Process",http:"HTTP"},Dqe={running:"#22d3ee",active:"#4ade80",paused:"#facc15",idle:"#facc15",error:"#f87171",terminated:"#a3a3a3"},Lqe="#a3a3a3";function Pqe(){const{selectedCompanyId:t}=en(),{setBreadcrumbs:e}=bs(),n=Ti(),{data:r,isLoading:s}=Be({queryKey:te.org(t),queryFn:()=>Ot.org(t),enabled:!!t}),{data:i}=Be({queryKey:te.agents.list(t),queryFn:()=>Ot.list(t),enabled:!!t}),o=v.useMemo(()=>{const M=new Map;for(const O of i??[])M.set(O.id,O);return M},[i]);v.useEffect(()=>{e([{label:"Org Chart"}])},[e]);const a=v.useMemo(()=>Mqe(r??[]),[r]),c=v.useMemo(()=>Rqe(a),[a]),d=v.useMemo(()=>Oqe(a),[a]),f=v.useMemo(()=>{if(c.length===0)return{width:800,height:600};let M=0,O=0;for(const I of c)M=Math.max(M,I.x+uh),O=Math.max(O,I.y+s2);return{width:M+nS,height:O+nS}},[c]),m=v.useRef(null),[p,x]=v.useState({x:0,y:0}),[y,w]=v.useState(1),[k,S]=v.useState(!1),C=v.useRef({x:0,y:0,panX:0,panY:0}),_=v.useRef(!1);v.useEffect(()=>{if(_.current||c.length===0||!m.current)return;_.current=!0;const M=m.current,O=M.clientWidth,I=M.clientHeight,$=(O-40)/f.width,z=(I-40)/f.height,V=Math.min($,z,1),W=f.width*V,J=f.height*V;w(V),x({x:(O-W)/2,y:(I-J)/2})},[c,f]);const E=v.useCallback(M=>{M.button!==0||M.target.closest("[data-org-card]")||(S(!0),C.current={x:M.clientX,y:M.clientY,panX:p.x,panY:p.y})},[p]),j=v.useCallback(M=>{if(!k)return;const O=M.clientX-C.current.x,I=M.clientY-C.current.y;x({x:C.current.panX+O,y:C.current.panY+I})},[k]),R=v.useCallback(()=>{S(!1)},[]),T=v.useCallback(M=>{M.preventDefault();const O=m.current;if(!O)return;const I=O.getBoundingClientRect(),$=M.clientX-I.left,z=M.clientY-I.top,V=M.deltaY<0?1.1:.9,W=Math.min(Math.max(y*V,.2),2),J=W/y;x({x:$-J*($-p.x),y:z-J*(z-p.y)}),w(W)},[y,p]);return t?s?l.jsx(ui,{variant:"org-chart"}):r&&r.length===0?l.jsx(Os,{icon:qT,message:"No organizational hierarchy defined."}):l.jsxs("div",{ref:m,className:"w-full h-[calc(100vh-4rem)] overflow-hidden relative bg-muted/20 border border-border rounded-lg",style:{cursor:k?"grabbing":"grab"},onMouseDown:E,onMouseMove:j,onMouseUp:R,onMouseLeave:R,onWheel:T,children:[l.jsxs("div",{className:"absolute top-3 right-3 z-10 flex flex-col gap-1",children:[l.jsx("button",{className:"w-7 h-7 flex items-center justify-center bg-background border border-border rounded text-sm hover:bg-accent transition-colors",onClick:()=>{const M=Math.min(y*1.2,2),O=m.current;if(O){const I=O.clientWidth/2,$=O.clientHeight/2,z=M/y;x({x:I-z*(I-p.x),y:$-z*($-p.y)})}w(M)},"aria-label":"Zoom in",children:"+"}),l.jsx("button",{className:"w-7 h-7 flex items-center justify-center bg-background border border-border rounded text-sm hover:bg-accent transition-colors",onClick:()=>{const M=Math.max(y*.8,.2),O=m.current;if(O){const I=O.clientWidth/2,$=O.clientHeight/2,z=M/y;x({x:I-z*(I-p.x),y:$-z*($-p.y)})}w(M)},"aria-label":"Zoom out",children:"−"}),l.jsx("button",{className:"w-7 h-7 flex items-center justify-center bg-background border border-border rounded text-[10px] hover:bg-accent transition-colors",onClick:()=>{if(!m.current)return;const M=m.current.clientWidth,O=m.current.clientHeight,I=(M-40)/f.width,$=(O-40)/f.height,z=Math.min(I,$,1),V=f.width*z,W=f.height*z;w(z),x({x:(M-V)/2,y:(O-W)/2})},title:"Fit to screen","aria-label":"Fit chart to screen",children:"Fit"})]}),l.jsx("svg",{className:"absolute inset-0 pointer-events-none",style:{width:"100%",height:"100%"},children:l.jsx("g",{transform:`translate(${p.x}, ${p.y}) scale(${y})`,children:d.map(({parent:M,child:O})=>{const I=M.x+uh/2,$=M.y+s2,z=O.x+uh/2,V=O.y,W=($+V)/2;return l.jsx("path",{d:`M ${I} ${$} L ${I} ${W} L ${z} ${W} L ${z} ${V}`,fill:"none",stroke:"var(--border)",strokeWidth:1.5},`${M.id}-${O.id}`)})})}),l.jsx("div",{className:"absolute inset-0",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${y})`,transformOrigin:"0 0"},children:c.map(M=>{const O=o.get(M.id),I=Dqe[M.status]??Lqe;return l.jsx("div",{"data-org-card":!0,className:"absolute bg-card border border-border rounded-lg shadow-sm hover:shadow-md hover:border-foreground/20 transition-[box-shadow,border-color] duration-150 cursor-pointer select-none",style:{left:M.x,top:M.y,width:uh,minHeight:s2},onClick:()=>n(O?fm(O):`/agents/${M.id}`),children:l.jsxs("div",{className:"flex items-center px-4 py-3 gap-3",children:[l.jsxs("div",{className:"relative shrink-0",children:[l.jsx("div",{className:"w-9 h-9 rounded-full bg-muted flex items-center justify-center",children:l.jsx(Ql,{icon:O==null?void 0:O.icon,className:"h-4.5 w-4.5 text-foreground/70"})}),l.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 h-3 w-3 rounded-full border-2 border-card",style:{backgroundColor:I}})]}),l.jsxs("div",{className:"flex flex-col items-start min-w-0 flex-1",children:[l.jsx("span",{className:"text-sm font-semibold text-foreground leading-tight",children:M.name}),l.jsx("span",{className:"text-[11px] text-muted-foreground leading-tight mt-0.5",children:(O==null?void 0:O.title)??$qe(M.role)}),O&&l.jsx("span",{className:"text-[10px] text-muted-foreground/60 font-mono leading-tight mt-1",children:Iqe[O.adapterType]??O.adapterType})]})]})},M.id)})})]}):l.jsx(Os,{icon:qT,message:"Select a company to view the org chart."})}const Fqe=LR;function $qe(t){return Fqe[t]??t}const Bqe=new Set(["claude_local","codex_local","opencode_local","pi_local","cursor","openclaw_gateway"]);function zqe(t){const{adapterType:e,...n}=Mb,r={...n,adapterType:t};return t==="codex_local"?(r.model=Qg,r.dangerouslyBypassSandbox=Tb):t==="cursor"?r.model=Xg:t==="opencode_local"&&(r.model=""),r}function Vqe(){const{selectedCompanyId:t}=en(),{setBreadcrumbs:e}=bs(),n=Nn(),r=Ti(),[s]=Qb(),i=s.get("adapterType"),[o,a]=v.useState(""),[c,d]=v.useState(""),[f,m]=v.useState("general"),[p,x]=v.useState(""),[y,w]=v.useState(Mb),[k,S]=v.useState(!1),[C,_]=v.useState(!1),[E,j]=v.useState(null),{data:R}=Be({queryKey:te.agents.list(t),queryFn:()=>Ot.list(t),enabled:!!t}),{data:T,error:M,isLoading:O,isFetching:I}=Be({queryKey:t?te.agents.adapterModels(t,y.adapterType):["agents","none","adapter-models",y.adapterType],queryFn:()=>Ot.adapterModels(t,y.adapterType),enabled:!!t}),$=!R||R.length===0,z=$?"ceo":f;v.useEffect(()=>{e([{label:"Agents",href:"/agents"},{label:"New Agent"}])},[e]),v.useEffect(()=>{$&&(o||a("CEO"),c||d("CEO"))},[$]),v.useEffect(()=>{const F=i;F&&Bqe.has(F)&&w(L=>L.adapterType===F?L:zqe(F))},[i]);const V=yt({mutationFn:F=>Ot.hire(t,F),onSuccess:F=>{n.invalidateQueries({queryKey:te.agents.list(t)}),n.invalidateQueries({queryKey:te.approvals.list(t)}),r(fm(F.agent))},onError:F=>{j(F instanceof Error?F.message:"Failed to create agent")}});function W(){return im(y.adapterType).buildAdapterConfig(y)}function J(){if(!(!t||!o.trim())){if(j(null),y.adapterType==="opencode_local"){const F=y.model.trim();if(!F){j("OpenCode requires an explicit model in provider/model format.");return}if(M){j(M instanceof Error?M.message:"Failed to load OpenCode models.");return}if(O||I){j("OpenCode models are still loading. Please wait and try again.");return}const L=T??[];if(!L.some(K=>K.id===F)){j(L.length===0?"No OpenCode models discovered. Run `opencode models` and authenticate providers.":`Configured OpenCode model is unavailable: ${F}`);return}}V.mutate({name:o.trim(),role:z,...c.trim()?{title:c.trim()}:{},...p?{reportsTo:p}:{},adapterType:y.adapterType,adapterConfig:W(),runtimeConfig:{heartbeat:{enabled:y.heartbeatEnabled,intervalSec:y.intervalSec,wakeOnDemand:!0,cooldownSec:10,maxConcurrentRuns:1}},budgetMonthlyCents:0})}}const G=(R??[]).find(F=>F.id===p);return l.jsxs("div",{className:"mx-auto max-w-2xl space-y-6",children:[l.jsxs("div",{children:[l.jsx("h1",{className:"text-lg font-semibold",children:"New Agent"}),l.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Advanced agent configuration"})]}),l.jsxs("div",{className:"border border-border",children:[l.jsx("div",{className:"px-4 pt-4 pb-2",children:l.jsx("input",{className:"w-full text-lg font-semibold bg-transparent outline-none placeholder:text-muted-foreground/50",placeholder:"Agent name",value:o,onChange:F=>a(F.target.value),autoFocus:!0})}),l.jsx("div",{className:"px-4 pb-2",children:l.jsx("input",{className:"w-full bg-transparent outline-none text-sm text-muted-foreground placeholder:text-muted-foreground/40",placeholder:"Title (e.g. VP of Engineering)",value:c,onChange:F=>d(F.target.value)})}),l.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-2 border-t border-border flex-wrap",children:[l.jsxs(Bn,{open:k,onOpenChange:S,children:[l.jsx(zn,{asChild:!0,children:l.jsxs("button",{className:re("inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",$&&"opacity-60 cursor-not-allowed"),disabled:$,children:[l.jsx(AY,{className:"h-3 w-3 text-muted-foreground"}),Ry[z]??z]})}),l.jsx(Vn,{className:"w-36 p-1",align:"start",children:nY.map(F=>l.jsx("button",{className:re("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",F===f&&"bg-accent"),onClick:()=>{m(F),S(!1)},children:Ry[F]??F},F))})]}),l.jsxs(Bn,{open:C,onOpenChange:_,children:[l.jsx(zn,{asChild:!0,children:l.jsx("button",{className:re("inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",$&&"opacity-60 cursor-not-allowed"),disabled:$,children:G?l.jsxs(l.Fragment,{children:[l.jsx(Ql,{icon:G.icon,className:"h-3 w-3 text-muted-foreground"}),`Reports to ${G.name}`]}):l.jsxs(l.Fragment,{children:[l.jsx(zp,{className:"h-3 w-3 text-muted-foreground"}),$?"Reports to: N/A (CEO)":"Reports to..."]})})}),l.jsxs(Vn,{className:"w-48 p-1",align:"start",children:[l.jsx("button",{className:re("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",!p&&"bg-accent"),onClick:()=>{x(""),_(!1)},children:"No manager"}),(R??[]).map(F=>l.jsxs("button",{className:re("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 truncate",F.id===p&&"bg-accent"),onClick:()=>{x(F.id),_(!1)},children:[l.jsx(Ql,{icon:F.icon,className:"shrink-0 h-3 w-3 text-muted-foreground"}),F.name,l.jsx("span",{className:"text-muted-foreground ml-auto",children:Ry[F.role]??F.role})]},F.id))]})]})]}),l.jsx(eoe,{mode:"create",values:y,onChange:F=>w(L=>({...L,...F})),adapterModels:T}),l.jsxs("div",{className:"border-t border-border px-4 py-3",children:[$&&l.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"This will be the CEO"}),E&&l.jsx("p",{className:"text-xs text-destructive mb-2",children:E}),l.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l.jsx(ke,{variant:"outline",size:"sm",onClick:()=>r("/agents"),children:"Cancel"}),l.jsx(ke,{size:"sm",disabled:!o.trim()||V.isPending,onClick:J,children:V.isPending?"Creating…":"Create agent"})]})]})]})]})}function Hqe(){const t=Nn(),e=Ti(),[n]=Qb(),[r,s]=v.useState("sign_in"),[i,o]=v.useState(""),[a,c]=v.useState(""),[d,f]=v.useState(""),[m,p]=v.useState(null),x=v.useMemo(()=>n.get("next")||"/",[n]),{data:y,isLoading:w}=Be({queryKey:te.auth.session,queryFn:()=>Ua.getSession(),retry:!1});v.useEffect(()=>{y&&e(x,{replace:!0})},[y,e,x]);const k=yt({mutationFn:async()=>{if(r==="sign_in"){await Ua.signInEmail({email:a.trim(),password:d});return}await Ua.signUpEmail({name:i.trim(),email:a.trim(),password:d})},onSuccess:async()=>{p(null),await t.invalidateQueries({queryKey:te.auth.session}),await t.invalidateQueries({queryKey:te.companies.all}),e(x,{replace:!0})},onError:C=>{p(C instanceof Error?C.message:"Authentication failed")}}),S=a.trim().length>0&&d.trim().length>=8&&(r==="sign_in"||i.trim().length>0);return w?l.jsx("div",{className:"fixed inset-0 flex items-center justify-center",children:l.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading…"})}):l.jsxs("div",{className:"fixed inset-0 flex bg-background",children:[l.jsx("div",{className:"w-full md:w-1/2 flex flex-col overflow-y-auto",children:l.jsxs("div",{className:"w-full max-w-md mx-auto my-auto px-8 py-12",children:[l.jsxs("div",{className:"flex items-center gap-2 mb-8",children:[l.jsx($h,{className:"h-4 w-4 text-muted-foreground"}),l.jsx("span",{className:"text-sm font-medium",children:"Paperclip"})]}),l.jsx("h1",{className:"text-xl font-semibold",children:r==="sign_in"?"Sign in to Paperclip":"Create your Paperclip account"}),l.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:r==="sign_in"?"Use your email and password to access this instance.":"Create an account for this instance. Email confirmation is not required in v1."}),l.jsxs("form",{className:"mt-6 space-y-4",onSubmit:C=>{C.preventDefault(),k.mutate()},children:[r==="sign_up"&&l.jsxs("div",{children:[l.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Name"}),l.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",value:i,onChange:C=>o(C.target.value),autoComplete:"name",autoFocus:!0})]}),l.jsxs("div",{children:[l.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Email"}),l.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",type:"email",value:a,onChange:C=>c(C.target.value),autoComplete:"email",autoFocus:r==="sign_in"})]}),l.jsxs("div",{children:[l.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Password"}),l.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50",type:"password",value:d,onChange:C=>f(C.target.value),autoComplete:r==="sign_in"?"current-password":"new-password"})]}),m&&l.jsx("p",{className:"text-xs text-destructive",children:m}),l.jsx(ke,{type:"submit",disabled:!S||k.isPending,className:"w-full",children:k.isPending?"Working…":r==="sign_in"?"Sign In":"Create Account"})]}),l.jsxs("div",{className:"mt-5 text-sm text-muted-foreground",children:[r==="sign_in"?"Need an account?":"Already have an account?"," ",l.jsx("button",{type:"button",className:"font-medium text-foreground underline underline-offset-2",onClick:()=>{p(null),s(r==="sign_in"?"sign_up":"sign_in")},children:r==="sign_in"?"Create one":"Sign in"})]})]})}),l.jsx("div",{className:"hidden md:block w-1/2 overflow-hidden",children:l.jsx(Pie,{})})]})}function Uqe(){const t=Nn(),e=Eu(),[n]=Qb(),r=(e.token??"").trim(),s=(n.get("code")??"").trim(),i=v.useMemo(()=>`/board-claim/${encodeURIComponent(r)}${s?`?code=${encodeURIComponent(s)}`:""}`,[r,s]),o=Be({queryKey:te.auth.session,queryFn:()=>Ua.getSession(),retry:!1}),a=Be({queryKey:["board-claim",r,s],queryFn:()=>Ha.getBoardClaimStatus(r,s),enabled:r.length>0&&s.length>0,retry:!1}),c=yt({mutationFn:()=>Ha.claimBoard(r,s),onSuccess:async()=>{await t.invalidateQueries({queryKey:te.auth.session}),await t.invalidateQueries({queryKey:te.health}),await t.invalidateQueries({queryKey:te.companies.all}),await t.invalidateQueries({queryKey:te.companies.stats}),await a.refetch()}});if(!r||!s)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"Invalid board claim URL."});if(a.isLoading||o.isLoading)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading claim challenge..."});if(a.error)return l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-lg font-semibold",children:"Claim challenge unavailable"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:a.error instanceof Error?a.error.message:"Challenge is invalid or expired."})]})});const d=a.data;return d?d.status==="claimed"?l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-lg font-semibold",children:"Board ownership claimed"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"This instance is now linked to your authenticated user."}),l.jsx(ke,{asChild:!0,className:"mt-4",children:l.jsx(Bt,{to:"/",children:"Open board"})})]})}):o.data?l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-xl font-semibold",children:"Claim Board ownership"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"This will promote your user to instance admin and migrate company ownership access from local trusted mode."}),c.error&&l.jsx("p",{className:"mt-3 text-sm text-destructive",children:c.error instanceof Error?c.error.message:"Failed to claim board ownership"}),l.jsx(ke,{className:"mt-5",onClick:()=>c.mutate(),disabled:c.isPending,children:c.isPending?"Claiming…":"Claim ownership"})]})}):l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-lg font-semibold",children:"Sign in required"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Sign in or create an account, then return to this page to claim Board ownership."}),l.jsx(ke,{asChild:!0,className:"mt-4",children:l.jsx(Bt,{to:`/auth?next=${encodeURIComponent(i)}`,children:"Sign in / Create account"})})]})}):l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"Claim challenge unavailable."})}const qqe=[...HS],Kqe={claude_local:"Claude (local)",codex_local:"Codex (local)",opencode_local:"OpenCode (local)",openclaw_gateway:"OpenClaw Gateway",cursor:"Cursor (local)",process:"Process",http:"HTTP"},VU=new Set(["claude_local","codex_local","opencode_local","cursor"]);function Wqe(t){return new Date(t).toLocaleString()}function J0(t,e){let n=t;for(const r of e){if(!n||typeof n!="object")return null;n=n[r]}return typeof n=="string"&&n.trim().length>0?n:null}function Gqe(){var T;const t=Nn(),n=(Eu().token??"").trim(),[r,s]=v.useState("human"),[i,o]=v.useState(""),[a,c]=v.useState("claude_local"),[d,f]=v.useState(""),[m,p]=v.useState(null),[x,y]=v.useState(null),w=Be({queryKey:te.health,queryFn:()=>n6.get(),retry:!1}),k=Be({queryKey:te.auth.session,queryFn:()=>Ua.getSession(),retry:!1}),S=Be({queryKey:te.access.invite(n),queryFn:()=>Ha.getInvite(n),enabled:n.length>0,retry:!1}),C=S.data,_=(C==null?void 0:C.allowedJoinTypes)??"both",E=v.useMemo(()=>(C==null?void 0:C.inviteType)==="bootstrap_ceo"?["human"]:_==="both"?["human","agent"]:[_],[C==null?void 0:C.inviteType,_]);v.useEffect(()=>{E.includes(r)||s(E[0]??"human")},[E,r]);const j=r==="human"&&((T=w.data)==null?void 0:T.deploymentMode)==="authenticated"&&!k.data,R=yt({mutationFn:async()=>{if(!C)throw new Error("Invite not found");return C.inviteType==="bootstrap_ceo"?Ha.acceptInvite(n,{requestType:"human"}):r==="human"?Ha.acceptInvite(n,{requestType:"human"}):Ha.acceptInvite(n,{requestType:"agent",agentName:i.trim(),adapterType:a,capabilities:d.trim()||null})},onSuccess:async M=>{y(null),await t.invalidateQueries({queryKey:te.auth.session}),await t.invalidateQueries({queryKey:te.companies.all});const O=M&&typeof M=="object"&&"bootstrapAccepted"in M;p({kind:O?"bootstrap":"join",payload:M})},onError:M=>{y(M instanceof Error?M.message:"Failed to accept invite")}});if(!n)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:"Invalid invite token."});if(S.isLoading||w.isLoading||k.isLoading)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading invite..."});if(S.error||!C)return l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-lg font-semibold",children:"Invite not available"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"This invite may be expired, revoked, or already used."})]})});if((m==null?void 0:m.kind)==="bootstrap")return l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-lg font-semibold",children:"Bootstrap complete"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"The first instance admin is now configured. You can continue to the board."}),l.jsx(ke,{asChild:!0,className:"mt-4",children:l.jsx(Bt,{to:"/",children:"Open board"})})]})});if((m==null?void 0:m.kind)==="join"){const M=m.payload,O=typeof M.claimSecret=="string"?M.claimSecret:null,I=typeof M.claimApiKeyPath=="string"?M.claimApiKeyPath:null,$=J0(M.onboarding,["skill","url"]),z=J0(M.onboarding,["skill","path"]),V=J0(M.onboarding,["skill","installPath"]),W=J0(M.onboarding,["textInstructions","url"]),J=J0(M.onboarding,["textInstructions","path"]),G=Array.isArray(M.diagnostics)?M.diagnostics:[];return l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-lg font-semibold",children:"Join request submitted"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Your request is pending admin approval. You will not have access until approved."}),l.jsxs("div",{className:"mt-4 rounded-md border border-border bg-muted/30 p-3 text-xs text-muted-foreground",children:["Request ID: ",l.jsx("span",{className:"font-mono",children:M.id})]}),O&&I&&l.jsxs("div",{className:"mt-3 space-y-1 rounded-md border border-border bg-muted/30 p-3 text-xs text-muted-foreground",children:[l.jsx("p",{className:"font-medium text-foreground",children:"One-time claim secret (save now)"}),l.jsx("p",{className:"font-mono break-all",children:O}),l.jsxs("p",{className:"font-mono break-all",children:["POST ",I]})]}),($||z||V)&&l.jsxs("div",{className:"mt-3 space-y-1 rounded-md border border-border bg-muted/30 p-3 text-xs text-muted-foreground",children:[l.jsx("p",{className:"font-medium text-foreground",children:"Paperclip skill bootstrap"}),$&&l.jsxs("p",{className:"font-mono break-all",children:["GET ",$]}),!$&&z&&l.jsxs("p",{className:"font-mono break-all",children:["GET ",z]}),V&&l.jsxs("p",{className:"font-mono break-all",children:["Install to ",V]})]}),(W||J)&&l.jsxs("div",{className:"mt-3 space-y-1 rounded-md border border-border bg-muted/30 p-3 text-xs text-muted-foreground",children:[l.jsx("p",{className:"font-medium text-foreground",children:"Agent-readable onboarding text"}),W&&l.jsxs("p",{className:"font-mono break-all",children:["GET ",W]}),!W&&J&&l.jsxs("p",{className:"font-mono break-all",children:["GET ",J]})]}),G.length>0&&l.jsxs("div",{className:"mt-3 space-y-1 rounded-md border border-border bg-muted/30 p-3 text-xs text-muted-foreground",children:[l.jsx("p",{className:"font-medium text-foreground",children:"Connectivity diagnostics"}),G.map((F,L)=>l.jsxs("div",{className:"space-y-0.5",children:[l.jsxs("p",{className:F.level==="warn"?"text-amber-600 dark:text-amber-400":void 0,children:["[",F.level,"] ",F.message]}),F.hint&&l.jsx("p",{className:"font-mono break-all",children:F.hint})]},`${F.code}:${L}`))]})]})})}return l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-xl font-semibold",children:C.inviteType==="bootstrap_ceo"?"Bootstrap your Paperclip instance":"Join this Paperclip company"}),l.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["Invite expires ",Wqe(C.expiresAt),"."]}),C.inviteType!=="bootstrap_ceo"&&l.jsx("div",{className:"mt-5 flex gap-2",children:E.map(M=>l.jsxs("button",{type:"button",onClick:()=>s(M),className:`rounded-md border px-3 py-1.5 text-sm ${r===M?"border-foreground bg-foreground text-background":"border-border bg-background text-foreground"}`,children:["Join as ",M]},M))}),r==="agent"&&C.inviteType!=="bootstrap_ceo"&&l.jsxs("div",{className:"mt-4 space-y-3",children:[l.jsxs("label",{className:"block text-sm",children:[l.jsx("span",{className:"mb-1 block text-muted-foreground",children:"Agent name"}),l.jsx("input",{className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm",value:i,onChange:M=>o(M.target.value)})]}),l.jsxs("label",{className:"block text-sm",children:[l.jsx("span",{className:"mb-1 block text-muted-foreground",children:"Adapter type"}),l.jsx("select",{className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm",value:a,onChange:M=>c(M.target.value),children:qqe.map(M=>l.jsxs("option",{value:M,disabled:!VU.has(M),children:[Kqe[M],VU.has(M)?"":" (Coming soon)"]},M))})]}),l.jsxs("label",{className:"block text-sm",children:[l.jsx("span",{className:"mb-1 block text-muted-foreground",children:"Capabilities (optional)"}),l.jsx("textarea",{className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm",rows:4,value:d,onChange:M=>f(M.target.value)})]})]}),j&&l.jsxs("div",{className:"mt-4 rounded-md border border-border bg-muted/30 p-3 text-sm",children:["Sign in or create an account before submitting a human join request.",l.jsx("div",{className:"mt-2",children:l.jsx(ke,{asChild:!0,size:"sm",variant:"outline",children:l.jsx(Bt,{to:`/auth?next=${encodeURIComponent(`/invite/${n}`)}`,children:"Sign in / Create account"})})})]}),x&&l.jsx("p",{className:"mt-3 text-sm text-destructive",children:x}),l.jsx(ke,{className:"mt-5",disabled:R.isPending||r==="agent"&&C.inviteType!=="bootstrap_ceo"&&i.trim().length===0||j,onClick:()=>R.mutate(),children:R.isPending?"Submitting…":C.inviteType==="bootstrap_ceo"?"Accept bootstrap invite":"Submit join request"})]})})}function Jqe({hasActiveInvite:t=!1}){return l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-xl font-semibold",children:"Instance setup required"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:t?"No instance admin exists yet. A bootstrap invite is already active. Check your Paperclip startup logs for the first admin invite URL, or run this command to rotate it:":"No instance admin exists yet. Run this command in your Paperclip environment to generate the first admin invite URL:"}),l.jsx("pre",{className:"mt-4 overflow-x-auto rounded-md border border-border bg-muted/30 p-3 text-xs",children:"pnpm paperclipai auth bootstrap-ceo"})]})})}function Yqe(){var s,i;const t=Fr(),e=Be({queryKey:te.health,queryFn:()=>n6.get(),retry:!1,refetchInterval:o=>{const a=o.state.data;return(a==null?void 0:a.deploymentMode)==="authenticated"&&a.bootstrapStatus==="bootstrap_pending"?2e3:!1},refetchIntervalInBackground:!0}),n=((s=e.data)==null?void 0:s.deploymentMode)==="authenticated",r=Be({queryKey:te.auth.session,queryFn:()=>Ua.getSession(),enabled:n,retry:!1});if(e.isLoading||n&&r.isLoading)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading..."});if(e.error)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:e.error instanceof Error?e.error.message:"Failed to load app state"});if(n&&((i=e.data)==null?void 0:i.bootstrapStatus)==="bootstrap_pending")return l.jsx(Jqe,{hasActiveInvite:e.data.bootstrapInviteActive});if(n&&!r.data){const o=encodeURIComponent(`${t.pathname}${t.search}`);return l.jsx(vo,{to:`/auth?next=${o}`,replace:!0})}return l.jsx(gq,{})}function Zqe(){return l.jsxs(l.Fragment,{children:[l.jsx(Nt,{index:!0,element:l.jsx(vo,{to:"dashboard",replace:!0})}),l.jsx(Nt,{path:"dashboard",element:l.jsx(xBe,{})}),l.jsx(Nt,{path:"companies",element:l.jsx(vBe,{})}),l.jsx(Nt,{path:"company/settings",element:l.jsx(Sqe,{})}),l.jsx(Nt,{path:"org",element:l.jsx(Pqe,{})}),l.jsx(Nt,{path:"agents",element:l.jsx(vo,{to:"/agents/all",replace:!0})}),l.jsx(Nt,{path:"agents/all",element:l.jsx(fC,{})}),l.jsx(Nt,{path:"agents/active",element:l.jsx(fC,{})}),l.jsx(Nt,{path:"agents/paused",element:l.jsx(fC,{})}),l.jsx(Nt,{path:"agents/error",element:l.jsx(fC,{})}),l.jsx(Nt,{path:"agents/new",element:l.jsx(Vqe,{})}),l.jsx(Nt,{path:"agents/:agentId",element:l.jsx(LA,{})}),l.jsx(Nt,{path:"agents/:agentId/:tab",element:l.jsx(LA,{})}),l.jsx(Nt,{path:"agents/:agentId/runs/:runId",element:l.jsx(LA,{})}),l.jsx(Nt,{path:"projects",element:l.jsx(lUe,{})}),l.jsx(Nt,{path:"projects/:projectId",element:l.jsx(vC,{})}),l.jsx(Nt,{path:"projects/:projectId/overview",element:l.jsx(vC,{})}),l.jsx(Nt,{path:"projects/:projectId/issues",element:l.jsx(vC,{})}),l.jsx(Nt,{path:"projects/:projectId/issues/:filter",element:l.jsx(vC,{})}),l.jsx(Nt,{path:"issues",element:l.jsx(AUe,{})}),l.jsx(Nt,{path:"issues/all",element:l.jsx(vo,{to:"/issues",replace:!0})}),l.jsx(Nt,{path:"issues/active",element:l.jsx(vo,{to:"/issues",replace:!0})}),l.jsx(Nt,{path:"issues/backlog",element:l.jsx(vo,{to:"/issues",replace:!0})}),l.jsx(Nt,{path:"issues/done",element:l.jsx(vo,{to:"/issues",replace:!0})}),l.jsx(Nt,{path:"issues/recent",element:l.jsx(vo,{to:"/issues",replace:!0})}),l.jsx(Nt,{path:"issues/:issueId",element:l.jsx(GUe,{})}),l.jsx(Nt,{path:"goals",element:l.jsx(JUe,{})}),l.jsx(Nt,{path:"goals/:goalId",element:l.jsx(QUe,{})}),l.jsx(Nt,{path:"approvals",element:l.jsx(vo,{to:"/approvals/pending",replace:!0})}),l.jsx(Nt,{path:"approvals/pending",element:l.jsx(DU,{})}),l.jsx(Nt,{path:"approvals/all",element:l.jsx(DU,{})}),l.jsx(Nt,{path:"approvals/:approvalId",element:l.jsx(nqe,{})}),l.jsx(Nt,{path:"costs",element:l.jsx(lqe,{})}),l.jsx(Nt,{path:"activity",element:l.jsx(dqe,{})}),l.jsx(Nt,{path:"inbox",element:l.jsx(vo,{to:"/inbox/new",replace:!0})}),l.jsx(Nt,{path:"inbox/new",element:l.jsx(BU,{})}),l.jsx(Nt,{path:"inbox/all",element:l.jsx(BU,{})}),l.jsx(Nt,{path:"design-guide",element:l.jsx(Aqe,{})})]})}function Qqe(){const{companies:t,selectedCompany:e,loading:n}=en(),{onboardingOpen:r}=$r();if(n)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading..."});if(r)return l.jsx(NM,{autoOpen:!1});const s=e??t[0]??null;return s?l.jsx(vo,{to:`/${s.issuePrefix}/dashboard`,replace:!0}):l.jsx(NM,{})}function xo(){const t=Fr(),{companies:e,selectedCompany:n,loading:r}=en();if(r)return l.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading..."});const s=n??e[0]??null;return s?l.jsx(vo,{to:`/${s.issuePrefix}${t.pathname}${t.search}${t.hash}`,replace:!0}):l.jsx(NM,{})}function NM({autoOpen:t=!0}){const{openOnboarding:e}=$r(),n=v.useRef(!1);return v.useEffect(()=>{t&&(n.current||(n.current=!0,e()))},[t,e]),l.jsx("div",{className:"mx-auto max-w-xl py-10",children:l.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[l.jsx("h1",{className:"text-xl font-semibold",children:"Create your first company"}),l.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Get started by creating a company."}),l.jsx("div",{className:"mt-4",children:l.jsx(ke,{onClick:()=>e(),children:"New Company"})})]})})}function Xqe(){return l.jsxs(l.Fragment,{children:[l.jsxs(yue,{children:[l.jsx(Nt,{path:"auth",element:l.jsx(Hqe,{})}),l.jsx(Nt,{path:"board-claim/:token",element:l.jsx(Uqe,{})}),l.jsx(Nt,{path:"invite/:token",element:l.jsx(Gqe,{})}),l.jsxs(Nt,{element:l.jsx(Yqe,{}),children:[l.jsx(Nt,{index:!0,element:l.jsx(Qqe,{})}),l.jsx(Nt,{path:"companies",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"issues",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"issues/:issueId",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"agents",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"agents/new",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"agents/:agentId",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"agents/:agentId/:tab",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"agents/:agentId/runs/:runId",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"projects",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"projects/:projectId",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"projects/:projectId/overview",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"projects/:projectId/issues",element:l.jsx(xo,{})}),l.jsx(Nt,{path:"projects/:projectId/issues/:filter",element:l.jsx(xo,{})}),l.jsx(Nt,{path:":companyPrefix",element:l.jsx(yFe,{}),children:Zqe()})]})]}),l.jsx(eBe,{})]})}const eKe=1e4,tKe=3,nKe=2e3;function An(t){return typeof t=="string"&&t.length>0?t:null}function w6(t){return typeof t!="object"||t===null||Array.isArray(t)?null:t}function o5(t){return t.slice(0,8)}function Goe(t,e,n){const r=t.getQueryData(te.agents.list(e));if(!r)return null;const s=r.find(i=>i.id===n);return(s==null?void 0:s.name)??null}function nh(t,e){return t.length<=e?t:t.slice(0,e-1)+"…"}function rKe(t,e,n,r){return n==="agent"&&r?Goe(t,e,r)??`Agent ${o5(r)}`:n==="system"?"System":n==="user"&&r?"Board":"Someone"}function Joe(t,e,n,r){const s=new Set([n]),i=t.getQueryData(te.issues.detail(n)),o=t.getQueryData(te.issues.list(e)),a=An(r==null?void 0:r.identifier)??An(r==null?void 0:r.issueIdentifier);a&&s.add(a),i!=null&&i.id&&s.add(i.id),i!=null&&i.identifier&&s.add(i.identifier);const c=o==null?void 0:o.find(d=>!!(d.id===n||d.identifier&&d.identifier===n||a&&d.identifier===a));return c!=null&&c.id&&s.add(c.id),c!=null&&c.identifier&&s.add(c.identifier),Array.from(s)}function sKe(t,e,n,r){var f;const s=Joe(t,e,n,r),i=s.map(m=>t.getQueryData(te.issues.detail(m))).find(m=>!!m),o=(f=t.getQueryData(te.issues.list(e)))==null?void 0:f.find(m=>s.some(p=>m.id===p||m.identifier===p)),a=i??o??null,c=An(r==null?void 0:r.identifier)??An(r==null?void 0:r.issueIdentifier)??(a==null?void 0:a.identifier)??`Issue ${o5(n)}`,d=An(r==null?void 0:r.title)??An(r==null?void 0:r.issueTitle)??(a==null?void 0:a.title)??null;return{ref:c,title:d,label:d?`${c} - ${nh(d,72)}`:c,href:`/issues/${(a==null?void 0:a.identifier)??n}`}}const iKe=new Set(["issue.created","issue.updated","issue.comment_added"]),oKe=new Set(["running","error"]),aKe=new Set(["succeeded","failed","timed_out","cancelled"]);function lKe(t){if(!t)return null;const e=[];if(typeof t.status=="string"&&e.push(`status -> ${t.status.replace(/_/g," ")}`),typeof t.priority=="string"&&e.push(`priority -> ${t.priority}`),typeof t.assigneeAgentId=="string"||typeof t.assigneeUserId=="string"?e.push("reassigned"):(t.assigneeAgentId===null||t.assigneeUserId===null)&&e.push("unassigned"),t.reopened===!0){const n=An(t.reopenedFrom);e.push(n?`reopened from ${n.replace(/_/g," ")}`:"reopened")}return typeof t.title=="string"&&e.push("title changed"),typeof t.description=="string"&&e.push("description changed"),e.length>0?e.join(", "):null}function cKe(t,e,n,r){const s=An(n.entityType),i=An(n.entityId),o=An(n.action),a=w6(n.details),c=An(n.actorId),d=An(n.actorType);if(s!=="issue"||!i||!o||!iKe.has(o))return null;const f=sKe(t,e,i,a),m=rKe(t,e,d,c);if(d==="user"&&!!r.userId&&c===r.userId||d==="agent"&&!1)return null;if(o==="issue.created")return{title:`${m} created ${f.ref}`,body:f.title?nh(f.title,96):void 0,tone:"success",action:{label:`View ${f.ref}`,href:f.href},dedupeKey:`activity:${o}:${i}`};if(o==="issue.updated"){if(An(a==null?void 0:a.source)==="comment")return null;const j=lKe(a),R=j?f.title?`${nh(f.title,64)} - ${j}`:j:f.title?nh(f.title,96):f.label;return{title:`${m} updated ${f.ref}`,body:nh(R,100),tone:"info",action:{label:`View ${f.ref}`,href:f.href},dedupeKey:`activity:${o}:${i}`}}const x=An(a==null?void 0:a.commentId),y=An(a==null?void 0:a.bodySnippet),w=(a==null?void 0:a.reopened)===!0,k=(a==null?void 0:a.updated)===!0,S=An(a==null?void 0:a.reopenedFrom),C=w?S?`reopened from ${S.replace(/_/g," ")}`:"reopened":null,_=w?`${m} reopened and commented on ${f.ref}`:k?`${m} commented and updated ${f.ref}`:`${m} commented on ${f.ref}`,E=y?C?`${C} - ${y.replace(/^#+\s*/m,"").replace(/\n/g," ")}`:y.replace(/^#+\s*/m,"").replace(/\n/g," "):C?f.title?`${C} - ${f.title}`:C:f.title??void 0;return{title:_,body:E?nh(E,96):void 0,tone:"info",action:{label:`View ${f.ref}`,href:f.href},dedupeKey:`activity:${o}:${i}:${x??"na"}`}}function uKe(t){const e=An(t.entityType),n=An(t.action),r=An(t.entityId),s=w6(t.details);return e!=="join_request"||!n||!r||n!=="join.requested"&&n!=="join.request_replayed"?null:{title:`${An(s==null?void 0:s.requestType)==="agent"?"Agent":"Someone"} wants to join`,body:"A new join request is waiting for approval.",tone:"info",action:{label:"View inbox",href:"/inbox/new"},dedupeKey:`join-request:${r}`}}function dKe(t,e,n,r){const s=An(t.agentId),i=An(t.status);if(!s||!i||!oKe.has(i))return null;const o=i==="error"?"error":"info",a=e(s)??`Agent ${o5(s)}`,c=i==="running"?`${a} started`:`${a} errored`,d=n.getQueryData(te.agents.list(r)),f=d==null?void 0:d.find(p=>p.id===s),m=(f==null?void 0:f.title)??void 0;return{title:c,body:m,tone:o,action:{label:"View agent",href:`/agents/${s}`},dedupeKey:`agent-status:${s}:${i}`}}function fKe(t,e){const n=An(t.runId),r=An(t.agentId),s=An(t.status);if(!n||!r||!s||!aKe.has(s))return null;const i=An(t.error),o=An(t.triggerDetail),a=e(r)??`Agent ${o5(r)}`,c=s==="succeeded"?"success":s==="cancelled"?"warn":"error",f=`${a} run ${s==="succeeded"?"succeeded":s==="failed"?"failed":s==="timed_out"?"timed out":"cancelled"}`;let m;return i?m=nh(i,100):o&&(m=`Trigger: ${o}`),{title:f,body:m,tone:c,ttlMs:s==="succeeded"?5e3:7e3,action:{label:"View run",href:`/agents/${r}/runs/${n}`},dedupeKey:`run-status:${n}:${s}`}}function hKe(t,e,n){t.invalidateQueries({queryKey:te.liveRuns(e)}),t.invalidateQueries({queryKey:te.heartbeats(e)}),t.invalidateQueries({queryKey:te.agents.list(e)}),t.invalidateQueries({queryKey:te.dashboard(e)}),t.invalidateQueries({queryKey:te.costs(e)}),t.invalidateQueries({queryKey:te.sidebarBadges(e)});const r=An(n.agentId);r&&(t.invalidateQueries({queryKey:te.agents.detail(r)}),t.invalidateQueries({queryKey:te.heartbeats(e,r)}))}function mKe(t,e,n){t.invalidateQueries({queryKey:te.activity(e)}),t.invalidateQueries({queryKey:te.dashboard(e)}),t.invalidateQueries({queryKey:te.sidebarBadges(e)});const r=An(n.entityType),s=An(n.entityId);if(r==="issue"){if(t.invalidateQueries({queryKey:te.issues.list(e)}),s){const i=w6(n.details),o=Joe(t,e,s,i);for(const a of o)t.invalidateQueries({queryKey:te.issues.detail(a)}),t.invalidateQueries({queryKey:te.issues.comments(a)}),t.invalidateQueries({queryKey:te.issues.activity(a)}),t.invalidateQueries({queryKey:te.issues.runs(a)}),t.invalidateQueries({queryKey:te.issues.liveRuns(a)}),t.invalidateQueries({queryKey:te.issues.activeRun(a)})}return}if(r==="agent"){t.invalidateQueries({queryKey:te.agents.list(e)}),t.invalidateQueries({queryKey:te.org(e)}),s&&(t.invalidateQueries({queryKey:te.agents.detail(s)}),t.invalidateQueries({queryKey:te.heartbeats(e,s)}));return}if(r==="project"){t.invalidateQueries({queryKey:te.projects.list(e)}),s&&t.invalidateQueries({queryKey:te.projects.detail(s)});return}if(r==="goal"){t.invalidateQueries({queryKey:te.goals.list(e)}),s&&t.invalidateQueries({queryKey:te.goals.detail(s)});return}if(r==="approval"){t.invalidateQueries({queryKey:te.approvals.list(e)});return}if(r==="join_request"){t.invalidateQueries({queryKey:te.access.joinRequests(e)});return}if(r==="cost_event"){t.invalidateQueries({queryKey:te.costs(e)});return}r==="company"&&t.invalidateQueries({queryKey:te.companies.all})}function pKe(t,e){const n=Date.now();if(n<t.suppressUntil)return!0;const r=t.cooldownHits.get(e);if(!r)return!1;const s=r.filter(i=>n-i<eKe);return t.cooldownHits.set(e,s),s.length>=tKe}function gKe(t,e){const n=Date.now(),r=t.cooldownHits.get(e)??[];r.push(n),t.cooldownHits.set(e,r)}function qA(t,e,n,r){if(pKe(t,n))return;e(r)!==null&&gKe(t,n)}function xKe(t,e,n,r,s,i){if(n.companyId!==e)return;const o=c=>Goe(t,e,c),a=n.payload??{};if(n.type!=="heartbeat.run.log"){if(n.type==="heartbeat.run.queued"||n.type==="heartbeat.run.status"){if(hKe(t,e,a),n.type==="heartbeat.run.status"){const c=fKe(a,o);c&&qA(s,r,"run-status",c)}return}if(n.type!=="heartbeat.run.event"){if(n.type==="agent.status"){t.invalidateQueries({queryKey:te.agents.list(e)}),t.invalidateQueries({queryKey:te.dashboard(e)}),t.invalidateQueries({queryKey:te.org(e)});const c=An(a.agentId);c&&t.invalidateQueries({queryKey:te.agents.detail(c)});const d=dKe(a,o,t,e);d&&qA(s,r,"agent-status",d);return}if(n.type==="activity.logged"){mKe(t,e,a);const c=An(a.action),d=cKe(t,e,a,i)??uKe(a);d&&qA(s,r,`activity:${c??"unknown"}`,d)}}}}function yKe({children:t}){var a,c;const{selectedCompanyId:e}=en(),n=Nn(),{pushToast:r}=Aie(),s=v.useRef({cooldownHits:new Map,suppressUntil:0}),{data:i}=Be({queryKey:te.auth.session,queryFn:()=>Ua.getSession(),retry:!1}),o=((a=i==null?void 0:i.user)==null?void 0:a.id)??((c=i==null?void 0:i.session)==null?void 0:c.userId)??null;return v.useEffect(()=>{if(!e)return;let d=!1,f=0,m=null,p=null;const x=()=>{m!==null&&(window.clearTimeout(m),m=null)},y=()=>{if(d)return;f+=1;const k=Math.min(15e3,1e3*2**Math.min(f-1,4));m=window.setTimeout(()=>{m=null,w()},k)},w=()=>{if(d)return;const S=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/api/companies/${encodeURIComponent(e)}/events/ws`;p=new WebSocket(S),p.onopen=()=>{f>0&&(s.current.suppressUntil=Date.now()+nKe),f=0},p.onmessage=C=>{const _=typeof C.data=="string"?C.data:"";if(_)try{const E=JSON.parse(_);xKe(n,e,E,r,s.current,{userId:o,agentId:null})}catch{}},p.onerror=()=>{p==null||p.close()},p.onclose=()=>{d||y()}};return w(),()=>{d=!0,x(),p&&(p.onopen=null,p.onmessage=null,p.onerror=null,p.onclose=null,p.close(1e3,"provider_unmount"))}},[n,e,r,o]),l.jsx(l.Fragment,{children:t})}"serviceWorker"in navigator&&window.addEventListener("load",()=>{navigator.serviceWorker.register("/sw.js")});const bKe=new Sde({defaultOptions:{queries:{staleTime:3e4,refetchOnWindowFocus:!0}}});yce.createRoot(document.getElementById("root")).render(l.jsx(v.StrictMode,{children:l.jsx(_de,{client:bKe,children:l.jsx(hFe,{children:l.jsx(Mde,{children:l.jsx(nFe,{children:l.jsx(yKe,{children:l.jsx(Hue,{children:l.jsx(r2e,{children:l.jsx(_2e,{children:l.jsx(f2e,{children:l.jsx(j2e,{children:l.jsx(n2e,{children:l.jsx(Xqe,{})})})})})})})})})})})})}));export{Cn as A,ah as B,Wre as C,f6e as D,at as E,_e as F,Wg as G,bDe as H,ar as I,D6e as J,ex as K,X4 as L,wKe as M,_9 as N,wre as P,cr as T,Ae as _,F6e as a,FKe as b,LKe as c,TDe as d,Ws as e,J6e as f,De as g,IKe as h,Nre as i,PKe as j,Ai as k,sn as l,DKe as m,$Ke as n,MKe as o,RKe as p,na as q,Ex as r,T6e as s,je as t,Sf as u,$v as v,la as w,W_ as x,G6e as y,Sre as z};