import { Component, ContentChildren, QueryList, AfterViewInit, ChangeDetectorRef, AfterViewChecked } from '@angular/core';
import { NeuSlideComponent } from './neu-slide/neu-slide.component';

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

  @ContentChildren(NeuSlideComponent) slides:QueryList<NeuSlideComponent>;

  constructor(private cdRef:ChangeDetectorRef) { }

  ngAfterViewInit() {
    this.slides.first?.activate();
  }

  ngAfterViewChecked() {
    this.cdRef.detectChanges();
  }

  changeSlide(slide:NeuSlideComponent) {
    this.slides.forEach(s => {
      if(slide==s) s.activate();
      else s.deactivate();
    });
  }

}
