import React from "react";
import { linkGame } from "../../../domain/apiMethods";
import { dispatch } from "../../../domain/gameStore";
import GameCreationForm from "../../util/GameCreationForm";
import styles from "./GameSummary.module.css";

export default React.memo(({ linkedGame, gameId }) => (
  <div className={styles.linked}>
    {linkedGame ? (
      <button onClick={() => dispatch.goToLobby(linkedGame)} type="button">
        Continue to Linked Game Lobby
      </button>
    ) : (
      <GameCreationForm afterCreate={linkId => linkGame(gameId, linkId)} />
    )}
  </div>
));
