// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  compatibilityDate: '2025-07-15',
  devtools: { enabled: true },

  modules: [
    '@nuxt/ui',
    'nuxt-auth-utils',
    '@vite-pwa/nuxt'
  ],

  // Runtime config para variables de entorno
  runtimeConfig: {
    // Variables privadas (solo servidor)
    oauth: {
      authentik: {
        clientId: process.env.NUXT_OAUTH_AUTHENTIK_CLIENT_ID || '',
        clientSecret: process.env.NUXT_OAUTH_AUTHENTIK_CLIENT_SECRET || '',
        serverUrl: process.env.NUXT_OAUTH_AUTHENTIK_SERVER_URL || '',
        serverUrlInternal: process.env.NUXT_OAUTH_AUTHENTIK_SERVER_URL_INTERNAL || '',
        redirectURL: process.env.NUXT_OAUTH_AUTHENTIK_REDIRECT_URL || ''
      }
    },
    // Variables públicas (cliente y servidor)
    public: {
      appUrl: process.env.NUXT_PUBLIC_APP_URL || ''
    }
  },

  // Configuración PWA
  pwa: {
    registerType: 'autoUpdate',
    manifest: {
      name: 'Seguidor de Lotes',
      short_name: 'Lotes',
      description: 'Aplicación para seguimiento y gestión de lotes',
      start_url: '/',
      display: 'standalone',
      background_color: '#1f2730',
      theme_color: '#1f2730',
      icons: [
        {
          src: 'icon-16x16.png',
          sizes: '16x16',
          type: 'image/png'
        },
        {
          src: 'icon-32x32.png',
          sizes: '32x32',
          type: 'image/png'
        },
        {
          src: 'icon-48x48.png',
          sizes: '48x48',
          type: 'image/png'
        },
        {
          src: 'icon-64x64.png',
          sizes: '64x64',
          type: 'image/png'
        },
        {
          src: 'icon-96x96.png',
          sizes: '96x96',
          type: 'image/png'
        },
        {
          src: 'icon-128x128.png',
          sizes: '128x128',
          type: 'image/png'
        },
        {
          src: 'icon-144x144.png',
          sizes: '144x144',
          type: 'image/png'
        },
        {
          src: 'icon-152x152.png',
          sizes: '152x152',
          type: 'image/png'
        },
        {
          src: 'icon-167x167.png',
          sizes: '167x167',
          type: 'image/png'
        },
        {
          src: 'icon-180x180.png',
          sizes: '180x180',
          type: 'image/png'
        },
        {
          src: 'icon-192x192.png',
          sizes: '192x192',
          type: 'image/png'
        },
        {
          src: 'icon-256x256.png',
          sizes: '256x256',
          type: 'image/png'
        },
        {
          src: 'icon-384x384.png',
          sizes: '384x384',
          type: 'image/png'
        },
        {
          src: 'icon-512x512.png',
          sizes: '512x512',
          type: 'image/png'
        },
        {
          src: 'icon-1024x1024.png',
          sizes: '1024x1024',
          type: 'image/png'
        },
        {
          src: 'icon-512x512-maskable.png',
          sizes: '512x512',
          type: 'image/png',
          purpose: 'maskable'
        },
        {
          src: 'icon-1024x1024-maskable.png',
          sizes: '1024x1024',
          type: 'image/png',
          purpose: 'maskable'
        }
      ]
    },
    workbox: {
      // Estrategia de caché para navegación offline
      navigateFallback: '/',
      navigateFallbackDenylist: [/^\/api\//],
      runtimeCaching: [
        {
          urlPattern: /^\/api\/.*/,
          handler: 'NetworkFirst',
          options: {
            cacheName: 'api-cache',
            expiration: {
              maxEntries: 50,
              maxAgeSeconds: 60 * 60 * 24 // 24 horas
            },
            networkTimeoutSeconds: 10
          }
        }
      ]
    },
    devOptions: {
      enabled: true,
      type: 'module'
    }
  }
})