/**
 * 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_uuidv4 = require('../../global/js/utils/uuidv4.js');
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
let _carbon_react = require("@carbon/react");
let _carbon_react_icons = require("@carbon/react/icons");

//#region src/components/ComboButton/ComboButton.tsx
/**
* Copyright IBM Corp. 2020, 2024
*
* 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}--combo-button`;
const componentName = "ComboButton";
/**
* The combo button consolidates similar actions, while exposing the most commonly used one.
*/
const ComboButton = (0, react.forwardRef)((props, ref) => {
	const { children, className, overflowMenu, ...rest } = props;
	const { current: instanceId } = (0, react.useRef)(require_uuidv4.default());
	const [isOpen, setIsOpen] = (0, react.useState)(false);
	const actions = react.Children.toArray(children).filter(Boolean).map((child) => {
		if (react.default.isValidElement(child)) {
			const { props } = child;
			return {
				...props,
				children: /* @__PURE__ */ react.default.createElement("span", { className: `${blockClass}__action` }, child)
			};
		}
		return null;
	});
	const primaryAction = actions.slice(0, 1);
	const secondaryActions = actions.slice(1);
	return /* @__PURE__ */ react.default.createElement("div", {
		...rest,
		ref,
		className: (0, import_classnames.default)(blockClass, className),
		"data-floating-menu-container": true
	}, /* @__PURE__ */ react.default.createElement(_carbon_react.Button, primaryAction), secondaryActions.length > 0 && /* @__PURE__ */ react.default.createElement(_carbon_react.OverflowMenu, {
		...overflowMenu,
		className: `${blockClass}__overflow-menu`,
		menuOptionsClass: `${blockClass}__overflow-menu__list`,
		onClick: () => !isOpen && setIsOpen(true),
		onClose: () => setIsOpen(false),
		renderIcon: () => (0, react.createElement)(isOpen ? (props) => /* @__PURE__ */ react.default.createElement(_carbon_react_icons.ChevronUp, {
			size: 16,
			...props
		}) : (props) => /* @__PURE__ */ react.default.createElement(_carbon_react_icons.ChevronDown, {
			size: 16,
			...props
		}), { className: `${blockClass}__overflow-menu__icon` }),
		flipped: true
	}, secondaryActions.map(({ children, renderIcon: Icon, ...action }, index) => /* @__PURE__ */ react.default.createElement(_carbon_react.OverflowMenuItem, {
		...action,
		key: `${blockClass}--${instanceId}__overflow-menu__item__${index}`,
		className: `${blockClass}__overflow-menu__item`,
		itemText: /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, children, Icon && /* @__PURE__ */ react.default.createElement("span", { className: `${blockClass}__overflow-menu__item__icon` }, /* @__PURE__ */ react.default.createElement(Icon, null)))
	}))));
});
/**@ts-ignore*/
ComboButton.deprecated = {
	level: "warn",
	details: `Please replace ${componentName} with Carbon's ComboButton`
};
ComboButton.displayName = componentName;
ComboButton.propTypes = {
	children: prop_types.node.isRequired,
	className: prop_types.string,
	overflowMenu: (0, prop_types.shape)(_carbon_react.OverflowMenu.propTypes)
};

//#endregion
exports.ComboButton = ComboButton;