import React from 'react'
import ReactDOM from 'react-dom/client'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { ThemeProvider } from '@/client/components/theme-provider'
import { Toaster } from '@/components/ui/sonner'
import { initSentry } from '@/client/lib/sentry'
import { appConfig, getThemeStorageKey } from '@/shared/config/app'
import App from './App'
import '@/index.css'

// Initialize Sentry for error tracking (must be done early)
initSentry()

// Create a query client for TanStack Query
const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      staleTime: 1000 * 60 * 5, // 5 minutes
      refetchOnWindowFocus: false,
    },
  },
})

ReactDOM.createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
    <QueryClientProvider client={queryClient}>
      <ThemeProvider defaultTheme={appConfig.defaultThemeMode} storageKey={getThemeStorageKey()}>
        <App />
        <Toaster />
      </ThemeProvider>
    </QueryClientProvider>
  </React.StrictMode>,
)
