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 n=L(u);if(n===null){let r=new Error("You used a <Label /> component, but it is not inside a relevant parent.");throw Error.captureStackTrace&&Error.captureStackTrace(r,c),r}return n}function M(){let[n,r]=b([]);return[n.length>0?n.join(" "):void 0,f(()=>function(e){let o=v(l=>(r(t=>[...t,l]),()=>r(t=>{let i=t.slice(),a=i.indexOf(l);return a!==-1&&i.splice(a,1),i}))),s=f(()=>({register:o,slot:e.slot,name:e.name,props:e.props}),[o,e.slot,e.name,e.props]);return p.createElement(u.Provider,{value:s},e.children)},[r])]}let h="label",F=x(function(r,d){let e=g(),{id:o=`headlessui-label-${e}`,passive:s=!1,...l}=r,t=c(),i=P(d);E(()=>t.register(o),[o,t.register]);let a={ref:i,...t.props,id:o};return s&&("onClick"in a&&delete a.onClick,"onClick"in l&&delete l.onClick),T({ourProps:a,theirProps:l,slot:t.slot||{},defaultTag:h,name:t.name||"Label"})});export{F as Label,M as useLabels};
