Files
lolympus-tournament-support/apps/web/src/pages/MatchGameDetailPage.tsx
T

2203 lines
70 KiB
TypeScript

import { useState } from "react";
import { Link, useLocation, useParams } from "react-router";
import {
Area,
AreaChart,
CartesianGrid,
Line,
ReferenceLine,
ResponsiveContainer,
Tooltip,
XAxis,
YAxis,
} from "recharts";
import { useDdragonManifest, useInternalMatchDetail } from "../api/hooks";
import type { ApiInternalMatchDetailResponse, TeamSide } from "../api/types";
import { DEFAULT_COMMUNITY_ID } from "../config";
import {
championDisplayName,
championIconUrl,
itemIconUrl,
runeIconUrl,
runeKeystoneIconUrl,
runeStyleIconUrl,
summonerSpellIconUrl,
} from "../lib/ddragon";
import {
sideShortLabel,
teamIndexColorClasses,
teamIndexLabel,
} from "../lib/league";
import {
internalMatchDetailPath,
internalMatchGamePath,
} from "../lib/internal-match-routes";
import { LANE_LABELS } from "../lib/riot-history";
type MatchGameDetail = ApiInternalMatchDetailResponse["games"][number];
type MatchGameTeam = MatchGameDetail["teams"][number];
type MatchGameParticipant = MatchGameTeam["participants"][number];
type DdragonManifestData = ReturnType<typeof useDdragonManifest>["data"];
type RuneStyleEntry = NonNullable<DdragonManifestData>["runesReforged"][number];
type DetailTab = "scoreboard" | "matchup" | "build";
type TimelineMetric = "gold" | "xp";
type MatchGameBackTarget = {
to: string;
label: string;
};
type MatchGameNavigationState = {
backTo: string;
backLabel: string;
};
const DETAIL_TABS: Array<{ id: DetailTab; label: string }> = [
{ id: "scoreboard", label: "스코어보드" },
{ id: "matchup", label: "라인전" },
{ id: "build", label: "룬 / 빌드" },
];
const TIMELINE_METRICS: Array<{ id: TimelineMetric; label: string }> = [
{ id: "gold", label: "골드" },
{ id: "xp", label: "경험치" },
];
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null;
}
function resolveBackTarget(
state: unknown,
fallbackTo: string,
): MatchGameBackTarget {
if (
isRecord(state) &&
typeof state.backTo === "string" &&
state.backTo.startsWith("/") &&
!state.backTo.startsWith("//")
) {
return {
to: state.backTo,
label:
typeof state.backLabel === "string"
? state.backLabel
: "돌아가기",
};
}
return {
to: fallbackTo,
label: "경기 결과로 돌아가기",
};
}
function createNavigationState(
backTarget: MatchGameBackTarget,
fallbackTo: string,
): MatchGameNavigationState | undefined {
if (backTarget.to === fallbackTo) return undefined;
return {
backTo: backTarget.to,
backLabel: backTarget.label,
};
}
const SKILL_ROWS: Array<{
slot: 1 | 2 | 3 | 4;
label: string;
className: string;
}> = [
{ slot: 1, label: "Q", className: "bg-blue-500 text-white" },
{ slot: 2, label: "W", className: "bg-cyan-500 text-white" },
{ slot: 3, label: "E", className: "bg-amber-500 text-black" },
{ slot: 4, label: "R", className: "bg-red-500 text-white" },
];
const STAT_PERK_LABELS: Record<number, string> = {
5001: "체력",
5002: "방어",
5003: "마저",
5005: "공속",
5007: "가속",
5008: "적응",
5010: "이속",
5011: "체력",
};
function formatDateTime(value: string | number) {
return new Intl.DateTimeFormat("ko-KR", {
month: "long",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
}).format(new Date(value));
}
function formatDuration(seconds: number) {
const minutes = Math.floor(seconds / 60);
const rest = seconds % 60;
return `${minutes}:${String(rest).padStart(2, "0")}`;
}
function formatNumber(value: number) {
return new Intl.NumberFormat("ko-KR").format(value);
}
function formatCompactNumber(value: number) {
if (value >= 1000) return `${(value / 1000).toFixed(1)}K`;
return String(value);
}
function formatSignedCompactNumber(value: number) {
if (value === 0) return "0";
return `${value > 0 ? "+" : "-"}${formatCompactNumber(Math.abs(value))}`;
}
function formatGameVersion(value: string | undefined) {
if (!value) return null;
const [major, minor] = value.split(".");
return major && minor ? `${major}.${minor}` : value;
}
function formatKda(kills: number, deaths: number, assists: number) {
if (deaths === 0) return kills + assists > 0 ? "Perfect" : "-";
return ((kills + assists) / deaths).toFixed(2);
}
function formatPercent(value: number) {
return `${value}%`;
}
function barWidth(value: number, max: number) {
return `${Math.max(0, Math.min(100, max > 0 ? (value / max) * 100 : 0))}%`;
}
function sideLabel(side: TeamSide) {
return sideShortLabel(side);
}
function sideTone(side: TeamSide) {
return side === "blue"
? {
border: "border-blue-500/20",
bg: "bg-blue-500/5",
text: "text-blue-400",
bar: "bg-blue-500",
}
: {
border: "border-red-500/20",
bg: "bg-red-500/5",
text: "text-red-400",
bar: "bg-red-500",
};
}
function teamTotals(team: MatchGameTeam) {
return team.participants.reduce(
(totals, participant) => ({
kills: totals.kills + participant.kills,
deaths: totals.deaths + participant.deaths,
assists: totals.assists + participant.assists,
gold: totals.gold + participant.gold,
damage: totals.damage + participant.damageDealtToChampions,
damageTaken: totals.damageTaken + (participant.damageTaken ?? 0),
vision: totals.vision + participant.visionScore,
}),
{
kills: 0,
deaths: 0,
assists: 0,
gold: 0,
damage: 0,
damageTaken: 0,
vision: 0,
},
);
}
function getTeamName(
detail: ApiInternalMatchDetailResponse,
teamIndex: number,
) {
return teamIndexLabel(
teamIndex,
detail.match.teams.find((team) => team.teamIndex === teamIndex)?.name,
);
}
function resolveSelectedSeries(
detail: ApiInternalMatchDetailResponse,
selectedGame: MatchGameDetail,
) {
const teamIndexes = selectedGame.teams.map((team) => team.teamIndex);
return detail.match.seriesResults.find(
(series) =>
teamIndexes.includes(series.teamAIndex) &&
teamIndexes.includes(series.teamBIndex),
);
}
function participantBuildKey(participant: MatchGameParticipant) {
return `${participant.side}-${participant.userId ?? participant.summonerName}-${participant.championId}`;
}
function findRuneStyle(
manifest: DdragonManifestData,
styleId: number | undefined,
) {
return manifest?.runesReforged.find((style) => style.id === styleId) ?? null;
}
function selectedRuneIds(participant: MatchGameParticipant) {
const explicit = participant.perks.selectedPerkIds ?? [];
const fromStyles =
participant.perks.styles?.flatMap((style) => style.perkIds) ?? [];
return new Set([
...explicit,
...fromStyles,
...(participant.perks.keystone ? [participant.perks.keystone] : []),
]);
}
function runeStyleSelection(
participant: MatchGameParticipant,
styleId: number | undefined,
) {
return participant.perks.styles?.find((style) => style.styleId === styleId);
}
function WinBadge({ win }: { win: boolean }) {
return win ? (
<span className="inline-flex items-center border border-accent/60 bg-accent px-2 py-0.5 text-xs font-black text-accent-content">
승리
</span>
) : (
<span className="inline-flex items-center border border-base-content/15 px-2 py-0.5 text-xs font-bold text-base-content/40">
패배
</span>
);
}
function ChampionCell({
participant,
manifest,
}: {
participant: MatchGameParticipant;
manifest: ReturnType<typeof useDdragonManifest>["data"];
}) {
const icon = championIconUrl(manifest, participant.championId);
const name =
championDisplayName(manifest, participant.championId) ??
String(participant.championId);
return (
<div className="flex min-w-0 items-center gap-2">
<span className="relative h-10 w-10 shrink-0 overflow-hidden bg-base-content/10">
{icon ? (
<img src={icon} alt={name} className="h-full w-full object-cover" />
) : null}
{participant.championLevel > 0 && (
<span className="absolute bottom-0 right-0 min-w-4 bg-base-300 px-1 text-center text-[10px] font-black leading-4 text-base-content">
{participant.championLevel}
</span>
)}
</span>
<div className="min-w-0">
<span className="block truncate text-sm font-bold text-base-content">
{name}
</span>
<span className="text-xs text-base-content/35">
{LANE_LABELS[participant.teamPosition] ??
participant.teamPosition ??
"-"}
</span>
</div>
</div>
);
}
function SpellRuneStrip({
participant,
manifest,
}: {
participant: MatchGameParticipant;
manifest: ReturnType<typeof useDdragonManifest>["data"];
}) {
const spellIcons = participant.summonerSpells
.map((spellId) => summonerSpellIconUrl(manifest, spellId))
.filter((icon): icon is string => Boolean(icon));
const runeIcons = [
runeKeystoneIconUrl(manifest, participant.perks.keystone),
runeStyleIconUrl(manifest, participant.perks.subStyle),
].filter((icon): icon is string => Boolean(icon));
return (
<div className="flex items-center gap-1.5">
<div className="grid grid-cols-1 gap-0.5">
{[0, 1].map((index) => (
<span
key={`spell-${index}`}
className="h-5 w-5 overflow-hidden bg-base-content/10"
>
{spellIcons[index] ? (
<img
src={spellIcons[index]}
alt=""
className="h-full w-full object-cover"
/>
) : null}
</span>
))}
</div>
<div className="grid grid-cols-1 gap-0.5">
{[0, 1].map((index) => (
<span
key={`rune-${index}`}
className="h-5 w-5 overflow-hidden bg-base-content/10"
>
{runeIcons[index] ? (
<img
src={runeIcons[index]}
alt=""
className="h-full w-full object-cover"
/>
) : null}
</span>
))}
</div>
</div>
);
}
function ItemStrip({
participant,
manifest,
}: {
participant: MatchGameParticipant;
manifest: ReturnType<typeof useDdragonManifest>["data"];
}) {
const itemIds = [
...Array.from({ length: 6 }, (_, index) => participant.items[index] ?? 0),
participant.trinket,
];
return (
<div className="grid grid-cols-7 gap-0.5">
{itemIds.map((itemId, index) => {
const icon = itemIconUrl(manifest, itemId);
return (
<span
key={`${itemId}-${index}`}
className="h-8 w-8 overflow-hidden border border-base-content/5 bg-base-content/10"
>
{icon ? (
<img src={icon} alt="" className="h-full w-full object-cover" />
) : null}
</span>
);
})}
</div>
);
}
function PercentBar({ value, side }: { value: number; side: TeamSide }) {
const width = `${Math.max(0, Math.min(100, value))}%`;
return (
<div className="mt-1 h-1.5 bg-base-content/8">
<div className={`h-full ${sideTone(side).bar}`} style={{ width }} />
</div>
);
}
function PlayerIdentityCell({
participant,
manifest,
avatarSize = "h-12 w-12",
nameMaxWidth = "max-w-[150px]",
}: {
participant: MatchGameParticipant;
manifest: ReturnType<typeof useDdragonManifest>["data"];
avatarSize?: string;
nameMaxWidth?: string;
}) {
const location = useLocation();
const historyBackTo = `${location.pathname}${location.search}${location.hash}`;
const lane =
LANE_LABELS[participant.teamPosition] ?? participant.teamPosition ?? "-";
const nameNode = (
<>
{participant.summonerName}
{participant.tagLine ? (
<span className="font-normal text-base-content/30">
{" "}
#{participant.tagLine}
</span>
) : null}
</>
);
return (
<div className="flex min-w-0 items-center gap-2">
<ChampionAvatar
participant={participant}
manifest={manifest}
size={avatarSize}
/>
<SpellRuneStrip participant={participant} manifest={manifest} />
<div className="min-w-0">
{participant.userId ? (
<Link
to={`/users/${participant.userId}/history?queueGroup=internal`}
state={{ backTo: historyBackTo }}
className={`block ${nameMaxWidth} truncate text-sm font-bold text-base-content hover:text-primary`}
>
{nameNode}
</Link>
) : (
<span
className={`block ${nameMaxWidth} truncate text-sm font-bold text-base-content`}
>
{nameNode}
</span>
)}
<div className="mt-0.5 flex items-center gap-1.5">
<span className="text-xs text-base-content/35">{lane}</span>
{(participant.firstBloodKill || participant.firstBloodAssist) && (
<span className="inline-flex border border-amber-400/30 bg-amber-400/10 px-1 text-[10px] font-black text-amber-400">
{participant.firstBloodKill ? "FB" : "FBA"}
</span>
)}
</div>
</div>
</div>
);
}
function PlayerRow({
participant,
manifest,
teamDamageTaken,
}: {
participant: MatchGameParticipant;
manifest: ReturnType<typeof useDdragonManifest>["data"];
teamDamageTaken: number;
}) {
const takenShare =
teamDamageTaken > 0
? ((participant.damageTaken ?? 0) / teamDamageTaken) * 100
: 0;
return (
<tr className="border-t border-base-content/5 hover:bg-base-content/[0.02]">
<td className="px-3 py-2.5">
<PlayerIdentityCell participant={participant} manifest={manifest} />
</td>
<td className="px-3 py-2.5 text-center">
<div className="text-sm font-black tabular-nums text-base-content">
{participant.kills}
<span className="text-base-content/25"> / </span>
<span className="text-red-400">{participant.deaths}</span>
<span className="text-base-content/25"> / </span>
{participant.assists}
</div>
<div className="text-xs font-bold tabular-nums text-base-content/40">
{formatKda(
participant.kills,
participant.deaths,
participant.assists,
)}
<span className="ml-1 text-base-content/35">
({participant.killParticipation}%)
</span>
</div>
</td>
<td className="px-3 py-2.5 text-center text-xs tabular-nums text-base-content/60">
{formatNumber(participant.damageDealtToChampions)}
<div className="mx-auto w-16">
<PercentBar value={participant.damageShare} side={participant.side} />
</div>
<span className="text-base-content/35">
{formatPercent(participant.damageShare)}
</span>
</td>
<td className="px-3 py-2.5 text-center text-xs tabular-nums text-base-content/60">
{formatNumber(participant.damageTaken ?? 0)}
<div className="mx-auto w-16">
<PercentBar value={takenShare} side={participant.side} />
</div>
<span className="text-base-content/35">{Math.round(takenShare)}%</span>
</td>
<td className="px-3 py-2.5 text-center text-xs tabular-nums text-base-content/60">
{participant.visionScore}
<span className="block text-base-content/35">
와드 {participant.wardsPlaced ?? 0}/{participant.wardsKilled ?? 0}
</span>
<span className="block text-base-content/30">
제어 {participant.controlWardsBought ?? 0}
</span>
</td>
<td className="px-3 py-2.5 text-center text-xs tabular-nums text-base-content/60">
{participant.cs}
<span className="block text-base-content/35">
{participant.csPerMin}/m
</span>
</td>
<td className="px-3 py-2.5">
<ItemStrip participant={participant} manifest={manifest} />
</td>
</tr>
);
}
function PlayerCard({
participant,
manifest,
teamDamageTaken,
}: {
participant: MatchGameParticipant;
manifest: ReturnType<typeof useDdragonManifest>["data"];
teamDamageTaken: number;
}) {
const takenShare =
teamDamageTaken > 0
? ((participant.damageTaken ?? 0) / teamDamageTaken) * 100
: 0;
return (
<div className="p-3">
<div className="flex items-start justify-between gap-2">
<PlayerIdentityCell participant={participant} manifest={manifest} />
<div className="shrink-0 text-right">
<div className="text-sm font-black tabular-nums text-base-content">
{participant.kills}
<span className="text-base-content/25"> / </span>
<span className="text-red-400">{participant.deaths}</span>
<span className="text-base-content/25"> / </span>
{participant.assists}
</div>
<div className="text-[11px] font-bold tabular-nums text-base-content/40">
{formatKda(
participant.kills,
participant.deaths,
participant.assists,
)}
<span className="ml-1 text-base-content/35">
({participant.killParticipation}%)
</span>
</div>
</div>
</div>
<div className="mt-2">
<ItemStrip participant={participant} manifest={manifest} />
</div>
<div className="mt-2 grid grid-cols-2 gap-2 text-[11px] tabular-nums sm:grid-cols-4">
<div className="border border-base-content/8 px-2 py-1.5">
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
가한 피해량
</div>
<div className="mt-0.5 font-black text-base-content/70">
{formatNumber(participant.damageDealtToChampions)}
<span className="ml-1 font-bold text-base-content/35">
{formatPercent(participant.damageShare)}
</span>
</div>
<PercentBar value={participant.damageShare} side={participant.side} />
</div>
<div className="border border-base-content/8 px-2 py-1.5">
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
받은 피해량
</div>
<div className="mt-0.5 font-black text-base-content/70">
{formatNumber(participant.damageTaken ?? 0)}
<span className="ml-1 font-bold text-base-content/35">
{Math.round(takenShare)}%
</span>
</div>
<PercentBar value={takenShare} side={participant.side} />
</div>
<div className="border border-base-content/8 px-2 py-1.5">
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
CS
</div>
<div className="mt-0.5 font-black text-base-content/70">
{participant.cs}
<span className="ml-1 font-bold text-base-content/35">
{participant.csPerMin}/m
</span>
</div>
</div>
<div className="border border-base-content/8 px-2 py-1.5">
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
시야
</div>
<div className="mt-0.5 font-black text-base-content/70">
{participant.visionScore}
<span className="ml-1 font-bold text-base-content/35">
{participant.wardsPlaced ?? 0}/{participant.wardsKilled ?? 0}
</span>
</div>
</div>
</div>
</div>
);
}
function TeamScoreHeader({
team,
detail,
}: {
team: MatchGameTeam;
detail: ApiInternalMatchDetailResponse;
}) {
const tone = sideTone(team.side);
const teamTone = teamIndexColorClasses(team.teamIndex);
const totals = teamTotals(team);
return (
<div
className={`border-b border-base-content/8 px-4 py-3 ${tone.bg} ${tone.border}`}
>
<div className="flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between">
<div className="flex min-w-0 items-center gap-3">
<span
className={`h-8 w-1 shrink-0 ${teamTone.bar}`}
aria-hidden="true"
/>
<div className="min-w-0">
<div className="flex flex-wrap items-center gap-2">
<h2 className={`text-sm font-black ${teamTone.text}`}>
{getTeamName(detail, team.teamIndex)}
</h2>
<span
className={`border px-2 py-0.5 text-xs font-black ${tone.text} ${tone.border}`}
>
{sideLabel(team.side)}
</span>
<WinBadge win={team.win} />
</div>
<div className="mt-1 text-xs text-base-content/45">
타워 {team.objectives.tower} · 드래곤 {team.objectives.dragon} ·
억제기 {team.objectives.inhibitor} · 바론 {team.objectives.baron}
</div>
</div>
</div>
<div className="flex shrink-0 items-center gap-4 text-sm font-black tabular-nums">
<div className="flex items-baseline gap-1.5">
<span className="text-[10px] font-bold uppercase tracking-wider text-base-content/35">
KDA
</span>
<span className="text-base-content">
{totals.kills} / {totals.deaths} / {totals.assists}
</span>
</div>
<div className="flex items-baseline gap-1.5">
<span className="text-[10px] font-bold uppercase tracking-wider text-base-content/35">
Gold
</span>
<span className="text-base-content">
{formatCompactNumber(totals.gold)}
</span>
</div>
</div>
</div>
</div>
);
}
function BanStrip({
bans,
manifest,
}: {
bans: MatchGameTeam["bans"] | undefined;
manifest: ReturnType<typeof useDdragonManifest>["data"];
}) {
const sortedBans = [...(bans ?? [])].sort(
(left, right) => left.pickTurn - right.pickTurn,
);
return (
<div className="flex flex-wrap items-center justify-start gap-1.5 sm:justify-end">
{sortedBans.length > 0 ? (
sortedBans.map((ban) => {
const icon = championIconUrl(manifest, ban.championId);
const name =
championDisplayName(manifest, ban.championId) ??
String(ban.championId);
return (
<span
key={`${ban.championId}-${ban.pickTurn}`}
className="h-8 w-8 overflow-hidden border border-base-content/5 bg-base-content/10 opacity-80"
title={name}
>
{icon ? (
<img
src={icon}
alt={name}
className="h-full w-full object-cover"
/>
) : null}
</span>
);
})
) : (
<span className="text-xs font-bold text-base-content/30">밴 없음</span>
)}
</div>
);
}
function PostgameBreakdown({
selectedGame,
detail,
manifest,
}: {
selectedGame: MatchGameDetail;
detail: ApiInternalMatchDetailResponse;
manifest: ReturnType<typeof useDdragonManifest>["data"];
}) {
const orderedTeams = [...selectedGame.teams].sort((left, right) =>
left.side === right.side ? 0 : left.side === "blue" ? -1 : 1,
);
const version = formatGameVersion(selectedGame.gameVersion);
return (
<section className="mt-5 overflow-hidden border border-base-content/10 bg-base-100">
<div className="flex flex-wrap items-center justify-between gap-3 border-b border-base-content/8 px-4 py-3">
<h2 className="text-sm font-black text-base-content">경기 요약</h2>
<div className="flex flex-wrap items-center gap-2 text-xs font-bold text-base-content/35">
{version ? <span>Ver. {version}</span> : null}
<span>{formatDuration(selectedGame.gameDuration)}</span>
<span className="font-mono">{selectedGame.riotMatchId}</span>
</div>
</div>
<div className="grid gap-0 sm:grid-cols-2">
{orderedTeams.map((team) => {
const tone = sideTone(team.side);
const teamTone = teamIndexColorClasses(team.teamIndex);
return (
<div
key={`${team.side}-bans`}
className={`flex flex-wrap items-center justify-between gap-2 border-b border-base-content/8 px-4 py-2.5 last:border-b-0 sm:border-b-0 sm:border-r sm:last:border-r-0 ${tone.bg}`}
>
<div className="flex items-center gap-2">
<span className={`text-xs font-black ${teamTone.text}`}>
{getTeamName(detail, team.teamIndex)}
</span>
<span className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
밴
</span>
</div>
<BanStrip bans={team.bans} manifest={manifest} />
</div>
);
})}
</div>
<GoldComparisonStrip selectedGame={selectedGame} detail={detail} />
</section>
);
}
function GoldComparisonStrip({
selectedGame,
detail,
}: {
selectedGame: MatchGameDetail;
detail: ApiInternalMatchDetailResponse;
}) {
const blueTeam = selectedGame.teams.find((team) => team.side === "blue");
const redTeam = selectedGame.teams.find((team) => team.side === "red");
if (!blueTeam || !redTeam) return null;
const blueTotals = teamTotals(blueTeam);
const redTotals = teamTotals(redTeam);
const goldDiff = blueTotals.gold - redTotals.gold;
const maxGold = Math.max(1, blueTotals.gold, redTotals.gold);
const leaderSide =
goldDiff > 0 ? "blue" : goldDiff < 0 ? "red" : ("blue" as TeamSide);
const leaderName =
goldDiff === 0
? "동률"
: getTeamName(
detail,
leaderSide === "blue" ? blueTeam.teamIndex : redTeam.teamIndex,
);
return (
<div className="border-t border-base-content/8 bg-base-content/[0.01] px-4 py-3">
<div className="grid gap-3 md:grid-cols-[minmax(0,1fr)_11rem_minmax(0,1fr)] md:items-center">
<div className="min-w-0 text-blue-400">
<div className="flex items-center justify-between gap-3 text-xs font-black">
<span className="truncate">
{getTeamName(detail, blueTeam.teamIndex)}
</span>
<span className="tabular-nums">
{formatNumber(blueTotals.gold)}
</span>
</div>
<div className="mt-1 h-1.5 bg-base-content/8">
<div
className="h-full bg-blue-500"
style={{ width: barWidth(blueTotals.gold, maxGold) }}
/>
</div>
</div>
<div className="text-center">
<div className="text-[10px] font-black uppercase tracking-wider text-base-content/30">
골드 차이
</div>
<div
className={`mt-1 text-lg font-black tabular-nums ${
goldDiff > 0
? "text-blue-400"
: goldDiff < 0
? "text-red-400"
: "text-base-content/55"
}`}
>
{formatSignedCompactNumber(goldDiff)}
</div>
<div className="mt-0.5 truncate text-[11px] font-bold text-base-content/35">
{leaderName}
</div>
</div>
<div className="min-w-0 text-red-400">
<div className="flex items-center justify-between gap-3 text-xs font-black">
<span className="tabular-nums">{formatNumber(redTotals.gold)}</span>
<span className="truncate text-right">
{getTeamName(detail, redTeam.teamIndex)}
</span>
</div>
<div className="mt-1 h-1.5 bg-base-content/8">
<div
className="ml-auto h-full bg-red-500"
style={{ width: barWidth(redTotals.gold, maxGold) }}
/>
</div>
</div>
</div>
</div>
);
}
interface TimelineChartPoint {
timestamp: number;
timeLabel: string;
value: number;
positive: number;
negative: number;
blueTotal: number;
redTotal: number;
leaderSide: TeamSide | null;
}
function TimelineTooltip({
active,
payload,
blueTeamName,
redTeamName,
metricLabel,
}: {
active?: boolean;
payload?: Array<{ payload: TimelineChartPoint }>;
blueTeamName: string;
redTeamName: string;
metricLabel: string;
}) {
const point = payload?.[0]?.payload;
if (!active || !point) return null;
const leaderName =
point.leaderSide === "blue"
? blueTeamName
: point.leaderSide === "red"
? redTeamName
: "동률";
return (
<div className="border border-base-content/10 bg-base-100 px-3 py-2 text-xs shadow-lg">
<div className="font-black text-base-content">{point.timeLabel}</div>
<div className="mt-1 font-bold text-base-content/55">
{leaderName} {formatSignedCompactNumber(point.value)}
</div>
<div className="mt-2 grid grid-cols-2 gap-3 tabular-nums">
<div className="text-blue-400">
{blueTeamName}
<span className="block font-black">
{formatNumber(point.blueTotal)}
</span>
</div>
<div className="text-red-400">
{redTeamName}
<span className="block font-black">
{formatNumber(point.redTotal)}
</span>
</div>
</div>
<div className="mt-1 text-[10px] font-bold uppercase tracking-wider text-base-content/30">
{metricLabel}
</div>
</div>
);
}
function TimelineGraph({
selectedGame,
detail,
}: {
selectedGame: MatchGameDetail;
detail: ApiInternalMatchDetailResponse;
}) {
const [metric, setMetric] = useState<TimelineMetric>("gold");
const blueTeam = selectedGame.teams.find((team) => team.side === "blue");
const redTeam = selectedGame.teams.find((team) => team.side === "red");
const blueTeamName = blueTeam
? getTeamName(detail, blueTeam.teamIndex)
: "BLUE";
const redTeamName = redTeam ? getTeamName(detail, redTeam.teamIndex) : "RED";
const metricLabel = metric === "gold" ? "골드" : "경험치";
const chartData: TimelineChartPoint[] = (selectedGame.timeline ?? []).map(
(point) => {
const value = metric === "gold" ? point.goldDiff : point.xpDiff;
return {
timestamp: point.timestamp,
timeLabel: formatDuration(point.timestamp),
value,
positive: Math.max(value, 0),
negative: Math.min(value, 0),
blueTotal: metric === "gold" ? point.blue.gold : point.blue.xp,
redTotal: metric === "gold" ? point.red.gold : point.red.xp,
leaderSide: value > 0 ? "blue" : value < 0 ? "red" : null,
};
},
);
const maxAbs = Math.max(
1,
...chartData.map((point) => Math.abs(point.value)),
);
const finalPoint = chartData[chartData.length - 1];
const finalLeader =
finalPoint?.leaderSide === "blue"
? blueTeamName
: finalPoint?.leaderSide === "red"
? redTeamName
: "동률";
return (
<section className="mt-5 overflow-hidden border border-base-content/10 bg-base-100">
<div className="flex flex-col gap-3 border-b border-base-content/8 px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
<div>
<h2 className="text-sm font-black text-base-content">경기 흐름</h2>
<div className="mt-1 text-xs font-bold text-base-content/35">
{finalPoint
? `${finalLeader} ${formatSignedCompactNumber(finalPoint.value)}`
: "타임라인 대기"}
</div>
</div>
<div className="flex w-full border border-base-content/10 bg-base-content/[0.02] sm:w-auto">
{TIMELINE_METRICS.map((item) => (
<button
key={item.id}
type="button"
onClick={() => setMetric(item.id)}
className={`min-w-24 flex-1 border-r border-base-content/8 px-4 py-2 text-xs font-black transition-colors last:border-r-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary sm:flex-none ${
metric === item.id
? "bg-primary text-primary-content"
: "text-base-content/45 hover:bg-base-content/[0.03] hover:text-base-content"
}`}
>
{item.label}
</button>
))}
</div>
</div>
{chartData.length > 0 ? (
<div className="px-2 py-4 sm:px-4">
<div className="h-[260px] min-w-0 w-full">
<ResponsiveContainer width="100%" height="100%">
<AreaChart
data={chartData}
margin={{ top: 12, right: 12, bottom: 0, left: 0 }}
>
<CartesianGrid
stroke="currentColor"
strokeOpacity={0.08}
vertical={false}
/>
<XAxis
dataKey="timestamp"
minTickGap={28}
tickFormatter={(value) =>
`${Math.round(Number(value) / 60)}분`
}
tick={{ fill: "currentColor", fontSize: 11 }}
tickLine={false}
axisLine={false}
/>
<YAxis
domain={[-maxAbs, maxAbs]}
tickFormatter={(value) =>
formatSignedCompactNumber(Number(value))
}
tick={{ fill: "currentColor", fontSize: 11 }}
tickLine={false}
axisLine={false}
width={58}
/>
<Tooltip
content={
<TimelineTooltip
blueTeamName={blueTeamName}
redTeamName={redTeamName}
metricLabel={metricLabel}
/>
}
/>
<ReferenceLine
y={0}
stroke="currentColor"
strokeOpacity={0.25}
/>
<Area
type="monotone"
dataKey="positive"
stroke="none"
fill="#3b82f6"
fillOpacity={0.16}
isAnimationActive={false}
/>
<Area
type="monotone"
dataKey="negative"
stroke="none"
fill="#ef4444"
fillOpacity={0.16}
isAnimationActive={false}
/>
<Line
type="monotone"
dataKey="value"
stroke="var(--color-primary)"
strokeWidth={2}
dot={false}
activeDot={{
r: 4,
fill: "var(--color-primary)",
stroke: "none",
}}
isAnimationActive={false}
/>
</AreaChart>
</ResponsiveContainer>
</div>
<div className="mt-2 flex items-center justify-between gap-3 text-[11px] font-black uppercase tracking-wider">
<span className="text-blue-400">{blueTeamName}</span>
<span className="text-base-content/25">0</span>
<span className="text-red-400">{redTeamName}</span>
</div>
</div>
) : (
<div className="px-4 py-12 text-center text-sm font-bold text-base-content/35">
타임라인 데이터가 아직 없습니다
</div>
)}
</section>
);
}
function TeamTable({
team,
detail,
manifest,
}: {
team: MatchGameTeam;
detail: ApiInternalMatchDetailResponse;
manifest: ReturnType<typeof useDdragonManifest>["data"];
}) {
const teamDamageTaken = teamTotals(team).damageTaken;
return (
<section className="overflow-hidden border border-base-content/10 bg-base-100">
<TeamScoreHeader team={team} detail={detail} />
<div className="divide-y divide-base-content/5 lg:hidden">
{team.participants.map((participant) => (
<PlayerCard
key={`card-${participant.side}-${participant.userId ?? participant.summonerName}-${participant.championId}`}
participant={participant}
manifest={manifest}
teamDamageTaken={teamDamageTaken}
/>
))}
</div>
<div className="hidden overflow-x-auto lg:block">
<table className="w-full min-w-[1040px] table-fixed text-left">
<thead>
<tr className="bg-base-content/[0.02] text-xs uppercase tracking-wider text-base-content/35">
<th className="w-[276px] px-3 py-2.5">선수</th>
<th className="w-[108px] px-3 py-2.5 text-center">KDA</th>
<th className="w-[120px] px-3 py-2.5 text-center">가한 피해량</th>
<th className="w-[120px] px-3 py-2.5 text-center">받은 피해량</th>
<th className="w-[80px] px-3 py-2.5 text-center">시야</th>
<th className="w-[76px] px-3 py-2.5 text-center">CS</th>
<th className="w-[260px] px-3 py-2.5">아이템</th>
</tr>
</thead>
<tbody>
{team.participants.map((participant) => (
<PlayerRow
key={`${participant.side}-${participant.userId ?? participant.summonerName}-${participant.championId}`}
participant={participant}
manifest={manifest}
teamDamageTaken={teamDamageTaken}
/>
))}
</tbody>
</table>
</div>
</section>
);
}
function DetailTabBar({
activeTab,
onChange,
}: {
activeTab: DetailTab;
onChange: (tab: DetailTab) => void;
}) {
return (
<div className="flex overflow-x-auto border border-base-content/10 bg-base-100">
{DETAIL_TABS.map((tab) => (
<button
key={tab.id}
type="button"
onClick={() => onChange(tab.id)}
className={`min-w-[7.5rem] border-r border-base-content/8 px-4 py-3 text-xs font-black transition-colors last:border-r-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary ${
activeTab === tab.id
? "bg-primary text-primary-content"
: "text-base-content/45 hover:bg-base-content/[0.03] hover:text-base-content"
}`}
>
{tab.label}
</button>
))}
</div>
);
}
function RuneBuildPanel({
selectedGame,
detail,
manifest,
}: {
selectedGame: MatchGameDetail;
detail: ApiInternalMatchDetailResponse;
manifest: DdragonManifestData;
}) {
const orderedTeams = [...selectedGame.teams].sort((left, right) =>
left.side === right.side ? 0 : left.side === "blue" ? -1 : 1,
);
const participants = orderedTeams.flatMap((team) => team.participants);
const defaultKey = participants[0]
? participantBuildKey(participants[0])
: "";
const [selectedKey, setSelectedKey] = useState(defaultKey);
const effectiveSelectedKey = participants.some(
(participant) => participantBuildKey(participant) === selectedKey,
)
? selectedKey
: defaultKey;
const selectedParticipant =
participants.find(
(participant) =>
participantBuildKey(participant) === effectiveSelectedKey,
) ?? participants[0];
if (!selectedParticipant) {
return (
<section className="border border-base-content/10 bg-base-100 px-4 py-12 text-center text-sm font-bold text-base-content/35">
빌드 데이터가 없습니다
</section>
);
}
return (
<section className="overflow-hidden border border-base-content/10 bg-base-100">
<BuildChampionSelector
selectedGame={selectedGame}
detail={detail}
manifest={manifest}
selectedKey={participantBuildKey(selectedParticipant)}
onSelect={setSelectedKey}
/>
<div className="grid border-t border-base-content/8 lg:grid-cols-[minmax(0,1.05fr)_minmax(0,1fr)]">
<RunesPanel participant={selectedParticipant} manifest={manifest} />
<div className="border-t border-base-content/8 lg:border-l lg:border-t-0">
<ItemBuildPanel
participant={selectedParticipant}
manifest={manifest}
/>
<SkillBuildPanel participant={selectedParticipant} />
</div>
</div>
</section>
);
}
function BuildChampionSelector({
selectedGame,
detail,
manifest,
selectedKey,
onSelect,
}: {
selectedGame: MatchGameDetail;
detail: ApiInternalMatchDetailResponse;
manifest: DdragonManifestData;
selectedKey: string;
onSelect: (key: string) => void;
}) {
const orderedTeams = [...selectedGame.teams].sort((left, right) =>
left.side === right.side ? 0 : left.side === "blue" ? -1 : 1,
);
return (
<div className="grid gap-4 bg-base-content/[0.015] p-4 lg:grid-cols-2">
{orderedTeams.map((team) => {
const tone = sideTone(team.side);
return (
<div key={`build-selector-${team.side}`} className="min-w-0">
<div className="flex items-center justify-between gap-3">
<div className={`text-sm font-black ${tone.text}`}>
{sideLabel(team.side)} Side
</div>
<div className="truncate text-xs font-bold text-base-content/40">
{getTeamName(detail, team.teamIndex)}
</div>
</div>
<div className="mt-2 flex flex-wrap gap-1.5">
{team.participants.map((participant) => (
<BuildChampionButton
key={`build-select-${participantBuildKey(participant)}`}
participant={participant}
manifest={manifest}
selected={participantBuildKey(participant) === selectedKey}
onClick={() => onSelect(participantBuildKey(participant))}
/>
))}
</div>
</div>
);
})}
</div>
);
}
function BuildChampionButton({
participant,
manifest,
selected,
onClick,
}: {
participant: MatchGameParticipant;
manifest: DdragonManifestData;
selected: boolean;
onClick: () => void;
}) {
const icon = championIconUrl(manifest, participant.championId);
const championName =
championDisplayName(manifest, participant.championId) ??
String(participant.championId);
const tone = sideTone(participant.side);
return (
<button
type="button"
onClick={onClick}
title={`${participant.summonerName} · ${championName}`}
className={`relative h-11 w-11 overflow-hidden border bg-base-content/10 transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary ${
selected
? `${tone.border} opacity-100 ring-2 ring-current ${tone.text}`
: "border-base-content/5 opacity-35 hover:opacity-75"
}`}
>
{icon ? (
<img src={icon} alt="" className="h-full w-full object-cover" />
) : null}
{participant.championLevel > 0 ? (
<span className="absolute bottom-0 right-0 min-w-4 bg-base-300 px-1 text-center text-[10px] font-black leading-4 text-base-content">
{participant.championLevel}
</span>
) : null}
</button>
);
}
function RunesPanel({
participant,
manifest,
}: {
participant: MatchGameParticipant;
manifest: DdragonManifestData;
}) {
const selectedIds = selectedRuneIds(participant);
const primaryStyleId =
participant.perks.primaryStyle ?? participant.perks.styles?.[0]?.styleId;
const subStyleId =
participant.perks.subStyle ?? participant.perks.styles?.[1]?.styleId;
const primaryStyle = findRuneStyle(manifest, primaryStyleId);
const subStyle = findRuneStyle(manifest, subStyleId);
return (
<div className="p-4">
<div className="mb-4 flex min-w-0 items-center justify-between gap-3">
<div>
<div className="text-sm font-black text-base-content">Runes</div>
<div className="mt-0.5 truncate text-xs text-base-content/40">
{participant.summonerName}
</div>
</div>
<ChampionCell participant={participant} manifest={manifest} />
</div>
<div className="grid gap-4 md:grid-cols-2">
<RuneTreeColumn
label="주 룬"
runeStyle={primaryStyle}
selection={runeStyleSelection(participant, primaryStyleId)}
selectedIds={selectedIds}
manifest={manifest}
/>
<RuneTreeColumn
label="보조 룬"
runeStyle={subStyle}
selection={runeStyleSelection(participant, subStyleId)}
selectedIds={selectedIds}
manifest={manifest}
/>
</div>
<RuneShardRows participant={participant} />
</div>
);
}
function RuneTreeColumn({
label,
runeStyle,
selection,
selectedIds,
manifest,
}: {
label: string;
runeStyle: RuneStyleEntry | null;
selection: ReturnType<typeof runeStyleSelection>;
selectedIds: Set<number>;
manifest: DdragonManifestData;
}) {
if (!runeStyle) {
return (
<div className="border border-base-content/8 bg-base-content/[0.02] p-3">
<div className="text-xs font-black text-base-content/35">{label}</div>
<div className="mt-8 text-center text-xs font-bold text-base-content/35">
룬 데이터 없음
</div>
</div>
);
}
const styleIcon = runeStyleIconUrl(manifest, runeStyle.id);
const selectionIds = new Set(selection?.perkIds ?? []);
return (
<div className="border border-base-content/8 bg-base-content/[0.02] p-3">
<div className="flex items-center gap-2">
<span className="h-7 w-7 overflow-hidden bg-base-content/10">
{styleIcon ? (
<img
src={styleIcon}
alt=""
className="h-full w-full object-cover"
/>
) : null}
</span>
<div className="min-w-0">
<div className="text-xs font-black text-base-content/35">{label}</div>
<div className="truncate text-sm font-black text-base-content">
{runeStyle.name}
</div>
</div>
</div>
<div className="mt-4 space-y-3">
{runeStyle.slots.map((slot, slotIndex) => (
<div
key={`${runeStyle.id}-${slotIndex}`}
className="grid justify-start gap-2 border-b border-base-content/8 pb-3 last:border-b-0 last:pb-0"
style={{
gridTemplateColumns: `repeat(${slot.runes.length}, minmax(0, 2.25rem))`,
}}
>
{slot.runes.map((rune) => {
const selected =
selectedIds.has(rune.id) || selectionIds.has(rune.id);
const icon = runeIconUrl(manifest, rune.id);
return (
<span
key={rune.id}
title={rune.name}
className={`h-9 w-9 overflow-hidden border bg-base-content/10 transition ${
selected
? "border-base-content/20 opacity-100 ring-2 ring-base-content/20"
: "border-transparent opacity-20 grayscale"
}`}
>
{icon ? (
<img
src={icon}
alt=""
className="h-full w-full object-cover"
/>
) : null}
</span>
);
})}
</div>
))}
</div>
</div>
);
}
function RuneShardRows({ participant }: { participant: MatchGameParticipant }) {
const statPerks = participant.perks.statPerks;
const shards = [
{ label: "공격", value: statPerks?.offense },
{ label: "보조", value: statPerks?.flex },
{ label: "방어", value: statPerks?.defense },
].filter((shard) => typeof shard.value === "number" && shard.value > 0);
if (shards.length === 0) return null;
return (
<div className="mt-4 border border-base-content/8 bg-base-content/[0.02] px-3 py-2">
<div className="text-xs font-black text-base-content/35">스탯 파편</div>
<div className="mt-2 flex flex-wrap gap-2">
{shards.map((shard) => (
<span
key={`${shard.label}-${shard.value}`}
className="inline-flex items-center gap-1 border border-base-content/8 bg-base-100 px-2 py-1 text-xs font-bold text-base-content/60"
>
<span className="text-base-content/35">{shard.label}</span>
{STAT_PERK_LABELS[shard.value ?? 0] ?? shard.value}
</span>
))}
</div>
</div>
);
}
function ItemBuildPanel({
participant,
manifest,
}: {
participant: MatchGameParticipant;
manifest: DdragonManifestData;
}) {
const buildEvents = (participant.itemBuild ?? []).filter(
(event) => event.itemId > 0 && event.type === "purchased",
);
const fallbackItems = [
...participant.items.filter((itemId) => itemId > 0),
participant.trinket,
].filter((itemId) => itemId > 0);
return (
<div className="p-4">
<div className="text-sm font-black text-base-content">Item Build</div>
{buildEvents.length > 0 ? (
<div className="mt-3 flex flex-wrap items-start gap-x-2 gap-y-4">
{buildEvents.map((event, index) => (
<div
key={`${event.timestamp}-${event.itemId}-${event.type}-${index}`}
className="flex items-start gap-2"
>
<ItemBuildNode
itemId={event.itemId}
timestamp={event.timestamp}
manifest={manifest}
/>
{index < buildEvents.length - 1 ? (
<span className="pt-2 text-xs font-black text-base-content/25">
&gt;
</span>
) : null}
</div>
))}
</div>
) : fallbackItems.length > 0 ? (
<div className="mt-3 flex flex-wrap gap-1.5">
{fallbackItems.map((itemId, index) => {
const icon = itemIconUrl(manifest, itemId);
return (
<span
key={`fallback-item-${itemId}-${index}`}
className="h-9 w-9 overflow-hidden border border-base-content/8 bg-base-content/10"
>
{icon ? (
<img
src={icon}
alt=""
className="h-full w-full object-cover"
/>
) : null}
</span>
);
})}
</div>
) : (
<div className="mt-6 text-center text-xs font-bold text-base-content/35">
아이템 빌드 데이터 없음
</div>
)}
</div>
);
}
function ItemBuildNode({
itemId,
timestamp,
manifest,
}: {
itemId: number;
timestamp: number;
manifest: DdragonManifestData;
}) {
const icon = itemIconUrl(manifest, itemId);
return (
<div className="w-11 text-center">
<span className="mx-auto block h-9 w-9 overflow-hidden border border-base-content/8 bg-base-content/10">
{icon ? (
<img src={icon} alt="" className="h-full w-full object-cover" />
) : null}
</span>
<span className="mt-1 block text-[11px] font-bold tabular-nums text-base-content/35">
{formatDuration(timestamp)}
</span>
</div>
);
}
function SkillBuildPanel({
participant,
}: {
participant: MatchGameParticipant;
}) {
const skillEvents = participant.skillBuild ?? [];
const skillByLevel = new Map(
skillEvents.map((event) => [event.level, event]),
);
return (
<div className="border-t border-base-content/8 p-4">
<div className="flex items-center justify-between gap-3">
<div className="text-sm font-black text-base-content">Skill Build</div>
<div className="text-xs font-bold text-base-content/35">
Lv. {skillEvents.length || participant.championLevel || "-"}
</div>
</div>
{skillEvents.length > 0 ? (
<div className="mt-3 overflow-x-auto">
<div className="min-w-[610px] space-y-1">
{SKILL_ROWS.map((row) => (
<div
key={`skill-row-${row.slot}`}
className="grid grid-cols-[2rem_repeat(18,minmax(1.45rem,1fr))] gap-1"
>
<div
className={`flex h-7 items-center justify-center text-xs font-black ${row.className}`}
>
{row.label}
</div>
{Array.from({ length: 18 }, (_, index) => index + 1).map(
(level) => {
const event = skillByLevel.get(level);
const active = event?.skillSlot === row.slot;
return (
<div
key={`${row.slot}-${level}`}
className={`flex h-7 items-center justify-center text-[11px] font-black tabular-nums ${
active
? row.className
: "bg-base-content/[0.045] text-transparent"
}`}
>
{active ? level : ""}
</div>
);
},
)}
</div>
))}
</div>
</div>
) : (
<div className="mt-6 text-center text-xs font-bold text-base-content/35">
스킬 빌드 데이터 없음
</div>
)}
</div>
);
}
const LANE_SORT_ORDER = ["TOP", "JUNGLE", "MIDDLE", "BOTTOM", "UTILITY"];
function laneSortValue(position: string) {
const index = LANE_SORT_ORDER.indexOf(position);
return index === -1 ? 99 : index;
}
function ChampionAvatar({
participant,
manifest,
size = "h-9 w-9",
}: {
participant: MatchGameParticipant;
manifest: ReturnType<typeof useDdragonManifest>["data"];
size?: string;
}) {
const icon = championIconUrl(manifest, participant.championId);
const name =
championDisplayName(manifest, participant.championId) ??
String(participant.championId);
return (
<span
className={`relative ${size} shrink-0 overflow-hidden bg-base-content/10`}
title={name}
>
{icon ? (
<img src={icon} alt={name} className="h-full w-full object-cover" />
) : null}
{participant.championLevel > 0 ? (
<span className="absolute bottom-0 right-0 min-w-4 bg-base-300 px-1 text-center text-[10px] font-black leading-4 text-base-content">
{participant.championLevel}
</span>
) : null}
</span>
);
}
function MatchupMetricRow({
label,
blueLead,
redLead,
blueText,
redText,
bluePct,
}: {
label: string;
blueLead: boolean;
redLead: boolean;
blueText: string;
redText: string;
bluePct: number;
}) {
return (
<div className="px-3 py-2">
<div className="grid grid-cols-[1fr_auto_1fr] items-center gap-2 text-xs">
<span
className={`text-right tabular-nums ${
blueLead
? "font-black text-blue-400"
: "font-bold text-base-content/55"
}`}
>
{blueText}
</span>
<span className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
{label}
</span>
<span
className={`tabular-nums ${
redLead
? "font-black text-red-400"
: "font-bold text-base-content/55"
}`}
>
{redText}
</span>
</div>
<div className="mt-1.5 flex h-1.5 overflow-hidden bg-base-content/8">
<div
className="bg-blue-500/70"
style={{ width: `${Math.max(0, Math.min(100, bluePct))}%` }}
/>
<div
className="ml-auto bg-red-500/70"
style={{ width: `${Math.max(0, Math.min(100, 100 - bluePct))}%` }}
/>
</div>
</div>
);
}
function LaneMatchupCard({
blue,
red,
detail,
manifest,
}: {
blue: MatchGameParticipant;
red: MatchGameParticipant;
detail: ApiInternalMatchDetailResponse;
manifest: ReturnType<typeof useDdragonManifest>["data"];
}) {
const laneLabel =
LANE_LABELS[blue.teamPosition] ??
LANE_LABELS[red.teamPosition] ??
blue.teamPosition ??
"-";
const metrics = [
{
key: "kda",
label: "KDA",
blueValue:
blue.deaths === 0
? blue.kills + blue.assists
: (blue.kills + blue.assists) / blue.deaths,
redValue:
red.deaths === 0
? red.kills + red.assists
: (red.kills + red.assists) / red.deaths,
blueText: `${blue.kills}/${blue.deaths}/${blue.assists}`,
redText: `${red.kills}/${red.deaths}/${red.assists}`,
},
{
key: "gold",
label: "골드",
blueValue: blue.gold,
redValue: red.gold,
blueText: formatNumber(blue.gold),
redText: formatNumber(red.gold),
},
{
key: "damage",
label: "딜량",
blueValue: blue.damageDealtToChampions,
redValue: red.damageDealtToChampions,
blueText: formatNumber(blue.damageDealtToChampions),
redText: formatNumber(red.damageDealtToChampions),
},
{
key: "cs",
label: "CS",
blueValue: blue.cs,
redValue: red.cs,
blueText: `${blue.cs} (${blue.csPerMin}/m)`,
redText: `${red.cs} (${red.csPerMin}/m)`,
},
];
const championName = (participant: MatchGameParticipant) =>
championDisplayName(manifest, participant.championId) ??
String(participant.championId);
return (
<div className="overflow-hidden border border-base-content/10 bg-base-100">
<div className="grid grid-cols-[1fr_auto_1fr] items-center gap-2 border-b border-base-content/8 bg-base-content/[0.015] px-3 py-2">
<div className="flex min-w-0 items-center justify-end gap-2">
<div className="min-w-0 text-right">
<div className="truncate text-xs font-bold text-base-content">
{blue.summonerName}
</div>
<div className="truncate text-[11px] text-base-content/40">
{championName(blue)}
</div>
</div>
<ChampionAvatar participant={blue} manifest={manifest} />
</div>
<span className="border border-base-content/10 px-2 py-0.5 text-[10px] font-black uppercase tracking-wider text-base-content/45">
{laneLabel}
</span>
<div className="flex min-w-0 items-center gap-2">
<ChampionAvatar participant={red} manifest={manifest} />
<div className="min-w-0">
<div className="truncate text-xs font-bold text-base-content">
{red.summonerName}
</div>
<div className="truncate text-[11px] text-base-content/40">
{championName(red)}
</div>
</div>
</div>
</div>
<div className="divide-y divide-base-content/5">
{metrics.map((metric) => {
const total = metric.blueValue + metric.redValue;
const bluePct = total > 0 ? (metric.blueValue / total) * 100 : 50;
return (
<MatchupMetricRow
key={`${detail.match.matchId}-${blue.teamPosition}-${metric.key}`}
label={metric.label}
blueLead={metric.blueValue > metric.redValue}
redLead={metric.redValue > metric.blueValue}
blueText={metric.blueText}
redText={metric.redText}
bluePct={bluePct}
/>
);
})}
</div>
</div>
);
}
function LaneMatchupPanel({
selectedGame,
detail,
manifest,
}: {
selectedGame: MatchGameDetail;
detail: ApiInternalMatchDetailResponse;
manifest: ReturnType<typeof useDdragonManifest>["data"];
}) {
const blueTeam = selectedGame.teams.find((team) => team.side === "blue");
const redTeam = selectedGame.teams.find((team) => team.side === "red");
if (!blueTeam || !redTeam) {
return (
<section className="border border-base-content/10 bg-base-100 px-4 py-12 text-center text-sm font-bold text-base-content/35">
라인전 비교 데이터가 없습니다
</section>
);
}
const blueSorted = [...blueTeam.participants].sort(
(left, right) =>
laneSortValue(left.teamPosition) - laneSortValue(right.teamPosition),
);
const redSorted = [...redTeam.participants].sort(
(left, right) =>
laneSortValue(left.teamPosition) - laneSortValue(right.teamPosition),
);
const blueTeamName = getTeamName(detail, blueTeam.teamIndex);
const redTeamName = getTeamName(detail, redTeam.teamIndex);
return (
<section className="overflow-hidden border border-base-content/10 bg-base-100">
<div className="grid grid-cols-[1fr_auto_1fr] items-center gap-3 border-b border-base-content/8 px-4 py-3 text-xs font-black">
<span className="truncate text-right text-blue-400">
{blueTeamName}
</span>
<span className="text-base-content/20">VS</span>
<span className="truncate text-red-400">{redTeamName}</span>
</div>
<div className="grid gap-3 p-4 lg:grid-cols-2">
{blueSorted.map((blue, index) => {
const red = redSorted[index];
if (!red) return null;
return (
<LaneMatchupCard
key={`matchup-${blue.teamPosition}-${blue.summonerName}`}
blue={blue}
red={red}
detail={detail}
manifest={manifest}
/>
);
})}
</div>
</section>
);
}
function ScoreboardTables({
selectedGame,
detail,
manifest,
}: {
selectedGame: MatchGameDetail;
detail: ApiInternalMatchDetailResponse;
manifest: ReturnType<typeof useDdragonManifest>["data"];
}) {
const orderedTeams = [...selectedGame.teams].sort((left, right) =>
left.side === right.side ? 0 : left.side === "blue" ? -1 : 1,
);
return (
<section className="space-y-4">
{orderedTeams.map((team) => (
<TeamTable
key={`${selectedGame.riotMatchId}-${team.side}`}
team={team}
detail={detail}
manifest={manifest}
/>
))}
</section>
);
}
function GameAnalysisPanel({
activeTab,
selectedGame,
detail,
manifest,
}: {
activeTab: DetailTab;
selectedGame: MatchGameDetail;
detail: ApiInternalMatchDetailResponse;
manifest: ReturnType<typeof useDdragonManifest>["data"];
}) {
if (activeTab === "scoreboard") {
return (
<ScoreboardTables
selectedGame={selectedGame}
detail={detail}
manifest={manifest}
/>
);
}
if (activeTab === "build") {
return (
<RuneBuildPanel
selectedGame={selectedGame}
detail={detail}
manifest={manifest}
/>
);
}
return (
<LaneMatchupPanel
selectedGame={selectedGame}
detail={detail}
manifest={manifest}
/>
);
}
function GameTabs({
detail,
communityId,
currentGameNumber,
navigationState,
}: {
detail: ApiInternalMatchDetailResponse;
communityId: string;
currentGameNumber: number;
navigationState: MatchGameNavigationState | undefined;
}) {
return (
<nav
className="mt-4 flex overflow-x-auto border border-base-content/10 bg-base-100"
aria-label="세트 선택"
>
{detail.games.map((game) => {
const winnerTeam = game.teams.find((team) => team.win);
const active = game.gameNumber === currentGameNumber;
return (
<Link
key={game.gameNumber}
to={internalMatchGamePath(
communityId,
detail.match.matchId,
game.gameNumber,
)}
state={navigationState}
className={`min-w-[8rem] border-r border-base-content/8 px-4 py-3 text-xs transition-colors last:border-r-0 ${
active
? "bg-primary/8 text-primary"
: "text-base-content/45 hover:bg-base-content/[0.03] hover:text-base-content"
}`}
>
<span className="block font-black">{game.gameNumber}세트</span>
<span className="mt-1 block truncate">
{winnerTeam
? `${getTeamName(detail, winnerTeam.teamIndex)} 승`
: "결과 대기"}
</span>
</Link>
);
})}
</nav>
);
}
function MatchScoreHero({
detail,
communityId,
selectedGame,
backTarget,
navigationState,
}: {
detail: ApiInternalMatchDetailResponse;
communityId: string;
selectedGame: MatchGameDetail;
backTarget: MatchGameBackTarget;
navigationState: MatchGameNavigationState | undefined;
}) {
const selectedSeries = resolveSelectedSeries(detail, selectedGame);
const [leftTeam, rightTeam] = selectedGame.teams;
const leftScore =
selectedSeries?.teamAIndex === leftTeam?.teamIndex
? selectedSeries?.teamAWins
: selectedSeries?.teamBWins;
const rightScore =
selectedSeries?.teamBIndex === rightTeam?.teamIndex
? selectedSeries?.teamBWins
: selectedSeries?.teamAWins;
return (
<section className="mt-5 border border-base-content/10 bg-base-content/[0.02] p-5">
<div className="flex flex-col gap-5 lg:flex-row lg:items-center lg:justify-between">
<div className="min-w-0">
<Link
to={backTarget.to}
className="text-xs text-base-content/40 hover:text-base-content"
>
← {backTarget.label}
</Link>
<h1 className="mt-4 text-2xl font-black text-base-content">
{detail.match.title} · {selectedGame.gameNumber}세트
</h1>
<p className="mt-2 text-sm text-base-content/45">
{formatDateTime(selectedGame.gameCreation)} ·{" "}
{formatDuration(selectedGame.gameDuration)} ·{" "}
<span className="font-mono">{selectedGame.riotMatchId}</span>
</p>
</div>
{leftTeam && rightTeam && (
<div className="grid min-w-full grid-cols-[1fr_auto_1fr] items-center gap-4 lg:min-w-[440px]">
<div
className={`min-w-0 text-right ${
leftTeam.win
? teamIndexColorClasses(leftTeam.teamIndex).text
: "text-base-content/30"
}`}
>
<div className="truncate text-sm font-black">
{getTeamName(detail, leftTeam.teamIndex)}
</div>
<div className="mt-1 text-xs font-bold text-base-content/35">
{sideLabel(leftTeam.side)}
</div>
</div>
<div className="flex items-center gap-3 text-center">
<span className="text-4xl font-black tabular-nums text-base-content">
{leftScore ?? (leftTeam.win ? 1 : 0)}
</span>
<span className="text-xs font-black text-base-content/15">
VS
</span>
<span className="text-4xl font-black tabular-nums text-base-content">
{rightScore ?? (rightTeam.win ? 1 : 0)}
</span>
</div>
<div
className={`min-w-0 ${
rightTeam.win
? teamIndexColorClasses(rightTeam.teamIndex).text
: "text-base-content/30"
}`}
>
<div className="truncate text-sm font-black">
{getTeamName(detail, rightTeam.teamIndex)}
</div>
<div className="mt-1 text-xs font-bold text-base-content/35">
{sideLabel(rightTeam.side)}
</div>
</div>
</div>
)}
</div>
<GameTabs
detail={detail}
communityId={communityId}
currentGameNumber={selectedGame.gameNumber}
navigationState={navigationState}
/>
</section>
);
}
export default function MatchGameDetailPage() {
const { cid, matchId, id, gameNumber } = useParams();
const location = useLocation();
const [activeTab, setActiveTab] = useState<DetailTab>("scoreboard");
const communityId = cid ?? DEFAULT_COMMUNITY_ID;
const resolvedMatchId = matchId ?? id;
const requestedGameNumber = Number(gameNumber);
const detailQuery = useInternalMatchDetail(resolvedMatchId, communityId);
const { data: ddragon } = useDdragonManifest();
const detail = detailQuery.data;
const fallbackBackTo = resolvedMatchId
? internalMatchDetailPath(communityId, resolvedMatchId)
: `/communities/${communityId}/internal-stats`;
const backTarget = resolveBackTarget(location.state, fallbackBackTo);
const navigationState = createNavigationState(backTarget, fallbackBackTo);
if (detailQuery.isLoading) {
return (
<main className="mx-auto max-w-6xl px-4 py-20 text-center text-sm text-base-content/40">
세트 상세 기록을 불러오는 중...
</main>
);
}
if (detailQuery.error || !detail) {
return (
<main className="mx-auto max-w-6xl px-4 py-20 text-center">
<h1 className="text-lg font-bold">세트 기록을 찾을 수 없습니다</h1>
<Link to={backTarget.to} className="btn btn-ghost btn-sm mt-4">
{backTarget.label}
</Link>
</main>
);
}
const selectedGame =
detail.games.find((game) => game.gameNumber === requestedGameNumber) ??
detail.games[0];
if (!selectedGame) {
return (
<main className="mx-auto max-w-6xl px-4 py-20 text-center">
<h1 className="text-lg font-bold">수집된 세트 기록이 없습니다</h1>
<Link
to={backTarget.to}
className="btn btn-ghost btn-sm mt-4"
>
{backTarget.label}
</Link>
</main>
);
}
return (
<main className="mx-auto max-w-6xl px-4 py-6 sm:px-6">
<MatchScoreHero
detail={detail}
communityId={communityId}
selectedGame={selectedGame}
backTarget={backTarget}
navigationState={navigationState}
/>
<PostgameBreakdown
selectedGame={selectedGame}
detail={detail}
manifest={ddragon}
/>
<div className="mt-5 space-y-4">
<DetailTabBar activeTab={activeTab} onChange={setActiveTab} />
<GameAnalysisPanel
activeTab={activeTab}
selectedGame={selectedGame}
detail={detail}
manifest={ddragon}
/>
</div>
<TimelineGraph selectedGame={selectedGame} detail={detail} />
</main>
);
}