import{jsxs as m,jsx as c}from"react/jsx-runtime";import"../primitives/button.js";import"../primitives/checkbox.js";import"../primitives/dropdown-selector.js";import"../primitives/popover.js";import"../primitives/radio.js";import"../primitives/segmented-control.js";import"../primitives/switch.js";import M from"../primitives/text.js";import{useClickAway as N}from"../../hooks/useClickAway.js";import{useToggleState as b}from"../../hooks/useToggleState.js";import{tooltip as k}from"../../recipes/tooltip.js";import{forwardRef as E,useState as j,useMemo as R,useRef as q,cloneElement as z}from"react";import{useTooltipTrigger as A,mergeProps as B}from"react-aria";const d=E((t,u)=>{const f="ontouchstart"in window||navigator.maxTouchPoints>0||navigator.maxTouchPoints>0,{children:g,content:h,width:x=288,closeDelay:O=2500,defaultOpen:T,placement:p="top",expand:v=!1,...w}=t,[i,r]=j(!1),{isSelected:l,setSelected:o}=b({isOpen:t.isOpen,defaultSelected:T,onChange(s){s||r(!1)},...t}),e=R(()=>({isOpen:l,open:()=>{o(!0)},close:s=>{if(s){o(!1);return}f?o(!1):(i&&setTimeout(()=>{o(!1),r(!1)},O),i||o(!1))}}),[l,i]),y=q(null),{triggerProps:a,tooltipProps:P}=A(t,e,y);a.onClick=()=>{e.open(),r(!0)};const S=N(()=>{e.close(!0)}),C=p.split(" ")[0],n=k({expand:v,isOpen:e.isOpen,placement:p,position:C});return m("div",{ref:S,className:n.trigger,onMouseLeave:()=>{e.close()},onFocus:()=>{e.open()},onBlur:()=>{e.close()},children:[z(g,{...a,tabIndex:0}),m("div",{ref:u,"aria-describedby":"tooltip",role:"tooltip",className:n.content,style:{width:x},onMouseEnter:()=>{e.open()},...B(P,w),children:[c(M,{size:"sm",children:h}),e.isOpen&&c("div",{onMouseEnter:()=>{e.open()},className:n.spacer})]})]})});d.displayName="Tooltip";export{d as default};
//# sourceMappingURL=tooltip.js.map
