"use client";var X=Object.defineProperty;var $=(o,t,e)=>t in o?X(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var f=(o,t,e)=>($(o,typeof t!="symbol"?t+"":t,e),e);import{useFocusRing as j}from"@react-aria/focus";import{useHover as q}from"@react-aria/interactions";import y,{Fragment as S,createContext as C,useContext as M,useEffect as z,useId as Q,useMemo as G,useReducer as Y,useRef as O,useSyncExternalStore as Z}from"react";import{useDisposables as ee}from'../../hooks/use-disposables.js';import{useEvent as a}from'../../hooks/use-event.js';import{useSlot as b}from'../../hooks/use-slot.js';import{useSyncRefs as I}from'../../hooks/use-sync-refs.js';import{FloatingProvider as te,useFloatingPanel as oe,useFloatingReference as ie,useResolvedAnchor as re}from'../../internal/floating.js';import{State as U,useOpenClosed as ne}from'../../internal/open-closed.js';import{match as s}from'../../utils/match.js';import{RenderFeatures as V,forwardRefWithAs as F,mergeProps as le,useRender as H}from'../../utils/render.js';import{Description as N,useDescribedBy as pe,useDescriptions as ae}from'../description/description.js';import{Keys as x}from'../keyboard.js';import{Portal as se}from'../portal/portal.js';var Te=(r=>(r[r.Hidden=0]="Hidden",r[r.Initiated=1]="Initiated",r[r.Visible=2]="Visible",r[r.Hiding=3]="Hiding",r))(Te||{}),de=(e=>(e[e.Delayed=0]="Delayed",e[e.Immediate=1]="Immediate",e))(de||{});class ue{constructor(){f(this,"_state",null);f(this,"_listeners",[]);f(this,"subscribe",t=>(this._listeners.push(t),()=>{this._listeners=this._listeners.filter(e=>e!==t)}));f(this,"getSnapshot",()=>this._state);f(this,"getServerSnapshot",()=>this._state);f(this,"setTooltipId",t=>{this._state!==t&&(this._state=t,this._listeners.forEach(e=>e(t)))})}}let P=new ue;var me=(e=>(e[e.ShowTooltip=0]="ShowTooltip",e[e.HideTooltip=1]="HideTooltip",e))(me||{});let fe={[0](o,t){return{...o,tooltipState:s(o.tooltipState,{[0]:s(t.when,{[1]:2,[0]:1}),[1]:s(t.when,{[1]:2,[0]:1}),[2]:2,[3]:2})}},[1](o,t){return{...o,tooltipState:s(o.tooltipState,{[0]:0,[1]:0,[2]:s(t.when,{[1]:0,[0]:3}),[3]:s(t.when,{[1]:0,[0]:3})})}}},W=C(null);W.displayName="TooltipActionsContext";function B(o){let t=M(W);if(t===null){let e=new Error(`<${o} /> is missing a parent <Tooltip /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(e,B),e}return t}let L=C(null);L.displayName="TooltipDataContext";function w(o){let t=M(L);if(t===null){let e=new Error(`<${o} /> is missing a parent <Tooltip /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(e,w),e}return t}function ce(o,t){return s(t.type,fe,o,t)}let ge=S;function ye(o,t){let{id:e=`headlessui-tooltip-${Q()}`,showDelayMs:d=750,hideDelayMs:r=300,...T}=o,i=Z(P.subscribe,P.getSnapshot,P.getServerSnapshot),[n,c]=Y(ce,{id:e,tooltipState:0}),[h,g]=ae(),l=ee();z(()=>{l.dispose(),s(n.tooltipState,{[0](){},[1](){l.setTimeout(()=>u(1),d)},[2](){},[3](){l.setTimeout(()=>m(1),r)}})},[l,n.tooltipState,d,r]);let u=a(p=>{p===0&&i!==null&&i!==e&&(p=1),p===1&&P.setTooltipId(e),c({type:0,when:p})}),m=a(p=>{i===e&&p===1&&P.setTooltipId(null),c({type:1,when:p})}),E={ref:I(t)},D=b({}),_=G(()=>({visible:i===n.id&&s(n.tooltipState,{[0]:!1,[1]:!1,[2]:!0,[3]:!0}),...n}),[i,n]),R=G(()=>({showTooltip:u,hideTooltip:m}),[u,m]),v=H();return y.createElement(g,{value:h},y.createElement(te,null,y.createElement(W.Provider,{value:R},y.createElement(L.Provider,{value:_},v({ourProps:E,theirProps:T,slot:D,defaultTag:ge,name:"Tooltip"})))))}let he=S;function Pe(o,t){let{disabled:e=!1,autoFocus:d=!1,...r}=o,T=w("TooltipTrigger"),i=B("TooltipTrigger"),n=pe(),c=O(null),h=I(c,t,ie()),{isFocusVisible:g,focusProps:l}=j({autoFocus:d}),{isHovered:u,hoverProps:m}=q({isDisabled:e}),A=a(J=>{switch(J.key){case x.Enter:case x.Escape:case x.Space:if(T.tooltipState===2)return i.hideTooltip(1);break}}),E=a(()=>{i.showTooltip(1)}),D=a(()=>{i.hideTooltip(1)}),_=a(()=>{i.hideTooltip(1)}),R=a(()=>{i.showTooltip(0)}),v=a(()=>{i.hideTooltip(0)}),p=a(()=>{T.tooltipState===3&&i.showTooltip(1)}),k=b({hover:u,focus:g,autofocus:d}),K=le({ref:h,"aria-describedby":T.visible?n:void 0,onKeyDown:A,onFocus:E,onBlur:D,onMouseDown:_,onMouseEnter:R,onMouseLeave:v,onMouseMove:p},l,m);return H()({ourProps:K,theirProps:r,slot:k,defaultTag:he,name:"TooltipTrigger"})}let Oe=N,Se=V.RenderStrategy|V.Static;function Ae(o,t){let{anchor:e,...d}=o,r=w("TooltipPanel"),T=ne(),i=(()=>T!==null?(T&U.Open)===U.Open:r.visible)(),n=O(null),c=re(e!=null?e:{to:"top",padding:8,gap:8,offset:-4}),[h,g]=oe(i?c:void 0),l=I(n,t,h),u={ref:l,role:"tooltip",...g?{style:g}:{}},m=b({});return H()({ourProps:{...u,as:S,children:y.createElement(se,null,y.createElement(N,{ref:l,...d}))},theirProps:{},slot:m,defaultTag:S,features:Se,visible:i,name:"TooltipPanel"})}let Ue=F(ye),Ve=F(Pe),Ne=F(Ae);export{Ue as Tooltip,Ne as TooltipPanel,Ve as TooltipTrigger};
