'use client';


import { useCallback, useEffect, useRef } from "react";
import { jsx } from "react/jsx-runtime";

//#region src/components/ClickOutsideDiv/index.tsx
const ClickOutsideDiv = ({ children, onClickOutSide, listenForEscape = false, disabled = false, ...props }) => {
	const divRef = useRef(null);
	const handleClickOutside = useCallback((event) => {
		if (disabled) return;
		if (divRef.current && !divRef.current.contains(event.target)) onClickOutSide();
	}, [onClickOutSide, disabled]);
	const handleKeyDown = useCallback((event) => {
		if (disabled || !listenForEscape) return;
		if (event.key === "Escape") onClickOutSide();
	}, [
		onClickOutSide,
		disabled,
		listenForEscape
	]);
	useEffect(() => {
		document.addEventListener("mousedown", handleClickOutside, { passive: true });
		if (listenForEscape) document.addEventListener("keydown", handleKeyDown);
		return () => {
			document.removeEventListener("mousedown", handleClickOutside);
			if (listenForEscape) document.removeEventListener("keydown", handleKeyDown);
		};
	}, [
		handleClickOutside,
		handleKeyDown,
		listenForEscape
	]);
	return /* @__PURE__ */ jsx("div", {
		ref: divRef,
		...props,
		role: props.role || "region",
		children
	});
};

//#endregion
export { ClickOutsideDiv };
//# sourceMappingURL=index.mjs.map