const preact = require('preact');
const { connect } = require('preact-redux');

const PlayerCtrl = require('./player.ctrl');
const PlayCtrl = require('./play.ctrl');

const addState = connect(
    function receiveState(state) {
        const {
            ws,
            game,
            instance,
            nav,
        } = state;

        return {
            game,
            instance,
            nav,
        };
    },
);

function Controls(args) {
    const {
        game,
        instance,
        nav,
        sendGameReady,
    } = args;

    if (game || instance) return <PlayerCtrl />;
    if (nav === 'play' || !nav) return <PlayCtrl />

    return false;
}

module.exports = addState(Controls);
