<?php
header("Content-Type: application/xml; charset=utf-8");

$base_url = "https://itin.pk";

// Static pages (manually verified or known)
$pages = [
    "/" => "daily",
    "/about.php" => "monthly",
    "/apply.php" => "weekly",
    "/services.php" => "monthly",
    "/contact.php" => "yearly",
    "/itin-registration.php" => "weekly",
    "/itin-renewal.php" => "monthly",
    "/w7-form.php" => "monthly",
    "/blog.php" => "weekly"
];

// Start XML
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

// Add static pages
foreach ($pages as $url => $freq) {
    echo "<url>";
    echo "<loc>{$base_url}{$url}</loc>";
    echo "<lastmod>" . date("Y-m-d") . "</lastmod>";
    echo "<changefreq>{$freq}</changefreq>";
    echo "<priority>" . ($url == "/" ? "1.0" : "0.8") . "</priority>";
    echo "</url>";
}

/*
 OPTIONAL: AUTO-FETCH BLOG POSTS FROM DATABASE
 Uncomment and adjust if you have a blog table

include 'includes/db.php';

$result = mysqli_query($conn, "SELECT slug, updated_at FROM blog");

while ($row = mysqli_fetch_assoc($result)) {
    echo "<url>";
    echo "<loc>{$base_url}/blog/" . $row['slug'] . "</loc>";
    echo "<lastmod>" . date("Y-m-d", strtotime($row['updated_at'])) . "</lastmod>";
    echo "<changefreq>weekly</changefreq>";
    echo "<priority>0.7</priority>";
    echo "</url>";
}
*/

echo '</urlset>';
?>