const preact = require('preact');
const range = require('lodash/range');
const { ITEMS: { SKILLS, COLOURS, SPECS: SPEC_CONSTANT } } = require('./constants');
const { COLOUR_ICONS, STATS, SPECS } = require('../utils');
function Info(args) {
const {
activeCryp,
info,
sendUnequip,
instance,
} = args;
function infoVar(info) {
let red = 0; let blue = 0; let green = 0;
instance.cryps.forEach(cryp => {
red += cryp.colours.red;
blue += cryp.colours.blue;
green += cryp.colours.green;
});
const teamColours = { red, blue, green };
const [type, value] = info;
if (type === 'item') {
let itemDetails;
if (SKILLS[value]) {
itemDetails = SKILLS[value];
} else if (SPEC_CONSTANT[value]) {
itemDetails = SPEC_CONSTANT[value];
} else if (COLOURS[value]) {
itemDetails = COLOURS[value];
}
return (
{value} - {itemDetails.description}
);
}
if (type === 'skill') {
return (
{value.skill}
{SKILLS[value.skill].description}
);
}
function thresholds(t, spec) {
return (
SPEC_CONSTANT[spec].colours.map((c, i) => (
{COLOUR_ICONS[c].svg(`stat-icon ${COLOUR_ICONS[c].colour}`)}
{Math.min(teamColours[c], t)} / {t}
))
);
}
if (type === 'spec') {
const breaks = SPEC_CONSTANT[value.spec].thresholds ? SPEC_CONSTANT[value.spec].thresholds.map((t, i) => {
const threshold = thresholds(t, value.spec);
return (
{threshold}
);
}) : null;
return (
{value.spec}
{SPEC_CONSTANT[value.spec].description}
{breaks}
);
}
}
function infoCrypElement(cryp) {
// onClick={() => setInfo('skill', { skill: s, cryp })}
const skills = range(0, 4).map(i => {
const s = cryp.skills[i]
? cryp.skills[i].skill
: ( );
return ;
});
const stats = Object.values(STATS).map((s, j) => (
{s.svg(`stat-icon ${s.colour}`)}
{cryp[s.stat].value}
));
const specs = cryp.specs.map((s, i) => (
{SPECS[s].svg(`stat-icon ${SPECS[s].colour}`)}
{SPECS[s].caption}
));
return (
{cryp.name}
{stats}
{specs}
{skills}
);
}
const infoCryp = activeCryp
? infoCrypElement(activeCryp)
: null;
const otherInfo = info.length
? infoVar(info)
: null;
return (
{infoCryp}
{otherInfo}
);
}
module.exports = Info;