export const recommendations = (persona, flags, tileConfig, salesPlanType, hasClusters) => {
    persona = { ...persona, ...{ flags, salesPlanType, hasClusters } };
    if (!tileConfig) {
        return [];
    }
    return tileConfig
        .filter((tile) => {
        if (!tile.prerequestites || typeof tile.prerequestites === "boolean") {
            return true;
        }
        if (tile.prerequestites.length === 1) {
            const pre = tile.prerequestites[0];
            const personaEntry = persona[pre.id];
            return evaluateRequirement(personaEntry, pre.value, pre.not);
        }
        switch (tile.bool) {
            case "OR":
                return tile.prerequestites.reduce((prev, curr) => {
                    const personaEntry = persona[curr.id];
                    return (prev || evaluateRequirement(personaEntry, curr.value, curr.not));
                }, false);
            case "AND":
                return tile.prerequestites.reduce((prev, curr) => {
                    const personaEntry = persona[curr.id];
                    return (prev && evaluateRequirement(personaEntry, curr.value, curr.not));
                }, true);
            default:
                return true;
        }
    })
        .map((tile) => tile.id);
};
function evaluateRequirement(personaEntry, reqValue, reqNot) {
    if (personaEntry instanceof Array) {
        if (reqNot) {
            return !personaEntry.includes(`${reqValue}`);
        }
        else {
            return personaEntry.includes(`${reqValue}`);
        }
    }
    else {
        if (reqNot) {
            return `${personaEntry}` !== `${reqValue}`;
        }
        else {
            return `${personaEntry}` === `${reqValue}`;
        }
    }
}
