

<?php $__env->startSection('content'); ?>
<div class="space-y-6">
    <div class="flex flex-col sm:flex-row sm:items-center gap-4 border-b border-slate-200 pb-4">
        <div class="flex items-center gap-4">
            <div class="w-12 h-12 bg-orange-100 rounded-xl flex items-center justify-center text-orange-600 flex-shrink-0">
                <i data-lucide="truck" class="w-6 h-6"></i>
            </div>
            <div>
                <h1 class="text-xl md:text-2xl font-black tracking-tight text-slate-800">Manajemen Pesanan</h1>
                <p class="text-[11px] md:text-sm text-slate-500 font-medium">Atur pesanan dan tugaskan kurir.</p>
            </div>
        </div>
        <div class="flex flex-wrap items-center gap-2 sm:ml-auto">
            <span class="px-2.5 py-1 bg-yellow-50 text-yellow-700 rounded-lg text-[10px] md:text-xs font-bold border border-yellow-100 flex items-center gap-1">
                <i data-lucide="clock" class="w-3.5 h-3.5"></i>
                <?php echo e($countMenunggu); ?> <span class="hidden xs:inline">Menunggu</span>
            </span>
            <span class="px-2.5 py-1 bg-blue-50 text-blue-700 rounded-lg text-[10px] md:text-xs font-bold border border-blue-100 flex items-center gap-1">
                <i data-lucide="loader" class="w-3.5 h-3.5"></i>
                <?php echo e($countDiproses); ?> <span class="hidden xs:inline">Diproses</span>
            </span>
            <span class="px-2.5 py-1 bg-indigo-50 text-indigo-700 rounded-lg text-[10px] md:text-xs font-bold border border-indigo-100 flex items-center gap-1">
                <i data-lucide="truck" class="w-3.5 h-3.5"></i>
                <?php echo e($countDikirim); ?> <span class="hidden xs:inline">Dikirim</span>
            </span>
        </div>
    </div>

    <div class="bg-white rounded-3xl shadow-sm border border-slate-200 overflow-hidden">
        <div class="p-2 border-b border-slate-100 flex gap-2 overflow-x-auto custom-scroll scrollbar-hide">
            <a href="<?php echo e(route('admin.pesanan')); ?>" class="px-4 py-2 rounded-xl text-xs md:text-sm font-bold transition-all whitespace-nowrap <?php echo e(!request()->has('tab') ? 'bg-slate-800 text-white shadow-xl shadow-slate-200' : 'text-slate-500 hover:bg-slate-50'); ?>">Semua Pesanan</a>
            <a href="<?php echo e(route('admin.pesanan', ['tab' => 'aktif'])); ?>" class="px-4 py-2 rounded-xl text-xs md:text-sm font-bold transition-all whitespace-nowrap <?php echo e(request('tab') == 'aktif' ? 'bg-slate-800 text-white shadow-xl shadow-slate-200' : 'text-slate-500 hover:bg-slate-50'); ?>">Pesanan Aktif</a>
            <a href="<?php echo e(route('admin.pesanan', ['tab' => 'selesai'])); ?>" class="px-4 py-2 rounded-xl text-xs md:text-sm font-bold transition-all whitespace-nowrap <?php echo e(request('tab') == 'selesai' ? 'bg-slate-800 text-white shadow-xl shadow-slate-200' : 'text-slate-500 hover:bg-slate-50'); ?>">Selesai / Batal</a>
        </div>
        
        <div class="overflow-x-auto">
            <table class="w-full text-left border-collapse">
                <thead>
                    <tr class="bg-slate-50 text-slate-500 border-b border-slate-200 text-[10px] md:text-xs uppercase tracking-wider font-bold">
                        <th class="p-3 md:p-4">Tanggal</th>
                        <th class="p-3 md:p-4">Pelanggan</th>
                        <th class="p-3 md:p-4">Produk</th>
                        <th class="p-3 md:p-4">Total</th>
                        <th class="p-3 md:p-4 text-center">Status</th>
                        <th class="p-3 md:p-4">Kurir</th>
                        <th class="p-3 md:p-4 text-right">Aksi</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $pesanan; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $trx): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoopIteration(); ?><?php endif; ?>
                        <tr class="hover:bg-slate-50 transition-colors <?php echo e($trx['nama_pengirim'] === 'User' ? 'border-l-4 border-l-purple-400' : ''); ?>">
                            <td class="p-3 md:p-4 text-[11px] md:text-sm font-medium text-slate-600 whitespace-nowrap">
                                <?php echo e(\Carbon\Carbon::parse($trx['created_at'])->format('d/m/y H:i')); ?>

                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($trx['nama_pengirim'] === 'User'): ?>
                                    <br><span class="inline-flex items-center gap-0.5 px-1.5 py-0.5 bg-purple-100 text-purple-700 rounded text-[9px] font-black uppercase mt-0.5"><i data-lucide="smartphone" class="w-2.5 h-2.5"></i> User</span>
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </td>
                            <td class="p-3 md:p-4">
                                <div class="font-bold text-slate-800 text-xs md:text-sm"><?php echo e($trx['pelanggan']->name ?? 'User '.$trx['customers_id']); ?></div>
                                <div class="text-[10px] text-slate-500 truncate max-w-[120px] md:max-w-xs">
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!empty($trx['pelanggan']->address)): ?>
                                        <?php
                                            $dest = !empty($trx['pelanggan']->titik_koordinat) ? $trx['pelanggan']->titik_koordinat : $trx['pelanggan']->address;
                                        ?>
                                        <a href="https://www.google.com/maps/dir/?api=1&destination=<?php echo e(urlencode($dest)); ?>"
                                           target="_blank"
                                           class="text-blue-600 hover:text-blue-800 hover:underline inline-flex items-center gap-0.5"
                                           title="Petunjuk Arah (Navigasi)">
                                            <i data-lucide="navigation" class="w-3 h-3 shrink-0 text-slate-400"></i>
                                            <span><?php echo e($trx['pelanggan']->address); ?></span>
                                        </a>
                                    <?php else: ?>
                                        -
                                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                </div>
                                <?php
                                    $firstItem = $trx['items']->first();
                                    $ongkirData = \App\Models\Transaksi::getOngkirAndDistance($trx['pelanggan']->titik_koordinat ?? null, $trx['pelanggan']->address ?? null, $trx['customers_id'] ?? null, $firstItem->qty_beli_isi ?? 1, $firstItem->id_produk ?? null);
                                ?>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($ongkirData['distance'] !== null): ?>
                                    <span class="inline-flex items-center gap-0.5 px-1.5 py-0.5 bg-blue-50 text-blue-600 rounded text-[9px] font-bold mt-1 border border-blue-100">
                                        <i data-lucide="navigation" class="w-2 h-2"></i>
                                        <?php echo e($ongkirData['distance']); ?> km
                                    </span>
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </td>
                            <td class="p-3 md:p-4">
                                <div class="space-y-2">
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__currentLoopData = $trx['items']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoopIteration(); ?><?php endif; ?>
                                        <div class="flex items-center justify-between gap-4 border-b border-slate-100 pb-1 last:border-0 last:pb-0">
                                            <div>
                                                <div class="font-bold text-slate-800 text-[11px] md:text-xs"><?php echo e($item->produk->nama_produk ?? $item->id_produk); ?></div>
                                                <div class="text-[10px] text-slate-500 font-bold whitespace-nowrap"><?php echo e($item->qty_beli_isi); ?> Tbg</div>
                                            </div>
                                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!in_array($trx['status'], ['selesai', 'dibatalkan'])): ?>
                                                <button onclick="bukaModalEditQty('<?php echo e($item->id); ?>', '<?php echo e($item->qty_beli_isi); ?>', '<?php echo e($item->produk->nama_produk ?? 'Gas'); ?>', '<?php echo e($item->produk->stok_isi ?? 0); ?>')" class="p-1 bg-blue-50 text-blue-600 rounded-md hover:bg-blue-100 transition-colors">
                                                    <i data-lucide="edit-2" class="w-2.5 h-2.5"></i>
                                                </button>
                                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                        </div>
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
                                </div>
                            </td>
                            <td class="p-3 md:p-4">
                                <div class="font-bold text-orange-600 text-xs md:text-sm whitespace-nowrap">Rp <?php echo e(number_format($trx['total_semua'], 0, ',', '.')); ?></div>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($trx['ongkir_semua'] > 0): ?>
                                    <div class="text-[9px] text-slate-500 font-semibold mt-0.5">Ongkir: Rp <?php echo e(number_format($trx['ongkir_semua'], 0, ',', '.')); ?></div>
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <div class="text-[9px] text-slate-400 font-bold uppercase mt-0.5 flex flex-col gap-1">
                                    <span><?php echo e($trx['metode_bayar']); ?></span>
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($trx['metode_bayar'] === 'Qris'): ?>
                                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($trx['bukti_bayar']): ?>
                                            <div class="mt-1 flex items-center gap-1.5">
                                                <div onclick="bukaModalBukti('<?php echo e(route('bukti-bayar', ['filename' => basename($trx['bukti_bayar'])])); ?>')" class="w-10 h-10 rounded-lg overflow-hidden border border-slate-200 cursor-pointer hover:border-purple-400 hover:scale-105 transition-all shadow-sm flex-shrink-0">
                                                    <img src="<?php echo e(route('bukti-bayar', ['filename' => basename($trx['bukti_bayar'])])); ?>" alt="Bukti Transfer" class="w-full h-full object-cover">
                                                </div>
                                                <button type="button" onclick="bukaModalBukti('<?php echo e(route('bukti-bayar', ['filename' => basename($trx['bukti_bayar'])])); ?>')" class="text-[9px] font-bold text-purple-600 hover:text-purple-800 hover:underline flex items-center gap-0.5">
                                                    <i data-lucide="zoom-in" class="w-3 h-3"></i> Zoom
                                                </button>
                                            </div>
                                        <?php else: ?>
                                            <span class="inline-flex items-center gap-0.5 px-1.5 py-0.5 bg-red-50 text-red-600 rounded text-[9px] font-bold mt-1 border border-red-100 w-max normal-case">
                                                ⚠️ Belum Upload
                                            </span>
                                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                </div>
                            </td>
                            <td class="p-3 md:p-4 text-center">
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($trx['status'] === 'menunggu'): ?>
                                    <span class="px-1.5 py-0.5 bg-yellow-100 text-yellow-700 rounded text-[9px] md:text-[10px] font-bold uppercase">Menunggu</span>
                                <?php elseif($trx['status'] === 'diproses'): ?>
                                    <span class="px-1.5 py-0.5 bg-blue-100 text-blue-700 rounded text-[9px] md:text-[10px] font-bold uppercase">Diproses</span>
                                <?php elseif($trx['status'] === 'dikirim'): ?>
                                    <span class="px-1.5 py-0.5 bg-indigo-100 text-indigo-700 rounded text-[9px] md:text-[10px] font-bold uppercase">Dikirim</span>
                                <?php elseif($trx['status'] === 'selesai'): ?>
                                    <span class="px-1.5 py-0.5 bg-green-100 text-green-700 rounded text-[9px] md:text-[10px] font-bold uppercase">Selesai</span>
                                <?php elseif($trx['status'] === 'dibatalkan'): ?>
                                    <span class="px-1.5 py-0.5 bg-red-100 text-red-700 rounded text-[9px] md:text-[10px] font-bold uppercase">Batal</span>
                                <?php else: ?>
                                    <span class="px-1.5 py-0.5 bg-green-100 text-green-700 rounded text-[9px] md:text-[10px] font-bold uppercase pl-2">Selesai/Offline</span>
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </td>
                            <td class="p-3 md:p-4">
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(in_array($trx['status'], ['diproses', 'menunggu'])): ?>
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$trx['stok_cukup']): ?>
                                        <button type="button" onclick="bukaModalKurir('<?php echo e($trx['id']); ?>', false, '<?php echo e(addslashes($trx['pesan_stok_kurang'])); ?>')" class="text-[10px] font-bold bg-red-100 text-red-700 border-red-300 hover:bg-red-200 px-2 py-1 rounded-lg border transition-colors flex items-center justify-center whitespace-nowrap shadow-sm">
                                            <i data-lucide="alert-triangle" class="w-3 h-3 mr-1 text-red-600"></i> Stok Kurang
                                        </button>
                                        <span class="inline-flex items-center gap-0.5 px-1.5 py-0.5 bg-red-50 text-red-600 rounded text-[9px] font-extrabold mt-1 border border-red-200">
                                            ⚠️ Harap Restok
                                        </span>
                                    <?php else: ?>
                                        <button type="button" onclick="bukaModalKurir('<?php echo e($trx['id']); ?>', true, '')" class="text-[10px] font-bold bg-slate-100 text-slate-600 border-slate-200 hover:bg-slate-200 px-2 py-1 rounded-lg border transition-colors flex items-center justify-center whitespace-nowrap">
                                            <i data-lucide="plus" class="w-3 h-3 mr-1"></i> Kurir
                                        </button>
                                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <?php elseif($trx['status'] === 'selesai' && !$trx['id_kurir']): ?>
                                    <span class="text-xs font-bold text-slate-400">-</span>
                                <?php else: ?>
                                    <div class="text-[11px] md:text-sm font-bold text-slate-800 flex items-center gap-1">
                                        <i data-lucide="user" class="w-3 h-3 text-slate-400"></i>
                                        <span class="truncate max-w-[80px]"><?php echo e($trx['kurir'] ? $trx['kurir']->name : ($trx['id_kurir'] ?? '-')); ?></span>
                                    </div>
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($trx['status'] === 'dikirim'): ?>
                                        <button type="button" onclick="bukaModalKurir('<?php echo e($trx['id']); ?>', <?php echo e($trx['stok_cukup'] ? 'true' : 'false'); ?>, '<?php echo e(addslashes($trx['pesan_stok_kurang'])); ?>')" class="text-[9px] font-bold text-blue-600 hover:text-blue-800 mt-0.5 whitespace-nowrap">Edit Kurir</button>
                                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </td>
                            <td class="p-3 md:p-4 text-right">
                                <div class="flex justify-end items-center gap-2">
                                    <form action="<?php echo e(route('admin.pesanan.status', $trx['id'])); ?>" method="POST" class="m-0 p-0 inline-block">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('PUT'); ?>
                                        <select name="status" onchange="this.form.submit()" class="text-[10px] md:text-xs font-bold bg-slate-50 border border-slate-200 rounded-lg px-2 py-1 focus:outline-none focus:border-orange-400" <?php echo e(in_array($trx['status'], ['selesai', 'dibatalkan']) ? 'disabled' : ''); ?>>
                                            <option value="menunggu" <?php echo e($trx['status'] == 'menunggu' ? 'selected' : ''); ?>>Menunggu</option>
                                            <option value="diproses" <?php echo e($trx['status'] == 'diproses' ? 'selected' : ''); ?> <?php echo e(!$trx['stok_cukup'] ? 'disabled' : ''); ?>>Diproses <?php echo e(!$trx['stok_cukup'] ? '(Stok Kurang)' : ''); ?></option>
                                            <option value="dikirim" <?php echo e($trx['status'] == 'dikirim' ? 'selected' : ''); ?> <?php echo e(!$trx['stok_cukup'] ? 'disabled' : ''); ?>>Dikirim <?php echo e(!$trx['stok_cukup'] ? '(Stok Kurang)' : ''); ?></option>
                                            <option value="selesai" <?php echo e($trx['status'] == 'selesai' ? 'selected' : ''); ?>>Selesai</option>
                                            <option value="dibatalkan" <?php echo e($trx['status'] == 'dibatalkan' ? 'selected' : ''); ?>>Batal</option>
                                        </select>
                                    </form>
                                    <form action="<?php echo e(route('admin.pesanan.destroy', $trx['id'])); ?>" method="POST" class="m-0 p-0 inline-block">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('DELETE'); ?>
                                        <button type="button" onclick="confirmDeleteOrder(this)" class="p-1.5 bg-red-600 hover:bg-red-700 text-white rounded-lg transition-all shadow-sm active:scale-95 flex items-center justify-center" title="Hapus Pesanan">
                                            <i data-lucide="trash-2" class="w-3.5 h-3.5"></i>
                                        </button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
                        <tr>
                            <td colspan="7" class="p-8 text-center text-slate-500">
                                <div class="flex flex-col items-center justify-center">
                                    <i data-lucide="inbox" class="w-12 h-12 text-slate-300 mb-3"></i>
                                    <p class="font-medium text-slate-600">Tidak ada data pesanan</p>
                                </div>
                            </td>
                        </tr>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </tbody>
            </table>
        </div>
        <div class="p-4 border-t border-slate-100">
            <?php echo e($pesanan->links('pagination::tailwind')); ?>

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

<div id="modalKurir" class="fixed inset-0 bg-slate-900/50 backdrop-blur-sm z-50 flex items-center justify-center hidden opacity-0 transition-opacity duration-300">
    <div class="bg-white w-[92%] max-w-sm rounded-3xl shadow-2xl p-5 md:p-6 transform scale-95 transition-transform duration-300 ease-out mx-4">
        <div class="flex justify-between items-center mb-6">
            <div class="flex items-center gap-3">
                <div class="w-10 h-10 bg-indigo-50 text-indigo-600 rounded-xl flex items-center justify-center">
                    <i data-lucide="truck" class="w-5 h-5"></i>
                </div>
                <h3 class="font-black text-slate-800 text-lg tracking-tight">Tugaskan Kurir</h3>
            </div>
            <button type="button" onclick="tutupModalKurir()" class="text-slate-400 hover:text-slate-600 focus:outline-none">
                <i data-lucide="x" class="w-6 h-6"></i>
            </button>
        </div>
        
        <form id="formAssignKurir" action="" method="POST">
            <?php echo csrf_field(); ?>
            <?php echo method_field('PUT'); ?>
            <div class="space-y-4">
                <div>
                    <label class="block text-sm font-bold text-slate-700 mb-2">Pilih Kurir / Kurir</label>
                    <select name="kurir_id" class="w-full border-slate-200 rounded-xl px-4 py-3 bg-slate-50 font-bold focus:ring-0 focus:border-indigo-400 text-sm" required>
                        <option value="">-- Pilih Kurir --</option>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__currentLoopData = $kurirList; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $kurir): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoopIteration(); ?><?php endif; ?>
                            <option value="<?php echo e($kurir->id); ?>"><?php echo e($kurir->name); ?></option>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
                    </select>
                </div>
            </div>
            <div class="mt-8 flex gap-3">
                <button type="button" onclick="tutupModalKurir()" class="flex-1 py-2.5 px-4 bg-slate-100 text-slate-600 rounded-xl font-bold hover:bg-slate-200 transition-colors">Batal</button>
                <button type="submit" class="flex-1 py-2.5 px-4 bg-indigo-600 text-white rounded-xl font-bold border border-indigo-700 shadow-md shadow-indigo-600/20 hover:bg-indigo-700 transition-colors">Tugaskan!</button>
            </div>
        </form>
    </div>
</div>

<div id="modalEditQty" class="fixed inset-0 bg-slate-900/50 backdrop-blur-sm z-50 flex items-center justify-center hidden opacity-0 transition-opacity duration-300">
    <div class="bg-white w-[92%] max-w-sm rounded-3xl shadow-2xl p-5 md:p-6 transform scale-95 transition-transform duration-300 ease-out mx-4">
        <div class="flex justify-between items-center mb-6">
            <div class="flex items-center gap-3">
                <div class="w-10 h-10 bg-blue-50 text-blue-600 rounded-xl flex items-center justify-center">
                    <i data-lucide="edit-3" class="w-5 h-5"></i>
                </div>
                <h3 class="font-black text-slate-800 text-lg tracking-tight">Ubah Jumlah</h3>
            </div>
            <button type="button" onclick="tutupModalEditQty()" class="text-slate-400 hover:text-slate-600 focus:outline-none">
                <i data-lucide="x" class="w-6 h-6"></i>
            </button>
        </div>
        
        <form id="formEditQty" action="" method="POST">
            <?php echo csrf_field(); ?>
            <?php echo method_field('PUT'); ?>
            <div class="space-y-4">
                <div>
                    <p class="text-xs font-bold text-slate-500 uppercase mb-1">Produk</p>
                    <p id="editQtyProduk" class="font-bold text-slate-800"></p>
                </div>
                <div>
                    <label class="block text-sm font-bold text-slate-700 mb-2">Jumlah Baru (Tabung)</label>
                    <input type="number" name="qty" id="inputQtyBaru" min="1" class="w-full border-slate-200 rounded-xl px-4 py-3 bg-slate-50 font-bold focus:ring-0 focus:border-blue-400 text-sm" required>
                    <p class="text-[10px] text-slate-500 mt-1">*Stok saat ini: <span id="stokTersediaLabel" class="font-bold">0</span> tabung</p>
                </div>
            </div>
            <div class="mt-8 flex gap-3">
                <button type="button" onclick="tutupModalEditQty()" class="flex-1 py-2.5 px-4 bg-slate-100 text-slate-600 rounded-xl font-bold hover:bg-slate-200 transition-colors">Batal</button>
                <button type="submit" class="flex-1 py-2.5 px-4 bg-blue-600 text-white rounded-xl font-bold border border-blue-700 shadow-md shadow-blue-600/20 hover:bg-blue-700 transition-colors">Simpan Perubahan</button>
            </div>
        </form>
    </div>
</div>

<div id="modalBukti" class="fixed inset-0 bg-slate-900/60 backdrop-blur-sm z-50 flex items-center justify-center hidden opacity-0 transition-opacity duration-300">
    <div class="bg-white w-[92%] max-w-md rounded-3xl shadow-2xl overflow-hidden transform scale-95 transition-transform duration-300 ease-out mx-4">
        <div class="p-4 border-b border-slate-100 flex justify-between items-center bg-slate-50">
            <div class="flex items-center gap-2">
                <div class="w-8 h-8 bg-purple-50 text-purple-600 rounded-lg flex items-center justify-center">
                    <i data-lucide="image" class="w-4 h-4"></i>
                </div>
                <h3 class="font-black text-slate-800 text-sm md:text-base tracking-tight">Bukti Pembayaran QRIS</h3>
            </div>
            <button type="button" onclick="tutupModalBukti()" class="text-slate-400 hover:text-slate-600 p-1 rounded-lg hover:bg-slate-100 transition-colors">
                <i data-lucide="x" class="w-5 h-5"></i>
            </button>
        </div>
        <div class="p-5 flex justify-center bg-slate-100/50 max-h-[60vh] overflow-y-auto">
            <img id="imgBuktiPreview" src="" alt="Bukti Transfer Preview" class="max-w-full max-h-[50vh] object-contain rounded-2xl border border-slate-200 shadow-sm">
        </div>
        <div class="p-4 border-t border-slate-100 flex gap-3 bg-slate-50">
            <a id="btnDownloadBukti" href="" download class="flex-1 py-2 px-4 bg-purple-600 text-white rounded-xl text-xs font-bold text-center border border-purple-700 shadow-md shadow-purple-600/20 hover:bg-purple-700 transition-colors flex items-center justify-center gap-1.5">
                <i data-lucide="download" class="w-4 h-4"></i> Unduh Gambar
            </a>
            <button type="button" onclick="tutupModalBukti()" class="flex-1 py-2 px-4 bg-slate-200 text-slate-700 rounded-xl text-xs font-bold hover:bg-slate-300 transition-colors">
                Tutup
            </button>
        </div>
    </div>
</div>

<script>
    function bukaModalBukti(src) {
        document.getElementById('imgBuktiPreview').src = src;
        document.getElementById('btnDownloadBukti').href = src;
        
        const modal = document.getElementById('modalBukti');
        modal.classList.remove('hidden');
        setTimeout(() => {
            modal.classList.remove('opacity-0');
            modal.firstElementChild.classList.remove('scale-95');
        }, 10);
    }

    function tutupModalBukti() {
        const modal = document.getElementById('modalBukti');
        modal.classList.add('opacity-0');
        modal.firstElementChild.classList.add('scale-95');
        setTimeout(() => {
            modal.classList.add('hidden');
            document.getElementById('imgBuktiPreview').src = '';
        }, 300);
    }
    function bukaModalEditQty(id, currentQty, produkNama, stok) {
        window.currentEditQty = parseInt(currentQty);
        window.currentOriginalStok = parseInt(stok);
        
        document.getElementById('editQtyProduk').innerText = produkNama;
        document.getElementById('inputQtyBaru').value = currentQty;
        document.getElementById('stokTersediaLabel').innerText = stok;
        document.getElementById('formEditQty').action = `<?php echo e(url('admin/pesanan')); ?>/${id}/update-qty`;
        
        const modal = document.getElementById('modalEditQty');
        modal.classList.remove('hidden');
        setTimeout(() => {
            modal.classList.remove('opacity-0');
            modal.firstElementChild.classList.remove('scale-95');
        }, 10);
    }

    document.getElementById('inputQtyBaru').addEventListener('input', function() {
        const newQty = parseInt(this.value) || 0;
        const diff = newQty - window.currentEditQty;
        const warningEl = document.getElementById('qtyWarningMsg');
        
        if (diff > window.currentOriginalStok) {
            if (!warningEl) {
                const msg = document.createElement('p');
                msg.id = 'qtyWarningMsg';
                msg.className = 'text-[10px] font-bold text-red-500 mt-1';
                msg.innerText = '⚠️ Peringatan: Melebihi stok yang ada!';
                this.parentNode.appendChild(msg);
            }
        } else {
            if (warningEl) warningEl.remove();
        }
    });

    function tutupModalEditQty() {
        const modal = document.getElementById('modalEditQty');
        const warningEl = document.getElementById('qtyWarningMsg');
        if (warningEl) warningEl.remove();
        
        modal.classList.add('opacity-0');
        modal.firstElementChild.classList.add('scale-95');
        setTimeout(() => {
            modal.classList.add('hidden');
        }, 300);
    }

    function confirmDeleteOrder(button) {
        Swal.fire({
            title: 'HAPUS PESANAN?',
            text: 'Stok akan otomatis dikembalikan jika pesanan masih aktif.',
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#ef4444',
            cancelButtonColor: '#94a3b8',
            confirmButtonText: 'Ya, Hapus',
            cancelButtonText: 'Batal'
        }).then((result) => {
            if (result.isConfirmed) {
                button.closest('form').submit();
            }
        });
    }

    function bukaModalKurir(pesananId, stokCukup = true, pesanStokKurang = '') {
        if (!stokCukup) {
            Swal.fire({
                title: 'STOK TIDAK MENCUKUPI!',
                text: pesanStokKurang || 'Stok gudang tidak mencukupi pesanan pelanggan. Harap restok atau belanja lagi!',
                icon: 'error',
                confirmButtonColor: '#ef4444',
                confirmButtonText: 'Paham, Harap Restok',
                footer: '<a href="<?php echo e(route("admin.belanja")); ?>" class="text-xs font-bold text-blue-600 hover:underline">🛒 Klik di sini untuk Belanja / Restok Gas</a>'
            });
            return;
        }

        document.getElementById('modalKurir').classList.remove('hidden');
        setTimeout(() => {
            document.getElementById('modalKurir').classList.remove('opacity-0');
            document.getElementById('modalKurir').firstElementChild.classList.remove('scale-95');
        }, 10);
        
        document.getElementById('formAssignKurir').action = `<?php echo e(url('admin/pesanan')); ?>/${pesananId}/assign`;
    }
    
    function tutupModalKurir() {
        document.getElementById('modalKurir').classList.add('opacity-0');
        document.getElementById('modalKurir').firstElementChild.classList.add('scale-95');
        setTimeout(() => {
            document.getElementById('modalKurir').classList.add('hidden');
        }, 300);
    }
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin_sidebar', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\LPG\resources\views/admin/pesanan.blade.php ENDPATH**/ ?>