<commit_before>import {
  AfterViewInit,
  Component,
  ElementRef,
  Inject,
  Input,
  OnDestroy,
  Renderer
} from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
import { LightboxEvent, LIGHTBOX_EVENT, IEvent } from './lightbox-event.service';
import { Subscription } from 'rxjs/Subscription';

@Component({
  selector: '[lb-overlay]',
  template: '',
  host: {
    '(click)': 'close()',
    '[class]': '_classList'
  }
})
export class LightboxOverlayComponent implements AfterViewInit, OnDestroy {
  @Input() options: any;
  @Input() cmpRef: any;
  private _subscription: Subscription;
  private _classList: string;
  constructor(
    private _elemRef: ElementRef,
    private _rendererRef: Renderer,
    private _lightboxEvent: LightboxEvent,
    @Inject(DOCUMENT) private _documentRef: any
  ) {
    this._classList = 'lightboxOverlay animation fadeInOverlay';
    this._subscription = this._lightboxEvent.lightboxEvent$.subscribe((event: IEvent) => this._onReceivedEvent(event));
  }

  public ngAfterViewInit(): void {
    const width = this._getOverlayWidth();
    const height = this._getOverlayHeight();
    const fadeDuration = this.options.fadeDuration;

    this._rendererRef.setElementStyle(this._elemRef.nativeElement, 'width', `${width}px`);
    this._rendererRef.setElementStyle(this._elemRef.nativeElement, 'height', `${height}px`);
    this._rendererRef.setElementStyle(this._elemRef.nativeElement,
      '-webkit-animation-duration', `${fadeDuration}s`);
    this._rendererRef.setElementStyle(this._elemRef.nativeElement,
      '-animation-duration', `${fadeDuration}s`);
  }

  public close(): void {
    // broadcast to itself and all others subscriber including the components
    this._lightboxEvent.broadcastLightboxEvent({ id: LIGHTBOX_EVENT.CLOSE, data: null });
  }

  public ngOnDestroy(): void {
    this._subscription.unsubscribe();
  }

  private _onReceivedEvent(event: IEvent): void {
    switch (event.id) {
      case LIGHTBOX_EVENT.CLOSE:
        this._end();
      break;
      default:
      break;
    }
  }

  private _end(): void {
    this._classList = 'lightboxOverlay animation fadeOutOverlay';

    // queue self destruction after the animation has finished
    // FIXME: not sure if there is any way better than this<commit_msg>Add window resize event<commit_after>import {
  AfterViewInit,
  Component,
  ElementRef,
  HostListener,
  Inject,
  Input,
  OnDestroy,
  Renderer
} from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
import { LightboxEvent, LIGHTBOX_EVENT, IEvent } from './lightbox-event.service';
import { Subscription } from 'rxjs/Subscription';

@Component({
  selector: '[lb-overlay]',
  template: '',
  host: {
    '(click)': 'close()',
    '[class]': '_classList'
  }
})
export class LightboxOverlayComponent implements AfterViewInit, OnDestroy {
  @Input() options: any;
  @Input() cmpRef: any;
  private _subscription: Subscription;
  private _classList: string;
  constructor(
    private _elemRef: ElementRef,
    private _rendererRef: Renderer,
    private _lightboxEvent: LightboxEvent,
    @Inject(DOCUMENT) private _documentRef: any
  ) {
    this._classList = 'lightboxOverlay animation fadeInOverlay';
    this._subscription = this._lightboxEvent.lightboxEvent$.subscribe((event: IEvent) => this._onReceivedEvent(event));
  }

  public ngAfterViewInit(): void {
    const fadeDuration = this.options.fadeDuration;

    this._rendererRef.setElementStyle(this._elemRef.nativeElement,
      '-webkit-animation-duration', `${fadeDuration}s`);
    this._rendererRef.setElementStyle(this._elemRef.nativeElement,
      '-animation-duration', `${fadeDuration}s`);
    this._sizeOverlay();
  }

  public close(): void {
    // broadcast to itself and all others subscriber including the components
    this._lightboxEvent.broadcastLightboxEvent({ id: LIGHTBOX_EVENT.CLOSE, data: null });
  }

  @HostListener('window:resize')
  public onResize(): void {
    this._sizeOverlay();
  }

  public ngOnDestroy(): void {
    this._subscription.unsubscribe();
  }

  private _sizeOverlay(): void {
    const width = this._getOverlayWidth();
    const height = this._getOverlayHeight();

    this._rendererRef.setElementStyle(this._elemRef.nativeElement, 'width', `${width}px`);
    this._rendererRef.setElementStyle(this._elemRef.nativeElement, 'height', `${height}px`);
  }

  private _onReceivedEvent(event: IEvent): void {
    switch (event.id) {
      case LIGHTBOX_EVENT.CLOSE:
        this._end();
      break;
      default:
      break;
    }
  }

  private _end(): void {
    this._classList = 'lightboxOverlay animation fadeOutOverlay';

    // queue self destruction after the animation has finished
    // FIXME: not sure if there is any way better than this
{'fraction_non_alphanumeric': 0.1219410165237398, 'fraction_numerical': 0.0, 'mean_word_length': 4.103521878335112, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2249925', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1435, 'n_words': 326}