

<?php $__env->startSection('title','Admin - Produk'); ?>

<?php $__env->startSection('content'); ?>
    <div class="card">
        <div style="display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:12px">
            <h1 style="margin:0">Produk</h1>
            <div style="display:flex;gap:8px;flex-wrap:wrap">
                <a href="<?php echo e(route('admin.products.create')); ?>" class="btn">+ Tambah Produk</a>
                <a href="<?php echo e(route('inventory.index')); ?>" class="btn ghost">Lihat toko</a>
            </div>
        </div>

        <?php if(session('status')): ?><div class="notice"><?php echo e(session('status')); ?></div><?php endif; ?>

        <?php if($lowStockProducts->count() > 0): ?>
            <div class="alert alert-warning">
                <strong>⚠ Peringatan Stok Rendah:</strong> <?php echo e($lowStockProducts->count()); ?> produk di bawah stok minimum.
                <a href="<?php echo e(route('admin.products.index', ['status' => 'low'])); ?>" style="margin-left:8px;color:#92400e">Lihat detail →</a>
            </div>
            <div class="low-stock-list">
                <?php $__currentLoopData = $lowStockProducts->take(5); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $lp): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <span class="badge badge-low"><?php echo e($lp->name); ?> (<?php echo e($lp->total_stock); ?>/<?php echo e($lp->min_stock); ?>)</span>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php if($lowStockProducts->count() > 5): ?>
                    <span class="badge badge-low">+<?php echo e($lowStockProducts->count() - 5); ?> lainnya</span>
                <?php endif; ?>
            </div>
        <?php endif; ?>

        <form method="get" class="search-box">
            <input type="text" name="q" placeholder="Cari nama produk..." value="<?php echo e(request('q')); ?>">
            <select name="status" style="width:auto">
                <option value="">Semua Status</option>
                <option value="low" <?php if(request('status') === 'low'): echo 'selected'; endif; ?>>Stok Rendah</option>
                <option value="over" <?php if(request('status') === 'over'): echo 'selected'; endif; ?>>Stok Berlebih</option>
            </select>
            <button class="btn" type="submit">Cari</button>
        </form>

        <table>
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Nama</th>
                    <th>Kategori</th>
                    <th>Stok</th>
                    <th>Min</th>
                    <th>Max</th>
                    <th>Reorder Qty</th>
                    <th>Status</th>
                    <th>Aksi</th>
                </tr>
            </thead>
            <tbody>
            <?php $__currentLoopData = $products; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td><?php echo e($p->id); ?></td>
                    <td><?php echo e($p->name); ?></td>
                    <td><?php echo e($p->category->name ?? '-'); ?></td>
                    <td><?php echo e($p->total_stock); ?></td>
                    <td><?php echo e($p->min_stock ?? '-'); ?></td>
                    <td><?php echo e($p->max_stock ?? '-'); ?></td>
                    <td><?php echo e($p->isLowStock() ? $p->reorder_quantity : '-'); ?></td>
                    <td>
                        <?php if($p->stock_status === 'low'): ?>
                            <span class="badge badge-low"><?php echo e($p->stock_status_label); ?></span>
                        <?php elseif($p->stock_status === 'over'): ?>
                            <span class="badge badge-over"><?php echo e($p->stock_status_label); ?></span>
                        <?php else: ?>
                            <span class="badge badge-ok"><?php echo e($p->stock_status_label); ?></span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <a class="btn ghost" href="<?php echo e(route('admin.products.edit', $p->id)); ?>">Edit</a>
                        <form method="post" action="<?php echo e(route('admin.products.delete', $p->id)); ?>" style="display:inline"><?php echo csrf_field(); ?><button class="btn" onclick="return confirm('Hapus produk?')" type="submit">Hapus</button></form>
                    </td>
                </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>

        <div style="margin-top:12px"><?php echo e($products->links()); ?></div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Mini projek - Toko pakaian\toko-pakaian-stok\resources\views/admin/products/index.blade.php ENDPATH**/ ?>