@php
    $branches = $data['branches'] ?? collect();
@endphp

<div class="site-section site-section--alt">
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
        <div class="text-center mb-12 reveal">
            <h2 class="section-title mx-auto">{{ $section->title ?? 'فروعنا' }}</h2>
            @if($section->subtitle)
                <p class="mt-4 text-gray-500 text-lg">{{ $section->subtitle }}</p>
            @endif
        </div>

        @if($branches->count())
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                @foreach($branches as $branch)
                    @php
                        $branchImage = \App\Domain\Website\Models\Media::withoutGlobalScope('academy')
                            ->where('academy_id', $academy->id)
                            ->where('collection', 'branch_photo')
                            ->where('mediable_type', 'branch')
                            ->where('mediable_id', $branch->id)
                            ->first();
                    @endphp
                    <div class="site-card reveal reveal--delay-{{ ($loop->index % 3) + 1 }}">
                        @if($branchImage)
                            <div class="relative overflow-hidden aspect-[3/2]">
                                <img src="{{ $branchImage->url }}"
                                     alt="{{ $branch->name_ar }}"
                                     class="site-card__image">
                            </div>
                        @endif

                        <div class="p-5">
                            <div class="flex items-start justify-between">
                                <h3 class="text-lg font-bold text-gray-900">{{ $branch->name_ar }}</h3>
                                @if($branch->is_main)
                                    <span class="px-2 py-0.5 text-xs rounded-full bg-blue-50 text-blue-600 border border-blue-100">
                                        رئيسي
                                    </span>
                                @endif
                            </div>

                            @if($branch->address)
                                <p class="mt-2 text-gray-500 text-sm flex items-start gap-2">
                                    <svg class="w-4 h-4 mt-0.5 shrink-0 text-[var(--site-accent)]" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"/></svg>
                                    {{ $branch->address }}
                                </p>
                            @endif

                            @if($branch->phone)
                                <p class="mt-2 text-gray-500 text-sm flex items-center gap-2">
                                    <svg class="w-4 h-4 shrink-0 text-[var(--site-accent)]" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"/></svg>
                                    <span dir="ltr">{{ $branch->phone }}</span>
                                </p>
                            @endif
                        </div>
                    </div>
                @endforeach
            </div>
        @else
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                @for($i = 0; $i < 3; $i++)
                    <div class="skeleton-card">
                        <div class="aspect-[3/2] skeleton-block"></div>
                        <div class="p-5 space-y-3">
                            <div class="skeleton-block h-5 w-1/2"></div>
                            <div class="skeleton-block h-3 w-3/4"></div>
                            <div class="skeleton-block h-3 w-1/2"></div>
                        </div>
                    </div>
                @endfor
            </div>
            <div class="empty-state mt-4">
                <p class="text-sm">لم تُضف فروع بعد</p>
            </div>
        @endif
    </div>
</div>
