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

test.describe('Activity Tracking Flow', () => {
  test.beforeEach(async ({ page }) => {
    // Login before each test
    await page.goto('/login');
    await page.fill('input[name="email"]', 'andrei@cloudz.ro');
    await page.fill('input[name="password"]', 'password');
    await page.click('button[type="submit"]');
    
    // Wait for redirect to homepage
    await page.waitForURL('/');
  });

  test('should navigate to feeding tracker', async ({ page }) => {
    // Click on feeding quick action
    await page.click('text=Feeding');
    
    // Verify we're on the feeding page
    await expect(page).toHaveURL('/track/feeding');
    await expect(page.locator('text=Track Feeding')).toBeVisible();
  });

  test('should navigate to sleep tracker', async ({ page }) => {
    // Click on sleep quick action
    await page.click('text=Sleep');
    
    // Verify we're on the sleep page
    await expect(page).toHaveURL('/track/sleep');
    await expect(page.locator('text=Track Sleep')).toBeVisible();
  });

  test('should navigate to diaper tracker', async ({ page }) => {
    // Click on diaper quick action
    await page.click('text=Diaper');
    
    // Verify we're on the diaper page
    await expect(page).toHaveURL('/track/diaper');
    await expect(page.locator('text=Track Diaper Change')).toBeVisible();
  });

  test('should display today summary on homepage', async ({ page }) => {
    // Check that Today's Summary section exists
    await expect(page.locator('text=Today\'s Summary')).toBeVisible();
    
    // Check that the three metrics are displayed
    await expect(page.locator('text=Feedings')).toBeVisible();
    await expect(page.locator('text=Sleep')).toBeVisible();
    await expect(page.locator('text=Diapers')).toBeVisible();
  });

  test('should navigate to AI Assistant', async ({ page }) => {
    // Click on AI Assistant quick action
    await page.click('text=AI Assistant');
    
    // Verify we're on the AI Assistant page
    await expect(page).toHaveURL('/ai-assistant');
    await expect(page.locator('text=AI Assistant')).toBeVisible();
  });

  test('should navigate to Analytics', async ({ page }) => {
    // Click on Analytics quick action
    await page.click('text=Analytics');
    
    // Verify we're on the Analytics page
    await expect(page).toHaveURL('/analytics');
  });
});

test.describe('Feeding Tracker', () => {
  test.beforeEach(async ({ page }) => {
    await page.goto('/login');
    await page.fill('input[name="email"]', 'andrei@cloudz.ro');
    await page.fill('input[name="password"]', 'password');
    await page.click('button[type="submit"]');
    await page.waitForURL('/');
    
    // Navigate to feeding tracker
    await page.goto('/track/feeding');
  });

  test('should have feeding type options', async ({ page }) => {
    // Check that feeding type buttons are visible
    await expect(page.locator('text=Bottle')).toBeVisible();
    await expect(page.locator('text=Breast')).toBeVisible();
    await expect(page.locator('text=Solid')).toBeVisible();
  });

  test('should have save button', async ({ page }) => {
    await expect(page.locator('button:has-text("Save")')).toBeVisible();
  });
});

test.describe('Sleep Tracker', () => {
  test.beforeEach(async ({ page }) => {
    await page.goto('/login');
    await page.fill('input[name="email"]', 'andrei@cloudz.ro');
    await page.fill('input[name="password"]', 'password');
    await page.click('button[type="submit"]');
    await page.waitForURL('/');
    
    // Navigate to sleep tracker
    await page.goto('/track/sleep');
  });

  test('should have sleep type options', async ({ page }) => {
    // Check that sleep type buttons are visible
    await expect(page.locator('text=Nap')).toBeVisible();
    await expect(page.locator('text=Night')).toBeVisible();
  });

  test('should have save button', async ({ page }) => {
    await expect(page.locator('button:has-text("Save")')).toBeVisible();
  });
});

test.describe('Diaper Tracker', () => {
  test.beforeEach(async ({ page }) => {
    await page.goto('/login');
    await page.fill('input[name="email"]', 'andrei@cloudz.ro');
    await page.fill('input[name="password"]', 'password');
    await page.click('button[type="submit"]');
    await page.waitForURL('/');
    
    // Navigate to diaper tracker
    await page.goto('/track/diaper');
  });

  test('should have diaper type options', async ({ page }) => {
    // Check that diaper type buttons are visible
    await expect(page.locator('text=Wet')).toBeVisible();
    await expect(page.locator('text=Dirty')).toBeVisible();
    await expect(page.locator('text=Both')).toBeVisible();
  });

  test('should have save button', async ({ page }) => {
    await expect(page.locator('button:has-text("Save")')).toBeVisible();
  });
});
