<div>
    <!-- Header -->
    <div class="mb-6 flex items-center justify-between">
        <div>
            <h1 class="text-xl sm:text-2xl font-bold text-gray-900">{{ __('التقييمات') }}</h1>
            <p class="mt-1 text-sm text-gray-500">{{ __('إدارة تقييمات المشتركين') }}</p>
        </div>
        @can('evaluations.create')
            <a href="{{ route('evaluations.create') }}"
               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-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>
        @endcan
    </div>

    <!-- Filters -->
    <div class="mb-6 p-4 bg-white border border-gray-200 rounded-lg">
        <div class="grid grid-cols-1 gap-4 sm:grid-cols-3">
            <!-- Search -->
            <div>
                <label for="search" class="block text-sm font-medium text-gray-700 mb-1">{{ __('بحث بالمشترك') }}</label>
                <input
                    type="text"
                    id="search"
                    wire:model.live.debounce.300ms="search"
                    placeholder="{{ __('اسم المشترك...') }}"
                    class="w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 text-sm">
            </div>

            <!-- Status Filter -->
            <div>
                <label for="status" class="block text-sm font-medium text-gray-700 mb-1">{{ __('الحالة') }}</label>
                <select
                    id="status"
                    wire:model.live="status"
                    class="w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 text-sm">
                    <option value="">{{ __('الكل') }}</option>
                    @foreach($statuses as $s)
                        <option value="{{ $s->value }}">{{ $s->label() }}</option>
                    @endforeach
                </select>
            </div>

            <!-- Group Filter -->
            <div>
                <label for="groupId" class="block text-sm font-medium text-gray-700 mb-1">{{ __('المجموعة') }}</label>
                <select
                    id="groupId"
                    wire:model.live="groupId"
                    class="w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 text-sm">
                    <option value="">{{ __('الكل') }}</option>
                    @foreach($groups as $group)
                        <option value="{{ $group->id }}">{{ $group->name_ar }}</option>
                    @endforeach
                </select>
            </div>
        </div>
    </div>

    <!-- Table -->
    <div class="bg-white border border-gray-200 rounded-lg overflow-hidden" wire:loading.class="opacity-50 pointer-events-none">
        @if($evaluations->isEmpty())
            <div class="p-12 text-center">
                <svg class="mx-auto h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01"/></svg>
                <p class="mt-4 text-sm text-gray-500">{{ __('لا توجد تقييمات بعد') }}</p>
                @can('evaluations.create')
                    <a href="{{ route('evaluations.create') }}" class="mt-3 inline-flex items-center gap-1 text-sm text-blue-600 hover:text-blue-700">
                        {{ __('إنشاء تقييم جديد') }}
                    </a>
                @endcan
            </div>
        @else
            <div class="overflow-x-auto">
                <table class="min-w-full divide-y divide-gray-200">
                    <thead class="bg-gray-50">
                        <tr>
                            <th class="px-4 py-3 text-start text-xs font-medium text-gray-500 uppercase">{{ __('المشترك') }}</th>
                            <th class="px-4 py-3 text-start text-xs font-medium text-gray-500 uppercase">{{ __('المجموعة') }}</th>
                            <th class="px-4 py-3 text-start text-xs font-medium text-gray-500 uppercase">{{ __('المقيّم') }}</th>
                            <th class="px-4 py-3 text-start text-xs font-medium text-gray-500 uppercase">{{ __('التاريخ') }}</th>
                            <th class="px-4 py-3 text-start text-xs font-medium text-gray-500 uppercase">{{ __('الدرجة') }}</th>
                            <th class="px-4 py-3 text-start text-xs font-medium text-gray-500 uppercase">{{ __('الحالة') }}</th>
                            <th class="px-4 py-3 text-start text-xs font-medium text-gray-500 uppercase">{{ __('إجراءات') }}</th>
                        </tr>
                    </thead>
                    <tbody class="bg-white divide-y divide-gray-200">
                        @foreach($evaluations as $evaluation)
                            <tr class="hover:bg-gray-50">
                                <!-- Participant -->
                                <td class="px-4 py-3 whitespace-nowrap text-sm font-medium text-gray-900">
                                    {{ $evaluation->participant?->person?->name_ar ?? '-' }}
                                </td>

                                <!-- Group -->
                                <td class="px-4 py-3 whitespace-nowrap text-sm text-gray-700">
                                    {{ $evaluation->group?->name_ar ?? '-' }}
                                </td>

                                <!-- Evaluator -->
                                <td class="px-4 py-3 whitespace-nowrap text-sm text-gray-700">
                                    {{ $evaluation->evaluator?->name_ar ?? $evaluation->evaluator?->name ?? '-' }}
                                </td>

                                <!-- Date -->
                                <td class="px-4 py-3 whitespace-nowrap text-sm text-gray-500" dir="ltr">
                                    {{ $evaluation->evaluation_date?->format('Y-m-d') }}
                                </td>

                                <!-- Score -->
                                <td class="px-4 py-3 whitespace-nowrap">
                                    @if($evaluation->overall_score !== null)
                                        @php
                                            $scoreColor = $evaluation->overall_score >= 80 ? 'green' : ($evaluation->overall_score >= 60 ? 'amber' : 'red');
                                        @endphp
                                        <div class="flex items-center gap-2">
                                            <div class="w-16 h-2 bg-gray-200 rounded-full overflow-hidden">
                                                <div class="h-full bg-{{ $scoreColor }}-500 rounded-full" style="width: {{ min($evaluation->overall_score, 100) }}%"></div>
                                            </div>
                                            <span class="text-xs font-medium text-{{ $scoreColor }}-700" dir="ltr">{{ number_format($evaluation->overall_score, 1) }}%</span>
                                        </div>
                                    @else
                                        <span class="text-xs text-gray-400">-</span>
                                    @endif
                                </td>

                                <!-- Status -->
                                <td class="px-4 py-3 whitespace-nowrap">
                                    @php
                                        $badgeColors = [
                                            'gray' => 'bg-gray-100 text-gray-800',
                                            'blue' => 'bg-blue-100 text-blue-800',
                                            'green' => 'bg-green-100 text-green-800',
                                            'purple' => 'bg-purple-100 text-purple-800',
                                        ];
                                        $color = $badgeColors[$evaluation->status->color()] ?? 'bg-gray-100 text-gray-800';
                                    @endphp
                                    <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium {{ $color }}">
                                        {{ $evaluation->status->label() }}
                                    </span>
                                </td>

                                <!-- Actions -->
                                <td class="px-4 py-3 whitespace-nowrap">
                                    <div class="flex items-center gap-2">
                                        <a href="{{ route('evaluations.show', $evaluation) }}"
                                           class="inline-flex items-center gap-1 px-2.5 py-1.5 text-xs font-medium text-blue-700 bg-blue-50 border border-blue-200 rounded-lg hover:bg-blue-100">
                                            <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/></svg>
                                            {{ __('عرض') }}
                                        </a>
                                        @if($evaluation->status->value === 'draft')
                                            @can('evaluations.update')
                                                <a href="{{ route('evaluations.edit', $evaluation) }}"
                                                   class="inline-flex items-center gap-1 px-2.5 py-1.5 text-xs font-medium text-amber-700 bg-amber-50 border border-amber-200 rounded-lg hover:bg-amber-100">
                                                    <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/></svg>
                                                    {{ __('تعديل') }}
                                                </a>
                                            @endcan
                                        @endif
                                    </div>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>

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

    <!-- Criteria Management Link -->
    @can('evaluations.manage')
        <div class="mt-4">
            <a href="{{ route('evaluations.criteria') }}"
               class="inline-flex items-center gap-2 text-sm text-gray-600 hover:text-blue-600 transition-colors">
                <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="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/></svg>
                {{ __('إدارة معايير التقييم') }}
            </a>
        </div>
    @endcan
</div>
