@extends('front.layout.pages-layout')
@section('pageTitle', isset($pageTitle) ? $pageTitle : 'Document Title')
@section('meta_tags')
{!! SEO::generate() !!}
@endsection
@section('content')
<section class="section department-single">
    <div class="container">
        <div class="row">
            <div class="col-12">
                <div class="d-flex justify-content-between align-items-center mb-4 flex-wrap">
                    <!-- Title -->
                    <h3 class="mb-0">Tag: {{ $pageTitle }} | Bulletin Room</h3>
                    <!-- Breadcrumb -->
                    <nav aria-label="breadcrumb">
                        <ol class="breadcrumb bg-transparent mb-0 px-0">
                            <li class="breadcrumb-item"><a href="{{ url('/') }}">Home</a></li>
                            <li class="breadcrumb-item"><a href="{{ route('bulletin') }}">Bulletin</a></li>
                            <li class="breadcrumb-item active" aria-current="page">{{ $pageTitle }}</li>
                        </ol>
                    </nav>
                </div>
                <hr>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-8">
                <section class="section">
                    <div class="container">
                        <div class="w-full mb-3">
                            <h3 class="title-color">{{ $pageTitle }}</h3>
                        </div>
                        <div class="row">
                            @if ($post->count())
                            <div class="row">
                                @foreach ($post as $posts )
                                <!-- Card 1 -->
                                <div class="col-md-6 col-lg-4">
                                    <div class="card h-100 border-0">
                                        <img src="/images/posts/resized/resized_{{ $posts->featured_image }}"
                                            class="card-img img-fluid rounded-3"
                                            alt="Post Image"
                                            style="height: 180px; object-fit: cover;">
                                        <div class="card-body px-0 ">
                                            <h6 class="card-title fw-semibold mb-3">

                                                <a href="{{ route('read_post', $posts->slug) }}">
                                                    <strong>{{ $posts->title }}</strong>
                                                </a>
                                            </h6>
                                            <p class="mb-0 text-muted ">Date : {{ date_formatter($posts->created_at) }}</p>
                                            <p class="mb-0 text-muted ">Author : <a href="{{ route('author_posts',$posts->author->username) }}" class="ml-1"> </a>{{ $posts->author->name }}</p>
                                        </div>
                                    </div>
                                </div>
                                @endforeach
                            </div>
                            @else
                            <p><span class="text-danger">No post found in this tag.</span></p>
                            @endif
                            <!-- /Blog Posts Section -->
                        </div>
                    </div>
                </section>
                <!-- Blog Pagination Section -->
                <section id="blog-pagination" class="blog-pagination section">

                    {{ $post->appends(request()->input())->links('custom_pagination') }}

                </section><!-- /Blog Pagination Section -->
            </div>
            <div class="col-lg-4 sidebar">

                <div class="widgets-container">

                    <!-- Search Widget -->
                    <x-sidebar-search></x-sidebar-search><!--/Search Widget -->

                    <!-- Categories Widget -->
                    @php
                    $grouped = sidebar_categories()->groupBy(fn($cat) => $cat->parent_category->name ?? 'Others');
                    @endphp

                    <div class="categories-widget widget-item">
                        <h3 class="widget-title">Categories</h3>

                        @foreach ($grouped as $parentName => $categories)
                        <h6 class="mt-3"><strong>{{ $parentName }}</strong></h6>
                        <ul class="ms-3">
                            @foreach ($categories as $item)
                            <li>
                                <a href="{{ route('category_post', $item->slug) }}">
                                    {{ $item->name }} <span>({{ $item->posts_count }})</span>
                                </a>
                            </li>
                            @endforeach
                        </ul>
                        @endforeach
                    </div>

                    <!--/Categories Widget -->

                    <!-- Recent Posts Widget -->
                    <div class="recent-posts-widget widget-item">

                        <h3 class="widget-title">Recent Posts</h3>
                        @foreach (sidebar_latest_posts() as $item)

                        <div class="post-item">
                            <img src="/images/posts/resized/resized_{{ $item->featured_image }}" alt="{{ $item->title }}" class="img-fluid" style="max-height: 100px; object-fit: cover;">
                            <div>
                                <h4 style="line-height: 1.5rem;"><a href="{{ route('read_post', $item->slug) }}">{{ $item->title }}</a></h4>
                                <time>{{ date_formatter($item->created_at) }}</li></time>
                            </div>
                        </div>
                        @endforeach
                        <!-- End recent post item-->
                    </div><!--/Recent Posts Widget -->

                    <!-- Tags Widget -->
                    <div class="tags-widget widget-item">

                        <h3 class="widget-title">Tags</h3>
                        <ul>
                            @foreach (getTags() as $tags )
                            <li><a href="{{ route('tag_posts', urlencode($tags)) }}">{{ $tags }}</a></li>
                            @endforeach
                        </ul>

                    </div><!--/Tags Widget -->

                </div>

            </div>
        </div>
    </div>
</section>
@endsection