import { MetadataRoute } from 'next';
import { headers } from 'next/headers';

export const dynamic = 'force-dynamic';

export default function robots(): MetadataRoute.Robots {
  const headersList = headers();
  const host = headersList.get('x-forwarded-host') || process.env.NEXTAUTH_URL || 'https://spookysoftwaresyndicate.com';
  const siteUrl = host.startsWith('http') ? host : `https://${host}`;

  return {
    rules: [
      {
        userAgent: '*',
        allow: '/',
        disallow: [
          '/api/',
          '/admin/',
          '/ghost-control/',
          '/gfs/',
          '/apps/',
          '/(auth)/',
          '/dark-factory/app/',
          '/dark-factory/login',
          '/dark-factory/signup',
          '/dark-factory/forgot-password',
          '/sms/',
          '/tesa/',
          '/talk-to-tes',
          '/srm',
          '/swag-store/success',
        ],
      },
    ],
    sitemap: `${siteUrl}/sitemap.xml`,
  };
}
