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

const actions = require('../actions');
const Info = require('./info.component');

const addState = connect(
    function receiveState(state) {
        const {
            activeCryp,
            info,
            ws,
            instance,
            player,
        } = state;

        function sendUnequip(crypId, item) {
            return ws.sendVboxUnequip(instance.id, crypId, item);
        }

        return {
            activeCryp,
            info,
            sendUnequip,
            instance,
            player,
        };
    },

    function receiveDispatch(dispatch) {
        function setInfo(item, value) {
            dispatch(actions.setInfo([item, value]));
        }

        function setActiveVar(value) {
            dispatch(actions.setActiveVar(value));
        }


        return {
            setInfo,
            setActiveVar,
        };
    }

);

module.exports = addState(Info);
