'use client';

import { useEffect, type ReactNode } from 'react';
import { AuthProvider } from '@/lib/auth-context';
import { ThemeProvider } from '@/lib/theme-context';
import { StripeConfigProvider } from '@/lib/stripe-context';
import { ProductProvider } from '@/lib/product-context';
import { ToastProvider } from '@/components/ui/toast';
import { CSPostHogProvider } from '@/components/posthog-provider';
import { initTelemetry } from '@/lib/telemetry';

export function Providers({ children }: { children: ReactNode }) {
  useEffect(() => {
    initTelemetry();
  }, []);

  return (
    <CSPostHogProvider>
      <ThemeProvider>
        <ProductProvider>
          <AuthProvider>
            <StripeConfigProvider>
              <ToastProvider>{children}</ToastProvider>
            </StripeConfigProvider>
          </AuthProvider>
        </ProductProvider>
      </ThemeProvider>
    </CSPostHogProvider>
  );
}
