122 lines
3.8 KiB
TypeScript
122 lines
3.8 KiB
TypeScript
import type {
|
|
CompetitionTeamView,
|
|
DoubleEliminationCompetitionProjection,
|
|
SeriesId,
|
|
TeamId,
|
|
} from "@lolympus/contracts";
|
|
import type { DoubleEliminationBracketLayout } from "./double-elimination-bracket-layout";
|
|
import { SeriesScoreCard } from "./SeriesScoreCard";
|
|
|
|
export function DoubleEliminationMobileBracket({
|
|
projection,
|
|
layout,
|
|
teamById,
|
|
}: {
|
|
projection: DoubleEliminationCompetitionProjection;
|
|
layout: DoubleEliminationBracketLayout;
|
|
teamById: ReadonlyMap<TeamId, CompetitionTeamView>;
|
|
}) {
|
|
const seriesById = new Map(
|
|
projection.series.map((series) => [series.seriesId, series]),
|
|
);
|
|
const nodeById = new Map(layout.nodes.map((node) => [node.seriesId, node]));
|
|
const sections = [
|
|
{
|
|
key: "upper",
|
|
title: "승자조",
|
|
description: "승리하면 승자조에 남고, 패배하면 패자조로 이동합니다.",
|
|
stages: new Set(["upper"]),
|
|
},
|
|
{
|
|
key: "lower",
|
|
title: "패자조",
|
|
description: "승리하면 다음 라운드로 진출하고, 패배하면 탈락합니다.",
|
|
stages: new Set(["lower"]),
|
|
},
|
|
{
|
|
key: "final",
|
|
title: "결승",
|
|
description: "승자조 우승 팀과 패자조 우승 팀이 최종 우승을 결정합니다.",
|
|
stages: new Set(["grand-final", "reset-final"]),
|
|
},
|
|
];
|
|
|
|
return (
|
|
<div
|
|
className="space-y-7 xl:hidden"
|
|
role="region"
|
|
aria-label="더블 엘리미네이션 대진표"
|
|
>
|
|
{sections.map((section) => {
|
|
const groups = layout.mobileGroups.filter((group) =>
|
|
section.stages.has(group.stage),
|
|
);
|
|
if (groups.length === 0) return null;
|
|
return (
|
|
<section key={section.key} aria-labelledby={`bracket-${section.key}`}>
|
|
<div className="mb-3 border-b border-base-content/10 pb-2">
|
|
<h3 id={`bracket-${section.key}`} className="text-sm font-bold">
|
|
{section.title}
|
|
</h3>
|
|
<p className="mt-0.5 text-xs text-content-muted">
|
|
{section.description}
|
|
</p>
|
|
</div>
|
|
<div className="space-y-5">
|
|
{groups.map((group) => (
|
|
<section
|
|
key={`${group.stage}:${group.roundNumber}`}
|
|
aria-label={group.label}
|
|
>
|
|
<h4 className="mb-2 text-xs font-bold text-content-muted">
|
|
{group.label}
|
|
</h4>
|
|
<div className="space-y-3">
|
|
{group.seriesIds.map((seriesId) => {
|
|
const series = seriesById.get(seriesId);
|
|
if (!series) return null;
|
|
return (
|
|
<div key={seriesId}>
|
|
<SeriesScoreCard
|
|
series={series}
|
|
displayLabel={nodeById.get(seriesId)?.label}
|
|
teamById={teamById}
|
|
variant="bracket"
|
|
/>
|
|
<MobileRoutes layout={layout} seriesId={seriesId} />
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
</section>
|
|
))}
|
|
</div>
|
|
</section>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function MobileRoutes({
|
|
layout,
|
|
seriesId,
|
|
}: {
|
|
layout: DoubleEliminationBracketLayout;
|
|
seriesId: SeriesId;
|
|
}) {
|
|
const routes = layout.connectors.filter(
|
|
(connector) => connector.fromSeriesId === seriesId,
|
|
);
|
|
if (routes.length === 0) return null;
|
|
return (
|
|
<ul className="mt-1.5 space-y-0.5 border-l border-base-content/10 pl-2 text-[11px] text-content-muted">
|
|
{routes.map((route) => (
|
|
<li key={`${route.select}:${route.toSeriesId}:${route.toSlot}`}>
|
|
{route.label}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
);
|
|
}
|