import { BaseMenu } from '@/manager/shared/base/BaseMenu';
import { Phone } from '@/shared/types/phone-types';
import { Locator } from '@playwright/test';

export class PhoneMenu extends BaseMenu {
  async select(phone: Phone, country: string): Promise<void> {
    const input = await this.getInput();
    const item = await this.getListItem(`${country} ${phone.prefix}`);

    await input.fill(phone.prefix);
    await item.click();
  }

  private async getListItem(name: string): Promise<Locator> {
    const list = await this.getList();
    return list.locator(`.v-list-item:has(.v-list-item-title:has-text("${name}"))`);
  }

  private async getList(): Promise<Locator> {
    const body = await this.getBody();
    return body.getByTestId('phone-prefix-list');
  }

  private async getInput(): Promise<Locator> {
    const body = await this.getBody();
    return body.locator('input');
  }
}
