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