/// <reference types="vitest" />
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '');
  return {
    plugins: [react(), tsconfigPaths()],
    server: {
      port: 3000,
      open: false,
      proxy: {
        '/api': { target: env.VITE_BASE_URL || 'http://localhost:5001', changeOrigin: true },
        '/socket.io': { target: env.VITE_BASE_URL || 'http://localhost:5001', changeOrigin: true, ws: true },
      },
    },
    build: { outDir: 'build', sourcemap: true },
    test: {
      globals: true,
      environment: 'jsdom',
      setupFiles: ['./src/setupTests.ts'],
      include: ['src/**/*.{test,spec}.{js,jsx,ts,tsx}'],
      coverage: {
        provider: 'v8',
        reporter: ['text', 'lcov', 'html'],
        include: ['src/**/*.{js,jsx,ts,tsx}'],
        exclude: [
          'src/index.tsx',
          'src/**/*.d.ts',
          'src/setupTests.ts',
          'src/setupEnv.ts',
          'src/test-polyfills.js',
          'src/mocks/**',
          'src/__mocks__/**',
        ],
        thresholds: {
          lines: 80,
          statements: 80,
        },
      },
    },
  };
});
