// src/pages/sitemap.xml.ts
const site = 'https://yourtvheroes.com';

// Страницы EN и их пары на ES. Добавьте/уберите пункты при необходимости.
const pages = [
  { en: '/',               es: '/es/' },
  { en: '/about/',         es: '/es/about/' },
  { en: '/testimonials/',  es: '/es/testimonials/' },
  { en: '/contact/',       es: '/es/contact/' },
];

function urlBlock(en: string, es: string) {
  const lastmod = new Date().toISOString();
  return `
    <url>
      <loc>${site}${en}</loc>
      <lastmod>${lastmod}</lastmod>
      <changefreq>weekly</changefreq>
      <priority>0.8</priority>
      <xhtml:link rel="alternate" hreflang="en" href="${site}${en}"/>
      <xhtml:link rel="alternate" hreflang="es" href="${site}${es}"/>
      <xhtml:link rel="alternate" hreflang="x-default" href="${site}${en}"/>
    </url>
    <url>
      <loc>${site}${es}</loc>
      <lastmod>${lastmod}</lastmod>
      <changefreq>weekly</changefreq>
      <priority>0.8</priority>
      <xhtml:link rel="alternate" hreflang="es" href="${site}${es}"/>
      <xhtml:link rel="alternate" hreflang="en" href="${site}${en}"/>
      <xhtml:link rel="alternate" hreflang="x-default" href="${site}${en}"/>
    </url>
  `;
}

export async function GET() {
  const body = `<?xml version="1.0" encoding="UTF-8"?>
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
          xmlns:xhtml="http://www.w3.org/1999/xhtml">
    ${pages.map(p => urlBlock(p.en, p.es)).join('\n')}
    <!-- thank-you страницы намеренно не добавляем -->
  </urlset>`.trim();

  return new Response(body, {
    headers: { 'Content-Type': 'application/xml; charset=utf-8' },
  });
}
