import { expect, type Page } from '@playwright/test';

export async function openTitleBarMenu(page: Page): Promise<void> {
  const menuButton = page.getByRole('button', { name: 'Menu' });

  await expect(menuButton).toBeVisible({ timeout: 15_000 });
  await menuButton.click();
  await expect(page.locator('app-title-bar .absolute.right-0.top-full').first()).toBeVisible({ timeout: 10_000 });
}

export async function openPluginStore(page: Page): Promise<void> {
  await openTitleBarMenu(page);
  await page.getByRole('button', { name: 'Plugin Store' }).click();
  await expect(page).toHaveURL(/\/plugin-store/, { timeout: 20_000 });
}

export async function openSettingsFromMenu(page: Page): Promise<void> {
  await openTitleBarMenu(page);
  await page.getByRole('button', { name: 'Settings' }).click();
}
