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

export class SepaPaymentSection extends BaseComponent {
  readonly ibanField = new StripeField(this.host.locator('[data-field=iban]'));
  readonly emailField = new StripeField(this.host.locator('[data-field=email]'));
  readonly fullNameField = new StripeField(this.host.locator('[data-field=name]'));
  readonly countrySelect = new StripeSelect(this.host.locator('[data-field=country]'));
  readonly addressLine1Field = new StripeField(this.host.locator('[data-field=addressLine1]'));
  readonly cityField = new StripeField(this.host.locator('[data-field=locality]'));
  readonly postalCodeField = new StripeField(this.host.locator('[data-field=postalCode]'));
  readonly administrativeAreaField = new StripeSelect(this.host.locator('[data-field=administrativeArea]'));

  async fill(data: SepaPayment): Promise<void> {
    await this.ibanField.fill(data.iban);
    await this.emailField.fill(data.email);
    await this.fullNameField.fill(data.fullName);
    await this.countrySelect.select(data.country.id);
    await this.addressLine1Field.fill(data.street);

    if (data.city != null) {
      await this.cityField.fill(data.city);
    }

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

    if (data.administrativeArea != null) {
      await this.administrativeAreaField.select(data.administrativeArea);
    }
  }
}
