export default defineNuxtConfig({
  ssr: false,
  compatibilityDate: "2024-11-01",
  devtools: { enabled: true },
  
  // Add startup logging
  hooks: {
    'ready': () => {
      console.log('🚀 MonacoUSA Portal Nuxt is ready!')
      console.log('Environment:', process.env.NODE_ENV)
      console.log('Port:', process.env.NUXT_PORT || process.env.PORT || 3000)
    },
    'listen': (server, { host, port }) => {
      console.log(`🌐 Server listening on http://${host}:${port}`)
    }
  },
  modules: ["vuetify-nuxt-module", 
  // TEMPORARILY DISABLED FOR TESTING - PWA causing reload loops on mobile Safari
  // [
  //   "@vite-pwa/nuxt",
  //   {
  //     registerType: 'autoUpdate',
  //     workbox: {
  //       globPatterns: ['**/*.{js,css,html,png,svg,ico}'],
  //       navigateFallback: '/',
  //       navigateFallbackDenylist: [/^\/api\//]
  //     },
  //     client: {
  //       installPrompt: true,
  //       periodicSyncForUpdates: 20
  //     },
  //     devOptions: {
  //       enabled: true,
  //       suppressWarnings: true,
  //       navigateFallbackAllowlist: [/^\/$/],
  //       type: 'module'
  //     },
  //     manifest: {
  //       name: 'MonacoUSA Portal',
  //       short_name: 'MonacoUSA',
  //       description: 'MonacoUSA Portal - Unified dashboard for tools and services',
  //       theme_color: '#a31515',
  //       background_color: '#ffffff',
  //       display: 'standalone',
  //       orientation: 'portrait',
  //       scope: '/',
  //       start_url: '/',
  //       icons: [
  //         {
  //           src: 'icon-192x192.png',
  //           sizes: '192x192',
  //           type: 'image/png'
  //         },
  //         {
  //           src: 'icon-512x512.png',
  //           sizes: '512x512',
  //           type: 'image/png'
  //         },
  //         {
  //           src: 'icon-512x512.png',
  //           sizes: '512x512',
  //           type: 'image/png',
  //           purpose: 'any maskable'
  //         }
  //       ]
  //     }
  //   }
  // ], 
  "@nuxtjs/device"],
  css: [
    'vuetify-pro-tiptap/style.css'
  ],
  app: {
    head: {
      titleTemplate: "%s • MonacoUSA Portal",
      title: "MonacoUSA Portal",
      meta: [
        { property: "og:title", content: "MonacoUSA Portal" },
        { property: "og:image", content: "/MONACOUSA-Flags_376x376.png" },
        { name: "twitter:card", content: "summary_large_image" },
        { name: "viewport", content: "width=device-width, initial-scale=1" },
        { name: "apple-mobile-web-app-capable", content: "yes" },
        { name: "apple-mobile-web-app-status-bar-style", content: "default" },
        { name: "apple-mobile-web-app-title", content: "MonacoUSA Portal" },
        { name: "theme-color", content: "#a31515" },
      ],
      link: [
        { rel: "icon", type: "image/png", sizes: "32x32", href: "/favicon-32x32.png" },
        { rel: "icon", type: "image/png", sizes: "192x192", href: "/icon-192x192.png" },
        { rel: "apple-touch-icon", sizes: "180x180", href: "/apple-touch-icon.png" },
        { rel: "shortcut icon", href: "/favicon-32x32.png" },
      ],
      htmlAttrs: {
        lang: "en",
      },
    },
  },
  nitro: {
    experimental: {
      wasm: true
    }
  },
  runtimeConfig: {
    // Server-side configuration
    keycloak: {
      issuer: process.env.NUXT_KEYCLOAK_ISSUER || "",
      clientId: process.env.NUXT_KEYCLOAK_CLIENT_ID || "monacousa-portal",
      clientSecret: process.env.NUXT_KEYCLOAK_CLIENT_SECRET || "",
      callbackUrl: process.env.NUXT_KEYCLOAK_CALLBACK_URL || "https://portal.monacousa.org/auth/callback",
    },
    keycloakAdmin: {
      issuer: process.env.NUXT_KEYCLOAK_ISSUER || "",
      clientId: process.env.NUXT_KEYCLOAK_ADMIN_CLIENT_ID || "admin-cli",
      clientSecret: process.env.NUXT_KEYCLOAK_ADMIN_CLIENT_SECRET || "",
    },
    nocodb: {
      url: process.env.NUXT_NOCODB_URL || "",
      token: process.env.NUXT_NOCODB_TOKEN || "",
      baseId: process.env.NUXT_NOCODB_BASE_ID || "",
      eventsBaseId: process.env.NUXT_NOCODB_EVENTS_BASE_ID || "",
      eventsTableId: process.env.NUXT_NOCODB_EVENTS_TABLE_ID || "",
      rsvpTableId: process.env.NUXT_NOCODB_RSVP_TABLE_ID || "",
    },
    minio: {
      endPoint: process.env.NUXT_MINIO_ENDPOINT || "s3.monacousa.org",
      port: parseInt(process.env.NUXT_MINIO_PORT || "443"),
      useSSL: process.env.NUXT_MINIO_USE_SSL !== "false",
      accessKey: process.env.NUXT_MINIO_ACCESS_KEY || "",
      secretKey: process.env.NUXT_MINIO_SECRET_KEY || "",
      bucketName: process.env.NUXT_MINIO_BUCKET_NAME || "monacousa-portal",
    },
    sessionSecret: process.env.NUXT_SESSION_SECRET || "",
    encryptionKey: process.env.NUXT_ENCRYPTION_KEY || "",
    jwtSecret: process.env.NUXT_JWT_SECRET || process.env.NUXT_SESSION_SECRET || "",
    public: {
      // Client-side configuration
      appName: "MonacoUSA Portal",
      domain: process.env.NUXT_PUBLIC_DOMAIN || "https://portal.monacousa.org",
      keycloakIssuer: process.env.NUXT_KEYCLOAK_ISSUER || "https://auth.monacousa.org/realms/monacousa",
    },
  },
  vuetify: {
    vuetifyOptions: {
      theme: {
        defaultTheme: "monacousa",
        themes: {
          monacousa: {
            colors: {
              primary: "#a31515",
              secondary: "#ffffff",
              accent: "#f5f5f5",
              error: "#ff5252",
              warning: "#ff9800",
              info: "#2196f3",
              success: "#4caf50",
            },
          },
        },
      },
    },
  },
});
