<?php require __DIR__ . '/../../layouts/header.php'; $lang=current_lang(); ?>
<div class="container">
  <h4 class="mb-3"><i class="fa-solid fa-award me-2"></i><?= e($lang==='ar'?'محرك الشهادات':'Certificates Rules Engine') ?></h4>

  <div class="card border-0 shadow-sm mb-3"><div class="card-body">
    <form method="post" action="<?= e(base_path('admin/certificates-rules/generate')) ?>" class="row g-2">
      <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
      <div class="col-md-5">
        <select class="form-select" name="user_id" required>
          <option value=""><?= e($lang==='ar'?'اختر مستخدم':'Select user') ?></option>
          <?php foreach(($users??[]) as $u): ?>
            <option value="<?= e((string)$u['id']) ?>">#<?= e((string)$u['id']) ?> — <?= e((string)$u['email']) ?></option>
          <?php endforeach; ?>
        </select>
      </div>
      <div class="col-md-4">
        <select class="form-select" name="cert_type">
          <option value="attendance">attendance</option>
          <option value="reviewer">reviewer</option>
          <option value="tpc">tpc</option>
          <option value="chair">chair</option>
          <option value="demo">demo</option>
        </select>
      </div>
      <div class="col-md-3 d-grid"><button class="btn btn-primary"><?= e($lang==='ar'?'إنشاء شهادة':'Generate') ?></button></div>
    </form>
    <div class="text-muted small mt-2"><?= e($lang==='ar'?'قاعدة بسيطة الآن: attendance يتطلب check-in، reviewer يتطلب وجود مراجعة مكتملة.':'Current rules: attendance requires check-in; reviewer requires at least one review.') ?></div>
  </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>user</th><th>conf</th><th>type</th><th>file</th><th>status</th><th>date</th></tr></thead>
        <tbody>
          <?php foreach(($logs??[]) as $r): ?>
            <tr>
              <td><?= e((string)$r['id']) ?></td>
              <td><?= e((string)$r['user_id']) ?></td>
              <td><?= e((string)$r['conference_id']) ?></td>
              <td><?= e((string)$r['cert_type']) ?></td>
              <td><?php if(!empty($r['file_path'])): ?><a href="<?= e(base_path((string)$r['file_path'])) ?>" target="_blank">open</a><?php endif; ?></td>
              <td><?= e((string)$r['status']) ?></td>
              <td class="text-muted"><?= e((string)$r['created_at']) ?></td>
            </tr>
          <?php endforeach; ?>
          <?php if(empty($logs)): ?><tr><td colspan="7" class="text-center text-muted py-4">—</td></tr><?php endif; ?>
        </tbody>
      </table>
    </div>
  </div></div>
</div>
<?php require __DIR__ . '/../../layouts/footer.php'; ?>
