<?php
/**
 * sitemap.xml — Dynamic XML sitemap
 */
require_once __DIR__ . '/app/bootstrap.php';
require_once __DIR__ . '/app/helpers.php';

$conn = create_db_connection();
$result = $conn->query("SELECT id, title, updated_at FROM services WHERE active = 1 ORDER BY id");

header('Content-Type: application/xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://masinfo.online/</loc>
    <changefreq>weekly</changefreq>
    <priority>1.0</priority>
  </url>
  <url>
    <loc>https://masinfo.online/como-funciona.php</loc>
    <changefreq>monthly</changefreq>
    <priority>0.7</priority>
  </url>
<?php while ($row = $result->fetch_assoc()): ?>
  <url>
    <loc>https://masinfo.online/servicio/<?= (int)$row['id'] ?>/<?= htmlspecialchars(slugify($row['title']), ENT_QUOTES, 'UTF-8') ?></loc>
    <changefreq>monthly</changefreq>
    <priority>0.8</priority>
  </url>
<?php endwhile; ?>
</urlset>
<?php
$conn->close();
