@extends('layouts.admin')

@section('title', 'Manage Bookings')

@section('content')
<div class="space-y-6">
    <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4">
        <h2 class="font-serif text-2xl text-[#0c2340]">Bookings</h2>
        
        <div class="flex gap-3 w-full sm:w-auto">
            <form method="GET" class="flex-1 sm:w-72">
                <input type="text" name="search" value="{{ request('search') }}" 
                       placeholder="Search by reference or customer..." 
                       class="w-full px-4 py-2 text-sm border border-gray-200 rounded-xl focus:ring-1 focus:ring-[#c9a84c]">
            </form>
        </div>
    </div>

    <div class="bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full text-left border-collapse">
                <thead>
                    <tr class="bg-gray-50/50 border-b border-gray-100 text-xs uppercase tracking-wider text-gray-500 font-semibold">
                        <th class="p-5">Booking Ref</th>
                        <th class="p-5">Customer</th>
                        <th class="p-5">Package</th>
                        <th class="p-5">Status</th>
                        <th class="p-5">Date</th>
                        <th class="p-5 text-right">Actions</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-100">
                    @forelse($bookings as $booking)
                        <tr class="hover:bg-gray-50/50 transition-colors">
                            <td class="p-5">
                                <div class="font-mono text-sm font-bold text-[#0c2340]">{{ $booking->booking_reference }}</div>
                                <div class="text-xs text-gray-500 mt-1">{{ $booking->total_people }} Pax</div>
                            </td>
                            <td class="p-5">
                                <div class="flex items-center gap-3">
                                    <div class="w-8 h-8 rounded-full bg-[#0c2340] text-white flex items-center justify-center font-bold text-xs shrink-0">
                                        {{ substr($booking->user->name, 0, 1) }}
                                    </div>
                                    <div>
                                        <div class="font-medium text-[#0c2340]">{{ $booking->user->name }}</div>
                                        <div class="text-xs text-gray-500">{{ $booking->user->email }}</div>
                                    </div>
                                </div>
                            </td>
                            <td class="p-5">
                                <div class="font-medium text-[#0c2340]">{{ $booking->package->title }}</div>
                                <div class="text-xs text-gray-500 font-semibold mt-1">{{ $booking->formatted_total_amount }}</div>
                            </td>
                            <td class="p-5">
                                @php
                                    $statusClasses = [
                                        'pending' => 'bg-yellow-100 text-yellow-800',
                                        'confirmed' => 'bg-green-100 text-green-800',
                                        'cancelled' => 'bg-red-100 text-red-800',
                                    ];
                                    $class = $statusClasses[$booking->status] ?? 'bg-gray-100 text-gray-800';
                                @endphp
                                <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-semibold {{ $class }}">
                                    {{ ucfirst($booking->status) }}
                                </span>
                            </td>
                            <td class="p-5">
                                <div class="text-sm text-[#0c2340]">{{ $booking->created_at->format('M d, Y') }}</div>
                                <div class="text-xs text-gray-500">{{ $booking->created_at->format('h:i A') }}</div>
                            </td>
                            <td class="p-5 text-right">
                                <a href="{{ route('admin.bookings.detail', $booking->booking_reference) }}" class="inline-flex items-center justify-center p-2 text-gray-400 hover:text-[#c9a84c] hover:bg-yellow-50 rounded-lg transition-colors" title="View Details">
                                    <i data-feather="eye" class="w-4 h-4"></i>
                                </a>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="6" class="p-8 text-center text-gray-500">
                                <div class="inline-flex items-center justify-center w-12 h-12 rounded-full bg-gray-100 mb-4">
                                    <i data-feather="calendar" class="w-6 h-6 text-gray-400"></i>
                                </div>
                                <p>No bookings found.</p>
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        @if($bookings->hasPages())
            <div class="p-5 border-t border-gray-100">
                {{ $bookings->links() }}
            </div>
        @endif
    </div>
</div>
@endsection
