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

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

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

  async cancel(data: BookingCancelData): Promise<BookingDetailsPage> {
    await this.fill(data);
    await Promise.all([this.getSnackbar().waitFor(), this.submit()]);
    return new BookingDetailsPage(this.host);
  }

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

  async submit(): Promise<void> {
    await this.submitButton.click();
  }

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