import fs from 'fs';
import vuetify from 'vite-plugin-vuetify'
import {NuxtI18nOptions} from "@nuxtjs/i18n";

/**
 * Nuxt configuration
 *
 * @see https://nuxt.com/docs/api/configuration/nuxt-config
  */
export default defineNuxtConfig({
    ssr: true,
    title: 'Opentalent',
    runtimeConfig: {
        // Private config that is only available on the server
        env: '',
        baseUrl: '',
        baseUrlLegacy: '',
        baseUrlAdminLegacy: '',
        baseUrlTypo3: '',
        baseUrlMercure: '',
        supportUrl: '',
        // Config within public will be also exposed to the client
        public: {
            env: '',
            baseUrl: '',
            baseUrlLegacy: '',
            baseUrlAdminLegacy: '',
            baseUrlTypo3: '',
            baseUrlMercure: '',
            supportUrl: '',
            school_product: 'school',
            school_premium_product: 'school-premium',
            artist_product: 'artist',
            artist_premium_product: 'artist-premium',
            manager_product: 'manager',
            cmf_network: 'CMF',
            ffec_network: 'FFEC',
            OPENTALENT_MANAGER_ID: 93931,
            CMF_ID: 12097
        }
    },
    hooks: {
      'builder:watch': console.log
    },
    app: {
        head: {
            title: 'Opentalent',
            meta: [
                { charset: 'utf-8' },
                { name: 'viewport', content: 'width=device-width, initial-scale=1' },
                { name: 'msapplication-TileColor', content: '#324250' },
                { name: 'msapplication-TileImage', content: '/favicon/mstile-144x144.png' }
            ],
            link: [
                { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
                { rel: 'apple-touch-icon-precomposed', sizes: '57x57', href: '/favicon/apple-touch-icon-57x57.png' },
                { rel: 'apple-touch-icon-precomposed', sizes: '114x114', href: '/favicon/apple-touch-icon-114x114.png' },
                { rel: 'apple-touch-icon-precomposed', sizes: '72x72', href: '/favicon/apple-touch-icon-72x72.png' },
                { rel: 'apple-touch-icon-precomposed', sizes: '144x144', href: '/favicon/apple-touch-icon-144x144.png' },
                { rel: 'apple-touch-icon-precomposed', sizes: '120x120', href: '/favicon/apple-touch-icon-120x120.png' },
                { rel: 'apple-touch-icon-precomposed', sizes: '152x152', href: '/favicon/apple-touch-icon-152x152.png' },
                { rel: 'icon', sizes: '32x32', type: 'image/x-icon', href: '/favicon/favicon-32x32.png' },
                { rel: 'icon', sizes: '16x16', type: 'image/x-icon', href: '/favicon/favicon-16x16.png' },
            ]
        }
    },
    css: [
        '@/assets/css/global.scss',
        '@/assets/css/import.scss'
    ],
    typescript: {
        strict: true
    },
    modules: [
        async (options, nuxt) => {
            nuxt.hooks.hook('vite:extendConfig', config => (config.plugins ?? []).push(
                vuetify()
                //Remplacer par cela quand l'issue https://github.com/vuetifyjs/vuetify-loader/issues/273 sera règlée..
                // voir aussi : https://github.com/nuxt/nuxt/issues/15412 et https://github.com/vuetifyjs/vuetify-loader/issues/290
                // vuetify({
                //     styles: { configFile: './assets/css/settings.scss' }
                // })
            ) as any );
        },
        [
            '@pinia/nuxt',
            {
                autoImports: [
                    // automatically imports `usePinia()`
                    'defineStore',
                    // automatically imports `usePinia()` as `usePiniaStore()`
                    ['defineStore', 'definePiniaStore'],
                ],
            }
        ],
        '@pinia-orm/nuxt',
        'nuxt-lodash',
        '@nuxtjs/i18n',
        '@nuxt/image-edge'
    ],
    vite: {
        esbuild: {
            drop: process.env.DEBUG ? [] : ['console', 'debugger'],
        },
        ssr: {
            noExternal: ['vuetify', 'nuxt-lodash']
        },
        server : {
            https: {
                key: fs.readFileSync('local.app-v3.opentalent.fr.key'),
                cert: fs.readFileSync('local.app-v3.opentalent.fr.crt'),
            },
            //@ts-ignore
            port: 443,
            hmr: {
                protocol: 'wss',
                port: 24678
            }
        },
    },
    i18n: {
        langDir: 'lang',
        lazy: true,
        locales: [
            {
                code: 'en',
                iso: 'en-US',
                file: 'en.json',
                name: 'English'
            },
            {
                code: 'fr',
                iso: 'fr-FR',
                file: 'fr.json',
                name: 'Français'
            }
        ],
        defaultLocale: 'fr',
        fallbackLocale: 'en',
        detectBrowserLanguage: false,
        vueI18n: {
            legacy: false,
            datetimeFormats: {
                'fr-FR': {
                    short: {
                        year: 'numeric', month: 'numeric', day: 'numeric'
                    },
                    long: {
                        year: 'numeric', month: 'numeric', day: 'numeric',
                        hour: 'numeric', minute: 'numeric'
                    }
                },
                'en': {
                    short: {
                        year: 'numeric', month: 'numeric', day: 'numeric'
                    },
                    long: {
                        year: 'numeric', month: 'numeric', day: 'numeric',
                        hour: 'numeric', minute: 'numeric'
                    }
                }
            }
        },
    } as NuxtI18nOptions,
    build: {
        transpile: ['vuetify'],
    },
})
