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

const CrypList = require('./cryp.list.component');
const actions = require('./../actions');

const addState = connect(
    function receiveState(state) {
        const { ws, cryps, selectedCryps, instances } = state;

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

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

        function sendCrypSpawn(name) {
            return ws.sendCrypSpawn(name);
        }

        return { cryps, selectedCryps, sendInstanceJoin, sendCrypSpawn, sendPlayerMmCrypsSet };
    },

    function receiveDispatch(dispatch) {
        function setSelectedCryps(crypIds) {
            dispatch(actions.setSelectedCryps(crypIds));
        }

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

        return {
            setSelectedCryps,
            setActiveInstance,
        };
    }
);

module.exports = addState(CrypList);


        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 };
    },

