import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
  build: {
    rollupOptions: {
      output: {
        manualChunks: {
          'react-vendor': ['react', 'react-dom', 'react-router-dom', '@tanstack/react-query'],
          'chart-vendor': ['recharts'],
          'icons-vendor': ['lucide-react'],
          'utils-vendor': ['date-fns', 'clsx', 'tailwind-merge'],
        },
      },
    },
    chunkSizeWarningLimit: 1000,
    sourcemap: false,
  },
  optimizeDeps: {
    esbuildOptions: {
      loader: {
        '.map': 'json',
      },
    },
  },
  server: {
    host: '0.0.0.0',
    port: 5173,
    allowedHosts: ['md.lic.ad', 'localhost', '127.0.0.1'],
    proxy: {
      '/api': {
        target: 'http://localhost:8000',
        changeOrigin: true,
        timeout: 120000,  // 120 seconds timeout
        proxyTimeout: 120000,  // 120 seconds proxy timeout
      },
      '/ws': {
        target: 'ws://localhost:8000',
        ws: true,
        timeout: 0,  // No timeout for WebSocket
      },
    },
  },
})
