<main class="container py-4 py-md-5">
    <div class="d-flex flex-column flex-md-row align-items-md-center justify-content-between gap-3 mb-4">
        <div>
            <h1 class="h3 fw-bold text-cfc-dark mb-1">Meus e-books</h1>
            <p class="text-muted mb-0">Aqui aparecem somente os materias liberados manualmente para o seu cadastro.</p>
        </div>
        <a class="btn btn-outline-primary rounded-pill" href="<?= e(url('dashboard')) ?>"><i class="bi bi-arrow-left"></i> Voltar</a>
    </div>

    <?php if (!$ebooks): ?>
        <div class="alert alert-info rounded-4 shadow-soft border-0">Nenhum e-book foi liberado para você ainda.</div>
    <?php else: ?>
        <div class="row g-4">
            <?php foreach ($ebooks as $ebook): ?>
                <div class="col-md-6 col-lg-4">
                    <div class="card border-0 shadow-soft rounded-4 h-100 overflow-hidden">
                        <?php if (!empty($ebook['cover_path'])): ?>
                            <img class="content-cover-card" src="<?= e(url('media/ebook-cover', ['id'=>(int)$ebook['id']])) ?>" alt="Capa de <?= e($ebook['title']) ?>">
                        <?php endif; ?>
                        <div class="card-body p-4 d-flex flex-column">
                            <?php if (empty($ebook['cover_path'])): ?><span class="feature-icon mb-3"><i class="bi bi-book"></i></span><?php endif; ?>
                            <h2 class="h5 fw-bold"><?= e($ebook['title']) ?></h2>
                            <?php if (!empty($ebook['description'])): ?><p class="text-muted flex-grow-1"><?= nl2br(e($ebook['description'])) ?></p><?php else: ?><p class="text-muted flex-grow-1">Matérial liberado pela Autoescola.</p><?php endif; ?>
                            <small class="text-muted mb-3">Liberado em <?= e(date('d/m/Y', strtotime($ebook['granted_at']))) ?></small>
                            <a class="btn btn-primary rounded-pill" target="_blank" href="<?= e(url('ebooks/download', ['id' => (int)$ebook['id']])) ?>"><i class="bi bi-download"></i> Abrir / baixar</a>
                        </div>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>
</main>
