import { fileURLToPath, URL } from 'node:url'

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

// https://vitejs.dev/config/
export default defineConfig(() => {
  return {
    plugins: [react(), mkcert()],
    server: {
      open: true,
      host: 'dev.ezijing.com',
      proxy: {
        // '/api/tiangong': {
        //   target: 'https://api.singularity-ai.com',
        //   changeOrigin: true,
        //   rewrite: (path) => path.replace(/^\/api\/tiangong/, ''),
        // },
        // '/api/deepseek': {
        //   target: 'https://api.deepseek.com',
        //   changeOrigin: true,
        //   rewrite: (path) => path.replace(/^\/api\/deepseek/, ''),
        // },
        // '/api/qwen': {
        //   target: 'https://dashscope.aliyuncs.com',
        //   changeOrigin: true,
        //   rewrite: (path) => path.replace(/^\/api\/qwen/, ''),
        // },
        // '/api/qianfan': {
        //   target: 'https://aip.baidubce.com',
        //   changeOrigin: true,
        //   rewrite: (path) => path.replace(/^\/api\/qianfan/, ''),
        // },
        // '/api/wenku': {
        //   target: 'https://wenchain.baidu.com',
        //   changeOrigin: true,
        //   rewrite: (path) => path.replace(/^\/api\/wenku/, '/'),
        // },
        // '/api/qianfan': {
        //   target: 'https://qianfan.baidubce.com',
        //   changeOrigin: true,
        //   rewrite: (path) => path.replace(/^\/api\/qianfan/, ''),
        // },
        '/api/volcano': {
          target: 'https://ark.cn-beijing.volces.com',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api\/volcano/, ''),
        },
        '/api/xiling': {
          target: 'https://open.xiling.baidu.com',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api\/xiling/, ''),
        },
        '/api/ai_file': {
          target: 'https://ark-content-generation-cn-beijing.tos-cn-beijing.volces.com',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api\/ai_file/, ''),
        },
        '/api': {
          target: 'https://zijingebook.ezijing.com',
          // target: 'http://localhost:7419',
          changeOrigin: true,
          secure: false,
        },
      },
    },
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },
    css: {
      preprocessorOptions: {
        less: {
          javascriptEnabled: true,
        },
      },
    },
  }
})
