import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import laravel from 'laravel-vite-plugin'
import { fileURLToPath } from 'node:url'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { defineConfig } from 'vite'
import vuetify from 'vite-plugin-vuetify'
import { resolve } from 'path';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    laravel({
      input: ['resources/js/main.js'],
      refresh: true,
    }),
    vue({
      template: {
        transformAssetUrls: {
          base: null,
          includeAbsolute: false,
        },
      },
    }),
    vueJsx(),

    // Docs: https://github.com/vuetifyjs/vuetify-loader/tree/master/packages/vite-plugin
    vuetify({
      styles: {
        configFile: 'resources/styles/variables/_vuetify.scss',
        additionalData: `
      @import "./../node_modules/bootstrap/scss/bootstrap";
      @import "./../node_modules/@vueform/vueform/themes/bootstrap/scss/index.scss";
    `
      },
    }),
    Components({
      dirs: ['resources/js/@core/components'],
      dts: true,
    }),

    // Docs: https://github.com/antfu/unplugin-auto-import#unplugin-auto-import
    AutoImport({
      eslintrc: {
        enabled: true,
        filepath: './.eslintrc-auto-import.json',
      },
      imports: ['vue', 'vue-router', '@vueuse/core', '@vueuse/math', 'pinia'],
      vueTemplate: true,
    }),
  ],
  define: { 'process.env': {} },
  resolve: {
    alias: {
      '@core-scss': fileURLToPath(new URL('./resources/styles/@core',
        import.meta.url)),
      '@': fileURLToPath(new URL('./resources/js',
        import.meta.url)),
      '@core': fileURLToPath(new URL('./resources/js/@core',
        import.meta.url)),
      '@layouts': fileURLToPath(new URL('./resources/js/@layouts',
        import.meta.url)),
      '@images': fileURLToPath(new URL('./resources/images/',
        import.meta.url)),
      '@styles': fileURLToPath(new URL('./resources/styles/',
        import.meta.url)),
      '@vendor': fileURLToPath(new URL('./resources/themestyle/',
        import.meta.url)),
      '@configured-variables': fileURLToPath(new URL('./resources/styles/variables/_template.scss',
        import.meta.url)),
      '@customPlugin': fileURLToPath(new URL('./resources/js/plugins/custom',
        import.meta.url)),
      '@axios': fileURLToPath(new URL('./resources/js/plugins/axios',
        import.meta.url)),
      '@validators': fileURLToPath(new URL('./resources/js/@core/utils/validators',
        import.meta.url)),
      'apexcharts': fileURLToPath(new URL('node_modules/apexcharts-clevision',
        import.meta.url)),
    },
  },
  // css: {
  //   preprocessorOptions: {
  //     scss: {
  //       additionalData: `@import "./resources/js/@core/scss/_variables.scss";`
  //     }
  //   }
  // },
  build: {
    chunkSizeWarningLimit: 5000,
    manifest: true,  // Ensure this is present to generate manifest.json
    rollupOptions: {
      input: {
        main: resolve(__dirname, 'resources/js/main.js'),
      },
    },
    outDir: 'public/build',  // This is where your build files will be generated
  },
  optimizeDeps: {
    exclude: ['vuetify'],
    entries: [
      './resources/js/**/*.vue',
    ],
  },
})
