/**
 * Group sidebar tests — numbered circles, switching, active state, add button, badges.
 */

describe("Group sidebar", () => {
  it("should show group buttons in sidebar", async () => {
    const groups = await $$(".group-btn");
    expect(groups.length).toBeGreaterThanOrEqual(1);
  });

  it("should show numbered circle for each group", async () => {
    const circles = await $$(".group-circle");
    expect(circles.length).toBeGreaterThanOrEqual(1);

    const text = await circles[0].getText();
    // First group should show "1"
    expect(text).toBe("1");
  });

  it("should highlight the active group", async () => {
    const activeGroups = await $$(".group-btn.active");
    expect(activeGroups.length).toBe(1);
  });

  it("should show add group button", async () => {
    const addBtn = await $(".add-group-btn");
    if (await addBtn.isExisting()) {
      expect(await addBtn.isDisplayed()).toBe(true);

      const circle = await addBtn.$(".group-circle");
      const text = await circle.getText();
      expect(text).toBe("+");
    }
  });

  it("should switch active group on click", async () => {
    const groups = await $$(".group-btn:not(.add-group-btn)");
    if (groups.length < 2) return;

    // Click second group
    await groups[1].click();
    await browser.pause(300);

    const cls = await groups[1].getAttribute("class");
    expect(cls).toContain("active");

    // Switch back to first
    await groups[0].click();
    await browser.pause(300);
  });

  it("should show notification badge when group has new activity", async () => {
    // Badge may or may not exist depending on state
    const badges = await $$(".group-badge");
    // Just verify the badge element structure exists in DOM
    expect(badges).toBeDefined();
  });

  it("should show project grid for active group", async () => {
    const grid = await $(".project-grid");
    expect(await grid.isDisplayed()).toBe(true);
  });

  it("should display project cards matching active group", async () => {
    const cards = await $$(".project-card");
    // Should show at least the cards for the active group
    expect(cards).toBeDefined();
  });
});
