'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// packages/ui/src/providers/NextJsAppProviders.tsx
/**
 * @fileoverview NextJsAppProviders component
 * @description Next.js-specific app providers with SSR support
 *
 * @version 0.0.1
 * @since 0.0.1
 * @author AMBROISE PARK Consulting
 */
import { lazy, Suspense } from 'react';
import { HelmetProvider } from 'react-helmet-async';
import { QueryProviders, AppConfigProvider } from '@donotdev/core';
import { useConsent } from '@donotdev/core';
import { NextJsStoresInitializer } from '../internal/initializers/NextJsStoresInitializer';
import FaviconHead from '../internal/layout/components/FaviconHead';
import PerformanceHints from '../internal/layout/components/PerformanceHints';
// import NextJsAutoMetaTags from '../internal/layout/components/NextJsAutoMetaTags'; // Deprecated - metadata now server-side
import { DnDevLayout } from '../internal/layout/DnDevLayout';
import { SentryInitializer } from '../internal/providers/SentryInitializer';
import { UIProviders } from '../internal/providers/UIProviders';
// Null fallback for lazy components that fail to load (e.g., optional auth dependency absent)
const NullFallback = () => null;
// Lazy load client-only components — each wrapped with catch to prevent hanging
// if an optional dependency (e.g., @donotdev/auth) is not installed.
const CookieConsent = lazy(() => import('../components/cookie-consent/CookieConsent').catch(() => ({ default: NullFallback })));
const PWAUpdateNotification = lazy(() => import('../internal/layout/components/PWAUpdateNotification')
    .then((m) => ({ default: m.default }))
    .catch(() => ({ default: NullFallback })));
const LicenseWatermark = lazy(() => import('../components/license/LicenseWatermark')
    .then((m) => ({ default: m.LicenseWatermark }))
    .catch(() => ({ default: NullFallback })));
const RedirectOverlay = lazy(() => import('../components/common/RedirectOverlay')
    .then((m) => ({ default: m.RedirectOverlay }))
    .catch(() => ({ default: NullFallback })));
/**
 * ConsentBanner - Lazy loaded consent component
 * Only shows if user hasn't consented yet
 *
 * @version 0.0.1
 * @since 0.0.1
 * @author AMBROISE PARK Consulting
 */
function ConsentBanner() {
    const hasConsented = useConsent('hasConsented');
    // Don't show if user has already consented
    if (hasConsented) {
        return null;
    }
    return (_jsx(Suspense, { fallback: null, children: _jsx(CookieConsent, {}) }));
}
export function NextJsAppProviders(props) {
    const { config = {}, layout, children, serverCookies, customStores } = props;
    return (_jsxs(AppConfigProvider, { config: config, platform: "nextjs", children: [_jsx(SentryInitializer, {}), _jsx(HelmetProvider, { children: _jsxs(NextJsStoresInitializer, { serverCookies: serverCookies, customStores: customStores, children: [_jsx(FaviconHead, {}), _jsx(PerformanceHints, {}), _jsx(QueryProviders, { children: _jsxs(UIProviders, { children: [_jsx(DnDevLayout, { layout: layout, children: children }), _jsx(ConsentBanner, {}), _jsx(Suspense, { fallback: null, children: _jsx(PWAUpdateNotification, {}) }), _jsx(Suspense, { fallback: null, children: _jsx(LicenseWatermark, {}) }), _jsx(Suspense, { fallback: null, children: _jsx(RedirectOverlay, {}) })] }) })] }) })] }));
}
