import { BaseDialog } from '@/manager/shared/base/BaseDialog';
import { PaymentMethodAddForm } from '@/manager/modules/ui/payment-method/components/PaymentMethodAddForm';
import { getSnackbarHost } from '@/manager/shared/utils/locator-utils';
import { PaymentMethod } from '@/shared/modules/payment-method/payment-method-types';
import { Page } from '@playwright/test';

export class InvoiceChargeCustomerDialog extends BaseDialog {
  readonly paymentMethodForm = new PaymentMethodAddForm(this.main);
  readonly snackbar = getSnackbarHost(this.host, 'Charged customer successfully');
  readonly errorSnackbar = getSnackbarHost(this.host, 'Validation failed');

  constructor(host: Page) {
    super(host, 'invoice-charge-customer-dialog');
  }

  async charge(method: PaymentMethod): Promise<void> {
    await this.fill(method);
    await Promise.all([this.snackbar.waitFor(), this.submit()]);
  }

  async fill(method: PaymentMethod): Promise<void> {
    await this.paymentMethodForm.select(method);
  }

  async submit(): Promise<void> {
    await this.submitButton.click();
  }
}
