<?php use App\Core\View; ?>
<header class="page-head">
  <h1>Dashboard</h1>
  <p>Welcome back, <?= View::e($user['name']) ?>.</p>
</header>

<div class="stat-grid">
  <?php
  $tiles = [
      'treatments'     => ['Treatments', '/admin/treatments'],
      'packages'       => ['Packages', '/admin/packages'],
      'gallery_images' => ['Gallery Images', '/admin/gallery_images'],
      'testimonials'   => ['Testimonials', '/admin/testimonials'],
      'team_members'   => ['Team Members', '/admin/team_members'],
      'blogs'          => ['Blog Posts', '/admin/blogs'],
      'faqs'           => ['FAQs', '/admin/faqs'],
      'contacts'       => ['Enquiries', '/admin/contacts'],
  ];
  foreach ($tiles as $key => [$label, $href]): ?>
  <a class="stat" href="<?= $href ?>">
    <strong><?= (int) $counts[$key] ?></strong>
    <span><?= $label ?></span>
  </a>
  <?php endforeach; ?>
</div>

<div class="panel-grid">
  <section class="panel">
    <h2>Recent Enquiries</h2>
    <?php if (!$contacts): ?><p class="empty">No enquiries yet.</p><?php endif; ?>
    <ul class="mini-list">
      <?php foreach ($contacts as $c): ?>
      <li>
        <strong><?= View::e($c['name']) ?></strong>
        <span><?= View::e(mb_substr($c['message'], 0, 70)) ?>…</span>
        <em><?= View::e($c['created_at']) ?></em>
      </li>
      <?php endforeach; ?>
    </ul>
  </section>

  <section class="panel">
    <h2>Latest Blog Posts</h2>
    <ul class="mini-list">
      <?php foreach ($posts as $p): ?>
      <li>
        <strong><a href="/admin/blogs/<?= (int) $p['id'] ?>/edit"><?= View::e($p['title']) ?></a></strong>
        <span class="badge <?= $p['status'] === 'published' ? 'ok' : '' ?>"><?= View::e($p['status']) ?></span>
        <em><?= View::e((string) $p['published_at']) ?></em>
      </li>
      <?php endforeach; ?>
    </ul>
  </section>

  <section class="panel">
    <h2>Recent Testimonials</h2>
    <ul class="mini-list">
      <?php foreach ($reviews as $r): ?>
      <li>
        <strong><?= View::e($r['client_name']) ?></strong>
        <span><?= str_repeat('★', (int) $r['rating']) ?></span>
        <em><?= View::e((string) $r['date']) ?></em>
      </li>
      <?php endforeach; ?>
    </ul>
  </section>

  <section class="panel">
    <h2>Recent Activity</h2>
    <ul class="mini-list">
      <?php foreach ($activity as $a): ?>
      <li>
        <strong><?= View::e($a['user_name'] ?? 'system') ?></strong>
        <span><?= View::e($a['action']) ?> · <?= View::e($a['entity']) ?><?= $a['entity_id'] ? ' #' . (int) $a['entity_id'] : '' ?></span>
        <em><?= View::e($a['created_at']) ?></em>
      </li>
      <?php endforeach; ?>
    </ul>
  </section>
</div>
