import { StrictMode } from 'react'
import { createRoot, hydrateRoot } from 'react-dom/client'
import App from './App'
import { PrefsProvider } from './hooks/usePrefs'
import { routeFor } from './routes'
import './index.css'

const root = document.getElementById('root') as HTMLElement
const app = (
  <StrictMode>
    <PrefsProvider>
      <App route={routeFor(location.pathname)} />
    </PrefsProvider>
  </StrictMode>
)

// The production build is prerendered to static HTML; hydrate it when present.
if (root.hasChildNodes()) hydrateRoot(root, app)
else createRoot(root).render(app)
