import type { MetadataRoute } from "next";
import { SITE } from "@/lib/site";

const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || SITE.siteUrl;
// True only once NEXT_PUBLIC_SITE_URL is set to the real main domain at cutover — until then
// (localhost, or a testing subdomain like app.iniyavalreturngifts.com) block indexing entirely
// so the test deployment never competes with the real site as duplicate content.
const isCanonicalDomain = siteUrl === SITE.siteUrl;

export default function robots(): MetadataRoute.Robots {
  if (!isCanonicalDomain) {
    return { rules: { userAgent: "*", disallow: "/" } };
  }
  return {
    rules: {
      userAgent: "*",
      allow: "/",
      disallow: ["/iv-manage-84x2", "/account", "/checkout", "/cart"],
    },
    sitemap: `${siteUrl}/sitemap.xml`,
  };
}
