import { render } from 'solid-js/web';
import { Router, RouteSectionProps } from '@solidjs/router';
import { ClerkProvider } from './lib/auth/clerk-provider';
import { routes } from './routes';
import './index.css';

if ('serviceWorker' in navigator) {
  window.addEventListener('load', () => {
    navigator.serviceWorker.register('/sw.js').catch((err) => {
      console.warn('Service worker registration failed:', err);
    });
  });
}

render(
  () => (
    <ClerkProvider>
      <Router root={(props: RouteSectionProps) => <>{props.children}</>}>
        {routes}
      </Router>
    </ClerkProvider>
  ),
  document.getElementById('root')!
);
