import { MetadataRoute } from 'next';

export default function robots(): MetadataRoute.Robots {
  const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || 'http://localhost:3000';
  const isProduction = process.env.NEXT_PUBLIC_ENV === 'production';
  const isTest = process.env.NEXT_PUBLIC_ENV === 'test' || baseUrl.includes('test.');

  // Block crawlers in development and test
  if (!isProduction || isTest) {
    return {
      rules: {
        userAgent: '*',
        disallow: '/',
      },
    };
  }

  // Production rules
  return {
    rules: [
      {
        // Default rule for all bots
        userAgent: '*',
        allow: '/',
        // Disallow English version and other non-public paths
        disallow: [
          '/en/', // English version
          '/api/', // API endpoints
          '/_next/', // Next.js internals
          '/kereses/', // Search pages
          '/angol-palyakepek/',
        ],
      },
    ],
    sitemap: `${baseUrl}/sitemap.xml`,
    host: baseUrl,
  };
}
