/**
 * Login Page Object Model
 * 
 * Encapsulates interactions with the login page.
 */

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

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

  async goto() {
    await this.page.goto('/auth');
    await this.page.waitForLoadState('networkidle');
  }

  async login(email: string, password: string) {
    await this.page.fill('input[type="email"]', email);
    await this.page.fill('input[type="password"]', password);
    await this.page.click('button[type="submit"]');
  }

  async expectLoginSuccess() {
    // Wait for navigation away from auth page
    await this.page.waitForURL('**/', { timeout: 10000 });
    
    // Verify we're on homepage or dashboard
    await expect(this.page).not.toHaveURL(/\/auth/);
  }

  async expectLoginError(message?: string) {
    // Check for error toast or message
    if (message) {
      await expect(this.page.getByText(message)).toBeVisible();
    } else {
      // Just verify we're still on auth page
      await expect(this.page).toHaveURL(/\/auth/);
    }
  }

  async clickSignUp() {
    await this.page.click('text=Sign up');
  }

  async clickForgotPassword() {
    await this.page.click('text=Forgot password');
  }
}
