import { BaseDialog } from '@/manager/shared/base/BaseDialog';
import { PaymentMethodAddRadioGroup } from '@/manager/modules/ui/payment-method/components/PaymentMethodAddRadioGroup';
import { StripeEmbeddedCheckoutAddDialog } from '@/manager/modules/ui/payment-method/views/StripeEmbeddedCheckoutAddDialog';
import { StripePaymentElementAddDialog } from '@/manager/modules/ui/payment-method/views/StripePaymentElementAddDialog';
import { PaymentMethod } from '@/shared/modules/payment-method/payment-method-types';
import { Page } from '@playwright/test';

export class PaymentMethodAddDialog extends BaseDialog {
  readonly paymentMethodRadioGroup = new PaymentMethodAddRadioGroup(this.main);

  constructor(host: Page) {
    super(host, 'add-payment-method-dialog');
  }

  async add(paymentMethod: PaymentMethod): Promise<void> {
    await this.setUp(paymentMethod);

    if (paymentMethod.kind === 'bacs') {
      const dialog = new StripeEmbeddedCheckoutAddDialog(this.host);
      await dialog.add(paymentMethod);
    } else {
      const dialog = new StripePaymentElementAddDialog(this.host);
      await dialog.add(paymentMethod);
    }
  }

  private async setUp(paymentMethod: PaymentMethod): Promise<void> {
    await this.paymentMethodRadioGroup.check(paymentMethod);
    await this.submitButton.click();
  }
}
