// src/routes/sitemap.xml/+server.js
const site = 'https://paintings-clicknbuy.com'; // your live site URL
// Example static routes and dynamic ones from paintings
const staticRoutes = [
  '/',
  '/gallery'
];

// Optional: import paintings.json to get dynamic painting pages
import paintings from '$lib/paintings.json';

/** @type {import('./$types').RequestHandler} */
export async function GET() {
  const pages = [
    ...staticRoutes.map(route => ({
      url: `${site}${route}`,
      lastmod: new Date().toISOString()
    })),
    ...paintings.map(p => ({
      url: `${site}/gallery/${p.title.toLowerCase().replace(/\s+/g, '-')}`,
      lastmod: new Date().toISOString()
    }))
  ];

  const xml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  ${pages
    .map(
      page => `<url>
  <loc>${page.url}</loc>
  <lastmod>${page.lastmod}</lastmod>
</url>`
    )
    .join('\n')}
</urlset>`;

  return new Response(xml, {
    headers: {
      'Content-Type': 'application/xml'
    }
  });
}
