import { BookingProductRecurring } from '@/shared/types/booking-types';
import { NumberField } from '@/manager/shared/components/NumberField';
import { SingleAutocomplete } from '@/manager/shared/components/SingleAutocomplete';
import { BaseComponent } from '@/shared/base/BaseComponent';

export class BookingCreateProductRecurringPickerTable extends BaseComponent {
  readonly main = this.host.getByTestId('booking-form-extra-recurring');
  readonly addButton = this.main.getByTestId('app-link-button');

  async add(products: BookingProductRecurring[]): Promise<void> {
    for (let index = 0; index < products.length; index++) {
      const product = products[index];

      await this.addButton.click();

      const row = this.main.getByTestId('product-row-body').nth(index);
      await new SingleAutocomplete(row.getByTestId('content-column-1')).fill(product.product.name);

      if (product.quantity !== 1) {
        await new NumberField(row.getByTestId('content-column-3')).fill(product.quantity);
      }
    }
  }
}
