@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">{{ $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">
                <!-- Blog Posts Section -->
                <section id="blog-posts" class="blog-posts">
                    <div class="container">
                        <div class="row gy-4">
                            <div class="card border-0 p-3">
                                @forelse ($post as $posts)
                                <div class="row mb-4 align-items-stretch">
                                    <!-- Image -->
                                    <div class="col-md-4 d-flex p-3">
                                        <img src="{{ asset('/images/posts/resized/resized_' . $posts->featured_image) }}"
                                            class="img-fluid rounded-3 w-100 object-fit-cover"
                                            style="height: 100%; max-height: 250px; object-fit: cover;"
                                            alt="{{ $posts->title ?? 'Post Image' }}">
                                    </div>

                                    <!-- Content -->
                                    <div class="col-md-8">
                                        <div class="card-body h-100 d-flex flex-column justify-content-between">
                                            <div>
                                                <h5 class="card-title fw-bold">
                                                    <a href="{{ route('read_post', $posts->slug) }}">{{ $posts->title }}</a>
                                                </h5>

                                                <div class="text-muted small mb-2 card-details">
                                                    <i class="icofont-ui-user"></i>
                                                    <a href="{{ route('author_posts', $posts->author->username) }}">{{ $posts->author->name }}</a> &nbsp;
                                                    <i class="mdi mdi-calendar-badge"></i> {{ date_formatter($posts->created_at) }} &nbsp;
                                                    <i class="icofont-category"></i>
                                                    <a href="{{ route('category_post', $posts->post_category->slug) }}" class="ml-1">{{ $posts->post_category->name }}</a>
                                                </div>

                                                <p class="card-text">
                                                    {!! Str::ucfirst(words($posts->content, 25)) !!}
                                                </p>
                                            </div>

                                            <div>
                                                <a href="{{ route('read_post', $posts->slug) }}">Read More...</a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                @empty
                                <p><span class="text-danger">No post found for your search</span></p>
                                @endforelse
                            </div><!-- End blog posts list -->
                        </div>
                    </div>
                </section><!-- /Blog Posts Section -->

                <!-- Blog Pagination Section -->
                <section id="blog-pagination" class="blog-pagination section">

                    <div class="container">
                        <div class="d-flex justify-content-center">
                            <ul>
                                <li><a href="#"><i class="bi bi-chevron-left"></i></a></li>
                                <li><a href="#">1</a></li>
                                <li><a href="#" class="active">2</a></li>
                                <li><a href="#">3</a></li>
                                <li><a href="#">4</a></li>
                                <li>...</li>
                                <li><a href="#">10</a></li>
                                <li><a href="#"><i class="bi bi-chevron-right"></i></a></li>
                            </ul>
                        </div>
                    </div>

                </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