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

(async () => {
  console.log("Testing Modelica UX Overhaul and Subsystem Creation...");
  const browser = await chromium.launch({ headless: true });
  const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });

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

  // 1. Open Bibliothèque tab
  console.log("Opening Bibliothèque tab...");
  const bibTab = page.locator("button").filter({ hasText: /^Bibliothèque/ }).first();
  await bibTab.click();
  await page.waitForTimeout(1000);

  // Take screenshot 1: Library with DualCircuit (2 sous-modules)
  const screenshotPath1 = "C:/Users/ramez/.gemini/antigravity-ide/brain/e16f5552-47ce-4483-9b25-8266bb395491/modelica_workspace_and_dualcircuit_count.png";
  await page.screenshot({ path: screenshotPath1 });
  console.log(`Saved screenshot 1 to ${screenshotPath1}`);

  // 2. Click "+ Nouveau Modèle" button in Bibliothèque
  console.log("Clicking + Nouveau Modèle...");
  await page.click("button:has-text('+ Nouveau Modèle')");
  await page.waitForTimeout(1000);

  // Take screenshot 2: New Model Wizard Modal
  const screenshotPath2 = "C:/Users/ramez/.gemini/antigravity-ide/brain/e16f5552-47ce-4483-9b25-8266bb395491/new_model_wizard_modal.png";
  await page.screenshot({ path: screenshotPath2 });
  console.log(`Saved screenshot 2 to ${screenshotPath2}`);

  // 3. Fill model name "CustomChiller" and submit
  console.log("Entering CustomChiller...");
  await page.fill("input[placeholder*='CustomChillerCircuit']", "CustomChiller");
  await page.waitForTimeout(500);

  console.log("Clicking Créer la Classe Modèle...");
  await page.click("button:has-text('Créer la Classe Modèle')");
  await page.waitForTimeout(2000);

  // Take screenshot 3: Active Modelica Editor view
  const screenshotPath3 = "C:/Users/ramez/.gemini/antigravity-ide/brain/e16f5552-47ce-4483-9b25-8266bb395491/modelica_class_editor_banner.png";
  await page.screenshot({ path: screenshotPath3 });
  console.log(`Saved screenshot 3 to ${screenshotPath3}`);

  await browser.close();
})();
