import { Page, expect } from "@playwright/test"

export class LoginPage {
  constructor(private readonly page: Page) {}

  async goto() {
    await this.page.goto("/login")
  }

  async login(email: string, password: string) {
    await this.page.locator("#email").fill(email)
    await this.page.locator("#password").fill(password)
    await this.page.getByRole("button", { name: /sign in/i }).click()
  }

  async expectLoggedIn() {
    await expect(this.page).toHaveURL(/\/dashboard/)
  }

  async expectError() {
    await expect(this.page.getByRole("alert")).toBeVisible()
  }
}
