<div>
    <div class="flex items-center justify-between mb-6">
        <h1 class="text-xl sm:text-2xl font-bold text-gray-800">{{ __('الأنشطة') }}</h1>
        @permission('participants.create')
        <a href="{{ route('activities.create') }}" wire:navigate
           class="inline-flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 text-sm font-medium">
            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/></svg>
            {{ __('إضافة نشاط') }}
        </a>
        @endpermission
    </div>

    {{-- Flash Messages --}}
    @if(session('success'))
        <div class="mb-4 p-4 bg-green-50 border border-green-200 text-green-700 rounded-lg text-sm">
            {{ session('success') }}
        </div>
    @endif
    @if(session('error'))
        <div class="mb-4 p-4 bg-red-50 border border-red-200 text-red-700 rounded-lg text-sm">
            {{ session('error') }}
        </div>
    @endif

    <!-- Filters -->
    <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 mb-4">
        <div class="flex flex-col sm:flex-row gap-4">
            <div class="flex-1">
                <input type="text" wire:model.live.debounce.300ms="search"
                       placeholder="{{ __('بحث بالاسم...') }}"
                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
            </div>
            <select wire:model.live="category" class="px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                <option value="">{{ __('كل التصنيفات') }}</option>
                @foreach($categoryLabels as $key => $label)
                    <option value="{{ $key }}">{{ $label }}</option>
                @endforeach
            </select>
        </div>
    </div>

    <!-- Grid -->
    <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4" wire:loading.class="opacity-50 pointer-events-none">
        @forelse($activities as $activity)
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-5 {{ !$activity->is_active ? 'opacity-60' : '' }}">
            <div class="flex items-start justify-between mb-3">
                <div class="flex items-center gap-3">
                    <div class="w-10 h-10 rounded-lg flex items-center justify-center" style="background-color: {{ $activity->color }}20">
                        <div class="w-4 h-4 rounded-full" style="background-color: {{ $activity->color }}"></div>
                    </div>
                    <div>
                        <h3 class="font-semibold text-gray-800">{{ $activity->name_ar }}</h3>
                        <p class="text-xs text-gray-500" dir="ltr">{{ $activity->name }}</p>
                    </div>
                </div>
                <span class="px-2 py-0.5 text-xs rounded-full bg-gray-100 text-gray-600">
                    {{ $categoryLabels[$activity->category->value ?? $activity->category] ?? $activity->category }}
                </span>
            </div>

            @if($activity->description_ar)
                <p class="text-sm text-gray-500 line-clamp-2 mb-3">{{ $activity->description_ar }}</p>
            @endif

            <div class="flex items-center justify-between text-sm text-gray-600 mt-4 pt-3 border-t border-gray-100">
                <span>{{ $activity->participants_count }} {{ __('مشترك') }}</span>
                <div class="flex items-center gap-3">
                    <button wire:click="toggleActive('{{ $activity->uuid }}')"
                            wire:loading.attr="disabled"
                            class="text-xs font-medium {{ $activity->is_active ? 'text-green-600 hover:text-green-800' : 'text-red-600 hover:text-red-800' }}">
                        {{ $activity->is_active ? __('نشط') : __('معطل') }}
                    </button>
                    @permission('participants.update')
                    <a href="{{ route('activities.edit', $activity) }}" wire:navigate class="text-blue-600 hover:text-blue-800 text-sm font-medium">{{ __('تعديل') }}</a>
                    @endpermission
                </div>
            </div>
        </div>
        @empty
        <div class="col-span-full text-center py-12 text-gray-500">
            <svg class="w-12 h-12 mx-auto mb-3 text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/></svg>
            <p class="text-lg font-medium">{{ __('لا توجد أنشطة مسجلة') }}</p>
            <p class="text-sm mt-1">{{ __('ابدأ بإضافة نشاط جديد') }}</p>
        </div>
        @endforelse
    </div>
</div>
