import React from "react";
import "./Winner.css";
import Paper from '@material-ui/core/Paper';
import Button from '@material-ui/core/Button';
import Resource from './Resource.js';
import { getPlayerName } from './Common.js';
import PlayerColor from './PlayerColor.js';
const Winner = ({table, color}) => {
const quitClicked = (event) => {
table.setSelected("");
}
if (!table.game) {
return <>>;
}
const name = getPlayerName(table.game.sessions, color),
player = table.game.players[color];
let playerCount = 0;
for (let key in table.game.players) {
if (table.game.players[key].status !== 'Not active') {
playerCount++;
}
}
let description = <>
Congratulations, {name}!
{name} won the game after {Math.floor(table.game.turns / playerCount)} turns. They
had {player.potential} unplayed Victory Point card(s).
>;
for (let key in table.game.players) {
if (key === color) {
continue;
}
let tmp = table.game.players[key];
if (tmp.status === 'Not active') {
continue;
}
let line = <> {getPlayerName(table.game.sessions, key)} finished with {tmp.points} victory points.
They had {tmp.potential} unplayed Victory Point card(s).>
description = <>{description}
{line}
>;
}
description = <>{description}
If everyone goes back to the Lobby, you can play again.
>;
return (
{name} has won with {player.points} victory points!