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

// The terminal blocked screen replaces every screen. The mock never blocks of its own accord, so
// the e2e drives it through the mock-mode __block seam (lib/app.svelte.ts), mirroring what
// enterBlocked does when any call returns the account_blocked code.

test('a temporary block shows the dated message and reason, replacing the lobby', async ({
  page,
}) => {
  await page.goto('/');
  await page.getByRole('button', { name: /guest/i }).click();
  await expect(page.getByText('Your turn')).toBeVisible(); // reached the lobby

  await page.evaluate(() =>
    (window as unknown as { __block: (b: unknown) => void }).__block({
      permanent: false,
      until: '2026-07-01T12:00:00Z',
      reason: 'Спам',
    }),
  );

  const blocked = page.locator('.blocked');
  await expect(blocked).toBeVisible();
  await expect(blocked).toContainText('2026'); // the expiry rendered in the user's locale/timezone
  await expect(blocked).toContainText('Спам'); // the operator reason
  // The lobby is gone: the blocked screen overlays every screen, stopping its push/poll.
  await expect(page.getByText('Your turn')).toHaveCount(0);
});

test('a permanent block shows the permanent message with no date', async ({ page }) => {
  await page.goto('/');
  await page.getByRole('button', { name: /guest/i }).click();
  await expect(page.getByText('Your turn')).toBeVisible();

  await page.evaluate(() =>
    (window as unknown as { __block: (b: unknown) => void }).__block({ permanent: true }),
  );

  const blocked = page.locator('.blocked');
  await expect(blocked).toBeVisible();
  await expect(blocked).not.toContainText('2026');
});
