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"]');
    this.leaveButton = page.getByRole('button', { name: /event verlassen/i });
    this.leaveConfirmButton = page.getByRole('button', { name: /^abmelden$/i });
    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');
  }
}
