import v,{Fragment as S,cloneElement as j,createElement as w,forwardRef as k,isValidElement as M,useCallback as x,useRef as O}from"react";import{classNames as N}from'./class-names.js';import{match as $}from'./match.js';var A=(a=>(a[a.None=0]="None",a[a.RenderStrategy=1]="RenderStrategy",a[a.Static=2]="Static",a))(A||{}),C=(t=>(t[t.Unmount=0]="Unmount",t[t.Hidden=1]="Hidden",t))(C||{});function K(){let e=I();return x(r=>U({mergeRefs:e,...r}),[e])}function U({ourProps:e,theirProps:r,slot:t,defaultTag:a,features:o,visible:n=!0,name:i,mergeRefs:l}){l=l!=null?l:H;let s=P(r,e);if(n)return F(s,t,a,i,l);let y=o!=null?o:0;if(y&2){let{static:f=!1,...u}=s;if(f)return F(u,t,a,i,l)}if(y&1){let{unmount:f=!0,...u}=s;return $(f?0:1,{[0](){return null},[1](){return F({...u,hidden:!0,style:{display:"none"}},t,a,i,l)}})}return F(s,t,a,i,l)}function F(e,r={},t,a,o){let{as:n=t,children:i,refName:l="ref",...s}=h(e,["unmount","static"]),y=e.ref!==void 0?{[l]:e.ref}:{},f=typeof i=="function"?i(r):i;f=E(f),"className"in s&&s.className&&typeof s.className=="function"&&(s.className=s.className(r)),s["aria-labelledby"]&&s["aria-labelledby"]===s.id&&(s["aria-labelledby"]=void 0);let u={};if(r){let d=!1,p=[];for(let[c,T]of Object.entries(r))typeof T=="boolean"&&(d=!0),T===!0&&p.push(c.replace(/([A-Z])/g,g=>`-${g.toLowerCase()}`));if(d){u["data-headlessui-state"]=p.join(" ");for(let c of p)u[`data-${c}`]=""}}if(b(n)&&(Object.keys(m(s)).length>0||Object.keys(m(u)).length>0))if(!M(f)||Array.isArray(f)&&f.length>1||L(f)){if(Object.keys(m(s)).length>0)throw new Error(['Passing props on "Fragment"!',"",`The current component <${a} /> is rendering a "Fragment".`,"However we need to passthrough the following props:",Object.keys(m(s)).concat(Object.keys(m(u))).map(d=>`  - ${d}`).join(`
`),"","You can apply a few solutions:",['Add an `as="..."` prop, to ensure that we render an actual element instead of a "Fragment".',"Render a single element as the child so that we can forward the props onto that element."].map(d=>`  - ${d}`).join(`
`)].join(`
`))}else{let d=f.props,p=d==null?void 0:d.className,c=typeof p=="function"?(...R)=>N(p(...R),s.className):N(p,s.className),T=c?{className:c}:{},g=P(f.props,m(h(s,["ref"])));for(let R in u)R in g&&delete u[R];return j(f,Object.assign({},g,u,y,{ref:o(D(f),y.ref)},T))}return w(n,Object.assign({},h(s,["ref"]),!b(n)&&y,!b(n)&&u),f)}function I(){let e=O([]),r=x(t=>{for(let a of e.current)a!=null&&(typeof a=="function"?a(t):a.current=t)},[]);return(...t)=>{if(!t.every(a=>a==null))return e.current=t,r}}function H(...e){return e.every(r=>r==null)?void 0:r=>{for(let t of e)t!=null&&(typeof t=="function"?t(r):t.current=r)}}function P(...e){var a;if(e.length===0)return{};if(e.length===1)return e[0];let r={},t={};for(let o of e)for(let n in o)n.startsWith("on")&&typeof o[n]=="function"?((a=t[n])!=null||(t[n]=[]),t[n].push(o[n])):r[n]=o[n];if(r.disabled||r["aria-disabled"])for(let o in t)/^(on(?:Click|Pointer|Mouse|Key)(?:Down|Up|Press)?)$/.test(o)&&(t[o]=[n=>{var i;return(i=n==null?void 0:n.preventDefault)==null?void 0:i.call(n)}]);for(let o in t)Object.assign(r,{[o](n,...i){let l=t[o];for(let s of l){if((n instanceof Event||(n==null?void 0:n.nativeEvent)instanceof Event)&&n.defaultPrevented)return;s(n,...i)}}});return r}function V(...e){var a;if(e.length===0)return{};if(e.length===1)return e[0];let r={},t={};for(let o of e)for(let n in o)n.startsWith("on")&&typeof o[n]=="function"?((a=t[n])!=null||(t[n]=[]),t[n].push(o[n])):r[n]=o[n];for(let o in t)Object.assign(r,{[o](...n){let i=t[o];for(let l of i)l==null||l(...n)}});return r}function Y(e){var r;return Object.assign(k(e),{displayName:(r=e.displayName)!=null?r:e.name})}function m(e){let r=Object.assign({},e);for(let t in r)r[t]===void 0&&delete r[t];return r}function h(e,r=[]){let t=Object.assign({},e);for(let a of r)a in t&&delete t[a];return t}function D(e){return v.version.split(".")[0]>="19"?e.props.ref:e.ref}function E(e){if(e!=null&&e.$$typeof===Symbol.for("react.lazy")){let r=e._payload;if(r!=null&&r.status==="fulfilled")return E(r.value)}return e}function b(e){return e===S||e===Symbol.for("react.fragment")}function L(e){return b(e.type)}export{A as RenderFeatures,C as RenderStrategy,m as compact,Y as forwardRefWithAs,b as isFragment,L as isFragmentInstance,V as mergeProps,K as useRender};
