import { Component, OnInit, ContentChildren, QueryList, AfterViewInit } from '@angular/core';
import { NeuExpansionPanelComponent } from '../neu-expansion-panel/neu-expansion-panel.component';

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

  @ContentChildren(NeuExpansionPanelComponent) panels:QueryList<NeuExpansionPanelComponent>;

  constructor() { }

  ngAfterViewInit() {
    this.panels.forEach(p => {
      p.onOpen.subscribe(opened => {
        if(opened) {
          this.panels.forEach(pan => {
            if(pan!=p) pan.close();
          });
        }
      });
    });
  }

}
