import { BookingUnitTypeList } from '@/apps/portal/modules/booking/components/BookingUnitTypeList';
import { BookingOptionsView } from '@/apps/portal/modules/booking/views/BookingOptionsView';
import { ICookieConsentData } from '@/apps/portal/modules/ui/cookie-consent/types/cookie-consent-types';
import { CookieConsentView } from '@/apps/portal/modules/ui/cookie-consent/views/CookieConsentView';
import { SegmentPicker } from '@/apps/portal/shared/components/inputs/SegmentPicker';
import { BaseView } from '@/shared/modules/base/views/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> {
    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: ICookieConsentData): Promise<void> {
    const cookieConsentView = new CookieConsentView(this.host);
    await cookieConsentView.selectSettings(cookieConsentData);
  }
}
