import{o as e}from"./rolldown-runtime-iuO8RvI4.js";import{Mi as s,ki as t}from"./vendor-frame-CwiylG4Y.js";import{rn as n}from"./vendor-all-2-BJdkbLSj.js";import{$ as r}from"./shared-frame-DbQbH4Yr.js";import{ja as a,pa as o,uo as l,ya as i}from"./shared-5-UQAFGbWu.js";import{Ls as m,Ss as c,jc as u}from"./shared-2-CMUBhYOn.js";import{At as p}from"./shared-10-DEXHYEQf.js";import{cr as d,gt as f,ht as h,lr as g}from"./shared-11-EQw1fy-I.js";var x=e(s()),j=t(),k=(0,j.jsx)(r,{name:"Scroll"}),y=(0,j.jsx)(r,{name:"Plugin"}),b=/(^|\s)(\/[\w:.-]+)/g;function C(e){return{type:"doc",content:e.split("\n").map(e=>{if(!e)return{type:"paragraph"};const s=[];let t,n=0;for(b.lastIndex=0;null!==(t=b.exec(e));){const r=t[1],a=t[2],o=e.slice(n,t.index)+r;o&&s.push({type:"text",text:o});const l=a.slice(1);s.push({type:"skillChip",attrs:{skillId:l,skillDisplayName:l,skillDescription:"",skillArgumentHint:""}}),n=t.index+t[0].length}const r=e.slice(n);return r&&s.push({type:"text",text:r}),{type:"paragraph",content:s}})}}function M({prompt:e}){const s=o();return(0,j.jsx)(j.Fragment,{children:e.split(b).map((e,t)=>{if(t%3!=2)return(0,j.jsx)(x.Fragment,{children:e},t);const n=e.slice(1),r=s.get(n);return r?(0,j.jsx)(p,{id:n,info:r},t):(0,j.jsx)(x.Fragment,{children:e},t)})})}function w({clientRect:e,decorationNode:s,editor:t,range:r,onClose:o,query:p}){const b=n(),{items:C}=i(),{data:M}=m(),w=(0,x.useRef)(r);w.current=r;const A=(0,x.useCallback)(e=>"skill"!==e.type?e:{...e,onAction:()=>{const s=w.current;t.chain().focus().deleteRange(s).insertContent(l(e.skillId,e.label??e.skillId,e.skillDescription??"",e.argumentHint??"")).run(),o()}},[t,o]),v=(0,x.useMemo)(()=>C.map(A),[C,A]),D=(0,x.useCallback)((e,s,n,r)=>{const a=w.current;t.chain().focus().deleteRange(a).insertContent(l(e,s,n,r??"")).run(),o()},[t,o]),I=(0,x.useMemo)(()=>M.filter(e=>e.enabled&&e.skills.some(c)).map(e=>({type:"submenu",label:u(e),items:a(e,D),submenuClassName:"!max-h-[288px]"})),[M,D]),R=(0,x.useMemo)(()=>{const e=[];return I.length>0&&e.push({type:"submenu",icon:y,label:b.formatMessage({defaultMessage:"Plugins",id:"QJAllUAc2k"}),items:I}),v.length>0&&e.push({type:"submenu",icon:k,label:b.formatMessage({defaultMessage:"Skills",id:"EJSVsOA19u"}),items:v}),e},[b,I,v]),F=(0,x.useMemo)(()=>g(R,p),[R,p]),N=F.length>0;return(0,x.useEffect)(()=>{const e=t.storage["slash-command-suggestion"];e&&(e.hasVisibleItems=N)},[t,N]),(0,x.useEffect)(()=>{t.view.dom.focus()},[t]),N?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(h,{editor:t,query:p}),(0,j.jsx)(d,{items:F,onClose:o,resetKey:p,ownerDocument:t.view.dom.ownerDocument,children:(0,j.jsx)(f,{clientRect:e,decorationNode:s,maxHeightCap:384})})]}):null}export{M as n,C as r,w as t};