import{r as y,j as s}from"./vendor-codemirror-B1SGo4xl.js";import{B as h,m as a}from"./index-lgmWPQDG.js";import{u as f}from"./use-toast-DNZLibQY.js";import{w as b,az as g}from"./vendor-icons-BlY7QrxS.js";async function v(t){if(!t)return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(t),!0}catch{}if(typeof document>"u")return!1;const e=document.createElement("textarea");e.value=t,e.style.position="fixed",e.style.top="0",e.style.left="0",e.style.width="2em",e.style.height="2em",e.style.padding="0",e.style.border="none",e.style.outline="none",e.style.boxShadow="none",e.style.background="transparent",e.style.opacity="0",e.style.pointerEvents="none",e.style.zIndex="-1",e.style.fontSize="16px",e.contentEditable="true",e.readOnly=!0,document.body.appendChild(e),e.focus(),e.select(),e.setSelectionRange&&e.setSelectionRange(0,t.length);let o=!1;try{o=document.execCommand("copy")}catch{o=!1}return document.body.removeChild(e),o}function w({text:t,label:e="已复制",children:o,className:c,size:n="sm",variant:r="outline",disabled:l,title:i="复制"}){const{toast:d}=f(),[u,p]=y.useState(!1),m=async()=>{await v(t)?(p(!0),d({title:e}),setTimeout(()=>p(!1),2e3)):d({title:"复制失败",description:"请手动选中内容后复制",variant:"destructive"})},x=!o&&n==="icon";return s.jsxs(h,{"code-path":"src/components/ui/copy-button.tsx:53:5",type:"button",variant:r,size:n,className:a(x?"h-8 w-8 shrink-0":"shrink-0",c),onClick:m,disabled:l||!t,title:i,"aria-label":i,children:[u?s.jsx(b,{"code-path":"src/components/ui/copy-button.tsx:67:9",className:a("text-emerald-400",o?"h-3.5 w-3.5 mr-1":"h-3.5 w-3.5")}):s.jsx(g,{"code-path":"src/components/ui/copy-button.tsx:69:9",className:a(o?"h-3.5 w-3.5 mr-1":"h-3.5 w-3.5")}),o]})}function E({label:t,code:e,copyLabel:o="已复制",className:c,copyDisabled:n,copyDisabledTitle:r}){return s.jsxs("div",{"code-path":"src/components/ui/code-snippet-block.tsx:19:5",className:a("space-y-1.5",c),children:[s.jsxs("div",{"code-path":"src/components/ui/code-snippet-block.tsx:20:7",className:"flex items-center justify-between gap-2",children:[t?s.jsx("p",{"code-path":"src/components/ui/code-snippet-block.tsx:22:11",className:"text-xs text-[var(--dg-text-muted)]",children:t}):s.jsx("span",{"code-path":"src/components/ui/code-snippet-block.tsx:24:11"}),s.jsx(w,{"code-path":"src/components/ui/code-snippet-block.tsx:26:9",text:e,label:o,variant:"outline",size:"sm",className:"border-[var(--dg-border)] text-[var(--dg-text-secondary)] h-7 px-2",disabled:n,title:n?r||"不可复制":"复制",children:"复制"})]}),s.jsx("pre",{"code-path":"src/components/ui/code-snippet-block.tsx:38:7",className:"text-[11px] font-mono text-[var(--dg-text-secondary)] bg-[var(--dg-bg-secondary)] border border-[var(--dg-border)] rounded-md p-3 overflow-x-auto whitespace-pre-wrap leading-relaxed",children:e})]})}export{E as C};