import { Component, OnInit, OnDestroy } from '@angular/core';
import { Router, NavigationStart, NavigationEnd, NavigationCancel } from '@angular/router';
import { Subscription } from 'rxjs';
import { NgCortexService } from '@ng-cortex/core';

@Component({
  selector: 'nc-layout',
  templateUrl: './nc-layout.component.html',
  styleUrls: ['./nc-layout.component.scss']
})
export class NcLayoutComponent implements OnInit, OnDestroy {

  _useReuse = false;
  _navigating = false;

  private _navigateSubscription: Subscription = null;

  constructor(
    private _router: Router,
    private _ncSrv: NgCortexService
    ) { }

  ngOnInit() {
    this._useReuse = this._ncSrv.config.useReuse;
    this._navigateSubscription = this._router.events
      .subscribe(ev => {
        if (ev instanceof NavigationStart) {
          this._navigating = true;
        } else if (ev instanceof NavigationEnd) {
          this._navigating = false;
        } else if (ev instanceof NavigationCancel) {
          this._navigating = false;
        }
      });
  }

  ngOnDestroy() {
    this._navigateSubscription && this._navigateSubscription.unsubscribe();
  }

}