/**
 * Smoke tests — verify the app launches and core UI elements are present.
 */

describe("Smoke tests", () => {
  it("should launch and have the correct title", async () => {
    const title = await browser.getTitle();
    expect(title).toContain("Agent Orchestrator");
  });

  it("should render the app shell", async () => {
    const shell = await $(".app-shell");
    await shell.waitForExist({ timeout: 10_000 });
    expect(await shell.isDisplayed()).toBe(true);
  });

  it("should show the left sidebar", async () => {
    const sidebar = await $(".sidebar");
    expect(await sidebar.isDisplayed()).toBe(true);
  });

  it("should show the AGOR title in sidebar", async () => {
    const title = await $(".agor-title");
    expect(await title.isDisplayed()).toBe(true);
    expect(await title.getText()).toBe("AGOR");
  });

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

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

  it("should show the right sidebar with window controls", async () => {
    const rightBar = await $(".right-bar");
    expect(await rightBar.isDisplayed()).toBe(true);
  });

  it("should show window close button", async () => {
    const closeBtn = await $(".close-btn");
    expect(await closeBtn.isDisplayed()).toBe(true);
  });

  it("should show the status bar", async () => {
    const statusBar = await $(".status-bar");
    await statusBar.waitForExist({ timeout: 5_000 });
    expect(await statusBar.isDisplayed()).toBe(true);
  });

  it("should show the settings gear icon", async () => {
    const gear = await $(".sidebar-icon");
    expect(await gear.isDisplayed()).toBe(true);
    expect(await gear.isClickable()).toBe(true);
  });

  it("should show the notification bell", async () => {
    const bell = await $(".notif-btn");
    expect(await bell.isDisplayed()).toBe(true);
  });

  it("should have at least one project card in default group", async () => {
    const cards = await $$(".project-card");
    // App may have demo data or be empty — just verify grid exists
    expect(cards).toBeDefined();
  });

  it("should show terminal section in a project card", async () => {
    const termSection = await $(".terminal-section");
    // Terminal section may or may not be visible depending on card state
    if (await termSection.isExisting()) {
      expect(await termSection.isDisplayed()).toBe(true);
    }
  });
});
