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

export class AccountPage {
  readonly page: Page;
  readonly displayName: Locator;
  readonly pinDisplay: Locator;
  readonly leaveButton: Locator;
  readonly leaveConfirmButton: Locator;
  readonly privacyNote: Locator;

  constructor(page: Page) {
    this.page = page;
    this.displayName = page.locator('[data-testid="account-display-name"]');
    this.pinDisplay = page.locator('[data-testid="account-pin"]');
    // Keyed on testids, not visible copy. The button was renamed "Event verlassen" ->
    // "Abmelden" and these locators silently went stale for a week — the smoke spec that
    // guards eight of nine UA projects runs through `leaveEvent()` below.
    this.leaveButton = page.getByTestId('account-logout');
    this.leaveConfirmButton = page.getByTestId('confirm-sheet-confirm');
    this.privacyNote = page.locator('[data-testid="privacy-note"]');
  }

  async goto() {
    await this.page.goto('/account');
  }

  async leaveEvent() {
    await this.leaveButton.click();
    await this.leaveConfirmButton.click();
    await this.page.waitForURL('**/join');
  }
}
