import type { APIRoute } from 'astro'

const PAGES = [
  '', 'features', 'pricing', 'pos', 'import', 'integrations',
  'for-grocery', 'for-pharmacy', 'for-cafe', 'for-alcohol', 'for-clothing', 'for-household',
  'signup', 'about', 'contacts', 'kb', 'blog', 'status', 'changelog',
  'legal/offer', 'legal/privacy', 'legal/consent', 'legal/requisites',
]

export const GET: APIRoute = ({ site }) => {
  const base = (site?.toString() ?? 'https://test.food-market.kz').replace(/\/$/, '')
  const urls = PAGES.map((p) => `<url><loc>${base}/${p}</loc></url>`).join('\n  ')
  const xml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  ${urls}
</urlset>`
  return new Response(xml, { headers: { 'Content-Type': 'application/xml' } })
}
