import { Component, OnDestroy, OnInit } from '@angular/core';
import { Router, ActivatedRoute, NavigationEnd } from '@angular/router';
import { Subscription } from 'rxjs';
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';
import { Sensor } from '@overflow/commons-typescript/model/sensor';

@Component({
  selector: 'of-pages-sensor-list',
  templateUrl: './sensor-list-page.component.html',
})
export class SensorListPageComponent implements OnInit {
  pageNo: number;

  constructor(
    private router: Router,
    private route: ActivatedRoute,
    private breadcrumbService: BreadcrumbService
  ) {
    this.breadcrumbService.setItems([
      { label: 'Sensor', routerLink: ['/sensor/list'], }
    ]);
  }

  ngOnInit() {
    this.route.queryParams.subscribe(queryParams => {
      this.pageNo = queryParams['page'] || 1;
    });
  }

  onSensorSelect(sensor: Sensor) {
    this.router.navigate(['sensor', sensor.id, 'info']);
  }

  onAddSensor() {
    this.router.navigate(['sensor', 0, 'info']);
  }

  onPageChange(pageNo: number) {
    this.router.navigate(['/notification'], { queryParams: { page: pageNo } });
  }
}
