{!! '<?xml version="1.0" encoding="UTF-8"?>' !!}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">

    {{-- Blog categories (active + with published posts) --}}
    @foreach($blogCategories as $cat)
    <url>
        <loc>{{ route('blog.category', $cat) }}</loc>
        <lastmod>{{ $cat->updated_at->toAtomString() }}</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.6</priority>
    </url>
    @endforeach

    {{-- Blog posts --}}
    @foreach($blogPosts as $post)
        @if($post->category)
        <url>
            <loc>{{ route('blog.show', [$post->category, $post]) }}</loc>
            <lastmod>{{ $post->updated_at->toAtomString() }}</lastmod>
            <changefreq>weekly</changefreq>
            <priority>0.7</priority>
            @if($post->featured_image)
            <image:image>
                <image:loc>{{ url('uploads/blog/posts/' . $post->featured_image) }}</image:loc>
                <image:title>{{ $post->featured_image_alt ?: $post->title }}</image:title>
            </image:image>
            @endif
        </url>
        @endif
    @endforeach

    {{-- Blog tags (only with published posts) --}}
    @foreach($blogTags as $tag)
    <url>
        <loc>{{ route('blog.tag', $tag) }}</loc>
        <lastmod>{{ $tag->updated_at->toAtomString() }}</lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.4</priority>
    </url>
    @endforeach

</urlset>
