<?php
declare(strict_types=1);
require __DIR__ . '/_common.php';
ec_require_coordinator();
$PAGE_TITLE = 'Release Center';
$ACTIVE = 'release';
list($scopeSql, $scopeParams) = coord_branch_scope('b');

$await = qall($mysqli, "
  SELECT DISTINCT a.id, a.title, a.due_at
  FROM lms_assessments a
  JOIN lms_assessment_batches ab ON ab.assessment_id=a.id
  JOIN batches b ON b.id=ab.batch_id
  WHERE $scopeSql
    AND a.active=1
    AND a.due_at IS NOT NULL
    AND a.due_at < NOW()
    AND (a.release_at IS NULL OR a.release_at > NOW())
  ORDER BY a.due_at ASC
", $scopeParams, str_repeat('i', count($scopeParams)));
?>
<!doctype html><html lang="en"><head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
<title>Release Center</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
</head><body>
<div class="ec-shell">
  <?php include __DIR__ . '/partials/sidebar.php'; ?>
  <div class="ec-content">
    <?php include __DIR__ . '/partials/topbar.php'; ?>
    <div class="wrap container-fluid">
      <div class="card section-card">
        <div class="card-header bg-white d-flex justify-content-between align-items-center">
          <strong>Awaiting Release</strong>
          <a href="/elms/verification/release.php" class="btn btn-success btn-sm">Go to Release Action</a>
        </div>
        <div class="card-body p-0">
          <div class="table-responsive">
            <table class="table table-hover mb-0">
              <thead class="table-light"><tr><th>Assessment</th><th>Due</th></tr></thead>
              <tbody>
                <?php if (!$await): ?>
                  <tr><td colspan="2" class="text-center text-muted py-4">Nothing pending.</td></tr>
                <?php else: foreach($await as $r): ?>
                  <tr>
                    <td class="fw-semibold"><?php echo h($r['title']); ?></td>
                    <td><?php echo h($r['due_at']); ?></td>
                  </tr>
                <?php endforeach; endif; ?>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
</body></html>
