const { chromium } = require("C:/Users/ramez/AppData/Roaming/npm/node_modules/playwright");

(async () => {
  console.log("Testing Dymola modes via + Poser sur canvas button...");
  const browser = await chromium.launch({ headless: true });
  const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });

  await page.goto("http://localhost:3001", { waitUntil: "domcontentloaded" });
  await page.waitForTimeout(1000);

  // 1. Click Bibliothèque tab
  console.log("Clicking Bibliothèque tab...");
  await page.click("button:has-text('Bibliothèque')");
  await page.waitForTimeout(800);

  // 2. Click "+ Poser sur canvas" on BaseChiller
  console.log("Clicking + Poser sur canvas on BaseChiller...");
  const addBtn = page.locator("button:has-text('+ Poser sur canvas')").first();
  await addBtn.click();
  await page.waitForTimeout(1000);

  // Screenshot Mode 1: Dymola Icon View
  await page.screenshot({ path: "C:/Users/ramez/.gemini/antigravity-ide/brain/e16f5552-47ce-4483-9b25-8266bb395491/dymola_mode_1_icon.png" });

  // 3. Click Mode Schéma button in node header
  const modeBtn = page.locator("button:has-text('Mode Schéma')").first();
  if (await modeBtn.isVisible()) {
    console.log("Clicking Mode Schéma button...");
    await modeBtn.click();
    await page.waitForTimeout(800);
  }

  // Screenshot Mode 2: In-Place Diagram View
  await page.screenshot({ path: "C:/Users/ramez/.gemini/antigravity-ide/brain/e16f5552-47ce-4483-9b25-8266bb395491/dymola_mode_2_diagram.png" });

  console.log("Both Dymola modes captured successfully!");
  await browser.close();
})();
