import type { MetadataRoute } from "next";
import { locales } from "@/lib/dictionaries";
import { SITE_URL } from "@/lib/seo";

// All public pages on the site (without locale prefix).
// The private /plans/[code] page is deliberately excluded.
const pages = [
  "",           // homepage
  "/about",
  "/services",
  "/projects",
  "/contact",
];

export default function sitemap(): MetadataRoute.Sitemap {
  const entries: MetadataRoute.Sitemap = [];

  for (const page of pages) {
    for (const locale of locales) {
      const languages: Record<string, string> = {};
      for (const l of locales) {
        languages[l] = `${SITE_URL}/${l}${page}`;
      }
      // x-default points to the English version
      languages["x-default"] = `${SITE_URL}/en${page}`;

      entries.push({
        url: `${SITE_URL}/${locale}${page}`,
        lastModified: new Date(),
        changeFrequency: page === "" ? "weekly" : "monthly",
        priority: page === "" ? 1.0 : 0.8,
        alternates: {
          languages,
        },
      });
    }
  }

  return entries;
}
