import{a as e,t}from"./react-D0JuimcS.js";import{n}from"./dist-ByPkKdya.js";var r=e(t(),1);function i(e,t){return r.useReducer((e,n)=>t[e][n]??e,e)}var a=e=>{let{present:t,children:n}=e,i=o(t),a=typeof n==`function`?n({present:i.isPresent}):r.Children.only(n),s=c(i.ref,u(a));return typeof n==`function`||i.isPresent?r.cloneElement(a,{ref:s}):null};a.displayName=`Presence`;function o(e){let[t,a]=r.useState(),o=r.useRef(null),s=r.useRef(e),c=r.useRef(`none`),[u,d]=i(e?`mounted`:`unmounted`,{mounted:{UNMOUNT:`unmounted`,ANIMATION_OUT:`unmountSuspended`},unmountSuspended:{MOUNT:`mounted`,ANIMATION_END:`unmounted`},unmounted:{MOUNT:`mounted`}});return r.useEffect(()=>{let e=l(o.current);c.current=u===`mounted`?e:`none`},[u]),n(()=>{let t=o.current,n=s.current;if(n!==e){let r=c.current,i=l(t);e?d(`MOUNT`):i===`none`||t?.display===`none`?d(`UNMOUNT`):d(n&&r!==i?`ANIMATION_OUT`:`UNMOUNT`),s.current=e}},[e,d]),n(()=>{if(t){let e,n=t.ownerDocument.defaultView??window,r=r=>{let i=l(o.current).includes(CSS.escape(r.animationName));if(r.target===t&&i&&(d(`ANIMATION_END`),!s.current)){let r=t.style.animationFillMode;t.style.animationFillMode=`forwards`,e=n.setTimeout(()=>{t.style.animationFillMode===`forwards`&&(t.style.animationFillMode=r)})}},i=e=>{e.target===t&&(c.current=l(o.current))};return t.addEventListener(`animationstart`,i),t.addEventListener(`animationcancel`,r),t.addEventListener(`animationend`,r),()=>{n.clearTimeout(e),t.removeEventListener(`animationstart`,i),t.removeEventListener(`animationcancel`,r),t.removeEventListener(`animationend`,r)}}else d(`ANIMATION_END`)},[t,d]),{isPresent:[`mounted`,`unmountSuspended`].includes(u),ref:r.useCallback(e=>{o.current=e?getComputedStyle(e):null,a(e)},[])}}function s(e,t){if(typeof e==`function`)return e(t);e!=null&&(e.current=t)}function c(...e){let t=r.useRef(e);return t.current=e,r.useCallback(e=>{let n=t.current,r=!1,i=n.map(t=>{let n=s(t,e);return!r&&typeof n==`function`&&(r=!0),n});if(r)return()=>{for(let e=0;e<i.length;e++){let t=i[e];typeof t==`function`?t():s(n[e],null)}}},[])}function l(e){return e?.animationName||`none`}function u(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var d=r.useId||(()=>void 0),f=0;function p(e){let[t,i]=r.useState(d());return n(()=>{e||i(e=>e??String(f++))},[e]),e||(t?`radix-${t}`:``)}function m(e){let t=r.useRef(e);return r.useEffect(()=>{t.current=e}),r.useMemo(()=>((...e)=>t.current?.(...e)),[])}export{p as n,a as r,m as t};