#!/usr/bin/env python3
"""v-round2 4차 피드백 수정 후 PNG 렌더링 (Cell 2, 7, 9 — 1200x628만)"""
import asyncio
from pathlib import Path
from playwright.async_api import async_playwright

BASE = Path("/home/jay/workspace/output/banners/versions/v-round2")

CELLS = [
    ("cell-2-incar-leader", 1200, 628),
    ("cell-7-snu-fair", 1200, 628),
    ("cell-9-snu-support", 1200, 628),
]

async def render_one(browser, cell_dir: str, w: int, h: int):
    html_path = BASE / cell_dir / f"google-resp-{w}x{h}.html"
    png_path = BASE / cell_dir / f"google-resp-{w}x{h}.png"
    if not html_path.exists():
        print(f"[SKIP] {html_path} not found")
        return
    page = await browser.new_page(viewport={"width": w, "height": h})
    await page.goto(f"file://{html_path}", wait_until="networkidle")
    await page.wait_for_timeout(1500)  # 폰트 로딩 대기
    await page.screenshot(path=str(png_path), type="png")
    await page.close()
    print(f"[OK] {png_path}")

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        for cell_dir, w, h in CELLS:
            await render_one(browser, cell_dir, w, h)
        await browser.close()
    print("\n=== 렌더링 완료: 3장 PNG ===")

if __name__ == "__main__":
    asyncio.run(main())
