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

const InstanceListContainer = require('./instance.list.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 } = state;

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

        return { game, instance };
    }
);

function renderBody(props) {
    const { game, instance } = props;
    if (game) {
        return (
            <GameContainer />
        );
    }

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

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

module.exports = addState(renderBody);
