<x-admin-layout>
    <div class="mb-6 flex flex-col md:flex-row justify-between items-center gap-4">
        <div>
            <h2 class="text-2xl font-bold text-slate-800">إدارة الحجوزات</h2>
            <p class="text-slate-500 text-sm">متابعة حجوزات الصيانة وقيادة التجربة</p>
        </div>
    </div>

    <div class="mb-6">
        <div class="border-b border-gray-200">
            <nav class="-mb-px flex space-x-8 space-x-reverse" aria-label="Tabs">
                <a href="{{ route('admin.bookings.index', ['type' => 'service']) }}" class="border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm">
                    حجوزات الصيانة
                </a>
                <a href="{{ route('admin.bookings.index', ['type' => 'test_drive']) }}" class="border-blue-500 text-blue-600 whitespace-nowrap py-4 px-1 border-b-2 font-bold text-sm">
                    قيادة التجربة
                </a>
            </nav>
        </div>
    </div>

    <div class="mb-6 rounded-2xl bg-white p-4 shadow-sm border border-slate-100">
        <form method="GET" action="{{ route('admin.bookings.index') }}" class="flex flex-col md:flex-row items-center gap-4">
            <input type="hidden" name="type" value="test_drive">
            <div class="relative flex-1 w-full">
                <x-icon name="Search" class="absolute right-3 top-1/2 -translate-y-1/2 h-5 w-5 text-gray-400" />
                <input type="text" name="search" placeholder="ابحث عن اسم العميل..." value="{{ request('search') }}" class="w-full rounded-xl border-gray-200 pr-10 focus:border-blue-500 focus:ring-blue-500">
            </div>
            <div class="w-full md:w-48">
                <select name="status" class="w-full rounded-xl border-gray-200 focus:border-blue-500 focus:ring-blue-500">
                    <option value="all">جميع الحالات</option>
                    <option value="PENDING" {{ request('status') == 'PENDING' ? 'selected' : '' }}>قيد الانتظار</option>
                    <option value="CONFIRMED" {{ request('status') == 'CONFIRMED' ? 'selected' : '' }}>مؤكد</option>
                    <option value="COMPLETED" {{ request('status') == 'COMPLETED' ? 'selected' : '' }}>مكتمل</option>
                    <option value="CANCELLED" {{ request('status') == 'CANCELLED' ? 'selected' : '' }}>ملغي</option>
                </select>
            </div>
            <button type="submit" class="w-full md:w-auto inline-flex items-center justify-center rounded-xl bg-slate-800 px-6 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-slate-700 transition-all">
                <x-icon name="Filter" class="ml-2 h-4 w-4" />
                تصفية
            </button>
        </form>
    </div>

    <div class="overflow-hidden rounded-2xl bg-white shadow-sm border border-slate-100">
        <div class="overflow-x-auto">
            <table class="min-w-full divide-y divide-gray-200">
                <thead class="bg-gray-50/50">
                    <tr>
                        <th class="px-6 py-4 text-right text-xs font-bold text-gray-500 uppercase tracking-wider">العميل</th>
                        <th class="px-6 py-4 text-right text-xs font-bold text-gray-500 uppercase tracking-wider">المركبة</th>
                        <th class="px-6 py-4 text-right text-xs font-bold text-gray-500 uppercase tracking-wider">الموعد</th>
                        <th class="px-6 py-4 text-right text-xs font-bold text-gray-500 uppercase tracking-wider">الحالة</th>
                        <th class="px-6 py-4 text-left text-xs font-bold text-gray-500 uppercase tracking-wider">إجراءات</th>
                    </tr>
                </thead>
                <tbody class="bg-white divide-y divide-gray-200">
                    @forelse($bookings as $booking)
                        <tr class="hover:bg-slate-50/50 transition-colors">
                            <td class="px-6 py-4 whitespace-nowrap">
                                <div class="flex items-center gap-3">
                                    <div class="h-10 w-10 rounded-full bg-blue-50 flex items-center justify-center text-blue-600">
                                        <span class="font-bold text-sm">{{ substr($booking->customer->name ?? 'G', 0, 1) }}</span>
                                    </div>
                                    <div>
                                        <div class="text-sm font-bold text-slate-900">{{ $booking->customer->name ?? 'زائر' }}</div>
                                        <div class="text-xs text-slate-500">{{ $booking->customer->email ?? '' }}</div>
                                    </div>
                                </div>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <div class="flex items-center gap-2">
                                    <div class="h-8 w-8 rounded-lg bg-slate-100 flex items-center justify-center">
                                        <x-icon name="Truck" class="h-4 w-4 text-slate-600" />
                                    </div>
                                    <div>
                                        <div class="text-sm font-bold text-slate-900">{{ $booking->vehicle->make }} {{ $booking->vehicle->model }}</div>
                                        <div class="text-xs text-slate-500">{{ $booking->vehicle->year }}</div>
                                    </div>
                                </div>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <div class="flex items-center gap-2 text-sm text-slate-700">
                                    <x-icon name="Calendar" class="h-4 w-4 text-slate-400" />
                                    <span>{{ $booking->date->format('Y-m-d') }}</span>
                                </div>
                                <div class="flex items-center gap-2 text-xs text-slate-500 mt-1">
                                    <x-icon name="Clock" class="h-3 w-3" />
                                    <span>{{ $booking->time_slot }}</span>
                                </div>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <span class="px-3 py-1 inline-flex text-xs leading-5 font-bold rounded-full 
                                    {{ $booking->status === 'CONFIRMED' ? 'bg-emerald-100 text-emerald-700' : 
                                       ($booking->status === 'PENDING' ? 'bg-amber-100 text-amber-700' : 
                                       ($booking->status === 'COMPLETED' ? 'bg-blue-100 text-blue-700' : 'bg-red-100 text-red-700')) }}">
                                    {{ $booking->status === 'CONFIRMED' ? 'مؤكد' : 
                                       ($booking->status === 'PENDING' ? 'قيد الانتظار' : 
                                       ($booking->status === 'COMPLETED' ? 'مكتمل' : 'ملغي')) }}
                                </span>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-left text-sm font-medium">
                                <div class="flex items-center gap-2 justify-end">
                                    <a href="{{ route('admin.bookings.show', $booking->id) }}" class="p-2 bg-slate-100 text-slate-600 rounded-lg hover:bg-slate-200 transition-colors" title="التفاصيل">
                                        <x-icon name="Eye" class="h-4 w-4" />
                                    </a>
                                    <form action="{{ route('admin.bookings.destroy', $booking->id) }}" method="POST" class="inline-block" onsubmit="return confirm('هل أنت متأكد من حذف الحجز؟');">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="p-2 bg-red-50 text-red-600 rounded-lg hover:bg-red-100 transition-colors" title="حذف">
                                            <x-icon name="Trash2" class="h-4 w-4" />
                                        </button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="5" class="px-6 py-12 text-center text-slate-500">
                                <div class="flex flex-col items-center justify-center">
                                    <div class="h-16 w-16 bg-slate-50 rounded-full flex items-center justify-center mb-4">
                                        <x-icon name="Car" class="h-8 w-8 text-slate-300" />
                                    </div>
                                    <p class="text-lg font-medium">لا توجد حجوزات تجربة قيادة</p>
                                    <p class="text-sm">لم يتم العثور على أي حجوزات تطابق بحثك.</p>
                                </div>
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        <div class="border-t border-gray-100 bg-gray-50/50 p-4">
            {{ $bookings->appends(['type' => 'test_drive'])->links() }}
        </div>
    </div>
</x-admin-layout>
