import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe';

@Component({
  selector: 'of-probe-list',
  templateUrl: './list.component.html',
})
export class ProbeListComponent {
  @Output() select = new EventEmitter<ProbeHost>();
  @Input() pending: boolean;
  @Input() probeHosts: ProbeHost[];
  @Input() error: any;

  constructor() {
  }

  onProbeSelect(event) {
    this.select.emit(event.data);
  }

  getUptime(probe: Probe) {
    if (!probe.connectDate) {
      return 'Not Connected.';
    }
    const hours = Math.abs(new Date().getTime() - probe.connectDate.getTime());
    return this.convertUptimeString(hours);
  }

  convertUptimeString(hours: number) {
    if (hours === 0) {
      return 'Less than an hour.';
    } else {
      return 'About ' + hours;
    }
  }
}