import { Component, Input, Output, EventEmitter, AfterContentInit } from '@angular/core';
import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth';
import { ConfirmationService, Message } from 'primeng/primeng';

@Component({
  selector: 'of-noauth-probe-list',
  templateUrl: './noauth-probe-list.component.html',
  providers: [ConfirmationService]
})
export class NoAuthProbeListComponent {
  @Input() noauthProbes: NoAuthProbe[];
  @Input() pending: boolean;
  @Input() error: any;

  @Output() accept = new EventEmitter<NoAuthProbe>();
  @Output() deny = new EventEmitter<NoAuthProbe>();
  msgs: Message[];

  constructor(
    private confirmationService: ConfirmationService,
  ) {
  }

  onAcceptOrDeny(isAccept: boolean, selected: NoAuthProbe) {
    console.log(selected);
    this.msgs = [];
    const title = isAccept ?
      'Are you sure to accept this Probe?' : 'Are you sure to deny this Probe';
    const message = isAccept ?
      'Start collecting data as a Probe.' : 'It will be permanently deleted.';

    this.confirmationService.confirm({
      header: title,
      message: message,
      icon: isAccept ? 'fa-check' : 'fa fa-trash',
      accept: () => {
        isAccept ? this.accept.emit(selected) : this.deny.emit(selected);
      },
      reject: () => {
      }
    });
  }
}