import { execSync } from 'node:child_process'

function getGitInfo() {
  try {
    const commit = execSync('git rev-parse --short HEAD').toString().trim()
    const tag = execSync('git describe --tags --abbrev=0').toString().trim()
    const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim()

    return { commit, tag, branch }
  } catch {
    // fallback (production / no .git)
    return {
      commit: process.env.NUXT_PUBLIC_GIT_COMMIT || 'unknown',
      tag: process.env.NUXT_PUBLIC_GIT_TAG || 'no-tag',
      branch: process.env.NUXT_PUBLIC_GIT_BRANCH || 'unknown'
    }
  }
}

const git = getGitInfo();

export default defineNuxtConfig({
  vite: {
    optimizeDeps: {
      include: [
        '@vue/devtools-core',
        '@vue/devtools-kit',
        'axios',
        'mitt',
        'motion'
      ]
    }
  },

  compatibilityDate: '2025-07-15',
  devtools: { enabled: true },
  css: [
    '~/assets/css/colors.scss',
    '~/assets/css/fonts.scss',
    '~/assets/css/main.scss',
    '~/assets/css/callouts.scss',
  ],

  runtimeConfig: {
    public: {
      apiBaseUrl: process.env.NUXT_PUBLIC_API_BASE_URL || 'http://localhost:5000/api',
      gitCommit: git.commit,
      gitTag: git.tag,
      gitBranch: git.branch,
      buildDate: new Date().toISOString(),
    }
  },

  i18n: {
    locales: [
      { code: 'en', iso: 'en-US', name: '🇺🇸 English', file: 'en.json' },
      { code: 'es', iso: 'es-ES', name: '🇪🇸 Spanish', file: 'es.json' },
      { code: 'ca', iso: 'ca-ES', name: '🇦🇩 Catalan', file: 'ca.json' }
    ],
    defaultLocale: 'en',
    vueI18n: './i18n.config.ts',
    langDir: 'locales/'
  },
  modules: ['@nuxtjs/i18n']
})
