<?php $base=array_filter(['token'=>$token]); ?>
<main class="container py-4 py-md-5">
    <div class="d-flex flex-column flex-md-row justify-content-between gap-3 align-items-md-center mb-4">
        <div><h1 class="h3 fw-bold text-cfc-dark mb-1"><i class="bi bi-play-btn"></i> Videoaulas liberadas</h1><p class="text-muted mb-0">Assista dentro do próprio painel aos conteúdos liberados individualmente.</p></div>
        <a class="btn btn-outline-primary rounded-pill" href="<?= e($actorType==='admin'?url('admin/video-lessons'):($actorType==='student'?url('dashboard'):($actorType==='professional'?url('professional/panel',$base):url('beginner/panel')))) ?>"><i class="bi bi-arrow-left"></i> Voltar</a>
    </div>
    <div class="row g-4">
        <?php foreach($videos as $video): ?>
            <div class="col-xl-6"><div class="card border-0 shadow-soft rounded-4 overflow-hidden h-100">
                <?php if(!empty($video['cover_path'])): ?><img src="<?= e(asset($video['cover_path'])) ?>" class="video-cover" alt="Capa da videoaula"><?php endif; ?>
                <div class="card-body p-4"><h2 class="h5 fw-bold"><?= e($video['title']) ?></h2><p class="text-muted"><?= e($video['description']??'') ?></p>
                    <?php if(($video['source_type']??'')==='upload'): ?>
                        <video class="w-100 rounded-4 bg-dark" controls preload="metadata" src="<?= e(url('portal/video-stream',array_merge($base,['id'=>(int)$video['id']]))) ?>"></video>
                    <?php else: ?>
                        <?php $embed=video_embed_url($video['video_url']??''); ?>
                        <?php if($embed!==''): ?><div class="ratio ratio-16x9"><iframe class="rounded-4" src="<?= e($embed) ?>" allowfullscreen loading="lazy"></iframe></div>
                        <?php elseif(is_direct_video_url($video['video_url']??'')): ?><video class="w-100 rounded-4 bg-dark" controls preload="metadata" src="<?= e($video['video_url']) ?>"></video>
                        <?php else: ?><a target="_blank" rel="noopener" class="btn btn-primary rounded-pill" href="<?= e($video['video_url']) ?>"><i class="bi bi-box-arrow-up-right"></i> Abrir videoaula</a><?php endif; ?>
                    <?php endif; ?>
                </div>
            </div></div>
        <?php endforeach; ?>
        <?php if(empty($videos)): ?><div class="col-12"><div class="alert alert-info rounded-4">Nenhuma videoaula foi liberada para seu cadastro.</div></div><?php endif; ?>
    </div>
</main>
