import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';

const backendTarget =
  process.env.INTERNAL_API_BASE_URL?.trim() ||
  process.env.PUBLIC_API_BASE_URL?.trim() ||
  'http://127.0.0.1:8000';

export default defineConfig({
  plugins: [sveltekit()],
  server: {
    host: '0.0.0.0',
    proxy: {
      '/api': {
        target: backendTarget,
        changeOrigin: true
      },
      '/health': {
        target: backendTarget,
        changeOrigin: true
      }
    }
  },
  preview: {
    host: '0.0.0.0',
    proxy: {
      '/api': {
        target: backendTarget,
        changeOrigin: true
      },
      '/health': {
        target: backendTarget,
        changeOrigin: true
      }
    }
  },
  test: {
    environment: 'node',
    include: ['src/**/*.test.ts'],
    clearMocks: true
  }
});
