import{useRef as e,useState as o,useCallback as n}from"react";import{useRadioGroupContext as i}from"./radio-group.js";import{useFormControlContext as a}from"../../../form-control/dist/esm/form-control.js";import{useId as r}from"../../../hooks/dist/esm/use-id.js";import{useBoolean as d}from"../../../hooks/dist/esm/use-boolean.js";import{useControllableProp as s}from"../../../hooks/dist/esm/use-controllable.js";import{warn as t,callAllHandlers as l,scheduleMicrotask as u}from"../../../utils/dist/esm/function.js";import{dataAttr as c,ariaAttr as f}from"../../../utils/dist/esm/dom.js";import{mergeRefs as v}from"../../../react-utils/dist/esm/refs.js";import{visuallyHiddenStyle as h}from"../../../visually-hidden/dist/esm/visually-hidden.js";function m(){return(m=Object.assign||function(e){for(var o=1;o<arguments.length;o++){var n=arguments[o];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}function p(p){void 0===p&&(p={});var{defaultIsChecked:k,defaultChecked:y=k,isChecked:g,isFocusable:C,isDisabled:j,isReadOnly:D,isRequired:M,onChange:O,isInvalid:w,name:R,value:I,id:P,"data-radiogroup":q}=p,F=function(e,o){if(null==e)return{};var n,i,a={},r=Object.keys(e);for(i=0;i<r.length;i++)n=r[i],o.indexOf(n)>=0||(a[n]=e[n]);return a}(p,["defaultIsChecked","defaultChecked","isChecked","isFocusable","isDisabled","isReadOnly","isRequired","onChange","isInvalid","name","value","id","data-radiogroup"]),x=r(void 0,"radio"),B=a(),K=i(),U=!!B&&!(!!K||!!q)?B.id:x;U=null!=P?P:U;var L=null!=j?j:null==B?void 0:B.isDisabled,T=null!=D?D:null==B?void 0:B.isReadOnly,E=null!=M?M:null==B?void 0:B.isRequired,S=null!=w?w:null==B?void 0:B.isInvalid,[A,H]=d(),[z,G]=d(),[J,N]=d(),Q=e(null),[V,W]=o(Boolean(y)),[X,Y]=s(g,V);t({condition:!!k,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 Z=n((e=>{T||L?e.preventDefault():(X||W(e.target.checked),null==O||O(e))}),[X,L,T,O]),$=n((e=>{" "===e.key&&N.on()}),[N]),_=n((e=>{" "===e.key&&N.off()}),[N]),ee=n((function(e,o){return void 0===e&&(e={}),void 0===o&&(o=null),m({},e,{ref:o,"data-active":c(J),"data-hover":c(z),"data-disabled":c(L),"data-invalid":c(S),"data-checked":c(Y),"data-focus":c(A),"data-readonly":c(T),"aria-hidden":!0,onMouseDown:l(e.onMouseDown,N.on),onMouseUp:l(e.onMouseUp,N.off),onMouseEnter:l(e.onMouseEnter,G.on),onMouseLeave:l(e.onMouseLeave,G.off)})}),[J,z,L,S,Y,A,T,N.on,N.off,G.on,G.off]),{onFocus:oe,onBlur:ne}=null!=B?B:{},ie=n((function(e,o){void 0===e&&(e={}),void 0===o&&(o=null);var n=L&&!C;return m({},e,{id:U,ref:v(o,Q),type:"radio",name:R,value:I,onChange:l(e.onChange,Z),onBlur:l(ne,e.onBlur,H.off),onFocus:l(oe,e.onFocus,(()=>{u((()=>{H.on()}))})),onKeyDown:l(e.onKeyDown,$),onKeyUp:l(e.onKeyUp,_),checked:Y,disabled:n,readOnly:T,required:E,"aria-invalid":f(S),"aria-disabled":f(n),"aria-readonly":f(T),"aria-required":f(E),style:h})}),[L,C,U,R,I,Z,ne,H,oe,$,_,Y,T,E,S]);return{state:{isInvalid:S,isFocused:A,isChecked:Y,isActive:J,isHovered:z,isDisabled:L,isReadOnly:T,isRequired:E},getCheckboxProps:ee,getInputProps:ie,getLabelProps:function(e,o){return void 0===e&&(e={}),void 0===o&&(o=null),m({},e,{ref:o,onMouseDown:l(e.onMouseDown,b),onTouchStart:l(e.onTouchStart,b),"data-disabled":c(L),"data-checked":c(Y),"data-invalid":c(S)})},htmlProps:F}}function b(e){e.preventDefault(),e.stopPropagation()}export{p as useRadio};
//# sourceMappingURL=use-radio.js.map
