import tailwindcss from "@tailwindcss/vite";
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig(() => ({
  plugins: [
    tailwindcss(),
    tsconfigPaths({ projects: ["./tsconfig.json"] }),
    // SPA mode: npm run build writes static files to dist/client, served by Apache (public/.htaccess sends every page to _shell.html).
    tanstackStart({ server: { entry: "server" }, spa: { enabled: true } }),
    react(),
  ],
  resolve: {
    dedupe: ["react", "react-dom", "@tanstack/react-query", "@tanstack/react-router"],
  },
  server: {
    // This computer only: the test server holds real data and one-click demo accounts.
    host: "localhost",
    port: 8080,
    strictPort: true,
    // The browser sees one origin, so cookies and CSRF work as in production.
    proxy: {
      "/api": { target: process.env["API_PROXY"] ?? "http://127.0.0.1:4100", changeOrigin: false },
    },
  },
}));
