@php
$items = collect($section->items ?? []); // flat array of {thumbnail, mobile_thumbnail, keyword}
$layout = $section->layout ?? 1;
$carouselId = 'banner-carousel-' . $section->id;
/**
* Distribute items round-robin into $n column buckets.
* e.g. 5 items, n=2 → [[0,2,4], [1,3]]
*/
$distribute = function(int $n) use ($items) {
$buckets = array_fill(0, $n, []);
foreach ($items->values() as $i => $banner) {
$buckets[$i % $n][] = $banner;
}
return $buckets; // array of arrays
};
@endphp
@if($layout == 1)
{{-- ── Layout 1: Full-width single carousel ── --}}
@foreach($items as $i => $banner)
@php
$bKeyword = data_get($banner, 'keyword');
$bThumb = data_get($banner, 'thumbnail');
$bMobileThumb = data_get($banner, 'mobile_thumbnail');
$bThumbUrl = $bThumb ? uploadedAsset($bThumb) : null;
$bMobileUrl = $bMobileThumb ? uploadedAsset($bMobileThumb) : null;
$finalUrl = $bKeyword ? route('frontend.product_list', ['q' => $bKeyword]) : null;
@endphp
@endforeach
@if($items->count() > 1)
@endif
@elseif($layout == 2)
{{-- ── Layout 2: Two carousels side-by-side (col-md-6 each) ── --}}
@php $columns = $distribute(2); @endphp
@foreach($columns as $colIdx => $group)
@if(count($group))
@php $cid = $carouselId . '-c' . $colIdx; @endphp
@foreach($group as $bi => $banner)
@php
$bKeyword = data_get($banner, 'keyword');
$bThumb = data_get($banner, 'thumbnail');
$bMobileThumb = data_get($banner, 'mobile_thumbnail');
$bThumbUrl = $bThumb ? uploadedAsset($bThumb) : null;
$bMobileUrl = $bMobileThumb ? uploadedAsset($bMobileThumb) : null;
$finalUrl = $bKeyword ? route('frontend.product_list', ['q' => $bKeyword]) : null;
@endphp
@endforeach
@if(count($group) > 1)
@endif
@endif
@endforeach
@elseif($layout == 3)
{{-- ── Layout 3: Three carousels side-by-side (col-md-4 each) ── --}}
@php $columns = $distribute(3); @endphp
@foreach($columns as $colIdx => $group)
@if(count($group))
@php $cid = $carouselId . '-c' . $colIdx; @endphp
@foreach($group as $bi => $banner)
@php
$bKeyword = data_get($banner, 'keyword');
$bThumb = data_get($banner, 'thumbnail');
$bMobileThumb = data_get($banner, 'mobile_thumbnail');
$bThumbUrl = $bThumb ? uploadedAsset($bThumb) : null;
$bMobileUrl = $bMobileThumb ? uploadedAsset($bMobileThumb) : null;
$finalUrl = $bKeyword ? route('frontend.product_list', ['q' => $bKeyword]) : null;
@endphp
@endforeach
@if(count($group) > 1)
@endif
@endif
@endforeach
@elseif($layout == 4)
{{-- ── Layout 4: Four carousels side-by-side (col-md-3 each) ── --}}
@php $columns = $distribute(4); @endphp
@foreach($columns as $colIdx => $group)
@if(count($group))
@php $cid = $carouselId . '-c' . $colIdx; @endphp
@foreach($group as $bi => $banner)
@php
$bKeyword = data_get($banner, 'keyword');
$bThumb = data_get($banner, 'thumbnail');
$bMobileThumb = data_get($banner, 'mobile_thumbnail');
$bThumbUrl = $bThumb ? uploadedAsset($bThumb) : null;
$bMobileUrl = $bMobileThumb ? uploadedAsset($bMobileThumb) : null;
$finalUrl = $bKeyword ? route('frontend.product_list', ['q' => $bKeyword]) : null;
@endphp
@endforeach
@if(count($group) > 1)
@endif
@endif
@endforeach
@endif