<?php
// learn_module.inc.php
?>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">

<div class="container my-5">

<h2><?= htmlspecialchars($module['title']) ?></h2>
<p class="text-muted"><?= htmlspecialchars($module['description']) ?></p>

<h3 class="mt-4">📚 Modules</h3>

<?php foreach ($lessons as $l): 
    $progress = $lessonProgress[$l['ref']] ?? 0;

    if ($progress >= 100) {
        $caption = "✅ Completed";
        $btnClass = "btn-success";
    } elseif ($progress > 0) {
        $caption = "▶ Continue ({$progress}%)";
        $btnClass = "btn-warning";
    } else {
        $caption = "🚀 Start";
        $btnClass = "btn-primary";
    }
?>

<div class="border rounded p-3 mb-3">
    <h4>📦 <?= htmlspecialchars($l['title']) ?></h4>
    <p><?= htmlspecialchars($l['description']) ?></p>

    <a href="index.php?p=learn_formation_module_lesson&ref=<?= $l['ref'] ?>"
       class="btn <?= $btnClass ?>">
        <?= $caption ?>
    </a>
</div>

<?php endforeach; ?>

 <div class="mt-5">
        <a href="index.php?p=learn_formation&ref=<?= $module['formation_ref'] ?>" class="btn btn-secondary">
            🔙 Back 
        </a>
    </div>

</div>
