<?php
require_once __DIR__ . '/includes/auth_check.php';
session_start();

/*
Progress State
(default everything NOT started)
*/
$language = $_SESSION['language'] ?? null;

$practice_status      = $_SESSION['practice_status'] ?? 'not_started';
$reinforcement_status = $_SESSION['reinforcement_status'] ?? 'locked';
$final_status         = $_SESSION['final_status'] ?? 'locked';

$class = $_SESSION['class'] ?? 'college';
$applied_allowed = in_array($class, ['11', '12']);
?>

<!DOCTYPE html>
<html>
<head>
    <title>Coding Challenges | RS Learning Lab</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

<h1>🏆 Coding Challenges</h1>
<p>Base to advanced learning path.</p>

<!-- LANGUAGE SELECTION -->
<?php if (!$language): ?>
<div class="card">
    <h2>Select Programming Language</h2>
    <form method="post" action="select_language.php">
        <select name="language" required>
            <option value="">-- Choose Language --</option>
            <option value="python">Python</option>
            <option value="c">C</option>
            <option value="java">Java</option>
        </select>
        <button class="btn">Start Practice Track</button>
    </form>
</div>
<?php endif; ?>

<!-- PRACTICE TRACK -->
<div class="card">
    <h2>Track 1: Practice Track</h2>
    <p>Focus: Syntax, basics, confidence building.</p>

    <?php if ($practice_status === 'not_started'): ?>
        <span class="pending">Not Started</span><br><br>
        <a href="practice_track.php" class="btn">Start Practice</a>
    <?php elseif ($practice_status === 'completed'): ?>
        <span class="completed">Completed</span>
    <?php endif; ?>
</div>

<!-- REINFORCEMENT TRACK -->
<div class="card">
    <h2>Track 2: Reinforcement Track</h2>
    <p>Focus: Logic strengthening.</p>

    <?php if ($reinforcement_status === 'locked'): ?>
        <span class="locked">Locked</span>
    <?php elseif ($reinforcement_status === 'active'): ?>
        <a href="practice_reinforcement.php" class="btn">Start Reinforcement</a>
    <?php elseif ($reinforcement_status === 'completed'): ?>
        <span class="completed">Completed</span><br>
        🏅 Learning Badge Earned
    <?php endif; ?>
</div>

<!-- FINAL TRACK -->
<div class="card">
    <h2>Track 3: Final Track</h2>
    <p>Focus: End-to-end problem solving.</p>

    <?php if ($final_status === 'locked'): ?>
        <span class="locked">Locked</span>
    <?php elseif ($final_status === 'active'): ?>
        <a href="practice_final.php" class="btn">Start Final Track</a>
    <?php elseif ($final_status === 'completed'): ?>
        <span class="completed">Completed</span><br>
        📜 Track Completion Certificate Unlocked
    <?php endif; ?>
</div>

<!-- APPLIED THINKING -->
<div class="card">
    <h2>Applied Thinking (Class 11–12 CS)</h2>

    <?php if ($applied_allowed): ?>
        <a href="applied_thinking.php" class="btn">Start Applied Thinking</a>
    <?php else: ?>
        <span class="locked">Only for Class 11–12 CS</span>
    <?php endif; ?>
</div>

<a href="dashboard.php" class="btn">← Back to Dashboard</a>

</body>
</html>
