/**
 * 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_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");
const require_ConditionBuilderItem = require("../ConditionBuilderItem/ConditionBuilderItem.js");
const require_ItemOption = require("../ConditionBuilderItem/ConditionBuilderItemOption/ItemOption.js");
const require_useDataConfigs = require("../utils/useDataConfigs.js");
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
//#region src/components/ConditionBuilder/ConditionBuilderConnector/ConditionConnector.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.
*/
const ConditionConnector = ({ operator, className, onChange, ...rest }) => {
	const { variant, conditionBuilderRef } = (0, react.useContext)(require_ConditionBuilderProvider.ConditionBuilderContext);
	const [connectorText] = require_useTranslations.useTranslations(["connectorText"]);
	const { connectorConfig } = require_useDataConfigs.useDataConfigs();
	const handleConnectorHover = (0, react.useCallback)((parentGroup, isHover) => {
		if (isHover) parentGroup.classList.add("hoveredConnector");
		else parentGroup.classList.remove("hoveredConnector");
	}, []);
	const activeConnectorHandler = (evt) => {
		const parentGroup = evt?.currentTarget.closest(".eachGroup");
		handleConnectorHover(parentGroup, true);
	};
	const inActiveConnectorHandler = (evt) => {
		const parentGroup = evt?.currentTarget.closest(".eachGroup");
		handleConnectorHover(parentGroup, false);
	};
	const onChangeHandler = (op, evt) => {
		onChange?.(op);
		require_util.focusThisField(evt, conditionBuilderRef);
	};
	return variant == "Hierarchical" ? /* @__PURE__ */ react.default.createElement("span", { className: `${className} ${require_util.blockClass}__connector ${require_util.blockClass}__connector--disabled` }, /* @__PURE__ */ react.default.createElement(require_ConditionBuilderButton.ConditionBuilderButton, { label: operator })) : /* @__PURE__ */ react.default.createElement(require_ConditionBuilderItem.ConditionBuilderItem, {
		label: operator,
		title: connectorText,
		"data-name": "connectorField",
		onMouseEnter: activeConnectorHandler,
		onMouseLeave: inActiveConnectorHandler,
		onFocus: activeConnectorHandler,
		onBlur: inActiveConnectorHandler,
		...rest,
		popOverClassName: `${className} ${require_util.blockClass}__connector`,
		className: `${require_util.blockClass}__connector-button`
	}, /* @__PURE__ */ react.default.createElement(require_ItemOption.ItemOption, {
		config: { options: connectorConfig },
		conditionState: {
			value: operator,
			label: connectorText
		},
		onChange: onChangeHandler
	}));
};
ConditionConnector.propTypes = {
	/**
	* Provide an optional class to be applied to the containing node.
	*/
	className: prop_types.default.string,
	/**
	* callback to update the current condition of the state tree
	*/
	onChange: prop_types.default.func,
	/**
	* string that defines the connector operator (and/or)
	*/
	operator: prop_types.default.string
};
//#endregion
exports.default = ConditionConnector;
