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

test.describe("Public pages", () => {
  test("landing page loads with heading and nav links", async ({ page }) => {
    await page.goto("/");

    await expect(page.locator(".landing-logo").first()).toHaveText("CERTifAI");
    await expect(page.locator(".landing-nav-links")).toBeVisible();
    await expect(page.locator('a[href="#features"]')).toBeVisible();
    await expect(page.locator('a[href="#how-it-works"]')).toBeVisible();
    await expect(page.locator('a[href="#pricing"]')).toBeVisible();
  });

  test("landing page Log In link navigates to login route", async ({
    page,
  }) => {
    await page.goto("/");

    const loginLink = page
      .locator(".landing-nav-actions a, .landing-nav-actions Link")
      .filter({ hasText: "Log In" });
    await loginLink.click();

    await expect(page).toHaveURL(/\/login/);
  });

  test("impressum page loads with legal content", async ({ page }) => {
    await page.goto("/impressum");

    await expect(page.locator("h1")).toHaveText("Impressum");
    await expect(
      page.locator("h2", { hasText: "Information according to" })
    ).toBeVisible();
    await expect(page.locator(".legal-content")).toContainText(
      "CERTifAI GmbH"
    );
  });

  test("privacy page loads with privacy content", async ({ page }) => {
    await page.goto("/privacy");

    await expect(page.locator("h1")).toHaveText("Privacy Policy");
    await expect(
      page.locator("h2", { hasText: "Introduction" })
    ).toBeVisible();
    await expect(
      page.locator("h2", { hasText: "Your Rights" })
    ).toBeVisible();
  });

  test("footer links are present on landing page", async ({ page }) => {
    await page.goto("/");

    const footer = page.locator(".landing-footer");
    await expect(footer.locator('a:has-text("Impressum")')).toBeVisible();
    await expect(
      footer.locator('a:has-text("Privacy Policy")')
    ).toBeVisible();
  });
});
