<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('employees.create')
        <a href="{{ route('employees.wizard') }}" 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-2 lg:grid-cols-4 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="employmentType" 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($employmentTypes as $t)
                    <option value="{{ $t->value }}">{{ $t->label() }}</option>
                @endforeach
            </select>

            <select wire:model.live="branchId" 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($branches as $b)
                    <option value="{{ $b->id }}">{{ $b->name_ar }}</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($employees as $emp)
                        <tr class="hover:bg-gray-50">
                            <td class="px-4 py-3 font-medium text-gray-900">{{ $emp->person?->name_ar ?? '-' }}</td>
                            <td class="px-4 py-3 text-gray-600 font-mono text-xs">{{ $emp->employee_number }}</td>
                            <td class="px-4 py-3 text-gray-600">{{ $emp->position ?? '-' }}</td>
                            <td class="px-4 py-3">
                                <span class="inline-flex px-2 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-700">
                                    {{ $emp->employment_type->label() }}
                                </span>
                            </td>
                            <td class="px-4 py-3 text-gray-600">{{ $emp->branch?->name_ar ?? '-' }}</td>
                            <td class="px-4 py-3">
                                @php
                                    $statusColors = [
                                        'active' => 'bg-green-100 text-green-800',
                                        'on_leave' => 'bg-yellow-100 text-yellow-800',
                                        'suspended' => 'bg-red-100 text-red-800',
                                        'terminated' => 'bg-gray-100 text-gray-800',
                                        'resigned' => 'bg-gray-100 text-gray-600',
                                    ];
                                @endphp
                                <span class="inline-flex px-2 py-0.5 rounded-full text-xs font-medium {{ $statusColors[$emp->status->value] ?? 'bg-gray-100 text-gray-600' }}">
                                    {{ $emp->status->label() }}
                                </span>
                            </td>
                            <td class="px-4 py-3">
                                <div class="flex items-center gap-2">
                                    @can('employees.update')
                                    <a href="{{ route('employees.edit', $emp) }}" wire:navigate
                                       class="text-blue-600 hover:text-blue-800 text-xs font-medium">{{ __('تعديل') }}</a>
                                    @endcan
                                    @can('employees.delete')
                                    <button wire:click="delete('{{ $emp->uuid }}')"
                                            wire:confirm="{{ __('هل أنت متأكد من حذف هذا الموظف؟') }}"
                                            class="text-red-600 hover:text-red-800 text-xs font-medium">{{ __('حذف') }}</button>
                                    @endcan
                                </div>
                            </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="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>
                                <p class="font-medium">{{ __('لا يوجد موظفين') }}</p>
                                <p class="text-sm text-gray-400 mt-1">{{ __('ابدأ بإضافة موظف جديد') }}</p>
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

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