import axios from 'axios';

const appConfig = {
  name: 'Piráti pracují',
  description: 'Přehled toho nejdůležitějšího, na čem Piráti pracují nejen v Poslanecké sněmovně.',
  //apiUrl: process.env.NODE_ENV === 'development' ? 'http://127.0.0.1:8000/api/' : 'https://admin.piratipracuji.cz/api/',
  //apiUrl: 'https://admin.piratipracuji.cz/api/',
  apiUrl: process.env.API_URL || 'https://redmineapi.mfnet.cz/',
  //apiUrl: 'https://redmineapi.mfnet.cz/',
  productionUrl: process.env.BASE_URL || 'https://www.piratipracuji.cz',
  //productionUrl: 'https://www.piratipracuji.cz',
  //productionUrl: 'https://piratiliberec.mfnet.cz',
  //googleAnalyticsId: 'UA-72526071-32',
  sentryDns: 'https://69eede94c351441295a3282449be6335@sentry.io/1365349',
  googleConsoleVerification: 'gJcie5kGIjJn_o5J6OHmQu9ZnrSFfssyjqGncMM4SOs',
};

const routes = async () => {
  const posts = await axios.get(`${appConfig.apiUrl}posts`);
  const postsRoutes = posts.data.map((post) => '/blog/' + post.slug);

  const pages = await axios.get(`${appConfig.apiUrl}pages`);
  const pagesRoutes = pages.data.map((page) => '/' + page.slug);

  return [...postsRoutes, ...pagesRoutes];
};

export default {
  /*
  ** Headers of the page
  */
    
  head: {
    titleTemplate: `%s | ${appConfig.name}`,
    htmlAttrs: {
      lang: 'cs',
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: appConfig.description },
      { hid: 'author', name: 'author', content: appConfig.name },

      { hid: 'og:title', property: 'og:title', content: appConfig.name },
      { hid: 'og:description', property: 'og:description', content: 'Přehled toho nejdůležitějšího nejen z Poslanecké sněmovny.' },
      { hid: 'og:site_name', property: 'og:site_name', content: appConfig.name },
      { hid: 'og:image', property: 'og:image', content: `${appConfig.productionUrl}/images/og-cover.jpg?v=3` },

      { name: 'google-site-verification', content: appConfig.googleConsoleVerification },
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },      
      { rel: 'script', href: 'https://unpkg.com/vue-masonry-css' },
    ]
  },

  /*
  ** Customize the progress bar color
  */
  loading: { color: '#000000' },

  /*
   ** Global CSS
   */
  css: [
    'modern-normalize/modern-normalize.css',
    '@/assets/scss/global.scss',
  ],

  /*
  ** Route config for pre-rendering
  */
  generate: {
    routes: routes,
  },

  /*
  ** Modules
  */
  modules: [
    '@nuxtjs/style-resources',
    '@nuxtjs/axios',
    '@nuxtjs/sitemap',
    'nuxt-rfg-icon',
    '@nuxtjs/pwa',
    '@nuxtjs/sentry',
    //'@nuxtjs/google-analytics',
    //'nuxt-facebook-pixel-module',
  ],

  styleResources: {
    scss: [
      './assets/scss/_variables.scss',
      './assets/scss/_mixins.scss',
    ]
  },

  axios: {
    baseURL: appConfig.apiUrl,
  },

  sitemap: {
    path: '/sitemap.xml',
    hostname: appConfig.productionUrl,
    cacheTime: 1000 * 60 * 15,
    gzip: true,
    generate: true,
    routes: routes,
    exclude: [
      '/404.html',
    ],
  },

  manifest: {
    name: appConfig.name,
    short_name: appConfig.name,
    theme_color: "#000",
    description: appConfig.description,
  },

  sentry: {
    dsn: appConfig.sentryDns,
  },

  //'google-analytics': {
  //  id: appConfig.googleAnalyticsId,
  //},

  //facebook: {
  //  track: 'PageView',
  //  pixelId: '2240341229621792',
  //  disabled: false,
  //},


  router: {
    linkActiveClass: 'is-active',
  },

  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
    '@/plugins/filters',
    '@/plugins/global-components',
    //'@/plugins/vue-social-sharing',
    { src: '@/plugins/vue-social-sharing', mode: 'client' },
  ],

  /*
  ** Build configuration
  */
  build: {
    /*
    ** Run ESLint on save
    */
    extend(config, { isDev, isClient }) {
      if (isDev && isClient) {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/
        })
      }
    }
  }
}