import { test, expectFixture as expect } from '../helpers/test-fixtures';

/**
 * Skeleton E2E coverage for the tenant onboarding journey.
 *
 * This suite is currently skipped until we have stable seed data and
 * authentication helpers for Playwright. Once those are in place we can
 * remove the skip and let the flow exercise the welcome -> packages -> summary
 * steps with mocked Paddle APIs.
 */
test.describe('Tenant Onboarding Welcome Flow', () => {
  test('redirects unauthenticated users to login', async ({ page }) => {
    await page.goto('/event-admin/mobile/welcome');
    await expect(page).toHaveURL(/\/event-admin\/login/);
    await expect(page.getByText(/Team Login|Fotospiel Event Admin|Login/i)).toBeVisible();
  });

  test('tenant admin can progress through welcome, packages, summary, and setup', async ({
    tenantAdminCredentials,
    signInTenantAdmin,
    page,
  }) => {
    test.skip(
      !tenantAdminCredentials,
      'Provide E2E_TENANT_EMAIL and E2E_TENANT_PASSWORD (see docs/testing/e2e.md) to run onboarding tests.'
    );

    await signInTenantAdmin();

    // If guard redirects to dashboard, hop to welcome manually.
    if (!page.url().includes('/event-admin/mobile/welcome')) {
      await page.goto('/event-admin/mobile/welcome');
    }

    await expect(page.getByRole('heading', { name: /Willkommen im Event-Erlebnisstudio/i })).toBeVisible();

    // Open package selection via CTA.
    await page.getByRole('button', { name: /Pakete entdecken/i }).click();
    await expect(page).toHaveURL(/\/event-admin\/mobile\/welcome\/packages/);
    await expect(page.getByRole('heading', { name: /Wähle dein Eventpaket/i })).toBeVisible();

    // Choose the first available package and ensure we land on the summary step.
    const choosePackageButton = page.getByRole('button', { name: /Paket wählen/i }).first();
    await choosePackageButton.waitFor({ state: 'visible', timeout: 10_000 });
    await choosePackageButton.click();

    await expect(page).toHaveURL(/\/event-admin\/mobile\/welcome\/summary/);
    await expect(page.getByRole('heading', { name: /Bestellübersicht/i })).toBeVisible();

    // Validate Paddle payment section.
    await expect(page.getByRole('heading', { name: /^Paddle$/i })).toBeVisible();

    // Continue to the setup step without completing a purchase.
    await page.getByRole('button', { name: /Weiter zum Setup/i }).click();
    await expect(page).toHaveURL(/\/event-admin\/mobile\/welcome\/event/);
    await expect(page.getByRole('heading', { name: /Bereite dein erstes Event vor/i })).toBeVisible();
  });
});
