import React from 'react';
import classNames from 'classnames';
import { InfoIcon } from '../info-icon';
import { RadioButtonConditionalWrapper } from '../radio-button';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
 * Groups together related options. Can render tooltip over options
 * @midnight-gray-supported
 * @alpine-light-supported
 * */
export const RadioGroup = ({
  groupLabel,
  groupIdentifier,
  groupLabelInfoIconParams,
  activeItemId,
  onSelectItem,
  options,
  className,
  vertical,
  wrapItems,
  testId,
  isDisabled,
  radioButtonRole,
  groupAriaLabel = ''
}) => {
  const uniqueGroupLabelId = [testId, groupIdentifier, 'group-label'].filter(opt => !!opt).join('-');
  const fieldsetAttr = {
    ...(groupLabel && !groupAriaLabel && {
      'aria-labelledby': uniqueGroupLabelId
    }),
    ...(groupAriaLabel && {
      'aria-label': groupAriaLabel
    })
  };
  return /*#__PURE__*/_jsxs("fieldset", {
    className: classNames('radiogroup', className),
    "test-id": testId,
    disabled: isDisabled,
    role: !radioButtonRole ? 'radiogroup' : undefined,
    ...fieldsetAttr,
    children: [groupLabel && /*#__PURE__*/_jsxs("p", {
      className: "group",
      children: [/*#__PURE__*/_jsx("span", {
        id: uniqueGroupLabelId,
        className: "group-label",
        children: groupLabel
      }), groupLabelInfoIconParams && /*#__PURE__*/_jsx(InfoIcon, {
        placement: groupLabelInfoIconParams.placement,
        docsLink: groupLabelInfoIconParams.docsLink,
        testId: groupLabelInfoIconParams.testId,
        children: groupLabelInfoIconParams.children
      })]
    }), /*#__PURE__*/_jsx("div", {
      className: classNames('radiogroup-items', {
        vertical
      }),
      "test-id": `${testId}-items`,
      children: options?.map(option => /*#__PURE__*/_jsx(RadioButtonConditionalWrapper, {
        option: option,
        onSelect: onSelectItem,
        checked: activeItemId === option.id,
        groupIdentifier: groupIdentifier,
        wrapItems: wrapItems,
        radioButtonRole: radioButtonRole
      }, option.id))
    })]
  });
};