import {Component} from '@angular/core';
import {ActivatedRoute, NavigationEnd, Router} from "@angular/router";
import {Subscription} from "rxjs";

@Component({
  templateUrl: 'administration-page.component.html',
  styleUrls: ['administration-page.component.scss']
})
export class AdministrationPageComponent {
  public tabs = <any>[{name: 'company', title: 'Структура ФАУ «ФЦС»'}, {name: 'committee', title: 'Структура ТК 465'}];
  routeSubscription: Subscription;

  constructor(private route: ActivatedRoute, private router: Router) {
    this.routeSubscription = this.router.events.subscribe(event => {
      if (event instanceof NavigationEnd && (this.route.snapshot.paramMap.get('tab') !== this.tab?.name)) this.switchTab(this.route.snapshot.paramMap.get('tab'));
    });
  }

  get tab() {
    return this.tabs.filter(tab => {return tab.active})[0];
  }

  ngOnInit() {

  }

  ngOnDestroy() {
    this.routeSubscription?.unsubscribe();
  }


  switchTab(name: string) {
    this.tabs.map(tab => {tab.active = tab.name === name});
  }

}
