/**
 * 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_util = require("../utils/util.js");
const require_ConditionBuilderProvider = require("../ConditionBuilderContext/ConditionBuilderProvider.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/ConditionBuilder/ConditionBuilderButton/ConditionBuilderButton.tsx
/**
* Copyright IBM Corp. 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 ConditionBuilderButton = ({ className, label, hideLabel, tooltipAlign, renderIcon: Icon, onClick, showToolTip, wrapperProps, onBlur, onFocus, onMouseEnter, onMouseLeave, isInvalid, wrapperClassName, tabIndex, description, ...rest }) => {
	const tooltipText = description || label;
	const carbonPrefix = (0, _carbon_react.usePrefix)();
	const Button = () => {
		const dataName = rest["data-name"] ?? "";
		const { readOnly } = (0, react.useContext)(require_ConditionBuilderProvider.ConditionBuilderContext);
		const handleClick = (e) => {
			if (readOnly) return;
			onClick?.(e);
		};
		return /* @__PURE__ */ react.default.createElement("button", {
			tabIndex: tabIndex !== void 0 ? tabIndex : -1,
			className: (0, import_classnames.default)([
				className,
				`${require_util.blockClass}__button`,
				{ [`${require_util.blockClass}__text-ellipsis`]: showToolTip && !hideLabel && !isInvalid },
				{ [`${require_util.blockClass}__invalid-input`]: isInvalid }
			]),
			type: "button",
			onClick: handleClick,
			onBlur,
			onFocus,
			onMouseEnter,
			onMouseLeave,
			"data-name": dataName,
			"aria-disabled": readOnly,
			...rest
		}, Icon && /* @__PURE__ */ react.default.createElement(Icon, null), !hideLabel && /* @__PURE__ */ react.default.createElement("span", null, label), isInvalid && /* @__PURE__ */ react.default.createElement(_carbon_react_icons.WarningAltFilled, null));
	};
	return hideLabel || showToolTip || description ? /* @__PURE__ */ react.default.createElement(_carbon_react.Tooltip, {
		label: tooltipText,
		align: tooltipAlign,
		className: `${wrapperClassName} ${require_util.blockClass}__tooltip ${carbonPrefix}--icon-tooltip`,
		...wrapperProps,
		leaveDelayMs: 0
	}, Button()) : /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, Button());
};
ConditionBuilderButton.propTypes = {
	/**
	* Provide an optional class to be applied to the containing node.
	*/
	className: prop_types.default.string,
	/**
	* decides if label and tooltip to be hidden
	*/
	hideLabel: prop_types.default.bool,
	/**
	* boolean to know the updated value in not valid
	*/
	isInvalid: prop_types.default.bool,
	/**
	* label of the button
	*/
	label: prop_types.default.string,
	/**
	* mouse events callbacks
	*/
	onBlur: prop_types.default.func,
	/**
	* callback triggered on click of add button
	*/
	onClick: prop_types.default.func,
	onFocus: prop_types.default.func,
	onMouseEnter: prop_types.default.func,
	onMouseLeave: prop_types.default.func,
	/**
	* Optional prop to allow overriding the icon rendering.
	*/
	renderIcon: prop_types.default.oneOfType([prop_types.default.func, prop_types.default.object]),
	/**
	*/
	/**
	*decides if  tooltip to be shown
	*/
	showToolTip: prop_types.default.bool,
	/**
	* Tab index
	*/
	tabIndex: prop_types.default.number,
	/**
	* tooltip position
	*/
	tooltipAlign: prop_types.default.string,
	/**
	* classname applies to the wrapper of popover
	*/
	wrapperClassName: prop_types.default.string,
	/**
	* optional props for tree grid to add role and aria-label to wrapper span
	*/
	wrapperProps: prop_types.default.object
};
//#endregion
exports.ConditionBuilderButton = ConditionBuilderButton;
