

<?php $__env->startSection('title', 'Keranjang & Form Alamat'); ?>

<?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">Checkout Pemesanan Sembako</h2>
    </div>

    <?php if(session('success')): ?>
    <div class="bg-emerald-50 text-emerald-800 text-xs p-3 rounded-xl font-semibold border border-emerald-200">
        🎉 <?php echo e(session('success')); ?>

    </div>
    <?php endif; ?>

    <?php if($errorKupon): ?>
    <div class="bg-red-50 text-red-800 text-xs p-3 rounded-xl font-semibold border border-red-200">
        ⚠️ <?php echo e($errorKupon); ?>

    </div>
    <?php endif; ?>

    <?php if(count($keranjang) > 0): ?>
    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">

        <div class="lg:col-span-2 space-y-6">

            <div class="bg-white border border-gray-200 rounded-xl p-4 space-y-4 shadow-sm">
                <h3 class="font-bold text-sm text-gray-800 border-b border-gray-100 pb-2">Rincian Komoditas</h3>
                <?php $__currentLoopData = $keranjang; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $id => $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <div class="flex justify-between items-center py-2 border-b border-gray-50 last:border-0">
                    <div>
                        <h4 class="font-bold text-gray-800 text-sm"><?php echo e($item['nama_barang']); ?></h4>
                        <p class="text-xs text-gray-500">Rp <?php echo e(number_format($item['harga'], 0, ',', '.')); ?></p>
                    </div>

                    <div class="flex items-center space-x-3">
                        <form action="<?php echo e(route('keranjang.kurangi', $id)); ?>" method="POST">
                            <?php echo csrf_field(); ?>
                            <button type="submit" class="w-6 h-6 rounded bg-gray-100 text-gray-600 hover:bg-gray-200 font-bold text-xs">-</button>
                        </form>

                        <span class="text-sm font-bold text-gray-900"><?php echo e($item['qty']); ?></span>

                        <form action="<?php echo e(route('keranjang.tambah')); ?>" method="POST">
                            <?php echo csrf_field(); ?>
                            <input type="hidden" name="barang_id" value="<?php echo e($id); ?>">
                            <button type="submit" class="w-6 h-6 rounded bg-gray-100 text-gray-600 hover:bg-gray-200 font-bold text-xs">+</button>
                        </form>
                    </div>
                </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>

            <div class="bg-white border border-gray-200 rounded-xl p-4 shadow-sm space-y-3">
                <h3 class="font-bold text-sm text-gray-800 border-b border-gray-100 pb-2">Destinasi Pengiriman</h3>
                <div>
                    <label class="block text-xs font-bold text-gray-400 uppercase mb-1">Alamat Terdaftar Saat Ini</label>
                    <p class="text-xs text-gray-600 bg-gray-50 p-2.5 rounded border border-gray-200 font-medium"><?php echo e($pelanggan->alamat); ?></p>
                </div>
            </div>

        </div>

        <div class="space-y-4">
            <div class="bg-white border border-gray-200 rounded-xl p-4 shadow-sm space-y-4">
                <h3 class="font-bold text-sm text-gray-800 border-b border-gray-100 pb-2">Ringkasan Harga</h3>
                <div class="space-y-2 text-xs text-gray-600">
                    <div class="flex justify-between">
                        <span>Subtotal Barang:</span>
                        <span>Rp <?php echo e(number_format($subtotal, 0, ',', '.')); ?></span>
                    </div>
                    <div class="flex justify-between text-emerald-600 font-bold">
                        <span>Potongan Kupon:</span>
                        <span>- Rp <?php echo e(number_format($potonganHarga, 0, ',', '.')); ?></span>
                    </div>
                    <div class="border-t border-gray-100 pt-3 flex justify-between font-black text-sm text-gray-900">
                        <span>Total Wajib Bayar:</span>
                        <span class="text-blue-600 text-base">Rp <?php echo e(number_format($totalBayar, 0, ',', '.')); ?></span>
                    </div>
                </div>

                <form action="<?php echo e(route('keranjang.index')); ?>" method="GET" class="pt-2 border-t border-gray-100 flex gap-2">
                    <input type="text" name="kode_kupon" value="<?php echo e($kodeKupon); ?>" placeholder="KODE VOUCHER" class="flex-1 px-3 py-2 border border-gray-300 rounded-lg outline-none text-xs font-mono uppercase focus:ring-1 focus:ring-blue-500 font-bold">
                    <button type="submit" class="bg-slate-900 text-white px-3 py-2 rounded-lg text-xs font-bold hover:bg-slate-800 transition">Klaim</button>
                </form>

                <form action="<?php echo e(route('keranjang.checkout_final')); ?>" method="POST" class="pt-4 border-t border-gray-100 space-y-3">
                    <?php echo csrf_field(); ?>
                    <input type="hidden" name="promo_id" value="<?php echo e($promoId); ?>">
                    <input type="hidden" name="total_bayar" value="<?php echo e($totalBayar); ?>">

                    <div>
                        <label class="block text-[10px] font-bold text-gray-500 uppercase mb-1">Ubah Alamat Pengiriman Baru (Opsional)</label>
                        <textarea name="alamat_baru" rows="2" placeholder="Tulis disini jika ingin diantar ke alamat rumah alternatif..." class="w-full px-3 py-2 border border-gray-300 rounded-lg outline-none text-xs focus:ring-1 focus:ring-blue-500 font-medium resize-none"></textarea>
                    </div>

                    <button type="submit" class="w-full bg-blue-600 text-white text-xs py-3 rounded-lg font-bold hover:bg-blue-700 transition shadow-sm uppercase tracking-wider text-center block">
                        🚀 Selesaikan Pembelian Sembako
                    </button>
                </form>
            </div>
        </div>

    </div>
    <?php else: ?>
    <div class="bg-white border border-gray-200 rounded-xl py-12 text-center shadow-sm">
        <span class="text-4xl block mb-2">🛒</span>
        <p class="text-gray-400 text-xs font-bold">Keranjang Anda kosong.</p>
    </div>
    <?php endif; ?>
</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/keranjang.blade.php ENDPATH**/ ?>