import { defineConfig } from 'astro/config';
import tailwind from '@astrojs/tailwind';
import node from '@astrojs/node';

export default defineConfig({
  output: 'server',
  adapter: node({
    mode: 'standalone'
  }),
  server: {
    host: '0.0.0.0',
    port: 10000
  },
  integrations: [tailwind()],
  site: 'https://workroot.in',

  // Image optimization configuration
  image: {
    // Enable sharp image service for WebP conversion
    service: {
      entrypoint: 'astro/assets/services/sharp',
      config: {
        limitInputPixels: false,
      },
    },
    // Default formats for image optimization
    domains: ['images.unsplash.com'],
    remotePatterns: [
      { protocol: 'https', hostname: 'images.unsplash.com' },
    ],
  },

  // Build optimizations
  build: {
    // Inline small assets to reduce HTTP requests
    inlineStylesheets: 'auto',
    // Split chunks for better caching
    assets: '_assets',
  },

  // Compression and performance
  compressHTML: true,

  // Prefetch configuration for faster navigation
  // hover: prefetch when user hovers over a link (lowest latency for clicks)
  // viewport: prefetch when link enters viewport (good for mobile)
  prefetch: {
    prefetchAll: false,
    defaultStrategy: 'hover',
  },

  // Vite optimizations
  vite: {
    build: {
      // Enable CSS code splitting
      cssCodeSplit: true,
      // Rollup optimizations
      rollupOptions: {
        output: {
          // Manual chunk splitting for better caching
          manualChunks: {
            'vendor': ['astro:content'],
          },
        },
      },
    },
    // Optimize dependencies
    optimizeDeps: {
      exclude: ['@astrojs/image'],
    },
  },
});
