import { Component, Input, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Target } from '@overflow/commons-typescript';

@Component({
  selector: 'of-pages-target-list',
  templateUrl: './target-list-page.component.html',
})
export class TargetListPageComponent implements OnInit {

  probeID: number;
  pageIdx: number;

  constructor(
    private router: Router,
    private activatedRoute: ActivatedRoute
  ) { }

  ngOnInit() {
    this.probeID = this.activatedRoute.snapshot.params['probeID'];
    // this.activatedRoute.queryParams.subscribe(queryParams => {
    //   this.pageIdx = Number(queryParams['page']);

      // if (this.pageIdx <= 0 || this.pageIdx === undefined || this.pageIdx === null || isNaN(this.pageIdx)) {
      //   this.pageIdx = 1;
      // }
    // });
  }

  // onPageChange(pageNo: number) {
  //   // this.pageIdx = pageNo + 1;
  //   this.router.navigate(['/probe', this.probeID, 'target'], { queryParams: { page: this.pageIdx } });
  // }

  onTargetSelect(target: Target) {
    this.router.navigate(['probe', this.probeID, 'target', target.id, 'info'], { queryParams: { page: this.pageIdx } });
  }
}
