// eslint-disable-next-line
const preact = require('preact');
const { connect } = require('preact-redux');

const LoginContainer = require('./login.container');
const MenuContainer = require('./menu.container');
const GameContainer = require('./game.container');
const InstanceContainer = require('./instance.container');

const addState = connect(
    state => {
        const { game, instance, ws, account } = state;
        return { game, instance, account };
    }
);

function renderBody(props) {
    const { game, instance, account } = props;

    if (!account) {
        return (
            <main>
                <LoginContainer />
            </main>
        );
    }

    if (instance) {
        return (
            <InstanceContainer />
        );
    }

    if (game) {
        return (
            <GameContainer />
        );
    }

    return (
        <MenuContainer />
    );
}

module.exports = addState(renderBody);
