@extends('theme::layout')

@section('content')
    <header class="category-hero panel">
        @if(filled($category->coverUrl()))
            <figure class="category-hero__cover">
                <img src="{{ $category->coverUrl() }}" alt="{{ $category->name }}">
            </figure>
        @endif
        <h1 class="page-title">{{ $category->name }}</h1>
        @if(filled($category->intro))
            <div class="category-hero__intro">{!! nl2br(e($category->intro)) !!}</div>
        @elseif(filled($category->description))
            <p class="excerpt">{{ $category->description }}</p>
        @endif
        <p class="meta">{{ __('frontend.category.post_count', ['count' => $articles->total()]) }}</p>
    </header>
    <div class="post-list">
        @forelse($articles as $article)
            <article class="post-item">
                @if($article->hasCover() && ($coverUrl = $article->coverUrl()))
                    <a class="post-item__cover" href="{{ url('/show-'.$article->id.'.shtml') }}">
                        <img src="{{ $coverUrl }}" alt="{{ $article->title }}" loading="lazy">
                    </a>
                @endif
                <h2><a href="{{ url('/show-'.$article->id.'.shtml') }}">{{ $article->title }}</a></h2>
                <p class="meta">
                    {{ optional($article->published_at)->format('Y-m-d') }}
                    · {{ strtoupper($article->content_format) }}
                    @if($article->stick) · {{ __('frontend.common.pinned') }} @endif
                </p>
                <p class="excerpt">{{ app(\App\Domain\Blog\ArticleExcerpt::class)->forList($article) }}</p>
            </article>
        @empty
            <div class="panel">
                <p class="meta">{{ __('frontend.common.no_posts') }}</p>
            </div>
        @endforelse
    </div>
    <div class="pagination">{{ $articles->links() }}</div>
@endsection
