/**
 * 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 { useCoachmark } from "./utils/context.js";
import React, { useEffect, useState } from "react";
import PropTypes from "prop-types";
import { Button } from "@carbon/react";
import { Close, Draggable } from "@carbon/react/icons";
//#region src/components/Coachmark/CoachmarkDragbar.tsx
/**
* Copyright IBM Corp. 2023, 2025
*
* 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}--coachmark-dragbar`;
const overlayBlockClass = `${pkg.prefix}--coachmark-overlay`;
const componentName = "CoachmarkDragbar";
const defaults = {
	onDrag: () => {},
	onClose: () => {},
	showCloseButton: true,
	theme: "light"
};
/**
* DO NOT USE. This component is for the exclusive use
* of other Onboarding components.
* @deprecated This component is deprecated.
*/
const CoachmarkDragbar = React.forwardRef(({ a11yKeyboardHandler, onClose = defaults.onClose, onDrag = defaults.onDrag, showCloseButton = defaults.showCloseButton, theme = defaults.theme, ...rest }, ref) => {
	const [isDragging, setIsDragging] = useState(false);
	useEffect(() => {
		const handleDragStop = () => setIsDragging(false);
		window.addEventListener("mouseup", handleDragStop);
		return () => {
			window.removeEventListener("mouseup", handleDragStop);
		};
	}, []);
	useEffect(() => {
		const handleDrag = (event) => {
			onDrag(event.movementX, event.movementY);
		};
		if (isDragging) window.addEventListener("mousemove", handleDrag);
		return () => {
			window.removeEventListener("mousemove", handleDrag);
		};
	}, [isDragging, onDrag]);
	const handleDragStart = () => setIsDragging(true);
	const closeIconDescription = useCoachmark()?.closeIconDescription;
	return /* @__PURE__ */ React.createElement("header", {
		...rest,
		className: (0, import_classnames.default)(blockClass, `${blockClass}__${theme}`, {}),
		ref,
		...getDevtoolsProps(componentName)
	}, /* @__PURE__ */ React.createElement("button", {
		type: "button",
		className: `${overlayBlockClass}__handle`,
		onMouseDown: handleDragStart,
		onKeyDown: a11yKeyboardHandler,
		title: "Drag Handle"
	}, /* @__PURE__ */ React.createElement(Draggable, { size: "16" })), showCloseButton && /* @__PURE__ */ React.createElement(Button, {
		kind: "ghost",
		size: "sm",
		renderIcon: Close,
		iconDescription: closeIconDescription,
		hasIconOnly: true,
		className: `${overlayBlockClass}--close-btn`,
		onClick: onClose
	}));
});
/**@ts-ignore*/
CoachmarkDragbar.deprecated = {
	level: "warn",
	details: `${componentName} is deprecated.`
};
CoachmarkDragbar.displayName = componentName;
CoachmarkDragbar.propTypes = {
	/**
	* Handler to manage keyboard interactions with the dragbar.
	*/
	a11yKeyboardHandler: PropTypes.func.isRequired,
	/**
	* Function to call when the close button is clicked.
	*/
	onClose: PropTypes.func,
	/**
	* Function to call when the user clicks and drags the Coachmark.
	* For internal use only by the parent CoachmarkOverlay.
	*/
	onDrag: PropTypes.func,
	/**
	* Show/hide the "X" close button.
	*/
	showCloseButton: PropTypes.bool,
	/**
	* Determines the theme of the component.
	*/
	theme: PropTypes.oneOf(["light", "dark"])
};
//#endregion
export { CoachmarkDragbar };
