<?php
/**
 * Partial: student popover preview card(s).
 *
 * Expected variables:
 *   $theses   array               rows from Database::getThesesByAuthorName()
 *   $name     string              student name
 *   $coverMap array<int,string>   thesis_id => cover file_path
 */

foreach ($theses as $t):
    $synopsis = $t['synopsis'] ?? '';
    // Truncate synopsis to ~160 chars
    if (strlen($synopsis) > 160) {
        $synopsis = substr($synopsis, 0, 157) . '…';
    }
    $meta = array_filter([
        $t['year']          ?? null,
        $t['orientation']   ?? null,
        $t['finality_type'] ?? null,
    ]);
?>
<a href="/tfe?id=<?= (int)$t['id'] ?>" class="student-card">
    <?php $cover = $coverMap[$t['id']] ?? null; ?>
    <?php if ($cover): ?>
    <div class="student-card__banner" style="background-image:url('/media?path=<?= urlencode($cover) ?>')"></div>
    <?php else: ?>
    <div class="student-card__banner student-card__banner--gradient">
        <span class="student-card__gradient-author"><?= htmlspecialchars($t['authors'] ?? '') ?></span>
        <span class="student-card__gradient-title"><?= htmlspecialchars($t['title']) ?></span>
    </div>
    <?php endif; ?>
    <div class="student-card__body">
        <p class="student-card__meta"><?= htmlspecialchars(implode(' · ', $meta)) ?></p>
        <h3 class="student-card__title"><?= htmlspecialchars($t['title']) ?></h3>
        <?php if (!empty($t['subtitle'])): ?>
        <p class="student-card__subtitle"><?= htmlspecialchars($t['subtitle']) ?></p>
        <?php endif; ?>
        <?php if ($synopsis !== ''): ?>
        <p class="student-card__synopsis"><?= htmlspecialchars($synopsis) ?></p>
        <?php endif; ?>
    </div>
</a>
<?php endforeach; ?>
