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