import { onCLS, onLCP, onFCP, onTTFB } from 'web-vitals';
import { useMount } from '@redocly/theme/core/openapi';
// TODO: web-vitals relies on the Performance API, which has varying browser support.
// TODO: add session duration to the metrics
// Consider implementing fallback mechanisms or alternative performance tracking approaches.
export function usePerformanceMetrics({ sendTelemetry }) {
    useMount(() => {
        const metricsTracker = {};
        const metricsPromises = [
            new Promise((resolve) => onCLS((metric) => resolve({ name: 'CLS', value: metric.value }))),
            new Promise((resolve) => onLCP((metric) => resolve({ name: 'LCP', value: metric.value }))),
            new Promise((resolve) => onFCP((metric) => resolve({ name: 'FCP', value: metric.value }))),
            new Promise((resolve) => onTTFB((metric) => resolve({ name: 'TTFB', value: metric.value }))),
        ];
        Promise.allSettled(metricsPromises).then((results) => {
            results.forEach((result) => {
                if (result.status === 'fulfilled') {
                    const { name, value } = result.value;
                    metricsTracker[name] = Math.round(value);
                }
            });
            sendTelemetry(metricsTracker);
        });
    });
}
//# sourceMappingURL=usePerformanceMetrics.js.map