import { Component, OnDestroy } from '@angular/core';
import { Router, ActivatedRoute, NavigationEnd } from '@angular/router';
import { Subscription } from 'rxjs/Subscription';
import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe';
import { Target } from '@overflow/commons-typescript/model/target';
import { BreadcrumbService } from '@app/commons/service/breadcrumb.service';

@Component({
  selector: 'of-pages-probe',
  templateUrl: './probe-page.component.html',
})
export class ProbePageComponent {

  isDetail: boolean;
  probeHostID: string;

  constructor(
    private router: Router,
    private route: ActivatedRoute,
    private breadcrumbService: BreadcrumbService
  ) {
    this.route.params.subscribe(params => {
      if (params['id']) {
        this.onDetailContainer(params['id']);
      } else {
        this.onListContainer();
      }
    });
  }

  onListContainer() {
    this.breadcrumbService.setItems([
      { label: 'Probe', routerLink: ['/probe/list'],  }
    ]);
    this.isDetail = false;
  }

  onDetailContainer(probeHostID: string) {
    this.probeHostID = probeHostID;
    this.breadcrumbService.setItems([
      { label: 'Probe', routerLink: ['/probe/list'] },
      { label: this.probeHostID }
    ]);
    this.isDetail = true;
  }

  onProbeSelect(probeHost: ProbeHost) {
    this.router.navigate(['probe', probeHost.id, 'info']);
  }

  onTargetSelect(target: Target) {
    console.log(target);
  }

  onDiscovery(probeHostID: number) {
    this.router.navigate(['discovery', probeHostID]);
  }
}
