// AUTH helpers — reused by every e2e test script.
// Usage: const { login } = require('../helpers/auth');

async function login(page, email = 'tech@pelagia.local', password = 'tech1234') {
  await page.goto('http://localhost:3000/login');
  await page.waitForLoadState('networkidle');
  await page.fill('#email', email);
  await page.fill('#password', password);
  // Start waiting for navigation before clicking submit
  const navPromise = page.waitForURL('http://localhost:3000/dashboard', { timeout: 15000 });
  await page.click('button[type=submit]');
  await navPromise;
  await page.waitForLoadState('networkidle');
  console.log(`✓ Logged in as ${email}`);
}

module.exports = { login };
