@props(['video']) @php use App\Models\CommentLike; $currentUserId = Auth::id() ?? 0; $llmEnabled = app(\App\Services\LlmLyricsService::class)->isEnabled(); // Flag per commenter: most-frequent access country, falling back to the // user's nationality. Batched so the comments list stays a single query. $commenterIds = $video->comments()->pluck('user_id')->filter()->unique()->values()->all(); $commenterCountry = \App\Models\User::topCountriesFor($commenterIds); $topComments = $video->comments()->whereNull('parent_id')->with('user', 'replies.user')->latest()->get(); $topLevelCount = $topComments->count(); $replyCount = $topComments->sum(fn($c) => $c->replies->count()); // Permalink: ?lc= scrolls to and highlights a specific // comment or reply so a shared link lands on the exact message. The // id is validated against the current video's comment ids so the // highlight only applies when the target really belongs here. $permalinkId = (int) request('lc', 0); $allCommentIds = $topComments->pluck('id') ->merge($topComments->flatMap(fn($c) => $c->replies->pluck('id'))) ->all(); $likeCounts = CommentLike::whereIn('comment_id', $allCommentIds) ->selectRaw('comment_id, COUNT(*) as cnt') ->groupBy('comment_id') ->pluck('cnt', 'comment_id'); $userLikedIds = $currentUserId ? CommentLike::where('user_id', $currentUserId) ->whereIn('comment_id', $allCommentIds) ->pluck('comment_id')->flip()->all() : []; if (!function_exists('ytcAvatar')) { function ytcAvatar($user) { if (!$user) return asset('images/default-avatar.svg'); return $user->avatar_url ?? asset('images/default-avatar.svg'); } } if (!function_exists('ytcTime')) { function ytcTime($dt) { if (!$dt) return ''; return $dt->diffForHumans(); } } @endphp
{{-- ── Header ── --}}
{{-- Top-level count on the header; reply count surfaces inside each thread's "N replies" expander. "1 Comment" singular when there's exactly one — never "1 Comments". --}} {{ number_format($topLevelCount) }} {{ Str::plural('Comment', $topLevelCount) }} @if($replyCount > 0) · {{ number_format($replyCount) }} {{ Str::plural('reply', $replyCount) }} @endif
Top comments
Newest first
{{-- ── New comment form ── --}} @auth
{{ Auth::user()->name }}
@else @endauth {{-- ── Comments list ── --}}
@forelse($topComments as $comment) @php $isOwn = $comment->user_id === $currentUserId; @endphp
{{ $comment->user->name ?? 'User' }}
@php $cFlag = $commenterCountry[$comment->user_id] ?? null; @endphp @if($cFlag)@endif {{ $comment->user->name ?? 'User' }} {{ ytcTime($comment->created_at) }}
{{ $comment->body }}
@if($llmEnabled) @endif {{-- Edit form --}} @if($isOwn) @endif {{-- Action bar --}}
@php $cLikes = $likeCounts->get($comment->id, 0); $cLiked = isset($userLikedIds[$comment->id]); @endphp @auth @endauth @if($llmEnabled) @endif @if($isOwn)
@endif
{{-- Reply form is lazy-cloned from #ytc-reply-form-tpl on first click; the ~13-line markup used to render for every top-level comment (so a 50-comment video shipped ~650 lines of hidden form markup to every viewer). --}} @auth
@endauth {{-- Replies --}} @if($comment->replies && $comment->replies->count() > 0)
@endif
@empty

No comments yet. Be the first!

@endforelse
{{-- ── Delete confirm modal ── --}}

Delete comment?

This will permanently delete your comment.

@auth {{-- Reply-form template. Cloned into .ytc-reply-slot the first time a user clicks Reply on a given comment. Keeping it here (not in the layout) means the markup travels with the comments component — the only place that uses it. --}} @endauth