import { StrictMode } from 'react'
import ReactDOM from 'react-dom/client'
import { RouterProvider, createRouter } from '@tanstack/react-router'
import { QueryClient } from '@tanstack/react-query'
import AppStackAuthProvider, { stackClientApp } from './integrations/stack-auth/provider'
import { routeTree } from './routeTree.gen'
import AppConvexProvider from './integrations/convex/provider'
import { ThemeProvider } from './integrations/themes/provider'

import './style.css'

const queryClient = new QueryClient()
const authClient = stackClientApp

export const router = createRouter({
	routeTree,
	context: {
		queryClient,
		authClient,
	},
})

declare module '@tanstack/react-router' {
	interface Register {
		router: typeof router
	}
}

const rootElement = document.getElementById('app')!
if (!rootElement.innerHTML) {
	const root = ReactDOM.createRoot(rootElement)
	root.render(
		<StrictMode>
			<RouterProvider router={router} />
		</StrictMode>,
	)
}
