<commit_before>import { customElement, bindable, ViewResources } from 'aurelia-templating';
import { computedFrom, bindingMode } from 'aurelia-binding';
import { inject } from 'aurelia-dependency-injection';
import { StyleEngine, UxComponent, normalizeBooleanAttribute } from '@aurelia-ux/core';
import { UxSwitchTheme } from './ux-switch-theme';

@inject(Element, ViewResources, StyleEngine)
@customElement('ux-switch')

export class UxSwitch implements UxComponent {
  @bindable public disabled: boolean | string = false;
  @bindable public effect = null;
  @bindable public id: string;
  @bindable public tabindex = 0;
  @bindable public theme: UxSwitchTheme;

  @bindable({ defaultBindingMode: bindingMode.twoWay })
  @bindable public checked: boolean = false;

  @computedFrom('disabled')
  public get isDisabled() {
    return normalizeBooleanAttribute('disabled', this.disabled);
  }

  constructor(public element: HTMLElement, public resources: ViewResources, private styleEngine: StyleEngine) {
    styleEngine.ensureDefaultTheme(new UxSwitchTheme());
  }

  public bind() {
    this.themeChanged(this.theme);

    if (this.checked) {
      this.checkedChanged();
    }

    if (normalizeBooleanAttribute('disabled', this.disabled) && !this.element.classList.contains('disabled')) {
      this.element.classList.add('disabled');
    } else if (this.element.classList.contains('disabled')) {
      this.element.classList.remove('disabled');
    }
  }

  public attached() {
    if (this.id) {
      const labelElement = document.querySelector(`label[for=${this.id}]`);

      if (labelElement != null) {
        labelElement.addEventListener('click', () => {
          this.toggleSwitch();
        });
      }
    }
  }

  public detached() {
    if (this.id) {
      const labelElement = document.querySelector(`label[for=${this.id}]`);

      if (labelElement != null) {
        labelElement.removeEventListener('click', () => {
          this.toggleSwitch();
        });
      }
    }
  }

  public themeChanged(newValue: UxSwitchTheme) {
    if (newValue != null && newValue.themeKey == null) {
      newValue.themeKey = 'radio';
    }

    this.styleEngine.applyTheme(newValue, this.element);
  }

  public disabledChanged(newValue: boolean | string) {
    if (normalizeBooleanAttribute('disabled', newValue) && !this.element.classList.contains('disabled')) {
      this.element.classList.add('disabled');
    } else if (this.element.classList.contains('disabled')) {
      this.element.classList.remove('disabled');
    }
  }
<commit_msg>fix(switch): use the correct theme key<commit_after>import { customElement, bindable, ViewResources } from 'aurelia-templating';
import { computedFrom, bindingMode } from 'aurelia-binding';
import { inject } from 'aurelia-dependency-injection';
import { StyleEngine, UxComponent, normalizeBooleanAttribute } from '@aurelia-ux/core';
import { UxSwitchTheme } from './ux-switch-theme';

@inject(Element, ViewResources, StyleEngine)
@customElement('ux-switch')

export class UxSwitch implements UxComponent {
  @bindable public disabled: boolean | string = false;
  @bindable public effect = null;
  @bindable public id: string;
  @bindable public tabindex = 0;
  @bindable public theme: UxSwitchTheme;

  @bindable({ defaultBindingMode: bindingMode.twoWay })
  @bindable public checked: boolean = false;

  @computedFrom('disabled')
  public get isDisabled() {
    return normalizeBooleanAttribute('disabled', this.disabled);
  }

  constructor(public element: HTMLElement, public resources: ViewResources, private styleEngine: StyleEngine) {
    styleEngine.ensureDefaultTheme(new UxSwitchTheme());
  }

  public bind() {
    this.themeChanged(this.theme);

    if (this.checked) {
      this.checkedChanged();
    }

    if (normalizeBooleanAttribute('disabled', this.disabled) && !this.element.classList.contains('disabled')) {
      this.element.classList.add('disabled');
    } else if (this.element.classList.contains('disabled')) {
      this.element.classList.remove('disabled');
    }
  }

  public attached() {
    if (this.id) {
      const labelElement = document.querySelector(`label[for=${this.id}]`);

      if (labelElement != null) {
        labelElement.addEventListener('click', () => {
          this.toggleSwitch();
        });
      }
    }
  }

  public detached() {
    if (this.id) {
      const labelElement = document.querySelector(`label[for=${this.id}]`);

      if (labelElement != null) {
        labelElement.removeEventListener('click', () => {
          this.toggleSwitch();
        });
      }
    }
  }

  public themeChanged(newValue: UxSwitchTheme) {
    if (newValue != null && newValue.themeKey == null) {
      newValue.themeKey = 'switch';
    }

    this.styleEngine.applyTheme(newValue, this.element);
  }

  public disabledChanged(newValue: boolean | string) {
    if (normalizeBooleanAttribute('disabled', newValue) && !this.element.classList.contains('disabled')) {
      this.element.classList.add('disabled');
    } else if (this.element.classList.contains('disabled')) {
      this.element.classList.remove('disabled');
    }
  }

{'fraction_non_alphanumeric': 0.13781676413255362, 'fraction_numerical': 0.0003898635477582846, 'mean_word_length': 3.8223684210526314, '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': '3930088', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1464, 'n_words': 297}