

<?php $__env->startSection('title', 'Status Pesanan & Riwayat Belanja'); ?>

<?php $__env->startSection('content'); ?>
<div class="max-w-5xl mx-auto space-y-6">

    <div class="border-b border-gray-200 pb-2">
        <h2 class="text-2xl font-black text-gray-900 tracking-tight">Status Pesanan Saya</h2>
        <p class="text-xs text-gray-500 mt-0.5">Pantau status validasi pembayaran, proses logistik kurir, dan riwayat mutasi nota sembako Anda.</p>
    </div>

    <div class="flex flex-wrap gap-2 border-b border-gray-200 pb-3 text-xs font-bold">
        <a href="<?php echo e(route('lacak.paket', ['status' => 'semua'])); ?>" class="px-4 py-2 rounded-lg border <?php echo e($statusFilter == 'semua' ? 'bg-slate-900 text-white border-slate-900' : 'bg-white text-gray-600 border-gray-200 hover:bg-gray-50'); ?> transition">
            Semua
        </a>
        <a href="<?php echo e(route('lacak.paket', ['status' => 'menunggu'])); ?>" class="px-4 py-2 rounded-lg border <?php echo e($statusFilter == 'menunggu' ? 'bg-amber-500 text-white border-amber-500' : 'bg-white text-gray-600 border-gray-200 hover:bg-gray-50'); ?> transition">
            ⏳ Menunggu Validasi
        </a>
        <a href="<?php echo e(route('lacak.paket', ['status' => 'proses'])); ?>" class="px-4 py-2 rounded-lg border <?php echo e($statusFilter == 'proses' ? 'bg-blue-600 text-white border-blue-600' : 'bg-white text-gray-600 border-gray-200 hover:bg-gray-50'); ?> transition">
            🚚 Sedang Dikirim / Proses
        </a>
        <a href="<?php echo e(route('lacak.paket', ['status' => 'selesai'])); ?>" class="px-4 py-2 rounded-lg border <?php echo e($statusFilter == 'selesai' ? 'bg-emerald-600 text-white border-emerald-600' : 'bg-white text-gray-600 border-gray-200 hover:bg-gray-50'); ?> transition">
            ✅ Selesai
        </a>
        <a href="<?php echo e(route('lacak.paket', ['status' => 'ditolak'])); ?>" class="px-4 py-2 rounded-lg border <?php echo e($statusFilter == 'ditolak' ? 'bg-gray-600 text-white border-gray-600' : 'bg-white text-gray-600 border-gray-200 hover:bg-gray-50'); ?> transition">
            🚫 Dibatalkan / Ditolak
        </a>
    </div>

    <?php if(session('success')): ?>
    <div class="bg-emerald-50 border border-emerald-200 text-emerald-800 text-xs p-4 rounded-xl font-bold shadow-sm flex items-center gap-2">
        <span>✨</span>
        <p><?php echo e(session('success')); ?></p>
    </div>
    <?php endif; ?>

    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6 items-start">

        <div class="lg:col-span-2 space-y-4">
            <?php $__empty_1 = true; $__currentLoopData = $transaksis; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $trx): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <div class="bg-white border border-gray-200 rounded-xl p-5 shadow-sm space-y-3">

                <div class="flex justify-between items-center border-b border-gray-100 pb-2">
                    <div>
                        <span class="font-mono text-xs font-bold text-gray-900">#TRX-<?php echo e($trx->id); ?></span>
                        <span class="text-[10px] text-gray-400 font-medium block mt-0.5"><?php echo e($trx->created_at->format('d M Y H:i')); ?></span>
                    </div>

                    <?php if($trx->status == 'menunggu' && !$trx->bukti_transfer): ?>
                    <span class="px-2.5 py-0.5 rounded-full font-black text-[10px] uppercase tracking-wider bg-red-100 text-red-800 border border-red-200 animate-pulse">
                        🔴 Menunggu Pembayaran
                    </span>
                    <?php elseif($trx->status == 'menunggu' && $trx->bukti_transfer): ?>
                    <span class="px-2.5 py-0.5 rounded-full font-black text-[10px] uppercase tracking-wider bg-amber-100 text-amber-800 border border-amber-200">
                        ⏳ Menunggu Verifikasi
                    </span>
                    <?php else: ?>
                    <span class="px-2.5 py-0.5 rounded-full font-black text-[10px] uppercase tracking-wider
                                <?php echo e($trx->status == 'proses' || $trx->status == 'dikirim' ? 'bg-blue-100 text-blue-800 border border-blue-200' : ''); ?>

                                <?php echo e($trx->status == 'selesai' ? 'bg-emerald-100 text-emerald-800 border border-emerald-200' : ''); ?>

                                <?php echo e($trx->status == 'ditolak' ? 'bg-gray-100 text-gray-600 border border-gray-200' : ''); ?>">
                        <?php echo e($trx->status == 'dikirim' ? 'sedang dikirim' : ($trx->status == 'ditolak' ? 'dibatalkan/ditolak' : $trx->status)); ?>

                    </span>
                    <?php endif; ?>
                </div>

                <div class="divide-y divide-gray-50">
                    <?php $__currentLoopData = $trx->detailTransaksis; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $detail): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <div class="flex justify-between items-center py-2 text-xs font-medium text-gray-700">
                        <div class="flex items-center space-x-2">
                            <span>📦</span>
                            <span>
                                <?php echo e($detail->barang->nama_barang ?? 'Produk Tidak Tersedia (Telah Dihapus)'); ?>

                                <span class="text-gray-400">x<?php echo e($detail->qty); ?></span>
                            </span>
                        </div>
                        <span class="font-bold text-gray-900">Subtotal: Rp <?php echo e(number_format($detail->subtotal, 0, ',', '.')); ?></span>
                    </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>

                <div class="border-t border-gray-100 pt-3 flex flex-col sm:flex-row sm:justify-between sm:items-center gap-3">
                    <p class="text-xs text-gray-600 font-medium">Total Bayar: <span class="font-black text-blue-600 text-sm">Rp <?php echo e(number_format($trx->total_bayar, 0, ',', '.')); ?></span></p>

                    <div class="flex flex-wrap items-center gap-2">
                        <?php if($trx->status == 'menunggu'): ?>
                        <form action="<?php echo e(route('transaksi.batalkan', $trx->id)); ?>" method="POST" onsubmit="return confirm('Apakah Anda yakin ingin membatalkan pemesanan sembako ini? Stok gudang akan otomatis dikembalikan.')" class="inline">
                            <?php echo csrf_field(); ?>
                            <button type="submit" class="bg-red-50 text-red-600 hover:bg-red-100 border border-red-200 text-[11px] px-3 py-1.5 rounded-md font-bold transition flex items-center gap-1">
                                <i class="fa-solid fa-xmark"></i> Batalkan Pesanan
                            </button>
                        </form>
                        <?php endif; ?>

                        <?php if($trx->status == 'ditolak'): ?>
                        <a href="<?php echo e(route('nota.detail', $trx->id)); ?>" class="bg-slate-900 text-white text-[11px] px-4 py-1.5 rounded-md font-bold hover:bg-slate-800 transition shadow-sm flex items-center gap-1">
                            <i class="fa-solid fa-circle-info"></i> Detail Nota
                        </a>
                        <?php else: ?>
                        <a href="<?php echo e(route('nota.detail', $trx->id)); ?>" class="bg-slate-100 text-slate-700 text-[11px] px-3 py-1.5 rounded-md font-bold hover:bg-slate-200 transition border border-slate-300 flex items-center gap-1">
                            <i class="fa-solid fa-receipt"></i>
                            <?php echo e(!$trx->bukti_transfer && $trx->status == 'menunggu' ? 'Bayar Sekarang' : 'Detail Bayar'); ?>

                        </a>

                        <a href="<?php echo e(route('lacak.paket', ['lacak_id' => $trx->id, 'status' => $statusFilter])); ?>" class="bg-blue-600 text-white text-[11px] px-3 py-1.5 rounded-md font-bold hover:bg-blue-700 transition shadow-sm flex items-center gap-1">
                            <i class="fa-solid fa-truck-ramp-box"></i> Lacak Kurir
                        </a>

                        <?php if($trx->status == 'proses' || $trx->status == 'dikirim'): ?>
                        <form action="<?php echo e(route('transaksi.selesai', $trx->id)); ?>" method="POST" onsubmit="return confirm('Apakah Anda yakin sudah menerima paket komoditas sembako ini dengan aman?')" class="inline">
                            <?php echo csrf_field(); ?>
                            <button type="submit" class="bg-emerald-600 text-white text-[11px] px-3 py-1.5 rounded-md font-bold hover:bg-emerald-700 transition shadow-sm flex items-center gap-1">
                                <i class="fa-solid fa-circle-check"></i> Sembako Diterima
                            </button>
                        </form>
                        <?php endif; ?>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <div class="bg-white border border-gray-200 rounded-xl py-12 text-center shadow-sm text-xs font-medium text-gray-400">
                📭 Tidak ada data transaksi untuk kategori status ini.
            </div>
            <?php endif; ?>
        </div>

        <div class="lg:col-span-1">
            <?php if($transaksiTerpilih): ?>
            <div class="bg-white border border-gray-200 rounded-xl p-5 shadow-sm space-y-4">
                <div class="border-b border-gray-100 pb-2">
                    <p class="text-[10px] font-bold text-gray-400 uppercase">Jalur Distribusi Paket</p>
                    <h3 class="font-bold text-gray-900 text-sm">Tracking #TRX-<?php echo e($transaksiTerpilih->id); ?></h3>
                </div>

                <div class="relative border-l-2 border-blue-100 ml-2 space-y-5">
                    <?php $__empty_1 = true; $__currentLoopData = $logs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <div class="relative pl-5">
                        <span class="absolute -left-[6px] top-1 w-2.5 h-2.5 rounded-full bg-blue-600 border-2 border-white shadow-sm"></span>
                        <div class="text-xs">
                            <span class="font-bold text-gray-900 block"><?php echo e($log->status); ?></span>
                            <span class="text-[10px] text-gray-400 block"><?php echo e(date('d M H:i', strtotime($log->created_at))); ?></span>
                            <p class="text-gray-500 text-[11px] mt-0.5 bg-gray-50 p-1.5 rounded border border-gray-100 font-medium italic">
                                "<?php echo e($log->keterangan); ?>"
                            </p>
                        </div>
                    </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <div class="relative pl-5">
                        <span class="absolute -left-[6px] top-1 w-2.5 h-2.5 rounded-full bg-gray-400 border-2 border-white shadow-sm"></span>
                        <div class="text-xs">
                            <?php if($transaksiTerpilih->status == 'menunggu' && !$transaksiTerpilih->bukti_transfer): ?>
                            <span class="font-bold text-red-600 block">Menunggu Pembayaran</span>
                            <p class="text-gray-500 text-[11px] mt-0.5 italic">"Silakan lakukan transfer dan unggah bukti pembayaran agar pesanan dapat diproses oleh admin."</p>
                            <?php elseif($transaksiTerpilih->status == 'ditolak'): ?>
                            <span class="font-bold text-red-600 block">Pesanan Dibatalkan/Ditolak</span>
                            <p class="text-gray-500 text-[11px] mt-0.5 italic">"Transaksi ini telah dibatalkan atau ditolak. Silakan periksa halaman detail nota untuk informasi lebih lengkap."</p>
                            <?php else: ?>
                            <span class="font-bold text-amber-600 block">Menunggu Verifikasi Admin</span>
                            <p class="text-gray-500 text-[11px] mt-0.5 italic">"Bukti transfer sudah diunggah. Menunggu antrean pemeriksaan berkas oleh staff admin store."</p>
                            <?php endif; ?>
                        </div>
                    </div>
                    <?php endif; ?>
                </div>
            </div>
            <?php else: ?>
            <div class="bg-slate-50 border border-dashed border-gray-300 rounded-xl p-5 text-center text-xs font-medium text-gray-400">
                ℹ️ Silakan klik tombol <span class="font-bold text-blue-600">"Lacak Kurir"</span> pada salah satu nota pesanan di sebelah kiri untuk melihat histori pelacakan logistik secara terperinci di panel ini.
            </div>
            <?php endif; ?>
        </div>

    </div>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.frontend', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\JOKI\2026\della\megamart-crm\resources\views/lacak_pesanan.blade.php ENDPATH**/ ?>