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

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

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

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

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

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

        return {
            setInfo,
            setVboxHidden,
            setActiveCryp,
        };
    }

);

module.exports = addState(Info);
