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

const Login = require('./login');
const Game = require('./game');
const Instance = require('./instance.component');
const Team = require('./team');
const List = require('./list');

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

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

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

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

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

    if (nav === 'team') return <Team />;
    if (nav === 'list') return <List />;

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

module.exports = addState(Main);
