/**
 * Copyright IBM Corp. 2020, 2026
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

import { pkg } from "../../../../../settings.js";
import React, { forwardRef } from "react";
import PropTypes from "prop-types";
import { RadioButton, RadioButtonGroup } from "@carbon/react";

//#region src/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.jsx
/**
* Copyright IBM Corp. 2021, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const blockClass = `${pkg.prefix}--datagrid__row-size`;
const RowSizeRadioGroup = forwardRef((props, ref) => {
	const { rowSizes = [
		{ value: "xl" },
		{ value: "lg" },
		{ value: "md" },
		{ value: "sm" },
		{ value: "xs" }
	], selectedOption = "lg", onChange, legendText, rowSizeLabels = {
		xl: "Extra large",
		lg: "Large (default)",
		md: "Medium",
		sm: "Small",
		xs: "Extra small"
	}, tableId } = props;
	return /* @__PURE__ */ React.createElement("div", {
		className: `${blockClass}-dropdown`,
		role: "presentation",
		ref
	}, /* @__PURE__ */ React.createElement(RadioButtonGroup, {
		legendText,
		name: `${tableId}--row-height-group`,
		orientation: "vertical",
		defaultSelected: getBackwardCompatibleRowSize(selectedOption),
		onChange
	}, rowSizes && Array.isArray(rowSizes) && rowSizes.map((option) => {
		let labelText;
		try {
			labelText = option.labelText || rowSizeLabels[option.value];
		} catch (e) {
			labelText = option.value;
		}
		return /* @__PURE__ */ React.createElement(RadioButton, {
			className: `${blockClass}-radio-button`,
			key: option.value,
			labelText,
			value: option.value,
			id: `${tableId || "datagrid"}--row-density--${option.value}`
		});
	})));
});
const getBackwardCompatibleRowSize = (rowSize) => {
	return {
		tall: "xl",
		normal: "lg",
		short: "sm",
		compact: "xs"
	}[rowSize] || rowSize;
};
RowSizeRadioGroup.propTypes = {
	legendText: PropTypes.string,
	onChange: PropTypes.func.isRequired,
	rowSizeLabels: PropTypes.object,
	rowSizes: PropTypes.array.isRequired,
	selectedOption: PropTypes.string.isRequired,
	tableId: PropTypes.string.isRequired
};

//#endregion
export { RowSizeRadioGroup as default };