<commit_before>import { h } from 'snabbdom'
import { VNode } from 'snabbdom/vnode'
import { bind, dataIcon, iconTag, richHTML } from '../util';
import { view as memberView } from './studyMembers';
import { view as chapterView } from './studyChapters';
import { view as chapterNewFormView } from './chapterNewForm';
import { view as chapterEditFormView } from './chapterEditForm';
import * as commentForm from './commentForm';
import * as glyphForm from './studyGlyph';
import { view as inviteFormView } from './inviteForm';
import { view as studyFormView } from './studyForm';
import { view as studyShareView } from './studyShare';
import { view as multiBoardView } from './multiBoard';
import { view as notifView } from './notif';
import { view as tagsView } from './studyTags';
import { view as serverEvalView } from './serverEval';
import * as practiceView from './practice/studyPracticeView';
import { playButtons as gbPlayButtons, overrideButton as gbOverrideButton } from './gamebook/gamebookButtons';
import { view as descView } from './description';
import AnalyseCtrl from '../ctrl';
import { StudyCtrl, Tab, ToolTab } from './interfaces';
import { MaybeVNodes } from '../interfaces';


interface ToolButtonOpts {
  ctrl: StudyCtrl;
  tab: ToolTab;
  hint: string;
  icon: VNode;
  onClick?: () => void;
  count?: number | string;
}

function toolButton(opts: ToolButtonOpts): VNode {
  return h('span.' + opts.tab, {
    attrs: { title: opts.hint },
    class: { active: opts.tab === opts.ctrl.vm.toolTab() },
    hook: bind('mousedown', () => {
      if (opts.onClick) opts.onClick();
      opts.ctrl.vm.toolTab(opts.tab);
    }, opts.ctrl.redraw)
  }, [
    opts.count ? h('count.data-count', { attrs: { 'data-count': opts.count } }) : null,
    opts.icon
  ]);
}

function buttons(root: AnalyseCtrl): VNode {
  const ctrl: StudyCtrl = root.study!,
    canContribute = ctrl.members.canContribute(),
    showSticky = ctrl.data.features.sticky && (canContribute || (ctrl.vm.behind && ctrl.isUpdatedRecently()));
  return h('div.study__buttons', [
    h('div.left-buttons.tabs-horiz', [
      // distinct classes (sync, write) allow snabbdom to differentiate buttons
      showSticky ? h('a.mode.sync', {
        attrs: { title: root.trans.noarg('allSyncMembersRemainOnTheSamePosition') },
        class: { on: ctrl.vm.mode.sticky },
        hook: bind('click', ctrl.toggleSticky)
      }, [
        ctrl.vm.behind ? h('span.behind', '' + ctrl.vm.behind) : h('i.is'),
        'SYNC'
      ]) : null,
      ctrl.members.canContribute() ? h('a.mode.write', {
        attrs: { title: ctrl.trans.noarg('shareChanges') },
        class: { on: ctrl.vm.mode.write },
        hook: bind('click', ctrl.toggleWrite)
      }, [ h('i.is'), 'REC' ]) : null,
      toolButton({
        ctrl,
        tab: 'tags',
        hint: ctrl.trans.noarg('pgnTags'),
        icon: iconTag('o'),
      }),
      toolButton({
        ctrl,
        tab: 'comments',
        hint: ctrl.trans.noarg('commentThisPosition'),
        icon: iconTag('c'),
        onClick() {
          ctrl.commentForm.start(ctrl.vm.chapterId, root.path, root.node);
        },
        count: (root.node.comments || []).length
      }),
      canContribute ?  toolButton({
        ctrl,
        tab: 'glyphs',
        hint: ctrl.trans.noarg('annotateWithGlyphs'),
        icon: h('i.glyph-icon'),
        count: (root.node.glyphs || []).length
      }) : null,
      toolButton({
        ctrl,
        tab: 'serverEval',
        hint: root.trans.noarg('computerAnalysis'),
        icon: iconTag(''),
        count: root.data.analysis && '✓'
      }),
      toolButton({
        ctrl,
        tab: 'multiBoard',
        hint: 'Multiboard',
        icon: iconTag('')
      }),
      toolButton({
        ctrl,
        tab: 'share',
        hint: ctrl.trans.noarg('shareAndExport'),
        icon: iconTag('$')
      }),
      h('span.help', {
        attrs: { title: 'Need help? Get the tour!', 'data-icon': '' },
        hook: bind('click', ctrl.startTour)
      })
    ]),
    h('div.right', [
      gbOverrideButton(ctrl)
    ])
  ]);
}

function metadata(ctrl: StudyCtrl): VNode {
  const d = ctrl.data,
    credit = ctrl.relay && ctrl.relay.data.credit;
  return h('div.study__metadata', [
    h('h2', [
      h('span.name', [
        d.name,
        ': ' + ctrl.currentChapter().name,
        credit ?  h('span.credit', { hook: richHTML(credit, false) }) : undefined
      ]),
      h('span.liking.text', {
        class: { liked: d.liked },
        attrs: {
          'data-icon': d.liked ? '' : '',
          title: ctrl.trans.noarg('like')
        },
        hook: bind('click', ctrl.toggleLike)
      }, '' + d.likes)<commit_msg>TS tweak<commit_after>import { h } from 'snabbdom'
import { VNode } from 'snabbdom/vnode'
import { bind, dataIcon, iconTag, richHTML } from '../util';
import { view as memberView } from './studyMembers';
import { view as chapterView } from './studyChapters';
import { view as chapterNewFormView } from './chapterNewForm';
import { view as chapterEditFormView } from './chapterEditForm';
import * as commentForm from './commentForm';
import * as glyphForm from './studyGlyph';
import { view as inviteFormView } from './inviteForm';
import { view as studyFormView } from './studyForm';
import { view as studyShareView } from './studyShare';
import { view as multiBoardView } from './multiBoard';
import { view as notifView } from './notif';
import { view as tagsView } from './studyTags';
import { view as serverEvalView } from './serverEval';
import * as practiceView from './practice/studyPracticeView';
import { playButtons as gbPlayButtons, overrideButton as gbOverrideButton } from './gamebook/gamebookButtons';
import { view as descView } from './description';
import AnalyseCtrl from '../ctrl';
import { StudyCtrl, Tab, ToolTab } from './interfaces';
import { MaybeVNodes } from '../interfaces';


interface ToolButtonOpts {
  ctrl: StudyCtrl;
  tab: ToolTab;
  hint: string;
  icon: VNode;
  onClick?: () => void;
  count?: number | string;
}

function toolButton(opts: ToolButtonOpts): VNode {
  return h('span.' + opts.tab, {
    attrs: { title: opts.hint },
    class: { active: opts.tab === opts.ctrl.vm.toolTab() },
    hook: bind('mousedown', () => {
      if (opts.onClick) opts.onClick();
      opts.ctrl.vm.toolTab(opts.tab);
    }, opts.ctrl.redraw)
  }, [
    opts.count ? h('count.data-count', { attrs: { 'data-count': opts.count } }) : null,
    opts.icon
  ]);
}

function buttons(root: AnalyseCtrl): VNode {
  const ctrl: StudyCtrl = root.study!,
    canContribute = ctrl.members.canContribute(),
    showSticky = ctrl.data.features.sticky && (canContribute || (ctrl.vm.behind && ctrl.isUpdatedRecently())),
    noarg = root.trans.noarg;
  return h('div.study__buttons', [
    h('div.left-buttons.tabs-horiz', [
      // distinct classes (sync, write) allow snabbdom to differentiate buttons
      showSticky ? h('a.mode.sync', {
        attrs: { title: noarg('allSyncMembersRemainOnTheSamePosition') },
        class: { on: ctrl.vm.mode.sticky },
        hook: bind('click', ctrl.toggleSticky)
      }, [
        ctrl.vm.behind ? h('span.behind', '' + ctrl.vm.behind) : h('i.is'),
        'SYNC'
      ]) : null,
      ctrl.members.canContribute() ? h('a.mode.write', {
        attrs: { title: noarg('shareChanges') },
        class: { on: ctrl.vm.mode.write },
        hook: bind('click', ctrl.toggleWrite)
      }, [ h('i.is'), 'REC' ]) : null,
      toolButton({
        ctrl,
        tab: 'tags',
        hint: noarg('pgnTags'),
        icon: iconTag('o'),
      }),
      toolButton({
        ctrl,
        tab: 'comments',
        hint: noarg('commentThisPosition'),
        icon: iconTag('c'),
        onClick() {
          ctrl.commentForm.start(ctrl.vm.chapterId, root.path, root.node);
        },
        count: (root.node.comments || []).length
      }),
      canContribute ?  toolButton({
        ctrl,
        tab: 'glyphs',
        hint: noarg('annotateWithGlyphs'),
        icon: h('i.glyph-icon'),
        count: (root.node.glyphs || []).length
      }) : null,
      toolButton({
        ctrl,
        tab: 'serverEval',
        hint: noarg('computerAnalysis'),
        icon: iconTag(''),
        count: root.data.analysis && '✓'
      }),
      toolButton({
        ctrl,
        tab: 'multiBoard',
        hint: 'Multiboard',
        icon: iconTag('')
      }),
      toolButton({
        ctrl,
        tab: 'share',
        hint: noarg('shareAndExport'),
        icon: iconTag('$')
      }),
      h('span.help', {
        attrs: { title: 'Need help? Get the tour!', 'data-icon': '' },
        hook: bind('click', ctrl.startTour)
      })
    ]),
    h('div.right', [
      gbOverrideButton(ctrl)
    ])
  ]);
}

function metadata(ctrl: StudyCtrl): VNode {
  const d = ctrl.data,
    credit = ctrl.relay && ctrl.relay.data.credit;
  return h('div.study__metadata', [
    h('h2', [
      h('span.name', [
        d.name,
        ': ' + ctrl.currentChapter().name,
        credit ?  h('span.credit', { hook: richHTML(credit, false) }) : undefined
      ]),
      h('span.liking.text', {
        class: { liked: d.liked },
        attrs: {
          'data-icon': d.liked ? '' : '',
          title: ctrl.trans.noarg('like')
        },
        hook: bind('click', ctrl.toggleLike)
      }, '' + d.likes)
{'fraction_non_alphanumeric': 0.16884228546971966, 'fraction_numerical': 0.00021399529210357372, 'mean_word_length': 2.6102742371572036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1191451', 'n_tokens_mistral': 3030, 'n_tokens_neox': 2959, 'n_words': 684}