<commit_before>import {
  AfterContentInit,
  Component,
  ContentChildren,
  Directive,
  ElementRef,
  EventEmitter,
  Input,
  Output,
  QueryList,
  TemplateRef,
  ViewContainerRef,
  ViewEncapsulation,
  NgModule,
  ModuleWithProviders
} from '@angular/core';
import { CommonModule } from '@angular/common';

export class Md2TabChangeEvent {
  index: number;
  tab: Md2Tab;
}

@Directive({ selector: '[md2Transclude]' })
export class Md2Transclude {

  private _md2Transclude: TemplateRef<any>;

  constructor(public viewRef: ViewContainerRef) { }

  @Input()
  get md2Transclude() { return this._md2Transclude; }
  set md2Transclude(templateRef: TemplateRef<any>) {
    this._md2Transclude = templateRef;
    if (templateRef) {
      this.viewRef.createEmbeddedView(templateRef);
    }
  }

}

@Component({
  moduleId: module.id,
  selector: 'md2-tab',
  template: `<ng-content></ng-content>`,
  host: {
    '[class]': 'class',
    '[class.active]': 'active'
  }
})
export class Md2Tab {

  @Input() label: string;

  @Input() active: boolean;

  @Input() disabled: boolean;

  @Input() class: string;

  labelRef: TemplateRef<any>;

}

@Directive({ selector: '[md2-tab-label]' })
export class Md2TabLabel {
  constructor(public templateRef: TemplateRef<any>, tab: Md2Tab) {
    tab.labelRef = templateRef;
  }
}

@Component({
  moduleId: module.id,
  selector: 'md2-tabs',
  templateUrl: 'tabs.html',
  styleUrls: ['tabs.css'],
  host: {
    '[class]': 'class',
    '(window:resize)': 'onWindowResize($event)'
  },
  encapsulation: ViewEncapsulation.None
})
export class Md2Tabs implements AfterContentInit {

  @ContentChildren(Md2Tab) tabs: QueryList<Md2Tab>;

  private _isInitialized: boolean = false;
  private _focusIndex: number = 0;
  private _selectedIndex: number = 0;
  _shouldPaginate: boolean = false;
  _offsetLeft: number = 0;
  _inkBarLeft: string = '0';
  _inkBarWidth: string = '0';

  @Input() class: string;

  @Input()
  set selectedIndex(value: any) {
    if (typeof value === 'string') { value = parseInt(value); }
    if (value != this._selectedIndex) {
      this._selectedIndex = value;
      this.adjustOffset(value);
      this._updateInkBar();
      if (this.tabs) {
        const tabs = this.tabs.toArray();
        if (!tabs[value].disabled) {
          tabs.forEach(tab => tab.active = false);
          tabs[value].active = true;
        }
      }
      if (this._isInitialized) {
        this.change.emit(this._createChangeEvent(value));
      }
    }
  }
  get selectedIndex() { return this._selectedIndex; }

  get focusIndex(): number { return this._focusIndex; }
  set focusIndex(value: number) {
    this._focusIndex = value;
    this.adjustOffset(value);
  }

  get element() {
    const elements: any = {
      root: this.elementRef.nativeElement,
      wrapper: null,
      canvas: null,
      paging: null,
      tabs: null
    };
    elements.wrapper = elements.root.querySelector('.md2-tabs-header-wrapper');
    elements.canvas = elements.wrapper.querySelector('.md2-tabs-canvas');
    elements.paging = elements.canvas.querySelector('.md2-tabs-header');
    elements.tabs = elements.paging.querySelectorAll('.md2-tab-label');
    return elements;
  }

  @Output() change: EventEmitter<Md2TabChangeEvent> = new EventEmitter<Md2TabChangeEvent>();

  constructor(private elementRef: ElementRef) { }

  /**
   * After Content Init
   */
  ngAfterContentInit() {
    setTimeout(() => {
      this.updatePagination();
    }, 0);
    setTimeout(() => {
      const tabs = this.tabs.toArray();
      if (this.selectedIndex) {
        if (this.selectedIndex >= tabs.length) {
          this.selectedIndex = 0;
        }
        tabs.forEach(tab => tab.active = false);
        tabs[this.selectedIndex].active = true;
        this.adjustOffset(this.selectedIndex);
      } else {
        let index = tabs.findIndex((t: any) => t.active);
        if (index < 0) {
          tabs[0].active = true;
        } else {
          this.selectedIndex = index;
        }
      }
      this._updateInkBar();
    }, 0);
    this._isInitialized = true;
  }

  /**
   * Calculates the styles from the selected tab for the ink-bar.
   */
  private _updateInkBar(): void {
    let elements = this.element;
    if (!elements.tabs[this.selectedIndex]) { return; }
    let tab = elements.tabs[this.selectedIndex];
    this._inkBarLeft = tab.offsetLeft + 'px';
    this._inkBarWidth = tab.offsetWidth + 'px';
  }

  /**
   * Create Change Event
   * @param index
   * @return event of Md2TabChangeEvent
   */
  private _createChangeEvent(index: number): Md2TabChangeEvent {
    const event = new Md2TabChangeEvent;
    event.index = index;
    if (this.tabs && this.tabs.length) {
      event.tab = this.tabs.toArray()[index];
    }
    return event;
  }

  /**
   * Focus next Tab<commit_msg>chore(tabs) update change event<commit_after>import {
  AfterContentInit,
  Component,
  ContentChildren,
  Directive,
  ElementRef,
  EventEmitter,
  Input,
  Output,
  QueryList,
  TemplateRef,
  ViewContainerRef,
  ViewEncapsulation,
  NgModule,
  ModuleWithProviders
} from '@angular/core';
import { CommonModule } from '@angular/common';

/** Change event object that is emitted when the tab has changed. */
export class Md2TabChange {
  constructor(public tab: Md2Tab, public index: number) { }
}

@Directive({ selector: '[md2Transclude]' })
export class Md2Transclude {

  private _md2Transclude: TemplateRef<any>;

  constructor(public viewRef: ViewContainerRef) { }

  @Input()
  get md2Transclude() { return this._md2Transclude; }
  set md2Transclude(templateRef: TemplateRef<any>) {
    this._md2Transclude = templateRef;
    if (templateRef) {
      this.viewRef.createEmbeddedView(templateRef);
    }
  }

}

@Component({
  moduleId: module.id,
  selector: 'md2-tab',
  template: `<ng-content></ng-content>`,
  host: {
    '[class]': 'class',
    '[class.active]': 'active'
  }
})
export class Md2Tab {

  @Input() label: string;

  @Input() active: boolean;

  @Input() disabled: boolean;

  @Input() class: string;

  labelRef: TemplateRef<any>;

}

@Directive({ selector: '[md2-tab-label]' })
export class Md2TabLabel {
  constructor(public templateRef: TemplateRef<any>, tab: Md2Tab) {
    tab.labelRef = templateRef;
  }
}

@Component({
  moduleId: module.id,
  selector: 'md2-tabs',
  templateUrl: 'tabs.html',
  styleUrls: ['tabs.css'],
  host: {
    '[class]': 'class',
    '(window:resize)': 'onWindowResize($event)'
  },
  encapsulation: ViewEncapsulation.None
})
export class Md2Tabs implements AfterContentInit {

  @ContentChildren(Md2Tab) tabs: QueryList<Md2Tab>;

  private _isInitialized: boolean = false;
  private _focusIndex: number = 0;
  private _selectedIndex: number = 0;
  _shouldPaginate: boolean = false;
  _offsetLeft: number = 0;
  _inkBarLeft: string = '0';
  _inkBarWidth: string = '0';

  @Input() class: string;

  @Input()
  set selectedIndex(value: any) {
    if (typeof value === 'string') { value = parseInt(value); }
    if (value != this._selectedIndex) {
      this._selectedIndex = value;
      this.adjustOffset(value);
      this._updateInkBar();
      if (this.tabs) {
        const tabs = this.tabs.toArray();
        if (!tabs[value].disabled) {
          tabs.forEach(tab => tab.active = false);
          tabs[value].active = true;
        }
      }
      if (this._isInitialized) {
        this._emitChangeEvent();
      }
    }
  }
  get selectedIndex() { return this._selectedIndex; }

  get focusIndex(): number { return this._focusIndex; }
  set focusIndex(value: number) {
    this._focusIndex = value;
    this.adjustOffset(value);
  }

  get element() {
    const elements: any = {
      root: this.elementRef.nativeElement,
      wrapper: null,
      canvas: null,
      paging: null,
      tabs: null
    };
    elements.wrapper = elements.root.querySelector('.md2-tabs-header-wrapper');
    elements.canvas = elements.wrapper.querySelector('.md2-tabs-canvas');
    elements.paging = elements.canvas.querySelector('.md2-tabs-header');
    elements.tabs = elements.paging.querySelectorAll('.md2-tab-label');
    return elements;
  }

  @Output() change: EventEmitter<Md2TabChange> = new EventEmitter<Md2TabChange>();

  constructor(private elementRef: ElementRef) { }

  /**
   * After Content Init
   */
  ngAfterContentInit() {
    setTimeout(() => {
      this.updatePagination();
    }, 0);
    setTimeout(() => {
      const tabs = this.tabs.toArray();
      if (this.selectedIndex) {
        if (this.selectedIndex >= tabs.length) {
          this.selectedIndex = 0;
        }
        tabs.forEach(tab => tab.active = false);
        tabs[this.selectedIndex].active = true;
        this.adjustOffset(this.selectedIndex);
      } else {
        let index = tabs.findIndex((t: any) => t.active);
        if (index < 0) {
          tabs[0].active = true;
        } else {
          this.selectedIndex = index;
        }
      }
      this._updateInkBar();
    }, 0);
    this._isInitialized = true;
  }

  /**
   * Calculates the styles from the selected tab for the ink-bar.
   */
  private _updateInkBar(): void {
    let elements = this.element;
    if (!elements.tabs[this.selectedIndex]) { return; }
    let tab = elements.tabs[this.selectedIndex];
    this._inkBarLeft = tab.offsetLeft + 'px';
    this._inkBarWidth = tab.offsetWidth + 'px';
  }

  /** Emits an event when the user selects an option. */
  _emitChangeEvent(): void {
    this.change.emit(new Md2TabChange(this.tabs.toArray()[this._selectedIndex], this._selectedIndex));
  }

  /**
   * Focus next Tab
{'fraction_non_alphanumeric': 0.13827005543353205, 'fraction_numerical': 0.007530593034201443, 'mean_word_length': 3.098585512216031, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 33, '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': '6498883', 'n_tokens_mistral': 3115, 'n_tokens_neox': 3050, 'n_words': 653}