import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext, useEffect, useMemo, } from 'react';
import { TelemetryClient } from './client.js';
export function TelemetryProvider({ children, client, ...props }) {
    const value = useMemo(() => {
        return { client: client ?? new TelemetryClient(props) };
    }, [client, props]);
    useEffect(() => {
        value.client.load(props);
        return () => {
            value.client.reset();
        };
    }, [props, value]);
    if (value.client == null) {
        throw new Error(`Must provide a Telemetry client.`);
    }
    const { Provider } = telemetryContext;
    return _jsx(Provider, { value: value, children: children });
}
export const telemetryContext = createContext({
    client: new TelemetryClient(),
});
export function useTelemetryContext() {
    return useContext(telemetryContext);
}
//# sourceMappingURL=TelemetryProvider.js.map