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 { ISepaPayment } from '@/shared/modules/payment-method/types/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: ISepaPayment): 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);

    data.city != null && (await this.cityField.fill(data.city));
    data.postalCode != null && (await this.postalCodeField.fill(data.postalCode));
    data.administrativeArea != null && (await this.administrativeAreaField.select(data.administrativeArea));
  }
}
