import { BaseComponent } from '@/shared/modules/base/components/BaseComponent';
import { StripeField } from '@/shared/modules/payment-method/components/StripeField';
import { StripeSelect } from '@/shared/modules/payment-method/components/StripeSelect';
import { ICardPayment } from '@/shared/modules/payment-method/types/payment-method-types';

export class CardPaymentSection extends BaseComponent {
  readonly cardNumberField = new StripeField(this.host.locator('[data-field=number]'));
  readonly expirationDateField = new StripeField(this.host.locator('[data-field=expiry]'));
  readonly cvcField = new StripeField(this.host.locator('[data-field=cvc]'));
  readonly countrySelect = new StripeSelect(this.host.locator('[data-field=country]'));
  readonly postalCodeField = new StripeField(this.host.locator('[data-field=postalCode]'));

  async fill(data: ICardPayment): Promise<void> {
    await this.cardNumberField.fill(data.number);
    await this.expirationDateField.fill(data.expirationDate);
    await this.cvcField.fill(data.cvc);
    await this.countrySelect.select(data.country.id);

    data.postalCode != null && (await this.postalCodeField.fill(data.postalCode));
  }
}
