<?php
 
$comments = $data['comments'] ?? [];
$reports = $data['reports'] ?? [];
$commentCount = (int) ($data['commentCount'] ?? 0);
$reportCount = (int) ($data['reportCount'] ?? 0);
$total = $commentCount + $reportCount;

$reasonLabels = [
    'illegal' => 'Illegal',
    'copyright' => 'Copyright',
    'spam' => 'Spam',
    'broken' => 'Broken',
    'underage' => 'Underage',
    'other' => 'Other',
];
?>

<div class="flex items-center gap-3 mb-3">
    <span class="inline-flex items-center gap-1 text-xs <?= $total > 0 ? 'text-orange-600 font-semibold' : 'text-gray-400' ?>">
        <i class="fa-solid fa-circle-exclamation text-[10px]"></i>
        <?= $total ?> pending item<?= $total !== 1 ? 's' : '' ?>
    </span>
    <?php if ($commentCount > 0): ?>
        <a href="/admin/comments" class="text-[10px] text-primary-600 hover:text-primary-700"><?= $commentCount ?> comment<?= $commentCount !== 1 ? 's' : '' ?></a>
    <?php endif; ?>
    <?php if ($reportCount > 0): ?>
        <a href="/admin/inbox" class="text-[10px] text-red-600 hover:text-red-700"><?= $reportCount ?> report<?= $reportCount !== 1 ? 's' : '' ?></a>
    <?php endif; ?>
</div>

<?php if ($total === 0): ?>
    <div class="text-center py-6">
        <i class="fa-solid fa-check-circle text-green-300 text-2xl mb-2"></i>
        <p class="text-xs text-gray-400">All clear! Nothing to moderate.</p>
    </div>
<?php else: ?>
    <div class="space-y-0 max-h-[280px] overflow-y-auto">
        <?php foreach ($comments as $c): ?>
        <div class="py-2 border-b border-gray-50 flex items-start gap-2">
            <span class="inline-flex items-center px-1.5 py-0.5 rounded text-[9px] font-medium bg-orange-100 text-orange-600 shrink-0 mt-0.5">Comment</span>
            <div class="flex-1 min-w-0">
                <div class="text-xs">
                    <span class="font-semibold text-gray-800"><?= htmlspecialchars($c['username'] ?? 'Anonymous') ?></span>
                    <span class="text-gray-300">on</span>
                    <a href="/admin/videos/<?= (int)($c['video_id'] ?? 0) ?>/edit" class="text-blue-600 hover:text-blue-800 truncate"><?= htmlspecialchars(mb_strimwidth($c['video_title'] ?? '', 0, 40, '...')) ?></a>
                </div>
                <div class="text-xs text-gray-500 mt-0.5 line-clamp-1"><?= htmlspecialchars(mb_strimwidth($c['body'] ?? '', 0, 80, '...')) ?></div>
                <div class="text-[10px] text-gray-300 mt-0.5"><?= htmlspecialchars(substr($c['created_at'] ?? '', 0, 16)) ?></div>
            </div>
        </div>
        <?php endforeach; ?>

        <?php foreach ($reports as $r): ?>
        <div class="py-2 border-b border-gray-50 flex items-start gap-2">
            <span class="inline-flex items-center px-1.5 py-0.5 rounded text-[9px] font-medium bg-red-100 text-red-600 shrink-0 mt-0.5">Report</span>
            <div class="flex-1 min-w-0">
                <div class="text-xs">
                    <span class="font-semibold text-gray-800"><?= htmlspecialchars($reasonLabels[$r['reason']] ?? $r['reason']) ?></span>
                    <span class="text-gray-300">-</span>
                    <a href="/admin/videos/<?= (int)($r['video_id'] ?? 0) ?>/edit" class="text-blue-600 hover:text-blue-800 truncate"><?= htmlspecialchars(mb_strimwidth($r['video_title'] ?? '', 0, 40, '...')) ?></a>
                </div>
                <?php if (!empty($r['details'])): ?>
                <div class="text-xs text-gray-500 mt-0.5 line-clamp-1"><?= htmlspecialchars(mb_strimwidth($r['details'] ?? '', 0, 80, '...')) ?></div>
                <?php endif; ?>
                <div class="text-[10px] text-gray-300 mt-0.5"><?= htmlspecialchars(substr($r['created_at'] ?? '', 0, 16)) ?></div>
            </div>
        </div>
        <?php endforeach; ?>
    </div>
<?php endif; ?>
