import { NextResponse } from "next/server";
import { generateSitemapXml, getSitemapEntries } from "@/lib/sitemap";

export const dynamic = "force-dynamic";

export async function GET() {
  try {
    const entries = await getSitemapEntries();
    const xml = generateSitemapXml(entries);
    return new NextResponse(xml, {
      headers: { "Content-Type": "application/xml" },
    });
  } catch (error) {
    console.error("Error generating sitemap.xml:", error);
    return new NextResponse(generateSitemapXml([]), {
      status: 500,
      headers: { "Content-Type": "application/xml" },
    });
  }
}
