<commit_before>import {
  Component,
  EventEmitter,
  ContentChildren,
  HostBinding,
  QueryList,
  Output,
  Input,
  forwardRef,
  Provider
} from '@angular/core'
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms'
import {curry, compose, equals, isNil, prop} from 'ramda'

const setActive = curry((isActive: boolean, object: TextSelectorItem) => object.active = isActive)

const TEXT_SELECTOR_CONTROL_VALUE_ACCESSOR = new Provider(NG_VALUE_ACCESSOR, {
  useExisting: forwardRef(() => TextSelector),
  multi: true
})

@Component({
  selector: 'text-selector',
  templateUrl: './text-selector.pug',
  styleUrls: ['./text-selector.scss'],
  providers: [TEXT_SELECTOR_CONTROL_VALUE_ACCESSOR]
})
export class TextSelector implements ControlValueAccessor {
  @ContentChildren(forwardRef(() => TextSelectorItem)) public selectItems: QueryList<TextSelectorItem>
  @Output() public onClick = new EventEmitter<any>()
  private _onChange: any
  private _onTouch: any

  public registerOnChange(onChangeFn: any) {
    this._onChange = onChangeFn
  }

  public registerOnTouched(onTouchFn: any) {
    this._onTouch = onTouchFn
  }

  public writeValue(value) {
    if (!this.selectItems)
      return
    else if (isNil(value))
      this.selectItems.forEach(setActive(false))

    this._selectItemByValue(value)
  }

  public itemSelected(textItem: TextSelectorItem) {
    this.writeValue(textItem.value)

    if (this._onChange)
      this._onChange(textItem.value)

    this.onClick.emit(textItem.value)
  }

  private _selectItemByValue(value) {
    const isCurrentValue = compose(
      equals(value),
      prop('value')
    )

    this.selectItems.forEach(item => {
      const isActiveItem = isCurrentValue(item)

      if (item.active && !isActiveItem) {
        item.active = false
        item.onDeselect.emit(item.value)
      } else if (isActiveItem) {
        item.active = true
        item.onSelect.emit(item.value)
      }
    })
  }
}

@Component({
  selector: 'text-selector-item',
  templateUrl: './text-selector-item/text-selector-item.pug
  styleUrls: ['./text-selector-item/text-selector-item.scss']
})
export class TextSelectorItem {
  @Input() public value: any<commit_msg>fix comma<commit_after>import {
  Component,
  EventEmitter,
  ContentChildren,
  HostBinding,
  QueryList,
  Output,
  Input,
  forwardRef,
  Provider
} from '@angular/core'
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms'
import {curry, compose, equals, isNil, prop} from 'ramda'

const setActive = curry((isActive: boolean, object: TextSelectorItem) => object.active = isActive)

const TEXT_SELECTOR_CONTROL_VALUE_ACCESSOR = new Provider(NG_VALUE_ACCESSOR, {
  useExisting: forwardRef(() => TextSelector),
  multi: true
})

@Component({
  selector: 'text-selector',
  templateUrl: './text-selector.pug',
  styleUrls: ['./text-selector.scss'],
  providers: [TEXT_SELECTOR_CONTROL_VALUE_ACCESSOR]
})
export class TextSelector implements ControlValueAccessor {
  @ContentChildren(forwardRef(() => TextSelectorItem)) public selectItems: QueryList<TextSelectorItem>
  @Output() public onClick = new EventEmitter<any>()
  private _onChange: any
  private _onTouch: any

  public registerOnChange(onChangeFn: any) {
    this._onChange = onChangeFn
  }

  public registerOnTouched(onTouchFn: any) {
    this._onTouch = onTouchFn
  }

  public writeValue(value) {
    if (!this.selectItems)
      return
    else if (isNil(value))
      this.selectItems.forEach(setActive(false))

    this._selectItemByValue(value)
  }

  public itemSelected(textItem: TextSelectorItem) {
    this.writeValue(textItem.value)

    if (this._onChange)
      this._onChange(textItem.value)

    this.onClick.emit(textItem.value)
  }

  private _selectItemByValue(value) {
    const isCurrentValue = compose(
      equals(value),
      prop('value')
    )

    this.selectItems.forEach(item => {
      const isActiveItem = isCurrentValue(item)

      if (item.active && !isActiveItem) {
        item.active = false
        item.onDeselect.emit(item.value)
      } else if (isActiveItem) {
        item.active = true
        item.onSelect.emit(item.value)
      }
    })
  }
}

@Component({
  selector: 'text-selector-item',
  templateUrl: './text-selector-item/text-selector-item.pug,
  styleUrls: ['./text-selector-item/text-selector-item.scss']
})
export class TextSelectorItem {
  @Input() public value: any
{'fraction_non_alphanumeric': 0.11800679501698755, 'fraction_numerical': 0.0, 'mean_word_length': 3.9395973154362416, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '3833887', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1394, 'n_words': 274}