import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.scss'
import 'react-day-picker/style.css'
import 'leaflet/dist/leaflet.css'
import { RouterProvider } from 'react-router-dom'
import { ApolloProvider } from '@apollo/client/react'
import { LazyMotion, domAnimation } from 'framer-motion'
import { apolloClient } from './shared/api/apolloClient'
import { router } from './app/router/router.tsx'
import { AuthGate } from './features/auth/ui/AuthGate'
import { initTheme } from './shared/theme/theme'

const isAuthEnabled = import.meta.env.VITE_AUTH_ENABLED === 'true'

initTheme()

const app = isAuthEnabled ? (
  <AuthGate>
    <RouterProvider router={router} />
  </AuthGate>
) : (
  <RouterProvider router={router} />
)

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <ApolloProvider client={apolloClient}>
      <LazyMotion features={domAnimation}>
        {app}
      </LazyMotion>
    </ApolloProvider>
  </StrictMode>,
)
