<?php $pageTitle = 'Certificates'; include __DIR__ . '/../shared/header.php'; ?>

<div class="page-header">
  <div>
    <div class="page-title"><i class="bi bi-award me-2"></i>Calibration Certificates</div>
    <div class="page-subtitle"><?= count($certificates) ?> certificate(s) issued</div>
  </div>
</div>

<div class="card">
  <div class="card-body p-0">
    <div class="table-responsive">
      <table class="table table-hover mb-0">
        <thead class="table-light">
          <tr><th>Certificate No.</th><th>Company</th><th>Equipment</th><th>Laboratory</th><th>Issued By</th><th>Date Issued</th><th>Downloads</th><th>Actions</th></tr>
        </thead>
        <tbody>
        <?php foreach ($certificates as $cert): ?>
          <tr>
            <td><code class="fw-bold"><?= e($cert['cert_number']) ?></code></td>
            <td><?= e($cert['company_name']) ?></td>
            <td><?= e($cert['equipment_name']) ?></td>
            <td><small><?= e($cert['lab_name']) ?></small></td>
            <td><?= e($cert['issued_by_name']) ?></td>
            <td><?= date('d M Y', strtotime($cert['issue_date'])) ?></td>
            <td class="text-nowrap">
              <a href="<?= APP_URL ?>/index.php?page=certificates&action=download&id=<?= $cert['cert_id'] ?>&type=pdf"
                 class="btn btn-sm btn-outline-danger me-1" title="Download PDF">
                <i class="bi bi-file-earmark-pdf"></i> PDF
              </a>
              <a href="<?= APP_URL ?>/index.php?page=certificates&action=download&id=<?= $cert['cert_id'] ?>&type=xml"
                 class="btn btn-sm btn-outline-secondary" title="Download XML (DCC)">
                <i class="bi bi-file-earmark-code"></i> XML
              </a>
            </td>
            <td>
              <a href="<?= APP_URL ?>/index.php?page=certificates&action=view&id=<?= $cert['cert_id'] ?>" class="btn btn-sm btn-outline-primary">
                <i class="bi bi-eye me-1"></i>View
              </a>
            </td>
          </tr>
        <?php endforeach; ?>
        <?php if (empty($certificates)): ?>
          <tr><td colspan="8" class="text-center text-muted py-5">
            <i class="bi bi-award fs-2 d-block mb-2 text-muted"></i>No certificates issued yet.
          </td></tr>
        <?php endif; ?>
        </tbody>
      </table>
    </div>
  </div>
</div>

<?php include __DIR__ . '/../shared/footer.php'; ?>
