import { Component, OnInit, Input, Output, EventEmitter, ElementRef, AfterViewInit } from '@angular/core';

@Component({
  selector: 'neu-toggle',
  templateUrl: './neu-toggle.component.html',
  styleUrls: ['./neu-toggle.component.css']
})
export class NeuToggleComponent implements OnInit, AfterViewInit {

  @Input() value:any;
  @Output('selected') selected = new EventEmitter<any>();
  public text:string;
  public active:boolean = false;
  
  constructor(private eRef:ElementRef) { }

  ngOnInit(): void {
  }

  ngAfterViewInit() {
    this.text = this.eRef.nativeElement.firstElementChild.textContent;
  }

  onClick() {
    this.active = !this.active;
    this.selected.emit({
      value: this.value,
      active: this.active
    });
  }

}
