<?php
require __DIR__ . '/_bootstrap.php';

$id = (int)($_GET['id'] ?? 0);
$stmt = $pdo->prepare("SELECT * FROM students WHERE id=?");
$stmt->execute([$id]);
$r = $stmt->fetch();
$docs = $pdo->prepare("SELECT * FROM student_documents WHERE student_id=? ORDER BY uploaded_at DESC");
$docs->execute([$r['id']]);
$docs = $docs->fetchAll();
if(!$r){ http_response_code(404); echo "Not found"; exit; }

include __DIR__ . '/_header.php';
?>
<div class="page-header"><h1>Student Details</h1></div>

<div class="card">
  <div class="kv">
    <div class="k">ID Number</div>        <div class="v"><?php echo htmlspecialchars($r['id_number']); ?></div>
    <div class="k">Student #</div>        <div class="v"><?php echo htmlspecialchars($r['student_number']); ?></div>
    <div class="k">Name</div>             <div class="v"><?php echo htmlspecialchars($r['first_name'].' '.$r['last_name']); ?></div>
    <div class="k">Place of Birth</div>   <div class="v"><?php echo htmlspecialchars($r['place_of_birth']); ?></div>
    <div class="k">Date of Birth</div>    <div class="v"><?php echo htmlspecialchars($r['date_of_birth']); ?></div>
    <div class="k">Nationality</div>      <div class="v"><?php echo htmlspecialchars($r['nationality']); ?></div>
    <div class="k">Email</div>            <div class="v"><?php echo htmlspecialchars($r['email']); ?></div>

<div class="k">Document / Notes</div>
<div class="v">
  <?php 
    echo !empty($r['document_text']) 
      ? htmlspecialchars($r['document_text']) 
      : '<span style="color:var(--muted)">—</span>'; 
  ?>
</div>



  <div class="actions-bar">
    <a class="btn" href="<?php echo url_for('/admin/students.php'); ?>">Back</a>
    <a class="btn btn-primary" href="<?php echo url_for('/admin/student_edit.php?id=' . $r['id']); ?>">Edit</a>
  </div>
</div>
<?php include __DIR__ . '/_footer.php'; ?>
