// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  ssr: false,
  compatibilityDate: '2025-07-15',
  devtools: { enabled: true },
  css: ['~/assets/css/main.css'],
  modules: ['@nuxt/image', '@nuxt/ui', '@nuxt/test-utils', '@vite-pwa/nuxt', '@pinia/nuxt'],

  // Performance optimizations
  experimental: {
    payloadExtraction: false,
    viewTransition: true
  },

  // Optimize build
  vite: {
    build: {
      cssCodeSplit: true,
      rollupOptions: {
        output: {
          manualChunks: {
            'vendor-ui': ['@nuxt/ui'],
            'vendor-pinia': ['pinia', '@pinia/nuxt']
          }
        }
      }
    }
  },
  app: {
    head: {
      link: [
        { rel: 'icon', type: 'image/png', href: '/icons/icon-192.png' },
        { rel: 'apple-touch-icon', sizes: '192x192', href: '/icons/icon-192.png' },
        { rel: 'manifest', href: '/manifest.webmanifest' }
      ],
      meta: [
        { name: 'theme-color', content: '#1b1209' },
        { name: 'apple-mobile-web-app-capable', content: 'yes' },
        { name: 'mobile-web-app-capable', content: 'yes' },
        { name: 'apple-mobile-web-app-status-bar-style', content: 'black-translucent' }
      ]
    }
  },
  pwa: {
    registerType: 'autoUpdate',
    strategies: 'generateSW',
    manifestFilename: 'manifest.webmanifest',
    manifest: {
      name: 'Analítica Núcleo Data Studio',
      short_name: 'Analítica',
      description: 'Explora y valida tus tablas Supabase desde un único panel en modo lectura.',
      start_url: '/',
      scope: '/',
      display: 'standalone',
      background_color: '#1b1209',
      theme_color: '#c08040',
      icons: [
        { src: '/icons/icon-192.png', sizes: '192x192', type: 'image/png' },
        { src: '/icons/icon-512.png', sizes: '512x512', type: 'image/png' },
        { src: '/icons/icon-192-maskable.png', sizes: '192x192', type: 'image/png', purpose: 'maskable' },
        { src: '/icons/icon-512-maskable.png', sizes: '512x512', type: 'image/png', purpose: 'maskable' },
        { src: '/icons/icon-192-black.png', sizes: '192x192', type: 'image/png' },
        { src: '/icons/icon-512-black.png', sizes: '512x512', type: 'image/png' }
      ],
      screenshots: [
        {
          src: '/screenshots/screenshot-desktop.png',
          sizes: '2048x1041',
          type: 'image/png',
          form_factor: 'wide',
          label: 'Dashboard en escritorio'
        },
        {
          src: '/screenshots/screenshot-mobile.png',
          sizes: '774x1459',
          type: 'image/png',
          form_factor: 'narrow',
          label: 'Vista móvil'
        }
      ]
    },
    workbox: {
      globPatterns: ['**/*.{js,css,html,png,svg,webp,ico,json,woff2}'],
      navigateFallback: '/',
      maximumFileSizeToCacheInBytes: 4 * 1024 * 1024,
      runtimeCaching: [
        {
          urlPattern: /^https:\/\/szesytydotpnuiuwybwb\.supabase\.co\//,
          handler: 'NetworkFirst',
          method: 'GET',
          options: {
            cacheName: 'supabase-data',
            networkTimeoutSeconds: 10,
            expiration: {
              maxEntries: 60,
              maxAgeSeconds: 3600
            },
            cacheableResponse: {
              statuses: [0, 200]
            }
          }
        }
      ]
    },
    client: {
      installPrompt: true,
      periodicSyncForUpdates: 3600
    },
    devOptions: {
      enabled: process.env.NODE_ENV === 'development',
      type: 'module'
    },
    includeAssets: [
      'favicon.ico',
      'icons/icon-192.png',
      'icons/icon-512.png',
      'icons/icon-192-maskable.png',
      'icons/icon-512-maskable.png',
      'icons/icon-192-black.png',
      'icons/icon-512-black.png',
      'screenshots/screenshot-desktop.png',
      'screenshots/screenshot-mobile.png'
    ]
  },
  runtimeConfig: {
    supabase: {
      url: process.env.SUPABASE_URL || process.env.NEXT_PUBLIC_SUPABASE_URL,
      serviceRoleKey:
        process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY
    }
  }
})
