import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2022-2025 GoodData Corporation
import { createContext, useContext, useEffect, useState } from "react";
import { v4 as uuid } from "uuid";
/**
 * @internal
 */
export const OverlayContext = createContext(undefined);
OverlayContext.displayName = "OverlayContext";
/**
 * Component for injecting {@link OverlayController} into all components in the application.
 *
 * @internal
 */
export function OverlayControllerProvider({ children, overlayController }) {
    return _jsx(OverlayContext.Provider, { value: overlayController, children: children });
}
/**
 * Hook to get current instance of the {@link OverlayController}
 *
 * @returns an instance of the {@link OverlayController}
 *
 * @internal
 */
export const useOverlayController = () => {
    return useContext(OverlayContext);
};
/**
 * Hook to get the css `z-index` property for given overlay.
 *
 * @param uuid - uuid of the overlay.
 *
 * @returns - `z-index` for given overlay.
 *
 * @internal
 */
export const useOverlayZIndex = (uuid) => {
    const overlayController = useContext(OverlayContext);
    return overlayController?.getZIndex(uuid);
};
/**
 * Registers a new overlay and returns its z-index
 *
 * @returns the overlay's z-index
 *
 * @internal
 */
export function useOverlayZIndexWithRegister() {
    const [overlayId] = useState(uuid());
    const overlayController = useOverlayController();
    const zIndex = useOverlayZIndex(overlayId);
    useEffect(() => {
        if (!overlayController) {
            return undefined;
        }
        overlayController.addOverlay(overlayId);
        return () => overlayController.removeOverlay(overlayId);
    }, [overlayController, overlayId]);
    return zIndex;
}
//# sourceMappingURL=OverlayContext.js.map