<commit_before>import AnalyseCtrl from '../../ctrl';
import RelayCtrl from './relayCtrl';
import { dataIcon } from 'common/snabbdom';
import { h, VNode } from 'snabbdom';
import { innerHTML } from '../../util';
import { LeadPlayer, RelayRound } from './interfaces';
import { StudyCtrl } from '../interfaces';
import { view as multiBoardView } from '../multiBoard';

export default function (ctrl: AnalyseCtrl): VNode | undefined {
  const study = ctrl.study;
  const relay = study?.relay;
  if (study && relay?.tourShow.active) {
    const round = relay?.currentRound();
    return h('div.relay-tour', [
      h('div.relay-tour__text', [
        h('h1', relay.data.tour.name),
        h('div.relay-tour__round', [
          h('strong', round.name),
          ' ',
          round.ongoing
            ? ctrl.trans.noarg('playingRightNow')
            : round.startsAt
            ? h(
                'time.timeago',
                {
                  hook: {
                    insert(vnode) {
                      (vnode.elm as HTMLElement).setAttribute('datetime', '' + round.startsAt);
                    },
                  },
                },
                lichess.timeago(round.startsAt)
              )
            : null,
        ]),
        relay.data.tour.markup
          ? h('div', {
              hook: innerHTML(relay.data.tour.markup, () => relay.data.tour.markup!),
            })
          : h('div', relay.data.tour.description),
        roundsTable(relay),
        relay.data.leaderboard?.length ? leaderboard(relay.data.leaderboard) : undefined,
      ]),
      study.looksNew() ? null : multiBoardView(study.multiBoard, study),
    ]);
  }
  return undefined;
}

const leaderboard = (players: LeadPlayer[]): VNode => {
  const withRating = players.find(p => p.rating);
  return h('div.relay-tour__text__leaderboard', [
    h('table.slist.slist-invert', [
      h(
        'thead',
        h('tr', [
          h('th', h('h2', 'Leaderboard')),
          withRating ? h('th', 'Elo') : undefined,
          h('th', 'Score'),
          h('th', 'Games'),
        ])
      ),
      h(
        'tbody',
        players.map(player =>
          h('tr', [
            h('th', player.name),
            h('td', player.rating),
            withRating ? h('td', player.score) : undefined,
            h('td', player.played),
          ])
        )
      ),
    ]),
  ]);
};

const roundsTable = (relay: RelayCtrl): VNode =>
  h('div.relay-tour__text__schedule', [
    h('h2', 'Schedule'),
    h(
      'table.slist.slist-invert',<commit_msg>fix broadcast leaderboard display<commit_after>import AnalyseCtrl from '../../ctrl';
import RelayCtrl from './relayCtrl';
import { dataIcon } from 'common/snabbdom';
import { h, VNode } from 'snabbdom';
import { innerHTML } from '../../util';
import { LeadPlayer, RelayRound } from './interfaces';
import { StudyCtrl } from '../interfaces';
import { view as multiBoardView } from '../multiBoard';

export default function (ctrl: AnalyseCtrl): VNode | undefined {
  const study = ctrl.study;
  const relay = study?.relay;
  if (study && relay?.tourShow.active) {
    const round = relay?.currentRound();
    return h('div.relay-tour', [
      h('div.relay-tour__text', [
        h('h1', relay.data.tour.name),
        h('div.relay-tour__round', [
          h('strong', round.name),
          ' ',
          round.ongoing
            ? ctrl.trans.noarg('playingRightNow')
            : round.startsAt
            ? h(
                'time.timeago',
                {
                  hook: {
                    insert(vnode) {
                      (vnode.elm as HTMLElement).setAttribute('datetime', '' + round.startsAt);
                    },
                  },
                },
                lichess.timeago(round.startsAt)
              )
            : null,
        ]),
        relay.data.tour.markup
          ? h('div', {
              hook: innerHTML(relay.data.tour.markup, () => relay.data.tour.markup!),
            })
          : h('div', relay.data.tour.description),
        roundsTable(relay),
        relay.data.leaderboard?.length ? leaderboard(relay.data.leaderboard) : undefined,
      ]),
      study.looksNew() ? null : multiBoardView(study.multiBoard, study),
    ]);
  }
  return undefined;
}

const leaderboard = (players: LeadPlayer[]): VNode => {
  const withRating = players.find(p => p.rating);
  return h('div.relay-tour__text__leaderboard', [
    h('table.slist.slist-invert', [
      h(
        'thead',
        h('tr', [
          h('th', h('h2', 'Leaderboard')),
          withRating ? h('th', 'Elo') : undefined,
          h('th', 'Score'),
          h('th', 'Games'),
        ])
      ),
      h(
        'tbody',
        players.map(player =>
          h('tr', [
            h('th', player.name),
            withRating ? h('td', player.rating) : undefined,
            h('td', player.score),
            h('td', player.played),
          ])
        )
      ),
    ]),
  ]);
};

const roundsTable = (relay: RelayCtrl): VNode =>
  h('div.relay-tour__text__schedule', [
    h('h2', 'Schedule'),
    h(
      'table.slist.slist-invert',
{'fraction_non_alphanumeric': 0.16478379431242696, 'fraction_numerical': 0.001168679392286716, 'mean_word_length': 1.8338852097130243, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4219278', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1568, 'n_words': 288}