import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './styles/index.css'
import App from './App.tsx'

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <App />
  </StrictMode>,
)

// Register service worker for PWA support
if ('serviceWorker' in navigator) {
  window.addEventListener('load', async () => {
    try {
      const { registerSW } = await import('virtual:pwa-register')
      registerSW({
        onNeedRefresh() {
          if (confirm('New version available. Reload to update?')) {
            window.location.reload()
          }
        },
        onOfflineReady() {
          console.log('CalcPad is ready to work offline')
        },
      })
    } catch {
      // PWA registration not available in dev mode
    }
  })
}
