<?php $__env->startSection('title', 'Dalam Pengiriman'); ?>
<?php $__env->startSection('page-title', 'Dalam Pengiriman'); ?>

<?php $__env->startSection('content'); ?>


<?php if(session('success')): ?>
    <div class="mb-4 px-4 py-3 rounded-lg bg-green-100 text-green-700 flex items-center gap-2">
        <i class="bi bi-check-circle-fill"></i> <?php echo e(session('success')); ?>

    </div>
<?php endif; ?>

<?php if(session('error')): ?>
    <div class="mb-4 px-4 py-3 rounded-lg bg-red-100 text-red-700 flex items-center gap-2">
        <i class="bi bi-exclamation-triangle-fill"></i> <?php echo e(session('error')); ?>

    </div>
<?php endif; ?>

<!-- HEADER -->
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4 mb-6">

    <div>
        <h2 class="text-xl font-bold text-gray-800">Dalam Pengiriman</h2>
        <p class="text-sm text-gray-500">Pesanan yang sedang Anda antar</p>
    </div>

    <!-- SEARCH -->
    <form method="GET" class="flex gap-2">
        <input 
            type="text" 
            name="search" 
            value="<?php echo e(request('search')); ?>"
            placeholder="Cari ID, nama, kota..."
            class="px-4 py-2 border rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none"
        >
        <button class="px-4 py-2 bg-blue-500 text-white rounded-lg text-sm hover:bg-blue-600">
            <i class="bi bi-search"></i>
        </button>
    </form>

</div>

<!-- TABLE -->
<div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">

    <?php if($pesanans->isEmpty()): ?>

        <div class="p-10 text-center text-gray-500">
            <i class="bi bi-truck text-3xl mb-2 block"></i>
            Tidak ada pesanan yang sedang dikirim
        </div>

    <?php else: ?>

    <div class="overflow-x-auto">
        <table class="w-full text-sm">

            <thead class="bg-gray-50 text-gray-500 uppercase text-xs">
                <tr>
                    <th class="px-6 py-3 text-left">ID</th>
                    <th class="px-6 py-3 text-left">Pelanggan</th>
                    <th class="px-6 py-3 text-left">Tujuan</th>
                    <th class="px-6 py-3 text-left">Diambil</th>
                    <th class="px-6 py-3 text-left">Total</th>
                    <th class="px-6 py-3 text-left">Aksi</th>
                </tr>
            </thead>

            <tbody class="divide-y">

                <?php $__currentLoopData = $pesanans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr class="hover:bg-gray-50">

                    <!-- ID -->
                    <td class="px-6 py-4 font-semibold text-blue-600">
                        #<?php echo e($p->id); ?>

                    </td>

                    <!-- USER -->
                    <td class="px-6 py-4">
                        <div class="font-medium text-gray-800">
                            <?php echo e($p->user->name ?? '-'); ?>

                        </div>
                        <div class="text-xs text-gray-500">
                            <?php echo e($p->user->email ?? ''); ?>

                        </div>
                    </td>

                    <!-- TUJUAN -->
                    <td class="px-6 py-4">
                        <div class="font-medium text-gray-800">
                            <?php echo e($p->alamat_tujuan ?? '-'); ?>

                        </div>
                        <div class="text-xs text-gray-500">
                            <?php echo e($p->kota ?? '-'); ?>

                        </div>
                    </td>

                    <!-- WAKTU -->
                    <td class="px-6 py-4">
                        <span class="text-xs bg-blue-100 text-blue-600 px-2 py-1 rounded-full">
                            <?php echo e($p->updated_at->diffForHumans()); ?>

                        </span>
                    </td>

                    <!-- TOTAL -->
                    <td class="px-6 py-4 font-medium">
                        Rp <?php echo e(number_format($p->total_harga, 0, ',', '.')); ?>

                    </td>

                    <!-- AKSI -->
                    <td class="px-6 py-4 flex gap-2 flex-wrap">

                        <!-- BUTTON SELESAI -->
                        <button onclick="openModal(<?php echo e($p->id); ?>)"
                            class="px-3 py-1.5 text-xs bg-green-500 text-white rounded-md hover:bg-green-600">
                            <i class="bi bi-check-lg"></i> Selesai
                        </button>

                        <!-- FORM MASALAH -->
                        <form method="POST" action="<?php echo e(route('ekspedisi.masalah', $p->id)); ?>">
                            <?php echo csrf_field(); ?>
                            <button 
                                onclick="return confirm('Tandai sebagai bermasalah?')"
                                class="px-3 py-1.5 text-xs bg-red-500 text-white rounded-md hover:bg-red-600">
                                <i class="bi bi-exclamation-lg"></i> Masalah
                            </button>
                        </form>

                    </td>

                </tr>

                <!-- MODAL -->
                <div id="modal-<?php echo e($p->id); ?>" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
                    <div class="bg-white rounded-xl w-full max-w-md p-6">

                        <h3 class="text-lg font-semibold mb-4">
                            Selesaikan Pesanan #<?php echo e($p->id); ?>

                        </h3>

                        <form method="POST" action="<?php echo e(route('ekspedisi.selesai', $p->id)); ?>" enctype="multipart/form-data">
                            <?php echo csrf_field(); ?>

                            <label class="block text-sm mb-2">Upload Bukti</label>
                            <input type="file" name="foto_bukti_pengiriman" required
                                class="w-full border rounded-lg p-2 mb-4 text-sm">

                            <div class="flex justify-end gap-2">
                                <button type="button" onclick="closeModal(<?php echo e($p->id); ?>)"
                                    class="px-4 py-2 text-sm border rounded-lg">
                                    Batal
                                </button>

                                <button class="px-4 py-2 text-sm bg-green-500 text-white rounded-lg hover:bg-green-600">
                                    Kirim
                                </button>
                            </div>

                        </form>

                    </div>
                </div>

                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

            </tbody>
        </table>
    </div>

    <!-- PAGINATION -->
    <?php if($pesanans->hasPages()): ?>
        <div class="p-4 border-t">
            <?php echo e($pesanans->links()); ?>

        </div>
    <?php endif; ?>

    <?php endif; ?>

</div>

<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
    function openModal(id) {
        document.getElementById('modal-' + id).classList.remove('hidden');
        document.getElementById('modal-' + id).classList.add('flex');
    }

    function closeModal(id) {
        document.getElementById('modal-' + id).classList.add('hidden');
        document.getElementById('modal-' + id).classList.remove('flex');
    }
</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.ekspedisi', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\Toko-miftah\resources\views/ekspedisi/dalam_pengiriman.blade.php ENDPATH**/ ?>