/**
 * 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.
 */

const require_runtime = require('../../../../../_virtual/_rolldown/runtime.js');
const require_index = require('../../../../../node_modules/classnames/index.js');
const require_settings = require('../../../../../settings.js');
const require_RowSizeRadioGroup = require('./RowSizeRadioGroup.js');
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
let _carbon_react = require("@carbon/react");
let _carbon_react_icons = require("@carbon/react/icons");

//#region src/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.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.
*/
var import_classnames = /* @__PURE__ */ require_runtime.__toESM(require_index.default);
const blockClass = `${require_settings.pkg.prefix}--datagrid__row-size`;
const RowSizeDropdown = ({ align = "bottom-right", legendText = "Row settings", autoAlign, ...props }) => {
	const radioGroupRef = (0, react.useRef)(void 0);
	const [isOpen, setIsOpen] = react.default.useState(false);
	const carbonPrefix = (0, _carbon_react.usePrefix)();
	const onCloseHandler = () => {
		setIsOpen(false);
	};
	const onKeyHandler = (e) => {
		if (e.key === "Escape") onCloseHandler();
	};
	const onBlurHandler = (e) => {
		if (!e.currentTarget.contains(e.relatedTarget)) onCloseHandler();
	};
	(0, react.useEffect)(() => {
		if (isOpen) ((radioGroupRef?.current)?.querySelector(`.${carbonPrefix}--radio-button:checked`))?.focus();
	}, [isOpen]);
	const onClickHandler = () => {
		setIsOpen((prev) => !prev);
	};
	return /* @__PURE__ */ react.default.createElement(_carbon_react.Popover, {
		tabIndex: -1,
		isTabTip: true,
		align: "bottom-right",
		open: isOpen,
		onRequestClose: onCloseHandler,
		className: `${blockClass}-options-container`,
		onKeyDown: onKeyHandler,
		onBlur: onBlurHandler,
		autoAlign
	}, /* @__PURE__ */ react.default.createElement(_carbon_react.IconButton, {
		align,
		kind: "ghost",
		onClick: onClickHandler,
		label: legendText,
		className: (0, import_classnames.default)(`${blockClass}-button`, { [`${blockClass}__row-settings-trigger--open`]: isOpen })
	}, /* @__PURE__ */ react.default.createElement(_carbon_react_icons.Settings, { size: 16 })), /* @__PURE__ */ react.default.createElement(_carbon_react.PopoverContent, null, /* @__PURE__ */ react.default.createElement(_carbon_react.Layer, null, /* @__PURE__ */ react.default.createElement(require_RowSizeRadioGroup.default, {
		ref: radioGroupRef,
		...props,
		legendText
	}))));
};
RowSizeDropdown.propTypes = {
	align: _carbon_react.IconButton.propTypes.align,
	autoAlign: prop_types.default.bool,
	datagridName: prop_types.default.string,
	legendText: prop_types.default.string,
	light: prop_types.default.bool,
	onChange: prop_types.default.func.isRequired,
	selectedOption: prop_types.default.string
};

//#endregion
exports.default = RowSizeDropdown;