<?php
header('Content-Type: application/xml');
require_once 'admin/db.php';

$baseUrl = 'https://verseimagine.com';
$lastmod = date('Y-m-d');

echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <!-- Static Pages -->
  <url>
    <loc><?= $baseUrl ?>/</loc>
    <lastmod><?= $lastmod ?></lastmod>
    <priority>1.0</priority>
  </url>
  <url>
    <loc><?= $baseUrl ?>/about</loc>
    <lastmod><?= $lastmod ?></lastmod>
    <priority>0.8</priority>
  </url>
  <url>
    <loc><?= $baseUrl ?>/contact</loc>
    <lastmod><?= $lastmod ?></lastmod>
    <priority>0.8</priority>
  </url>

  <!-- Dynamic Work Pages -->
  <?php
  $stmt = $pdo->query("SELECT id, updated_at FROM portfolio_works WHERE status = 'published'");
  while ($row = $stmt->fetch()) {
      $workUrl = $baseUrl . '/?work=' . $row['id'];
      $updated = date('Y-m-d', strtotime($row['updated_at'] ?? 'now'));
  ?>
  <url>
    <loc><?= htmlspecialchars($workUrl) ?></loc>
    <lastmod><?= $updated ?></lastmod>
    <priority>0.6</priority>
  </url>
  <?php } ?>
</urlset>