@extends('layouts.site')

@section('title', settings('site_name'))
@section('seo')
    <meta name="description" content="{{ settings('site_description') }}">
    <meta name="keywords" content="{{ settings('site_tags') }}">
    <meta name="robots" content="index, follow">
@endsection


@section('content')
    <!-- هیرو سکشن -->
    @include('site.statics.index_hero')

    <!-- بخش محصولات -->
    <section id="products" class="py-5">
        <div class="container">
            <div class="d-flex justify-content-between align-items-end mb-5">
                <div>
                    <h2 class="fw-bold mb-1">جدیدترین محصولات</h2>
                    <p class="text-muted mb-0">برترین فایل‌های افزوده شده در هفته گذشته</p>
                </div>
                <a href="#" class="btn btn-link text-decoration-none fw-bold">مشاهده همه <i class="bi bi-arrow-right"></i></a>
            </div>

            <div class="row g-4">

                @foreach($lastProducts as $product)
                    <div class="col-md-6 col-lg-3">
                        <div class="card h-100">
                            <img src="{{ Storage::disk('VahabDisk')->url($product->image) }}" class="card-img-top" alt="Product">
                            <div class="card-body d-flex flex-column">
                                <div class="mb-2">
                                    <span class="badge bg-primary bg-opacity-10 text-primary rounded-pill">
                                        {{ $product->category->name }}
                                    </span>
                                </div>
                                <h5 class="card-title fw-bold">
                                    <a href="{{ route('product.view', $product->slug) }}">
                                        {{ $product->name }}
                                    </a>
                                </h5>
                                <p class="card-text text-muted small flex-grow-1">
                                    {{ mb_substr($product->seo_description, 0, 250) }}
                                </p>
                                <div class="d-flex justify-content-between align-items-center mt-3">
                                    <span class="price-tag">{{ number_format($product->price) }} تومان</span>
                                    <div class="btn-group">
                                        <a href="{{ route('product.view', $product->slug) }}" class="btn btn-sm btn-outline-custom rounded-3">
                                            <i class="bi bi-eye"></i>
                                        </a>
                                        <a href="{{ route('cart.add', $product->id) }}" class="btn btn-sm btn-custom rounded-3">
                                            <i class="bi bi-cart-plus"></i>
                                        </a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                @endforeach



            </div>
        </div>
    </section>

    <!-- بخش وبلاگ -->
    <section id="blog" class="py-5 bg-white">
        <div class="container">
            <div class="text-center mb-5">
                <h2 class="fw-bold mb-1">آخرین مطالب وبلاگ</h2>
                <p class="text-muted">اخبار، ترفندها و مقالات آموزشی</p>
            </div>

            <div class="row g-4">

                @foreach($lastPost as $post)
                    <div class="col-md-4">
                        <div class="card h-100 border-0 shadow-sm">
                            <a href="{{ route('blog.view', $post->slug) }}">
                                <img src="{{ Storage::disk('VahabDisk')->url($post->image) }}" class="card-img-top rounded-top-4" alt="Blog">
                            </a>
                            <div class="card-body">
                                <div class="d-flex align-items-center gap-2 mb-2">
                                    <i class="bi bi-calendar3 text-muted small"></i>
                                    <small class="text-muted">{{ $post->created_at->format('Y/m/d') }}</small>
                                </div>
                                <h5 class="card-title fw-bold">
                                    <a href="{{ route('blog.view', $post->slug) }}">
                                        {{ $post->title }}
                                    </a>
                                </h5>
                                <p class="card-text text-muted small">
                                    {{ mb_substr( $post->content, 0, 255) }}
                                </p>
                                <a href="{{ route('blog.view', $post->slug) }}" class="text-decoration-none fw-bold" style="color: var(--primary-color);">ادامه مطلب
                                    <i class="bi bi-arrow-right small"></i>
                                </a>
                            </div>
                        </div>
                    </div>
                @endforeach


            </div>
        </div>
    </section>

@endsection
