<?php
require_once __DIR__ . '/includes/auth.php';
$pageTitle = 'Dashboard';

$counts = [];
foreach (['projects','categories','subcategories','products','keywords','keyword_categories'] as $t) {
    $counts[$t] = $conn->query("SELECT COUNT(*) c FROM $t")->fetch_assoc()['c'];
}

include __DIR__ . '/includes/header.php';
?>
<h2 class="mb-4">Dashboard</h2>
<div class="row g-3">
  <?php
  $cards = [
    ['Projects','projects','bi-folder-fill','primary'],
    ['Categories','categories','bi-tags-fill','success'],
    ['Subcategories','subcategories','bi-tag','info'],
    ['Products','products','bi-box-seam-fill','warning'],
    ['Keyword Categories','keyword_categories','bi-bookmark-fill','secondary'],
    ['Keywords','keywords','bi-key-fill','danger'],
  ];
  foreach ($cards as [$lbl,$tbl,$icon,$color]): ?>
  <div class="col-md-4 col-lg-2">
    <a href="<?= BASE_URL ?>/<?= $tbl ?>/index.php" class="text-decoration-none">
      <div class="card text-bg-<?= $color ?>">
        <div class="card-body text-center">
          <i class="bi <?= $icon ?>" style="font-size:2rem;"></i>
          <h3><?= $counts[$tbl] ?></h3>
          <p class="mb-0 small"><?= $lbl ?></p>
        </div>
      </div>
    </a>
  </div>
  <?php endforeach; ?>
</div>
<?php include __DIR__ . '/includes/footer.php'; ?>
