import { Component, ChangeDetectionStrategy, Output, EventEmitter, Input } from '@angular/core';
import { ModalService } from '@libs/ui';
import { ModalDialogAction } from 'apps/sales/src/app/shared/components/modal-dialog';

@Component({
  selector: 'app-remission-scan-confirmation-dialog',
  templateUrl: './remission-scan-confirmation-dialog.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RemissionScanConfirmationDialogComponent {
  id = 'remission-scan-confirmation-dialog';
  barcode: string;
  readonly title = 'Ist die Wannennummer korrekt oder möchten Sie die Wannennummer erneut scannen?';
  readonly actions: ModalDialogAction[] = [
    {
      text: 'Erneut Scannen',
      primary: false,
      onClick: () => this.retryScan(),
    },
    {
      text: 'Nummer korrekt',
      primary: true,
      onClick: () => this.confirmScan(),
    },
  ];

  @Output() retry = new EventEmitter<void>();
  @Output() confirm = new EventEmitter<string>();
  @Output() close = new EventEmitter<void>();

  constructor(private modalService: ModalService) {}

  public openDialog(barcode: string) {
    this.barcode = barcode;
    this.modalService.open(this.id);
  }

  retryScan() {
    this.modalService.close(this.id);
    this.retry.emit();
  }

  confirmScan() {
    this.modalService.close(this.id);
    this.confirm.emit(this.barcode);
  }

  closeDialog() {
    this.modalService.close(this.id);
    this.close.emit();
  }
}
