var React = require('react');
var List = require('./List');
var Game = require('./Game');
var GameModel = require('../models/Game');
// Root view of the application
var App = module.exports = React.createClass({
  displayName:'App',

  render: function() {
    return (
      <div className="container">
         {select(this.props.model)}
      </div>);
  }
});

App.propTypes = {
  model: React.PropTypes.object,
}

function select(model){
  if(model.selected){
    var game = model.games.has(model.selected)
      ? model.games.get(model.selected)
      : null;
    return (<Game game={game}
                  selected={model.selected}
                  edit={model.edit} />);
  }
  return (<List platforms={model.platforms}
                title={model.title}
                games={model.games} />);
}
