import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
import { ModalService } from '@libs/ui';

@Component({
  selector: 'app-remission-add-product-to-shipping-document-dialog',
  templateUrl: './remission-add-product-to-shipping-document-dialog.component.html',
  styleUrls: ['./remission-add-product-to-shipping-document-dialog.component.scss'],
})
export class RemissionAddProductToShippingDocumentDialogComponent implements OnInit {
  id = 'remission-add-product-to-shipping-document-modal';
  loading = false;
  placement = '';

  @Input() quantity: number;
  @Input()
  set placementType(value: string) {
    this.placement =
      value === 'Stapel'
        ? `Sie sind gerade dabei alle ${this.quantity} Exemplare von einem Stapelplatz zu remittieren. Sind wirklich alle Exemplare auf einem Stapel?`
        : `Sie sind gerade dabei alle ${this.quantity} Exemplare von einem Leistungsplatz zu remittieren. Sind wirklich alle Exemplare in der Leistung?`;
  }
  @Output() add = new EventEmitter();
  @Output() closed = new EventEmitter();

  constructor(private modalService: ModalService) {}

  ngOnInit() {}

  public openDialog() {
    this.loading = false;
    this.modalService.open(this.id);
  }

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

  addProduct() {
    this.loading = true;
    this.add.emit();
  }

  public stopLoading() {
    this.loading = false;
  }
}
