import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2023-2025 GoodData Corporation
import { createContext, useContext } from "react";
import { invariant } from "ts-invariant";
const TelemetryContext = createContext(undefined);
TelemetryContext.displayName = "TelemetryContext";
export function TelemetryProvider({ trackEvent, children }) {
    return _jsx(TelemetryContext.Provider, { value: trackEvent, children: children });
}
export const useTelemetry = () => {
    const trackEvent = useContext(TelemetryContext);
    invariant(trackEvent, "useTelemetry must be called in TelemetryContext with initialized value!");
    return trackEvent;
};
export function withTelemetry(WrappedComponent) {
    function ResultComponent(props) {
        return (_jsx(TelemetryProvider, { trackEvent: props.onEvent, children: _jsx(WrappedComponent, { ...props }) }));
    }
    ResultComponent.displayName = WrappedComponent.displayName;
    return ResultComponent;
}
//# sourceMappingURL=TelemetryContext.js.map