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 { i18nextSortPlugin } from "./plugins/i18nextSortPlugin";
import { i18nextTypesPlugin } from "./plugins/i18nextTypesPlugin";
import i18nextConfig, {
  DEFAULT_LANGUAGE,
  LOCALES_PATH,
  LOCAL_LOCALES_PATH,
} from "./i18next.config";

export default defineConfig({
  plugins: [
    i18nextSortPlugin({
      sourceDir: LOCAL_LOCALES_PATH,
    }),
    i18nextTypesPlugin({
      sourceDir: LOCAL_LOCALES_PATH,
      destination: "./src/i18n/resources.d.ts",
    }),
    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"),
    },
  },
});
