<commit_before>import './participants.postcss';
import currentGuildId from '../common/currentGuildId';
import {isArray} from '../common/isArray';
import isObject from '../common/isObject';
import partial from '../common/partial';
import querySelectorArray from '../common/querySelectorArray';

const addId = e => [e, Number(e.previousElementSibling.value)];

function addMeta(json, e) {
  if (json.r && json.r.arenas) {
    return e.concat(json.r.arenas.find(a => a.id === e[1]));
  }
  return e;
}

function listPlayers(myGuild, p) {
  if (p.guild_id === myGuild) {
    return '<span class="fshRed">' + p.name + '</span>';
  }
  return p.name;
}

const joinBtn = (myGuild, button) => myGuild && button.value === 'Join';

function testGuildies(myGuild, button, arena) {
  const fromMyGuild = arena.players.filter(p => p.guild_id === myGuild)
    .length;
  const maxGuildies = arena.max_players / 4;
  if (fromMyGuild === maxGuildies) {button.classList.add('fshGray');}
}

function hazPlayers(myGuild, button, arena) {
  button.dataset.tipped = arena.players.map(partial(listPlayers, myGuild))
    .join('<br>');
  button.classList.add('tip-static');
  if (joinBtn(myGuild, button)) {testGuildies(myGuild, button, arena);}
}

const arenaChecks = [isObject, e => isArray(e.players),
  e => e.players.length > 0];

function decorate(myGuild, [button, , arena]) {
  if (arenaChecks.every(f => f(arena))) {
    hazPlayers(myGuild, button, arena);
  }
}

export default function participants(json) {
  if (!json.s) {return;}
  const theButtons = querySelectorArray(
    '#arenaTypeTabs tr:not([style="display: none;"]) input[type="submit"]');
  const withPvpId = theButtons.map(addId);
  const withMeta = withPvpId.map(partial(addMeta, json));
  withMeta.forEach(partial(decorate, currentGuildId()));
  return 0;
}<commit_msg>grey out join button when max moves<commit_after>import './participants.postcss';
import currentGuildId from '../common/currentGuildId';
import {isArray} from '../common/isArray';
import isObject from '../common/isObject';
import partial from '../common/partial';
import querySelectorArray from '../common/querySelectorArray';

const addId = e => [e, Number(e.previousElementSibling.value)];

function addMeta(json, e) {
  if (json.r.arenas) {
    return e.concat(json.r.arenas.find(a => a.id === e[1]));
  }
  return e;
}

function listPlayers(myGuild, p) {
  if (p.guild_id === myGuild) {
    return '<span class="fshRed">' + p.name + '</span>';
  }
  return p.name;
}

function grey(el) {
  if (el && el.classList) {el.classList.add('fshGray');}
}

const validMoves = (json, arena) => arena.reward_type === 1 && json.r.moves;

const findMove = (json, arena) => json.r.moves.find(a => a.id === arena.reward);

const isMax = thisMove => thisMove && thisMove.max === 3;

const hasMax = (json, arena) =>
  validMoves(json, arena) && isMax(findMove(json, arena));

function testMoves(json, [button, , arena]) {
  if (hasMax(json, arena)) {grey(button);}
}

function testGuildies(myGuild, button, arena) {
  const fromMyGuild = arena.players.filter(p => p.guild_id === myGuild)
    .length;
  const maxGuildies = arena.max_players / 4;
  if (fromMyGuild === maxGuildies) {grey(button);}
}

function hazPlayers(myGuild, button, arena) {
  button.dataset.tipped = arena.players.map(partial(listPlayers, myGuild))
    .join('<br>');
  button.classList.add('tip-static');
  if (myGuild && button.value === 'Join') {
    testGuildies(myGuild, button, arena);
  }
}

const arenaPlayerListChecks = [
  isObject,
  e => isArray(e.players),
  e => e.players.length > 0
];

function decorate(myGuild, [button, , arena]) {
  if (arenaPlayerListChecks.every(f => f(arena))) {
    hazPlayers(myGuild, button, arena);
  }
}

export default function participants(json) {
  if (!json.s || !isObject(json.r)) {return;}
  const theButtons = querySelectorArray(
    '#arenaTypeTabs tr:not([style="display: none;"]) input[type="submit"]');
  const withPvpId = theButtons.map(addId);
  const withMeta = withPvpId.map(partial(addMeta, json));
  withMeta.forEach(partial(decorate, currentGuildId()));
  withMeta.forEach(partial(testMoves, json));
  return 0;
}
{'fraction_non_alphanumeric': 0.17328519855595667, 'fraction_numerical': 0.0024067388688327317, 'mean_word_length': 4.646739130434782, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6519747', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1479, 'n_words': 314}