import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2024-2026 GoodData Corporation
import { useCallback, useState } from "react";
import { areObjRefsEqual } from "@gooddata/sdk-model";
import { createContextStore } from "@gooddata/sdk-ui";
// Create the context with a default value
export const HoveredWidgetContext = createContextStore("HoveredWidgets");
export const useHoveredWidgetContextValue = () => {
    const [hoveredWidgets, setHoveredWidgets] = useState([]);
    const addHoveredWidget = useCallback((widgetRef) => {
        setHoveredWidgets((prev) => {
            if (!widgetRef || prev.some((ref) => areObjRefsEqual(ref, widgetRef))) {
                return prev;
            }
            return [...prev, widgetRef];
        });
    }, []);
    const removeHoveredWidget = useCallback((widgetRef) => {
        setHoveredWidgets((prev) => {
            if (!widgetRef || !prev.some((ref) => areObjRefsEqual(ref, widgetRef))) {
                return prev;
            }
            return prev.filter((ref) => !areObjRefsEqual(ref, widgetRef));
        });
    }, []);
    const isHovered = useCallback((widgetRef, hoveredWidgets) => {
        return hoveredWidgets.some((ref) => areObjRefsEqual(ref, widgetRef));
    }, []);
    return { hoveredWidgets, addHoveredWidget, removeHoveredWidget, isHovered };
};
export function HoveredWidgetProvider({ children }) {
    return _jsx(HoveredWidgetContext, { value: useHoveredWidgetContextValue(), children: children });
}
//# sourceMappingURL=HoveredWidgetContext.js.map