import type { MetadataRoute } from "next";

// Block ALL crawling on preview / development environments to prevent
// duplicate-content with prod and avoid leaking unfinished work into search
// indexes. Vercel exposes `VERCEL_ENV` ("production" | "preview" | "development").
const isProduction = process.env.VERCEL_ENV === "production";

export default function robots(): MetadataRoute.Robots {
  if (!isProduction) {
    return {
      rules: {
        userAgent: "*",
        disallow: "/",
      },
    };
  }

  return {
    rules: {
      userAgent: "*",
      allow: "/",
      disallow: [
        "/api/",
        "/cdn-cgi/",
        // Block server-path patterns Googlebot extracted from blog code blocks.
        // These were never real URLs on the site; the leading slash made them
        // look like relative URLs to Google's link extractor.
        "/tmp/",
        "/var/",
        "/usr/",
        "/etc/",
        "/srv/",
        "/index.php",
        "/wp-admin/",
        "/wp-login.php",
        "/wp-content/",
        "/wp-includes/",
        "/database-backup.sql",
        "/about-us.html",
        "/archives/",
        "/collections/",
        "/page/",
        "/products/",
        "/produits/",
        "/category/",
        "/categories/",
        "/path/",
        "/chemin/",
      ],
    },
    sitemap: [
      "https://www.elevaseo.com/sitemap.xml",
      "https://www.elevaseo.com/blog/rss.xml",
      "https://www.elevaseo.com/en/blog/rss.xml",
    ],
  };
}
