@php
    $topSellContent = getContent('top_sell.content', true);
    $cards = App\Models\Card::with('subcategory.category')
        ->whereHas('subcategory.category', function ($q) {
            $q->active();
        })
        ->where('user_id', '!=', 0)
        ->groupBy('subcategory_id')
        ->selectRaw('subcategory_id, count(subcategory_id) as sold, id')
        ->orderBy('sold', 'DESC')
        ->take(12)
        ->get();
@endphp

@if (count($cards))
    <section class="latest-card-section pt-120 pb-120">
        <div class="container">
            <div class="row justify-content-center">
                <div class="col-lg-7 col-xxl-6">
                    <div class="section__header text-center">
                        <span class="section__category">
                            {{ __(@$topSellContent->data_values->title) }}
                        </span>
                        <h3 class="section__title">
                            {{ __(@$topSellContent->data_values->heading) }}
                        </h3>
                        <p>
                            {{ __(@$topSellContent->data_values->subheading) }}
                        </p>
                    </div>
                </div>
            </div>
            <div class="row g-3 g-sm-4 justify-content-center card-wrapper">
                @foreach ($cards as $card)
                    <div class="col-md-4 col-lg-3 col-sm-6">
                        <div class="card-item">
                            <div class="card-thumb">
                                <a href="{{ route('card.details', ['name' => slug($card->subcategory->name), 'id' => $card->subcategory->id]) }}">
                                    <img src="{{ getImage(getFilePath('subcategory') . '/' . $card->subcategory->image, getFileSize('subcategory')) }}" alt="">
                                </a>
                            </div>
                            <h5 class="title">
                                <a href="{{ route('card.details', ['name' => slug($card->subcategory->name), 'id' => $card->subcategory->id]) }}">
                                    {{ __($card->subcategory->name) }}
                                </a>
                            </h5>
                        </div>
                    </div>
                @endforeach
            </div>
        </div>
    </section>
@endif
