'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');
var Radio = require('../radio/Radio.js');
var contexts = require('../inputs/contexts.js');
var jsxRuntime = require('react/jsx-runtime');

function RadioGroup({
  name,
  radios,
  selectedValue: controlledValue,
  onChange,
  UNSAFE_inputAttributes
}) {
  const inputAttributes = contexts.useInputAttributes({
    nonLabelable: true
  });
  const [uncontrolledValue, setUncontrolledValue] = React.useState(controlledValue);
  return radios.length > 0 ? /*#__PURE__*/jsxRuntime.jsx("div", {
    role: "radiogroup",
    ...inputAttributes,
    ...UNSAFE_inputAttributes,
    className: "wds-radio-group",
    children: radios.map(({
      value = '',
      ...restProps
    }, index) => /*#__PURE__*/jsxRuntime.jsx(Radio.default
    // eslint-disable-next-line react/no-array-index-key
    , {
      ...restProps,
      name: name,
      value: value,
      checked: value === uncontrolledValue,
      onChange: nextValue => {
        setUncontrolledValue(nextValue);
        onChange(nextValue);
      }
    }, index))
  }) : null;
}

exports.default = RadioGroup;
//# sourceMappingURL=RadioGroup.js.map
