<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Track Shipment - <?php echo e($shipment->tracking_number); ?></title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" rel="stylesheet"/>
    <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
</head>
<body class="min-h-screen bg-gray-100 py-12 px-4 sm:px-6 lg:px-8">
    <div class="max-w-3xl mx-auto">
        <h1 class="text-3xl font-bold text-center mb-8">Shipment Tracking</h1>

        <div class="bg-white shadow-lg rounded-lg overflow-hidden">
            <div class="p-6">
                <!-- Tracking Status -->
                <div class="flex items-center justify-between mb-6">
                    <div>
                        <h2 class="text-2xl font-semibold flex items-center">
                            <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4" />
                            </svg>
                            <?php echo e($shipment->tracking_number); ?>

                        </h2>
                        <p class="text-gray-600">Status: <?php echo e(ucfirst($shipment->status)); ?></p>
                    </div>
                    <div class="text-right">
                        <p class="text-sm text-gray-600">Estimated Delivery</p>
                        <p class="text-lg font-semibold"><?php echo e($shipment->delivery_date); ?></p>
                    </div>
                </div>

                <!-- Progress Bar -->
                <div class="mb-6">
                    <div class="relative pt-1">
                        <div class="flex mb-2 items-center justify-between">
                            <div>
                                <span class="text-xs font-semibold inline-block py-1 px-2 uppercase rounded-full text-blue-600 bg-blue-200">
                                    Shipment Progress
                                </span>
                            </div>
                            <div class="text-right">
                                <span class="text-xs font-semibold inline-block text-blue-600">
                                    <?php echo e($progress); ?>%
                                </span>
                            </div>
                        </div>
                        <div class="overflow-hidden h-2 mb-4 text-xs flex rounded bg-blue-200">
                            <div style="width:<?php echo e($progress); ?>%" class="shadow-none flex flex-col text-center whitespace-nowrap text-white justify-center bg-blue-500"></div>
                        </div>
                    </div>
                </div>

                <!-- Map -->
                <div id="map" class="w-full h-96 rounded-lg overflow-hidden mb-6"></div>

                <!-- Location Information -->
                <div class="mb-6">
                    <h3 class="text-lg font-semibold mb-2">Location Information</h3>
                    <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                        <div>
                            <p class="text-sm text-gray-600">Origin</p>
                            <p class="font-medium flex items-center">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
                                </svg>
                                <?php echo e($shipment->dispatch_location); ?>

                            </p>
                        </div>
                        <div>
                            <p class="text-sm text-gray-600">Current Location</p>
                            <p class="font-medium flex items-center">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
                                </svg>
                                <?php echo e($shipment->current_location ?? 'In Transit'); ?>

                            </p>
                        </div>
                        <div>
                            <p class="text-sm text-gray-600">Destination</p>
                            <p class="font-medium flex items-center">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
                                </svg>
                                <?php echo e($shipment->destination); ?>

                            </p>
                        </div>
                    </div>
                </div>

                <!-- Customer and Package Details -->
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                    <div>
                        <h3 class="text-lg font-semibold mb-2 flex items-center">
                            <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
                            </svg>
                            Receiver Information
                        </h3>
                        <p class="font-medium"><?php echo e($shipment->receiver_name); ?></p>
                        <p class="text-gray-600"><?php echo e($shipment->receiver_address); ?></p>
                    </div>
                    <div>
                        <h3 class="text-lg font-semibold mb-2 flex items-center">
                            <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
                            </svg>
                            Package Details
                        </h3>
                        <p><span class="font-medium">Weight:</span> <?php echo e($shipment->weight); ?></p>
                        <p><span class="font-medium">Description:</span> <?php echo e($shipment->pdesc); ?></p>
                    </div>
                </div>

                <!-- Tracking Updates -->
                <?php if($shipment->trackingUpdates->count() > 0): ?>
                <div>
                    <h3 class="text-lg font-semibold mb-2 flex items-center">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
                        </svg>
                        Tracking Updates
                    </h3>
                    <div class="space-y-4">
                        <?php $__currentLoopData = $shipment->trackingUpdates->sortByDesc('created_at'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $update): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="flex items-start">
                            <div class="bg-blue-500 rounded-full w-2 h-2 mt-2 mr-4"></div>
                            <div>
                                <p class="font-medium"><?php echo e($update->created_at->format('Y-m-d - h:i A')); ?></p>
                                <p class="text-gray-600"><?php echo e($update->description); ?></p>
                            </div>
                        </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <script>
        // Initialize the map
        var map = L.map('map').setView([0, 0], 2);
        L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
        }).addTo(map);

        // Add markers and route based on tracking updates
        var markers = [];
        var routePoints = [];
        
        // Add origin marker
        var origin = L.marker([<?php echo e($shipment->dispatch_location_lat ?? 0); ?>, <?php echo e($shipment->dispatch_location_lng ?? 0); ?>]).addTo(map);
        origin.bindPopup("Origin: <?php echo e($shipment->dispatch_location); ?>");
        markers.push(origin);

        // Add destination marker
        var destination = L.marker([<?php echo e($shipment->destination_lat ?? 0); ?>, <?php echo e($shipment->destination_lng ?? 0); ?>]).addTo(map);
        destination.bindPopup("Destination: <?php echo e($shipment->destination); ?>");
        markers.push(destination);

        // Add current location marker if available
        <?php if($shipment->current_location): ?>
        var current = L.marker([<?php echo e($shipment->current_location_lat ?? 0); ?>, <?php echo e($shipment->current_location_lng ?? 0); ?>]).addTo(map);
        current.bindPopup("Current Location: <?php echo e($shipment->current_location); ?>");
        markers.push(current);
        <?php endif; ?>

         // Create the route line
        var route = L.polyline([
            [<?php echo e($shipment->dispatch_location_lat ?? 0); ?>, <?php echo e($shipment->dispatch_location_lng ?? 0); ?>],
            <?php if($shipment->current_location_lat): ?>
            [<?php echo e($shipment->current_location_lat); ?>, <?php echo e($shipment->current_location_lng); ?>],
            <?php endif; ?>
            [<?php echo e($shipment->destination_lat ?? 0); ?>, <?php echo e($shipment->destination_lng ?? 0); ?>]
        ], {
            color: 'blue',
            weight: 3,
            opacity: 0.7,
            dashArray: '10, 10'
        }).addTo(map);

        // Create bounds for all points
        var bounds = L.latLngBounds([
            [<?php echo e($shipment->dispatch_location_lat ?? 0); ?>, <?php echo e($shipment->dispatch_location_lng ?? 0); ?>],
            <?php if($shipment->current_location_lat): ?>
            [<?php echo e($shipment->current_location_lat); ?>, <?php echo e($shipment->current_location_lng); ?>],
            <?php endif; ?>
            [<?php echo e($shipment->destination_lat ?? 0); ?>, <?php echo e($shipment->destination_lng ?? 0); ?>]
        ]);

        // Fit map to bounds with padding
        map.fitBounds(bounds, {
            padding: [50, 50]
        });
    </script>
</body>
</html><?php /**PATH /home/waccoama/expressdeliveryfreight.com/resources/views/tracking/show.blade.php ENDPATH**/ ?>