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

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

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

    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);
