<?php /* stock/low.php */ ?>
<div class="d-flex justify-content-between align-items-center mb-3">
  <h5 class="fw-semibold mb-0">Low Stock Alert <span class="badge bg-danger ms-1"><?= count($products) ?></span></h5>
  <a href="<?= APP_URL ?>/stock" class="btn btn-sm btn-outline-secondary">Back to Stock</a>
</div>
<div class="card"><div class="card-body p-0"><div class="table-responsive">
  <table class="table table-hover mb-0">
    <thead><tr><th>Code</th><th>Product</th><th>Category</th><th class="text-end">Current Stock</th><th class="text-end">Reorder Level</th><th>Unit</th></tr></thead>
    <tbody>
      <?php foreach($products as $p): ?>
      <tr class="<?= $p['current_stock']<=0?'table-danger':'table-warning' ?>">
        <td><small><?= e($p['product_code']) ?></small></td>
        <td class="fw-semibold"><?= e($p['product_name']) ?></td>
        <td><small><?= e($p['category_name']??'-') ?></small></td>
        <td class="text-end fw-bold text-danger"><?= number_format($p['current_stock'],2) ?></td>
        <td class="text-end"><?= $p['reorder_level'] ?></td>
        <td><?= e($p['unit']) ?></td>
      </tr>
      <?php endforeach; ?>
      <?php if(empty($products)): ?><tr><td colspan="6" class="text-center text-success py-4"><i class="bi bi-check-circle me-2"></i>All products are well stocked</td></tr><?php endif; ?>
    </tbody>
  </table>
</div></div></div>
