- 리그 탭에서 월드컵 제거, ?league=wc 는 KBO 강등, 기본 리그 kbo·mlb·mls - index.html·OG 기본 타이틀에서 월드컵 문구 제거, 월드컵 특설 정적 플레이리스트 제거 - 응원가 MLS 포함: 라인업 소스 없는 리그는 윈도우 진입 즉시 생성, 스타일은 soccer 앤섬 변형, 커버 로고는 Match flag(ESPN PNG) 재사용 - MLB 도 한국 팬 표기 지시 적용, 전날 활약 조회는 kbo/mlb 만 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
333 lines
14 KiB
TypeScript
333 lines
14 KiB
TypeScript
import { useEffect, useRef, useState } from "react";
|
|
import type { Match, TeamStanding } from "@/lib/types";
|
|
import { kickoffDisplay } from "@/lib/format";
|
|
import { type Lang, dict, teamShort, roundLabel as tRound } from "@/lib/i18n";
|
|
import { getTeamSongTracks, type Track } from "@/lib/playlist";
|
|
import { usePlayer } from "@/lib/usePlayer";
|
|
import BallIcon from "./BallIcon";
|
|
import { FormBadges } from "./ScheduleBoard";
|
|
import TeamFlag from "./TeamFlag";
|
|
import WaveStrip from "./WaveStrip";
|
|
|
|
// 팀별 '응원가 듣기' 버튼 — 오늘의 응원가(Suno 자동 생성)를 플레이어에 싣는다.
|
|
// 이 팀 곡이 재생 중이면 일시정지/이어듣기 토글. 곡이 없으면 렌더 안 함.
|
|
function CheerSongButton({
|
|
matchId,
|
|
teamCode,
|
|
lang,
|
|
}: {
|
|
matchId: string;
|
|
teamCode: string;
|
|
lang: Lang;
|
|
}) {
|
|
const { currentTrack, isPlaying, toggle, loadPlaylist, open } = usePlayer();
|
|
const [tracks, setTracks] = useState<Track[]>([]);
|
|
useEffect(() => {
|
|
let alive = true;
|
|
getTeamSongTracks(matchId, teamCode).then((ts) => alive && setTracks(ts));
|
|
return () => {
|
|
alive = false;
|
|
};
|
|
}, [matchId, teamCode]);
|
|
|
|
// 공유 링크(/song/...→ ?song=팀코드) 진입 시 그 팀 응원가 자동 로드 (1회)
|
|
const autoLoaded = useRef(false);
|
|
useEffect(() => {
|
|
if (autoLoaded.current || tracks.length === 0) return;
|
|
const q = new URLSearchParams(window.location.search).get("song");
|
|
if (q === teamCode) {
|
|
autoLoaded.current = true;
|
|
loadPlaylist(tracks);
|
|
open();
|
|
}
|
|
}, [tracks, teamCode, loadPlaylist, open]);
|
|
|
|
if (tracks.length === 0) return null;
|
|
const active = !!currentTrack && tracks.some((t) => t.src === currentTrack.src);
|
|
const label = active
|
|
? isPlaying
|
|
? lang === "en" ? "⏸ Pause" : "⏸ 일시정지"
|
|
: lang === "en" ? "▶ Resume" : "▶ 이어 듣기"
|
|
: lang === "en" ? "♪ Cheer song" : "♪ 응원가 듣기";
|
|
|
|
return (
|
|
<button
|
|
type="button"
|
|
onClick={() => {
|
|
if (active) toggle();
|
|
else {
|
|
loadPlaylist(tracks);
|
|
open();
|
|
}
|
|
}}
|
|
className={`rounded-full border px-3 py-1 text-[12px] font-bold transition active:scale-95 ${
|
|
active
|
|
? "border-[var(--green)] bg-[var(--green)]/15 text-[var(--green)]"
|
|
: "border-[var(--green)]/50 text-[var(--green)] hover:bg-[var(--green)]/10"
|
|
}`}
|
|
>
|
|
{label}
|
|
</button>
|
|
);
|
|
}
|
|
|
|
// 순위 캐시 → "3위 · 52승37패 (0.584)" 한 줄 (야구)
|
|
function standingLine(
|
|
st: { rank?: number | null; w?: number; l?: number; wra?: string | number } | null | undefined,
|
|
lang: Lang,
|
|
): string | null {
|
|
if (!st?.rank) return null;
|
|
const rank = lang === "en" ? `#${st.rank}` : `${st.rank}위`;
|
|
if (st.w == null || st.l == null) return rank;
|
|
const rec = lang === "en" ? `${st.w}W ${st.l}L` : `${st.w}승${st.l}패`;
|
|
return `${rank} · ${rec}${st.wra ? ` (${st.wra})` : ""}`;
|
|
}
|
|
|
|
// MLS 순위 캐시 → "동부 3위 · 8승2무4패 (승점 26)" 한 줄
|
|
function mlsStandingLine(st: TeamStanding & { div?: string | null } | null | undefined, lang: Lang): string | null {
|
|
if (!st?.rank) return null;
|
|
const conf =
|
|
st.div === "EAST"
|
|
? lang === "en" ? "East" : "동부"
|
|
: st.div === "WEST"
|
|
? lang === "en" ? "West" : "서부"
|
|
: "";
|
|
const rank = lang === "en" ? `#${st.rank}` : `${st.rank}위`;
|
|
const rec =
|
|
st.w != null && st.l != null
|
|
? lang === "en"
|
|
? ` · ${st.w}W-${st.d ?? 0}D-${st.l}L`
|
|
: ` · ${st.w}승${st.d ?? 0}무${st.l}패`
|
|
: "";
|
|
const pts = st.pts != null ? (lang === "en" ? ` (${st.pts}pts)` : ` (승점 ${st.pts})`) : "";
|
|
return `${conf} ${rank}${rec}${pts}`.trim();
|
|
}
|
|
|
|
export default function MatchupHUD({ match, lang = "ko" }: { match: Match; lang?: Lang }) {
|
|
const t = dict(lang);
|
|
const { group } = match;
|
|
const finished = !!match.result;
|
|
const isBaseball = match.league === "kbo" || match.league === "mlb";
|
|
const isMls = match.league === "mls";
|
|
const isClub = isBaseball || isMls; // 클럽 리그 공통 분기 (로고·venue 등)
|
|
// 월드컵: 한국을 항상 왼쪽에. 야구: 원정-홈. MLS: 홈-원정 (축구 관례 — 화면만 교체).
|
|
const flip =
|
|
isMls || (!isClub && match.teamB.code === "KOR" && match.teamA.code !== "KOR");
|
|
const left = flip ? match.teamB : match.teamA;
|
|
const right = flip ? match.teamA : match.teamB;
|
|
const leftScore = flip ? match.result?.scoreB : match.result?.scoreA;
|
|
const rightScore = flip ? match.result?.scoreA : match.result?.scoreB;
|
|
|
|
const ex = match.extras;
|
|
const spL = ex?.starterA;
|
|
const spR = ex?.starterB;
|
|
const stL = standingLine(ex?.standings?.a, lang);
|
|
const stR = standingLine(ex?.standings?.b, lang);
|
|
const vs = ex?.seasonVs;
|
|
const hasVs = !!vs && vs.aWin != null && vs.bWin != null;
|
|
// MLS 프리뷰 (폼·시즌 전적·순위·맞대결) — 왼쪽=홈(teamB) 기준으로 교체
|
|
const mlsStL = mlsStandingLine(ex?.standings?.b, lang);
|
|
const mlsStR = mlsStandingLine(ex?.standings?.a, lang);
|
|
const h2h = ex?.h2h ?? [];
|
|
const flagCls = isClub ? "mx-auto h-[72px] w-[72px]" : "mx-auto h-[68px] w-[104px]";
|
|
|
|
return (
|
|
<section className="mt-6">
|
|
{/* 대결 카드 (녹색 글로우 보더) */}
|
|
<div
|
|
className="relative rounded-3xl border-2 border-[var(--green)] bg-[#171b21] p-5"
|
|
style={{ boxShadow: "0 0 28px rgba(74,255,160,0.35), inset 0 0 24px rgba(74,255,160,0.06)" }}
|
|
>
|
|
{/* 파도타기 마스코트 — 월드컵 전용 (야구·MLS 미노출) */}
|
|
{!isClub && (
|
|
<div className="absolute right-2 top-2 z-10">
|
|
<WaveStrip />
|
|
</div>
|
|
)}
|
|
|
|
{/* 헤더: 브랜드 아이콘 + 팀명 + 일시 */}
|
|
<div className="flex items-center gap-3">
|
|
<BallIcon className="h-14 w-14 shrink-0" />
|
|
<div className="min-w-0">
|
|
<div className="text-[22px] font-extrabold leading-tight">
|
|
{teamShort(left, lang)} <span className="text-white/55">vs</span>{" "}
|
|
{teamShort(right, lang)}
|
|
</div>
|
|
<div className="mt-1 text-[15px] font-bold text-[var(--green)]">
|
|
{kickoffDisplay(match.kickoffKst, lang)} ·{" "}
|
|
{!isBaseball && group ? t.group(group) : tRound(match.roundLabel, lang)}
|
|
</div>
|
|
<div className="mt-0.5 text-[12px] text-white/65">
|
|
{match.venue}
|
|
{isClub && (
|
|
<span className="text-white/40">
|
|
{" "}· {lang === "en" ? "Home: " : "홈 "}{teamShort(match.teamB, lang)}
|
|
</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* 국기/로고 + 라이트닝 VS (종료 시 최종 스코어) + 팀별 응원가 버튼(KBO) */}
|
|
<div className="mt-5 grid grid-cols-[1fr_auto_1fr] items-center gap-3">
|
|
<div className="flex flex-col items-center gap-2.5">
|
|
<TeamFlag team={left} className={flagCls} />
|
|
{isClub && (
|
|
<CheerSongButton matchId={match.matchId} teamCode={left.code} lang={lang} />
|
|
)}
|
|
</div>
|
|
<div className="relative grid place-items-center">
|
|
<div className="vs-glow absolute h-28 w-28" />
|
|
{finished && match.result ? (
|
|
<span className="relative whitespace-nowrap font-mono text-[34px] font-extrabold tabular-nums text-white">
|
|
{leftScore}
|
|
<span className="px-1 text-white/55">-</span>
|
|
{rightScore}
|
|
</span>
|
|
) : (
|
|
<span
|
|
className="relative font-impact text-[46px] italic leading-none text-[var(--green)]"
|
|
style={{ textShadow: "0 0 18px rgba(74,255,160,0.8)" }}
|
|
>
|
|
VS
|
|
</span>
|
|
)}
|
|
</div>
|
|
<div className="flex flex-col items-center gap-2.5">
|
|
<TeamFlag team={right} className={flagCls} />
|
|
{isClub && (
|
|
<CheerSongButton matchId={match.matchId} teamCode={right.code} lang={lang} />
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* 야구 정보 패널: 선발 매치업 · 순위 · 시즌 상대전적 (캐시 있을 때만) */}
|
|
{isBaseball && (spL || spR || stL || stR || hasVs) && (
|
|
<div className="mt-4 rounded-2xl bg-white/[0.04] p-3.5 text-[12px]">
|
|
{(spL || spR) && (
|
|
<div className="grid grid-cols-[1fr_auto_1fr] items-start gap-2">
|
|
<div className="min-w-0">
|
|
<div className="truncate font-extrabold text-white/90">
|
|
{spL?.name ?? (lang === "en" ? "TBA" : "미정")}
|
|
{spL?.hitType ? (
|
|
<span className="ml-1 font-semibold text-white/40">{spL.hitType.slice(0, 2)}</span>
|
|
) : null}
|
|
</div>
|
|
{spL?.era != null && (
|
|
<div className="mt-0.5 text-white/50">
|
|
ERA {spL.era}
|
|
{spL.w != null ? ` · ${spL.w}${lang === "en" ? "W" : "승"}${spL.l ?? 0}${lang === "en" ? "L" : "패"}` : ""}
|
|
</div>
|
|
)}
|
|
</div>
|
|
<span className="pt-0.5 text-[11px] font-bold text-[var(--green)]">
|
|
{lang === "en" ? "Starting P" : "선발 투수"}
|
|
</span>
|
|
<div className="min-w-0 text-right">
|
|
<div className="truncate font-extrabold text-white/90">
|
|
{spR?.hitType ? (
|
|
<span className="mr-1 font-semibold text-white/40">{spR.hitType.slice(0, 2)}</span>
|
|
) : null}
|
|
{spR?.name ?? (lang === "en" ? "TBA" : "미정")}
|
|
</div>
|
|
{spR?.era != null && (
|
|
<div className="mt-0.5 text-white/50">
|
|
ERA {spR.era}
|
|
{spR.w != null ? ` · ${spR.w}${lang === "en" ? "W" : "승"}${spR.l ?? 0}${lang === "en" ? "L" : "패"}` : ""}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{(stL || stR) && (
|
|
<div className="mt-2.5 flex items-center justify-between border-t border-white/10 pt-2.5 text-white/55">
|
|
<span className="truncate">{stL ?? "—"}</span>
|
|
<span className="px-2 text-[10px] text-white/30">{lang === "en" ? "STANDINGS" : "순위"}</span>
|
|
<span className="truncate text-right">{stR ?? "—"}</span>
|
|
</div>
|
|
)}
|
|
|
|
{hasVs && (
|
|
<div className="mt-2.5 border-t border-white/10 pt-2.5">
|
|
<div className="flex items-center justify-between font-bold text-white/75">
|
|
<span>{vs!.aWin}{lang === "en" ? "W" : "승"}</span>
|
|
<span className="text-[10px] text-white/35">
|
|
{lang === "en" ? "SEASON H2H" : "시즌 상대전적"}
|
|
{vs!.draw ? ` · ${vs!.draw}${lang === "en" ? "D" : "무"}` : ""}
|
|
</span>
|
|
<span>{vs!.bWin}{lang === "en" ? "W" : "승"}</span>
|
|
</div>
|
|
<div className="mt-1.5 flex h-1.5 gap-0.5 overflow-hidden rounded-full">
|
|
<div
|
|
className="bg-[var(--green)]/80"
|
|
style={{ width: `${(100 * (vs!.aWin ?? 0)) / Math.max(1, (vs!.aWin ?? 0) + (vs!.bWin ?? 0))}%` }}
|
|
/>
|
|
<div className="flex-1 bg-white/20" />
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{/* MLS 정보 패널: 최근 5경기 폼 · 컨퍼런스 순위 · 최근 맞대결 (캐시 있을 때만) */}
|
|
{isMls && (ex?.formA || ex?.formB || mlsStL || mlsStR || h2h.length > 0) && (
|
|
<div className="mt-4 rounded-2xl bg-white/[0.04] p-3.5 text-[12px]">
|
|
{(ex?.formA || ex?.formB) && (
|
|
<div className="grid grid-cols-[1fr_auto_1fr] items-center gap-2">
|
|
<div className="min-w-0">
|
|
<FormBadges form={ex?.formB} />
|
|
{ex?.recordB && (
|
|
<span className="ml-1.5 text-white/45">{ex.recordB}</span>
|
|
)}
|
|
</div>
|
|
<span className="text-[11px] font-bold text-[var(--green)]">
|
|
{lang === "en" ? "Last 5 · W-L-D" : "최근 5경기 · 시즌"}
|
|
</span>
|
|
<div className="min-w-0 text-right">
|
|
{ex?.recordA && (
|
|
<span className="mr-1.5 text-white/45">{ex.recordA}</span>
|
|
)}
|
|
<FormBadges form={ex?.formA} />
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{(mlsStL || mlsStR) && (
|
|
<div className="mt-2.5 flex items-center justify-between border-t border-white/10 pt-2.5 text-white/55">
|
|
<span className="truncate">{mlsStL ?? "—"}</span>
|
|
<span className="px-2 text-[10px] text-white/30">{lang === "en" ? "STANDINGS" : "순위"}</span>
|
|
<span className="truncate text-right">{mlsStR ?? "—"}</span>
|
|
</div>
|
|
)}
|
|
|
|
{h2h.length > 0 && (
|
|
<div className="mt-2.5 border-t border-white/10 pt-2.5">
|
|
<div className="mb-1 text-center text-[10px] text-white/35">
|
|
{lang === "en" ? "RECENT H2H" : "최근 맞대결"}
|
|
</div>
|
|
<ul className="space-y-0.5 text-center font-mono text-[11px] text-white/60">
|
|
{h2h.slice(0, 3).map((g, i) => (
|
|
<li key={i}>
|
|
<span className="text-white/35">{g.date.slice(5).replace("-", ".")}</span>{" "}
|
|
{g.home} {g.scoreH}
|
|
<span className="px-1 text-white/30">:</span>
|
|
{g.scoreA} {g.away}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{finished && (
|
|
<div className="mt-3 text-center text-[12px] font-bold text-[var(--green)]">
|
|
{t.matchEnded}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|