import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import config from '../../shared/config.js'
import { toSass } from '../../shared/libs/sass/index.js'

export default defineConfig({
    plugins: [vue()],
    server: {
        port: 3000,
    },
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url)),
            '@shared': fileURLToPath(new URL('../../shared', import.meta.url)),
        },
    },
    base: '/drops/testing/',
    build: {
        outDir: '../../app/public/drops/testing',
        emptyOutDir: true,
    },
    css: {
        preprocessorOptions: {
            scss: {
                api: 'modern-compiler',
                additionalData:
                    '@use "@shared/styles/_functions.scss" as *; @use "@shared/styles/_font-style.scss" as *;',
                functions: {
                    'get($keys)': function (keys) {
                        keys = keys.toString().replace(/['"]+/g, '').split('.')

                        let result = config
                        for (let i = 0; i < keys.length; i++) {
                            result = result[keys[i]]
                        }

                        return toSass(result)
                    },
                    'getColors()': function () {
                        return toSass(config.colors)
                    },
                    'getThemes()': function () {
                        return toSass(config.themes)
                    },
                },
            },
        },
    },
})
