import { useState, useRef } from "react"; export function CountryBadge({ country }: { country: string | null }) { if (!country) return —; const isCode = country.length === 2; return ( {isCode && ( )} {country} ); } import { createPortal } from "react-dom"; import { IconLock, IconUnlock } from "@/components/shared/Icons"; import { t } from "@/lib/i18n"; interface Props { status: string; } const STATUS_KEYS: Record = { unknown: ["badge-unknown", "status.unknown"], valid: ["badge-ok", "status.valid"], invalid: ["badge-error", "status.invalid"], locked: ["badge-error", "status.locked"], limited: ["badge-running", "status.limited"], }; export function StatusBadge({ status }: Props) { const entry = STATUS_KEYS[status]; const [cls, text] = entry ? [entry[0], t(entry[1])] : ["badge-unknown", status]; return {text}; } export function BanBadge({ status }: { status: string | null }) { if (status === "BANNED") return {t("status.banned")}; if (status === "NO BAN") return {t("status.ok")}; return —; } export function LockBadge({ status }: Props) { if (status === "locked") return ; return ; } export function MafileBadge({ hasMafile }: { hasMafile: boolean }) { return hasMafile ? ✓ : —; } export function VacBadge({ status, games }: { status: string | null; games?: string | null }) { const [pos, setPos] = useState<{ top: number; left: number } | null>(null); const ref = useRef(null); const gameList: string[] = (() => { if (!games) return []; try { return JSON.parse(games) as string[]; } catch { return []; } })(); const handleEnter = () => { if (!ref.current || gameList.length === 0) return; const r = ref.current.getBoundingClientRect(); setPos({ top: r.top, left: r.right + 6 }); }; const handleLeave = () => setPos(null); if (status === "VAC") return Vac; if (status === "GAME BAN") { return ( <> Vac{gameList.length > 0 && ({gameList.length})} {pos && gameList.length > 0 && createPortal( Game Bans {gameList.map((g, i) => ( {g} ))} , document.body, )} > ); } if (status === "CLEAN") return NoVac; return —; } export function LimitBadge({ status }: { status: string | null }) { if (status === "Lim") return Lim; if (status === "NoLim") return NoLim; return —; }