import*as e from"react";import{useControllableProp as r}from"../../../hooks/dist/esm/use-controllable.js";import{useId as o}from"../../../hooks/dist/esm/use-id.js";import{isInputEvent as t}from"../../../utils/dist/esm/assertion.js";import{mergeRefs as a}from"../../../react-utils/dist/esm/refs.js";function n(){return(n=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var o=arguments[r];for(var t in o)Object.prototype.hasOwnProperty.call(o,t)&&(e[t]=o[t])}return e}).apply(this,arguments)}function u(u){void 0===u&&(u={});var{onChange:l,value:i,defaultValue:s,name:c,isNative:f}=u,d=function(e,r){if(null==e)return{};var o,t,a={},n=Object.keys(e);for(t=0;t<n.length;t++)o=n[t],r.indexOf(o)>=0||(a[o]=e[o]);return a}(u,["onChange","value","defaultValue","name","isNative"]),[v,m]=e.useState(s||""),[p,h]=r(i,v),g=e.useRef(null),b=e.useCallback((()=>{var e=g.current;if(e){var r="input:not(:disabled):checked",o=e.querySelector(r);if(o)o.focus();else{r="input:not(:disabled)";var t=e.querySelector(r);null==t||t.focus()}}}),[]),k=o(void 0,"radio"),C=c||k,j=e.useCallback((e=>{var r=t(e)?e.target.value:e;p||m(r),null==l||l(String(r))}),[l,p]);return{getRootProps:e.useCallback((function(e,r){return void 0===e&&(e={}),void 0===r&&(r=null),n({},e,{ref:a(r,g),role:"radiogroup"})}),[]),getRadioProps:e.useCallback((function(e,r){return void 0===e&&(e={}),void 0===r&&(r=null),n({},e,{ref:r,name:C,[f?"checked":"isChecked"]:null!=h?e.value===h:void 0,onChange:j,"data-radiogroup":!0})}),[f,C,j,h]),name:C,ref:g,focus:b,setValue:m,value:h,onChange:j,htmlProps:d}}export{u as useRadioGroup};
//# sourceMappingURL=use-radio-group.js.map
