<?php
require 'config.php';

header('Content-Type: application/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    
    <!-- Pagina principală -->
    <url>
        <loc><?= SITE_URL ?>/</loc>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
        <lastmod><?= date('Y-m-d') ?></lastmod>
    </url>
    
    <!-- Pagina Toate Rețetele -->
    <url>
        <loc><?= SITE_URL ?>/toate-retetele</loc>
        <changefreq>weekly</changefreq>
        <priority>0.9</priority>
    </url>
    
    <?php
    // Toate rețetele individuale
    $stmt = $pdo->query("SELECT id, slug, data_adaugare FROM retete");
    while ($row = $stmt->fetch()) {
        $url = $row['slug'] ? SITE_URL . '/reteta/' . $row['slug'] : SITE_URL . '/?id=' . $row['id'];
        echo '
    <url>
        <loc>' . $url . '</loc>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
        <lastmod>' . date('Y-m-d', strtotime($row['data_adaugare'])) . '</lastmod>
    </url>';
    }
    ?>
</urlset>