"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.RadioGroup = void 0;
var _react = require("react");
var _layout = require("../layout");
var _listitems = require("../listitems");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * A list of radio buttons.
 * The management of the selection is demanded and derived by the `selectedItem` prop.
 * The item with the `id` equal to the `selectedItem` is the active one.
 */

const RadioListItem = props => /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
  children: props.items.map((item, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_listitems.ListItemRadio, {
      testID: `RadioItemTestID_${item.id}`,
      value: item.value,
      description: item.description,
      accessibilityLabel: item.accessibilityLabel,
      startImage: item.startImage,
      disabled: item.disabled,
      loadingProps: item.loadingProps,
      onValueChange: () => props.onPress(item.id),
      selected: props.selectedItem === item.id
    }), index < props.items.length - 1 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_layout.Divider, {})]
  }, `radio_item_${item.id}`))
});
const RadioListItemWithAmount = props => /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
  children: props.items.map((item, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
    children: [item.isSuggested ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_listitems.ListItemRadioWithAmount, {
      label: item.label,
      formattedAmountString: item.formattedAmountString,
      suggestReason: item.suggestReason,
      isSuggested: item.isSuggested,
      onValueChange: () => props.onPress(item.id),
      selected: props.selectedItem === item.id
    }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_listitems.ListItemRadioWithAmount, {
      label: item.label,
      formattedAmountString: item.formattedAmountString,
      onValueChange: () => props.onPress(item.id),
      selected: props.selectedItem === item.id
    }), index < props.items.length - 1 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_layout.Divider, {})]
  }, `radio_item_${item.id}`))
});
const RadioGroup = props => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
  children: [props.type === "radioListItem" && RadioListItem(props), props.type === "radioListItemWithAmount" && RadioListItemWithAmount(props)]
});
exports.RadioGroup = RadioGroup;
//# sourceMappingURL=RadioGroup.js.map