import { BasePage } from '@/manager/shared/base/BasePage';
import { CustomerDetailsBookingsCard } from '@/manager/modules/customer/components/CustomerDetailsBookingsCard';
import { CustomerDetailsDetailsCard } from '@/manager/modules/customer/components/CustomerDetailsDetailsCard';
import { CustomerDetailsGeneralCard } from '@/manager/modules/customer/components/CustomerDetailsGeneralCard';
import { CustomerDetailsInvoicesCard } from '@/manager/modules/customer/components/CustomerDetailsInvoicesCard';
import { CustomerEditGeneralDialog } from '@/manager/modules/customer/views/CustomerEditGeneralDialog';
import { CustomerListPage } from '@/manager/modules/customer/views/CustomerListPage';
import { getPageHeaderStatusHost, getPageHeaderBackButtonHost } from '@/manager/shared/utils/host-utils';

export class CustomerDetailsPage extends BasePage {
  readonly status = getPageHeaderStatusHost(this.header);
  readonly backButton = getPageHeaderBackButtonHost(this.header);
  readonly actionMenu = this.host.getByTestId('customer-action-menu');
  readonly actionMenuButton = this.header.getByTestId('customer-action-button');
  readonly createBookingMenuItem = this.actionMenu.getByTestId('customer-action-create-booking');
  readonly generalCard = new CustomerDetailsGeneralCard(this.body);
  readonly detailsCard = new CustomerDetailsDetailsCard(this.body);
  readonly bookingsCard = new CustomerDetailsBookingsCard(this.body);
  readonly invoicesCard = new CustomerDetailsInvoicesCard(this.body);

  async openCustomerEditGeneralDialog(): Promise<CustomerEditGeneralDialog> {
    await Promise.all([this.host.waitForURL('**/customers/*/edit/general'), this.generalCard.editButton.click()]);
    return new CustomerEditGeneralDialog(this.host);
  }

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