// Angular Core
import { Component, Input } from '@angular/core';

// Third Party
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';

@Component({
  standalone: false,
  selector: 'app-mark-paid-externally-modal',
  templateUrl: './mark-paid-externally-modal.component.html',
  styleUrls: ['./mark-paid-externally-modal.component.scss']
})
export class MarkPaidExternallyModalComponent {
  @Input() order: any = null;
  @Input() isLoading: boolean = false;
  @Input() confirmAction!: () => void;
  @Input() cancelAction!: () => void;

  constructor(public activeModal: NgbActiveModal) {}

  /**
   * Handles confirm button click and prevents duplicate submissions.
   */
  onConfirm(): void {
    if (this.isLoading) {
      return;
    }
    if (this.confirmAction) {
      this.confirmAction();
    }
  }

  /**
   * Handles cancel button click while respecting loading state.
   */
  onCancel(): void {
    if (this.isLoading) {
      return;
    }
    if (this.cancelAction) {
      this.cancelAction();
      return;
    }
    this.activeModal.dismiss();
  }
}
