157 lines
5.2 KiB
TypeScript
157 lines
5.2 KiB
TypeScript
import type {
|
|
CompetitionTeamView,
|
|
DoubleEliminationCompetitionProjection,
|
|
SeriesId,
|
|
TeamId,
|
|
} from "@lolympus/contracts";
|
|
import { useId } from "react";
|
|
import type { DoubleEliminationBracketLayout } from "./double-elimination-bracket-layout";
|
|
import { SeriesScoreCard } from "./SeriesScoreCard";
|
|
import { getSeriesScoreCardAccessibleLabel } from "./series-score-card-model";
|
|
|
|
export function DoubleEliminationMobileBracket({
|
|
projection,
|
|
layout,
|
|
teamById,
|
|
}: {
|
|
projection: DoubleEliminationCompetitionProjection;
|
|
layout: DoubleEliminationBracketLayout;
|
|
teamById: ReadonlyMap<TeamId, CompetitionTeamView>;
|
|
}) {
|
|
const bracketId = useId();
|
|
const seriesById = new Map(
|
|
projection.series.map((series) => [series.seriesId, series]),
|
|
);
|
|
const nodeById = new Map(layout.nodes.map((node) => [node.seriesId, node]));
|
|
const isCurrentRound = (seriesIds: readonly SeriesId[]) => seriesIds.some((seriesId) => {
|
|
const status = seriesById.get(seriesId)?.status;
|
|
return status === "ready" || status === "in-progress";
|
|
});
|
|
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={`${bracketId}-${section.key}`}
|
|
>
|
|
<div className="mb-3 border-b border-base-content/10 pb-2">
|
|
<h3
|
|
id={`${bracketId}-${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-2">
|
|
{groups.map((group) => (
|
|
<details
|
|
key={`${group.stage}:${group.roundNumber}`}
|
|
open={groups.length === 1 || isCurrentRound(group.seriesIds)}
|
|
className="group lts-panel"
|
|
>
|
|
<summary
|
|
className="cursor-pointer px-3 py-3 text-sm font-semibold hover:bg-sunken"
|
|
>
|
|
{group.accessibleLabel}
|
|
<span className="ml-2 text-xs font-medium text-content-muted">{group.seriesIds.length}경기</span>
|
|
</summary>
|
|
<div className="space-y-3 border-t border-line p-3">
|
|
{group.seriesIds.map((seriesId) => {
|
|
const series = seriesById.get(seriesId);
|
|
if (!series) return null;
|
|
const node = nodeById.get(seriesId);
|
|
const accessibilityLabel =
|
|
getSeriesScoreCardAccessibleLabel(
|
|
series,
|
|
node?.accessibleLabel,
|
|
teamById,
|
|
);
|
|
return (
|
|
<div key={seriesId}>
|
|
<SeriesScoreCard
|
|
series={series}
|
|
displayLabel={node?.label}
|
|
teamById={teamById}
|
|
variant="bracket"
|
|
accessibilityLabel={accessibilityLabel}
|
|
/>
|
|
<MobileRoutes
|
|
layout={layout}
|
|
seriesId={seriesId}
|
|
seriesLabel={node?.accessibleLabel ?? "경기"}
|
|
/>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
</details>
|
|
))}
|
|
</div>
|
|
</section>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function MobileRoutes({
|
|
layout,
|
|
seriesId,
|
|
seriesLabel,
|
|
}: {
|
|
layout: DoubleEliminationBracketLayout;
|
|
seriesId: SeriesId;
|
|
seriesLabel: string;
|
|
}) {
|
|
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"
|
|
aria-label={`${seriesLabel} 연결 경로`}
|
|
>
|
|
{routes.map((route) => (
|
|
<li key={`${route.select}:${route.toSeriesId}:${route.toSlot}`}>
|
|
<span aria-hidden="true">{route.label}</span>
|
|
<span className="sr-only">{route.accessibleLabel}</span>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
);
|
|
}
|