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

const actions = require('./../actions');

const addState = connect(
    function receiveState(state) {
        const {
            teamSelect,
            ws,
        } = state;

        function sendAccountSetTeam() {
            return ws.sendAccountSetTeam(teamSelect);
        }

        return {
            sendAccountSetTeam,
            teamSelect,
        };
    },
);

function TeamCtrl(args) {
    const {
        teamSelect,
        sendAccountSetTeam,
    } = args;

    return (
        <aside>
            <div class="timer-container"></div>
            <button
                class='ready'
                disabled={teamSelect.some(c => !c)}
                onClick={sendAccountSetTeam}>
                Set Team
            </button>
        </aside>
    );
}

module.exports = addState(TeamCtrl);
