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

  modules: [
    '@nuxt/ui',
    '@nuxt/test-utils',
    '@nuxt/image',
    '@nuxt/eslint',
    '@nuxt/content',
    '@vite-pwa/nuxt'
  ],

  css: ['~/assets/css/main.css'],

  runtimeConfig: {
    postgresUrl: process.env.NUXT_POSTGRES_URL || '',
    public: {
      authentikUrl: process.env.NUXT_PUBLIC_AUTHENTIK_URL || 'https://authentik.nucleoriofrio.com'
    }
  },

  pwa: {
    registerType: 'autoUpdate',
    includeAssets: ['favicon.ico', 'apple-touch-icon.png', 'icon.svg', 'offline.html'],
    manifest: {
      name: 'Seguidor de Lotes - Trazabilidad de Café',
      short_name: 'Lotes Café',
      description: 'Sistema de trazabilidad y gestión de lotes de café - Beneficio Río Frío',
      theme_color: '#16a34a',
      background_color: '#ffffff',
      display: 'standalone',
      display_override: ['window-controls-overlay'],
      orientation: 'portrait',
      scope: '/',
      start_url: '/',
      icons: [
        {
          src: '/icon-16x16.png',
          sizes: '16x16',
          type: 'image/png',
          purpose: 'any'
        },
        {
          src: '/icon-32x32.png',
          sizes: '32x32',
          type: 'image/png',
          purpose: 'any'
        },
        {
          src: '/icon-48x48.png',
          sizes: '48x48',
          type: 'image/png',
          purpose: 'any'
        },
        {
          src: '/icon-64x64.png',
          sizes: '64x64',
          type: 'image/png',
          purpose: 'any'
        },
        {
          src: '/icon-72x72.png',
          sizes: '72x72',
          type: 'image/png',
          purpose: 'any'
        },
        {
          src: '/icon-96x96.png',
          sizes: '96x96',
          type: 'image/png',
          purpose: 'any'
        },
        {
          src: '/icon-128x128.png',
          sizes: '128x128',
          type: 'image/png',
          purpose: 'any'
        },
        {
          src: '/icon-144x144.png',
          sizes: '144x144',
          type: 'image/png',
          purpose: 'any'
        },
        {
          src: '/icon-152x152.png',
          sizes: '152x152',
          type: 'image/png',
          purpose: 'any'
        },
        {
          src: '/icon-167x167.png',
          sizes: '167x167',
          type: 'image/png',
          purpose: 'any'
        },
        {
          src: '/icon-180x180.png',
          sizes: '180x180',
          type: 'image/png',
          purpose: 'any'
        },
        {
          src: '/icon-192x192.png',
          sizes: '192x192',
          type: 'image/png',
          purpose: 'any'
        },
        {
          src: '/icon-256x256.png',
          sizes: '256x256',
          type: 'image/png',
          purpose: 'any'
        },
        {
          src: '/icon-384x384.png',
          sizes: '384x384',
          type: 'image/png',
          purpose: 'any'
        },
        {
          src: '/icon-512x512.png',
          sizes: '512x512',
          type: 'image/png',
          purpose: 'any'
        }
      ],
      screenshots: [
        {
          src: '/screenshots/desktop-1.png',
          sizes: '1920x1080',
          type: 'image/png',
          form_factor: 'wide',
          label: 'Pantalla principal en escritorio'
        },
        {
          src: '/screenshots/mobile-1.png',
          sizes: '614x853',
          type: 'image/png',
          form_factor: 'narrow',
          label: 'Pantalla principal en móvil'
        }
      ]
    },
    workbox: {
      navigateFallback: '/offline.html',
      navigateFallbackDenylist: [/^\/api\//, /^\/authentik\//],
      globPatterns: ['**/*.{js,css,html,png,svg,ico,json}'],
      cleanupOutdatedCaches: true,
      runtimeCaching: [
        {
          urlPattern: /^https:\/\/authentik\.nucleoriofrio\.com\/.*/i,
          handler: 'NetworkOnly'
        },
        {
          urlPattern: ({ url, request }) => {
            return request.destination === 'document' ||
                   request.mode === 'navigate' ||
                   url.pathname === '/'
          },
          handler: 'NetworkFirst',
          options: {
            cacheName: 'pages-cache',
            networkTimeoutSeconds: 3,
            expiration: {
              maxEntries: 50,
              maxAgeSeconds: 60 * 60 * 24 * 7 // 7 days
            },
            cacheableResponse: {
              statuses: [0, 200]
            }
          }
        }
      ]
    },
    devOptions: {
      enabled: true,
      type: 'module'
    }
  }
})
