// The Lucia project.
// Copyright 2026-2026 DSP, inc.  All rights reserved.
// Authors:
//   imacat.yang@dsp.im (imacat), 2026/03/22

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

test.describe("Discover Map Page", () => {
  test.beforeEach(async ({ page, context }) => {
    await loginWithMSW(context);
    await page.goto("/discover/log/297310264/map");
    await expect(page.locator("#cy")).toBeVisible();
  });

  test("page loads and cytoscape container exists", async ({ page }) => {
    await expect(page.locator("#cy")).toBeVisible();
  });

  test("displays left sidebar buttons", async ({ page }) => {
    // Visualization Setting, Filter, Traces buttons
    await expect(
      page.locator(".material-symbols-outlined", { hasText: "track_changes" }),
    ).toBeVisible();
    await expect(
      page.locator(".material-symbols-outlined", { hasText: "tornado" }),
    ).toBeVisible();
    await expect(
      page.locator(".material-symbols-outlined", { hasText: "rebase" }),
    ).toBeVisible();
  });

  test("displays right sidebar Summary button", async ({ page }) => {
    await expect(page.locator("#sidebar_state")).toBeVisible();
    await expect(page.locator("#iconState")).toBeVisible();
  });

  test("clicking Visualization Setting button toggles sidebar", async ({
    page,
  }) => {
    // Click the track_changes icon (Visualization Setting)
    await page
      .locator("span.material-symbols-outlined", { hasText: "track_changes" })
      .locator("..")
      .click();
    // SidebarView should open
    await expect(page.getByText("Visualization Setting").first()).toBeVisible();
  });

  test("clicking Summary button toggles sidebar", async ({ page }) => {
    await page.locator("#iconState").click();
    // SidebarState should open with insights/stats
    await expect(page.getByText("Summary").first()).toBeVisible();
  });

  test("clicking Traces button toggles sidebar", async ({ page }) => {
    await page
      .locator("span.material-symbols-outlined", { hasText: "rebase" })
      .locator("..")
      .click();
    // SidebarTraces should open
    await expect(page.getByText("Traces")).toBeVisible();
  });
});
