import { BaseComponent } from '@/shared/base/BaseComponent';
import { getAttribute } from '@/shared/utils/locator-utils';
import { Locator } from '@playwright/test';

export abstract class BaseMenu extends BaseComponent {
  async open(): Promise<void> {
    const body = await this.getBody();

    if (await body.isHidden()) {
      await this.host.click();
    }
  }

  async getBody(): Promise<Locator> {
    const id = await getAttribute(this.host, 'aria-controls');
    const head = this.host.page().locator(`#${id}`);
    return head.locator('.v-overlay__content');
  }
}
