

<?php $__env->startSection('title', 'Booking Details'); ?>
<?php $__env->startSection('page-title', 'Booking Details'); ?>

<?php $__env->startSection('content'); ?>
<div class="max-w-6xl mx-auto">
    <div class="mb-6 flex justify-between items-center">
        <h3 class="text-2xl font-bold text-gray-800">CNTR NO: <?php echo e($booking->cntr_no); ?></h3>
        <div class="space-x-3">
            <a href="<?php echo e(route('bookings.edit', $booking)); ?>" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700">
                <i class="fas fa-edit mr-2"></i>Edit
            </a>
            <div class="relative inline-block">
                <button onclick="togglePrintDropdown()" class="px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700">
                    <i class="fas fa-print mr-2"></i>Print Documents
                </button>
                <div id="printDropdown" class="hidden absolute right-0 mt-2 w-56 bg-white rounded-lg shadow-xl z-10 border border-gray-200">
                    <a href="<?php echo e(route('bookings.invoice', $booking)); ?>" target="_blank" class="block px-4 py-3 text-sm text-gray-700 hover:bg-purple-50 border-b">
                        <i class="fas fa-file-invoice mr-2 text-purple-600"></i>
                        <strong>Invoice</strong>
                        <p class="text-xs text-gray-500">Professional invoice</p>
                    </a>
                    <a href="<?php echo e(route('bookings.cargo-slip', $booking)); ?>" target="_blank" class="block px-4 py-3 text-sm text-gray-700 hover:bg-purple-50 border-b">
                        <i class="fas fa-receipt mr-2 text-green-600"></i>
                        <strong>Cargo Slip (Bilti)</strong>
                        <p class="text-xs text-gray-500">بلٹی / Cargo receipt</p>
                    </a>
                    <a href="<?php echo e(route('bookings.delivery-receipt', $booking)); ?>" target="_blank" class="block px-4 py-3 text-sm text-gray-700 hover:bg-purple-50 border-b">
                        <i class="fas fa-clipboard-check mr-2 text-blue-600"></i>
                        <strong>Delivery Receipt</strong>
                        <p class="text-xs text-gray-500">Proof of delivery</p>
                    </a>
                    <a href="<?php echo e(route('bookings.pdf', $booking)); ?>" class="block px-4 py-3 text-sm text-gray-700 hover:bg-purple-50">
                        <i class="fas fa-download mr-2 text-orange-600"></i>
                        <strong>Download PDF</strong>
                        <p class="text-xs text-gray-500">Save invoice as PDF</p>
                    </a>
                </div>
            </div>
        </div>
    </div>

    <script>
    function togglePrintDropdown() {
        document.getElementById('printDropdown').classList.toggle('hidden');
    }
    
    // Close dropdown when clicking outside
    document.addEventListener('click', function(event) {
        const dropdown = document.getElementById('printDropdown');
        const button = event.target.closest('button');
        if (!button || !button.onclick || button.onclick.toString().indexOf('togglePrintDropdown') === -1) {
            if (!event.target.closest('#printDropdown')) {
                dropdown.classList.add('hidden');
            }
        }
    });
    </script>

    <div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6">
        <!-- Customer Information -->
        <div class="bg-white rounded-lg shadow-md p-6">
            <h4 class="text-lg font-semibold text-gray-800 mb-4 border-b pb-2">Customer Information</h4>
            <div class="space-y-3">
                <div>
                    <p class="text-sm text-gray-500">Name</p>
                    <p class="text-gray-800 font-medium"><?php echo e($booking->customer->name); ?></p>
                </div>
                <div>
                    <p class="text-sm text-gray-500">Email</p>
                    <p class="text-gray-800"><?php echo e($booking->customer->email); ?></p>
                </div>
                <div>
                    <p class="text-sm text-gray-500">Phone</p>
                    <p class="text-gray-800"><?php echo e($booking->customer->phone); ?></p>
                </div>
                <div>
                    <p class="text-sm text-gray-500">Address</p>
                    <p class="text-gray-800"><?php echo e($booking->customer->address); ?>, <?php echo e($booking->customer->city); ?></p>
                </div>
            </div>
        </div>

        <!-- Booking Information -->
        <div class="bg-white rounded-lg shadow-md p-6">
            <h4 class="text-lg font-semibold text-gray-800 mb-4 border-b pb-2">Booking Information</h4>
            <div class="space-y-3">
                <div>
                    <p class="text-sm text-gray-500">Status</p>
                    <span class="inline-block px-3 py-1 rounded-full text-sm font-semibold
                        <?php if($booking->status == 'Delivered'): ?> bg-green-100 text-green-800
                        <?php elseif($booking->status == 'In Transit'): ?> bg-blue-100 text-blue-800
                        <?php else: ?> bg-yellow-100 text-yellow-800
                        <?php endif; ?>">
                        <?php echo e($booking->status); ?>

                    </span>
                </div>
                <div>
                    <p class="text-sm text-gray-500">Booking Date</p>
                    <p class="text-gray-800 font-medium"><?php echo e($booking->booking_date->format('Y-m-d')); ?></p>
                </div>
                <?php if($booking->loading_date): ?>
                <div>
                    <p class="text-sm text-gray-500">Loading Date</p>
                    <p class="text-gray-800 font-medium"><?php echo e(\Carbon\Carbon::parse($booking->loading_date)->format('Y-m-d')); ?></p>
                </div>
                <?php endif; ?>
                <?php if($booking->shipping_date): ?>
                <div>
                    <p class="text-sm text-gray-500">Shipping Date</p>
                    <p class="text-gray-800 font-medium"><?php echo e(\Carbon\Carbon::parse($booking->shipping_date)->format('Y-m-d')); ?></p>
                </div>
                <?php endif; ?>
                <div>
                    <p class="text-sm text-gray-500">Pickup Date</p>
                    <p class="text-gray-800"><?php echo e($booking->pickup_date->format('Y-m-d')); ?></p>
                </div>
                <?php if($booking->delivery_date): ?>
                <div>
                    <p class="text-sm text-gray-500">Delivery Date</p>
                    <p class="text-gray-800"><?php echo e($booking->delivery_date->format('Y-m-d')); ?></p>
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <!-- Shipment Details -->
    <div class="bg-white rounded-lg shadow-md p-6 mb-6">
        <h4 class="text-lg font-semibold text-gray-800 mb-4 border-b pb-2">Shipment Details</h4>
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
            <div>
                <p class="text-sm text-gray-500">Pickup Location</p>
                <p class="text-gray-800 font-medium"><?php echo e($booking->pickup_location); ?></p>
            </div>
            <div>
                <p class="text-sm text-gray-500">Delivery Location</p>
                <p class="text-gray-800 font-medium"><?php echo e($booking->delivery_location); ?></p>
            </div>
            <div>
                <p class="text-sm text-gray-500">Weight (KG)</p>
                <p class="text-gray-800 font-medium"><?php echo e(number_format($booking->weight_kg, 2)); ?></p>
            </div>
            <?php if($booking->volume_cbm): ?>
            <div>
                <p class="text-sm text-gray-500">Volume (CBM)</p>
                <p class="text-gray-800 font-medium"><?php echo e(number_format($booking->volume_cbm, 2)); ?></p>
            </div>
            <?php endif; ?>
            <?php if($booking->carton_count): ?>
            <div>
                <p class="text-sm text-gray-500">Carton Count</p>
                <p class="text-gray-800 font-medium"><?php echo e($booking->carton_count); ?></p>
            </div>
            <?php endif; ?>
        </div>
        <div class="mt-4">
            <p class="text-sm text-gray-500">Cargo Description</p>
            <p class="text-gray-800"><?php echo e($booking->cargo_description); ?></p>
        </div>
        <?php if($booking->notes): ?>
        <div class="mt-4">
            <p class="text-sm text-gray-500">Notes</p>
            <p class="text-gray-800"><?php echo e($booking->notes); ?></p>
        </div>
        <?php endif; ?>
    </div>

    <!-- Cargo Items -->
    <?php if($booking->items && $booking->items->count() > 0): ?>
    <div class="bg-white rounded-lg shadow-md p-6 mb-6">
        <h4 class="text-lg font-semibold text-gray-800 mb-4 border-b pb-2">Cargo Items</h4>
        <div class="overflow-x-auto">
            <table class="min-w-full divide-y divide-gray-200">
                <thead>
                    <tr>
                        <th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Description</th>
                        <th class="px-6 py-3 bg-gray-50 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">Quantity</th>
                        <th class="px-6 py-3 bg-gray-50 text-center text-xs font-medium text-gray-500 uppercase tracking-wider">Unit</th>
                        <th class="px-6 py-3 bg-gray-50 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Rate</th>
                        <th class="px-6 py-3 bg-gray-50 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Amount</th>
                    </tr>
                </thead>
                <tbody class="bg-white divide-y divide-gray-200">
                    <?php $__currentLoopData = $booking->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td class="px-6 py-4 text-sm text-gray-900 font-medium"><?php echo e($item->description); ?></td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700 text-center"><?php echo e(number_format($item->quantity, 2)); ?></td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-center">
                            <span class="inline-block px-3 py-1 bg-blue-100 text-blue-800 rounded-full font-semibold">
                                <?php echo e(strtoupper($item->unit ?? 'PCS')); ?>

                            </span>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700 text-right"><?php echo e(number_format($item->rate, 2)); ?></td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 font-bold text-right"><?php echo e(\App\Helpers\CurrencyHelper::format($item->amount)); ?></td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <tr class="bg-gray-50 font-bold">
                        <td class="px-6 py-4 text-sm text-gray-900" colspan="4">TOTAL</td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 text-right">
                            <?php echo e(\App\Helpers\CurrencyHelper::format($booking->items->sum('amount'))); ?>

                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <?php endif; ?>

    <!-- Payment Details -->
    <div class="bg-white rounded-lg shadow-md p-6 mb-6">
        <h4 class="text-lg font-semibold text-gray-800 mb-4 border-b pb-2">Payment Details</h4>
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
            <div>
                <p class="text-sm text-gray-500">Total Amount</p>
                <p class="text-gray-800 font-bold text-2xl"><?php echo e(\App\Helpers\CurrencyHelper::format($booking->total_amount)); ?></p>
            </div>
            <?php if($booking->discount > 0): ?>
            <div>
                <p class="text-sm text-gray-500">Discount</p>
                <p class="text-red-600 font-bold text-2xl">- <?php echo e(\App\Helpers\CurrencyHelper::format($booking->discount)); ?></p>
            </div>
            <?php endif; ?>
            <div>
                <p class="text-sm text-gray-500">Advance Payment</p>
                <p class="text-green-600 font-bold text-2xl"><?php echo e(\App\Helpers\CurrencyHelper::format($booking->advance_payment)); ?></p>
            </div>
            <div>
                <p class="text-sm text-gray-500">Due Payment</p>
                <p class="text-red-600 font-bold text-2xl"><?php echo e(\App\Helpers\CurrencyHelper::format($booking->due_payment)); ?></p>
            </div>
            <div>
                <p class="text-sm text-gray-500">Payment Status</p>
                <span class="inline-block px-4 py-2 rounded-full text-sm font-semibold
                    <?php if($booking->payment_status == 'Paid'): ?> bg-green-100 text-green-800
                    <?php elseif($booking->payment_status == 'Partial'): ?> bg-yellow-100 text-yellow-800
                    <?php else: ?> bg-red-100 text-red-800
                    <?php endif; ?>">
                    <?php echo e($booking->payment_status); ?>

                </span>
            </div>
        </div>
    </div>

    <!-- Tracking History -->
    <div class="bg-white rounded-lg shadow-md p-6">
        <h4 class="text-lg font-semibold text-gray-800 mb-4 border-b pb-2">Tracking History</h4>
        <?php $__empty_1 = true; $__currentLoopData = $booking->tracking; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $track): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
        <div class="flex items-start mb-4 pb-4 border-b last:border-b-0">
            <div class="flex-shrink-0 w-10 h-10 bg-purple-600 rounded-full flex items-center justify-center">
                <i class="fas fa-map-marker-alt text-white"></i>
            </div>
            <div class="ml-4 flex-1">
                <div class="flex justify-between items-start">
                    <div>
                        <p class="font-semibold text-gray-800"><?php echo e($track->status); ?></p>
                        <p class="text-sm text-gray-600"><?php echo e($track->location); ?></p>
                        <?php if($track->remarks): ?>
                            <p class="text-sm text-gray-500 mt-1"><?php echo e($track->remarks); ?></p>
                        <?php endif; ?>
                    </div>
                    <span class="text-sm text-gray-500"><?php echo e($track->status_date->format('Y-m-d H:i')); ?></span>
                </div>
            </div>
        </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
        <p class="text-gray-500 text-center py-4">No tracking history available</p>
        <?php endif; ?>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\al-wasi\Downloads\cargomanagement-system\cargo-management-system\resources\views/bookings/show.blade.php ENDPATH**/ ?>