'use client';

import { ContainerProvider } from '@/lib/di/providers/ContainerProvider';
import { QueryClientProvider } from '@/lib/providers/QueryClientProvider';
import { AuthProvider } from '@/components/auth/AuthContext';
import { FeatureFlagProvider } from '@/lib/feature/FeatureFlagProvider';
import { NotificationProvider } from '@/components/notifications/NotificationProvider';
import { NotificationIntegration } from '@/components/errors/NotificationIntegration';
import { EnhancedErrorBoundary } from '@/components/errors/EnhancedErrorBoundary';
import { DevToolbar } from '@/components/dev/DevToolbar';
import { ThemeProvider } from '@/components/shared/ThemeProvider';
import React from 'react';

interface AppWrapperProps {
  children: React.ReactNode;
  enabledFlags: string[];
}

export function AppWrapper({ children, enabledFlags }: AppWrapperProps) {
  return (
    <ContainerProvider>
      <QueryClientProvider>
        <ThemeProvider>
          <AuthProvider>
            <FeatureFlagProvider flags={enabledFlags}>
              <NotificationProvider>
                <NotificationIntegration />
                <EnhancedErrorBoundary enableDevOverlay={process.env.NODE_ENV === 'development'}>
                  {children}
                  {process.env.NODE_ENV === 'development' && <DevToolbar />}
                </EnhancedErrorBoundary>
              </NotificationProvider>
            </FeatureFlagProvider>
          </AuthProvider>
        </ThemeProvider>
      </QueryClientProvider>
    </ContainerProvider>
  );
}