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

test('home page shows the product browse shell with reusable thing cards', async ({ page }) => {
  await page.goto('/');

  await expect(page.getByRole('heading', { name: 'Polymodel' })).toBeVisible();
  await expect(page.getByLabel('Browse shell')).toBeVisible();
  await expect(page.getByRole('tab', { name: 'Recent' })).toBeVisible();
  await expect(page.getByRole('tab', { name: 'Hot' })).toBeVisible();
  await expect(page.getByRole('searchbox', { name: 'Search model projects' })).toBeVisible();

  const results = page.getByLabel('Browse results');
  await expect(results).toBeVisible();
  await expect(results.getByRole('article')).toHaveCount(3);
  await expect(page.getByRole('heading', { name: 'Parametric enclosure kit' })).toBeVisible();
  await expect(page.getByText('by Ari Chen')).toBeVisible();
  await expect(page.getByText('#parametric')).toBeVisible();
  await expect(page.getByText('3 models')).toBeVisible();
  await expect(page.getByText('18 parts')).toBeVisible();
  await expect(page.getByRole('img', { name: 'Rendered preview of a parametric electronics enclosure' })).toBeVisible();


  await expect(page.getByRole('heading', { name: 'Untitled thing' })).toBeVisible();
  await expect(page.getByText('by mira.tools')).toBeVisible();

  await expect(page.getByRole('heading', { name: 'Modular calibration tower' })).toBeVisible();
  await expect(page.getByRole('img', { name: 'Blueprint placeholder for missing preview media' })).toHaveCount(2);
  await expect(page.getByText('No preview')).toHaveCount(2);
  await expect(page.getByText('preview pending')).toHaveCount(2);

  await expect(page.getByLabel('Browse results placeholder')).toHaveCount(0);
  await expect(page.getByText('Empty')).toHaveCount(0);
});

test('home thing cards remain readable at narrow widths', async ({ page }) => {
  await page.setViewportSize({ width: 390, height: 900 });
  await page.goto('/');

  await expect(page.getByLabel('Browse results')).toBeVisible();
  await expect(page.getByRole('heading', { name: 'Parametric enclosure kit' })).toBeVisible();
  await expect(page.getByRole('heading', { name: 'Untitled thing' })).toBeVisible();
  await expect(page.getByRole('heading', { name: 'Modular calibration tower' })).toBeVisible();
  await expect(page.getByRole('img', { name: 'Blueprint placeholder for missing preview media' })).toHaveCount(2);
});

test('foundation route shows PM-38 primitives and reusable states', async ({ page }) => {
  await page.goto('/foundation');

  await expect(page.getByRole('heading', { name: 'Foundation', exact: true })).toBeVisible();
  await expect(page.getByText('Token and asset check')).toBeVisible();
  await expect(page.getByLabel('Foundation primitives')).toBeVisible();
  await expect(page.getByLabel('Reusable states')).toBeVisible();
  await expect(page.getByText('No projects yet')).toBeVisible();
  await expect(page.getByText('Feed unavailable')).toBeVisible();
});

test('home page no longer uses workflow roadmap demo copy as the product surface', async ({ page }) => {
  await page.goto('/');

  await expect(page.getByText('Thingiverse on atproto')).toHaveCount(0);
  await expect(page.getByText('Project lexicon')).toHaveCount(0);
  await expect(page.getByText('Jira and Confluence')).toHaveCount(0);
  await expect(page.getByText('Polytoken workflow')).toHaveCount(0);
  await expect(page.getByText('PM-38 foundation')).toHaveCount(0);
});
