import { createRouter } from '@tanstack/react-router'
import { setupRouterSsrQueryIntegration } from '@tanstack/react-router-ssr-query'
import { getContext as getQueryContext } from './integrations/tanstack-query'
import { routeTree } from './routeTree.gen'

export const getRouter = () => {
  const queryContext = getQueryContext()

  const router = createRouter({
    routeTree,
    context: {
      ...queryContext,
    },

    scrollRestoration: true,
    defaultPreloadStaleTime: 0,
  })

  setupRouterSsrQueryIntegration({
    router,
    queryClient: queryContext.queryClient,
  })

  return router
}
