import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2025 GoodData Corporation
import { createContext, useContext, useMemo } from "react";
import { useOverlayZIndexWithRegister } from "../../Overlay/OverlayContext.js";
const OverlayContext = createContext({
    zIndex: 1,
});
export const DEFAULT_ELEVATION = 10;
/**
 * @internal
 */
export function OverlayProvider({ children, elevation = DEFAULT_ELEVATION, zIndex }) {
    const parent = useContext(OverlayContext);
    const zIndexOverlay = useOverlayZIndexWithRegister();
    const value = useMemo(() => {
        return {
            zIndex: zIndex ?? zIndexOverlay ?? parent.zIndex + elevation,
        };
    }, [parent.zIndex, elevation, zIndex, zIndexOverlay]);
    return _jsx(OverlayContext.Provider, { value: value, children: children });
}
/**
 * @internal
 */
export function OverlayContent({ children }) {
    const current = useContext(OverlayContext);
    return children({ zIndex: current.zIndex });
}
