'use client';

import { Provider } from 'react-redux';
import { store } from '@/lib/store/store';
import { ThemeProvider } from 'next-themes';
import { Toaster } from '@/components/ui/sonner';
import AuthGuard from './auth/auth-guard';
import dynamic from 'next/dynamic';

// 动态导入 OAuthCallbackHandler 和 DevHelper
const OAuthCallbackHandler = dynamic(
  () => import('./ui/oauth-callback-handler').then(mod => mod.default),
  { ssr: false }
);

const DevHelper = dynamic(
  () => import('@/utils/dev-helper').then(mod => mod.default),
  { ssr: false }
);

export function Providers({ children }: { children: React.ReactNode }) {
  return (
    <Provider store={store}>
      <ThemeProvider
        attribute="class"
        defaultTheme="dark"
        enableSystem
        disableTransitionOnChange
      >
        <AuthGuard>
          {children}
        </AuthGuard>
        <Toaster />
        <OAuthCallbackHandler />
        {process.env.NODE_ENV === 'development' && <DevHelper />}
      </ThemeProvider>
    </Provider>
  );
} 