@extends('frontend.layouts.template-base')
@section('meta_tags')
@include('frontend.layouts.meta-tags', ['title' => 'Grocery', 'page' => 'grocery'])
@endsection
@section('styles')
@endsection
@section('content')
{{-- ═══════════════════════════════════════════════════════════
STATIC HERO SECTION — DO NOT MODIFY
═══════════════════════════════════════════════════════════ --}}
{{-- ═══════════════════════════════════════════════════════════
END STATIC HERO SECTION
═══════════════════════════════════════════════════════════ --}}
{{-- ═══════════════════════════════════════════════════════════
DYNAMIC CONTENT — driven entirely by admin panel
═══════════════════════════════════════════════════════════ --}}
@php
$grocerySections = collect($grocerySections ?? []);
$groceryBannersByPosition = collect($groceryBannersByPosition ?? []);
$positionedGroceryBannerIds = array_flip(
$groceryBannersByPosition->flatten(1)->pluck('id')->toArray()
);
@endphp
@if (!($groceryLoadError ?? null) && ($grocerySections->isNotEmpty() || $groceryBannersByPosition->isNotEmpty()))
@foreach ($grocerySections as $grocerySectionIndex => $grocerySection)
{{-- Banners positioned before this section --}}
@foreach ($groceryBannersByPosition->get($grocerySectionIndex, collect()) as $groceryBanner)
@include('frontend.components.home-sections.poster', ['section' => (object) ['banners' => collect([$groceryBanner]), 'background_image' => null]])
@endforeach
@php
$hasGroups = $grocerySection->groups->isNotEmpty();
$allTabProds = $grocerySection->tabs->flatMap(fn ($t) => $t->products)->unique('id');
$hasTabs = $grocerySection->tabs->isNotEmpty() && $allTabProds->isNotEmpty();
$hasProducts = $grocerySection->products->isNotEmpty();
$sectionBanners = $grocerySection->banners->filter(fn ($b) => !isset($positionedGroceryBannerIds[$b->id]));
$hasBannersOnly = !$hasGroups && !$hasTabs && !$hasProducts && $sectionBanners->isNotEmpty();
@endphp
{{-- ── BANNER SECTION → 2-up promo row or full-width poster ── --}}
@if ($hasBannersOnly)
@php
// Expand "multiple" type banners: each image (main + additional_images) becomes its own promo slot.
// Two separate banner records also produce two slots — same grid, no special casing needed.
$promoSlots = collect();
foreach ($sectionBanners as $b) {
if (($b->banner_type ?? '') === 'multiple' && !empty($b->additional_images)) {
$promoSlots->push(['image' => $b->banner_image, 'banner' => $b]);
foreach ($b->additional_images as $extraImg) {
$promoSlots->push(['image' => $extraImg, 'banner' => $b]);
}
} else {
$promoSlots->push(['image' => $b->banner_image, 'banner' => $b]);
}
}
@endphp
@if ($promoSlots->count() >= 2)
{{ $grocerySection->name }}
{{ $grocerySection->name }}