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

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

const InstanceList = require('./instance.list.component');

const addState = connect(
    function receiveState(state) {
        const { ws, selectedCryps, instances } = state;
        function sendCrypsSet() {
            console.log('set crypos');
            // return ws.sendGamePvp(crypIds);
        }

        function sendInstanceJoin() {
            if (selectedCryps.length) {
                return ws.sendInstanceJoin(selectedCryps);
            }
            return false;
        }


        return { instances, sendCrypsSet, sendInstanceJoin };
    },

    function receiveDispatch(dispatch) {
        function setActiveInstance(instance) {
            dispatch(actions.setInstance(instance));
        }

        return { setActiveInstance };
    }
);

module.exports = addState(InstanceList);
