// ===================
// © AngelaMos | 2026
// index.tsx
// ===================
import { Router } from '@solidjs/router'
import { QueryClient, QueryClientProvider } from '@tanstack/solid-query'
import { render } from 'solid-js/web'
import App from './App'
import { ToastContainer } from './components/UI/Toast'
import './index.css'
import { authService } from './services'

const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      refetchOnWindowFocus: false,
      retry: 1,
      staleTime: 5 * 60 * 1000,
    },
  },
})

const root = document.getElementById('root')

if (root === null) {
  throw new Error('Root element not found')
}

void authService.rehydrateSession()

render(
  () => (
    <QueryClientProvider client={queryClient}>
      <Router>
        <App />
      </Router>
      <ToastContainer />
    </QueryClientProvider>
  ),
  root
)
