/* 临时截图脚本：mock 登录后截取登录页/主界面/通讯录 */
const { chromium } = require("@playwright/test");

(async () => {
  const browser = await chromium.launch({
    executablePath:
      "C:/Users/MoBai/AppData/Local/ms-playwright/chromium_headless_shell-1228/chrome-headless-shell-win64/chrome-headless-shell.exe",
  });
  const page = await browser.newPage({ viewport: { width: 1200, height: 800 } });
  page.on("console", (msg) => {
    if (msg.type() === "error") console.log("[console.error]", msg.text().slice(0, 200));
  });

  await page.goto("http://localhost:5173/", { waitUntil: "networkidle" });
  await page.waitForTimeout(2000);
  await page.screenshot({ path: "e2e/screenshots/01-login.png" });

  await page.fill('input[placeholder="请输入工号"]', "test001");
  await page.fill('input[placeholder="请输入您的密码"]', "test123");
  await page.click('button:has-text("登录")');

  // 等 SDK 登录 + 同步
  await page.waitForTimeout(18000);
  await page.screenshot({ path: "e2e/screenshots/02-main.png" });

  // 进入会话
  await page.click('text=测试二号');
  await page.waitForTimeout(4000);
  await page.screenshot({ path: "e2e/screenshots/04-chat.png" });

  // 发一条文字消息看气泡
  await page.fill("textarea", "好，我开完会就看，下午给你回复");
  await page.keyboard.press("Enter");
  await page.waitForTimeout(2500);
  await page.screenshot({ path: "e2e/screenshots/05-chat-sent.png" });

  await page.goto("http://localhost:5173/#/contact");
  await page.waitForTimeout(4000);
  await page.screenshot({ path: "e2e/screenshots/03-contact.png" });

  await browser.close();
  console.log("done");
})().catch((e) => {
  console.error(e);
  process.exit(1);
});
