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

const InstanceListContainer = require('./instance.list.container');
const LoginContainer = require('./login.container');
const CrypListContainer = require('./cryp.list.container');
const GameContainer = require('./game.container');
const InstanceContainer = require('./instance.container');

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

        if (!game) {
            console.log('clear gs interval');
            // ws.clearGameStateInterval();
        }

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

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

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

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

    return (
        <main>
            <CrypListContainer />
            <InstanceListContainer />
        </main>
    );
}

module.exports = addState(renderBody);
