import { BookingUnitType } from '@/shared/types/booking-types';
import { SingleAutocomplete } from '@/manager/shared/components/SingleAutocomplete';
import { getInputHostByLabel } from '@/manager/shared/utils/locator-utils';
import { BaseComponent } from '@/shared/base/BaseComponent';
import { Unit } from '@/shared/types/unit-types';
import { formatBillingPeriod } from '@/shared/utils/formatters';

export class BookingCreateUnitTypePickerTable extends BaseComponent {
  readonly unitTypeAutocomplete = new SingleAutocomplete(getInputHostByLabel(this.host, 'Unit type'));
  readonly bookingPlanAutocomplete = new SingleAutocomplete(getInputHostByLabel(this.host, 'Booking plan'));
  readonly unitAutocomplete = new SingleAutocomplete(getInputHostByLabel(this.host, 'Unit *'));

  async select(unitType: BookingUnitType, unit: Unit): Promise<void> {
    await this.unitTypeAutocomplete.fill(unitType.unitType.name);
    await this.bookingPlanAutocomplete.fill(
      formatBillingPeriod(unitType.plan.period, unitType.plan.amount, unitType.plan.name)
    );
    await this.unitAutocomplete.fill(unit.name);
  }
}
