<?php $__env->startSection('title'); ?>
    Manage Bookings - Hotel Management System
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <!-- Breadcrumb -->
    <div class="bg-white shadow-sm border-b border-gray-200 px-6 py-4">
        <div class="flex items-center justify-between">
            <div class="flex items-center text-sm text-gray-600">
                <i class="fas fa-home mr-2"></i>
                <span>/ Manage Bookings</span>
            </div>
            <div class="flex space-x-2">
                <?php if(auth()->check() && auth()->user()->hasPermissionTo('create-bookings')): ?>
                <a href="<?php echo e(route('bookings.create')); ?>" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg transition-colors">
                    <i class="fas fa-plus mr-2"></i>New Booking
                </a>
                <?php endif; ?>

                <a href="<?php echo e(route('bookings.room-board')); ?>" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition-colors">
                    <i class="fas fa-bed mr-2"></i>Front Desk 
                </a>
            </div>
        </div>
    </div>

    <!-- Content -->
    <div class="p-6">
        <?php if(session('success')): ?>
            <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4">
                <?php echo e(session('success')); ?>

            </div>
        <?php endif; ?>

        <?php if(session('error')): ?>
            <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
                <?php echo e(session('error')); ?>

            </div>
        <?php endif; ?>

        <!-- Filters and Search -->
        <div class="bg-white rounded-lg shadow-md mb-6">
            <div class="px-6 py-4 border-b border-gray-200">
                <h2 class="text-xl font-semibold text-gray-800">Search & Filter Bookings</h2>
            </div>
            
            <div class="p-6">
                <form method="GET" action="<?php echo e(route('bookings.index')); ?>" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
                    <!-- Search -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Search</label>
                        <input type="text" 
                               name="search" 
                               value="<?php echo e(request('search')); ?>"
                               placeholder="Customer name, document, room..."
                               class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
                    </div>

                    <!-- Status Filter -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Status</label>
                        <select name="status" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
                            <option value="">All Status</option>


                            <option value="Checked In" <?php echo e(request('status') == 'Checked In' ? 'selected' : ''); ?>>Checked In</option>
                            <option value="Checked Out" <?php echo e(request('status') == 'Checked Out' ? 'selected' : ''); ?>>Checked Out</option>
                            <option value="Rejected" <?php echo e(request('status') == 'Rejected' ? 'selected' : ''); ?>>Rejected</option>
                            <option value="Cancelled" <?php echo e(request('status') == 'Cancelled' ? 'selected' : ''); ?>>Cancelled</option>
                        </select>
                    </div>

                    <!-- Date From -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">From Date</label>
                        <input type="date" 
                               name="date_from" 
                               value="<?php echo e(request('date_from')); ?>"
                               class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
                    </div>

                    <!-- Date To -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">To Date</label>
                        <input type="date" 
                               name="date_to" 
                               value="<?php echo e(request('date_to')); ?>"
                               class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
                    </div>
                </form>
            </div>
        </div>

        <!-- Bookings Table -->
        <div class="bg-white rounded-lg shadow-md">
            <div class="overflow-x-auto">
                <table class="min-w-full divide-y divide-gray-200">
                    <thead class="bg-gray-50">
                        <tr>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                Booking Info
                            </th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                Customer Details
                            </th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                Room & Dates
                            </th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                Payment
                            </th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                Status
                            </th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                Actions
                            </th>
                        </tr>
                    </thead>
                    <tbody class="bg-white divide-y divide-gray-200">
                        <?php $__empty_1 = true; $__currentLoopData = $bookings; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $booking): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr class="hover:bg-gray-50">
                                <td class="px-6 py-4 whitespace-nowrap">
                                    <div class="text-sm font-medium text-gray-900">#<?php echo e($booking->booking_id); ?></div>
                                    <div class="text-xs text-gray-500"><?php echo e($booking->created_at->format('M d, Y H:i')); ?></div>
                                    <div class="text-xs text-gray-500"><?php echo e($booking->number_of_customers); ?> customer(s)</div>
                                </td>
                                <td class="px-6 py-4">
                                    <?php if($booking->primaryCustomer): ?>
                                        <div class="text-sm font-medium text-gray-900">
                                            <?php echo e($booking->primaryCustomer->full_name); ?>

                                        </div>
                                        <div class="text-xs text-gray-500">
                                            <?php echo e($booking->primaryCustomer->document_type); ?>: <?php echo e($booking->primaryCustomer->document_number); ?>

                                        </div>
                                        <?php if($booking->number_of_customers > 1): ?>
                                            <div class="text-xs text-blue-600">
                                                +<?php echo e($booking->number_of_customers - 1); ?> more customer(s)
                                            </div>
                                        <?php endif; ?>
                                    <?php else: ?>
                                        <div class="text-sm text-gray-500">No customer data</div>
                                    <?php endif; ?>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap">
                                    <div class="text-sm font-medium text-gray-900"><?php echo e($booking->room->room_no); ?></div>
                                    <div class="text-xs text-gray-500"><?php echo e($booking->room->roomType->room_type); ?></div>
                                    <div class="text-xs text-gray-500">
                                        <?php echo e(\Carbon\Carbon::parse($booking->check_in)->format('M d')); ?> - <?php echo e(\Carbon\Carbon::parse($booking->check_out)->format('M d, Y')); ?>

                                    </div>
                                    <div class="text-xs text-gray-500"><?php echo e($booking->number_of_nights); ?> night(s)</div>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap">
                                    <div class="text-sm font-medium text-gray-900">$<?php echo e(number_format($booking->total_price, 2)); ?></div>
                                    <div class="text-xs text-gray-500">
                                        Paid: $<?php echo e(number_format($booking->advance_payment, 2)); ?>

                                    </div>
                                    <div class="text-xs text-red-600">
                                        Due: $<?php echo e(number_format($booking->due_amount, 2)); ?>

                                    </div>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap">
                                    <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium <?php echo e($booking->getStatusBadgeColor()); ?>">
                                        <?php echo e($booking->booking_status); ?>

                                    </span>
                                    <?php if($booking->payment_status): ?>
                                        <div class="mt-1">
                                            <span class="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">
                                                Paid
                                            </span>
                                        </div>
                                    <?php else: ?>
                                        <div class="mt-1">
                                            <span class="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800">
                                                Unpaid
                                            </span>
                                        </div>
                                    <?php endif; ?>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                                    <div class="flex space-x-2">
                                        <a href="<?php echo e(route('bookings.show', $booking)); ?>" 
                                           class="inline-flex items-center justify-center w-8 h-8 bg-blue-100 text-blue-600 rounded-full hover:bg-blue-200 transition-colors">
                                            <i class="fas fa-eye text-sm"></i>
                                        </a>
                                        
                                        <?php if(auth()->check() && auth()->user()->hasPermissionTo('edit-bookings')): ?>
                                            <?php if(now()->format('Y-m-d') <= $booking->check_out): ?>
                                            <a href="<?php echo e(route('bookings.edit', $booking)); ?>" 
                                               class="inline-flex items-center justify-center w-8 h-8 bg-green-100 text-green-600 rounded-full hover:bg-green-200 transition-colors">
                                                <i class="fas fa-edit text-sm"></i>
                                            </a>
                                            <?php else: ?>
                                            <span class="inline-flex items-center justify-center w-8 h-8 bg-gray-100 text-gray-400 rounded-full cursor-not-allowed" title="Cannot edit after checkout date">
                                                <i class="fas fa-edit text-sm"></i>
                                            </span>
                                            <?php endif; ?>
                                        <?php endif; ?>

                                        <?php if($booking->receipt): ?>
                                        <a href="<?php echo e(route('receipts.show', $booking->receipt)); ?>" 
                                           class="inline-flex items-center justify-center w-8 h-8 bg-purple-100 text-purple-600 rounded-full hover:bg-purple-200 transition-colors"
                                           title="View Receipt">
                                            <i class="fas fa-receipt text-sm"></i>
                                        </a>
                                        <?php endif; ?>



                                        <?php if($booking->booking_status === 'Checked In'): ?>
                                            <?php if(auth()->check() && auth()->user()->hasPermissionTo('edit-bookings')): ?>
                                            <form action="<?php echo e(route('bookings.check-out', $booking)); ?>" 
                                                  method="POST" 
                                                  class="inline"
                                                  onsubmit="return confirm('Check out this guest?')">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('PATCH'); ?>
                                                <button type="submit" class="inline-flex items-center justify-center w-8 h-8 bg-purple-100 text-purple-600 rounded-full hover:bg-purple-200 transition-colors">
                                                    <i class="fas fa-sign-out-alt text-sm"></i>
                                                </button>
                                            </form>
                                            <?php endif; ?>
                                        <?php endif; ?>
                                        
                                        <?php if(auth()->check() && auth()->user()->hasPermissionTo('delete-bookings')): ?>
                                        <form action="<?php echo e(route('bookings.destroy', $booking)); ?>" 
                                              method="POST" 
                                              class="inline"
                                              onsubmit="return confirm('Are you sure you want to delete this booking?')">
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('DELETE'); ?>
                                            <button type="submit" class="inline-flex items-center justify-center w-8 h-8 bg-red-100 text-red-600 rounded-full hover:bg-red-200 transition-colors">
                                                <i class="fas fa-trash text-sm"></i>
                                            </button>
                                        </form>
                                        <?php endif; ?>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="6" class="px-6 py-4 text-center text-gray-500">
                                    <div class="py-8">
                                        <i class="fas fa-calendar-times text-4xl text-gray-300 mb-4"></i>
                                        <p>No bookings found.</p>
                                    </div>
                                </td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
            
            <!-- Pagination -->
            <?php if($bookings->hasPages()): ?>
                <div class="px-6 py-4 border-t border-gray-200">
                    <?php echo e($bookings->links()); ?>

                </div>
            <?php endif; ?>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('backend.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\laragon\www\HotelMS\resources\views/backend/bookings/index.blade.php ENDPATH**/ ?>