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 TeamFooter(args) {
    const {
        teamSelect,
        sendAccountSetTeam,
    } = args;

    return (
        <footer>
            <button
                disabled={teamSelect.some(c => !c)}
                onClick={sendAccountSetTeam}>
                Set Team
            </button>
        </footer>
    );
}

module.exports = addState(TeamFooter);
