"use client"; import { useState, type ReactNode } from "react"; import { YouTubeLiveBadge } from "@/components/YouTubeLiveBadge"; import { shortsLiveRef } from "@/lib/youtubeLive"; export type YtProfileSnippet = { title?: string; custom_url?: string; youtube_channel_id?: string; thumbnails?: { default?: { url?: string }; medium?: { url?: string }; high?: { url?: string }; }; thumb_url?: string; statistics?: { subscriberCount?: string | number; videoCount?: string | number; viewCount?: string | number; }; }; const AVATAR_COLORS = [ "bg-purple-600", "bg-fuchsia-600", "bg-orange-500", "bg-violet-600", "bg-stone-600", "bg-amber-600", "bg-rose-700", "bg-sky-700", ]; export function thumbOf(p?: YtProfileSnippet | null): string { if (!p) return ""; return ( String(p.thumb_url || "").trim() || String(p.thumbnails?.medium?.url || p.thumbnails?.default?.url || p.thumbnails?.high?.url || "").trim() ); } function handleOf(p?: YtProfileSnippet | null, fallbackId?: string): string { const raw = String(p?.custom_url || "").trim() || String(fallbackId || p?.youtube_channel_id || "").trim(); if (!raw) return ""; if (raw.startsWith("http")) return raw.replace(/^https?:\/\/(www\.)?youtube\.com\//i, ""); return raw.startsWith("@") ? raw : raw.startsWith("UC") ? raw : `@${raw.replace(/^@/, "")}`; } function letterStyle(name: string): { letter: string; color: string } { const t = name.trim() || "?"; const letter = t[0].toUpperCase(); let h = 0; for (let i = 0; i < t.length; i += 1) h = (h * 31 + t.charCodeAt(i)) >>> 0; return { letter, color: AVATAR_COLORS[h % AVATAR_COLORS.length] }; } function LetterAvatar({ name }: { name: string }) { const { letter, color } = letterStyle(name); return (