"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../../hooks/use-event.js"),r=require("../../hooks/use-iso-morphic-effect.js"),l=require("../../hooks/use-slot.js"),o=require("../../hooks/use-sync-refs.js"),n=require("../../internal/disabled.js"),i=require("../../internal/id.js"),s=require("../../utils/dom.js"),u=require("../../utils/render.js");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=a(e);let d=e.createContext(null);function p(){let t=e.useContext(d);if(null===t){let e=new Error("You used a <Label /> component, but it is not inside a relevant parent.");throw Error.captureStackTrace&&Error.captureStackTrace(e,p),e}return t}function f(t){var r,l,o;let n=null!=(l=null==(r=e.useContext(d))?void 0:r.value)?l:void 0;return(null!=(o=null==t?void 0:t.length)?o:0)>0?[n,...t].filter(Boolean).join(" "):n}d.displayName="LabelContext";let v=u.forwardRefWithAs((function(a,c){var d;let f=e.useId(),v=p(),b=i.useProvidedId(),h=n.useDisabled(),{id:m=`headlessui-label-${f}`,htmlFor:k=(null!=b?b:null==(d=v.props)?void 0:d.htmlFor),passive:g=!1,...j}=a,C=o.useSyncRefs(c);r.useIsoMorphicEffect((()=>v.register(m)),[m,v.register]);let x=t.useEvent((e=>{let t=e.currentTarget;if((e.target===e.currentTarget||!s.isInteractiveElement(e.target))&&(s.isHTMLLabelElement(t)&&e.preventDefault(),v.props&&"onClick"in v.props&&"function"==typeof v.props.onClick&&v.props.onClick(e),s.isHTMLLabelElement(t))){let e=document.getElementById(t.htmlFor);if(e){let t=e.getAttribute("disabled");if("true"===t||""===t)return;let r=e.getAttribute("aria-disabled");if("true"===r||""===r)return;(s.isHTMLInputElement(e)&&("file"===e.type||"radio"===e.type||"checkbox"===e.type)||"radio"===e.role||"checkbox"===e.role||"switch"===e.role)&&e.click(),e.focus({preventScroll:!0})}}})),E=l.useSlot({...v.slot,disabled:h||!1}),y={ref:C,...v.props,id:m,htmlFor:k,onClick:x};return g&&("onClick"in y&&(delete y.htmlFor,delete y.onClick),"onClick"in j&&delete j.onClick),u.useRender()({ourProps:y,theirProps:j,slot:E,defaultTag:k?"label":"div",name:v.name||"Label"})}));Object.assign(v,{}),exports.useLabelContext=p,exports.useLabelledBy=f,exports.useLabels=function(){let{inherit:r=!1}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},l=f(),[o,n]=e.useState([]),i=r?[l,...o].filter(Boolean):o;return[i.length>0?i.join(" "):void 0,e.useMemo((()=>function(r){let l=t.useEvent((e=>(n((t=>[...t,e])),()=>n((t=>{let r=t.slice(),l=r.indexOf(e);return-1!==l&&r.splice(l,1),r}))))),o=e.useMemo((()=>({register:l,slot:r.slot,name:r.name,props:r.props,value:r.value})),[l,r.slot,r.name,r.props,r.value]);return c.default.createElement(d.Provider,{value:o},r.children)}),[n])]};
//# sourceMappingURL=label.js.map
