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

export default defineConfig(({ mode }) => {
  // Use `vite build --mode maui` to emit artifacts into the MAUI app's `wwwroot` for embedded hosting.
  const outDir = mode === 'maui'
    ? resolve(__dirname, '../Hua.Todo.Maui/wwwroot')
    : resolve(__dirname, 'dist')

  return {
    plugins: [vue()],
    build: {
      outDir,
      emptyOutDir: true,
    },
    define: {
      'window.__API_BASE_URL__': JSON.stringify('/api')
    },
    server: {
      port: 5174,
      proxy: {
          '/api': {
              target: 'http://localhost:5173',
          changeOrigin: true,
          secure: false,
        },
      },
    },
  }
})
