@foreach($products as $product)
@php
$game = $product->game;
$image = $game?->image_path ? asset($game->image_path) : asset('images/kroti/product-108.webp');
$visibleOffer = $product->offers
->filter(fn ($offer) => $offer->appliesToUser(auth()->user()))
->sortByDesc('discount_percent')
->first();
$basePrice = max((int) $product->price_minor, 1);
$salePrice = $visibleOffer ? $visibleOffer->salePriceMinor() : $product->sale_price_minor;
$discount = $visibleOffer ? (int) round($visibleOffer->discount_percent) : ($salePrice ? max(1, round((($basePrice - $salePrice) / $basePrice) * 100)) : null);
@endphp
@if($discount)
{{ $discount }}% خصم
@elseif($product->is_best_seller)
الأكثر طلبًا
@endif
{{ $game?->category?->name_ar ?: 'منتج' }}
{{ $product->name_ar }}
{{ $game?->name_ar }}
@endforeach
@else