import { Link, useLocation, useSearchParams } from 'react-router'; import { useCommunity, useCommunityInternalStatsMatches, useCommunityLeaderboard, useDdragonManifest, useTeamInsights, } from '../api/hooks'; import type { ApiInternalMatchCard, ApiLeaderHighlight, ApiLeaderboardRow, TeamSide, } from '../api/types'; import { DEFAULT_COMMUNITY_ID } from '../config'; import { championDisplayName, championIconUrl, profileIconUrl } from '../lib/ddragon'; import { sideShortLabel, teamIndexColorClasses, teamIndexLabel } from '../lib/league'; function formatDateTime(value: string) { 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 sideLabel(side: TeamSide) { return sideShortLabel(side); } function sideText(side: TeamSide) { return side === 'blue' ? 'text-blue-400' : 'text-red-400'; } function ratioClass(value: number) { if (value >= 55) return 'text-blue-400'; if (value >= 50) return 'text-amber-400'; return 'text-base-content/45'; } function ChampionChip({ championId, manifest, }: { championId: number; manifest: ReturnType['data']; }) { const icon = championIconUrl(manifest, championId); const name = championDisplayName(manifest, championId) ?? String(championId); return ( {icon ? : null} {name} ); } function MatchCard({ match, manifest, }: { match: ApiInternalMatchCard; manifest: ReturnType['data']; }) { const primarySeries = match.seriesResults[0]; const teamName = (teamIndex: number) => teamIndexLabel( teamIndex, match.teams.find((team) => team.teamIndex === teamIndex)?.name, ); return (
{formatDateTime(match.scheduledAt)}

{match.title}

{match.games.map((game) => ( {game.gameNumber}경기 {game.winnerSide && game.winnerTeamIndex ? ( {teamName(game.winnerTeamIndex)} 승 ({sideLabel(game.winnerSide)}) ) : ( '대기' )} {formatDuration(game.gameDuration)} ))}
{primarySeries && (
{primarySeries.teamAWins}
{teamName(primarySeries.teamAIndex)}
VS
{primarySeries.teamBWins}
{teamName(primarySeries.teamBIndex)}
)}
{match.teams.map((team) => (
{team.name}
{team.members.slice(0, 5).map((member) => (
{member.summonerName}
))}
))}
); } function HighlightCard({ title, highlight, suffix = '', }: { title: string; highlight: ApiLeaderHighlight | null | undefined; suffix?: string; }) { return (
{title}
{highlight ? `${highlight.metric}${suffix}` : '-'}
{highlight?.summonerName ?? '기록 없음'}
); } function LeaderboardTable({ rows, manifest, }: { rows: ApiLeaderboardRow[]; manifest: ReturnType['data']; }) { const location = useLocation(); const historyBackTo = `${location.pathname}${location.search}${location.hash}`; return (
{rows.map((row, index) => ( ))} {rows.length === 0 && ( )}
# 소환사 승률 게임 KDA GPM 킬관여 분당 CS 주 챔피언
{index + 1} {row.summonerName} {row.winRate}% {row.games} {row.kda} {row.avgGoldPerMin} {row.avgKillParticipation}% {row.avgCsPerMin}
{row.topChampions.map((champion) => ( ))}
아직 집계할 내전 기록이 없습니다.
); } export default function CommunityInternalStatsPage() { const [searchParams] = useSearchParams(); const championIdParam = Number(searchParams.get('championId')); const championId = Number.isFinite(championIdParam) && championIdParam > 0 ? championIdParam : undefined; const filters = { seasonId: searchParams.get('seasonId') ?? undefined, championId, limit: 12, }; const communityQuery = useCommunity(DEFAULT_COMMUNITY_ID); const matchesQuery = useCommunityInternalStatsMatches(filters); const leaderboardQuery = useCommunityLeaderboard(filters); const insightsQuery = useTeamInsights(filters); const { data: ddragon } = useDdragonManifest(); const matches = matchesQuery.data?.pages.flatMap((page) => page.matches) ?? []; const season = leaderboardQuery.data?.season ?? matchesQuery.data?.pages[0]?.season ?? null; if (!DEFAULT_COMMUNITY_ID) { return (
`VITE_DEFAULT_COMMUNITY_ID` 설정이 필요합니다.
); } return (
← 홈으로

Community Records

{communityQuery.data?.name ?? '커뮤니티'} 내전 전적

토너먼트 코드로 수집된 결과를 기준으로 매치, 선수 순위, 팀 인사이트를 보여줍니다.

시즌
{season?.label ?? '현재 시즌'}

최근 내전

블루 승률 {insightsQuery.data?.sideWinRate.blue ?? 0}% · 레드 승률{' '} {insightsQuery.data?.sideWinRate.red ?? 0}%
{matchesQuery.isLoading ? (
내전 기록을 불러오는 중...
) : (
{matches.map((match) => ( ))} {matches.length === 0 && (
아직 수집된 내전 결과가 없습니다.
)}
)} {matchesQuery.hasNextPage && ( )}

선수 순위

포지션은 Riot Match의 라인 정보를 기준으로 합니다.
); }