/**
 * 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_PageHeaderUtils = require("../PageHeaderUtils.js");
const require_overflowHandler = require("./overflowHandler.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _carbon_react = require("@carbon/react");
//#region src/components/PageHeader/next/PageHeaderTagOverflow.tsx
/**
* Copyright IBM Corp. 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.
*/
var import_classnames = /* @__PURE__ */ require_runtime.__toESM(require_index.default);
const PageHeaderTagOverflow = react.default.forwardRef(({ renderOverflowTag, renderPopoverContent, children }, ref) => {
	const [openPopover, setOpenPopover] = (0, react.useState)(false);
	const [hiddenTags, setHiddenTags] = (0, react.useState)([]);
	const localRef = (0, react.useRef)(null);
	const tagsContainerRef = ref || localRef;
	(0, react.useEffect)(() => {
		const handleResize = () => {
			setOpenPopover(false);
		};
		window.addEventListener("resize", handleResize);
		return () => {
			window.removeEventListener("resize", handleResize);
		};
	}, []);
	const handleOverflowClick = (0, react.useCallback)((event) => {
		event.stopPropagation();
		setOpenPopover((prev) => !prev);
	}, []);
	(0, react.useEffect)(() => {
		require_overflowHandler.createOverflowHandler({
			container: tagsContainerRef.current,
			onChange: (_, hidden) => {
				setHiddenTags(hidden);
			}
		});
	}, []);
	return /* @__PURE__ */ react.default.createElement("div", {
		ref: tagsContainerRef,
		className: (0, import_classnames.default)(`${require_settings.pkg.prefix}--page-header--tag-overflow-container`, { [`${require_settings.pkg.prefix}--page-header--tag-overflow-container__has-no-hidden-items`]: !hiddenTags.length })
	}, children, /* @__PURE__ */ react.default.createElement(_carbon_react.Popover, {
		open: openPopover,
		onRequestClose: () => setOpenPopover(false),
		"data-fixed": true,
		className: (0, import_classnames.default)(`${require_settings.pkg.prefix}--page-header--tag-overflow-popover`, { [`${require_settings.pkg.prefix}--page-header--tag-overflow-popover__hidden`]: !hiddenTags.length })
	}, renderOverflowTag?.(hiddenTags, handleOverflowClick, openPopover), /* @__PURE__ */ react.default.createElement(_carbon_react.PopoverContent, null, /* @__PURE__ */ react.default.createElement("div", { className: `${require_PageHeaderUtils.blockClass}__tags-popover-list` }, renderPopoverContent?.(hiddenTags)))));
});
PageHeaderTagOverflow.displayName = "PageHeaderTagOverflow";
//#endregion
exports.PageHeaderTagOverflow = PageHeaderTagOverflow;
