// /src/app/radar/TeamSidebar.tsx 'use client' import React, { useEffect, useState } from 'react' import { useAvatarDirectoryStore } from '@/app/lib/useAvatarDirectoryStore' export type Team = 'T' | 'CT' export type SidebarPlayer = { id: string // <- SteamID name?: string | null hp?: number | null armor?: number | null helmet?: boolean | null defuse?: boolean | null hasBomb?: boolean | null alive?: boolean | null } export default function TeamSidebar({ team, teamId, players, align = 'left', onHoverPlayer, }: { team: Team teamId?: string players: SidebarPlayer[] align?: 'left' | 'right' onHoverPlayer?: (id: string | null) => void }) { // ---- NEU: Team-Info (Logo) laden ---- const [teamLogo, setTeamLogo] = useState(null) const [teamApiName, setTeamApiName] = useState(null) const BOT_ICON = '/assets/img/icons/ui/bot.svg' const isBotId = (id: string) => id?.toUpperCase().startsWith('BOT:') useEffect(() => { let abort = false async function loadTeam() { if (!teamId) { setTeamLogo(null); setTeamApiName(null); return } try { const res = await fetch(`/api/team/${teamId}`, { cache: 'no-store' }) if (!res.ok) throw new Error(`HTTP ${res.status}`) const data = await res.json() if (!abort) { setTeamLogo(data?.logo || null) setTeamApiName(data?.name || null) } } catch { if (!abort) { setTeamLogo(null); setTeamApiName(null) } } } loadTeam() return () => { abort = true } }, [teamId]) // ---- Rest wie gehabt ---- const ensureTeamsLoaded = useAvatarDirectoryStore(s => s.ensureTeamsLoaded) const avatarById = useAvatarDirectoryStore(s => s.byId) const avatarVer = useAvatarDirectoryStore(s => s.version) useEffect(() => { if (teamId) ensureTeamsLoaded([teamId]) }, [teamId, ensureTeamsLoaded]) const defaultTeamName = team === 'CT' ? 'Counter-Terrorists' : 'Terrorists' const teamName = teamApiName || defaultTeamName const teamColor = team === 'CT' ? 'text-blue-400' : 'text-amber-400' const barArmor = team === 'CT' ? 'bg-blue-500' : 'bg-amber-500' const ringColor = team === 'CT' ? 'ring-blue-500' : 'ring-amber-500' const isRight = align === 'right' // Fallback-Icon, falls API kein Logo liefert: const fallbackLogo = '/assets/img/logos/cs2.webp'; const logoSrc = teamLogo || fallbackLogo const aliveCount = players.filter(p => p.alive !== false && (p.hp ?? 1) > 0).length const sorted = [...players].sort((a, b) => { const al = (b.alive ? 1 : 0) - (a.alive ? 1 : 0) if (al !== 0) return al const hp = (b.hp ?? -1) - (a.hp ?? -1) if (hp !== 0) return hp return (a.name ?? '').localeCompare(b.name ?? '') }) return ( ) } function clamp(n: number, a: number, b: number) { return Math.max(a, Math.min(b, n)) }