import { defineConfig } from 'vite'
import mdx from '@mdx-js/rollup'
import react from '@vitejs/plugin-react'
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import { paraglideVitePlugin } from '@inlang/paraglide-js'
import { getSitemapPages } from './lib/sitemap'

// Plain-object config (not a callback): the fabric deploy injects a CF adapter
// via `mergeConfig(base, thisConfig)`, and vite's mergeConfig cannot merge a
// config in the form of a callback. Paraglide is a hard dependency, so import
// it statically (matches the green germantax/perauset apps).
export default defineConfig({
  plugins: [
    paraglideVitePlugin({
      project: './project.inlang',
      outdir: './i18n/paraglide',
    }),
    { enforce: 'pre', ...mdx() },
    tanstackStart({
      srcDirectory: 'src',
      pages: getSitemapPages(),
      sitemap: {
        host: process.env.VITE_SITE_URL ?? 'https://hey-germany.com',
      },
      router: {
        routesDirectory: 'routes',
        generatedRouteTree: 'routeTree.gen.ts',
      },
    }),
    react({
      include: /\.(mdx|js|jsx|ts|tsx)$/,
    }),
  ],
})
