<div>
    {{-- Header --}}
    <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6">
        <h1 class="text-2xl font-bold text-gray-900">{{ __('المدربين') }}</h1>
        @can('trainers.create')
        <a href="{{ route('trainers.create') }}" wire:navigate
           class="inline-flex items-center gap-2 px-4 py-2.5 bg-blue-600 text-white text-sm font-medium rounded-lg hover:bg-blue-700 transition-colors">
            <svg class="w-5 h-5" 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>
        @endcan
    </div>

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

    {{-- Filters --}}
    <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 mb-4">
        <div class="grid grid-cols-1 sm:grid-cols-3 gap-3">
            <input type="text" wire:model.live.debounce.300ms="search"
                   placeholder="{{ __('بحث بالاسم أو رقم المدرب...') }}"
                   class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">

            <select wire:model.live="status" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500">
                <option value="">{{ __('كل الحالات') }}</option>
                @foreach($statuses as $s)
                    <option value="{{ $s->value }}">{{ $s->label() }}</option>
                @endforeach
            </select>

            <select wire:model.live="compensationModel" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500">
                <option value="">{{ __('كل نماذج التعويض') }}</option>
                @foreach($compensationModels as $cm)
                    <option value="{{ $cm->value }}">{{ $cm->label() }}</option>
                @endforeach
            </select>
        </div>
    </div>

    {{-- Table --}}
    <div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
        <div class="overflow-x-auto" wire:loading.class="opacity-50 pointer-events-none">
            <table class="w-full text-sm">
                <thead class="bg-gray-50 border-b border-gray-200">
                    <tr>
                        <th class="px-4 py-3 text-start font-semibold text-gray-600">{{ __('المدرب') }}</th>
                        <th class="px-4 py-3 text-start font-semibold text-gray-600">{{ __('الأنشطة') }}</th>
                        <th class="px-4 py-3 text-start font-semibold text-gray-600">{{ __('نموذج التعويض') }}</th>
                        <th class="px-4 py-3 text-start font-semibold text-gray-600">{{ __('التقييم') }}</th>
                        <th class="px-4 py-3 text-start font-semibold text-gray-600">{{ __('الحصص') }}</th>
                        <th class="px-4 py-3 text-start font-semibold text-gray-600">{{ __('الحالة') }}</th>
                        <th class="px-4 py-3 text-start font-semibold text-gray-600">{{ __('إجراءات') }}</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-100">
                    @forelse($trainers as $trainer)
                        <tr class="hover:bg-gray-50">
                            <td class="px-4 py-3">
                                <p class="font-medium text-gray-900">{{ $trainer->employee->person->name_ar ?? '-' }}</p>
                                <p class="text-xs text-gray-500 mt-0.5">{{ $trainer->employee->branch?->name_ar ?? '' }}</p>
                            </td>
                            <td class="px-4 py-3">
                                @if(!empty($trainer->sports))
                                    <div class="flex flex-wrap gap-1">
                                        @foreach($activities->whereIn('id', $trainer->sports) as $act)
                                            <span class="inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium" style="background-color: {{ $act->color }}15; color: {{ $act->color }}">
                                                <span class="w-1.5 h-1.5 rounded-full" style="background-color: {{ $act->color }}"></span>
                                                {{ $act->name_ar }}
                                            </span>
                                        @endforeach
                                    </div>
                                @else
                                    <span class="text-gray-400 text-xs">-</span>
                                @endif
                            </td>
                            <td class="px-4 py-3">
                                <span class="inline-flex px-2 py-0.5 rounded-full text-xs font-medium bg-purple-100 text-purple-800">
                                    {{ $trainer->compensation_model->label() }}
                                </span>
                            </td>
                            <td class="px-4 py-3 text-gray-600">
                                @if($trainer->rating)
                                    <span class="flex items-center gap-1">
                                        <svg class="w-4 h-4 text-yellow-500" fill="currentColor" viewBox="0 0 20 20"><path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"/></svg>
                                        {{ number_format($trainer->rating, 1) }}
                                    </span>
                                @else
                                    <span class="text-gray-400">-</span>
                                @endif
                            </td>
                            <td class="px-4 py-3 text-gray-600">{{ $trainer->total_sessions_conducted }}</td>
                            <td class="px-4 py-3">
                                @php
                                    $statusColors = [
                                        'active' => 'bg-green-100 text-green-800',
                                        'inactive' => 'bg-gray-100 text-gray-600',
                                        'on_leave' => 'bg-yellow-100 text-yellow-800',
                                        'suspended' => 'bg-red-100 text-red-800',
                                    ];
                                @endphp
                                <span class="inline-flex px-2 py-0.5 rounded-full text-xs font-medium {{ $statusColors[$trainer->status->value] ?? 'bg-gray-100 text-gray-600' }}">
                                    {{ $trainer->status->label() }}
                                </span>
                            </td>
                            <td class="px-4 py-3">
                                @can('trainers.update')
                                <a href="{{ route('trainers.edit', $trainer) }}" wire:navigate
                                   class="text-blue-600 hover:text-blue-800 text-xs font-medium">{{ __('تعديل') }}</a>
                                @endcan
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="7" class="px-4 py-12 text-center text-gray-500">
                                <svg class="w-12 h-12 text-gray-300 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M4.26 10.147a60.436 60.436 0 00-.491 6.347A48.627 48.627 0 0112 20.904a48.627 48.627 0 018.232-4.41 60.46 60.46 0 00-.491-6.347m-15.482 0a50.57 50.57 0 00-2.658-.813A59.905 59.905 0 0112 3.493a59.902 59.902 0 0110.399 5.84c-.896.248-1.783.52-2.658.814m-15.482 0A50.697 50.697 0 0112 13.489a50.702 50.702 0 017.74-3.342"/></svg>
                                <p class="font-medium">{{ __('لا يوجد مدربين') }}</p>
                                <p class="text-sm text-gray-400 mt-1">{{ __('ابدأ بإضافة مدرب جديد') }}</p>
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        @if($trainers->hasPages())
            <div class="px-4 py-3 border-t border-gray-200">
                {{ $trainers->links() }}
            </div>
        @endif
    </div>
</div>
