import { headers } from 'next/headers';
import { getBaseUrl } from '../utils/sitemap';

async function getCurrentDomain() {
    try {
        const headersList = await headers();
        return headersList.get('host') || 'nobat724.com';
    } catch {
        return 'nobat724.com';
    }
}

export default async function robots() {
    const domain = await getCurrentDomain();
    const baseUrl = getBaseUrl(domain);

    // If DEV_MODE is TRUE, disallow all crawlers
    if (process.env.DEV_MODE === 'TRUE') {
        return {
            rules: {
                userAgent: '*',
                disallow: '/',
            },
        };
    }

    return {
        rules: {
            userAgent: '*',
            allow: '/',
            disallow: [
                '/dashboard',
                '/login',
                '/login-verify',
                '/payment',
                '/appointment',
            ],
        },
        sitemap: `${baseUrl}/sitemap.xml`,
    };
}
