<?php
 
?>
<div class="flex items-center justify-between mb-2">
    <span class="text-xs text-gray-500">Latest additions</span>
    <a href="/admin/videos" 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">Thumb</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-left text-[10px] font-semibold uppercase tracking-wider text-gray-400">Status</th>
                <th class="px-3 py-1.5 text-right text-[10px] font-semibold uppercase tracking-wider text-gray-400 hide-mobile">Views</th>
                <th class="px-3 py-1.5 text-right text-[10px] font-semibold uppercase tracking-wider text-gray-400 hide-mobile">Date</th>
            </tr>
        </thead>
        <tbody class="divide-y divide-gray-50">
            <?php foreach ($data as $video): ?>
            <tr class="hover:bg-gray-50/50 transition-colors">
                <td class="px-3 py-1.5">
                    <?php $thumbUrl = VideoAsset::thumbUrl($video); ?>
                    <?php if ($thumbUrl !== ''): ?>
                        <img src="<?= htmlspecialchars($thumbUrl) ?>" alt="" class="w-14 h-8 rounded object-cover" data-zoom-src="<?= htmlspecialchars($thumbUrl) ?>">
                    <?php else: ?>
                        <div class="w-14 h-8 rounded bg-gray-100 flex items-center justify-center text-[9px] text-gray-300">No img</div>
                    <?php endif; ?>
                </td>
                <td class="px-3 py-1.5 text-xs max-w-[200px]">
                    <a href="/admin/videos/<?= (int)$video['id'] ?>/edit" class="text-blue-600 hover:text-blue-800 font-medium line-clamp-1"><?= htmlspecialchars($video['title']) ?></a>
                </td>
                <td class="px-3 py-1.5 text-xs">
                    <?php
                    $statusMap = [
                        'published' => ['bg-green-100 text-green-700', 'Pub'],
                        'draft' => ['bg-gray-100 text-gray-500', 'Draft'],
                        'private' => ['bg-yellow-100 text-yellow-700', 'Priv'],
                        'processing' => ['bg-blue-100 text-blue-700', 'Transcoding'],
                        'error' => ['bg-red-100 text-red-700', 'Error'],
                    ];
                    $st = $statusMap[$video['status'] ?? ''] ?? ['bg-gray-100 text-gray-500', htmlspecialchars($video['status'] ?? '-')];
                    $stLink = ($video['status'] ?? '') === 'processing' ? '/admin/settings?tab=transcode&sub=queue' : (($video['status'] ?? '') === 'error' ? '/admin/settings?tab=transcode&sub=queue' : '');
                    ?>
                    <?php if ($stLink): ?>
                    <a href="<?= $stLink ?>" class="inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-medium no-underline hover:opacity-80 <?= $st[0] ?>"><?= $st[1] ?></a>
                    <?php else: ?>
                    <span class="inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-medium <?= $st[0] ?>"><?= $st[1] ?></span>
                    <?php endif; ?>
                </td>
                <td class="px-3 py-1.5 text-xs text-gray-500 text-right hide-mobile"><?= number_format((int)($video['views'] ?? 0)) ?></td>
                <td class="px-3 py-1.5 text-[11px] text-gray-400 text-right hide-mobile"><?= htmlspecialchars(substr($video['created_at'] ?? '', 0, 10)) ?></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>
<?php else: ?>
<div class="text-center py-8 text-gray-300 text-xs">No videos yet</div>
<?php endif; ?>
