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

import { __toESM } from "../../../_virtual/_rolldown/runtime.js";
import { require_classnames } from "../../../node_modules/classnames/index.js";
import { pkg } from "../../../settings.js";
import { getDevtoolsProps } from "../../../global/js/utils/devtools.js";
import { FilterPanelCheckbox } from "../FilterPanelCheckbox/FilterPanelCheckbox.js";
import React, { useEffect, useRef, useState } from "react";
import PropTypes from "prop-types";
import { OverflowMenu } from "@carbon/react";

//#region src/components/FilterPanel/FilterPanelCheckboxWithOverflow/FilterPanelCheckboxWithOverflow.jsx
/**
* Copyright IBM Corp. 2024, 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__ */ __toESM(require_classnames());
const blockClass = `${pkg.prefix}--filter-panel-checkbox-with-overflow`;
const componentName = "FilterPanelCheckboxWithOverflow";
const defaults = { overflowMenuProps: {} };
/**
* Provides a filter panel checkbox with an overflow menu.
*
* This component's props refer to the Carbon Checkbox,
* just like FilterPanelCheckbox.
*
* Use `overflowMenuProps` for properties specific to the OverflowMenu.
* @deprecated This component is deprecated
*/
let FilterPanelCheckboxWithOverflow = React.forwardRef(({ children, className, count, id, labelText, overflowMenuProps = defaults.overflowMenuProps, title, ...rest }, ref) => {
	const [menuIsOpen, setMenuIsOpen] = useState(false);
	const [showMenuButton, setShowMenuButton] = useState(false);
	const { ...other } = overflowMenuProps;
	const backupRef = useRef(void 0);
	const localRef = ref || backupRef;
	const setHideButton = (activeElement) => {
		if (!menuIsOpen && !localRef.current.contains(activeElement)) setShowMenuButton(false);
	};
	useEffect(() => {
		setShowMenuButton(menuIsOpen);
	}, [menuIsOpen]);
	return /* @__PURE__ */ React.createElement("div", {
		className: (0, import_classnames.default)(blockClass, className, { [`${blockClass}--open`]: menuIsOpen }),
		onBlur: ({ relatedTarget }) => setHideButton(relatedTarget),
		onFocus: () => setShowMenuButton(true),
		onMouseDown: (event) => event.preventDefault(),
		onMouseEnter: () => setShowMenuButton(true),
		onMouseLeave: () => setHideButton(document.activeElement),
		ref: localRef,
		...getDevtoolsProps(componentName)
	}, /* @__PURE__ */ React.createElement(FilterPanelCheckbox, {
		...rest,
		className: (0, import_classnames.default)(`${blockClass}__checkbox`),
		count,
		id,
		labelText,
		title
	}), showMenuButton && /* @__PURE__ */ React.createElement(OverflowMenu, {
		open: overflowMenuProps?.open,
		className: (0, import_classnames.default)(`${blockClass}__overflow-button`, overflowMenuProps?.menuClass),
		menuOptionsClass: (0, import_classnames.default)(`${blockClass}__overflow-options`, overflowMenuProps?.menuOptionsClass),
		"aria-label": overflowMenuProps?.["aria-label"],
		iconDescription: overflowMenuProps?.["aria-label"],
		onOpen: () => setMenuIsOpen(true),
		onClose: () => setMenuIsOpen(false),
		flipped: overflowMenuProps?.flipped || true,
		selectorPrimaryFocus: overflowMenuProps?.selectorPrimaryFocus,
		...other
	}, children));
});
FilterPanelCheckboxWithOverflow.deprecated = {
	level: "warn",
	details: `This component is deprecated`
};
FilterPanelCheckboxWithOverflow = pkg.checkComponentEnabled(FilterPanelCheckboxWithOverflow, componentName);
FilterPanelCheckboxWithOverflow.displayName = componentName;
FilterPanelCheckboxWithOverflow.propTypes = {
	children: PropTypes.node.isRequired,
	className: PropTypes.string,
	count: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
	id: PropTypes.string.isRequired,
	labelText: PropTypes.node.isRequired,
	onChange: PropTypes.func,
	overflowMenuProps: PropTypes.shape({
		["aria-label"]: PropTypes.string,
		flipped: PropTypes.bool,
		menuClass: PropTypes.string,
		menuOptionsClass: PropTypes.string,
		open: PropTypes.bool,
		selectorPrimaryFocus: PropTypes.string
	}),
	title: PropTypes.string
};

//#endregion
export { FilterPanelCheckboxWithOverflow };