<?php $this->start('body'); ?>
<?php $rows = $this->data['rows']; $filters = $this->data['filters']; ?>

<div class="d-flex align-items-center justify-content-between mb-3 flex-wrap gap-2">
  <div><h5 class="mb-0 fw-semibold"><i class="fas fa-industry me-2 text-muted"></i>Suppliers</h5></div>
  <a href="<?= PROOT; ?>Suppliers/add" class="btn btn-sm btn-primary"><i class="fas fa-plus me-1"></i>Add supplier</a>
</div>

<?= flashHtml(); ?>

<form method="GET" class="card border-0 shadow-sm mb-3">
  <div class="card-body py-2 d-flex flex-wrap gap-2 align-items-end">
    <div class="flex-grow-1">
      <label class="form-label small mb-1 text-uppercase text-muted">Search</label>
      <input type="text" name="q" class="form-control form-control-sm" value="<?= htmlspecialchars($filters['q']); ?>" placeholder="name · TIN · phone">
    </div>
    <button type="submit" class="btn btn-sm btn-primary"><i class="fas fa-search"></i></button>
  </div>
</form>

<div class="card border-0 shadow-sm">
  <div class="table-responsive">
    <table class="table table-sm mb-0 align-middle">
      <thead class="table-light">
        <tr><th>Supplier no</th><th>Name</th><th>Category</th><th>TIN</th><th>Phone</th><th>City</th><th>Status</th><th class="text-end"></th></tr>
      </thead>
      <tbody>
        <?php if (empty($rows)): ?>
          <tr><td colspan="8" class="text-center text-muted py-5">No suppliers. <a href="<?= PROOT; ?>Suppliers/add">Add the first one</a>.</td></tr>
        <?php else: ?>
          <?php foreach ($rows as $r):
            $bg = ($r['status'] === 'ACTIVE') ? 'success' : 'secondary';
          ?>
            <tr>
              <td class="font-monospace small"><?= htmlspecialchars($r['vendor_no']); ?></td>
              <td class="fw-semibold"><?= htmlspecialchars($r['vendor_name']); ?></td>
              <td class="small text-muted"><?= htmlspecialchars($r['vendor_category'] ?: '—'); ?></td>
              <td class="small font-monospace"><?= htmlspecialchars($r['vendor_tin'] ?: '—'); ?></td>
              <td class="small"><?= htmlspecialchars($r['vendor_phone_1'] ?: '—'); ?></td>
              <td class="small"><?= htmlspecialchars($r['vendor_city'] ?: '—'); ?></td>
              <td><span class="badge bg-<?= $bg; ?>"><?= htmlspecialchars($r['status']); ?></span></td>
              <td class="text-end"><a href="<?= PROOT; ?>Suppliers/view/<?= (int)$r['c0d']; ?>" class="btn btn-sm btn-outline-primary"><i class="fas fa-arrow-right"></i></a></td>
            </tr>
          <?php endforeach; ?>
        <?php endif; ?>
      </tbody>
    </table>
  </div>
</div>
<?= $this->raw('pg_html'); ?>
<?php $this->end(); ?>
