const { connect } = require('preact-redux');
const preact = require('preact');
const range = require('lodash/range');
const shapes = require('./shapes');
const { SPECS, crypAvatar } = require('../utils');
const actions = require('../actions');
const addState = connect(
function receiveState(state) {
const { ws, instance, player, account, vboxHidden, vboxInfo } = state;
function sendInstanceReady() {
return ws.sendInstanceReady(instance.id);
}
function sendVboxApply(crypId, i) {
return ws.sendVboxApply(instance.id, crypId, i);
}
return { instance, player, account, sendInstanceReady, sendVboxApply, vboxHidden, vboxInfo };
},
function receiveDispatch(dispatch) {
function quit() {
dispatch(actions.setInstance(null));
}
function setInfo(item, value) {
dispatch(actions.setInfo([item, value]));
}
function setActiveCryp(value) {
dispatch(actions.setActiveCryp(value));
}
function clearInfo() {
return dispatch(actions.setInfo([]));
}
function setVboxHighlight(v) {
dispatch(actions.setVboxHighlight(v));
}
return { quit, clearInfo, setInfo, setActiveCryp, setVboxHighlight };
}
);
function Cryp(props) {
const {
cryp,
setInfo,
setActiveCryp,
vboxInfo,
setVboxHighlight,
} = props;
function setHighlight(type) {
if (type === 'skill') return setVboxHighlight(vboxInfo.vars.filter(v => v.skill).map(v => v.v));
if (type === 'spec') return setVboxHighlight(vboxInfo.vars.filter(v => v.spec).map(v => v.v));
return false;
}
const skills = range(0, 3).map(i => {
const skill = cryp.skills[i];
const s = skill
? skill.skill
: ( );
function skillClick(e) {
if (!skill) setHighlight('skill');
else setInfo('skill', { skill: skill.skill, cryp });
e.stopPropagation();
return setActiveCryp(cryp);
}
const classes = `right ${skill ? '' : 'action'}`;
return ;
});
function onClick(e) {
e.stopPropagation();
e.preventDefault();
return setActiveCryp(cryp);
}
const specs = range(0, 6).map(i => {
const s = cryp.specs[i];
function blankSpecClick(e) {
e.stopPropagation();
setActiveCryp(cryp);
setHighlight('spec');
}
if (!s) {
return (