/**
 * 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");
const require_ConditionBuilderButton = require("../ConditionBuilderButton/ConditionBuilderButton.js");
const require_useTranslations = require("../utils/useTranslations.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_icons = require("@carbon/react/icons");
//#region src/components/ConditionBuilder/ConditionBuilderAdd/ConditionBuilderAdd.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 ConditionBuilderAdd = ({ className, onClick, addConditionSubGroupHandler, showConditionSubGroupPreviewHandler, hideConditionSubGroupPreviewHandler, showConditionPreviewHandler, hideConditionPreviewHandler, enableSubGroup, buttonLabel, tabIndex, group }) => {
	const [addConditionText, addConditionRowText, addSubgroupText] = require_useTranslations.useTranslations([
		"addConditionText",
		"addConditionRowText",
		"addSubgroupText"
	]);
	const { onAddItem, rootState } = (0, react.useContext)(require_ConditionBuilderProvider.ConditionBuilderContext);
	const onClickHandler = () => {
		const { preventAdd } = onAddItem?.({
			type: "condition",
			state: rootState,
			group
		}) ?? {};
		if (!preventAdd) {
			hideConditionPreviewHandler?.();
			onClick();
		}
	};
	const previewHandlers = () => {
		return enableSubGroup ? {
			onMouseEnter: showConditionPreviewHandler,
			onMouseLeave: hideConditionPreviewHandler,
			onFocus: showConditionPreviewHandler,
			onBlur: hideConditionPreviewHandler
		} : {};
	};
	const previewHandlersForSubgroup = () => ({
		onMouseEnter: showConditionSubGroupPreviewHandler,
		onMouseLeave: hideConditionSubGroupPreviewHandler,
		onFocus: showConditionSubGroupPreviewHandler,
		onBlur: hideConditionSubGroupPreviewHandler
	});
	const handleAddSubGroup = () => {
		const { preventAdd } = onAddItem?.({
			type: "subgroup",
			state: rootState,
			group
		}) ?? {};
		if (!preventAdd) addConditionSubGroupHandler?.();
	};
	const getAriaLabel = () => {
		return buttonLabel ? buttonLabel : !enableSubGroup ? addConditionRowText : void 0;
	};
	const wrapperProps = enableSubGroup ? { role: "gridcell" } : {};
	return /* @__PURE__ */ react.default.createElement("div", {
		className: `${className} ${require_util.blockClass}__add-button-wrapper`,
		role: !enableSubGroup ? "gridcell" : "none",
		"aria-label": getAriaLabel()
	}, /* @__PURE__ */ react.default.createElement(require_ConditionBuilderButton.ConditionBuilderButton, {
		renderIcon: _carbon_react_icons.AddAlt,
		onClick: onClickHandler,
		...previewHandlers(),
		wrapperProps,
		className: `${require_util.blockClass}__add-button`,
		hideLabel: true,
		"data-name": "addButton",
		label: buttonLabel ?? addConditionText,
		tabIndex,
		wrapperClassName: `${require_util.blockClass}__add-condition-wrapper`
	}), enableSubGroup && /* @__PURE__ */ react.default.createElement(require_ConditionBuilderButton.ConditionBuilderButton, {
		renderIcon: _carbon_react_icons.TextNewLine,
		onClick: handleAddSubGroup,
		className: (0, import_classnames.default)(`${require_util.blockClass}__add-condition-sub-group`),
		hideLabel: true,
		label: addSubgroupText,
		wrapperProps,
		wrapperClassName: `${require_util.blockClass}__add-condition-sub-group-wrapper ${require_util.blockClass}__gap-left`,
		...previewHandlersForSubgroup()
	}));
};
ConditionBuilderAdd.propTypes = {
	/**
	* handler for hiding sub group preview
	*/
	addConditionSubGroupHandler: prop_types.default.func,
	/**
	* handler for hiding sub group preview
	*/ /**
	* tooltip label for plus button
	*/
	buttonLabel: prop_types.default.string,
	/**
	* Provide an optional class to be applied to the containing node.
	*/
	className: prop_types.default.string,
	/**
	* boolean to enable sub groups for the tree variant
	*/
	enableSubGroup: prop_types.default.bool,
	/**
	* handler for hiding sub group preview
	*/
	hideConditionPreviewHandler: prop_types.default.func,
	hideConditionSubGroupPreviewHandler: prop_types.default.func,
	/**
	* handler for hiding sub group preview
	*/ /**
	* callback triggered on click of add button
	*/
	onClick: prop_types.default.func,
	showConditionPreviewHandler: prop_types.default.func,
	showConditionSubGroupPreviewHandler: prop_types.default.func,
	/**
	* handler for hiding sub group preview
	*/
	/**
	* Tab index
	*/
	tabIndex: prop_types.default.number
};
//#endregion
exports.default = ConditionBuilderAdd;
