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