import { BookingUnitTypeList } from '@/portal/modules/booking/components/BookingUnitTypeList';
import { BookingOptionsView } from '@/portal/modules/booking/views/BookingOptionsView';
import { CookieConsentData } from '@/portal/modules/ui/cookie-consent/cookie-consent-types';
import { CookieConsentView } from '@/portal/modules/ui/cookie-consent/views/CookieConsentView';
import { SegmentPicker } from '@/portal/shared/components/SegmentPicker';
import { BaseView } from '@/shared/base/BaseView';

export class BookingUnitTypeView extends BaseView {
  readonly unitTypeCategoryPicker = new SegmentPicker(this.host.getByTestId('unit-type-category-picker'));
  readonly unitTypeList = new BookingUnitTypeList(this.host.getByTestId('unit-type-list'));

  async select(unitType: string, category?: string): Promise<BookingOptionsView> {
    if (category) {
      await this.unitTypeCategoryPicker.select(category);
    }

    await Promise.all([
      this.host.waitForURL('**/unit-type/*/options?section=moveInDate&lang=en'),
      this.unitTypeList.select(unitType),
    ]);
    return new BookingOptionsView(this.host);
  }

  async acceptCookieConsent(cookieConsentData: CookieConsentData): Promise<void> {
    const cookieConsentView = new CookieConsentView(this.host);
    await cookieConsentView.selectSettings(cookieConsentData);
  }
}
