import { resolve } from 'path'
import { defineConfig } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'

import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const isProduction = mode === 'production';

  const isSlashEnv = mode === 'slash';

  const outDir = isSlashEnv ? '../build/adm' : './dist';

  return {
    base: './',
    server: {
      host: '0.0.0.0',
      port: 8082,
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src'),
      },
    },
    plugins: [
      vue(),
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ],
    build: {
      rollupOptions: {
        input: {
          dashboard: resolve(__dirname, 'dashboard.html'),
          login: resolve(__dirname, 'login.html'),
          payment: resolve(__dirname, 'payment.html'),
          shipping: resolve(__dirname, 'shipping.html'),
          order: resolve(__dirname, 'order.html'),
          bonus: resolve(__dirname, 'bonus.html'),
          affiliate: resolve(__dirname, 'affiliate.html'),
        },
      },
      emptyOutDir: true,
      outDir
    },
  }
})
