@extends('site.layouts.site-layout')

@section('title', 'وبلاگ')

@section('seo')
<meta name="description" content="جدیدترین مقالات و اخبار وبلاگ">
@endsection

@section('content')

<div class="bread-crumb pt-3">
    <div class="container-fluid">
        <div class="content-box">
            <div class="container-fluid">
                <nav aria-label="breadcrumb" class="my-lg-0 my-2">
                    <ol class="breadcrumb mb-0">
                        <li class="breadcrumb-item"><a href="{{ route('home') }}" class="font-14 text-muted">خانه</a></li>
                        <li class="breadcrumb-item active main-color-one-color font-14" aria-current="page">وبلاگ</li>
                    </ol>
                </nav>
            </div>
        </div>
    </div>
</div>

<div class="content">

    {{-- header / featured layout --}}
    <div class="container-fluid">
        <div class="row gy-3">
            <div class="col-lg-3">
                @include('site.blog.partials._sidebar')
            </div>

            <div class="col-lg-9">
                <div class="side-left-blog">
                    <div class="row gy-3">
                        @forelse($featured as $i => $post)
                            @php
                                $colClass = $i === 1 ? 'col-md-6' : 'col-md-3';
                                $thumb = $post->featured_image
                                    ? url('uploads/blog/posts/' . $post->featured_image)
                                    : asset('theme/assets/image/blog-' . (($i % 8) + 1) . '.jpg');
                            @endphp
                            <div class="{{ $colClass }}">
                                <div class="blog-news-item">
                                    <a href="{{ $post->url() }}">
                                        <img src="{{ $thumb }}" alt="{{ $post->featured_image_alt ?: $post->title }}" class="img-fluid">
                                        <div class="desc">
                                            <h3 class="title">{{ $post->title }}</h3>
                                            <div class="date">
                                                <span class="text-date">{{ \App\Support\Jalali::format($post->published_at ?: $post->created_at, 'j F Y') }}</span>
                                                <i class="bi bi-arrow-left"></i>
                                            </div>
                                        </div>
                                    </a>
                                </div>
                            </div>
                        @empty
                        @endforelse
                    </div>
                </div>
            </div>
        </div>
    </div>

    {{-- popular posts slider --}}
    @if($popular->isNotEmpty())
    <div class="blog-slider site-slider site-slider-sm py-20">
        <div class="container-fluid">
            <div class="header-content mb-4 bg-white shadow-box rounded-3 p-3 d-flex align-items-center justify-content-between flex-wrap">
                <div class="title d-flex align-items-center">
                    <img src="{{ asset('theme/assets/image/square.png') }}" alt="" class="img-fluid">
                    <h5 class="font-16 ms-3">پربازدیدترین مطالب
                        <span class="main-color-one-color d-inline-block">وبلاگ</span>
                    </h5>
                </div>
            </div>
        </div>

        <div class="parent">
            <div class="container-fluid">
                <div class="swiper product-slider-swiper">
                    <div class="swiper-wrapper">
                        @foreach($popular as $post)
                            <div class="swiper-slide">
                                @include('site.blog.partials._post-card', ['post' => $post])
                            </div>
                        @endforeach
                    </div>
                    <div class="swiper-button-next"></div>
                    <div class="swiper-button-prev"></div>
                </div>
            </div>
        </div>
    </div>
    @endif

    {{-- latest posts grid --}}
    <div class="gird-post-blog py-20">
        <div class="container-fluid">
            <div class="header-content mb-4 bg-white shadow-box rounded-3 p-3 d-flex align-items-center justify-content-between flex-wrap">
                <div class="title d-flex align-items-center">
                    <img src="{{ asset('theme/assets/image/square.png') }}" alt="" class="img-fluid">
                    <h5 class="font-16 ms-3">آخرین مطالب
                        <span class="main-color-one-color d-inline-block">وبلاگ</span>
                    </h5>
                </div>
            </div>
        </div>

        <div class="container-fluid">
            <div class="row gy-3">
                @forelse($posts as $post)
                    <div class="col-lg-3 col-md-6">
                        @include('site.blog.partials._post-card', ['post' => $post])
                    </div>
                @empty
                    <div class="col-12">
                        <div class="content-box text-center py-5 text-muted">
                            <i class="bi bi-journal-x fs-1 d-block mb-3"></i>
                            مقاله‌ای یافت نشد.
                        </div>
                    </div>
                @endforelse
            </div>

            @if($posts->hasPages())
                <div class="mt-4 d-flex justify-content-center">
                    {{ $posts->onEachSide(1)->links() }}
                </div>
            @endif
        </div>
    </div>

</div>

@endsection
