

<?php $__env->startSection('title', 'Katalog Sembako'); ?>

<?php $__env->startSection('content'); ?>
<div class="space-y-6">

    <div class="bg-gradient-to-r from-blue-600 to-indigo-700 rounded-2xl p-8 text-white shadow-md flex flex-col md:flex-row justify-between items-center gap-4">
        <div>
            <h1 class="text-3xl font-extrabold tracking-tight">Belanja Sembako Hemat & Mudah</h1>
            <p class="text-blue-100 mt-2 max-w-xl">
                Selamat datang kembali, <span class="font-bold text-yellow-300"><?php echo e(session('pelanggan_nama', 'Member')); ?></span>! Kumpulkan terus poin loyalitas di setiap transaksi belanja Anda.
            </p>
        </div>
        <div class="hidden lg:block bg-white/10 px-6 py-4 rounded-xl backdrop-blur-sm text-center">
            <span class="block text-2xl font-black text-yellow-300">
                ⭐ <?php echo e(\App\Models\Pelanggan::find(session('pelanggan_id'))->poin_loyalitas ?? 0); ?> Poin
            </span>
            <span class="text-xs text-blue-200 font-medium">Sistem Reward Aktif</span>
        </div>
    </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 class="text-base">✨</span>
        <p><?php echo e(session('success')); ?></p>
    </div>
    <?php endif; ?>

    <div class="space-y-2">
        <label class="text-xs font-black text-gray-400 uppercase tracking-wider block">Filter Komoditas</label>
        <div class="flex flex-wrap gap-2 text-xs font-bold">
            <a href="<?php echo e(route('katalog', ['kategori' => 'semua'])); ?>"
                class="px-4 py-2.5 rounded-xl border transition flex items-center gap-1.5 <?php echo e($kategoriTerpilih == 'semua' ? 'bg-slate-950 text-white border-slate-950 shadow-sm' : 'bg-white text-gray-600 border-gray-200 hover:bg-gray-50'); ?>">
                Semua Sembako
            </a>

            <?php $__currentLoopData = $daftarKategori; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $kat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <a href="<?php echo e(route('katalog', ['kategori' => $kat])); ?>"
                class="px-4 py-2.5 rounded-xl border transition uppercase tracking-wide <?php echo e($kategoriTerpilih == $kat ? 'bg-blue-600 text-white border-blue-600 shadow-sm' : 'bg-white text-gray-600 border-gray-200 hover:bg-gray-50'); ?>">
                <?php echo e($kat); ?>

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

    <div class="border-b border-gray-200 pb-2 pt-2 flex justify-between items-center">
        <h2 class="text-xl font-black text-gray-900 tracking-tight">
            <?php if($kategoriTerpilih && $kategoriTerpilih !== 'semua'): ?>
            Menampilkan Kategori: <span class="text-blue-600 uppercase">"<?php echo e($kategoriTerpilih); ?>"</span>
            <?php else: ?>
            Semua Daftar Komoditas Sembako
            <?php endif; ?>
        </h2>
        <span class="text-xs font-bold text-gray-400 bg-gray-100 px-2.5 py-1 rounded-full">Total: <?php echo e($barangs->count()); ?> Produk</span>
    </div>

    <div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
        <?php $__empty_1 = true; $__currentLoopData = $barangs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $barang): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
        <div class="bg-white border border-gray-200 rounded-xl overflow-hidden shadow-sm hover:shadow-md transition flex flex-col justify-between relative">

            <div class="h-48 bg-gray-100 flex items-center justify-center border-b border-gray-100 relative overflow-hidden">

                <a href="<?php echo e(route('katalog.detail', $barang->id)); ?>" class="block w-full h-full">
                    <img src="<?php echo e(!empty($barang->foto) && file_exists(public_path('images/' . $barang->foto)) ? asset('images/' . $barang->foto) : 'https://placehold.co/400x300?text=Produk+Sembako'); ?>"
                        alt="<?php echo e($barang->nama_barang); ?>"
                        class="w-full h-full object-cover hover:scale-105 transition duration-300">
                </a>

                <span class="absolute top-3 right-3 bg-emerald-100 text-emerald-800 text-[10px] font-black px-2 py-1 rounded-md uppercase shadow-sm">
                    Stok: <?php echo e($barang->stok); ?>

                </span>

                <?php if($barang->kategori): ?>
                <span class="absolute top-3 left-3 bg-slate-900/80 backdrop-blur-sm text-white text-[9px] font-bold px-2 py-0.5 rounded uppercase tracking-wider shadow-sm">
                    <?php echo e($barang->kategori); ?>

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

            <div class="p-5 flex-grow flex flex-col justify-between">
                <div class="space-y-2">
                    <h3 class="font-bold text-gray-800 text-base line-clamp-2 min-h-[3rem] hover:text-blue-600 transition">
                        <a href="<?php echo e(route('katalog.detail', $barang->id)); ?>">
                            <?php echo e($barang->nama_barang); ?>

                        </a>
                    </h3>
                    <p class="text-xl font-black text-blue-600">
                        Rp <?php echo e(number_format($barang->harga, 0, ',', '.')); ?>

                    </p>
                </div>

                <div class="mt-5 space-y-2">
                    <?php if($barang->stok > 0): ?>

                    <form action="<?php echo e(route('keranjang.tambah')); ?>" method="POST">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="barang_id" value="<?php echo e($barang->id); ?>">
                        <input type="hidden" name="aksi" value="langsung">
                        <button type="submit" class="w-full bg-blue-600 text-white text-xs py-2.5 rounded-lg hover:bg-blue-700 transition font-bold shadow-sm flex items-center justify-center space-x-1">
                            <span>Beli Langsung</span>
                        </button>
                    </form>

                    <form action="<?php echo e(route('keranjang.tambah')); ?>" method="POST">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="barang_id" value="<?php echo e($barang->id); ?>">
                        <button type="submit" class="w-full bg-slate-100 text-slate-800 text-xs py-2.5 rounded-lg hover:bg-slate-200 transition font-bold border border-slate-300 flex items-center justify-center space-x-1">
                            <span>🛒 Tambah ke Keranjang</span>
                        </button>
                    </form>

                    <?php else: ?>
                    <button disabled class="w-full bg-gray-200 text-gray-400 text-xs py-2.5 rounded-lg font-semibold cursor-not-allowed flex items-center justify-center">
                        <span>Stok Habis</span>
                    </button>
                    <?php endif; ?>
                </div>
            </div>

        </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
        <div class="col-span-full bg-white border border-dashed border-gray-300 rounded-2xl py-16 text-center text-xs font-bold text-gray-400">
            Maaf, saat ini produk untuk kategori ini belum tersedia di gudang Mega Mart.
        </div>
        <?php endif; ?>
    </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/katalog.blade.php ENDPATH**/ ?>