<?php
// ================================
// REINFORCEMENT TRACK (CLEAN VERSION)
// ================================

ini_set('display_errors', 1);
error_reporting(E_ALL);

session_start();
require_once __DIR__ . "/config/db.php";

/* =========================
   STUDENT INPUTS
========================= */
$name  = $_GET['name'] ?? 'Student';
$roll  = $_GET['roll'] ?? 'NA';
$class = $_GET['class'] ?? '';
$lang  = $_GET['lang'] ?? 'python';
$topic_id = $_GET['topic_id'] ?? 1;

/* =========================
   FETCH REINFORCEMENT QUESTIONS
========================= */
$stmt = $pdo->prepare("
    SELECT *
    FROM questions
    WHERE topic_id = ?
      AND track_type = 'reinforcement'
    ORDER BY RAND()
    LIMIT 5
");
$stmt->execute([$topic_id]);
$questions = $stmt->fetchAll(PDO::FETCH_ASSOC);

/* HARD FAIL */
if (!$questions || count($questions) === 0) {
    die("❌ Reinforcement questions not found");
}
?>

<!DOCTYPE html>
<html>
<head>
<title>Reinforcement Track</title>
<style>
body{
    background:#020617;
    color:#e5e7eb;
    font-family:Arial;
}
.card{
    width:70%;
    margin:40px auto;
    background:#0f172a;
    padding:30px;
    border-radius:14px;
}
button{
    padding:10px 20px;
    border:none;
    border-radius:8px;
    margin-top:10px;
}
</style>
</head>
<body>

<div class="card">
    <h2>🧠 Reinforcement Track</h2>

    <?php foreach ($questions as $i => $q): ?>
        <div style="margin-bottom:25px">
            <h3>Q<?= $i+1 ?>. <?= htmlspecialchars($q['question']) ?></h3>
        </div>
    <?php endforeach; ?>

    <form method="POST" action="/rs_lab/reinforcement_finish.php">

        <input type="hidden" name="name" value="<?= htmlspecialchars($name) ?>">
        <input type="hidden" name="roll" value="<?= htmlspecialchars($roll) ?>">
        <input type="hidden" name="class" value="<?= htmlspecialchars($class) ?>">
        <input type="hidden" name="lang" value="<?= htmlspecialchars($lang) ?>">
        <input type="hidden" name="topic_id" value="<?= $topic_id ?>">

        <button type="submit">
            Finish Reinforcement
        </button>
    </form>

</div>

</body>
</html>