const nuxtPort = Number(process.env.NUXT_PORT || process.env.NITRO_PORT || process.env.PORT || 3000);
const internalApolloBaseUrl = process.env.NUXT_INTERNAL_SITE_URL || `http://localhost:${nuxtPort}`;
const authCookieName = process.env.AUTH_COOKIE_NAME || 'fregat_auth_token';

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  compatibilityDate: '2025-07-15',
  devtools: { enabled: true },
  modules: ['@nuxt/eslint', '@nuxtjs/tailwindcss', '@nuxtjs/apollo'],
  css: ['~/assets/css/main.css'],
  runtimeConfig: {
    backendGraphqlUrl:
      process.env.NUXT_BACKEND_GRAPHQL_URL ||
      process.env.BACKEND_GRAPHQL_URL ||
      'http://localhost:4000/graphql',
    authCookieName,
    dadataApiToken: process.env.DADATA_API_TOKEN ?? '',
    public: {
      authCookieName,
      telegramBotUrl: process.env.NUXT_PUBLIC_TELEGRAM_BOT_URL ?? '',
      maxBotUrl: process.env.NUXT_PUBLIC_MAX_BOT_URL ?? '',
      sentryDsn: process.env.NUXT_PUBLIC_SENTRY_DSN ?? '',
      sentryEnvironment: process.env.NUXT_PUBLIC_SENTRY_ENVIRONMENT ?? 'development',
      sentryRelease: process.env.NUXT_PUBLIC_SENTRY_RELEASE ?? 'dev',
    },
  },
  apollo: {
    proxyCookies: true,
    clients: {
      default: {
        httpEndpoint: `${internalApolloBaseUrl}/api/graphql`,
        browserHttpEndpoint: '/api/graphql',
        tokenStorage: 'cookie',
        tokenName: authCookieName,
        authType: 'Bearer',
        authHeader: 'Authorization',
        connectToDevTools: process.env.NODE_ENV !== 'production',
      },
    },
  },
  app: {
    head: {
      title: 'Fregat Client Cabinet',
      meta: [{ name: 'viewport', content: 'width=device-width, initial-scale=1' }],
      script: [
        { src: 'https://telegram.org/js/telegram-web-app.js?61' },
        { src: 'https://st.max.ru/js/max-web-app.js' },
      ],
    },
  },
});
