import{useRef as e,useState as o,useCallback as a}from"react";import{useBoolean as n}from"../../../hooks/dist/esm/use-boolean.js";import{useControllableProp as i}from"../../../hooks/dist/esm/use-controllable.js";import{visuallyHiddenStyle as r}from"../../../visually-hidden/dist/esm/visually-hidden.js";import{warn as t,callAllHandlers as s,scheduleMicrotask as d}from"../../../utils/dist/esm/function.js";import{useCallbackRef as l}from"../../../hooks/dist/esm/use-callback-ref.js";import{useSafeLayoutEffect as u}from"../../../hooks/dist/esm/use-safe-layout-effect.js";import{dataAttr as c}from"../../../utils/dist/esm/dom.js";import{mergeRefs as f}from"../../../react-utils/dist/esm/refs.js";import{focus as h}from"../../../utils/dist/esm/focus.js";function m(){return(m=Object.assign||function(e){for(var o=1;o<arguments.length;o++){var a=arguments[o];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e}).apply(this,arguments)}function v(v){void 0===v&&(v={});var{defaultIsChecked:p,defaultChecked:k=p,isChecked:y,isFocusable:g,isDisabled:C,isReadOnly:j,isRequired:D,onChange:I,isIndeterminate:M,isInvalid:w,name:O,value:P,id:R,onBlur:B,onFocus:F,"aria-label":x,"aria-labelledby":L,"aria-invalid":q,"aria-describedby":K}=v,T=function(e,o){if(null==e)return{};var a,n,i={},r=Object.keys(e);for(n=0;n<r.length;n++)a=r[n],o.indexOf(a)>=0||(i[a]=e[a]);return i}(v,["defaultIsChecked","defaultChecked","isChecked","isFocusable","isDisabled","isReadOnly","isRequired","onChange","isIndeterminate","isInvalid","name","value","id","onBlur","onFocus","aria-label","aria-labelledby","aria-invalid","aria-describedby"]),U=l(I),E=l(B),A=l(F),[S,H]=n(),[N,z]=n(),[G,J]=n(),Q=e(null),[V,W]=o(!0),[X,Y]=o(!!k),[Z,$]=i(y,X);t({condition:!!p,message:'The "defaultIsChecked" prop has been deprecated and will be removed in a future version. Please use the "defaultChecked" prop instead, which mirrors default React checkbox behavior.'});var _=a((e=>{j||C?e.preventDefault():(Z||Y($?e.target.checked:!!M||e.target.checked),null==U||U(e))}),[j,C,$,Z,M,U]);u((()=>{Q.current&&(Q.current.indeterminate=Boolean(M))}),[M]);var ee=C&&!g,oe=a((e=>{" "===e.key&&J.on()}),[J]),ae=a((e=>{" "===e.key&&J.off()}),[J]);u((()=>{Q.current&&(Q.current.checked!==$&&Y(Q.current.checked))}),[Q.current]);var ne=a((function(e,o){void 0===e&&(e={}),void 0===o&&(o=null);return m({},e,{ref:o,"data-active":c(G),"data-hover":c(N),"data-checked":c($),"data-focus":c(S),"data-indeterminate":c(M),"data-disabled":c(C),"data-invalid":c(w),"data-readonly":c(j),"aria-hidden":!0,onMouseDown:s(e.onMouseDown,(e=>{e.preventDefault(),J.on()})),onMouseUp:s(e.onMouseUp,J.off),onMouseEnter:s(e.onMouseEnter,z.on),onMouseLeave:s(e.onMouseLeave,z.off)})}),[G,$,C,S,N,M,w,j,J,z.off,z.on]),ie=a((function(e,o){return void 0===e&&(e={}),void 0===o&&(o=null),m({},T,e,{ref:f(o,(e=>{e&&W("LABEL"===e.tagName)})),onClick:s(e.onClick,(()=>{var e;V||(null==(e=Q.current)||e.click(),h(Q.current,{nextTick:!0}))})),"data-disabled":c(C)})}),[T,C,V]),re=a((function(e,o){void 0===e&&(e={}),void 0===o&&(o=null);return m({},e,{ref:f(Q,o),type:"checkbox",name:O,value:P,id:R,onChange:s(e.onChange,_),onBlur:s(e.onBlur,E,H.off),onFocus:s(e.onFocus,A,(()=>{d(H.on)})),onKeyDown:s(e.onKeyDown,oe),onKeyUp:s(e.onKeyUp,ae),required:D,checked:$,disabled:ee,readOnly:j,"aria-label":x,"aria-labelledby":L,"aria-invalid":q?Boolean(q):w,"aria-describedby":K,"aria-disabled":C,style:r})}),[O,P,R,_,H.off,H.on,E,A,oe,ae,D,$,ee,j,x,L,q,w,K,C]),te=a((function(e,o){return void 0===e&&(e={}),void 0===o&&(o=null),m({},e,{ref:o,onMouseDown:s(e.onMouseDown,b),onTouchStart:s(e.onTouchStart,b),"data-disabled":c(C),"data-checked":c($),"data-invalid":c(w)})}),[$,C,w]);return{state:{isInvalid:w,isFocused:S,isChecked:$,isActive:G,isHovered:N,isIndeterminate:M,isDisabled:C,isReadOnly:j,isRequired:D},getRootProps:ie,getCheckboxProps:ne,getInputProps:re,getLabelProps:te,htmlProps:T}}function b(e){e.preventDefault(),e.stopPropagation()}export{v as useCheckbox};
//# sourceMappingURL=use-checkbox.js.map
