import React__default, { useId } from 'react';
import classnames from 'classnames';
import { T as Text } from './Text-es.js';

var styles = {"radioGroup":"KZfSK2vhTyI-","directionHorizontal":"PbxbMNv8uwM-","input":"w1Rr3bk2t5g-","label":"gN41T07x0l0-","description":"Ke2WKKuvmRo-","children":"JZOA-psW-FI-","spinning":"_54fzkHxkCbs-"};

/**
 * For rendering props only. To make updates to
 * the real RadioOption, look at InternalRadioOption
 */
function RadioOption({ children }) {
    return React__default.createElement(React__default.Fragment, null, children);
}
function InternalRadioOption({ value, name, label, description, disabled, checked, children, onChange, }) {
    const inputId = `${value.toString()}_${useId()}`;
    const shouldRenderIndependentChildren = label && children;
    return (React__default.createElement("div", null,
        React__default.createElement("input", { onChange: handleChange, type: "radio", name: name, value: value, disabled: disabled, checked: checked, id: inputId, className: styles.input, "aria-describedby": description ? `${inputId}_description` : undefined }),
        React__default.createElement("label", { className: styles.label, htmlFor: inputId }, label ? label : children),
        description && (React__default.createElement("div", { className: styles.description, id: `${inputId}_description` },
            React__default.createElement(Text, { variation: "subdued", size: "small" }, description))),
        shouldRenderIndependentChildren && (React__default.createElement("div", { className: styles.children, id: `${inputId}_children` }, children))));
    function handleChange() {
        onChange(value);
    }
}

function RadioGroup({ children, value, ariaLabel, onChange, name = useId(), direction = "vertical", }) {
    const className = classnames(styles.radioGroup, {
        [styles.directionHorizontal]: direction === "horizontal",
    });
    return (React__default.createElement("div", { role: "radiogroup", "aria-label": ariaLabel, className: className }, React__default.Children.map(children, option => (React__default.createElement(InternalRadioOption, Object.assign({ checked: value === option.props.value, name: name, onChange: handleChange }, option.props), option.props.children)))));
    function handleChange(newValue) {
        if (newValue !== value) {
            onChange(newValue);
        }
    }
}

export { RadioGroup as R, RadioOption as a };
