import{al as N,bZ as S,b0 as T,aw as C,s as P,r as h,E as M,R as U,G as w,d as _,C as F,O as k}from"./m2W8DxR4.js";import{r as x}from"./DT-hKSom.js";import{g as D,i as L,c as R}from"./b1l8QPBl.js";function j(u){const e=N(),t=e==null?void 0:e.type.emits,c={};return t!=null&&t.length||console.warn(`No emitted event found. Please check component: ${e==null?void 0:e.type.__name}`),t==null||t.forEach(l=>{c[S(T(l))]=(...i)=>u(l,...i)}),c}function $(u){const e=N(),t=Object.keys((e==null?void 0:e.type.props)??{}).reduce((l,i)=>{const n=(e==null?void 0:e.type.props[i]).default;return n!==void 0&&(l[i]=n),l},{}),c=C(u);return P(()=>{const l={},i=(e==null?void 0:e.vnode.props)??{};return Object.keys(i).forEach(n=>{l[T(n)]=i[n]}),Object.keys({...t,...l}).reduce((n,r)=>(c.value[r]!==void 0&&(n[r]=c.value[r]),n),{})})}function Y(u,e){const t=$(u),c=e?j(e):{};return P(()=>({...t.value,...c}))}function V(u,e){const t=h(u);function c(i){return e[t.value][i]??t.value}return{state:t,dispatch:i=>{t.value=c(i)}}}function B(u,e){var g;const t=h({}),c=h("none"),l=h(u),i=u.value?"mounted":"unmounted";let n;const r=((g=e.value)==null?void 0:g.ownerDocument.defaultView)??D,{state:p,dispatch:f}=V(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}}),m=a=>{var s;if(L){const v=new CustomEvent(a,{bubbles:!1,cancelable:!1});(s=e.value)==null||s.dispatchEvent(v)}};M(u,async(a,s)=>{var y;const v=s!==a;if(await w(),v){const E=c.value,d=A(e.value);a?(f("MOUNT"),m("enter"),d==="none"&&m("after-enter")):d==="none"||d==="undefined"||((y=t.value)==null?void 0:y.display)==="none"?(f("UNMOUNT"),m("leave"),m("after-leave")):s&&E!==d?(f("ANIMATION_OUT"),m("leave")):(f("UNMOUNT"),m("after-leave"))}},{immediate:!0});const o=a=>{const s=A(e.value),v=s.includes(CSS.escape(a.animationName)),y=p.value==="mounted"?"enter":"leave";if(a.target===e.value&&v&&(m(`after-${y}`),f("ANIMATION_END"),!l.value)){const E=e.value.style.animationFillMode;e.value.style.animationFillMode="forwards",n=r==null?void 0:r.setTimeout(()=>{var d;((d=e.value)==null?void 0:d.style.animationFillMode)==="forwards"&&(e.value.style.animationFillMode=E)})}a.target===e.value&&s==="none"&&f("ANIMATION_END")},O=a=>{a.target===e.value&&(c.value=A(e.value))},b=M(e,(a,s)=>{a?(t.value=getComputedStyle(a),a.addEventListener("animationstart",O),a.addEventListener("animationcancel",o),a.addEventListener("animationend",o)):(f("ANIMATION_END"),n!==void 0&&(r==null||r.clearTimeout(n)),s==null||s.removeEventListener("animationstart",O),s==null||s.removeEventListener("animationcancel",o),s==null||s.removeEventListener("animationend",o))},{immediate:!0}),I=M(p,()=>{const a=A(e.value);c.value=p.value==="mounted"?a:"none"});return U(()=>{b(),I()}),{isPresent:P(()=>["mounted","unmountSuspended"].includes(p.value))}}function A(u){return u&&getComputedStyle(u).animationName||"none"}var Z=_({name:"Presence",props:{present:{type:Boolean,required:!0},forceMount:{type:Boolean}},slots:{},setup(u,{slots:e,expose:t}){var f;const{present:c,forceMount:l}=F(u),i=h(),{isPresent:n}=B(c,i);t({present:n});let r=e.default({present:n.value});r=x(r||[]);const p=N();if(r&&(r==null?void 0:r.length)>1){const m=(f=p==null?void 0:p.parent)!=null&&f.type.name?`<${p.parent.type.name} />`:"component";throw new Error([`Detected an invalid children for \`${m}\` for  \`Presence\` component.`,"","Note: Presence works similarly to `v-if` directly, but it waits for animation/transition to finished before unmounting. So it expect only one direct child of valid VNode type.","You can apply a few solutions:",["Provide a single child element so that `presence` directive attach correctly.","Ensure the first child is an actual element instead of a raw text node or comment node."].map(o=>`  - ${o}`).join(`
`)].join(`
`))}return()=>l.value||c.value||n.value?k(e.default({present:n.value})[0],{ref:m=>{const o=R(m);return typeof(o==null?void 0:o.hasAttribute)>"u"||(o!=null&&o.hasAttribute("data-reka-popper-content-wrapper")?i.value=o.firstElementChild:i.value=o),o}}):null}});export{Z as P,$ as a,j as b,Y as u};
