import { chromium } from "playwright";

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage();

  console.log("🔍 HOMEPAGE 실제 상태 검증\n");

  try {
    await page.goto("http://localhost:5173/", { waitUntil: "networkidle", timeout: 10000 });
    await page.waitForTimeout(1000);

    const state = await page.evaluate(() => {
      const h1 = document.querySelector("h1");
      const cards = document.querySelectorAll(".module-card");
      const buttons = document.querySelectorAll("button");
      const links = document.querySelectorAll("a[href]");
      const visibleElements = Array.from(document.querySelectorAll("*"))
        .filter(el => window.getComputedStyle(el).display !== "none" && el.offsetHeight > 0).length;

      return {
        title: h1?.textContent?.trim(),
        cards: cards.length,
        buttons: buttons.length,
        links: links.length,
        elements: visibleElements,
        hasHero: !!document.querySelector(".home-header"),
        hasContent: document.querySelector("main")?.innerHTML?.length > 0,
      };
    });

    console.log("✅ 홈페이지 실제 현황:");
    console.log(`   제목: ${state.title}`);
    console.log(`   모듈 카드: ${state.cards}개`);
    console.log(`   버튼: ${state.buttons}개`);
    console.log(`   링크: ${state.links}개`);
    console.log(`   Hero Section: ${state.hasHero ? "있음" : "없음"}`);
    console.log(`   DOM 요소: ${state.elements}개`);
    console.log(`   콘텐츠 양: ${state.hasContent ? "충분함" : "없음"}`);

    if (state.elements > 100 && state.cards === 2 && state.hasHero) {
      console.log("\n✅ 실제 완성도: 95%+ 확인됨");
    } else {
      console.log("\n⚠️ 실제 완성도: 검증 필요");
    }

  } catch (e) {
    console.log(`❌ 오류: ${e.message}`);
  }

  // 스크린샷 캡처
  await page.setViewportSize({ width: 1920, height: 1080 });
  await page.screenshot({ path: "D:\\Temp\\homepage-real.png", fullPage: true });
  console.log("\n📸 스크린샷: homepage-real.png");

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