import { BaseDialog } from '@/manager/shared/base/BaseDialog';
import { BookingCancelRadioGroup } from '@/manager/modules/booking/components/BookingCancelRadioGroup';
import { IBookingCancelData } from '@/manager/modules/booking/types/booking-types';
import { getSnackbarHost } from '@/manager/shared/utils/host-utils';
import { Locator, Page } from '@playwright/test';

export class BookingCancelDialog extends BaseDialog {
  readonly radioGroup = new BookingCancelRadioGroup(this.main);

  constructor(
    host: Page,
    readonly reschedule = false
  ) {
    super(host, 'booking-cancel-dialog');
  }

  async cancel(data: IBookingCancelData): Promise<void> {
    await this.fill(data);
    await this.submit();
  }

  fill(data: IBookingCancelData): Promise<void> {
    return this.radioGroup.fill(data);
  }

  async submit(): Promise<void> {
    await Promise.all([this.getSnackbar().waitFor(), this.submitButton.click()]);
  }

  getSnackbar(): Locator {
    return getSnackbarHost(this.host, this.reschedule ? 'Reschedule successful' : 'Booking cancelled successfully');
  }
}
