<?php
session_start();

/* ---------- AUTH CHECK ---------- */
if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit();
}

/* ---------- REQUIRED SESSION DATA ---------- */
$username = $_SESSION['username'] ?? null;
$practice_score = $_SESSION['practice_score'] ?? 0;

/* ---------- SCORE VALIDATION ---------- */
if (!isset($_SESSION['practice_attempted'])) {
    header("Location: practice_track.php");
    exit();
}

/* ---------- MARK PRACTICE COMPLETED ---------- */
$_SESSION['practice_done'] = true;
?>

<?php require_once 'includes/header.php'; ?>

<div class="track-complete-wrapper">
    <h2>🎉 Track Completed!</h2>

    <h3>Python Basics – Learning Badge</h3>

    <p>
        Well done, <strong><?php echo htmlspecialchars($username); ?></strong>!
        You have successfully completed the practice challenges in this track.
    </p>

    <p>
        This badge recognises your learning effort and consistency.
    </p>

    <!-- ✅ BADGE DOWNLOAD -->
    <a href="generate_badge_pdf.php" class="btn-primary">
        Download Learning Badge
    </a>

    <div class="actions">
        <a href="practice_reinforcement.php" class="btn-secondary">
            Proceed to Practice Reinforcement Test
        </a>
        <br><br>
        <a href="tracks.php">← Back to Tracks</a> |
        <a href="dashboard.php">Go to Dashboard</a>
    </div>
</div>
