/**
 * Single source of truth for the deploy environment used by SEO production
 * gates. Prefers `VERCEL_ENV` (which distinguishes `preview` from `production`
 * on Vercel) over `NODE_ENV` (which is `production` even on preview deploys),
 * so `noIndexNonProduction` correctly noindexes preview deployments.
 */
export function resolveSeoEnvironment(explicit) {
    return explicit ?? process.env.VERCEL_ENV ?? process.env.NODE_ENV;
}
function robotsPolicyDirectives(policy) {
    switch (policy) {
        case 'index-follow':
            return { noIndex: false, noFollow: false };
        case 'noindex-follow':
            return { noIndex: true, noFollow: false };
        case 'index-nofollow':
            return { noIndex: false, noFollow: true };
        case 'noindex-nofollow':
            return { noIndex: true, noFollow: true };
        default:
            return null;
    }
}
export function resolveRobotsDirectives(input) {
    const pageData = input.pageData ?? {};
    const settings = input.settings ?? {};
    const environment = resolveSeoEnvironment(input.environment);
    const policyDirectives = robotsPolicyDirectives(pageData.robotsPolicy);
    const noIndex = policyDirectives
        ? policyDirectives.noIndex
        : typeof pageData.noIndex === 'boolean'
            ? pageData.noIndex
            : Boolean(settings.defaultNoIndex);
    const noFollow = policyDirectives
        ? policyDirectives.noFollow
        : typeof pageData.noFollow === 'boolean'
            ? pageData.noFollow
            : Boolean(settings.defaultNoFollow);
    return {
        noIndex: noIndex || (settings.noIndexNonProduction === true && environment !== 'production'),
        noFollow,
    };
}
//# sourceMappingURL=robots.js.map