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

export default defineConfig({
  plugins: [
    react(),
    tailwindcss(),
  ],
  server: {
    proxy: {
      // In dev: forward /api/* to the local PowerOn backend.
      // Set AI_BACKEND_URL in your shell or .env.local (no VITE_ prefix — never bundled).
      // Example: AI_BACKEND_URL=http://localhost:3001
      //
      // In production: the same-origin backend serves /api/* directly.
      // No proxy needed; the relative URL /api/ai/chat/completions resolves correctly.
      '/api': {
        target: process.env['AI_BACKEND_URL'] ?? 'http://localhost:3001',
        changeOrigin: true,
      },
    },
  },
})
