import { DefaultErrorPage } from '@pages/error/default-error.page'
import { NotFoundErrorPage } from '@pages/error/not-found-error.page'
import { createRouter } from '@tanstack/react-router'

import { routeTree } from '../routeTree.gen'

export const router = createRouter({
  routeTree,
  defaultPreload: 'intent',
  scrollRestoration: true,
  context: {
    // This will be set after we wrap the app in an AuthProvider (see main.tsx)
    auth: undefined!,
  },
  defaultErrorComponent: (error) => <DefaultErrorPage error={error} />,
  defaultNotFoundComponent: (error) => <NotFoundErrorPage error={error} />,
  // defaultPendingComponent: () => <div>Loading...</div>,
})

// Register things for typesafety (when using routes as string)
declare module '@tanstack/react-router' {
  // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
  interface Register {
    router: typeof router
  }
}
