<?php include app()->basePath('app/Views/partials/header.php'); ?>

<section class="panel">
    <p class="eyebrow"><?= e($course['title'] ?? 'Curso') ?></p>
    <h1><?= e($lesson['title']) ?></h1>
    <p><?= e($lesson['description'] ?: lesson_type_label($lesson['type'])) ?></p>

    <?php if ($lesson['type'] === 'video'): ?>
        <div class="secure-player" oncontextmenu="return false">
            <video controls controlsList="nodownload noplaybackrate" disablePictureInPicture preload="metadata" src="/secure/video?lesson_id=<?= e((string) $lesson['id']) ?>"></video>
        </div>
        <p class="small">Video servido por rota protegida. O caminho real do ficheiro nao fica publico.</p>
    <?php elseif ($lesson['type'] === 'pdf'): ?>
        <iframe class="pdf-frame" src="/secure/lesson-file?lesson_id=<?= e((string) $lesson['id']) ?>"></iframe>
    <?php else: ?>
        <article class="lesson-text">
            <?= nl2br(e($lesson['text_content'])) ?>
        </article>
    <?php endif; ?>

    <?php if (!empty($lesson['materials'])): ?>
        <section class="sub-panel">
            <h2>Materiais de apoio</h2>
            <div class="material-list">
                <?php foreach ($lesson['materials'] as $material): ?>
                    <a class="material-link" href="/secure/material?material_id=<?= e((string) $material['id']) ?>">
                        <?= e($material['title']) ?>
                        <span><?= e($material['file_type']) ?></span>
                    </a>
                <?php endforeach; ?>
            </div>
        </section>
    <?php endif; ?>

    <div class="actions">
        <a class="ghost-button" href="/manage/courses/content?id=<?= e((string) $lesson['course_id']) ?>">Voltar ao conteudo</a>
    </div>
</section>

<script>
document.addEventListener('contextmenu', function (event) {
    if (event.target.closest('.secure-player')) {
        event.preventDefault();
    }
});
</script>

<?php include app()->basePath('app/Views/partials/footer.php'); ?>
