'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// packages/ui/src/internal/layout/components/PerformanceHints.tsx
/**
 * @fileoverview Performance hints for faster page loads
 * @description Adds preconnect, dns-prefetch, and font preload hints
 *
 * - Preconnect establishes early connections (DNS + TCP + TLS) to origins
 *   the page will need, saving 100-300ms per origin on slow networks.
 * - Font preload initiates font downloads early, reducing LCP by ~500-1000ms
 *
 * @version 0.0.2
 * @since 0.0.1
 * @author AMBROISE PARK Consulting
 */
import { Helmet } from 'react-helmet-async';
/**
 * Common third-party origins that benefit from preconnect
 * Only includes origins that are commonly used and safe to preconnect
 */
const DEFAULT_PRECONNECTS = [
    // YouTube embeds - thumbnails and iframe
    'https://img.youtube.com',
    'https://www.youtube.com',
    // Google Fonts (if used)
    'https://fonts.googleapis.com',
    'https://fonts.gstatic.com',
    // Google APIs (Firebase, Analytics, etc.)
    'https://www.googleapis.com',
    // Stripe (if used)
    'https://js.stripe.com',
];
/**
 * Origins to dns-prefetch only (less aggressive than preconnect)
 * Use for origins that might be needed but aren't certain
 */
const DEFAULT_DNS_PREFETCH = [
    'https://www.google-analytics.com',
    'https://www.googletagmanager.com',
];
/**
 * Default critical fonts to preload.
 * Empty: when using the framework's Vite or Next setup, font preload is handled by build-time
 * injection (Vite: FontPreloadPlugin patches index.html; Next: FontPreloadLinks in root layout
 * reads public/dndev-font-preloads.json). Pass fontPreloads only for extra/custom URLs.
 */
const DEFAULT_FONT_PRELOADS = [];
/**
 * PerformanceHints component
 *
 * Adds preconnect, dns-prefetch, and font preload hints to improve page load.
 * Automatically includes common third-party origins and critical fonts.
 *
 * @example
 * ```tsx
 * // Default: preconnect/dns-prefetch only; font preload handled by framework build (Vite/Next)
 * <PerformanceHints />
 *
 * // Add custom font preload URLs
 * <PerformanceHints fontPreloads={[customFontUrl]} />
 *
 * // Disable font preloads
 * <PerformanceHints disableFontPreloads />
 * ```
 */
const PerformanceHints = ({ preconnects = [], dnsPrefetch = [], fontPreloads = [], disableDefaults = false, disableFontPreloads = false, }) => {
    // Merge defaults with custom origins
    const allPreconnects = disableDefaults
        ? preconnects
        : [...new Set([...DEFAULT_PRECONNECTS, ...preconnects])];
    const allDnsPrefetch = disableDefaults
        ? dnsPrefetch
        : [...new Set([...DEFAULT_DNS_PREFETCH, ...dnsPrefetch])];
    // Normalize font preloads to FontPreload objects
    const normalizeFontPreload = (font) => typeof font === 'string' ? { href: font } : font;
    const customFontPaths = fontPreloads.map((f) => typeof f === 'string' ? f : f.href);
    const allFontPreloads = disableFontPreloads
        ? []
        : fontPreloads.length > 0
            ? fontPreloads.map(normalizeFontPreload)
            : DEFAULT_FONT_PRELOADS.filter((f) => !customFontPaths.includes(f)).map(normalizeFontPreload);
    return (_jsxs(Helmet, { children: [allFontPreloads.map((font) => (_jsx("link", { rel: "preload", as: "font", href: font.href, type: font.type || 'font/woff2', crossOrigin: font.crossOrigin || 'anonymous' }, `font-${font.href}`))), allPreconnects.map((origin) => (_jsx("link", { rel: "preconnect", href: origin, crossOrigin: "anonymous" }, `preconnect-${origin}`))), allDnsPrefetch.map((origin) => (_jsx("link", { rel: "dns-prefetch", href: origin }, `dns-${origin}`)))] }));
};
export default PerformanceHints;
