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

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

const Instance = require('./instance.component');

const addState = connect(
    function receiveState(state) {
        const { ws, instance, account, combiner } = state;

        function sendInstanceReady() {
            return ws.sendInstanceReady(instance.instance);
        }

        function sendVboxApply(crypId, i) {
            return ws.sendVboxApply(instance.instance, crypId, i);
        }

        return { instance, account, sendInstanceReady, sendVboxApply };
    },

    function receiveDispatch(dispatch, { instance, combiner }) {
        function quit() {
            dispatch(actions.setInstance(null));
        }

        function setInfo(item, cryp) {
            dispatch(actions.setInfo(item, cryp));
        }

        return { quit, setInfo };
    }

);

module.exports = addState(Instance);
