@php
    $height = ['sm' => 'h-64', 'md' => 'h-96', 'lg' => 'h-[32rem]'][$block->get('height', 'md')] ?? 'h-96';
    $locations = $block->get('use_branch_data', true)
        ? $items->map(fn ($b) => ['name' => $b->name_ar ?? $b->name ?? '', 'address' => $b->address ?? '', 'coords' => $b->coordinates ?? null])
        : collect($block->get('locations') ?: []);
    $primary = $locations->first();
    $query = $primary ? (data_get($primary, 'coords') ?: data_get($primary, 'address')) : null;
@endphp
<div class="{{ $variant === 'full_width' ? '' : 'max-w-7xl mx-auto px-4 sm:px-6 lg:px-8' }}">
    @if ($block->get('title'))
        <h2 class="ec-heading text-3xl font-bold text-center mb-8">{{ $block->get('title') }}</h2>
    @endif
    <div class="{{ $variant === 'split' ? 'grid md:grid-cols-[20rem_1fr] gap-8' : '' }}">
        @if ($variant === 'split')
            <ul class="flex flex-col gap-3">
                @foreach ($locations as $loc)
                    <li class="ec-surface rounded-xl p-4">
                        <p class="font-semibold">{{ data_get($loc, 'name') }}</p>
                        <p class="ec-muted text-sm">{{ data_get($loc, 'address') }}</p>
                    </li>
                @endforeach
            </ul>
        @endif
        <div class="{{ $height }} w-full overflow-hidden {{ $variant === 'full_width' ? '' : 'rounded-2xl' }}">
            @if ($query)
                <iframe class="w-full h-full border-0" loading="lazy" allowfullscreen
                        referrerpolicy="no-referrer-when-downgrade"
                        title="{{ $block->get('title') ?: __('الموقع على الخريطة') }}"
                        src="https://www.google.com/maps?q={{ urlencode($query) }}&z={{ (int) $block->get('zoom', 13) }}&output=embed"></iframe>
            @else
                <div class="w-full h-full grid place-items-center ec-surface ec-muted">{{ __('لم يتم تحديد موقع') }}</div>
            @endif
        </div>
    </div>
</div>
