import React from "react";

class PreRound extends React.Component {
  constructor(props) {
    super(props);
    this.textareaRef = React.createRef();
  }

  copyGameId() {
    const { current } = this.textareaRef;
    current.select();
    document.execCommand("copy");
  }
  
  render() {
    const { gameId, playerName, onStart } = this.props;
    return (
      <div>
        <p>Playing as {playerName}</p>
        <p>
          Game Code: {gameId} <button onClick={() => this.copyGameId()}>Copy</button>
        </p>
        <button onClick={onStart}>Start Game</button>
        <textarea
          ref={this.textareaRef}
          style={{ position: "absolute", top: "-1000px" }}
          value={gameId}
        />
      </div>
      );
    }
  }
  
  export default PreRound;
  