import { prefetchRoute } from '@/lib/prefetch'

/** Map of base route paths to their lazy import functions for hover-prefetching */
const PREFETCH_MAP: Record<string, () => Promise<unknown>> = {
  '/': () => import('@/pages/QuickStartPage'),
  '/trees': () => import('@/pages/TreeLibraryPage'),
  '/my-trees': () => import('@/pages/MyTreesPage'),
  '/sessions': () => import('@/pages/SessionHistoryPage'),
  '/shares': () => import('@/pages/MySharesPage'),
  '/analytics': () => import('@/pages/TeamAnalyticsPage'),
  '/analytics/me': () => import('@/pages/MyAnalyticsPage'),
  '/assistant': () => import('@/pages/AssistantChatPage'),
  '/step-library': () => import('@/pages/StepLibraryPage'),
  '/guides': () => import('@/pages/GuidesHubPage'),
  '/feedback': () => import('@/pages/FeedbackPage'),
  '/account': () => import('@/pages/AccountSettingsPage'),
}

/** Prefetch the chunk for a route on hover/focus */
export function prefetchForRoute(path: string) {
  // Strip query params for lookup
  const basePath = path.split('?')[0]
  const importFn = PREFETCH_MAP[basePath]
  if (importFn) {
    prefetchRoute(importFn)
  }
}
