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