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

test.describe('Projects API', () => {
  test('should sign in and fetch projects', async ({ page }) => {
    await page.goto('https://code-dev.g4dge7.com:5174/sign-in');
    await page.waitForLoadState('networkidle');

    await page.fill('#email', 'rob@digitaltelepresence.com');
    await page.fill('#password', 'ionfrali');
    await page.click('button[type="submit"]');
    await page.waitForTimeout(3000);

    const userData = await page.evaluate(() => localStorage.getItem('dtp_user'));
    expect(userData).toBeDefined();

    await page.goto('https://code-dev.g4dge7.com:5174/projects');
    await page.waitForLoadState('networkidle');
    await page.waitForTimeout(3000);

    const content = await page.content();
    expect(content).not.toContain('Please sign in to view projects');
  });

  test('should show project manager after sign in', async ({ page }) => {
    await page.goto('https://code-dev.g4dge7.com:5174/sign-in');
    await page.waitForLoadState('networkidle');

    await page.fill('#email', 'rob@digitaltelepresence.com');
    await page.fill('#password', 'ionfrali');
    await page.click('button[type="submit"]');
    await page.waitForTimeout(3000);

    await page.goto('https://code-dev.g4dge7.com:5174/projects');
    await page.waitForLoadState('networkidle');
    await page.waitForTimeout(2000);

    const content = await page.content();
    expect(content).toContain('[New Project]');
  });
});