import useHasFeature from '../../hooks/auth/useHasFeature';
import { MOBILE_DATADOG_SESSION_REPLAY } from '../../constants/features';
import { useEffect } from 'react';
import * as datadogService from '../../services/datadog.service';
import { useReactiveVar } from '@apollo/client';
import { logException } from '../../services/sentry.service';

export const DatadogSessionHandler = () => {
    const sdkInitialized = useReactiveVar(
        datadogService.sdkInitializedReactiveVar
    );
    const hasDatadogSessionReplay = useHasFeature(
        MOBILE_DATADOG_SESSION_REPLAY
    );

    useEffect(() => {
        datadogService
            .enableSessionReplay(sdkInitialized && hasDatadogSessionReplay)
            .catch(logException);
    }, [sdkInitialized, hasDatadogSessionReplay]);

    return null;
};
