import { BasePage } from '@/manager/shared/base/BasePage';
import { BookingDetailsBillingCard } from '@/manager/modules/booking/components/BookingDetailsBillingCard';
import { BookingDetailsGeneralCard } from '@/manager/modules/booking/components/BookingDetailsGeneralCard';
import { BookingDetailsInvoicesCard } from '@/manager/modules/booking/components/BookingDetailsInvoicesCard';
import { BookingDetailsItemsCard } from '@/manager/modules/booking/components/BookingDetailsItemsCard';
import { BookingDetailsNotesCard } from '@/manager/modules/booking/components/BookingDetailsNotesCard';
import { BookingDetailsPaymentsCard } from '@/manager/modules/booking/components/BookingDetailsPaymentsCard';
import { BookingCancelDialog } from '@/manager/modules/booking/views/BookingCancelDialog';
import { BookingCancelRevokeDialog } from '@/manager/modules/booking/views/BookingCancelRevokeDialog';
import { BookingListPage } from '@/manager/modules/booking/views/BookingListPage';
import { getPageHeaderStatusHost, getPageHeaderBackButtonHost } from '@/manager/shared/utils/host-utils';

export class BookingDetailsPage extends BasePage {
  readonly baseStatus = getPageHeaderStatusHost(this.header);
  readonly cancelsOnStatus = this.header.getByTestId('base-view-header-status-cancels-on');
  readonly canceledBeforeStartStatus = this.header.getByTestId('base-view-header-status-canceled-before-start');
  readonly accessRevokedStatus = this.header.getByTestId('base-view-header-status-access-revoked');
  readonly backButton = getPageHeaderBackButtonHost(this.header);
  readonly actionMenu = this.host.getByTestId('booking-action-menu');
  readonly actionMenuButton = this.header.getByTestId('booking-action-button');
  readonly actionMenuCancelBookingItem = this.actionMenu.getByTestId('booking-action-cancel-booking');
  readonly actionMenuCancelRescheduleBookingItem = this.actionMenu.getByTestId(
    'booking-action-reschedule-cancellation'
  );
  readonly actionMenuCancelRevokeBookingItem = this.actionMenu.getByTestId('booking-action-revert-cancel');
  readonly generalCard = new BookingDetailsGeneralCard(this.body);
  readonly notesCard = new BookingDetailsNotesCard(this.body);
  readonly billingCard = new BookingDetailsBillingCard(this.body);
  readonly itemsCard = new BookingDetailsItemsCard(this.body);
  readonly invoicesCard = new BookingDetailsInvoicesCard(this.body);
  readonly paymentsCard = new BookingDetailsPaymentsCard(this.body);

  async openBookingCancelDialog(): Promise<BookingCancelDialog> {
    await this.actionMenuButton.click();
    await this.actionMenuCancelBookingItem.click();
    return new BookingCancelDialog(this.host);
  }

  async openBookingCancelRescheduleDialog(): Promise<BookingCancelDialog> {
    await this.actionMenuButton.click();
    await this.actionMenuCancelRescheduleBookingItem.click();
    return new BookingCancelDialog(this.host, true);
  }

  async openBookingCancelRevokeDialog(): Promise<BookingCancelRevokeDialog> {
    await this.actionMenuButton.click();
    await this.actionMenuCancelRevokeBookingItem.click();
    return new BookingCancelRevokeDialog(this.host);
  }

  async returnToBookingListPage(): Promise<BookingListPage> {
    await Promise.all([this.host.waitForURL('/bookings'), this.backButton.click()]);
    return new BookingListPage(this.host);
  }
}
