@extends('website.layout')

@section('content')
<div class="site-section">
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <div class="text-center mb-12">
            <h1 class="section-title mx-auto">{{ __('الإيفنتات والبطولات') }}</h1>
            <p class="mt-4 text-gray-500 text-lg">{{ __('تابع أحدث الفعاليات والبطولات وسجّل الآن') }}</p>
        </div>

        @if($events->count())
            <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
                @foreach($events as $event)
                    @php
                        $cover = $event->cover;
                        $statusColors = [
                            'published' => 'bg-green-100 text-green-800',
                            'registration_closed' => 'bg-yellow-100 text-yellow-800',
                            'in_progress' => 'bg-blue-100 text-blue-800',
                            'completed' => 'bg-gray-100 text-gray-800',
                        ];
                        $statusLabels = [
                            'published' => 'التسجيل مفتوح',
                            'registration_closed' => 'التسجيل مغلق',
                            'in_progress' => 'جارٍ الآن',
                            'completed' => 'انتهى',
                        ];
                    @endphp
                    <a href="{{ route('website.events.show', ['slug' => $academy->slug, 'eventSlug' => $event->slug]) }}"
                       class="site-card group block transition-transform hover:-translate-y-1">
                        <div class="relative overflow-hidden rounded-t-xl bg-gray-100">
                            @if($cover)
                                <img src="{{ $cover->url }}"
                                     alt="{{ $event->title }}"
                                     class="w-full h-auto object-contain group-hover:scale-105 transition-transform duration-300">
                            @else
                                <div class="w-full h-full bg-gradient-to-br from-[var(--site-accent)]/20 to-[var(--site-primary)]/10 flex items-center justify-center">
                                    <svg class="w-14 h-14 text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/>
                                    </svg>
                                </div>
                            @endif

                            {{-- Status Badge --}}
                            <div class="absolute top-3 start-3">
                                <span class="inline-block px-2.5 py-1 text-xs font-bold rounded-full {{ $statusColors[$event->status->value ?? $event->status] ?? 'bg-gray-100 text-gray-800' }}">
                                    {{ $statusLabels[$event->status->value ?? $event->status] ?? $event->status }}
                                </span>
                            </div>
                        </div>

                        <div class="p-5">
                            <h3 class="font-bold text-lg text-gray-900 group-hover:text-[var(--site-accent)] transition-colors line-clamp-1">
                                {{ $event->title }}
                            </h3>

                            <div class="mt-3 space-y-2 text-sm text-gray-500">
                                {{-- Date --}}
                                <div class="flex items-center gap-2">
                                    <svg class="w-4 h-4 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/>
                                    </svg>
                                    <span dir="ltr">{{ $event->starts_at->translatedFormat('d M Y') }}</span>
                                </div>

                                {{-- Location --}}
                                @if($event->location_name || $event->facility)
                                    <div class="flex items-center gap-2">
                                        <svg class="w-4 h-4 shrink-0" 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>
                                        <span class="line-clamp-1">{{ $event->location_name ?? $event->facility?->name_ar }}</span>
                                    </div>
                                @endif

                                {{-- Capacity --}}
                                @if($event->max_capacity)
                                    <div class="flex items-center gap-2">
                                        <svg class="w-4 h-4 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"/>
                                        </svg>
                                        <span>{{ $event->registrations_count }}/{{ $event->max_capacity }}</span>
                                    </div>
                                @endif
                            </div>
                        </div>
                    </a>
                @endforeach
            </div>

            <div class="mt-10">
                {{ $events->links() }}
            </div>
        @else
            <div class="text-center py-16">
                <svg class="w-16 h-16 mx-auto text-gray-300 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/>
                </svg>
                <p class="text-gray-500 text-lg">{{ __('لا توجد إيفنتات حالياً') }}</p>
            </div>
        @endif
    </div>
</div>
@endsection
