var Game = React.createClass({
  mixins: [SetIntervalMixin],
  propTypes: {
    title: React.PropTypes.string,
    players: React.PropTypes.array,
    id: React.PropTypes.number,
    source: React.PropTypes.string
  },

  getInitialState: function() {
    return {
      players: [],
      title: ""
    };
  },

  loadGameFromServer: function() {
    //console.log(this.props.source);
    $.get(this.props.source, function(result) {
      if (this.isMounted()) {
        //console.log("Mounted");
        this.setState({
          title: result.title,
          players: result.players
        });
      }
    }.bind(this));
  },

  componentDidMount: function() {
    this.loadGameFromServer();
    this.setInterval(this.loadGameFromServer, 3000);
  },

  render: function() {
    return (
      <div>
        <div>Title: {this.state.title}</div>
        <div>Id: {this.props.id}</div>
        <div>Current Player: {this.props.current_player}</div>
        <div className='player-list'>
          <PlayerList game_id={this.props.id} players={this.state.players} />
        </div>
        <div>
        </div>
      </div>
    );
  }
});
