<?php require __DIR__ . '/../../layouts/header.php'; $lang=current_lang(); ?>
<div class="container">
  <h4 class="mb-3"><i class="fa-solid fa-user-check me-2"></i><?= e($lang==='ar'?'الحضور':'Attendance') ?></h4>

  <div class="card border-0 shadow-sm mb-3"><div class="card-body">
    <form method="get" class="row g-2 align-items-end">
      <div class="col-md-8">
        <label class="form-label"><?= e($lang==='ar'?'اختر جلسة':'Select session') ?></label>
        <select class="form-select" name="session_id" onchange="this.form.submit()">
          <option value="0">—</option>
          <?php foreach(($sessions??[]) as $s): ?>
            <option value="<?= e((string)$s['id']) ?>" <?= ((int)$s['id']===(int)($session_id??0)?'selected':'') ?>>
              #<?= e((string)$s['id']) ?> — <?= e($lang==='ar'?(string)$s['title_ar']:(string)$s['title_en']) ?>
            </option>
          <?php endforeach; ?>
        </select>
      </div>
      <div class="col-md-4 text-muted small">
        <?= e($lang==='ar'?'رابط تسجيل الحضور (للطلاب/المشاركين):':'Check-in link:') ?>
        <?php if(!empty($session_id)): ?>
          <div><code><?= e(base_path('attendance/checkin?session_id='.(int)$session_id)) ?></code></div>
        <?php endif; ?>
      </div>
    </form>
  </div></div>

  <div class="card border-0 shadow-sm"><div class="card-body">
    <div class="table-responsive">
      <table class="table align-middle">
        <thead><tr><th>#</th><th>Email</th><th><?= e($lang==='ar'?'الاسم':'Name') ?></th><th><?= e($lang==='ar'?'وقت التسجيل':'Time') ?></th></tr></thead>
        <tbody>
          <?php foreach(($rows??[]) as $r): ?>
            <tr>
              <td><?= e((string)$r['id']) ?></td>
              <td><?= e((string)$r['email']) ?></td>
              <td><?= e(trim((string)$r['first_name'].' '.(string)$r['last_name'])) ?></td>
              <td class="text-muted"><?= e((string)$r['checked_in_at']) ?></td>
            </tr>
          <?php endforeach; ?>
          <?php if(empty($rows)): ?><tr><td colspan="4" class="text-center text-muted py-4">—</td></tr><?php endif; ?>
        </tbody>
      </table>
    </div>
  </div></div>
</div>
<?php require __DIR__ . '/../../layouts/footer.php'; ?>
