import{Ar as e,ii as t,kr as n,ri as r}from"./app-server-manager-signals-Yn0WSnoY.js";import{t as i}from"./jsx-runtime-CiQ1k8xo.js";import{t as a}from"./clsx-BcPLHiun.js";import{lt as o}from"./vscode-api-DjORcpSo.js";import{a as s,i as c,n as l,s as u,t as d}from"./inline-mentions-C7OnU--w.js";import{t as f}from"./external-markdown-link-p5PFMQlq.js";var p=o(),m=i(),h=/(```[\s\S]*?```|`[^`\n]+`|```[\s\S]*|`[^`\n]*\n|`[^`\n]*$)/g,g=/\[((?:\\.|[^\]\n])+)\]\(((?:\\.|[^)\n])+)\)/g;function _(e){let t=(0,p.c)(9),{text:n,ref:r,className:i,style:o,cwd:s,hostId:c}=e,d;if(t[0]!==i||t[1]!==s||t[2]!==c||t[3]!==r||t[4]!==o||t[5]!==n){let e=n.split(h).filter(v),f=[];for(let t of e){if(t.startsWith("```")){let e=t.endsWith("```")?t.slice(3,-3).trim():t.slice(3).trim();f.push({kind:`code-block`,content:e});continue}if(t.startsWith("`")){let e=t.endsWith("`")?t.slice(1,-1):t.slice(1);f.push({kind:`inline-code`,content:e});continue}f.push({kind:`text`,content:t})}let p=[];for(let e=0;e<f.length;e+=1){let t=f[e];if(t.kind===`text`){let n=t.content,r=e>0?f[e-1]:null,i=e+1<f.length?f[e+1]:null;r?.kind===`code-block`&&(n=n.replace(/^\n{2,}/,`
`)),i?.kind===`code-block`&&(n=n.replace(/\n{2,}$/,`
`)),p.push({kind:`text`,content:n});continue}p.push(t)}let g;t[7]===i?g=t[8]:(g=a(`text-size-chat whitespace-pre-wrap`,i),t[7]=i,t[8]=g),d=(0,m.jsx)(`div`,{ref:r,className:g,style:o,children:p.map((e,t)=>{if(e.kind===`code-block`)return(0,m.jsx)(`pre`,{className:`m-0 max-w-full overflow-x-auto font-mono whitespace-pre`,children:(0,m.jsx)(`code`,{children:e.content})},`user-code-block-${t}`);if(e.kind===`inline-code`){let n=e.content;return l(n)?(0,m.jsx)(u,{label:y(n)},`user-inline-code-${t}`):(0,m.jsx)(`code`,{className:`font-mono`,children:e.content},`user-inline-code-${t}`)}return(0,m.jsx)(`span`,{children:x(e.content,`user-text-${t}`,s,c)},`user-text-${t}`)})}),t[0]=i,t[1]=s,t[2]=c,t[3]=r,t[4]=o,t[5]=n,t[6]=d}else d=t[6];return d}function v(e){return e.length>0}function y(e){return e.startsWith(`$`)?e.startsWith(`$[`)&&e.endsWith(`]`)?e.slice(2,-1):e.slice(1):e}function b(t,r,i,a){let o=d(t);if(o==null)return[t];let c=[],f=0;for(let[d,p]of o.entries()){if(p.index>f&&c.push(t.slice(f,p.index)),l(p.content))c.push((0,m.jsx)(u,{label:y(p.content)},`${r}-skill-${d}`));else if(p.content.startsWith(`@`)){let t=p.content.slice(1);n(t)?c.push((0,m.jsx)(s,{reference:e(t),cwd:i,hostId:a},`${r}-file-${d}`)):c.push(p.content)}else c.push(p.content);f=p.index+p.content.length}return f<t.length&&c.push(t.slice(f)),c}function x(e,n,i,a){if(!g.test(e))return b(e,n,i,a);let o=[],s=0;g.lastIndex=0;let l,u=0;for(;(l=g.exec(e))!=null;){l.index>s&&o.push(...b(e.slice(s,l.index),`${n}-text-${u}`,i,a));let d=l[1],p=l[2],h=r(d),g=t(p),_=c({cwd:i,elementKey:`${n}-link-${u}`,hostId:a,href:g,label:h,openFileLinksInSidePanel:h.trim().startsWith(`$`)});_==null?o.push((0,m.jsx)(f,{href:g,originHostId:a,children:h},`${n}-link-${u}`)):o.push(_),s=l.index+l[0].length,u+=1}return s<e.length&&o.push(...b(e.slice(s),`${n}-text-${u}`,i,a)),o}export{_ as t};
//# sourceMappingURL=user-formatted-text-CR3zEeHg.js.map