import { MancalaGame } from 'mancala.js'; import * as React from 'react'; import { FunctionComponent } from "react" import { context } from '../context'; const InfoPanel: FunctionComponent<{ game: MancalaGame, 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 wonPlayer = game.getWonPlayerId(); let whoWon = game.getWonPlayerId() === userKey ? context.texts.YouWon : context.texts.YouLost if(!wonPlayer){ whoWon = context.texts.GameDraw } return (

{ context.texts.GameEnded + " " + whoWon }

) } else { return (

{game.checkIsPlayerTurn(userKey) ? context.texts.YourTurn : context.texts.OpponentTurn}

) } } return

} export default InfoPanel