<?php
declare(strict_types=1);
define('APP_ROOT', dirname(__DIR__, 2));
if (session_status() === PHP_SESSION_NONE) session_start();
require_once APP_ROOT . '/includes/auth.php';
require_once APP_ROOT . '/includes/db.php';
require_role(['super_admin','branch_admin']);

$id = (int)($_GET['id'] ?? 0);
$st = $mysqli->prepare("SELECT * FROM lms_assessments WHERE id=?");
$st->bind_param('i',$id); $st->execute();
$row = $st->get_result()->fetch_assoc(); $st->close();

if (!$row) { http_response_code(404); exit('Assessment not found'); }

function esc($s){ return htmlspecialchars((string)$s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); }
?><!doctype html>
<html><head><meta charset="utf-8"><title>View Assessment</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head><body class="p-3">
  <a class="btn btn-outline-secondary btn-sm mb-3" href="../assessments/index.php">← Back</a>
  <div class="card"><div class="card-body">
    <h5 class="card-title mb-2"><?= esc($row['title']) ?></h5>
    <div class="text-uppercase small text-muted mb-3"><?= esc($row['type']) ?></div>
    <?php if(!empty($row['description'])): ?><p><?= nl2br(esc($row['description'])) ?></p><?php endif; ?>
    <dl class="row small">
      <dt class="col-sm-3">Available</dt><dd class="col-sm-9"><?= esc($row['available_from'] ?: '—') ?> → <?= esc($row['available_to'] ?: '—') ?></dd>
      <dt class="col-sm-3">Due</dt><dd class="col-sm-9"><?= esc($row['due_at'] ?: '—') ?></dd>
      <dt class="col-sm-3">Release</dt><dd class="col-sm-9"><?= esc($row['release_at'] ?: '—') ?></dd>
      <dt class="col-sm-3">Max score</dt><dd class="col-sm-9"><?= (int)$row['max_score'] ?></dd>
      <dt class="col-sm-3">Active</dt><dd class="col-sm-9"><?= $row['active']?'Yes':'No' ?></dd>
    </dl>
  </div></div>
</body></html>
