import path from "node:path";

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import tailwindcss from "@tailwindcss/vite";
import tanstackRouter from "@tanstack/router-plugin/vite";
import { devtools as tanstackDevtools } from "@tanstack/devtools-vite";
import { i18nextVitePlugin } from "@i18next-selector/vite-plugin";
import i18nextConfig, {
  DEFAULT_LANGUAGE,
  LOCALES_PATH,
  LOCAL_LOCALES_PATH,
} from "./i18next.config";

export default defineConfig({
  plugins: [
    i18nextVitePlugin({
      sourceDir: LOCAL_LOCALES_PATH,
    }),
    tanstackDevtools({
      removeDevtoolsOnBuild: true,
    }),
    tanstackRouter({
      target: "react",
      autoCodeSplitting: true,
    }),
    react(),
    tailwindcss(),
  ],
  define: {
    __LANGS__: JSON.stringify(i18nextConfig.locales),
    __LOCALES_PATH__: JSON.stringify(LOCALES_PATH),
    __DEFAULT_LANG__: JSON.stringify(DEFAULT_LANGUAGE),
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
      "@components": path.resolve(__dirname, "./src/components"),
    },
  },
});
