@props(['item']) {{-- Demo data is pre-computed in ProductInventory component for consistency and performance --}}
{{-- Product Image with Badges --}}
@php $primaryImage = $item->getPrimaryImage(); @endphp {{-- Condition Badge - Top Right --}} @if($item->conditionGrade)
{{ $item->conditionGrade->name }}
@endif {{-- Popular Badge - Top Left --}} @if($item->is_popular ?? false)
🔥 HOT DEAL
@endif {{-- Discount Badge --}} @if($item->has_discount ?? false)
{{ $item->discount_percent }}% OFF
@endif @if($item->display_image_url || ($primaryImage && $primaryImage->image_url)) {{ $primaryImage->alt_text ?? ($item->product_name ?? 'Product') }} @else

No Image

@endif {{-- CTA Buttons - Under Image --}}
Details @php $imageCount = method_exists($item, 'getGroupedVisibleImages') ? $item->getGroupedVisibleImages()->count() : 0; @endphp @if($imageCount > 1) 📷 {{ $imageCount }} @endif
{{-- Product Information --}}
{{-- Category Line --}}
@if($item->category) {{ $item->category->name }} @endif
{{-- Product Name with Brand --}}

@if($item->brand) {{ $item->brand->name }} @endif {{ $item->product_name ?? 'Unknown Product' }}

{{-- Star Rating and Reviews --}}
{{-- Trust Indicators --}}
@if(($item->demo_sold ?? 0) > 0) {{ $item->demo_sold }}+ bought this month @endif {{ $item->computed_status['status'] }} @if($item->has_fast_shipping ?? false) Fast Shipping @endif
{{-- Key Specifications --}} @if($item->product_specs) @php $specs = $item->product_specs; $displaySpecs = []; $maxSpecs = 4; // Extract first 4 specs (flatten if nested) if (is_array($specs)) { foreach ($specs as $categoryOrKey => $valueOrSpecs) { if (count($displaySpecs) >= $maxSpecs) break; if (is_array($valueOrSpecs)) { // Nested structure - take first few items foreach ($valueOrSpecs as $key => $value) { if (count($displaySpecs) >= $maxSpecs) break; if ($value) { $displaySpecs[$key] = is_array($value) ? implode(', ', $value) : $value; } } } else { // Flat structure if ($valueOrSpecs) { $displaySpecs[$categoryOrKey] = is_array($valueOrSpecs) ? implode(', ', $valueOrSpecs) : $valueOrSpecs; } } } } @endphp @if(!empty($displaySpecs))
@foreach($displaySpecs as $key => $value)
{{ $key }}: {{ $value }}
@endforeach
@endif @endif
{{-- Price & Savings --}}
@if(($item->has_discount ?? false) && isset($item->original_price))
${{ $item->original_price }}
@endif
{{ $item->computed_price }}
@if(($item->has_discount ?? false) && isset($item->savings)) Save ${{ $item->savings }} @endif
{{-- Media Gallery Column --}} @php // Resolve images for gallery // Always use inventory item images, whether grouped or individual $galleryImages = collect(); // Check if we need to load images for a grouped item if (!$item->relationLoaded('images') && isset($item->model_id)) { // Grouped item - load images from first available inventory item $firstItem = \App\Models\InventoryItem::where('model_id', $item->model_id) ->whereIn('status', ['in_stock', 'listed']) ->with(['images' => function($q) { $q->where('is_visible', true)->orderBy('display_order'); }, 'images.productImage']) ->first(); if ($firstItem) { $item->setRelation('images', $firstItem->images); } } // Now process inventory images (works for both grouped and individual items) if ($item->relationLoaded('images')) { $primaryImage = $item->getPrimaryImage(); // Get unique images, grouped by original source to avoid size variant duplicates $grouped = $item->images ->where('is_visible', true) ->groupBy(function($img) { if ($img->is_shared && $img->productImage) { // For shared product images, group by timestamp pattern if (preg_match('/(\d+_\d+)(?:\.[^.]+)?$/', $img->productImage->original_filename ?? '', $matches)) { return 'product_'.$matches[1]; } return 'product_'.($img->product_image_id ?? 'unknown_'.$img->id); } else { // For inventory-specific images, group by original filename return 'inventory_'.($img->original_filename ?? 'unknown_'.$img->id); } }); // Select the best variant for each group (prefer 500x500) $galleryImages = $grouped->map(function($variants) { $thumb = $variants->first(function($img) { if ($img->is_shared && $img->productImage) { return $img->productImage->width == 500 && $img->productImage->height == 500; } else { return $img->width == 500 && $img->height == 500; } }); if (!$thumb) { // Fallback to largest $thumb = $variants->sortByDesc(function($img) { if ($img->is_shared && $img->productImage) { return ($img->productImage->width ?? 0) * ($img->productImage->height ?? 0); } else { return ($img->width ?? 0) * ($img->height ?? 0); } })->first(); } return $thumb; })->filter(); // Exclude the primary image from gallery if ($primaryImage) { $galleryImages = $galleryImages->filter(function($img) use ($primaryImage) { return $img->id !== $primaryImage->id; }); } // Sort by display order $galleryImages = $galleryImages->sortBy('display_order'); } @endphp @if($galleryImages->count() > 0) @endif {{-- Specifications Column (Enhanced) --}} @if($item->product_specs) @endif