import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__chakra_ui_react__ from "@chakra-ui/react";
import * as __WEBPACK_EXTERNAL_MODULE__RadioCard_mjs__ from "./RadioCard.mjs";
function RadioGroup(props) {
    const { size = 'md', isAttached = true, direction, options = [], onBlur, onClick, ...groupProps } = props;
    const { getRootProps, getRadioProps } = (0, __WEBPACK_EXTERNAL_MODULE__chakra_ui_react__.useRadioGroup)(groupProps);
    const group = getRootProps();
    const [selectedRadio, setSelectedRadio] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(groupProps.defaultValue);
    const currentSelectedRadio = props.value ?? selectedRadio;
    return /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(__WEBPACK_EXTERNAL_MODULE__chakra_ui_react__.Stack, {
        ...group,
        direction: props.direction ?? 'row',
        spacing: isAttached ? '-1px' : '4',
        onBlur: (event)=>{
            if (void 0 !== groupProps.value || void 0 !== selectedRadio) onBlur?.(event);
        }
    }, options.map((option)=>{
        const radio = getRadioProps(option);
        return /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(__WEBPACK_EXTERNAL_MODULE__RadioCard_mjs__["default"], {
            ...radio,
            name: groupProps.name,
            key: `${option.value}`,
            isAttached: isAttached,
            direction: direction,
            size: size,
            id: `${option.value}`,
            value: `${option.value}`,
            isInvalid: option.invalid,
            isDisabled: group.disabled || option.disabled || props.isDisabled,
            isChecked: option.value === currentSelectedRadio,
            onChange: (eventKey)=>{
                // skip if component is user-controlled (they've specified a `value` prop);
                if (!props.value && eventKey.target.checked) setSelectedRadio(option.value);
                radio.onChange?.(eventKey);
            },
            onClick: (eventKey)=>{
                // skip if component is user-controlled (they've specified a `value` prop);
                if (!props.value) setSelectedRadio(option.value);
                onClick?.(eventKey);
            }
        }, option.label);
    }));
}
/* ESM default export */ const RadioGroup_rslib_entry_ = RadioGroup;
export { RadioGroup_rslib_entry_ as default };
