"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.RadioGroup = void 0;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _infoIcon = require("../info-icon");
var _radioButton = require("../radio-button");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
 * Groups together related options. Can render tooltip over options
 * @midnight-gray-supported
 * @alpine-light-supported
 * */
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__*/(0, _jsxRuntime.jsxs)("fieldset", {
    className: (0, _classnames.default)('radiogroup', className),
    "test-id": testId,
    disabled: isDisabled,
    role: !radioButtonRole ? 'radiogroup' : undefined,
    ...fieldsetAttr,
    children: [groupLabel && /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
      className: "group",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
        id: uniqueGroupLabelId,
        className: "group-label",
        children: groupLabel
      }), groupLabelInfoIconParams && /*#__PURE__*/(0, _jsxRuntime.jsx)(_infoIcon.InfoIcon, {
        placement: groupLabelInfoIconParams.placement,
        docsLink: groupLabelInfoIconParams.docsLink,
        testId: groupLabelInfoIconParams.testId,
        children: groupLabelInfoIconParams.children
      })]
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: (0, _classnames.default)('radiogroup-items', {
        vertical
      }),
      "test-id": `${testId}-items`,
      children: options?.map(option => /*#__PURE__*/(0, _jsxRuntime.jsx)(_radioButton.RadioButtonConditionalWrapper, {
        option: option,
        onSelect: onSelectItem,
        checked: activeItemId === option.id,
        groupIdentifier: groupIdentifier,
        wrapItems: wrapItems,
        radioButtonRole: radioButtonRole
      }, option.id))
    })]
  });
};
exports.RadioGroup = RadioGroup;