@php
    $tagItems = collect(is_array($tags ?? null) ? $tags : [])->filter()->take(16)->values();
@endphp

@if ($tagItems->isNotEmpty())
    <section class="mt-14 px-4 sm:px-6 lg:px-8">
        <h2 class="mb-5 text-xl font-bold text-white">Popular Tags</h2>

        <div class="flex flex-wrap gap-2">
            @foreach ($tagItems as $tag)
                <a href="/tag/{{ $tag['slug'] ?? '' }}" class="rounded-full bg-nova-800 px-4 py-1.5 text-sm font-medium text-nova-200 transition hover:bg-nova-700 hover:text-white">
                    {{ $tag['name'] ?? 'Tag' }}
                    @if ((int) ($tag['count'] ?? 0) > 0)
                        <span class="ml-1.5 text-xs text-soft">{{ number_format((int) ($tag['count'] ?? 0)) }}</span>
                    @endif
                </a>
            @endforeach
        </div>
    </section>
@endif