import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2019-2026 GoodData Corporation
import { useEffect, useRef } from "react";
import { HoveredWidgetContext } from "../../../dragAndDrop/HoveredWidgetContext.js";
export function HoverDetector({ widgetRef, children }) {
    const { addHoveredWidget, removeHoveredWidget } = HoveredWidgetContext.useContextStoreValues([
        "addHoveredWidget",
        "removeHoveredWidget",
    ]);
    const divRef = useRef(null);
    useEffect(() => {
        const handleMouseEnter = () => {
            addHoveredWidget(widgetRef);
        };
        const handleMouseLeave = () => {
            removeHoveredWidget(widgetRef);
        };
        const divElement = divRef.current;
        if (divElement) {
            divElement.addEventListener("mouseenter", handleMouseEnter);
            divElement.addEventListener("mouseleave", handleMouseLeave);
        }
        return () => {
            removeHoveredWidget(widgetRef);
            if (divElement) {
                divElement.removeEventListener("mouseenter", handleMouseEnter);
                divElement.removeEventListener("mouseleave", handleMouseLeave);
            }
        };
    }, [addHoveredWidget, removeHoveredWidget, widgetRef]);
    return (_jsx("div", { ref: divRef, className: "gd-hover-detector", children: children }));
}
//# sourceMappingURL=HoverDetector.js.map