import * as React from "react"; import { FunctionComponent } from "react"; import { useTranslation } from "react-i18next"; import { getSeriesScore, Seat, SeriesGame } from "@mancala/core"; // The most boxes the strip shows; earlier games collapse into a "+N" box. const MAX_BOXES = 8; // Above the board from the second game of a series (docs/specs/rematch, R3): the series score and one box per game, // each with its winner's colour, the stores from the bottom player's side, a dot for who moved first and how it // ended. Finished games open their replay in a new tab; the game being played is marked. const SeriesStrip: FunctionComponent<{ // Finished games, oldest first. games: SeriesGame[], // A game of the series is being played after them. hasCurrentGame: boolean, bottomSeat: Seat, bottomName: string, topName: string, }> = ({ games, hasCurrentGame, bottomSeat, bottomName, topName }) => { const { t } = useTranslation(); const score = getSeriesScore(games, bottomSeat); const finishedBoxes = MAX_BOXES - (hasCurrentGame ? 1 : 0); const hiddenCount = games.length > finishedBoxes ? games.length - finishedBoxes + 1 : 0; const shown = games.slice(hiddenCount); const renderGame = (game: SeriesGame, index: number) => { const number = hiddenCount + index + 1; const bottomStore = bottomSeat === "player1" ? game.player1Store : game.player2Store; const topStore = bottomSeat === "player1" ? game.player2Store : game.player1Store; const winner = game.result === "player1" || game.result === "player2" ? (game.result === bottomSeat ? "mine" : "theirs") : "draw"; const ending = game.endReason === "timeout" ? t("EndedOnTime") : game.endReason === "left" ? t("EndedByLeaving") : undefined; const bottomFirst = game.firstSeat === bottomSeat; const firstMark = ; const label = [ t("SeriesGameNumber", { number }), `${bottomName} ${bottomStore} โ ${topStore} ${topName}`, `${t("MovedFirst")}: ${bottomFirst ? bottomName : topName}`, ending, ].filter(Boolean).join(", "); return (