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

import {
    coreRoutePaths,
    expectDisclosureLayer,
    expectFooterLinks,
    expectNavigationVsCtaDifferentiation,
    expectPageFamily,
    expectPrimaryNavigation,
    expectShell,
    openMobileNavigation,
    visitPage,
} from './smoke-helpers';

test('contact page qualifies the conversation and keeps legal links reachable', async ({ page }) => {
    await visitPage(page, '/contact');
    await expectShell(page, /working session|contact path|qualified/i);
    await expectPageFamily(page, 'content');
    await expectDisclosureLayer(page, '1');
    await expectDisclosureLayer(page, '2');
    await expectPrimaryNavigation(page);
    await expectNavigationVsCtaDifferentiation(page);
    await expectFooterLinks(page);
    await expect(
        page.getByRole('heading', {
            name: 'Structure the first conversation before anyone shares sensitive context.',
        }),
    ).toBeVisible();
    await expect(page.getByRole('main').getByRole('link', { name: 'Email the TenantAtlas team' }).first()).toBeVisible();
    await expect(page.getByRole('main').getByRole('link', { name: 'Review the trust posture' }).first()).toBeVisible();
    await expect(page.getByRole('main').getByRole('link', { name: 'Privacy' }).first()).toBeVisible();
    await expect(page.getByRole('main').getByRole('link', { name: 'Terms' }).first()).toBeVisible();
    await expect(page.getByRole('main').getByRole('link', { name: 'Imprint' }).first()).toBeVisible();
});

test('legal, privacy, imprint, and terms routes are published and linked', async ({ page }) => {
    await visitPage(page, '/legal');
    await expectShell(page, /Legal access should stay one click away from the trust and contact path\./);
    await expectPageFamily(page, 'content');
    await expectDisclosureLayer(page, '1');
    await expectDisclosureLayer(page, '2');
    await expect(
        page.getByRole('heading', { name: 'Keep the legal baseline explicit without promoting it into the main navigation.' }),
    ).toBeVisible();
    await expect(page.getByRole('main').getByRole('link', { name: 'Trust' }).first()).toBeVisible();
    await expect(page.getByRole('main').getByRole('link', { name: 'Terms' }).first()).toBeVisible();
    await expect(page.getByRole('main').getByRole('link', { name: 'Imprint' }).first()).toBeVisible();

    await visitPage(page, '/privacy');
    await expectShell(page, /Public-site privacy overview|privacy/i);
    await expectPageFamily(page, 'content');

    await visitPage(page, '/imprint');
    await expectShell(page, /Imprint|legal notice/i);
    await expectPageFamily(page, 'content');

    await visitPage(page, '/terms');
    await expectShell(page, /Website terms|terms/i);
    await expectPageFamily(page, 'content');
});

test('core pages keep contact and legal paths within reach', async ({ page }) => {
    for (const path of coreRoutePaths) {
        await visitPage(page, path);
        await expectFooterLinks(page);

        if (path !== '/contact') {
            await expect(page.locator('main a[href="/contact"]').first()).toBeVisible();
        }
    }
});

test.describe('mobile navigation', () => {
    test.use({ viewport: { width: 390, height: 844 } });

    test('mobile menu exposes the published contact and legal paths', async ({ page }) => {
        await visitPage(page, '/');
        await openMobileNavigation(page);
        await expect(page.locator('[data-mobile-nav]').first()).toBeVisible();
        await expect(page.getByRole('banner').getByRole('link', { name: /Contact/ }).first()).toBeVisible();
        await expect(page.getByRole('banner').getByRole('link', { name: 'Trust' }).first()).toBeVisible();
        await expect(page.getByRole('banner').getByRole('link', { name: 'Changelog' }).first()).toBeVisible();
        await expect(page.getByRole('contentinfo').getByRole('link', { name: 'Privacy' })).toBeVisible();
        await expect(page.getByRole('contentinfo').getByRole('link', { name: 'Terms' })).toBeVisible();
        await expect(page.getByRole('contentinfo').getByRole('link', { name: 'Imprint' })).toBeVisible();
    });
});
