import * as React from 'react';
import { FunctionComponent } from "react"
import { context } from '../context';
import { Game } from '../mancala';
const InfoPanel: FunctionComponent<{
game: Game,
crashMessage: string,
userKey: string,
userKeyWhoLeave: string,
searchingOpponent: boolean
}> = ({
game, crashMessage, userKey, userKeyWhoLeave, searchingOpponent }) => {
if (searchingOpponent) {
return (
{
context.texts.SearchingOpponent + " " + context.texts.PleaseWait
}
)
}
if (crashMessage) {
return (
{
context.texts.GameCrashed + " " + crashMessage
}
)
}
if (userKeyWhoLeave) {
let message = context.texts.OpponentLeavesTheGame
if (userKeyWhoLeave == userKey) {
message = context.texts.YouLeftTheGame
}
return (
{message}
)
}
if (game) {
if (game.state == "ended") {
const whoWon = game.getWonPlayer() == userKey ? context.texts.YouWon : context.texts.YouLost
return (
{
context.texts.GameEnded + " " + whoWon
}
)
} else {
return (
{game.checkGameTurn(userKey) ? context.texts.YourTurn : context.texts.OpponentTurn}
)
}
}
return
}
export default InfoPanel