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

test.describe('Sprint N: All Filters Enabled', () => {
  test('Sampling category filters all clickable', async ({ page }) => {
    await page.goto('/');
    await page.locator('[data-testid="menu-bar"]').waitFor({ state: 'visible', timeout: 10000 });
    await page.click('[data-testid="menu-Filters"]');
    await page.click('text=Sampling');
    // Previously disabled filters now enabled
    for (const name of ['Clustered Vertex Sampling', 'Stratified Triangle Sampling', 'Texel Sampling', 'Uniform Mesh Resampling']) {
      const item = page.locator(`text=${name}`).first();
      await expect(item).toBeVisible();
      await expect(item.locator('..')).not.toHaveAttribute('data-disabled', 'true');
    }
  });

  test('Smoothing category filters all clickable', async ({ page }) => {
    await page.goto('/');
    await page.click('[data-testid="menu-Filters"]');
    await page.click('text=Smoothing, Fairing and Deformation');
    for (const name of ['HC Laplacian Smooth', 'Depth Smooth', 'UnSharp Mask Geometry', 'Two Step Smooth']) {
      const item = page.locator(`text=${name}`).first();
      await expect(item).toBeVisible();
      await expect(item.locator('..')).not.toHaveAttribute('data-disabled', 'true');
    }
  });

  test('Color category filters all clickable', async ({ page }) => {
    await page.goto('/');
    await page.click('[data-testid="menu-Filters"]');
    await page.click('text=Color Creation and Processing');
    for (const name of ['Vertex Color Fill', 'Perlin Color', 'Random Face Color', 'Smooth Vertex Colors']) {
      const item = page.locator(`text=${name}`).first();
      await expect(item).toBeVisible();
      await expect(item.locator('..')).not.toHaveAttribute('data-disabled', 'true');
    }
  });

  test('Mesh Creation all enabled', async ({ page }) => {
    await page.goto('/');
    await page.click('[data-testid="menu-Filters"]');
    await page.click('text=Create New Mesh Layer');
    for (const name of ['Icosahedron', 'Tetrahedron', 'Octahedron', 'Dodecahedron', 'Annulus', 'Sphere Cap']) {
      const item = page.locator(`text=${name}`).first();
      await expect(item).toBeVisible();
      await expect(item.locator('..')).not.toHaveAttribute('data-disabled', 'true');
    }
  });

  test('Normals category all enabled', async ({ page }) => {
    await page.goto('/');
    await page.click('[data-testid="menu-Filters"]');
    await page.click('text=Normals, Curvatures and Orientation');
    for (const name of ['Normalize Face Normals', 'Normal Extrapolation', 'Principal Curvature Direction']) {
      const item = page.locator(`text=${name}`).first();
      await expect(item).toBeVisible();
      await expect(item.locator('..')).not.toHaveAttribute('data-disabled', 'true');
    }
  });

  test('Remeshing category reconstruction filters enabled', async ({ page }) => {
    await page.goto('/');
    await page.click('[data-testid="menu-Filters"]');
    await page.click('text=Remeshing, Simplification and Reconstruction');
    for (const name of ['Screened Poisson Reconstruction', 'Ball Pivoting Surface Reconstruction', 'Clustering Decimation']) {
      const item = page.locator(`text=${name}`).first();
      await expect(item).toBeVisible();
      await expect(item.locator('..')).not.toHaveAttribute('data-disabled', 'true');
    }
  });

  test('About dialog shows 147 Filters', async ({ page }) => {
    await page.goto('/');
    await page.click('[data-testid="menu-Help"]');
    await page.click('text=About MeshLab Web');
    await expect(page.locator('[data-testid="about-dialog"]')).toBeVisible();
    await expect(page.locator('[data-testid="about-dialog"]')).toContainText('147 Filters');
  });
});
