import p,{createContext as m,useContext as L,useMemo as f,useState as b}from"react";import{useId as g}from"../../hooks/use-id.js";import{forwardRefWithAs as x,render as T}from"../../utils/render.js";import{useIsoMorphicEffect as E}from"../../hooks/use-iso-morphic-effect.js";import{useSyncRefs as P}from"../../hooks/use-sync-refs.js";import{useEvent as v}from"../../hooks/use-event.js";let u=m(null);function c(){let o=L(u);if(o===null){let t=new Error("You used a <Label /> component, but it is not inside a relevant parent.");throw Error.captureStackTrace&&Error.captureStackTrace(t,c),t}return o}function M(){let[o,t]=b([]);return[o.length>0?o.join(" "):void 0,f(()=>function(e){let l=v(a=>(t(i=>[...i,a]),()=>t(i=>{let n=i.slice(),d=n.indexOf(a);return d!==-1&&n.splice(d,1),n}))),r=f(()=>({register:l,slot:e.slot,name:e.name,props:e.props}),[l,e.slot,e.name,e.props]);return p.createElement(u.Provider,{value:r},e.children)},[t])]}let h="label",F=x(function(t,s){let{passive:e=!1,...l}=t,r=c(),a=`headlessui-label-${g()}`,i=P(s);E(()=>r.register(a),[a,r.register]);let n={ref:i,...r.props,id:a};return e&&("onClick"in n&&delete n.onClick,"onClick"in l&&delete l.onClick),T({ourProps:n,theirProps:l,slot:r.slot||{},defaultTag:h,name:r.name||"Label"})});export{F as Label,M as useLabels};
