import { IBookingCancelData, IBookingCancelOption } from '@/manager/modules/booking/types/booking-types';
import { RadioButton } from '@/manager/shared/components/RadioButton';
import { SingleDatePicker } from '@/manager/shared/components/SingleDatePicker';
import { getInputHostByLabel, getRadioGroupHost } from '@/manager/shared/utils/host-utils';
import { BaseComponent } from '@/shared/base/BaseComponent';

export class BookingCancelRadioGroup extends BaseComponent {
  readonly main = getRadioGroupHost(this.host);
  readonly immediatelyRadioButton = new RadioButton(this.main.locator('.ui-radio-group-item').nth(0));
  readonly endOfCurrentPeriodRadioButton = new RadioButton(this.main.locator('.ui-radio-group-item').nth(1));
  readonly customDateRadioButton = new RadioButton(this.main.locator('.ui-radio-group-item').nth(2));
  readonly customDatePicker = new SingleDatePicker(getInputHostByLabel(this.main.locator('.content'), 'Date *'));

  async fill(data: IBookingCancelData): Promise<void> {
    await this.check(data.option);

    if (data.option === 'custom_date' && data.date) {
      await this.customDatePicker.fill(data.date);
    }
  }

  private check(option: IBookingCancelOption): Promise<void> {
    switch (option) {
      case 'immediately':
        return this.immediatelyRadioButton.check();
      case 'end_of_current_period':
        return this.endOfCurrentPeriodRadioButton.check();
      case 'custom_date':
        return this.customDateRadioButton.check();
    }
  }
}
