/**
 * 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_context = require("./context.js");
const require_makeDraggable = require("../../../../global/js/utils/makeDraggable/makeDraggable.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/Coachmark/next/Coachmark/ContentHeader.tsx
/**
* Copyright IBM Corp. 2024, 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 ContentHeader = (0, react.forwardRef)((props, ref) => {
	const { className = "", closeIconDescription, dragIconDescription, children, ...rest } = props;
	const { setOpen, onClose, contentRef, floating } = (0, react.useContext)(require_context.CoachmarkContext);
	const headerRef = (0, react.useRef)(null);
	const dragRef = (0, react.useRef)(null);
	const handleRef = ref || headerRef;
	const contentHeaderBlockClass = `${require_context.blockClass}--content-header`;
	const closeBubble = (e) => {
		e?.stopPropagation();
		onClose?.();
		setOpen(false);
	};
	(0, react.useEffect)(() => {
		if (floating && contentRef && typeof handleRef === "object" && handleRef !== null && "current" in handleRef && handleRef.current && dragRef.current) {
			const dragStyleContainer = contentRef.querySelector(`.${require_settings.carbon.prefix}--popover-content`);
			contentRef.style.transform = "none";
			contentRef.style.left = "0px";
			contentRef.style.top = "0px";
			const draggable = require_makeDraggable.makeDraggable({
				el: contentRef,
				dragHandle: handleRef.current,
				focusableDragHandle: dragRef.current
			});
			const onDragStart = () => {
				if (dragStyleContainer) {
					dragStyleContainer.classList.add(`${contentHeaderBlockClass}--is-dragging`);
					dragStyleContainer.setAttribute("aria-label", "Coachmark is being dragged");
				}
			};
			const onDragEnd = () => {
				if (dragStyleContainer) {
					dragStyleContainer.classList.remove(`${contentHeaderBlockClass}--is-dragging`);
					dragStyleContainer.removeAttribute("aria-label");
				}
			};
			contentRef.addEventListener("dragstart", onDragStart);
			contentRef.addEventListener("dragend", onDragEnd);
			return () => {
				contentRef.removeEventListener("dragstart", onDragStart);
				contentRef.removeEventListener("dragend", onDragEnd);
				draggable.cleanup();
			};
		}
	}, [
		floating,
		contentRef,
		handleRef,
		dragRef,
		contentHeaderBlockClass
	]);
	return /* @__PURE__ */ react.default.createElement("div", {
		ref: handleRef,
		className: (0, import_classnames.default)(contentHeaderBlockClass, className),
		...rest
	}, floating && /* @__PURE__ */ react.default.createElement(_carbon_react.Button, {
		kind: "ghost",
		size: "sm",
		ref: dragRef,
		renderIcon: _carbon_react_icons.Draggable,
		iconDescription: dragIconDescription,
		hasIconOnly: true,
		className: `${contentHeaderBlockClass}--drag-icon`
	}), children, /* @__PURE__ */ react.default.createElement(_carbon_react.Button, {
		kind: "ghost",
		size: "sm",
		renderIcon: _carbon_react_icons.Close,
		iconDescription: closeIconDescription,
		hasIconOnly: true,
		onClick: closeBubble
	}));
});
ContentHeader.propTypes = {
	/**
	* Optional contents of the Coachmark Header.
	*/
	children: prop_types.default.node,
	/**
	* Provide an optional class to be applied to the containing node.
	*/
	className: prop_types.default.string,
	/**
	* Tooltip text and aria label for the Close button icon.
	*/
	closeIconDescription: prop_types.default.string,
	/**
	* Tooltip text and aria label for the Drag button icon.
	*/
	dragIconDescription: prop_types.default.string
};
//#endregion
exports.ContentHeader = ContentHeader;
