import{o as e}from"./rolldown-runtime-C_s2cVnS.js";import{a as t}from"./i18n-CsN8OUP9.js";import{h as n,m as r}from"./vendor-react-nmZsNlRz.js";import{t as i}from"./IconCheck-CTnHqwr6.js";import{t as a}from"./IconCopy-C1Eb9xiT.js";import{t as o}from"./IconX-B-240xwH.js";import{t as s}from"./button-C_jHykqW.js";import{r as c}from"./tooltip-vc4SoMXn.js";import{a as l}from"./dropdown-menu-DPM6aa8A.js";import{i as u}from"./context-menu-D9asNM1Q.js";import{t as d}from"./utils-BRwGVQJx.js";import{n as f}from"./haptics-MK-CNWlU.js";var p=e(n(),1),m=e(r(),1),h=1500;async function g(e){if(e){if(window.hermesDesktop?.writeClipboard){await window.hermesDesktop.writeClipboard(e);return}if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(e);return}throw Error(`Clipboard API is unavailable`)}}function _({appearance:e=`button`,buttonSize:n,buttonVariant:r=`ghost`,children:_,className:v,disabled:y=!1,errorMessage:b,haptic:x=!0,iconClassName:S,label:C,onCopied:w,onCopyError:T,preventDefault:E=!1,showLabel:D,side:O,stopPropagation:k=!1,text:A,title:j}){let{t:M}=t(),N=b??M.common.copyFailed,P=C??M.common.copy,[F,I]=p.useState(`idle`),L=p.useRef(null);p.useEffect(()=>()=>{L.current!==null&&window.clearTimeout(L.current)},[]);let R=p.useCallback(async e=>{E&&e?.preventDefault(),k&&e?.stopPropagation();try{let e=typeof A==`function`?await A():A;if(!e)return;await g(e),x&&f(`selection`),L.current!==null&&window.clearTimeout(L.current),I(`copied`),L.current=window.setTimeout(()=>{I(`idle`),L.current=null},h),w?.()}catch(e){T?.(e),L.current!==null&&window.clearTimeout(L.current),I(`error`),L.current=window.setTimeout(()=>{I(`idle`),L.current=null},h)}},[x,w,T,E,k,A]),z=(0,m.jsx)(F===`copied`?i:F===`error`?o:a,{className:d(`size-3.5`,S)}),B=D??(e!==`icon`&&e!==`tool-row`)?F===`copied`?M.common.copied:F===`error`?M.common.failed:_??P:null,V=(0,m.jsxs)(m.Fragment,{children:[z,B]}),H=F===`copied`?M.common.copied:F===`error`?N:j??P,U=F===`idle`?P:H;if(e===`menu-item`||e===`context-menu-item`)return(0,m.jsx)(e===`menu-item`?l:u,{className:v,disabled:y,onSelect:e=>{e.preventDefault(),R(e)},children:V});if(e===`inline`)return(0,m.jsx)(c,{label:H,side:O,children:(0,m.jsx)(`button`,{"aria-label":U,className:d(`inline-flex items-center gap-1 rounded-sm px-1.5 py-0.5 text-[0.75rem] text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-40`,v),disabled:y,onClick:e=>void R(e),type:`button`,children:V})});if(e===`tool-row`)return(0,m.jsx)(c,{label:H,children:(0,m.jsx)(`button`,{"aria-label":U,className:d(`grid size-6 place-items-center rounded-md text-muted-foreground/70 opacity-0 transition-opacity hover:bg-accent/55 hover:text-foreground focus-visible:opacity-100 group-hover/tool-row:opacity-100 disabled:opacity-40`,v),disabled:y,onClick:e=>void R(e),type:`button`,children:z})});let W=(0,m.jsx)(s,{"aria-label":U,className:v,disabled:y,onClick:e=>void R(e),size:n??(e===`icon`?`icon`:`default`),type:`button`,variant:r,children:V});return e===`icon`?(0,m.jsx)(c,{label:H,side:O??`bottom`,children:W}):W}export{g as n,_ as t};