"use client";import{useFocusRing as S}from"@react-aria/focus";import{useHover as W}from"@react-aria/interactions";import i,{useCallback as N,useMemo as V,useState as w}from"react";import{useActivePress as J}from'../../hooks/use-active-press.js';import{useControllable as $}from'../../hooks/use-controllable.js';import{useDefaultValue as j}from'../../hooks/use-default-value.js';import{useDisposables as q}from'../../hooks/use-disposables.js';import{useEvent as l}from'../../hooks/use-event.js';import{useId as z}from'../../hooks/use-id.js';import{useDisabled as Q}from'../../internal/disabled.js';import{FormFields as Y}from'../../internal/form-fields.js';import{useProvidedId as Z}from'../../internal/id.js';import{isDisabledReactIssue7711 as ee}from'../../utils/bugs.js';import{attemptSubmit as oe}from'../../utils/form.js';import{forwardRefWithAs as te,mergeProps as re,render as ae}from'../../utils/render.js';import{useDescribedBy as ne}from'../description/description.js';import{Keys as y}from'../keyboard.js';import{useLabelledBy as le}from'../label/label.js';let se="span";function ie(T,h){let C=z(),k=Z(),x=Q(),{id:g=k||`headlessui-checkbox-${C}`,disabled:e=x||!1,autoFocus:s=!1,checked:E,defaultChecked:v,onChange:P,name:d,value:D,form:R,indeterminate:n=!1,...A}=T,r=j(v),[a,t]=$(E,P,r!=null?r:!1),F=le(),K=ne(),_=q(),[p,c]=w(!1),u=l(()=>{c(!0),t==null||t(!a),_.nextFrame(()=>{c(!1)})}),H=l(o=>{if(ee(o.currentTarget))return o.preventDefault();o.preventDefault(),u()}),B=l(o=>{o.key===y.Space?(o.preventDefault(),u()):o.key===y.Enter&&oe(o.currentTarget)}),L=l(o=>o.preventDefault()),{isFocusVisible:m,focusProps:I}=S({autoFocus:s}),{isHovered:f,hoverProps:M}=W({isDisabled:e}),{pressed:b,pressProps:U}=J({disabled:e}),O=re({ref:h,id:g,role:"checkbox","aria-checked":n?"mixed":a?"true":"false","aria-labelledby":F,"aria-describedby":K,"aria-disabled":e?!0:void 0,indeterminate:n?"true":void 0,tabIndex:e?void 0:0,onKeyUp:e?void 0:B,onKeyPress:e?void 0:L,onClick:e?void 0:H},I,M,U),X=V(()=>({checked:a,disabled:e,hover:f,focus:m,active:b,indeterminate:n,changing:p,autofocus:s}),[a,n,e,f,m,b,p,s]),G=N(()=>{if(r!==void 0)return t==null?void 0:t(r)},[t,r]);return i.createElement(i.Fragment,null,d!=null&&i.createElement(Y,{disabled:e,data:{[d]:D||"on"},overrides:{type:"checkbox",checked:a},form:R,onReset:G}),ae({ourProps:O,theirProps:A,slot:X,defaultTag:se,name:"Checkbox"}))}let Re=te(ie);export{Re as Checkbox};
