import { createFileRoute } from "@tanstack/react-router";
import type {} from "@tanstack/react-start";

const BASE_URL = "";

const entries = [
  { path: "/", priority: "1.0" },
  { path: "/about", priority: "0.9" },
  { path: "/about-down-syndrome", priority: "0.9" },
  { path: "/causes", priority: "0.8" },
  { path: "/initiatives", priority: "0.8" },
  { path: "/projects", priority: "0.8" },
  { path: "/impact", priority: "0.8" },
  { path: "/events", priority: "0.7" },
  { path: "/news", priority: "0.7" },
  { path: "/resources", priority: "0.6" },
  { path: "/volunteer", priority: "0.8" },
  { path: "/donate", priority: "0.9" },
  { path: "/contact", priority: "0.7" },
];

export const Route = createFileRoute("/sitemap.xml")({
  server: {
    handlers: {
      GET: async () => {
        const urls = entries
          .map((e) => `  <url>\n    <loc>${BASE_URL}${e.path}</loc>\n    <changefreq>weekly</changefreq>\n    <priority>${e.priority}</priority>\n  </url>`)
          .join("\n");
        const xml = `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls}\n</urlset>`;
        return new Response(xml, {
          headers: { "Content-Type": "application/xml", "Cache-Control": "public, max-age=3600" },
        });
      },
    },
  },
});
