const dotenv = require('dotenv').config();

// Merge dotenv values with process.env, preferring process.env
const envVars = {
  ...(dotenv.parsed || {}),
  ...process.env
};

export default {
  ssr: false,
  env: envVars,
  /*
  ** Headers of the page
  */
  head: {
    titleTemplate: '%s - ' + process.env.npm_package_description,
    title: process.env.npm_package_name || '',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
    ],
    link: [
      { rel: 'stylesheet', href: 'https://fonts.googleapis.com/css?family=Source+Sans+Pro&display=swap' },
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  /*
  ** Customize the progress-bar color
  */
  // loading: { color: '#fff' },
  loading: '~/components/UI/Loading/Loading.vue',
  /*
  ** Global CSS
  */
  css: [
    '@/assets/main.css',
    '@/assets/icons.scss'
  ],
  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
    '~/plugins/axios',
    '~/plugins/constants',
    '~/plugins/notifier',
    '~/plugins/vue2-filters',
  ],
  /*
  ** Nuxt.js dev-modules
  */
  buildModules: [
    '@nuxtjs/vuetify',
    '@nuxtjs/dotenv',
    ['@nuxtjs/laravel-echo', {
      broadcaster: 'pusher',
      authModule: true,
      connectOnLogin: true,
      authEndpoint: `${process.env.WEBSOCKETS_HOST}/broadcasting/auth`,
      key: process.env.WEBSOCKETS_KEY,
      wsHost: process.env.WEBSOCKETS_HOST,
      wsPort: process.env.WEBSOCKETS_PORT || 6001,
      encrypted: true,
      disableStats: true,
      forceTLS: false,
      wssPort: process.env.WEBSOCKETS_PORT || 6001,
    }],
  ],
  /*
  ** Nuxt.js modules
  */
  modules: [
    '@nuxtjs/axios',
    '@nuxtjs/pwa',
    '@nuxtjs/dotenv',
    '@nuxtjs/auth',
    'nuxt-i18n',
    '@nuxtjs/svg',
  ],
  /*
  ** Axios module configuration
  ** See https://axios.nuxtjs.org/options
  */
  axios: {
    baseURL: `${process.env.API_HOST}/${process.env.API_HOST_API_SUFFIX}`,
  },
  // Token based flow
  auth: {
    redirect: {
      login: '/auth/login',
      logout: '/auth/login',
      // home: '/app',
      // callback: '/login'
    },
    strategies: {
      local: {
        endpoints: {
          login: { url: '/auth/login', method: 'post', propertyName: 'token' },
          logout: false,
          // logout: { url: '/auth/logout', method: 'post' },
          user: { url: '/auth/user', method: 'get', propertyName: false }
        }
      }
    }
  },

  i18n: {
    locales: [
      {
        code: 'en',
        file: 'en.json',
        iso: 'en-EN',
        name: 'English',
        flag: '260-united-kingdom.svg'
      },
      {
        code: 'nl',
        file: 'nl.json',
        iso: 'nl-NL',
        name: 'Dutch',
        flag: '237-netherlands.svg'
      }
    ],
    lazy: true,
    langDir: `lang/${process.env.CUSTOMER}/`,
    defaultLocale: 'nl',
  },

  /*
  ** vuetify module configuration
  ** https://github.com/nuxt-community/vuetify-module
  */
  vuetify: {
    customVariables: ['~/assets/variables.scss'],
    treeShake: true,
    theme: {
      options: {
        customProperties: true,
      },
      dark: false,
      themes: {
        dark: {
          primary: '#002937',
          secondary: '#003547',
          tertiary: '#5F838E',
          txt: '#FFFFFF',
          lines: '#0F566C',
          accent: '#E54E0F',
          secAccent: '#30B7CD',
          error: '#bb1d28',
          warning: '#f5aa00',
          info: '#30b7cd',
          success: '#1ada79',
          stroke: '#30B7CD',
          disabled: '#adacac',
          secDisabled: '#002937',
          terDisabled: '#002937',
          quaDisabled: '#003547',
          tab: '#5f838e',
          search: '#002937',
        },
        light: {
          primary: '#FFFFFF',
          secondary: '#EEF7F9',
          tertiary: '#5F838E',
          txt: '#003547',
          lines: '#D5EAF0',
          accent: '#E54E0F',
          secAccent: '#30B7CD',
          error: '#bb1d28',
          warning: '#f5aa00',
          info: '#30b7cd',
          success: '#1ada79',
          stroke: '#003547',
          disabled: '#adacac',
          secDisabled: '#adacac',
          terDisabled: '#adacac',
          quaDisabled: '#ffffff',
          tab: '#70848e',
          search: '#e0f0f4',
        }
      }
    }
  },
  /*
  ** Build configuration
  */
  build: {
    /*
    ** You can extend webpack config here
    */
    extractCSS: true,  // Extract CSS into separate files
    optimization: {
      splitChunks: {
        chunks: 'all',
        automaticNameDelimiter: '.',
        name: undefined,
        cacheGroups: {
          vendor: {
            test: /[\\/]node_modules[\\/]/,
            priority: -10
          }
        }
      }
    },
    terser: {
      terserOptions: {
        compress: {
          drop_console: true  // Remove console.log in production
        }
      }
    },
    extend(config, ctx) {
      // Disable source maps in production
      if (!ctx.isDev) {
        config.devtool = false
      }
    },
  }
}
