@extends('news.layout', [
    'metaTitle' => $category->name . ' — News',
    'metaDescription' => $category->description ?: ('Announcements in the ' . $category->name . ' category.'),
    'metaCanonical' => route('news.category', $category->slug),
])

@section('news_content')
@php
    $articleItems = collect($articles->items());
    $headerBreadcrumbs = collect([
        (object) ['name' => 'News', 'url' => route('news.index')],
        (object) ['name' => $category->name, 'url' => route('news.category', $category->slug)],
    ]);

    $structuredData = [
        [
            '@context' => 'https://schema.org',
            '@type' => 'CollectionPage',
            'name' => $category->name . ' — News',
            'description' => $category->description ?: ('Announcements filed under ' . $category->name . '.'),
            'url' => route('news.category', $category->slug),
        ],
    ];

    if ($articleItems->isNotEmpty()) {
        $structuredData[] = [
            '@context' => 'https://schema.org',
            '@type' => 'ItemList',
            'name' => $category->name . ' — News Articles',
            'description' => 'Published News stories in the ' . $category->name . ' category.',
            'url' => route('news.category', $category->slug),
            'numberOfItems' => $articleItems->count(),
            'itemListElement' => $articleItems->values()->map(fn ($article, int $index): array => [
                '@type' => 'ListItem',
                'position' => $index + 1,
                'name' => $article->title,
                'url' => route('news.show', ['slug' => $article->slug]),
            ])->all(),
        ];
    }

    $seo = \App\Support\Seo\SeoDataBuilder::fromArray([
        'title' => $category->name . ' — News',
        'description' => $category->description ?: ('Announcements in the ' . $category->name . ' category.'),
        'canonical' => route('news.category', $category->slug),
        'breadcrumbs' => $headerBreadcrumbs,
        'structured_data' => $structuredData,
    ])->build();
@endphp

<x-nova-page-header
    section="News"
    :title="$category->name"
    icon="fa-folder-open"
    :breadcrumbs="$headerBreadcrumbs"
    :description="$category->description ?: ('Announcements filed under ' . $category->name . '.')"
    headerClass="pb-6"
    innerClass="mx-auto max-w-7xl"
/>

<div class="mx-auto max-w-7xl px-6 pt-8 pb-16 md:px-10">
    <div class="grid gap-8 xl:grid-cols-[minmax(0,1fr)_320px]">
        <section>
            @if($articles->isEmpty())
                <div class="rounded-[28px] border border-white/[0.06] bg-white/[0.025] px-8 py-14 text-center text-white/45">No articles in this category yet.</div>
            @else
                <div class="grid gap-5 md:grid-cols-2">
                    @foreach($articles as $article)
                        @include('news._article_card', ['article' => $article])
                    @endforeach
                </div>
                <div class="mt-8 flex justify-center">{{ $articles->links() }}</div>
            @endif
        </section>
        <aside class="space-y-4">
            @include('news._sidebar', ['categories' => $categories, 'trending' => $trending, 'tags' => $tags])
        </aside>
    </div>
</div>
@endsection
