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

test.describe('Package Flow in Admin PWA', () => {
  test('Create event in admin PWA and verify it appears in the list', async ({ tenantAdminCredentials, signInTenantAdmin, page }) => {
    test.skip(
      !tenantAdminCredentials,
      'Provide E2E_TENANT_EMAIL and E2E_TENANT_PASSWORD to run admin package flow tests.'
    );

    await signInTenantAdmin();

    await page.goto('/event-admin/mobile/events/new');

    const eventName = `Package Flow ${Date.now()}`;
    const date = new Date(Date.now() + 14 * 86400000).toISOString().slice(0, 10);

    await page.getByPlaceholder(/Sommerfest|Summer Party/i).fill(eventName);
    await page.locator('input[type="datetime-local"]').fill(`${date}T12:00`);

    await page.locator('select').first().selectOption({ index: 1 });

    await page.getByRole('button', { name: /Event erstellen|Create event/i }).click();
    await expect(page).toHaveURL(/\/event-admin\/mobile\/events\/[a-z0-9-]+$/, { timeout: 20_000 });

    await page.goto('/event-admin/mobile/events');
    await expect(page.getByText(eventName, { exact: false })).toBeVisible();
  });

  test('Upload blocked when package limit reached in Guest PWA', async ({ page }) => {
    const eventToken = process.env.E2E_GUEST_LIMIT_EVENT_TOKEN;
    test.skip(!eventToken, 'Set E2E_GUEST_LIMIT_EVENT_TOKEN to a guest join token with exhausted limits.');

    await page.goto(`/e/${eventToken}/upload`);

    await expect(page.getByText(/Upload-Limit erreicht/i)).toBeVisible();
  });
});
