@php
    $trainers = json_decode($section->getSetting('trainers', '[]'), true) ?? [];
    $teamPhotos = \App\Domain\Website\Models\Media::withoutGlobalScope('academy')
        ->where('academy_id', $academy->id)
        ->where('collection', 'team_photo')
        ->orderBy('sort_order')
        ->get();
@endphp

<div class="site-section site-section--dark site-section--pattern">
    <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-white/60 text-lg">{{ $section->subtitle }}</p>
            @endif
        </div>

        @if(count($trainers))
            <div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
                @foreach($trainers as $index => $trainer)
                    <div class="text-center reveal reveal--delay-{{ ($index % 4) + 1 }}">
                        <div class="relative mx-auto w-32 h-32 mb-4">
                            @php $photo = $teamPhotos->get($index); @endphp
                            @if($photo)
                                <img src="{{ $photo->url }}"
                                     alt="{{ $trainer['name'] ?? '' }}"
                                     class="w-full h-full rounded-full object-cover border-3 border-[var(--site-accent)] shadow-lg shadow-[var(--site-accent)]/10">
                            @else
                                <div class="w-full h-full rounded-full bg-gradient-to-br from-[var(--site-accent)]/20 to-[var(--site-secondary)] border-3 border-[var(--site-accent)]/40 flex items-center justify-center">
                                    <svg class="w-12 h-12 text-white/30" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                                    </svg>
                                </div>
                            @endif
                        </div>
                        <h4 class="text-white font-bold">{{ $trainer['name'] ?? '' }}</h4>
                        @if(!empty($trainer['role']))
                            <p class="text-[var(--site-accent)] text-sm mt-1">{{ $trainer['role'] }}</p>
                        @endif
                        @if(!empty($trainer['bio']))
                            <p class="text-white/50 text-sm mt-1">{{ $trainer['bio'] }}</p>
                        @endif
                    </div>
                @endforeach
            </div>
        @else
            <div class="text-center text-white/40 py-8">
                <p>سيتم إضافة فريق المدربين قريباً</p>
            </div>
        @endif
    </div>
</div>
