import{o as e,r as t}from"./jsx-runtime-Bypl69v7.js";import{n}from"./dist-D46zjeVv.js";var r=e(t(),1);function i(e){let t=r.useRef(e);return r.useEffect(()=>{t.current=e}),r.useMemo(()=>((...e)=>t.current?.(...e)),[])}var a=r.useId||(()=>void 0),o=0;function s(e){let[t,i]=r.useState(a());return n(()=>{e||i(e=>e??String(o++))},[e]),e||(t?`radix-${t}`:``)}function c(e,t){return r.useReducer((e,n)=>t[e][n]??e,e)}var l=e=>{let{present:t,children:n}=e,i=u(t),a=typeof n==`function`?n({present:i.isPresent}):r.Children.only(n),o=f(i.ref,m(a));return typeof n==`function`||i.isPresent?r.cloneElement(a,{ref:o}):null};l.displayName=`Presence`;function u(e){let[t,i]=r.useState(),a=r.useRef(null),o=r.useRef(e),s=r.useRef(`none`),l=r.useRef(void 0),[u,d]=c(e?`mounted`:`unmounted`,{mounted:{UNMOUNT:`unmounted`,ANIMATION_OUT:`unmountSuspended`},unmountSuspended:{MOUNT:`mounted`,ANIMATION_END:`unmounted`},unmounted:{MOUNT:`mounted`}});return r.useEffect(()=>{u===`mounted`?(s.current=l.current??p(a.current),l.current=void 0):s.current=`none`},[u]),n(()=>{let t=a.current,n=o.current;if(n!==e){let r=s.current,i=p(t);e?(l.current=i,d(`MOUNT`)):i===`none`||t?.display===`none`?d(`UNMOUNT`):d(n&&r!==i?`ANIMATION_OUT`:`UNMOUNT`),o.current=e}},[e,d]),n(()=>{if(t){let e,n=t.ownerDocument.defaultView??window,r=r=>{let i=p(a.current).includes(CSS.escape(r.animationName));if(r.target===t&&i&&(d(`ANIMATION_END`),!o.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&&(s.current=p(a.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=>{if(e){let t=getComputedStyle(e);a.current=t,l.current=p(t)}else a.current=null;i(e)},[])}}function d(e,t){if(typeof e==`function`)return e(t);e!=null&&(e.current=t)}function f(...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=d(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():d(n[e],null)}}},[])}function p(e){return e?.animationName||`none`}function m(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)}export{s as n,i as r,l as t};