import {Component, EventEmitter, Input, Output, OnInit} from '@angular/core';
import { Router } from '@angular/router';
import { PagesService } from '@app/_services/pages.service';

@Component({
  selector: 'pages-menu',
  templateUrl: 'pages-menu.component.html',
  styleUrls: ['pages-menu.component.scss']
})
export class PagesMenuComponent implements OnInit {
  @Input() items: any[];
  @Input() level = 0;


  private currentURL:string;
  private root = false;

  constructor(
    private pagesService: PagesService,
    private router: Router,
    
  ){
    router.events.subscribe((event:any)=>{
      if(event.url)this.currentURL = event.url
    })
    this.currentURL = router.url
  }
  

  private hiddenPages = ['/o-tsentre/protivodeistvie-korruptsii', '/o-tsentre/zashchita-personalnykh-dannykh', '/o-tsentre/okhrana-truda'];
  get visibleItems() {
    return this.items?.filter(item => {
      return this.hiddenPages.indexOf(item.link) === -1;
    });
  }

  ngOnInit() {

    if (!this.items){
      this.root = true;
      this.pagesService.pagesTree.subscribe(res=>{
        this.items = res.data
      }); 
    }    
  }
}
