<?php
require_once __DIR__ . '/../../admin/_nav.php';
$pageTitle  = 'Enroll Student';
$sidebarNav = adminNav();
$u = function($p) { return \Core\View::url($p); };
?>
<div class="page-header">
  <div><h1>Enroll New Student</h1></div>
  <a href="<?= $u('admin/students') ?>" class="btn btn-secondary"><i class="bi bi-arrow-left"></i> Back</a>
</div>
<div class="card" style="max-width:700px">
  <div class="card-body">
    <form method="POST" action="<?= $u('admin/students/store') ?>">
      <?= \Core\View::csrf() ?>

      <!-- Student Info -->
      <div class="grid g2">
        <div class="form-group">
          <label>Full Name *</label>
          <input type="text" name="name" value="<?= \Core\View::old('name') ?>" required>
          <?php foreach(\Core\View::errors('name') as $e): ?><div class="form-error"><?= htmlspecialchars($e) ?></div><?php endforeach; ?>
        </div>

        <div class="form-group">
          <label>Assessment Number *</label>
          <input type="text" name="assessment_no" value="<?= \Core\View::old('assessment_no') ?>" required>
          <?php foreach(\Core\View::errors('assessment_no') as $e): ?><div class="form-error"><?= htmlspecialchars($e) ?></div><?php endforeach; ?>
        </div>
        <div class="form-group">
          <label>Stream *</label>
          <select name="stream_id" required>
            <option value="">Select Stream</option>
            <?php foreach($streams as $s): ?>
            <option value="<?= $s['id'] ?>" <?= \Core\View::old('stream_id') == $s['id'] ? 'selected' : '' ?>><?= htmlspecialchars($s['full_name']) ?></option>
            <?php endforeach; ?>
          </select>
        </div>
        <div class="form-group">
          <label>Gender *</label>
          <select name="gender" required>
            <option value="">Select</option>
            <option value="male"   <?= \Core\View::old('gender')==='male'  ?'selected':'' ?>>Male</option>
            <option value="female" <?= \Core\View::old('gender')==='female'?'selected':'' ?>>Female</option>
          </select>
        </div>
        <div class="form-group">
          <label>Date of Birth</label>
          <input type="date" name="dob" value="<?= \Core\View::old('dob') ?>">
        </div>
      </div>

      <!-- Parent / Guardian -->
      <div style="margin:20px 0 10px;padding-top:16px;border-top:2px solid var(--border)">
        <h5 style="margin-bottom:14px"><i class="bi bi-person-heart"></i> Parent / Guardian <span style="font-weight:400;font-size:13px;color:var(--gray)">(optional — can be added later)</span></h5>
        <div class="grid g2">
          <div class="form-group">
            <label>Parent Full Name</label>
            <input type="text" name="parent_name" value="<?= \Core\View::old('parent_name') ?>" placeholder="e.g. John Kamau">
          </div>
          <div class="form-group">
            <label>Parent Phone</label>
            <input type="text" name="parent_phone" value="<?= \Core\View::old('parent_phone') ?>" placeholder="0712345678">
            <small style="color:var(--gray)">Used for SMS notifications</small>
          </div>
          <div class="form-group">
            <label>Parent Email</label>
            <input type="email" name="parent_email" value="<?= \Core\View::old('parent_email') ?>" placeholder="parent@email.com">
          </div>
          <div class="form-group">
            <label>Relationship</label>
            <select name="parent_relationship">
              <option value="parent">Parent</option>
              <option value="guardian">Guardian</option>
              <option value="mother">Mother</option>
              <option value="father">Father</option>
              <option value="sibling">Sibling</option>
              <option value="other">Other</option>
            </select>
          </div>
        </div>
      </div>

      <p style="font-size:12px;color:var(--gray);margin-bottom:16px"><i class="bi bi-info-circle"></i> Student admission number is auto-generated. Default login password is the admission number.</p>
      <button type="submit" class="btn btn-primary"><i class="bi bi-person-plus"></i> Enroll Student</button>
    </form>
  </div>
</div>
