import { test, expect } from './fixtures';

test.describe('Seed', () => {
  test('seed', async ({ page, createUniqueUser }) => {
    // 1. Create User
    const user = await createUniqueUser();

    // 2. Go to Login
    await page.goto('/');

    // 3. Login
    await page.getByLabel('Email').fill(user.email);
    await page.getByLabel('Password').fill(user.password);
    await page.getByRole('button', { name: 'Login' }).click();

    // 4. Handle First Time Password Change if it appears
    // Wait for either dashboard or change password screen
    try {
        await expect(page.getByRole('heading', { name: /Change Password/i }).or(page.getByText('Free Workout'))).toBeVisible({ timeout: 5000 });
        
        if (await page.getByRole('heading', { name: /Change Password/i }).isVisible()) {
             await page.getByLabel('New Password').fill('StrongNewPass123!');
             await page.getByRole('button', { name: /Save|Change/i }).click();
        }
    } catch (e) {
        console.log('Timeout waiting for login transition');
    }

    // 5. Ensure we are at Dashboard
    await expect(page.getByText('Free Workout')).toBeVisible();
  });
});
