import { BaseDialog } from '@/manager/shared/base/BaseDialog';
import { AddPaymentMethodRadioGroup } from '@/manager/modules/ui/payment-method/components/AddPaymentMethodRadioGroup';
import { AddStripeEmbeddedCheckoutDialog } from '@/manager/modules/ui/payment-method/views/AddStripeEmbeddedCheckoutDialog';
import { AddStripePaymentElementDialog } from '@/manager/modules/ui/payment-method/views/AddStripePaymentElementDialog';
import { IPaymentMethod } from '@/shared/modules/payment-method/types/payment-method-types';
import { Page } from '@playwright/test';

export class AddPaymentMethodDialog extends BaseDialog {
  readonly paymentMethodRadioGroup = new AddPaymentMethodRadioGroup(this.main);

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

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

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

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