import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { RouterProvider } from 'react-router-dom'
import './index.css'
import { router } from './app/router'
import { AuthProvider } from './context/AuthContext'
import { bootstrapReports } from './data/reports'
import { bootstrapEvents } from './data/events'
import { bootstrapTeam } from './data/team'
import { bootstrapRadar } from './content/radar'
import { bootstrapRadarPages } from './content/radarCategories'
import { bootstrapBanners } from './data/banners'
import { bootstrapPlans } from './data/plans'
import { bootstrapRisks } from './data/risks'
import { bootstrapMarket } from './data/market'
import { bootstrapFactoryReports } from './content/factoryReports'
import { bootstrapIntegrations } from './content/integrations'
import { bootstrapAbout } from './data/about'
import { bootstrapMedia } from './data/media'
import { bootstrapPosts } from './content/posts'
import { bootstrapRadarFuture } from './content/radarFuture'

await Promise.all([
  bootstrapReports(), bootstrapEvents(), bootstrapTeam(), bootstrapRadar(), bootstrapRadarPages(), bootstrapBanners(),
  bootstrapPlans(), bootstrapRisks(), bootstrapMarket(),
  bootstrapFactoryReports(), bootstrapIntegrations(), bootstrapAbout(), bootstrapMedia(), bootstrapPosts(), bootstrapRadarFuture(),
])

// PWA: register service worker in production builds only (skip in dev — avoids stale-cache pain)
if ('serviceWorker' in navigator && import.meta.env.PROD) {
  window.addEventListener('load', () => {
    navigator.serviceWorker.register('/sw.js').catch(() => {})
  })
}
// iOS Safari ignores user-scalable=no — block pinch + double-tap zoom manually
document.addEventListener('gesturestart', (e) => e.preventDefault())
document.addEventListener('dblclick', (e) => e.preventDefault(), { passive: false })

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <AuthProvider>
      <RouterProvider router={router} />
    </AuthProvider>
  </StrictMode>,
)