<?php
 
?>
<div class="flex items-center justify-between mb-2">
    <span class="text-xs text-gray-500">Most viewed published galleries</span>
    <a href="/admin/albums" class="text-[11px] text-primary-600 hover:text-primary-700 font-medium">View all</a>
</div>
<?php if (!empty($data)): ?>
<div class="overflow-x-auto -mx-4">
    <table class="w-full">
        <thead>
            <tr class="bg-gray-50/50">
                <th class="px-3 py-1.5 text-left text-[10px] font-semibold uppercase tracking-wider text-gray-400 w-8">#</th>
                <th class="px-3 py-1.5 text-left text-[10px] font-semibold uppercase tracking-wider text-gray-400">Cover</th>
                <th class="px-3 py-1.5 text-left text-[10px] font-semibold uppercase tracking-wider text-gray-400">Title</th>
                <th class="px-3 py-1.5 text-right text-[10px] font-semibold uppercase tracking-wider text-gray-400">Views</th>
                <th class="px-3 py-1.5 text-right text-[10px] font-semibold uppercase tracking-wider text-gray-400 hide-mobile">Images</th>
            </tr>
        </thead>
        <tbody class="divide-y divide-gray-50">
            <?php foreach ($data as $i => $album): ?>
            <tr class="hover:bg-gray-50/50 transition-colors">
                <td class="px-3 py-1.5 text-xs font-bold <?= $i < 3 ? 'text-primary-600' : 'text-gray-400' ?>"><?= $i + 1 ?></td>
                <td class="px-3 py-1.5">
                    <?php $coverUrl = AlbumAsset::coverUrl($album); ?>
                    <?php if ($coverUrl !== ''): ?>
                        <img src="<?= htmlspecialchars($coverUrl) ?>" alt="" class="w-14 h-9 rounded object-cover" data-zoom-src="<?= htmlspecialchars($coverUrl) ?>">
                    <?php else: ?>
                        <div class="w-14 h-9 rounded bg-gray-100 flex items-center justify-center text-[9px] text-gray-300"><i class="fa-light fa-images"></i></div>
                    <?php endif; ?>
                </td>
                <td class="px-3 py-1.5 text-xs max-w-[200px]">
                    <a href="/admin/albums/<?= (int)$album['id'] ?>/edit" class="text-blue-600 hover:text-blue-800 font-medium line-clamp-1"><?= htmlspecialchars($album['title']) ?></a>
                </td>
                <td class="px-3 py-1.5 text-xs font-semibold text-gray-700 text-right"><?= number_format((int)($album['views'] ?? 0)) ?></td>
                <td class="px-3 py-1.5 text-xs text-gray-500 text-right hide-mobile"><?= number_format((int)($album['image_count'] ?? 0)) ?></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>
<?php else: ?>
<div class="text-center py-8 text-gray-300 text-xs">No published albums yet</div>
<?php endif; ?>
