<commit_before>// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @ts-nocheck
// TODO(crbug.com/1011811): Enable TypeScript compiler checks

import {HBox} from './Widget.js';

export class SegmentedButton extends HBox {
  constructor() {
    super(true);
    /** @type {!Map<string, !Element>} */
    this._buttons = new Map();

    /** @type {?string} */
    this._selected = null;
    this.registerRequiredCSS('ui/segmentedButton.css');
    this.contentElement.classList.add('segmented-button');
  }

  /**
   * @param {string} label
   * @param {string} value
   * @param {string=} tooltip
   */
  addSegment(label, value, tooltip) {
    const button = this.contentElement.createChild('button', 'segmented-button-segment');
    button.textContent = label;
    button.title = tooltip;
    this._buttons.set(value, button);
    button.addEventListener('click', () => this.select(value));
  }

  /**
   * @param {string} value
   */
  select(value) {
    if (this._selected === value) {
      return;
    }
    this._selected = value;
    for (const key of this._buttons.keys()) {
      this._buttons.get(key).classList.toggle('segmented-button-segment-selected', key === this._selected);
    }
  }

  /**
   * @return {?string}
   */
  selected() {
    return this._selected;<commit_msg>[ts] Type-check ui/SegmentedButton.js with TypeScript<commit_after>// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import {HBox} from './Widget.js';

export class SegmentedButton extends HBox {
  constructor() {
    super(true);
    /** @type {!Map<string, !Element>} */
    this._buttons = new Map();

    /** @type {?string} */
    this._selected = null;
    this.registerRequiredCSS('ui/segmentedButton.css');
    this.contentElement.classList.add('segmented-button');
  }

  /**
   * @param {string} label
   * @param {string} value
   * @param {string=} tooltip
   */
  addSegment(label, value, tooltip) {
    const button = this.contentElement.createChild('button', 'segmented-button-segment');
    button.textContent = label;
    if (tooltip) {
      button.title = tooltip;
    }
    this._buttons.set(value, button);
    button.addEventListener('click', () => this.select(value));
  }

  /**
   * @param {string} value
   */
  select(value) {
    if (this._selected === value) {
      return;
    }
    this._selected = value;
    for (const [key, button] of this._buttons) {
      button.classList.toggle('segmented-button-segment-selected', key === this._selected);
    }
  }

  /**
   * @return {?string}
   */
  selected() {
    return this._selected;
{'fraction_non_alphanumeric': 0.15351506456241032, 'fraction_numerical': 0.005380200860832138, 'mean_word_length': 3.065597667638484, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3689765', 'n_tokens_mistral': 878, 'n_tokens_neox': 856, 'n_words': 208}