"use strict";

import { Fragment } from "react";
import { Divider } from "../layout";
import { ListItemRadio, ListItemRadioWithAmount } from "../listitems";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "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__*/_jsx(_Fragment, {
  children: props.items.map((item, index) => /*#__PURE__*/_jsxs(Fragment, {
    children: [/*#__PURE__*/_jsx(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__*/_jsx(Divider, {})]
  }, `radio_item_${item.id}`))
});
const RadioListItemWithAmount = props => /*#__PURE__*/_jsx(_Fragment, {
  children: props.items.map((item, index) => /*#__PURE__*/_jsxs(Fragment, {
    children: [item.isSuggested ? /*#__PURE__*/_jsx(ListItemRadioWithAmount, {
      label: item.label,
      formattedAmountString: item.formattedAmountString,
      suggestReason: item.suggestReason,
      isSuggested: item.isSuggested,
      onValueChange: () => props.onPress(item.id),
      selected: props.selectedItem === item.id
    }) : /*#__PURE__*/_jsx(ListItemRadioWithAmount, {
      label: item.label,
      formattedAmountString: item.formattedAmountString,
      onValueChange: () => props.onPress(item.id),
      selected: props.selectedItem === item.id
    }), index < props.items.length - 1 && /*#__PURE__*/_jsx(Divider, {})]
  }, `radio_item_${item.id}`))
});
export const RadioGroup = props => /*#__PURE__*/_jsxs(_Fragment, {
  children: [props.type === "radioListItem" && RadioListItem(props), props.type === "radioListItemWithAmount" && RadioListItemWithAmount(props)]
});
//# sourceMappingURL=RadioGroup.js.map