import{s as b}from"./chunk-LvLJmgfZ.js";import{t as h}from"./react-Bj1aDYRI.js";import{t as x}from"./jsx-runtime-Blw4afVn.js";import"./cjs-D5tzp-Y6.js";import{i as p,n as k,r as u,t as N}from"./chunk-5FQGJX7Z-CYQpNADu.js";var l=b(h(),1),r=b(x(),1),j=u("block","before:content-[counter(line)]","before:inline-block","before:[counter-increment:line]","before:w-6","before:mr-4","before:text-[13px]","before:text-right","before:text-muted-foreground/50","before:font-mono","before:select-none"),y=(0,l.memo)(({children:a,result:e,language:n,className:c,...g})=>{let d=(0,l.useMemo)(()=>({backgroundColor:e.bg,color:e.fg}),[e.bg,e.fg]);return(0,r.jsx)("pre",{className:u(c,"p-4 text-sm dark:bg-(--shiki-dark-bg)!"),"data-language":n,"data-streamdown":"code-block-body",style:d,...g,children:(0,r.jsx)("code",{className:"[counter-increment:line_0] [counter-reset:line]",children:e.tokens.map((i,t)=>(0,r.jsx)("span",{className:j,children:i.map((o,s)=>(0,r.jsx)("span",{className:"dark:bg-(--shiki-dark-bg)! dark:text-(--shiki-dark)!",style:{color:o.color,backgroundColor:o.bgColor,...o.htmlStyle},...o.htmlAttrs,children:o.content},s))},t))})})},(a,e)=>a.result===e.result&&a.language===e.language&&a.className===e.className),w=({className:a,language:e,style:n,...c})=>(0,r.jsx)("div",{className:u("my-4 w-full overflow-hidden rounded-xl border border-border",a),"data-language":e,"data-streamdown":"code-block",style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...n},...c}),v=({language:a,children:e})=>(0,r.jsxs)("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-language":a,"data-streamdown":"code-block-header",children:[(0,r.jsx)("span",{className:"ml-1 font-mono lowercase",children:a}),(0,r.jsx)("div",{className:"flex items-center gap-2",children:e})]}),C=({code:a,language:e,className:n,children:c,...g})=>{let{shikiTheme:d}=(0,l.useContext)(N),i=p(),t=(0,l.useMemo)(()=>({bg:"transparent",fg:"inherit",tokens:a.split(`
`).map(m=>[{content:m,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[a]),[o,s]=(0,l.useState)(t);return(0,l.useEffect)(()=>{if(!i){s(t);return}let m=i.highlight({code:a,language:e,themes:d},f=>{s(f)});if(m){s(m);return}s(t)},[a,e,d,i,t]),(0,r.jsx)(k.Provider,{value:{code:a},children:(0,r.jsxs)(w,{language:e,children:[(0,r.jsx)(v,{language:e,children:c}),(0,r.jsx)(y,{className:n,language:e,result:o,...g})]})})};export{C as CodeBlock};
